@directus/extensions-sdk 9.15.1 → 9.17.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.
@@ -129,7 +129,7 @@ async function buildAppOrApiExtension({ type, input, output, watch, sourcemap, m
129
129
  process.exit(1);
130
130
  }
131
131
  if (output.length === 0) {
132
- (0, logger_1.log)(`Output file ${chalk_1.default.bold(output)} must be a valid path.`, 'error');
132
+ (0, logger_1.log)(`Output file can not be empty.`, 'error');
133
133
  process.exit(1);
134
134
  }
135
135
  const language = (0, languages_1.getLanguageFromPath)(input);
@@ -160,11 +160,11 @@ async function buildHybridExtension({ inputApp, inputApi, outputApp, outputApi,
160
160
  process.exit(1);
161
161
  }
162
162
  if (outputApp.length === 0) {
163
- (0, logger_1.log)(`App output file ${chalk_1.default.bold(outputApp)} must be a valid path.`, 'error');
163
+ (0, logger_1.log)(`App output file can not be empty.`, 'error');
164
164
  process.exit(1);
165
165
  }
166
166
  if (outputApi.length === 0) {
167
- (0, logger_1.log)(`API output file ${chalk_1.default.bold(outputApi)} must be a valid path.`, 'error');
167
+ (0, logger_1.log)(`API output file can not be empty.`, 'error');
168
168
  process.exit(1);
169
169
  }
170
170
  const languageApp = (0, languages_1.getLanguageFromPath)(inputApp);
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/create.ts"],"names":[],"mappings":"AAyBA,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,CAqFtG"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/create.ts"],"names":[],"mappings":"AA0BA,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,CA2FtG"}
@@ -17,20 +17,25 @@ const get_package_version_1 = __importDefault(require("../utils/get-package-vers
17
17
  const pkg = require('../../../../package.json');
18
18
  const TEMPLATE_PATH = path_1.default.resolve(__dirname, '../../../../templates');
19
19
  async function create(type, name, options) {
20
- const targetPath = path_1.default.resolve(name);
20
+ const targetDir = name.substring(name.lastIndexOf('/') + 1);
21
+ const targetPath = path_1.default.resolve(targetDir);
21
22
  if (!(0, utils_1.isIn)(type, constants_1.EXTENSION_TYPES)) {
22
23
  (0, logger_1.log)(`Extension type ${chalk_1.default.bold(type)} is not supported. Available extension types: ${constants_1.EXTENSION_TYPES.map((t) => chalk_1.default.bold.magenta(t)).join(', ')}.`, 'error');
23
24
  process.exit(1);
24
25
  }
26
+ if (targetDir.length === 0) {
27
+ (0, logger_1.log)(`Extension name can not be empty.`, 'error');
28
+ process.exit(1);
29
+ }
25
30
  if (await fs_extra_1.default.pathExists(targetPath)) {
26
31
  const info = await fs_extra_1.default.stat(targetPath);
27
32
  if (!info.isDirectory()) {
28
- (0, logger_1.log)(`Destination ${chalk_1.default.bold(name)} already exists and is not a directory.`, 'error');
33
+ (0, logger_1.log)(`Destination ${chalk_1.default.bold(targetDir)} already exists and is not a directory.`, 'error');
29
34
  process.exit(1);
30
35
  }
31
36
  const files = await fs_extra_1.default.readdir(targetPath);
32
37
  if (files.length > 0) {
33
- (0, logger_1.log)(`Destination ${chalk_1.default.bold(name)} already exists and is not empty.`, 'error');
38
+ (0, logger_1.log)(`Destination ${chalk_1.default.bold(targetDir)} already exists and is not empty.`, 'error');
34
39
  process.exit(1);
35
40
  }
36
41
  }
@@ -48,7 +53,7 @@ async function create(type, name, options) {
48
53
  ? { app: `src/app.${(0, languages_1.languageToShort)(options.language)}`, api: `src/api.${(0, languages_1.languageToShort)(options.language)}` }
49
54
  : `src/index.${(0, languages_1.languageToShort)(options.language)}`;
50
55
  const packageManifest = {
51
- name: `directus-extension-${name}`,
56
+ name: constants_1.EXTENSION_NAME_REGEX.test(name) ? name : `directus-extension-${name}`,
52
57
  version: '1.0.0',
53
58
  keywords: ['directus', 'directus-extension', `directus-custom-${type}`],
54
59
  [constants_1.EXTENSION_PKG_KEY]: {
@@ -70,7 +75,7 @@ async function create(type, name, options) {
70
75
  Your ${type} extension has been created at ${chalk_1.default.green(targetPath)}
71
76
 
72
77
  To start developing, run:
73
- ${chalk_1.default.blue('cd')} ${name}
78
+ ${chalk_1.default.blue('cd')} ${targetDir}
74
79
  ${chalk_1.default.blue('npm run')} dev
75
80
 
76
81
  and then to build for production, run:
@@ -123,7 +123,7 @@ async function buildAppOrApiExtension({ type, input, output, watch, sourcemap, m
123
123
  process.exit(1);
124
124
  }
125
125
  if (output.length === 0) {
126
- log(`Output file ${chalk.bold(output)} must be a valid path.`, 'error');
126
+ log(`Output file can not be empty.`, 'error');
127
127
  process.exit(1);
128
128
  }
129
129
  const language = getLanguageFromPath(input);
@@ -154,11 +154,11 @@ async function buildHybridExtension({ inputApp, inputApi, outputApp, outputApi,
154
154
  process.exit(1);
155
155
  }
156
156
  if (outputApp.length === 0) {
157
- log(`App output file ${chalk.bold(outputApp)} must be a valid path.`, 'error');
157
+ log(`App output file can not be empty.`, 'error');
158
158
  process.exit(1);
159
159
  }
160
160
  if (outputApi.length === 0) {
161
- log(`API output file ${chalk.bold(outputApi)} must be a valid path.`, 'error');
161
+ log(`API output file can not be empty.`, 'error');
162
162
  process.exit(1);
163
163
  }
164
164
  const languageApp = getLanguageFromPath(inputApp);
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/create.ts"],"names":[],"mappings":"AAyBA,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,CAqFtG"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/create.ts"],"names":[],"mappings":"AA0BA,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,CA2FtG"}
@@ -3,7 +3,7 @@ import chalk from 'chalk';
3
3
  import fse from 'fs-extra';
4
4
  import execa from 'execa';
5
5
  import ora from 'ora';
6
- import { EXTENSION_TYPES, EXTENSION_PKG_KEY, EXTENSION_LANGUAGES, HYBRID_EXTENSION_TYPES, API_OR_HYBRID_EXTENSION_TYPES, APP_OR_HYBRID_EXTENSION_TYPES, } from '@directus/shared/constants';
6
+ import { EXTENSION_TYPES, EXTENSION_PKG_KEY, EXTENSION_LANGUAGES, HYBRID_EXTENSION_TYPES, API_OR_HYBRID_EXTENSION_TYPES, APP_OR_HYBRID_EXTENSION_TYPES, EXTENSION_NAME_REGEX, } from '@directus/shared/constants';
7
7
  import { isIn } from '@directus/shared/utils';
8
8
  import { log } from '../utils/logger';
9
9
  import { isLanguage, languageToShort } from '../utils/languages';
@@ -12,20 +12,25 @@ import getPackageVersion from '../utils/get-package-version';
12
12
  const pkg = require('../../../../package.json');
13
13
  const TEMPLATE_PATH = path.resolve(__dirname, '../../../../templates');
14
14
  export default async function create(type, name, options) {
15
- const targetPath = path.resolve(name);
15
+ const targetDir = name.substring(name.lastIndexOf('/') + 1);
16
+ const targetPath = path.resolve(targetDir);
16
17
  if (!isIn(type, EXTENSION_TYPES)) {
17
18
  log(`Extension type ${chalk.bold(type)} is not supported. Available extension types: ${EXTENSION_TYPES.map((t) => chalk.bold.magenta(t)).join(', ')}.`, 'error');
18
19
  process.exit(1);
19
20
  }
21
+ if (targetDir.length === 0) {
22
+ log(`Extension name can not be empty.`, 'error');
23
+ process.exit(1);
24
+ }
20
25
  if (await fse.pathExists(targetPath)) {
21
26
  const info = await fse.stat(targetPath);
22
27
  if (!info.isDirectory()) {
23
- log(`Destination ${chalk.bold(name)} already exists and is not a directory.`, 'error');
28
+ log(`Destination ${chalk.bold(targetDir)} already exists and is not a directory.`, 'error');
24
29
  process.exit(1);
25
30
  }
26
31
  const files = await fse.readdir(targetPath);
27
32
  if (files.length > 0) {
28
- log(`Destination ${chalk.bold(name)} already exists and is not empty.`, 'error');
33
+ log(`Destination ${chalk.bold(targetDir)} already exists and is not empty.`, 'error');
29
34
  process.exit(1);
30
35
  }
31
36
  }
@@ -43,7 +48,7 @@ export default async function create(type, name, options) {
43
48
  ? { app: `src/app.${languageToShort(options.language)}`, api: `src/api.${languageToShort(options.language)}` }
44
49
  : `src/index.${languageToShort(options.language)}`;
45
50
  const packageManifest = {
46
- name: `directus-extension-${name}`,
51
+ name: EXTENSION_NAME_REGEX.test(name) ? name : `directus-extension-${name}`,
47
52
  version: '1.0.0',
48
53
  keywords: ['directus', 'directus-extension', `directus-custom-${type}`],
49
54
  [EXTENSION_PKG_KEY]: {
@@ -65,7 +70,7 @@ export default async function create(type, name, options) {
65
70
  Your ${type} extension has been created at ${chalk.green(targetPath)}
66
71
 
67
72
  To start developing, run:
68
- ${chalk.blue('cd')} ${name}
73
+ ${chalk.blue('cd')} ${targetDir}
69
74
  ${chalk.blue('npm run')} dev
70
75
 
71
76
  and then to build for production, run:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@directus/extensions-sdk",
3
- "version": "9.15.1",
3
+ "version": "9.17.0",
4
4
  "description": "A toolkit to develop extensions to extend Directus.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "repository": "directus/directus",
@@ -25,7 +25,7 @@
25
25
  "author": "Nicola Krumschmidt",
26
26
  "gitHead": "24621f3934dc77eb23441331040ed13c676ceffd",
27
27
  "dependencies": {
28
- "@directus/shared": "9.15.1",
28
+ "@directus/shared": "9.17.0",
29
29
  "@rollup/plugin-commonjs": "^21.0.1",
30
30
  "@rollup/plugin-json": "^4.1.0",
31
31
  "@rollup/plugin-node-resolve": "^13.1.3",
@@ -190,7 +190,7 @@ async function buildAppOrApiExtension({
190
190
  }
191
191
 
192
192
  if (output.length === 0) {
193
- log(`Output file ${chalk.bold(output)} must be a valid path.`, 'error');
193
+ log(`Output file can not be empty.`, 'error');
194
194
  process.exit(1);
195
195
  }
196
196
 
@@ -243,11 +243,11 @@ async function buildHybridExtension({
243
243
  }
244
244
 
245
245
  if (outputApp.length === 0) {
246
- log(`App output file ${chalk.bold(outputApp)} must be a valid path.`, 'error');
246
+ log(`App output file can not be empty.`, 'error');
247
247
  process.exit(1);
248
248
  }
249
249
  if (outputApi.length === 0) {
250
- log(`API output file ${chalk.bold(outputApi)} must be a valid path.`, 'error');
250
+ log(`API output file can not be empty.`, 'error');
251
251
  process.exit(1);
252
252
  }
253
253
 
@@ -10,6 +10,7 @@ import {
10
10
  HYBRID_EXTENSION_TYPES,
11
11
  API_OR_HYBRID_EXTENSION_TYPES,
12
12
  APP_OR_HYBRID_EXTENSION_TYPES,
13
+ EXTENSION_NAME_REGEX,
13
14
  } from '@directus/shared/constants';
14
15
  import { isIn } from '@directus/shared/utils';
15
16
  import { ExtensionType } from '@directus/shared/types';
@@ -26,7 +27,8 @@ const TEMPLATE_PATH = path.resolve(__dirname, '../../../../templates');
26
27
  type CreateOptions = { language: string };
27
28
 
28
29
  export default async function create(type: string, name: string, options: CreateOptions): Promise<void> {
29
- const targetPath = path.resolve(name);
30
+ const targetDir = name.substring(name.lastIndexOf('/') + 1);
31
+ const targetPath = path.resolve(targetDir);
30
32
 
31
33
  if (!isIn(type, EXTENSION_TYPES)) {
32
34
  log(
@@ -38,18 +40,23 @@ export default async function create(type: string, name: string, options: Create
38
40
  process.exit(1);
39
41
  }
40
42
 
43
+ if (targetDir.length === 0) {
44
+ log(`Extension name can not be empty.`, 'error');
45
+ process.exit(1);
46
+ }
47
+
41
48
  if (await fse.pathExists(targetPath)) {
42
49
  const info = await fse.stat(targetPath);
43
50
 
44
51
  if (!info.isDirectory()) {
45
- log(`Destination ${chalk.bold(name)} already exists and is not a directory.`, 'error');
52
+ log(`Destination ${chalk.bold(targetDir)} already exists and is not a directory.`, 'error');
46
53
  process.exit(1);
47
54
  }
48
55
 
49
56
  const files = await fse.readdir(targetPath);
50
57
 
51
58
  if (files.length > 0) {
52
- log(`Destination ${chalk.bold(name)} already exists and is not empty.`, 'error');
59
+ log(`Destination ${chalk.bold(targetDir)} already exists and is not empty.`, 'error');
53
60
  process.exit(1);
54
61
  }
55
62
  }
@@ -78,7 +85,7 @@ export default async function create(type: string, name: string, options: Create
78
85
  : `src/index.${languageToShort(options.language)}`;
79
86
 
80
87
  const packageManifest = {
81
- name: `directus-extension-${name}`,
88
+ name: EXTENSION_NAME_REGEX.test(name) ? name : `directus-extension-${name}`,
82
89
  version: '1.0.0',
83
90
  keywords: ['directus', 'directus-extension', `directus-custom-${type}`],
84
91
  [EXTENSION_PKG_KEY]: {
@@ -104,7 +111,7 @@ export default async function create(type: string, name: string, options: Create
104
111
  Your ${type} extension has been created at ${chalk.green(targetPath)}
105
112
 
106
113
  To start developing, run:
107
- ${chalk.blue('cd')} ${name}
114
+ ${chalk.blue('cd')} ${targetDir}
108
115
  ${chalk.blue('npm run')} dev
109
116
 
110
117
  and then to build for production, run: