directus-template-cli 0.5.0-beta.2 → 0.5.0-beta.4

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.
@@ -7,6 +7,7 @@ const inquirer = tslib_1.__importStar(require("inquirer"));
7
7
  const index_js_1 = tslib_1.__importDefault(require("../lib/load/index.js"));
8
8
  const sdk_2 = require("../lib/sdk");
9
9
  const auth_1 = require("../lib/utils/auth");
10
+ const catch_error_1 = tslib_1.__importDefault(require("../lib/utils/catch-error"));
10
11
  const get_template_1 = require("../lib/utils/get-template");
11
12
  const open_url_1 = tslib_1.__importDefault(require("../lib/utils/open-url"));
12
13
  const separator = '------------------';
@@ -25,7 +26,9 @@ class ApplyCommand extends core_1.Command {
25
26
  core_1.ux.log(`Logged in as ${response.first_name} ${response.last_name}`);
26
27
  }
27
28
  catch {
28
- throw new Error('Invalid Directus token. Please check your credentials.');
29
+ (0, catch_error_1.default)('Invalid Directus token. Please check your credentials.', {
30
+ fatal: true,
31
+ });
29
32
  }
30
33
  }
31
34
  redirectToDirectusPlus() {
@@ -111,7 +114,9 @@ class ApplyCommand extends core_1.Command {
111
114
  break;
112
115
  }
113
116
  default: {
114
- throw new Error('Invalid template type');
117
+ (0, catch_error_1.default)('Invalid template type. Please check your template type.', {
118
+ fatal: true,
119
+ });
115
120
  }
116
121
  }
117
122
  await this.initializeDirectusApi(validatedFlags);
@@ -9,6 +9,7 @@ const slugify_1 = tslib_1.__importDefault(require("slugify"));
9
9
  const extract_1 = tslib_1.__importDefault(require("../lib/extract/"));
10
10
  const sdk_2 = require("../lib/sdk");
11
11
  const auth_1 = require("../lib/utils/auth");
12
+ const catch_error_1 = tslib_1.__importDefault(require("../lib/utils/catch-error"));
12
13
  const template_defaults_1 = require("../lib/utils/template-defaults");
13
14
  const separator = '------------------';
14
15
  class ExtractCommand extends core_1.Command {
@@ -48,7 +49,9 @@ class ExtractCommand extends core_1.Command {
48
49
  core_1.ux.log(`Logged in as ${response.first_name} ${response.last_name}`);
49
50
  }
50
51
  catch {
51
- throw new Error('Invalid Directus token. Please check your credentials.');
52
+ (0, catch_error_1.default)('Invalid Directus token. Please check your credentials.', {
53
+ fatal: true,
54
+ });
52
55
  }
53
56
  }
54
57
  async runInteractive(flags) {
@@ -4,6 +4,7 @@ const tslib_1 = require("tslib");
4
4
  const sdk_1 = require("@directus/sdk");
5
5
  const core_1 = require("@oclif/core");
6
6
  const sdk_2 = require("../sdk");
7
+ const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
7
8
  const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
8
9
  /**
9
10
  * Extract fields from the Directus instance
@@ -28,9 +29,7 @@ async function extractFields(dir) {
28
29
  core_1.ux.log('Extracted fields');
29
30
  }
30
31
  catch (error) {
31
- core_1.ux.warn('Error extracting Fields:');
32
- core_1.ux.warn(error.message);
33
- console.error(error);
32
+ (0, catch_error_1.default)(error.message);
34
33
  }
35
34
  }
36
35
  exports.default = extractFields;
@@ -95,7 +95,7 @@ async function getCollectionPrimaryKeys(dir) {
95
95
  }
96
96
  function getPrimaryKey(collectionsMap, collection) {
97
97
  if (!collectionsMap[collection]) {
98
- throw new Error(`Collection ${collection} not found in collections map`);
98
+ (0, catch_error_1.default)(`Collection ${collection} not found in collections map`);
99
99
  }
100
100
  return collectionsMap[collection];
101
101
  }
@@ -18,53 +18,54 @@ async function installExtension(extension) {
18
18
  }
19
19
  async function loadExtensions(dir) {
20
20
  const extensions = (0, read_file_1.default)('extensions', dir);
21
- if (!extensions || extensions.length === 0) {
22
- core_1.ux.log('No extensions found');
23
- return;
24
- }
25
- const installedExtensions = await sdk_2.api.client.request((0, sdk_1.readExtensions)());
26
- const registryExtensions = extensions.filter(ext => { var _a; return ((_a = ext.meta) === null || _a === void 0 ? void 0 : _a.source) === 'registry' && !ext.bundle; });
27
- const bundles = [...new Set(extensions.filter(ext => ext.bundle).map(ext => ext.bundle))];
28
- const localExtensions = extensions.filter(ext => { var _a; return ((_a = ext.meta) === null || _a === void 0 ? void 0 : _a.source) === 'local'; });
29
- const extensionsToInstall = extensions.filter(ext => {
30
- var _a;
31
- return ((_a = ext.meta) === null || _a === void 0 ? void 0 : _a.source) === 'registry'
32
- && !ext.bundle
33
- // @ts-expect-error
34
- && !installedExtensions.some(installed => installed.id === ext.id);
35
- });
36
- core_1.ux.log(`Found ${extensions.length} extensions total: ${registryExtensions.length} registry extensions (including ${bundles.length} bundles), and ${localExtensions.length} local extensions`);
37
- if (extensionsToInstall.length > 0) {
38
- core_1.ux.action.start(`Installing ${extensionsToInstall.length} extensions`);
39
- const results = await Promise.allSettled(extensionsToInstall.map(async (ext) => {
40
- var _a, _b, _c;
41
- try {
42
- await installExtension({
43
- id: ext.id,
44
- // The extension version UUID is the folder name
45
- version: (_a = ext.meta) === null || _a === void 0 ? void 0 : _a.folder,
46
- });
47
- return `Installed ${(_b = ext.schema) === null || _b === void 0 ? void 0 : _b.name}`;
48
- }
49
- catch (error) {
50
- (0, catch_error_1.default)(error);
51
- return `Failed to install ${(_c = ext.schema) === null || _c === void 0 ? void 0 : _c.name}`;
52
- }
53
- }));
54
- for (const result of results) {
55
- if (result.status === 'fulfilled') {
56
- core_1.ux.log(result.value);
21
+ if (extensions && extensions.length > 0) {
22
+ const installedExtensions = await sdk_2.api.client.request((0, sdk_1.readExtensions)());
23
+ const registryExtensions = extensions.filter(ext => { var _a; return ((_a = ext.meta) === null || _a === void 0 ? void 0 : _a.source) === 'registry' && !ext.bundle; });
24
+ const bundles = [...new Set(extensions.filter(ext => ext.bundle).map(ext => ext.bundle))];
25
+ const localExtensions = extensions.filter(ext => { var _a; return ((_a = ext.meta) === null || _a === void 0 ? void 0 : _a.source) === 'local'; });
26
+ const extensionsToInstall = extensions.filter(ext => {
27
+ var _a;
28
+ return ((_a = ext.meta) === null || _a === void 0 ? void 0 : _a.source) === 'registry'
29
+ && !ext.bundle
30
+ // @ts-expect-error
31
+ && !installedExtensions.some(installed => installed.id === ext.id);
32
+ });
33
+ core_1.ux.log(`Found ${extensions.length} extensions total: ${registryExtensions.length} registry extensions (including ${bundles.length} bundles), and ${localExtensions.length} local extensions`);
34
+ if (extensionsToInstall.length > 0) {
35
+ core_1.ux.action.start(`Installing ${extensionsToInstall.length} extensions`);
36
+ const results = await Promise.allSettled(extensionsToInstall.map(async (ext) => {
37
+ var _a, _b, _c;
38
+ try {
39
+ await installExtension({
40
+ id: ext.id,
41
+ // The extension version UUID is the folder name
42
+ version: (_a = ext.meta) === null || _a === void 0 ? void 0 : _a.folder,
43
+ });
44
+ return `Installed ${(_b = ext.schema) === null || _b === void 0 ? void 0 : _b.name}`;
45
+ }
46
+ catch (error) {
47
+ (0, catch_error_1.default)(error);
48
+ return `Failed to install ${(_c = ext.schema) === null || _c === void 0 ? void 0 : _c.name}`;
49
+ }
50
+ }));
51
+ for (const result of results) {
52
+ if (result.status === 'fulfilled') {
53
+ core_1.ux.log(result.value);
54
+ }
57
55
  }
56
+ core_1.ux.action.stop();
57
+ core_1.ux.log('Finished installing extensions');
58
+ }
59
+ else {
60
+ // All extensions are already installed
61
+ core_1.ux.log('All extensions are already installed');
62
+ }
63
+ if (localExtensions.length > 0) {
64
+ core_1.ux.log(`Note: ${localExtensions.length} local extensions need to be installed manually.`);
58
65
  }
59
- core_1.ux.action.stop();
60
- core_1.ux.log('Finished installing extensions');
61
66
  }
62
67
  else {
63
- // All extensions are already installed
64
- core_1.ux.log('All extensions are already installed');
65
- }
66
- if (localExtensions.length > 0) {
67
- core_1.ux.log(`Note: ${localExtensions.length} local extensions need to be installed manually.`);
68
+ core_1.ux.log('No extensions found or extensions file is empty. Skipping extension installation.');
68
69
  }
69
70
  }
70
71
  exports.default = loadExtensions;
@@ -32,7 +32,6 @@ async function loadFolders(dir) {
32
32
  const { id, ...rest } = folder;
33
33
  try {
34
34
  await sdk_2.api.client.request((0, sdk_1.updateFolder)(id, rest));
35
- core_1.ux.log(`Updated relationships for folder: ${folder.name}`);
36
35
  }
37
36
  catch (error) {
38
37
  (0, catch_error_1.default)(error);
@@ -3,10 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
5
5
  const node_path_1 = tslib_1.__importDefault(require("node:path"));
6
+ const catch_error_1 = tslib_1.__importDefault(require("./catch-error"));
6
7
  function readFile(file, dir) {
7
8
  const filePath = node_path_1.default.join(dir, `${file}.json`); // Use path.join for proper path resolution
8
9
  if (!node_fs_1.default.existsSync(filePath)) {
9
- throw new Error(`File not found: ${filePath}`); // Improved error handling
10
+ (0, catch_error_1.default)(`File not found: ${filePath}`, {
11
+ context: {
12
+ dir,
13
+ file,
14
+ operation: 'readFile',
15
+ },
16
+ });
10
17
  }
11
18
  const fileContents = node_fs_1.default.readFileSync(filePath, 'utf8');
12
19
  const obj = JSON.parse(fileContents);
@@ -234,5 +234,5 @@
234
234
  ]
235
235
  }
236
236
  },
237
- "version": "0.5.0-beta.2"
237
+ "version": "0.5.0-beta.4"
238
238
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "directus-template-cli",
3
- "version": "0.5.0-beta.2",
3
+ "version": "0.5.0-beta.4",
4
4
  "description": "CLI Utility for applying templates to a Directus instance.",
5
5
  "author": "bryantgillespie @bryantgillespie",
6
6
  "bin": {