create-directus-extension 12.0.0 → 12.1.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/lib/index.js +33 -3
- package/package.json +4 -3
- package/readme.md +20 -0
package/lib/index.js
CHANGED
|
@@ -3,17 +3,47 @@
|
|
|
3
3
|
|
|
4
4
|
import { BUNDLE_EXTENSION_TYPES, EXTENSION_LANGUAGES, EXTENSION_TYPES } from '@directus/extensions';
|
|
5
5
|
import { create } from '@directus/extensions-sdk/cli';
|
|
6
|
+
import { Command } from 'commander';
|
|
6
7
|
import inquirer from 'inquirer';
|
|
7
8
|
|
|
8
9
|
if (process.env.NODE_ENV !== 'test') {
|
|
9
10
|
run();
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export async function run() {
|
|
13
|
+
export async function run(argv = process.argv) {
|
|
14
|
+
const program = new Command('create-directus-extension')
|
|
15
|
+
.description('Scaffold a Directus extension')
|
|
16
|
+
.argument('[type]', 'extension type')
|
|
17
|
+
.argument('[name]', 'extension name (required when type is provided)')
|
|
18
|
+
.option('-l, --language <language>', 'specify the language to use')
|
|
19
|
+
.option('--no-install', 'skip dependency installation after creating extension');
|
|
20
|
+
|
|
21
|
+
program.parse(argv);
|
|
22
|
+
|
|
23
|
+
const options = program.opts();
|
|
24
|
+
const [type, name] = program.args;
|
|
25
|
+
|
|
26
|
+
if (type) {
|
|
27
|
+
// Both arguments are required for non-interactive mode.
|
|
28
|
+
if (!name) {
|
|
29
|
+
program.error('Missing required argument "name". Run without arguments for interactive mode.');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let language;
|
|
34
|
+
|
|
35
|
+
if (BUNDLE_EXTENSION_TYPES.includes(type) === false) {
|
|
36
|
+
language = options.language ?? 'javascript';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
await create(type, name, { language, install: options.install });
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
13
43
|
// eslint-disable-next-line no-console
|
|
14
44
|
console.log('This utility will walk you through creating a Directus extension.\n');
|
|
15
45
|
|
|
16
|
-
const
|
|
46
|
+
const answers = await inquirer.prompt([
|
|
17
47
|
{
|
|
18
48
|
type: 'list',
|
|
19
49
|
name: 'type',
|
|
@@ -40,5 +70,5 @@ export async function run() {
|
|
|
40
70
|
},
|
|
41
71
|
]);
|
|
42
72
|
|
|
43
|
-
await create(type, name, { language, install });
|
|
73
|
+
await create(answers.type, answers.name, { language: answers.language, install: answers.install });
|
|
44
74
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-directus-extension",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.1.0",
|
|
4
4
|
"description": "A small util that will scaffold a Directus extension",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"directus",
|
|
@@ -33,9 +33,10 @@
|
|
|
33
33
|
"lib/index.js"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"commander": "14.0.2",
|
|
36
37
|
"inquirer": "12.11.0",
|
|
37
|
-
"@directus/extensions": "
|
|
38
|
-
"@directus/extensions
|
|
38
|
+
"@directus/extensions-sdk": "18.0.0",
|
|
39
|
+
"@directus/extensions": "4.0.0"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@vitest/coverage-v8": "3.2.6",
|
package/readme.md
CHANGED
|
@@ -13,3 +13,23 @@ npx create-directus-extension
|
|
|
13
13
|
```
|
|
14
14
|
yarn create directus-extension
|
|
15
15
|
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Run without arguments to create an extension interactively:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
npx create-directus-extension
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Pass the extension type and name to create an extension non-interactively:
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
npx create-directus-extension interface my-interface
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
You can also use the `--language` and `--no-install` options:
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
npx create-directus-extension hook my-hook --language typescript --no-install
|
|
35
|
+
```
|