@directus/extensions-sdk 9.0.0-rc.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/.editorconfig +12 -0
  2. package/cli.d.ts +1 -0
  3. package/cli.js +2 -0
  4. package/dist/cjs/cli/commands/build.d.ts +11 -0
  5. package/dist/cjs/cli/commands/build.d.ts.map +1 -0
  6. package/dist/cjs/cli/commands/build.js +181 -0
  7. package/dist/cjs/cli/commands/create.d.ts +6 -0
  8. package/dist/cjs/cli/commands/create.d.ts.map +1 -0
  9. package/dist/cjs/cli/commands/create.js +96 -0
  10. package/dist/cjs/cli/index.d.ts +4 -0
  11. package/dist/cjs/cli/index.d.ts.map +1 -0
  12. package/dist/cjs/cli/index.js +10 -0
  13. package/dist/cjs/cli/run.d.ts +2 -0
  14. package/dist/cjs/cli/run.d.ts.map +1 -0
  15. package/dist/cjs/cli/run.js +29 -0
  16. package/dist/cjs/cli/types.d.ts +4 -0
  17. package/dist/cjs/cli/types.d.ts.map +1 -0
  18. package/dist/cjs/cli/types.js +2 -0
  19. package/dist/cjs/cli/utils/get-package-version.d.ts +2 -0
  20. package/dist/cjs/cli/utils/get-package-version.d.ts.map +1 -0
  21. package/dist/cjs/cli/utils/get-package-version.js +12 -0
  22. package/dist/cjs/cli/utils/languages.d.ts +5 -0
  23. package/dist/cjs/cli/utils/languages.d.ts.map +1 -0
  24. package/dist/cjs/cli/utils/languages.js +30 -0
  25. package/dist/cjs/cli/utils/load-config.d.ts +2 -0
  26. package/dist/cjs/cli/utils/load-config.d.ts.map +1 -0
  27. package/dist/cjs/cli/utils/load-config.js +20 -0
  28. package/dist/cjs/cli/utils/logger.d.ts +2 -0
  29. package/dist/cjs/cli/utils/logger.d.ts.map +1 -0
  30. package/dist/cjs/cli/utils/logger.js +22 -0
  31. package/dist/cjs/cli/utils/rename-map.d.ts +2 -0
  32. package/dist/cjs/cli/utils/rename-map.d.ts.map +1 -0
  33. package/dist/cjs/cli/utils/rename-map.js +23 -0
  34. package/dist/cjs/index.d.ts +3 -0
  35. package/dist/cjs/index.d.ts.map +1 -0
  36. package/dist/cjs/index.js +19 -0
  37. package/dist/esm/cli/commands/build.d.ts +11 -0
  38. package/dist/esm/cli/commands/build.d.ts.map +1 -0
  39. package/dist/esm/cli/commands/build.js +175 -0
  40. package/dist/esm/cli/commands/create.d.ts +6 -0
  41. package/dist/esm/cli/commands/create.d.ts.map +1 -0
  42. package/dist/esm/cli/commands/create.js +90 -0
  43. package/dist/esm/cli/index.d.ts +4 -0
  44. package/dist/esm/cli/index.d.ts.map +1 -0
  45. package/dist/esm/cli/index.js +3 -0
  46. package/dist/esm/cli/run.d.ts +2 -0
  47. package/dist/esm/cli/run.d.ts.map +1 -0
  48. package/dist/esm/cli/run.js +24 -0
  49. package/dist/esm/cli/types.d.ts +4 -0
  50. package/dist/esm/cli/types.d.ts.map +1 -0
  51. package/dist/esm/cli/types.js +1 -0
  52. package/dist/esm/cli/utils/get-package-version.d.ts +2 -0
  53. package/dist/esm/cli/utils/get-package-version.d.ts.map +1 -0
  54. package/dist/esm/cli/utils/get-package-version.js +6 -0
  55. package/dist/esm/cli/utils/languages.d.ts +5 -0
  56. package/dist/esm/cli/utils/languages.d.ts.map +1 -0
  57. package/dist/esm/cli/utils/languages.js +24 -0
  58. package/dist/esm/cli/utils/load-config.d.ts +2 -0
  59. package/dist/esm/cli/utils/load-config.d.ts.map +1 -0
  60. package/dist/esm/cli/utils/load-config.js +14 -0
  61. package/dist/esm/cli/utils/logger.d.ts +2 -0
  62. package/dist/esm/cli/utils/logger.d.ts.map +1 -0
  63. package/dist/esm/cli/utils/logger.js +16 -0
  64. package/dist/esm/cli/utils/rename-map.d.ts +2 -0
  65. package/dist/esm/cli/utils/rename-map.d.ts.map +1 -0
  66. package/dist/esm/cli/utils/rename-map.js +17 -0
  67. package/dist/esm/index.d.ts +3 -0
  68. package/dist/esm/index.d.ts.map +1 -0
  69. package/dist/esm/index.js +2 -0
  70. package/license +674 -0
  71. package/package.json +56 -0
  72. package/readme.md +3 -0
  73. package/src/cli/commands/build.ts +211 -0
  74. package/src/cli/commands/create.ts +121 -0
  75. package/src/cli/index.ts +4 -0
  76. package/src/cli/run.ts +30 -0
  77. package/src/cli/types.ts +4 -0
  78. package/src/cli/utils/get-package-version.ts +9 -0
  79. package/src/cli/utils/languages.ts +26 -0
  80. package/src/cli/utils/load-config.ts +19 -0
  81. package/src/cli/utils/logger.ts +15 -0
  82. package/src/cli/utils/rename-map.ts +20 -0
  83. package/src/index.ts +11 -0
  84. package/templates/common/javascript/_gitignore +3 -0
  85. package/templates/common/typescript/_gitignore +3 -0
  86. package/templates/common/typescript/tsconfig.json +28 -0
  87. package/templates/display/javascript/src/display.vue +14 -0
  88. package/templates/display/javascript/src/index.js +11 -0
  89. package/templates/display/typescript/src/display.vue +16 -0
  90. package/templates/display/typescript/src/index.ts +12 -0
  91. package/templates/display/typescript/src/shims.d.ts +5 -0
  92. package/templates/endpoint/javascript/src/index.js +3 -0
  93. package/templates/endpoint/typescript/src/index.ts +5 -0
  94. package/templates/hook/javascript/src/index.js +5 -0
  95. package/templates/hook/typescript/src/index.ts +7 -0
  96. package/templates/interface/javascript/src/index.js +11 -0
  97. package/templates/interface/javascript/src/interface.vue +22 -0
  98. package/templates/interface/typescript/src/index.ts +12 -0
  99. package/templates/interface/typescript/src/interface.vue +24 -0
  100. package/templates/interface/typescript/src/shims.d.ts +5 -0
  101. package/templates/layout/javascript/src/index.js +19 -0
  102. package/templates/layout/javascript/src/layout.vue +22 -0
  103. package/templates/layout/typescript/src/index.ts +20 -0
  104. package/templates/layout/typescript/src/layout.vue +24 -0
  105. package/templates/layout/typescript/src/shims.d.ts +5 -0
  106. package/templates/module/javascript/src/index.js +13 -0
  107. package/templates/module/javascript/src/module.vue +7 -0
  108. package/templates/module/typescript/src/index.ts +14 -0
  109. package/templates/module/typescript/src/module.vue +9 -0
  110. package/templates/module/typescript/src/shims.d.ts +5 -0
  111. package/tsconfig.json +30 -0
@@ -0,0 +1,175 @@
1
+ import path from 'path';
2
+ import chalk from 'chalk';
3
+ import fse from 'fs-extra';
4
+ import ora from 'ora';
5
+ import { rollup, watch as rollupWatch, } from 'rollup';
6
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
7
+ import commonjs from '@rollup/plugin-commonjs';
8
+ import json from '@rollup/plugin-json';
9
+ import replace from '@rollup/plugin-replace';
10
+ import typescript from 'rollup-plugin-typescript2';
11
+ import { terser } from 'rollup-plugin-terser';
12
+ import styles from 'rollup-plugin-styles';
13
+ import vue from 'rollup-plugin-vue';
14
+ import { EXTENSION_PKG_KEY, EXTENSION_TYPES, APP_SHARED_DEPS, API_SHARED_DEPS } from '@directus/shared/constants';
15
+ import { isAppExtension, isExtension, validateExtensionManifest } from '@directus/shared/utils';
16
+ import log from '../utils/logger';
17
+ import { getLanguageFromPath, isLanguage } from '../utils/languages';
18
+ import loadConfig from '../utils/load-config';
19
+ export default async function build(options) {
20
+ var _a, _b, _c;
21
+ const packagePath = path.resolve('package.json');
22
+ let extensionManifest = {};
23
+ if (!(await fse.pathExists(packagePath))) {
24
+ log(`Current directory is not a package.`, !options.force ? 'error' : 'warn');
25
+ if (!options.force)
26
+ process.exit(1);
27
+ }
28
+ else {
29
+ extensionManifest = await fse.readJSON(packagePath);
30
+ if (!validateExtensionManifest(extensionManifest)) {
31
+ log(`Current directory is not a Directus extension.`, !options.force ? 'error' : 'warn');
32
+ if (!options.force)
33
+ process.exit(1);
34
+ }
35
+ }
36
+ const type = options.type || ((_a = extensionManifest[EXTENSION_PKG_KEY]) === null || _a === void 0 ? void 0 : _a.type);
37
+ const input = options.input || ((_b = extensionManifest[EXTENSION_PKG_KEY]) === null || _b === void 0 ? void 0 : _b.source);
38
+ const output = options.output || ((_c = extensionManifest[EXTENSION_PKG_KEY]) === null || _c === void 0 ? void 0 : _c.path);
39
+ if (!type || !isExtension(type)) {
40
+ log(`Extension type ${chalk.bold(type)} does not exist. Available extension types: ${EXTENSION_TYPES.map((t) => chalk.bold.magenta(t)).join(', ')}.`, 'error');
41
+ process.exit(1);
42
+ }
43
+ if (!input || !(await fse.pathExists(input)) || !(await fse.stat(input)).isFile()) {
44
+ log(`Entrypoint ${chalk.bold(input)} does not exist.`, 'error');
45
+ process.exit(1);
46
+ }
47
+ if (!output) {
48
+ log(`Output file must be a valid path.`, 'error');
49
+ process.exit(1);
50
+ }
51
+ const language = options.language || getLanguageFromPath(input);
52
+ if (!isLanguage(language)) {
53
+ log(`Language ${chalk.bold(language)} is not supported.`, 'error');
54
+ process.exit(1);
55
+ }
56
+ const config = await loadConfig();
57
+ const spinner = ora('Building Directus extension...').start();
58
+ const rollupOptions = getRollupOptions(type, language, input, config.plugins);
59
+ const rollupOutputOptions = getRollupOutputOptions(type, output);
60
+ if (options.watch) {
61
+ const watcher = rollupWatch({
62
+ ...rollupOptions,
63
+ output: rollupOutputOptions,
64
+ });
65
+ watcher.on('event', async (event) => {
66
+ switch (event.code) {
67
+ case 'ERROR': {
68
+ spinner.fail(chalk.bold('Failed'));
69
+ handleRollupError(event.error);
70
+ spinner.start(chalk.bold('Watching files for changes...'));
71
+ break;
72
+ }
73
+ case 'BUNDLE_END':
74
+ await event.result.close();
75
+ spinner.succeed(chalk.bold('Done'));
76
+ spinner.start(chalk.bold('Watching files for changes...'));
77
+ break;
78
+ case 'BUNDLE_START':
79
+ spinner.text = 'Building Directus extension...';
80
+ break;
81
+ }
82
+ });
83
+ }
84
+ else {
85
+ try {
86
+ const bundle = await rollup(rollupOptions);
87
+ await bundle.write(rollupOutputOptions);
88
+ await bundle.close();
89
+ spinner.succeed(chalk.bold('Done'));
90
+ }
91
+ catch (error) {
92
+ spinner.fail(chalk.bold('Failed'));
93
+ handleRollupError(error);
94
+ process.exitCode = 1;
95
+ }
96
+ }
97
+ }
98
+ function getRollupOptions(type, language, input, plugins = []) {
99
+ if (isAppExtension(type)) {
100
+ return {
101
+ input,
102
+ external: APP_SHARED_DEPS,
103
+ plugins: [
104
+ vue({ preprocessStyles: true }),
105
+ language === 'typescript' ? typescript({ check: false }) : null,
106
+ styles(),
107
+ ...plugins,
108
+ nodeResolve({ browser: true }),
109
+ commonjs({ esmExternals: true, sourceMap: false }),
110
+ json(),
111
+ replace({
112
+ values: {
113
+ 'process.env.NODE_ENV': JSON.stringify('production'),
114
+ },
115
+ preventAssignment: true,
116
+ }),
117
+ terser(),
118
+ ],
119
+ };
120
+ }
121
+ else {
122
+ return {
123
+ input,
124
+ external: API_SHARED_DEPS,
125
+ plugins: [
126
+ language === 'typescript' ? typescript({ check: false }) : null,
127
+ ...plugins,
128
+ nodeResolve(),
129
+ commonjs({ sourceMap: false }),
130
+ json(),
131
+ replace({
132
+ values: {
133
+ 'process.env.NODE_ENV': JSON.stringify('production'),
134
+ },
135
+ preventAssignment: true,
136
+ }),
137
+ terser(),
138
+ ],
139
+ };
140
+ }
141
+ }
142
+ function getRollupOutputOptions(type, output) {
143
+ if (isAppExtension(type)) {
144
+ return {
145
+ file: output,
146
+ format: 'es',
147
+ };
148
+ }
149
+ else {
150
+ return {
151
+ file: output,
152
+ format: 'cjs',
153
+ exports: 'default',
154
+ };
155
+ }
156
+ }
157
+ function handleRollupError(error) {
158
+ const pluginPrefix = error.plugin ? `(plugin ${error.plugin}) ` : '';
159
+ log('\n' + chalk.red.bold(`${pluginPrefix}${error.name}: ${error.message}`));
160
+ if (error.url) {
161
+ log(chalk.cyan(error.url), 'error');
162
+ }
163
+ if (error.loc) {
164
+ log(`${(error.loc.file || error.id)} (${error.loc.line}:${error.loc.column})`);
165
+ }
166
+ else if (error.id) {
167
+ log(error.id);
168
+ }
169
+ if (error.frame) {
170
+ log(chalk.dim(error.frame));
171
+ }
172
+ if (error.stack) {
173
+ log(chalk.dim(error.stack));
174
+ }
175
+ }
@@ -0,0 +1,6 @@
1
+ declare type CreateOptions = {
2
+ language: string;
3
+ };
4
+ export default function create(type: string, name: string, options: CreateOptions): Promise<void>;
5
+ export {};
6
+ //# sourceMappingURL=create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/create.ts"],"names":[],"mappings":"AAkBA,aAAK,aAAa,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1C,wBAA8B,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CA4EtG"}
@@ -0,0 +1,90 @@
1
+ import path from 'path';
2
+ import chalk from 'chalk';
3
+ import fse from 'fs-extra';
4
+ import execa from 'execa';
5
+ import ora from 'ora';
6
+ import { EXTENSION_TYPES, EXTENSION_PKG_KEY, EXTENSION_LANGUAGES } from '@directus/shared/constants';
7
+ import { isAppExtension, isExtension } from '@directus/shared/utils';
8
+ import log from '../utils/logger';
9
+ import { isLanguage, languageToShort } from '../utils/languages';
10
+ import renameMap from '../utils/rename-map';
11
+ import getPackageVersion from '../utils/get-package-version';
12
+ const pkg = require('../../../../package.json');
13
+ const TEMPLATE_PATH = path.resolve(__dirname, '../../../../templates');
14
+ export default async function create(type, name, options) {
15
+ const targetPath = path.resolve(name);
16
+ if (!isExtension(type)) {
17
+ log(`Extension type ${chalk.bold(type)} does not exist. Available extension types: ${EXTENSION_TYPES.map((t) => chalk.bold.magenta(t)).join(', ')}.`, 'error');
18
+ process.exit(1);
19
+ }
20
+ if (await fse.pathExists(targetPath)) {
21
+ const info = await fse.stat(targetPath);
22
+ if (!info.isDirectory()) {
23
+ log(`Destination ${chalk.bold(name)} already exists and is not a directory.`, 'error');
24
+ process.exit(1);
25
+ }
26
+ const files = await fse.readdir(targetPath);
27
+ if (files.length > 0) {
28
+ log(`Destination ${chalk.bold(name)} already exists and is not empty.`, 'error');
29
+ process.exit(1);
30
+ }
31
+ }
32
+ if (!isLanguage(options.language)) {
33
+ log(`Language ${chalk.bold(options.language)} is not supported. Available languages: ${EXTENSION_LANGUAGES.map((t) => chalk.bold.magenta(t)).join(', ')}.`, 'error');
34
+ process.exit(1);
35
+ }
36
+ const spinner = ora(`Scaffolding Directus extension...`).start();
37
+ await fse.ensureDir(targetPath);
38
+ await fse.copy(path.join(TEMPLATE_PATH, 'common', options.language), targetPath);
39
+ await fse.copy(path.join(TEMPLATE_PATH, type, options.language), targetPath);
40
+ await renameMap(targetPath, (name) => (name.startsWith('_') ? `.${name.substring(1)}` : null));
41
+ const packageManifest = {
42
+ name: `directus-extension-${name}`,
43
+ version: '1.0.0',
44
+ keywords: ['directus', 'directus-extension', `directus-custom-${type}`],
45
+ [EXTENSION_PKG_KEY]: {
46
+ type,
47
+ path: 'dist/index.js',
48
+ source: `src/index.${languageToShort(options.language)}`,
49
+ host: `^${pkg.version}`,
50
+ },
51
+ scripts: {
52
+ build: 'directus-extension build',
53
+ },
54
+ devDependencies: await getPackageDeps(type, options.language),
55
+ };
56
+ await fse.writeJSON(path.join(targetPath, 'package.json'), packageManifest, { spaces: '\t' });
57
+ await execa('npm', ['install'], { cwd: targetPath });
58
+ spinner.succeed(chalk.bold('Done'));
59
+ log(`
60
+ Your ${type} extension has been created at ${chalk.green(targetPath)}
61
+
62
+ Build your extension by running:
63
+ ${chalk.blue('cd')} ${name}
64
+ ${chalk.blue('npm run')} build
65
+ `);
66
+ }
67
+ async function getPackageDeps(type, language) {
68
+ if (isAppExtension(type)) {
69
+ return {
70
+ '@directus/extensions-sdk': pkg.version,
71
+ ...(language === 'typescript'
72
+ ? {
73
+ typescript: `^${await getPackageVersion('typescript')}`,
74
+ }
75
+ : {}),
76
+ vue: `^${await getPackageVersion('vue', 'next')}`,
77
+ };
78
+ }
79
+ else {
80
+ return {
81
+ '@directus/extensions-sdk': pkg.version,
82
+ ...(language === 'typescript'
83
+ ? {
84
+ '@types/node': `^${await getPackageVersion('@types/node')}`,
85
+ typescript: `^${await getPackageVersion('typescript')}`,
86
+ }
87
+ : {}),
88
+ };
89
+ }
90
+ }
@@ -0,0 +1,4 @@
1
+ import create from './commands/create';
2
+ import build from './commands/build';
3
+ export { create, build };
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,KAAK,MAAM,kBAAkB,CAAC;AAErC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import create from './commands/create';
2
+ import build from './commands/build';
3
+ export { create, build };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/cli/run.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ import { Command } from 'commander';
2
+ import create from './commands/create';
3
+ import build from './commands/build';
4
+ const pkg = require('../../../package.json');
5
+ const program = new Command();
6
+ program.name('directus-extension').usage('[command] [options]');
7
+ program.version(pkg.version, '-v, --version');
8
+ program
9
+ .command('create')
10
+ .arguments('<type> <name>')
11
+ .description('Scaffold a new Directus extension')
12
+ .option('-l, --language <language>', 'specify the language to use', 'javascript')
13
+ .action(create);
14
+ program
15
+ .command('build')
16
+ .description('Bundle a Directus extension to a single entrypoint')
17
+ .option('-t, --type <type>', 'overwrite the extension type read from package manifest')
18
+ .option('-i, --input <file>', 'overwrite the entrypoint read from package manifest')
19
+ .option('-o, --output <file>', 'overwrite the output file read from package manifest')
20
+ .option('-l, --language <language>', 'overwrite the language to use')
21
+ .option('-f, --force', 'ignore the package manifest')
22
+ .option('-w, --watch', 'watch and rebuild on changes')
23
+ .action(build);
24
+ program.parse(process.argv);
@@ -0,0 +1,4 @@
1
+ import { EXTENSION_LANGUAGES } from '@directus/shared/constants';
2
+ export declare type Language = typeof EXTENSION_LANGUAGES[number];
3
+ export declare type LanguageShort = 'js' | 'ts';
4
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/cli/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,oBAAY,QAAQ,GAAG,OAAO,mBAAmB,CAAC,MAAM,CAAC,CAAC;AAC1D,oBAAY,aAAa,GAAG,IAAI,GAAG,IAAI,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export default function getPackageVersion(name: string, tag?: string): Promise<string>;
2
+ //# sourceMappingURL=get-package-version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-package-version.d.ts","sourceRoot":"","sources":["../../../../src/cli/utils/get-package-version.ts"],"names":[],"mappings":"AAEA,wBAA8B,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,SAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAM7F"}
@@ -0,0 +1,6 @@
1
+ import execa from 'execa';
2
+ export default async function getPackageVersion(name, tag = 'latest') {
3
+ const npmView = await execa('npm', ['view', name, '--json']);
4
+ const packageInfo = JSON.parse(npmView.stdout);
5
+ return packageInfo['dist-tags'][tag];
6
+ }
@@ -0,0 +1,5 @@
1
+ import { Language, LanguageShort } from '../types';
2
+ export declare function isLanguage(language: string): language is Language;
3
+ export declare function languageToShort(language: Language): LanguageShort;
4
+ export declare function getLanguageFromPath(path: string): string;
5
+ //# sourceMappingURL=languages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"languages.d.ts","sourceRoot":"","sources":["../../../../src/cli/utils/languages.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEnD,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,IAAI,QAAQ,CAEjE;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,aAAa,CAMjE;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAUxD"}
@@ -0,0 +1,24 @@
1
+ import { EXTENSION_LANGUAGES } from '@directus/shared/constants';
2
+ export function isLanguage(language) {
3
+ return EXTENSION_LANGUAGES.includes(language);
4
+ }
5
+ export function languageToShort(language) {
6
+ if (language === 'javascript') {
7
+ return 'js';
8
+ }
9
+ else {
10
+ return 'ts';
11
+ }
12
+ }
13
+ export function getLanguageFromPath(path) {
14
+ const fileExtension = path.substring(path.lastIndexOf('.') + 1);
15
+ if (fileExtension === 'js') {
16
+ return 'javascript';
17
+ }
18
+ else if (fileExtension === 'ts') {
19
+ return 'typescript';
20
+ }
21
+ else {
22
+ return fileExtension;
23
+ }
24
+ }
@@ -0,0 +1,2 @@
1
+ export default function loadConfig(): Promise<Record<string, any>>;
2
+ //# sourceMappingURL=load-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-config.d.ts","sourceRoot":"","sources":["../../../../src/cli/utils/load-config.ts"],"names":[],"mappings":"AAQA,wBAA8B,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAUvE"}
@@ -0,0 +1,14 @@
1
+ import path from 'path';
2
+ import fse from 'fs-extra';
3
+ const CONFIG_FILE_NAMES = ['extension.config.js', 'extension.config.mjs', 'extension.config.cjs'];
4
+ // This is needed to work around Typescript always transpiling import() to require() for CommonJS targets.
5
+ const _import = new Function('url', 'return import(url)');
6
+ export default async function loadConfig() {
7
+ for (const fileName of CONFIG_FILE_NAMES) {
8
+ if (await fse.pathExists(fileName)) {
9
+ const configFile = await _import(path.join(process.cwd(), fileName));
10
+ return configFile.default;
11
+ }
12
+ }
13
+ return {};
14
+ }
@@ -0,0 +1,2 @@
1
+ export default function log(message: string, type?: 'info' | 'warn' | 'error'): void;
2
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../../src/cli/utils/logger.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,OAAO,UAAU,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAUnF"}
@@ -0,0 +1,16 @@
1
+ /* eslint-disable no-console */
2
+ import chalk from 'chalk';
3
+ export default function log(message, type) {
4
+ if (type === 'info') {
5
+ console.log(`${chalk.bold.gray('[Info]')} ${message}`);
6
+ }
7
+ else if (type === 'warn') {
8
+ console.warn(`${chalk.bold.yellow('[Warn]')} ${message}`);
9
+ }
10
+ else if (type === 'error') {
11
+ console.error(`${chalk.bold.red('[Error]')} ${message}`);
12
+ }
13
+ else {
14
+ console.log(message);
15
+ }
16
+ }
@@ -0,0 +1,2 @@
1
+ export default function renameMap(file: string, map: (name: string) => string | null): Promise<void>;
2
+ //# sourceMappingURL=rename-map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rename-map.d.ts","sourceRoot":"","sources":["../../../../src/cli/utils/rename-map.ts"],"names":[],"mappings":"AAGA,wBAA8B,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBzG"}
@@ -0,0 +1,17 @@
1
+ import path from 'path';
2
+ import fse from 'fs-extra';
3
+ export default async function renameMap(file, map) {
4
+ const info = await fse.stat(file);
5
+ if (info.isFile()) {
6
+ const newName = map(path.basename(file));
7
+ if (newName !== null) {
8
+ fse.rename(file, path.join(path.dirname(file), newName));
9
+ }
10
+ }
11
+ else {
12
+ const subFiles = await fse.readdir(file);
13
+ for (const subFile of subFiles) {
14
+ await renameMap(path.join(file, subFile), map);
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,3 @@
1
+ export { defineInterface, defineDisplay, defineLayout, defineModule, defineHook, defineEndpoint, getFieldsFromTemplate, getRelationType, } from '@directus/shared/utils';
2
+ export { useStores, useApi, useSync, useCollection, useItems, useFilterFields } from '@directus/shared/composables';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,eAAe,EACf,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,eAAe,GACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { defineInterface, defineDisplay, defineLayout, defineModule, defineHook, defineEndpoint, getFieldsFromTemplate, getRelationType, } from '@directus/shared/utils';
2
+ export { useStores, useApi, useSync, useCollection, useItems, useFilterFields } from '@directus/shared/composables';