directus-template-cli 0.5.0-beta.1 → 0.5.0-beta.3
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 +11 -4
- package/dist/commands/extract.js +7 -2
- package/dist/lib/extract/extract-fields.js +2 -3
- package/dist/lib/load/index.js +1 -1
- package/dist/lib/load/load-data.js +1 -1
- package/dist/lib/load/load-extensions.js +53 -43
- package/dist/lib/utils/read-file.js +8 -1
- package/oclif.manifest.json +2 -2
- 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() {
|
|
@@ -81,7 +84,9 @@ class ApplyCommand extends core_1.Command {
|
|
|
81
84
|
core_1.ux.log(separator);
|
|
82
85
|
// Get Directus URL and token
|
|
83
86
|
const directusUrl = await (0, auth_1.getDirectusUrl)();
|
|
84
|
-
await (0, auth_1.getDirectusToken)(directusUrl);
|
|
87
|
+
const directusToken = await (0, auth_1.getDirectusToken)(directusUrl);
|
|
88
|
+
flags.directusUrl = directusUrl;
|
|
89
|
+
flags.directusToken = directusToken;
|
|
85
90
|
if (template) {
|
|
86
91
|
core_1.ux.log(`Applying template - ${template.templateName} to ${directusUrl}`);
|
|
87
92
|
await (0, index_js_1.default)(template.directoryPath, validatedFlags);
|
|
@@ -109,7 +114,9 @@ class ApplyCommand extends core_1.Command {
|
|
|
109
114
|
break;
|
|
110
115
|
}
|
|
111
116
|
default: {
|
|
112
|
-
|
|
117
|
+
(0, catch_error_1.default)('Invalid template type. Please check your template type.', {
|
|
118
|
+
fatal: true,
|
|
119
|
+
});
|
|
113
120
|
}
|
|
114
121
|
}
|
|
115
122
|
await this.initializeDirectusApi(validatedFlags);
|
|
@@ -174,7 +181,7 @@ ApplyCommand.description = 'Apply a template to a blank Directus instance.';
|
|
|
174
181
|
ApplyCommand.examples = [
|
|
175
182
|
'$ directus-template-cli apply',
|
|
176
183
|
'$ directus-template-cli apply -p --directusUrl="http://localhost:8055" --directusToken="admin-token-here" --templateLocation="./my-template" --templateType="local"',
|
|
177
|
-
'$ directus-template-cli apply -p --directusUrl="http://localhost:8055" --directusToken="admin-token-here" --templateLocation="./my-template" --templateType="local" --partial --no-content --no-users',
|
|
184
|
+
'$ directus-template-cli@beta apply -p --directusUrl="http://localhost:8055" --directusToken="admin-token-here" --templateLocation="./my-template" --templateType="local" --partial --no-content --no-users',
|
|
178
185
|
];
|
|
179
186
|
ApplyCommand.flags = {
|
|
180
187
|
content: core_1.Flags.boolean({
|
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) {
|
|
@@ -57,7 +60,9 @@ class ExtractCommand extends core_1.Command {
|
|
|
57
60
|
core_1.ux.log(`You selected ${directory}`);
|
|
58
61
|
// Get Directus URL and token
|
|
59
62
|
const directusUrl = await (0, auth_1.getDirectusUrl)();
|
|
60
|
-
await (0, auth_1.getDirectusToken)(directusUrl);
|
|
63
|
+
const directusToken = await (0, auth_1.getDirectusToken)(directusUrl);
|
|
64
|
+
flags.directusUrl = directusUrl;
|
|
65
|
+
flags.directusToken = directusToken;
|
|
61
66
|
await this.extractTemplate(templateName, directory, flags);
|
|
62
67
|
}
|
|
63
68
|
async runProgrammatic(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;
|
package/dist/lib/load/index.js
CHANGED
|
@@ -39,8 +39,8 @@ async function apply(dir, flags) {
|
|
|
39
39
|
await (0, load_users_1.default)(source);
|
|
40
40
|
}
|
|
41
41
|
if (flags.files) {
|
|
42
|
-
await (0, load_files_1.default)(source);
|
|
43
42
|
await (0, load_folders_1.default)(source);
|
|
43
|
+
await (0, load_files_1.default)(source);
|
|
44
44
|
}
|
|
45
45
|
if (flags.content) {
|
|
46
46
|
await (0, load_data_1.default)(source);
|
|
@@ -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
|
}
|
|
@@ -17,54 +17,64 @@ async function installExtension(extension) {
|
|
|
17
17
|
}));
|
|
18
18
|
}
|
|
19
19
|
async function loadExtensions(dir) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
20
|
+
try {
|
|
21
|
+
const extensions = (0, read_file_1.default)('extensions', dir);
|
|
22
|
+
if (extensions && extensions.length > 0) {
|
|
23
|
+
const installedExtensions = await sdk_2.api.client.request((0, sdk_1.readExtensions)());
|
|
24
|
+
const registryExtensions = extensions.filter(ext => { var _a; return ((_a = ext.meta) === null || _a === void 0 ? void 0 : _a.source) === 'registry' && !ext.bundle; });
|
|
25
|
+
const bundles = [...new Set(extensions.filter(ext => ext.bundle).map(ext => ext.bundle))];
|
|
26
|
+
const localExtensions = extensions.filter(ext => { var _a; return ((_a = ext.meta) === null || _a === void 0 ? void 0 : _a.source) === 'local'; });
|
|
27
|
+
const extensionsToInstall = extensions.filter(ext => {
|
|
28
|
+
var _a;
|
|
29
|
+
return ((_a = ext.meta) === null || _a === void 0 ? void 0 : _a.source) === 'registry'
|
|
30
|
+
&& !ext.bundle
|
|
31
|
+
// @ts-expect-error
|
|
32
|
+
&& !installedExtensions.some(installed => installed.id === ext.id);
|
|
33
|
+
});
|
|
34
|
+
core_1.ux.log(`Found ${extensions.length} extensions total: ${registryExtensions.length} registry extensions (including ${bundles.length} bundles), and ${localExtensions.length} local extensions`);
|
|
35
|
+
if (extensionsToInstall.length > 0) {
|
|
36
|
+
core_1.ux.action.start(`Installing ${extensionsToInstall.length} extensions`);
|
|
37
|
+
const results = await Promise.allSettled(extensionsToInstall.map(async (ext) => {
|
|
38
|
+
var _a, _b, _c;
|
|
39
|
+
try {
|
|
40
|
+
await installExtension({
|
|
41
|
+
id: ext.id,
|
|
42
|
+
// The extension version UUID is the folder name
|
|
43
|
+
version: (_a = ext.meta) === null || _a === void 0 ? void 0 : _a.folder,
|
|
44
|
+
});
|
|
45
|
+
return `Installed ${(_b = ext.schema) === null || _b === void 0 ? void 0 : _b.name}`;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
(0, catch_error_1.default)(error);
|
|
49
|
+
return `Failed to install ${(_c = ext.schema) === null || _c === void 0 ? void 0 : _c.name}`;
|
|
50
|
+
}
|
|
51
|
+
}));
|
|
52
|
+
for (const result of results) {
|
|
53
|
+
if (result.status === 'fulfilled') {
|
|
54
|
+
core_1.ux.log(result.value);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
core_1.ux.action.stop();
|
|
58
|
+
core_1.ux.log('Finished installing extensions');
|
|
48
59
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
60
|
+
else {
|
|
61
|
+
// All extensions are already installed
|
|
62
|
+
core_1.ux.log('All extensions are already installed');
|
|
52
63
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (result.status === 'fulfilled') {
|
|
56
|
-
core_1.ux.log(result.value);
|
|
64
|
+
if (localExtensions.length > 0) {
|
|
65
|
+
core_1.ux.log(`Note: ${localExtensions.length} local extensions need to be installed manually.`);
|
|
57
66
|
}
|
|
58
67
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
else {
|
|
63
|
-
// All extensions are already installed
|
|
64
|
-
core_1.ux.log('All extensions are already installed');
|
|
68
|
+
else {
|
|
69
|
+
core_1.ux.log('No extensions found or extensions file is empty. Skipping extension installation.');
|
|
70
|
+
}
|
|
65
71
|
}
|
|
66
|
-
|
|
67
|
-
|
|
72
|
+
catch (error) {
|
|
73
|
+
(0, catch_error_1.default)(error, {
|
|
74
|
+
context: {
|
|
75
|
+
operation: 'loadExtensions',
|
|
76
|
+
},
|
|
77
|
+
});
|
|
68
78
|
}
|
|
69
79
|
}
|
|
70
80
|
exports.default = loadExtensions;
|
|
@@ -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
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"examples": [
|
|
8
8
|
"$ directus-template-cli apply",
|
|
9
9
|
"$ directus-template-cli apply -p --directusUrl=\"http://localhost:8055\" --directusToken=\"admin-token-here\" --templateLocation=\"./my-template\" --templateType=\"local\"",
|
|
10
|
-
"$ directus-template-cli apply -p --directusUrl=\"http://localhost:8055\" --directusToken=\"admin-token-here\" --templateLocation=\"./my-template\" --templateType=\"local\" --partial --no-content --no-users"
|
|
10
|
+
"$ directus-template-cli@beta apply -p --directusUrl=\"http://localhost:8055\" --directusToken=\"admin-token-here\" --templateLocation=\"./my-template\" --templateType=\"local\" --partial --no-content --no-users"
|
|
11
11
|
],
|
|
12
12
|
"flags": {
|
|
13
13
|
"content": {
|
|
@@ -234,5 +234,5 @@
|
|
|
234
234
|
]
|
|
235
235
|
}
|
|
236
236
|
},
|
|
237
|
-
"version": "0.5.0-beta.
|
|
237
|
+
"version": "0.5.0-beta.3"
|
|
238
238
|
}
|