@directus/extensions-sdk 9.24.0 → 9.25.0
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.
- package/cli.js +1 -1
- package/dist/{cjs/cli → cli}/commands/add.d.ts +0 -1
- package/dist/{esm/cli → cli}/commands/add.js +16 -18
- package/dist/{esm/cli → cli}/commands/build.d.ts +0 -1
- package/dist/{esm/cli → cli}/commands/build.js +23 -29
- package/dist/{cjs/cli → cli}/commands/create.d.ts +0 -1
- package/dist/{esm/cli → cli}/commands/create.js +12 -13
- package/dist/{cjs/cli → cli}/commands/helpers/copy-template.d.ts +2 -3
- package/dist/{esm/cli → cli}/commands/helpers/copy-template.js +2 -2
- package/dist/cli/commands/helpers/generate-bundle-entrypoint.d.ts +2 -0
- package/dist/{esm/cli → cli}/commands/helpers/generate-bundle-entrypoint.js +3 -3
- package/dist/{cjs/cli → cli}/commands/helpers/get-extension-dev-deps.d.ts +2 -3
- package/dist/{esm/cli → cli}/commands/helpers/get-extension-dev-deps.js +4 -4
- package/dist/cli/commands/helpers/load-config.d.ts +2 -0
- package/dist/{esm/cli → cli}/commands/helpers/load-config.js +2 -2
- package/dist/cli/commands/helpers/validate-cli-options.d.ts +2 -0
- package/dist/{esm/cli → cli}/commands/helpers/validate-cli-options.js +1 -1
- package/dist/{cjs/cli → cli}/commands/link.d.ts +0 -1
- package/dist/{esm/cli → cli}/commands/link.js +4 -5
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +3 -0
- package/dist/{esm/cli → cli}/run.js +4 -4
- package/dist/{esm/cli → cli}/types.d.ts +2 -3
- package/dist/cli/types.js +1 -0
- package/dist/{cjs/cli → cli}/utils/detect-json-indent.d.ts +0 -1
- package/dist/{esm/cli → cli}/utils/detect-json-indent.js +1 -2
- package/dist/{cjs/cli → cli}/utils/get-package-manager-agent.d.ts +0 -1
- package/dist/{esm/cli → cli}/utils/get-package-manager-agent.js +1 -1
- package/dist/cli/utils/get-package-manager-agent.test.d.ts +1 -0
- package/dist/{esm/cli → cli}/utils/get-package-manager-agent.test.js +3 -3
- package/dist/{cjs/cli → cli}/utils/get-package-manager.d.ts +0 -1
- package/dist/{esm/cli → cli}/utils/get-package-manager.js +3 -3
- package/dist/cli/utils/get-package-manager.test.d.ts +1 -0
- package/dist/{esm/cli → cli}/utils/get-package-manager.test.js +3 -3
- package/dist/{cjs/cli → cli}/utils/get-package-version.d.ts +0 -1
- package/dist/{cjs/cli → cli}/utils/get-sdk-version.d.ts +0 -1
- package/dist/cli/utils/get-sdk-version.js +8 -0
- package/dist/{cjs/cli → cli}/utils/get-template-path.d.ts +0 -1
- package/dist/{cjs/cli → cli}/utils/languages.d.ts +1 -2
- package/dist/{esm/cli → cli}/utils/languages.js +1 -1
- package/dist/{cjs/cli → cli}/utils/logger.d.ts +0 -1
- package/dist/cli/utils/try-parse-json.d.ts +2 -0
- package/dist/{cjs/index.d.ts → index.d.ts} +2 -3
- package/dist/{esm/index.js → index.js} +2 -2
- package/package.json +14 -25
- package/dist/cjs/cli/commands/add.js +0 -243
- package/dist/cjs/cli/commands/build.d.ts +0 -11
- package/dist/cjs/cli/commands/build.js +0 -446
- package/dist/cjs/cli/commands/create.js +0 -125
- package/dist/cjs/cli/commands/helpers/copy-template.js +0 -53
- package/dist/cjs/cli/commands/helpers/generate-bundle-entrypoint.d.ts +0 -3
- package/dist/cjs/cli/commands/helpers/generate-bundle-entrypoint.js +0 -24
- package/dist/cjs/cli/commands/helpers/get-extension-dev-deps.js +0 -27
- package/dist/cjs/cli/commands/helpers/load-config.d.ts +0 -3
- package/dist/cjs/cli/commands/helpers/load-config.js +0 -21
- package/dist/cjs/cli/commands/helpers/validate-cli-options.d.ts +0 -3
- package/dist/cjs/cli/commands/helpers/validate-cli-options.js +0 -23
- package/dist/cjs/cli/commands/link.js +0 -54
- package/dist/cjs/cli/index.d.ts +0 -4
- package/dist/cjs/cli/index.js +0 -10
- package/dist/cjs/cli/run.d.ts +0 -2
- package/dist/cjs/cli/run.js +0 -39
- package/dist/cjs/cli/types.d.ts +0 -13
- package/dist/cjs/cli/types.js +0 -2
- package/dist/cjs/cli/utils/detect-json-indent.js +0 -14
- package/dist/cjs/cli/utils/get-package-manager-agent.js +0 -15
- package/dist/cjs/cli/utils/get-package-manager-agent.test.d.ts +0 -2
- package/dist/cjs/cli/utils/get-package-manager-agent.test.js +0 -24
- package/dist/cjs/cli/utils/get-package-manager.js +0 -20
- package/dist/cjs/cli/utils/get-package-manager.test.d.ts +0 -2
- package/dist/cjs/cli/utils/get-package-manager.test.js +0 -42
- package/dist/cjs/cli/utils/get-package-version.js +0 -12
- package/dist/cjs/cli/utils/get-sdk-version.js +0 -7
- package/dist/cjs/cli/utils/get-template-path.js +0 -10
- package/dist/cjs/cli/utils/languages.js +0 -30
- package/dist/cjs/cli/utils/logger.js +0 -32
- package/dist/cjs/cli/utils/try-parse-json.d.ts +0 -3
- package/dist/cjs/cli/utils/try-parse-json.js +0 -11
- package/dist/cjs/index.js +0 -24
- package/dist/esm/cli/commands/add.d.ts +0 -2
- package/dist/esm/cli/commands/create.d.ts +0 -6
- package/dist/esm/cli/commands/helpers/copy-template.d.ts +0 -4
- package/dist/esm/cli/commands/helpers/generate-bundle-entrypoint.d.ts +0 -3
- package/dist/esm/cli/commands/helpers/get-extension-dev-deps.d.ts +0 -4
- package/dist/esm/cli/commands/helpers/load-config.d.ts +0 -3
- package/dist/esm/cli/commands/helpers/validate-cli-options.d.ts +0 -3
- package/dist/esm/cli/commands/link.d.ts +0 -2
- package/dist/esm/cli/index.d.ts +0 -4
- package/dist/esm/cli/index.js +0 -3
- package/dist/esm/cli/run.d.ts +0 -2
- package/dist/esm/cli/utils/detect-json-indent.d.ts +0 -2
- package/dist/esm/cli/utils/get-package-manager-agent.d.ts +0 -5
- package/dist/esm/cli/utils/get-package-manager-agent.test.d.ts +0 -2
- package/dist/esm/cli/utils/get-package-manager.d.ts +0 -5
- package/dist/esm/cli/utils/get-package-manager.test.d.ts +0 -2
- package/dist/esm/cli/utils/get-package-version.d.ts +0 -2
- package/dist/esm/cli/utils/get-sdk-version.d.ts +0 -2
- package/dist/esm/cli/utils/get-sdk-version.js +0 -4
- package/dist/esm/cli/utils/get-template-path.d.ts +0 -2
- package/dist/esm/cli/utils/languages.d.ts +0 -5
- package/dist/esm/cli/utils/logger.d.ts +0 -3
- package/dist/esm/cli/utils/try-parse-json.d.ts +0 -3
- package/dist/esm/index.d.ts +0 -3
- package/license +0 -674
- package/readme.md +0 -3
- /package/dist/{esm/cli/types.js → cli/run.d.ts} +0 -0
- /package/dist/{esm/cli → cli}/utils/get-package-version.js +0 -0
- /package/dist/{esm/cli → cli}/utils/get-template-path.js +0 -0
- /package/dist/{esm/cli → cli}/utils/logger.js +0 -0
- /package/dist/{esm/cli → cli}/utils/try-parse-json.js +0 -0
package/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
import './dist/esm/cli/run.js';
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EXTENSION_LANGUAGES, EXTENSION_NAME_REGEX, EXTENSION_PKG_KEY, EXTENSION_TYPES, ExtensionManifest, HYBRID_EXTENSION_TYPES, } from '@directus/constants';
|
|
2
|
+
import { isIn, isTypeIn } from '@directus/utils';
|
|
3
|
+
import { pathToRelativeUrl } from '@directus/utils/node';
|
|
2
4
|
import chalk from 'chalk';
|
|
5
|
+
import execa from 'execa';
|
|
3
6
|
import fse from 'fs-extra';
|
|
4
7
|
import inquirer from 'inquirer';
|
|
5
|
-
import { log } from '../utils/logger';
|
|
6
|
-
import { ExtensionManifest, } from '@directus/shared/types';
|
|
7
|
-
import { isIn, isTypeIn } from '@directus/shared/utils';
|
|
8
|
-
import { pathToRelativeUrl } from '@directus/shared/utils/node';
|
|
9
|
-
import { EXTENSION_LANGUAGES, EXTENSION_NAME_REGEX, EXTENSION_PKG_KEY, EXTENSION_TYPES, HYBRID_EXTENSION_TYPES, } from '@directus/shared/constants';
|
|
10
|
-
import { getLanguageFromPath, isLanguage, languageToShort } from '../utils/languages';
|
|
11
|
-
import getExtensionDevDeps from './helpers/get-extension-dev-deps';
|
|
12
|
-
import execa from 'execa';
|
|
13
8
|
import ora from 'ora';
|
|
14
|
-
import
|
|
15
|
-
import detectJsonIndent from '../utils/detect-json-indent';
|
|
16
|
-
import getPackageManager from '../utils/get-package-manager';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import detectJsonIndent from '../utils/detect-json-indent.js';
|
|
11
|
+
import getPackageManager from '../utils/get-package-manager.js';
|
|
12
|
+
import { getLanguageFromPath, isLanguage, languageToShort } from '../utils/languages.js';
|
|
13
|
+
import { log } from '../utils/logger.js';
|
|
14
|
+
import copyTemplate from './helpers/copy-template.js';
|
|
15
|
+
import getExtensionDevDeps from './helpers/get-extension-dev-deps.js';
|
|
17
16
|
export default async function add() {
|
|
18
|
-
var _a, _b;
|
|
19
17
|
const extensionPath = process.cwd();
|
|
20
18
|
const packagePath = path.resolve('package.json');
|
|
21
19
|
if (!(await fse.pathExists(packagePath))) {
|
|
@@ -63,7 +61,7 @@ export default async function add() {
|
|
|
63
61
|
},
|
|
64
62
|
]);
|
|
65
63
|
const spinner = ora(chalk.bold('Modifying Directus extension...')).start();
|
|
66
|
-
const source = alternativeSource
|
|
64
|
+
const source = alternativeSource ?? 'src';
|
|
67
65
|
const sourcePath = path.resolve(source, name);
|
|
68
66
|
await fse.ensureDir(sourcePath);
|
|
69
67
|
await copyTemplate(type, extensionPath, sourcePath, language);
|
|
@@ -90,7 +88,7 @@ export default async function add() {
|
|
|
90
88
|
[EXTENSION_PKG_KEY]: newExtensionOptions,
|
|
91
89
|
devDependencies: await getExtensionDevDeps(newEntries.map((entry) => entry.type), getLanguageFromEntries(newEntries)),
|
|
92
90
|
};
|
|
93
|
-
await fse.writeJSON(packagePath, newExtensionManifest, { spaces: indent
|
|
91
|
+
await fse.writeJSON(packagePath, newExtensionManifest, { spaces: indent ?? '\t' });
|
|
94
92
|
const packageManager = getPackageManager();
|
|
95
93
|
await execa(packageManager, ['install'], { cwd: extensionPath });
|
|
96
94
|
spinner.succeed(chalk.bold('Done'));
|
|
@@ -107,7 +105,7 @@ export default async function add() {
|
|
|
107
105
|
log(`Extension has not been modified.`, 'info');
|
|
108
106
|
process.exit(1);
|
|
109
107
|
}
|
|
110
|
-
const oldName =
|
|
108
|
+
const oldName = extensionManifest.name.match(EXTENSION_NAME_REGEX)?.[1] ?? extensionManifest.name;
|
|
111
109
|
const { type, name, language, convertName, extensionName, alternativeSource } = await inquirer.prompt([
|
|
112
110
|
{
|
|
113
111
|
type: 'list',
|
|
@@ -149,7 +147,7 @@ export default async function add() {
|
|
|
149
147
|
},
|
|
150
148
|
]);
|
|
151
149
|
const spinner = ora(chalk.bold('Modifying Directus extension...')).start();
|
|
152
|
-
const source = alternativeSource
|
|
150
|
+
const source = alternativeSource ?? 'src';
|
|
153
151
|
const convertSourcePath = path.resolve(source, convertName);
|
|
154
152
|
const entrySourcePath = path.resolve(source, name);
|
|
155
153
|
const convertFiles = await fse.readdir(source);
|
|
@@ -201,7 +199,7 @@ export default async function add() {
|
|
|
201
199
|
[EXTENSION_PKG_KEY]: newExtensionOptions,
|
|
202
200
|
devDependencies: await getExtensionDevDeps(entries.map((entry) => entry.type), getLanguageFromEntries(entries)),
|
|
203
201
|
};
|
|
204
|
-
await fse.writeJSON(packagePath, newExtensionManifest, { spaces: indent
|
|
202
|
+
await fse.writeJSON(packagePath, newExtensionManifest, { spaces: indent ?? '\t' });
|
|
205
203
|
const packageManager = getPackageManager();
|
|
206
204
|
await execa(packageManager, ['install'], { cwd: extensionPath });
|
|
207
205
|
spinner.succeed(chalk.bold('Done'));
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { API_SHARED_DEPS, APP_EXTENSION_TYPES, APP_SHARED_DEPS, EXTENSION_PKG_KEY, EXTENSION_TYPES, HYBRID_EXTENSION_TYPES, } from '@directus/
|
|
2
|
-
import {
|
|
3
|
-
import { isIn, isTypeIn } from '@directus/shared/utils';
|
|
1
|
+
import { API_SHARED_DEPS, APP_EXTENSION_TYPES, APP_SHARED_DEPS, EXTENSION_PKG_KEY, EXTENSION_TYPES, ExtensionManifest, ExtensionOptionsBundleEntries, HYBRID_EXTENSION_TYPES, } from '@directus/constants';
|
|
2
|
+
import { isIn, isTypeIn } from '@directus/utils';
|
|
4
3
|
import commonjs from '@rollup/plugin-commonjs';
|
|
5
4
|
import json from '@rollup/plugin-json';
|
|
6
5
|
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
@@ -15,17 +14,16 @@ import { rollup, watch as rollupWatch, } from 'rollup';
|
|
|
15
14
|
import esbuild from 'rollup-plugin-esbuild';
|
|
16
15
|
import styles from 'rollup-plugin-styles';
|
|
17
16
|
import vue from 'rollup-plugin-vue';
|
|
18
|
-
import { getLanguageFromPath, isLanguage } from '../utils/languages';
|
|
19
|
-
import { clear, log } from '../utils/logger';
|
|
20
|
-
import tryParseJson from '../utils/try-parse-json';
|
|
21
|
-
import generateBundleEntrypoint from './helpers/generate-bundle-entrypoint';
|
|
22
|
-
import loadConfig from './helpers/load-config';
|
|
23
|
-
import { validateSplitEntrypointOption } from './helpers/validate-cli-options';
|
|
17
|
+
import { getLanguageFromPath, isLanguage } from '../utils/languages.js';
|
|
18
|
+
import { clear, log } from '../utils/logger.js';
|
|
19
|
+
import tryParseJson from '../utils/try-parse-json.js';
|
|
20
|
+
import generateBundleEntrypoint from './helpers/generate-bundle-entrypoint.js';
|
|
21
|
+
import loadConfig from './helpers/load-config.js';
|
|
22
|
+
import { validateSplitEntrypointOption } from './helpers/validate-cli-options.js';
|
|
24
23
|
export default async function build(options) {
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const minify = (_c = options.minify) !== null && _c !== void 0 ? _c : false;
|
|
24
|
+
const watch = options.watch ?? false;
|
|
25
|
+
const sourcemap = options.sourcemap ?? false;
|
|
26
|
+
const minify = options.minify ?? false;
|
|
29
27
|
if (!options.type && !options.input && !options.output) {
|
|
30
28
|
const packagePath = path.resolve('package.json');
|
|
31
29
|
if (!(await fse.pathExists(packagePath))) {
|
|
@@ -147,7 +145,6 @@ export default async function build(options) {
|
|
|
147
145
|
}
|
|
148
146
|
}
|
|
149
147
|
async function buildAppOrApiExtension({ type, input, output, watch, sourcemap, minify, }) {
|
|
150
|
-
var _a;
|
|
151
148
|
if (!(await fse.pathExists(input)) || !(await fse.stat(input)).isFile()) {
|
|
152
149
|
log(`Entrypoint ${chalk.bold(input)} does not exist.`, 'error');
|
|
153
150
|
process.exit(1);
|
|
@@ -162,7 +159,7 @@ async function buildAppOrApiExtension({ type, input, output, watch, sourcemap, m
|
|
|
162
159
|
process.exit(1);
|
|
163
160
|
}
|
|
164
161
|
const config = await loadConfig();
|
|
165
|
-
const plugins =
|
|
162
|
+
const plugins = config.plugins ?? [];
|
|
166
163
|
const mode = isIn(type, APP_EXTENSION_TYPES) ? 'browser' : 'node';
|
|
167
164
|
const rollupOptions = getRollupOptions({ mode, input, language, sourcemap, minify, plugins });
|
|
168
165
|
const rollupOutputOptions = getRollupOutputOptions({ mode, output, sourcemap });
|
|
@@ -174,7 +171,6 @@ async function buildAppOrApiExtension({ type, input, output, watch, sourcemap, m
|
|
|
174
171
|
}
|
|
175
172
|
}
|
|
176
173
|
async function buildHybridExtension({ inputApp, inputApi, outputApp, outputApi, watch, sourcemap, minify, }) {
|
|
177
|
-
var _a;
|
|
178
174
|
if (!(await fse.pathExists(inputApp)) || !(await fse.stat(inputApp)).isFile()) {
|
|
179
175
|
log(`App entrypoint ${chalk.bold(inputApp)} does not exist.`, 'error');
|
|
180
176
|
process.exit(1);
|
|
@@ -202,7 +198,7 @@ async function buildHybridExtension({ inputApp, inputApi, outputApp, outputApi,
|
|
|
202
198
|
process.exit(1);
|
|
203
199
|
}
|
|
204
200
|
const config = await loadConfig();
|
|
205
|
-
const plugins =
|
|
201
|
+
const plugins = config.plugins ?? [];
|
|
206
202
|
const rollupOptionsApp = getRollupOptions({
|
|
207
203
|
mode: 'browser',
|
|
208
204
|
input: inputApp,
|
|
@@ -233,7 +229,6 @@ async function buildHybridExtension({ inputApp, inputApi, outputApp, outputApi,
|
|
|
233
229
|
}
|
|
234
230
|
}
|
|
235
231
|
async function buildBundleExtension({ entries, outputApp, outputApi, watch, sourcemap, minify, }) {
|
|
236
|
-
var _a;
|
|
237
232
|
if (outputApp.length === 0) {
|
|
238
233
|
log(`App output file can not be empty.`, 'error');
|
|
239
234
|
process.exit(1);
|
|
@@ -289,7 +284,7 @@ async function buildBundleExtension({ entries, outputApp, outputApi, watch, sour
|
|
|
289
284
|
}
|
|
290
285
|
}
|
|
291
286
|
const config = await loadConfig();
|
|
292
|
-
const plugins =
|
|
287
|
+
const plugins = config.plugins ?? [];
|
|
293
288
|
const entrypointApp = generateBundleEntrypoint('app', entries);
|
|
294
289
|
const entrypointApi = generateBundleEntrypoint('api', entries);
|
|
295
290
|
const rollupOptionsApp = getRollupOptions({
|
|
@@ -390,21 +385,21 @@ function getRollupOptions({ mode, input, language, sourcemap, minify, plugins, }
|
|
|
390
385
|
input: typeof input !== 'string' ? 'entry' : input,
|
|
391
386
|
external: mode === 'browser' ? APP_SHARED_DEPS : API_SHARED_DEPS,
|
|
392
387
|
plugins: [
|
|
393
|
-
typeof input !== 'string' ? virtual(input) : null,
|
|
394
|
-
mode === 'browser' ? vue({ preprocessStyles: true }) : null,
|
|
395
|
-
languages.includes('typescript') ? esbuild({ include: /\.tsx?$/, sourceMap: sourcemap }) : null,
|
|
396
|
-
mode === 'browser' ? styles() : null,
|
|
388
|
+
typeof input !== 'string' ? virtual.default(input) : null,
|
|
389
|
+
mode === 'browser' ? vue.default({ preprocessStyles: true }) : null,
|
|
390
|
+
languages.includes('typescript') ? esbuild.default({ include: /\.tsx?$/, sourceMap: sourcemap }) : null,
|
|
391
|
+
mode === 'browser' ? styles.default() : null,
|
|
397
392
|
...plugins,
|
|
398
393
|
nodeResolve({ browser: mode === 'browser' }),
|
|
399
|
-
commonjs({ esmExternals: mode === 'browser', sourceMap: sourcemap }),
|
|
400
|
-
json(),
|
|
401
|
-
replace({
|
|
394
|
+
commonjs.default({ esmExternals: mode === 'browser', sourceMap: sourcemap }),
|
|
395
|
+
json.default(),
|
|
396
|
+
replace.default({
|
|
402
397
|
values: {
|
|
403
398
|
'process.env.NODE_ENV': JSON.stringify('production'),
|
|
404
399
|
},
|
|
405
400
|
preventAssignment: true,
|
|
406
401
|
}),
|
|
407
|
-
minify ? terser() : null,
|
|
402
|
+
minify ? terser.default() : null,
|
|
408
403
|
],
|
|
409
404
|
};
|
|
410
405
|
}
|
|
@@ -418,14 +413,13 @@ function getRollupOutputOptions({ mode, output, sourcemap, }) {
|
|
|
418
413
|
};
|
|
419
414
|
}
|
|
420
415
|
function formatRollupError(error) {
|
|
421
|
-
var _a;
|
|
422
416
|
let message = '';
|
|
423
417
|
message += `${chalk.bold.red(`[${error.name}]`)} ${error.message}${error.plugin ? ` (plugin ${error.plugin})` : ''}\n`;
|
|
424
418
|
if (error.url) {
|
|
425
419
|
message += '\n' + chalk.green(error.url);
|
|
426
420
|
}
|
|
427
421
|
if (error.loc) {
|
|
428
|
-
message += '\n' + chalk.green(`${
|
|
422
|
+
message += '\n' + chalk.green(`${error.loc.file ?? error.id}:${error.loc.line}:${error.loc.column}`);
|
|
429
423
|
}
|
|
430
424
|
else if (error.id) {
|
|
431
425
|
message += '\n' + chalk.green(error.id);
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { BUNDLE_EXTENSION_TYPES, EXTENSION_LANGUAGES, EXTENSION_NAME_REGEX, EXTENSION_PKG_KEY, EXTENSION_TYPES, HYBRID_EXTENSION_TYPES, } from '@directus/constants';
|
|
2
|
+
import { isIn } from '@directus/utils';
|
|
2
3
|
import chalk from 'chalk';
|
|
3
|
-
import fse from 'fs-extra';
|
|
4
4
|
import execa from 'execa';
|
|
5
|
+
import fse from 'fs-extra';
|
|
5
6
|
import ora from 'ora';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { isLanguage, languageToShort } from '../utils/languages';
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import getPackageManager from '../utils/get-package-manager';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import getPackageManager from '../utils/get-package-manager.js';
|
|
9
|
+
import getSdkVersion from '../utils/get-sdk-version.js';
|
|
10
|
+
import { isLanguage, languageToShort } from '../utils/languages.js';
|
|
11
|
+
import { log } from '../utils/logger.js';
|
|
12
|
+
import copyTemplate from './helpers/copy-template.js';
|
|
13
|
+
import getExtensionDevDeps from './helpers/get-extension-dev-deps.js';
|
|
14
14
|
export default async function create(type, name, options) {
|
|
15
|
-
var _a;
|
|
16
15
|
const targetDir = name.substring(name.lastIndexOf('/') + 1);
|
|
17
16
|
const targetPath = path.resolve(targetDir);
|
|
18
17
|
if (!isIn(type, EXTENSION_TYPES)) {
|
|
@@ -39,7 +38,7 @@ export default async function create(type, name, options) {
|
|
|
39
38
|
await createPackageExtension({ type, name, targetDir, targetPath });
|
|
40
39
|
}
|
|
41
40
|
else {
|
|
42
|
-
const language =
|
|
41
|
+
const language = options.language ?? 'javascript';
|
|
43
42
|
await createLocalExtension({ type, name, targetDir, targetPath, language });
|
|
44
43
|
}
|
|
45
44
|
}
|
|
@@ -101,7 +100,7 @@ function getPackageManifest(name, options, deps) {
|
|
|
101
100
|
devDependencies: deps,
|
|
102
101
|
};
|
|
103
102
|
if (options.type === 'bundle') {
|
|
104
|
-
packageManifest
|
|
103
|
+
packageManifest['scripts']['add'] = 'directus-extension add';
|
|
105
104
|
}
|
|
106
105
|
return packageManifest;
|
|
107
106
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ExtensionType } from '@directus/
|
|
2
|
-
import { Language } from '../../types';
|
|
1
|
+
import type { ExtensionType } from '@directus/types';
|
|
2
|
+
import type { Language } from '../../types.js';
|
|
3
3
|
export default function copyTemplate(type: ExtensionType, extensionPath: string, sourcePath?: string, language?: Language): Promise<void>;
|
|
4
|
-
//# sourceMappingURL=copy-template.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import fse from 'fs-extra';
|
|
3
|
-
import
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import getTemplatePath from '../../utils/get-template-path.js';
|
|
4
4
|
async function copyTemplateFile(templateFile, extensionPath, sourcePath) {
|
|
5
5
|
if (sourcePath !== undefined) {
|
|
6
6
|
const oldName = path.basename(templateFile.path);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { API_EXTENSION_TYPES, APP_EXTENSION_TYPES, HYBRID_EXTENSION_TYPES } from '@directus/constants';
|
|
2
|
+
import { isIn, isTypeIn, pluralize } from '@directus/utils';
|
|
3
|
+
import { pathToRelativeUrl } from '@directus/utils/node';
|
|
1
4
|
import path from 'path';
|
|
2
|
-
import { API_EXTENSION_TYPES, APP_EXTENSION_TYPES, HYBRID_EXTENSION_TYPES } from '@directus/shared/constants';
|
|
3
|
-
import { isIn, isTypeIn, pluralize } from '@directus/shared/utils';
|
|
4
|
-
import { pathToRelativeUrl } from '@directus/shared/utils/node';
|
|
5
5
|
export default function generateBundleEntrypoint(mode, entries) {
|
|
6
6
|
const types = [...(mode === 'app' ? APP_EXTENSION_TYPES : API_EXTENSION_TYPES), ...HYBRID_EXTENSION_TYPES];
|
|
7
7
|
const entriesForTypes = entries.filter((entry) => isIn(entry.type, types));
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ExtensionType } from '@directus/
|
|
2
|
-
import { Language } from '../../types';
|
|
1
|
+
import type { ExtensionType } from '@directus/types';
|
|
2
|
+
import type { Language } from '../../types.js';
|
|
3
3
|
export default function getExtensionDevDeps(type: ExtensionType | ExtensionType[], language?: Language | Language[]): Promise<Record<string, string>>;
|
|
4
|
-
//# sourceMappingURL=get-extension-dev-deps.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isIn } from '@directus/
|
|
3
|
-
import getPackageVersion from '../../utils/get-package-version';
|
|
4
|
-
import getSdkVersion from '../../utils/get-sdk-version';
|
|
1
|
+
import { API_EXTENSION_TYPES, APP_EXTENSION_TYPES, HYBRID_EXTENSION_TYPES } from '@directus/constants';
|
|
2
|
+
import { isIn } from '@directus/utils';
|
|
3
|
+
import getPackageVersion from '../../utils/get-package-version.js';
|
|
4
|
+
import getSdkVersion from '../../utils/get-sdk-version.js';
|
|
5
5
|
export default async function getExtensionDevDeps(type, language = []) {
|
|
6
6
|
const types = Array.isArray(type) ? type : [type];
|
|
7
7
|
const languages = Array.isArray(language) ? language : [language];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { pathToRelativeUrl } from '@directus/utils/node';
|
|
2
2
|
import fse from 'fs-extra';
|
|
3
|
-
import
|
|
3
|
+
import path from 'path';
|
|
4
4
|
const CONFIG_FILE_NAMES = ['extension.config.js', 'extension.config.mjs', 'extension.config.cjs'];
|
|
5
5
|
// This is needed to work around Typescript always transpiling import() to require() for CommonJS targets.
|
|
6
6
|
const _import = new Function('url', 'return import(url)');
|
|
@@ -12,7 +12,7 @@ export function validateSplitEntrypointOption(option) {
|
|
|
12
12
|
if (!validateNonPrimitive(option) || Array.isArray(option)) {
|
|
13
13
|
return false;
|
|
14
14
|
}
|
|
15
|
-
if (!option
|
|
15
|
+
if (!option['app'] || !option['api']) {
|
|
16
16
|
return false;
|
|
17
17
|
}
|
|
18
18
|
return true;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ExtensionManifest } from '@directus/constants';
|
|
2
2
|
import fs from 'fs-extra';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { log } from '../utils/logger.js';
|
|
5
5
|
export default async function link(extensionsPath) {
|
|
6
|
-
var _a;
|
|
7
6
|
const extensionPath = process.cwd();
|
|
8
7
|
const absoluteExtensionsPath = path.resolve(extensionsPath);
|
|
9
8
|
if (!fs.existsSync(absoluteExtensionsPath)) {
|
|
@@ -29,7 +28,7 @@ export default async function link(extensionsPath) {
|
|
|
29
28
|
log(`Extension name not found in package.json`, 'error');
|
|
30
29
|
return;
|
|
31
30
|
}
|
|
32
|
-
const type =
|
|
31
|
+
const type = extensionManifest['directus:extension']?.type;
|
|
33
32
|
if (!type) {
|
|
34
33
|
log(`Extension type not found in package.json`, 'error');
|
|
35
34
|
return;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import link from './commands/link';
|
|
2
|
+
import add from './commands/add.js';
|
|
3
|
+
import build from './commands/build.js';
|
|
4
|
+
import create from './commands/create.js';
|
|
5
|
+
import link from './commands/link.js';
|
|
6
6
|
const pkg = require('../../../package.json');
|
|
7
7
|
const program = new Command();
|
|
8
8
|
program.name('directus-extension').usage('[command] [options]');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EXTENSION_LANGUAGES } from '@directus/
|
|
2
|
-
import { Plugin, RollupOptions, OutputOptions as RollupOutputOptions } from 'rollup';
|
|
1
|
+
import type { EXTENSION_LANGUAGES } from '@directus/constants';
|
|
2
|
+
import type { Plugin, RollupOptions, OutputOptions as RollupOutputOptions } from 'rollup';
|
|
3
3
|
export type Language = (typeof EXTENSION_LANGUAGES)[number];
|
|
4
4
|
export type LanguageShort = 'js' | 'ts';
|
|
5
5
|
export type Config = {
|
|
@@ -10,4 +10,3 @@ export type RollupConfig = {
|
|
|
10
10
|
rollupOutputOptions: RollupOutputOptions;
|
|
11
11
|
};
|
|
12
12
|
export type RollupMode = 'browser' | 'node';
|
|
13
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
export default function detectJsonIndent(json) {
|
|
2
|
-
var _a;
|
|
3
2
|
const lines = json.split(/\r?\n/);
|
|
4
3
|
const braceLine = lines.findIndex((line) => /^(?:\{|\[)/.test(line));
|
|
5
4
|
if (braceLine === -1 || braceLine + 1 > lines.length - 1)
|
|
6
5
|
return null;
|
|
7
|
-
const indent =
|
|
6
|
+
const indent = lines[braceLine + 1].match(/[ \t]+/)?.[0];
|
|
8
7
|
if (indent === undefined)
|
|
9
8
|
return null;
|
|
10
9
|
return indent;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Extract the npm user agent from the npm_config_user_agent environment variable string
|
|
3
3
|
*/
|
|
4
4
|
export default function getPackageManagerAgent() {
|
|
5
|
-
const userAgent = process.env
|
|
5
|
+
const userAgent = process.env['npm_config_user_agent'];
|
|
6
6
|
if (!userAgent)
|
|
7
7
|
return null;
|
|
8
8
|
const values = userAgent.split(' ');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { afterEach, expect, test } from 'vitest';
|
|
2
|
-
import getPackageManagerAgent from './get-package-manager-agent';
|
|
2
|
+
import getPackageManagerAgent from './get-package-manager-agent.js';
|
|
3
3
|
const envCopy = { ...process.env };
|
|
4
4
|
afterEach(() => {
|
|
5
5
|
process.env = envCopy;
|
|
6
6
|
});
|
|
7
7
|
test('Returns null if user agent cannot be extracted from env', () => {
|
|
8
|
-
delete process.env
|
|
8
|
+
delete process.env['npm_config_user_agent'];
|
|
9
9
|
expect(getPackageManagerAgent()).toBe(null);
|
|
10
10
|
});
|
|
11
11
|
test('Returns information object from parsed user agent', () => {
|
|
12
|
-
process.env
|
|
12
|
+
process.env['npm_config_user_agent'] = 'pnpm/7.16.0 npm/? node/v18.12.1 darwin arm64';
|
|
13
13
|
expect(getPackageManagerAgent()).toStrictEqual({
|
|
14
14
|
node: 'v18.12.1',
|
|
15
15
|
npm: '?',
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import getPackageManagerAgent from './get-package-manager-agent';
|
|
1
|
+
import getPackageManagerAgent from './get-package-manager-agent.js';
|
|
2
2
|
/**
|
|
3
3
|
* Determine whether to use pnpm, yarn, or npm based on the parsed package manager agent info
|
|
4
4
|
*/
|
|
5
5
|
export default function getPackageManager() {
|
|
6
6
|
const agent = getPackageManagerAgent();
|
|
7
7
|
if (agent !== null) {
|
|
8
|
-
if ('pnpm' in agent && agent
|
|
8
|
+
if ('pnpm' in agent && agent['pnpm'] !== '?')
|
|
9
9
|
return 'pnpm';
|
|
10
|
-
if ('yarn' in agent && agent
|
|
10
|
+
if ('yarn' in agent && agent['yarn'] !== '?')
|
|
11
11
|
return 'yarn';
|
|
12
12
|
}
|
|
13
13
|
return 'npm';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import getPackageManagerAgent from './get-package-manager-agent';
|
|
3
|
-
import getPackageManager from './get-package-manager';
|
|
1
|
+
import { afterEach, expect, test, vi } from 'vitest';
|
|
2
|
+
import getPackageManagerAgent from './get-package-manager-agent.js';
|
|
3
|
+
import getPackageManager from './get-package-manager.js';
|
|
4
4
|
vi.mock('./get-package-manager-agent');
|
|
5
5
|
afterEach(() => {
|
|
6
6
|
vi.clearAllMocks();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { dirname } from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
const pkg = JSON.parse(readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), '../../../../package.json'), 'utf8'));
|
|
6
|
+
export default function getSdkVersion() {
|
|
7
|
+
return pkg.version;
|
|
8
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Language, LanguageShort } from '../types';
|
|
1
|
+
import type { Language, LanguageShort } from '../types.js';
|
|
2
2
|
export declare function isLanguage(language: string): language is Language;
|
|
3
3
|
export declare function languageToShort(language: Language): LanguageShort;
|
|
4
4
|
export declare function getLanguageFromPath(path: string): string;
|
|
5
|
-
//# sourceMappingURL=languages.d.ts.map
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export { defineInterface, defineDisplay, defineLayout, defineModule, definePanel, defineHook, defineEndpoint, defineOperationApp, defineOperationApi, getFieldsFromTemplate, getRelationType, } from '@directus/
|
|
2
|
-
export { useStores, useApi, useExtensions, useSync, useCollection, useItems, useLayout, useFilterFields, } from '@directus/
|
|
3
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
export { defineInterface, defineDisplay, defineLayout, defineModule, definePanel, defineHook, defineEndpoint, defineOperationApp, defineOperationApi, getFieldsFromTemplate, getRelationType, } from '@directus/utils';
|
|
2
|
+
export { useStores, useApi, useExtensions, useSync, useCollection, useItems, useLayout, useFilterFields, } from '@directus/composables';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { defineInterface, defineDisplay, defineLayout, defineModule, definePanel, defineHook, defineEndpoint, defineOperationApp, defineOperationApi, getFieldsFromTemplate, getRelationType, } from '@directus/
|
|
2
|
-
export { useStores, useApi, useExtensions, useSync, useCollection, useItems, useLayout, useFilterFields, } from '@directus/
|
|
1
|
+
export { defineInterface, defineDisplay, defineLayout, defineModule, definePanel, defineHook, defineEndpoint, defineOperationApp, defineOperationApi, getFieldsFromTemplate, getRelationType, } from '@directus/utils';
|
|
2
|
+
export { useStores, useApi, useExtensions, useSync, useCollection, useItems, useLayout, useFilterFields, } from '@directus/composables';
|