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.
- package/dist/commands/apply.js +7 -2
- package/dist/commands/extract.js +4 -1
- package/dist/lib/extract/extract-fields.js +2 -3
- package/dist/lib/load/load-data.js +1 -1
- package/dist/lib/load/load-extensions.js +44 -43
- package/dist/lib/load/load-folders.js +0 -1
- package/dist/lib/utils/read-file.js +8 -1
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/dist/commands/apply.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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);
|
package/dist/commands/extract.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
22
|
-
|
|
23
|
-
return;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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);
|
package/oclif.manifest.json
CHANGED