directus-template-cli 0.5.0-beta.9 → 0.5.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/README.md +186 -17
- package/dist/commands/apply.d.ts +25 -3
- package/dist/commands/apply.js +78 -121
- package/dist/commands/extract.d.ts +29 -1
- package/dist/commands/extract.js +72 -50
- package/dist/flags/common.d.ts +7 -0
- package/dist/flags/common.js +41 -0
- package/dist/lib/extract/extract-access.js +5 -3
- package/dist/lib/extract/extract-assets.d.ts +0 -414
- package/dist/lib/extract/extract-assets.js +29 -25
- package/dist/lib/extract/extract-collections.js +5 -4
- package/dist/lib/extract/extract-content.d.ts +0 -2
- package/dist/lib/extract/extract-content.js +16 -15
- package/dist/lib/extract/extract-dashboards.js +8 -6
- package/dist/lib/extract/extract-extensions.js +5 -3
- package/dist/lib/extract/extract-fields.js +4 -2
- package/dist/lib/extract/extract-files.js +5 -3
- package/dist/lib/extract/extract-flows.js +8 -6
- package/dist/lib/extract/extract-folders.js +5 -3
- package/dist/lib/extract/extract-permissions.js +5 -3
- package/dist/lib/extract/extract-policies.js +5 -3
- package/dist/lib/extract/extract-presets.js +5 -3
- package/dist/lib/extract/extract-relations.js +5 -3
- package/dist/lib/extract/extract-roles.js +5 -3
- package/dist/lib/extract/extract-schema.js +6 -8
- package/dist/lib/extract/extract-settings.js +5 -3
- package/dist/lib/extract/extract-translations.js +6 -6
- package/dist/lib/extract/extract-users.js +6 -6
- package/dist/lib/load/apply-flags.d.ts +22 -0
- package/dist/lib/load/apply-flags.js +67 -0
- package/dist/lib/load/index.js +9 -5
- package/dist/lib/load/load-access.js +45 -37
- package/dist/lib/load/load-collections.js +20 -2
- package/dist/lib/load/load-dashboards.js +27 -25
- package/dist/lib/load/load-data.js +3 -3
- package/dist/lib/load/load-files.js +42 -46
- package/dist/lib/load/load-flows.js +27 -30
- package/dist/lib/load/load-folders.js +32 -30
- package/dist/lib/load/load-permissions.js +14 -12
- package/dist/lib/load/load-policies.js +21 -19
- package/dist/lib/load/load-presets.js +25 -23
- package/dist/lib/load/load-relations.js +17 -15
- package/dist/lib/load/load-roles.js +43 -41
- package/dist/lib/load/load-translations.js +22 -20
- package/dist/lib/load/load-users.js +42 -39
- package/dist/lib/load/update-required-fields.d.ts +1 -0
- package/dist/lib/load/update-required-fields.js +24 -0
- package/dist/lib/sdk.d.ts +20 -2
- package/dist/lib/sdk.js +124 -9
- package/dist/lib/utils/auth.d.ts +26 -0
- package/dist/lib/utils/auth.js +48 -4
- package/dist/lib/utils/catch-error.d.ts +15 -2
- package/dist/lib/utils/catch-error.js +31 -25
- package/oclif.manifest.json +74 -28
- package/package.json +2 -2
- package/dist/lib/interfaces.d.ts +0 -8
- package/dist/lib/interfaces.js +0 -2
package/dist/lib/utils/auth.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDirectusToken = exports.getDirectusUrl = void 0;
|
|
3
|
+
exports.validateAuthFlags = exports.initializeDirectusApi = exports.getDirectusToken = exports.getDirectusUrl = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const sdk_1 = require("@directus/sdk");
|
|
6
6
|
const core_1 = require("@oclif/core");
|
|
7
7
|
const sdk_2 = require("../sdk");
|
|
8
8
|
const catch_error_1 = tslib_1.__importDefault(require("./catch-error"));
|
|
9
9
|
const validate_url_1 = tslib_1.__importDefault(require("./validate-url"));
|
|
10
|
+
/**
|
|
11
|
+
* Get the Directus URL from the user
|
|
12
|
+
* @returns The Directus URL
|
|
13
|
+
*/
|
|
10
14
|
async function getDirectusUrl() {
|
|
11
15
|
const directusUrl = await core_1.ux.prompt('What is your Directus URL?', { default: 'http://localhost:8055' });
|
|
12
16
|
// Validate URL
|
|
@@ -18,13 +22,17 @@ async function getDirectusUrl() {
|
|
|
18
22
|
return directusUrl;
|
|
19
23
|
}
|
|
20
24
|
exports.getDirectusUrl = getDirectusUrl;
|
|
25
|
+
/**
|
|
26
|
+
* Get the Directus token from the user
|
|
27
|
+
* @param directusUrl - The Directus URL
|
|
28
|
+
* @returns The Directus token
|
|
29
|
+
*/
|
|
21
30
|
async function getDirectusToken(directusUrl) {
|
|
22
31
|
const directusToken = await core_1.ux.prompt('What is your Directus Admin Token?');
|
|
23
|
-
// Validate token
|
|
32
|
+
// Validate token by fetching the user
|
|
24
33
|
try {
|
|
25
|
-
sdk_2.api.
|
|
34
|
+
await sdk_2.api.loginWithToken(directusToken);
|
|
26
35
|
const response = await sdk_2.api.client.request((0, sdk_1.readMe)());
|
|
27
|
-
core_1.ux.log(`-- Logged in as ${response.first_name} ${response.last_name}`);
|
|
28
36
|
return directusToken;
|
|
29
37
|
}
|
|
30
38
|
catch (error) {
|
|
@@ -39,3 +47,39 @@ async function getDirectusToken(directusUrl) {
|
|
|
39
47
|
}
|
|
40
48
|
}
|
|
41
49
|
exports.getDirectusToken = getDirectusToken;
|
|
50
|
+
/**
|
|
51
|
+
* Initialize the Directus API with the provided flags
|
|
52
|
+
* @param flags - The validated ApplyFlags
|
|
53
|
+
*/
|
|
54
|
+
async function initializeDirectusApi(flags) {
|
|
55
|
+
sdk_2.api.initialize(flags.directusUrl);
|
|
56
|
+
try {
|
|
57
|
+
if (flags.directusToken) {
|
|
58
|
+
await sdk_2.api.loginWithToken(flags.directusToken);
|
|
59
|
+
}
|
|
60
|
+
else if (flags.userEmail && flags.userPassword) {
|
|
61
|
+
await sdk_2.api.login(flags.userEmail, flags.userPassword);
|
|
62
|
+
}
|
|
63
|
+
const response = await sdk_2.api.client.request((0, sdk_1.readMe)());
|
|
64
|
+
core_1.ux.log(`-- Logged in as ${response.first_name} ${response.last_name}`);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
(0, catch_error_1.default)('-- Unable to authenticate with the provided credentials. Please check your credentials.', {
|
|
68
|
+
fatal: true,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.initializeDirectusApi = initializeDirectusApi;
|
|
73
|
+
/**
|
|
74
|
+
* Validate the authentication flags
|
|
75
|
+
* @param flags - The AuthFlags
|
|
76
|
+
*/
|
|
77
|
+
function validateAuthFlags(flags) {
|
|
78
|
+
if (!flags.directusUrl) {
|
|
79
|
+
core_1.ux.error('Directus URL is required.');
|
|
80
|
+
}
|
|
81
|
+
if (!flags.directusToken && (!flags.userEmail || !flags.userPassword)) {
|
|
82
|
+
core_1.ux.error('Either Directus token or email and password are required.');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.validateAuthFlags = validateAuthFlags;
|
|
@@ -1,6 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Options for configuring the error handler behavior.
|
|
3
|
+
*/
|
|
4
|
+
interface ErrorHandlerOptions {
|
|
5
|
+
/** Additional context to be included in the error log. */
|
|
2
6
|
context?: Record<string, any>;
|
|
7
|
+
/** If true, the error will be treated as fatal and the process will exit. */
|
|
3
8
|
fatal?: boolean;
|
|
9
|
+
/** If true, the error will be logged to a file. */
|
|
10
|
+
logToFile?: boolean;
|
|
4
11
|
}
|
|
5
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Handles errors by formatting them and optionally logging to console and file.
|
|
14
|
+
* @param error - The error to be handled.
|
|
15
|
+
* @param options - Configuration options for error handling.
|
|
16
|
+
* @returns void
|
|
17
|
+
*/
|
|
18
|
+
export default function catchError(error: unknown, options?: ErrorHandlerOptions): void;
|
|
6
19
|
export {};
|
|
@@ -1,35 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const core_1 = require("@oclif/core");
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
const sdk_1 = require("../sdk");
|
|
5
|
+
const logger_1 = require("../utils/logger");
|
|
6
|
+
/**
|
|
7
|
+
* Handles errors by formatting them and optionally logging to console and file.
|
|
8
|
+
* @param error - The error to be handled.
|
|
9
|
+
* @param options - Configuration options for error handling.
|
|
10
|
+
* @returns void
|
|
11
|
+
*/
|
|
12
|
+
function catchError(error, options = {}) {
|
|
13
|
+
const { context = {}, fatal = false, logToFile = true } = options;
|
|
14
|
+
let errorMessage;
|
|
15
|
+
if (error instanceof sdk_1.DirectusError) {
|
|
16
|
+
errorMessage = error.message;
|
|
17
|
+
}
|
|
18
|
+
else if (error instanceof Error) {
|
|
19
|
+
errorMessage = `Error: ${error.message}`;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
errorMessage = `Unknown error: ${JSON.stringify(error)}`;
|
|
23
|
+
}
|
|
24
|
+
// Format the error message with context if provided
|
|
13
25
|
const formattedMessage = [
|
|
14
26
|
errorMessage,
|
|
15
|
-
|
|
27
|
+
Object.keys(context).length > 0 && `Context: ${JSON.stringify(context)}`,
|
|
16
28
|
].filter(Boolean).join('\n');
|
|
17
|
-
|
|
29
|
+
// Log the error message to the console with the appropriate color
|
|
30
|
+
if (fatal) {
|
|
31
|
+
// ux.error exits the process with a non-zero code
|
|
32
|
+
core_1.ux.error(formattedMessage);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
core_1.ux.warn(formattedMessage);
|
|
36
|
+
}
|
|
18
37
|
if (logToFile) {
|
|
19
|
-
logger_1.logger.log('error', errorMessage,
|
|
38
|
+
logger_1.logger.log('error', errorMessage, context);
|
|
20
39
|
}
|
|
21
40
|
}
|
|
22
41
|
exports.default = catchError;
|
|
23
|
-
function isDirectusError(error) {
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
return error && Array.isArray(error.errors) && error.errors.length > 0;
|
|
26
|
-
}
|
|
27
|
-
function formatDirectusError(error) {
|
|
28
|
-
var _a;
|
|
29
|
-
const status = ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) || 'Unknown';
|
|
30
|
-
const { extensions, message } = error.errors[0];
|
|
31
|
-
return `Directus Error: ${message.trim()}${extensions ? ` (${JSON.stringify(extensions)})` : ''} (Status: ${status})`;
|
|
32
|
-
}
|
|
33
|
-
function formatGenericError(error) {
|
|
34
|
-
return `Error: ${error.message}`;
|
|
35
|
-
}
|
package/oclif.manifest.json
CHANGED
|
@@ -13,15 +13,6 @@
|
|
|
13
13
|
"content": {
|
|
14
14
|
"description": "Load Content (data)",
|
|
15
15
|
"name": "content",
|
|
16
|
-
"relationships": [
|
|
17
|
-
{
|
|
18
|
-
"flags": [
|
|
19
|
-
"schema",
|
|
20
|
-
"files"
|
|
21
|
-
],
|
|
22
|
-
"type": "all"
|
|
23
|
-
}
|
|
24
|
-
],
|
|
25
16
|
"allowNo": true,
|
|
26
17
|
"type": "boolean"
|
|
27
18
|
},
|
|
@@ -33,15 +24,19 @@
|
|
|
33
24
|
},
|
|
34
25
|
"directusToken": {
|
|
35
26
|
"description": "Token to use for the Directus instance",
|
|
36
|
-
"env": "
|
|
27
|
+
"env": "DIRECTUS_TOKEN",
|
|
28
|
+
"exclusive": [
|
|
29
|
+
"userEmail",
|
|
30
|
+
"userPassword"
|
|
31
|
+
],
|
|
37
32
|
"name": "directusToken",
|
|
38
33
|
"hasDynamicHelp": false,
|
|
39
34
|
"multiple": false,
|
|
40
35
|
"type": "option"
|
|
41
36
|
},
|
|
42
37
|
"directusUrl": {
|
|
43
|
-
"description": "URL of the Directus instance
|
|
44
|
-
"env": "
|
|
38
|
+
"description": "URL of the Directus instance",
|
|
39
|
+
"env": "DIRECTUS_URL",
|
|
45
40
|
"name": "directusUrl",
|
|
46
41
|
"hasDynamicHelp": false,
|
|
47
42
|
"multiple": false,
|
|
@@ -104,10 +99,9 @@
|
|
|
104
99
|
},
|
|
105
100
|
"templateLocation": {
|
|
106
101
|
"dependsOn": [
|
|
107
|
-
"programmatic"
|
|
108
|
-
"templateType"
|
|
102
|
+
"programmatic"
|
|
109
103
|
],
|
|
110
|
-
"description": "Location of the template
|
|
104
|
+
"description": "Location of the template",
|
|
111
105
|
"env": "TEMPLATE_LOCATION",
|
|
112
106
|
"name": "templateLocation",
|
|
113
107
|
"hasDynamicHelp": false,
|
|
@@ -132,17 +126,37 @@
|
|
|
132
126
|
],
|
|
133
127
|
"type": "option"
|
|
134
128
|
},
|
|
129
|
+
"userEmail": {
|
|
130
|
+
"dependsOn": [
|
|
131
|
+
"userPassword"
|
|
132
|
+
],
|
|
133
|
+
"description": "Email for Directus authentication",
|
|
134
|
+
"env": "DIRECTUS_EMAIL",
|
|
135
|
+
"exclusive": [
|
|
136
|
+
"directusToken"
|
|
137
|
+
],
|
|
138
|
+
"name": "userEmail",
|
|
139
|
+
"hasDynamicHelp": false,
|
|
140
|
+
"multiple": false,
|
|
141
|
+
"type": "option"
|
|
142
|
+
},
|
|
143
|
+
"userPassword": {
|
|
144
|
+
"dependsOn": [
|
|
145
|
+
"userEmail"
|
|
146
|
+
],
|
|
147
|
+
"description": "Password for Directus authentication",
|
|
148
|
+
"env": "DIRECTUS_PASSWORD",
|
|
149
|
+
"exclusive": [
|
|
150
|
+
"directusToken"
|
|
151
|
+
],
|
|
152
|
+
"name": "userPassword",
|
|
153
|
+
"hasDynamicHelp": false,
|
|
154
|
+
"multiple": false,
|
|
155
|
+
"type": "option"
|
|
156
|
+
},
|
|
135
157
|
"users": {
|
|
136
158
|
"description": "Load users",
|
|
137
159
|
"name": "users",
|
|
138
|
-
"relationships": [
|
|
139
|
-
{
|
|
140
|
-
"flags": [
|
|
141
|
-
"permissions"
|
|
142
|
-
],
|
|
143
|
-
"type": "all"
|
|
144
|
-
}
|
|
145
|
-
],
|
|
146
160
|
"allowNo": true,
|
|
147
161
|
"type": "boolean"
|
|
148
162
|
}
|
|
@@ -173,15 +187,19 @@
|
|
|
173
187
|
"flags": {
|
|
174
188
|
"directusToken": {
|
|
175
189
|
"description": "Token to use for the Directus instance",
|
|
176
|
-
"env": "
|
|
190
|
+
"env": "DIRECTUS_TOKEN",
|
|
191
|
+
"exclusive": [
|
|
192
|
+
"userEmail",
|
|
193
|
+
"userPassword"
|
|
194
|
+
],
|
|
177
195
|
"name": "directusToken",
|
|
178
196
|
"hasDynamicHelp": false,
|
|
179
197
|
"multiple": false,
|
|
180
198
|
"type": "option"
|
|
181
199
|
},
|
|
182
200
|
"directusUrl": {
|
|
183
|
-
"description": "URL of the Directus instance
|
|
184
|
-
"env": "
|
|
201
|
+
"description": "URL of the Directus instance",
|
|
202
|
+
"env": "DIRECTUS_URL",
|
|
185
203
|
"name": "directusUrl",
|
|
186
204
|
"hasDynamicHelp": false,
|
|
187
205
|
"multiple": false,
|
|
@@ -199,7 +217,7 @@
|
|
|
199
217
|
"dependsOn": [
|
|
200
218
|
"programmatic"
|
|
201
219
|
],
|
|
202
|
-
"description": "
|
|
220
|
+
"description": "Location of the template",
|
|
203
221
|
"env": "TEMPLATE_LOCATION",
|
|
204
222
|
"name": "templateLocation",
|
|
205
223
|
"hasDynamicHelp": false,
|
|
@@ -216,6 +234,34 @@
|
|
|
216
234
|
"hasDynamicHelp": false,
|
|
217
235
|
"multiple": false,
|
|
218
236
|
"type": "option"
|
|
237
|
+
},
|
|
238
|
+
"userEmail": {
|
|
239
|
+
"dependsOn": [
|
|
240
|
+
"userPassword"
|
|
241
|
+
],
|
|
242
|
+
"description": "Email for Directus authentication",
|
|
243
|
+
"env": "DIRECTUS_EMAIL",
|
|
244
|
+
"exclusive": [
|
|
245
|
+
"directusToken"
|
|
246
|
+
],
|
|
247
|
+
"name": "userEmail",
|
|
248
|
+
"hasDynamicHelp": false,
|
|
249
|
+
"multiple": false,
|
|
250
|
+
"type": "option"
|
|
251
|
+
},
|
|
252
|
+
"userPassword": {
|
|
253
|
+
"dependsOn": [
|
|
254
|
+
"userEmail"
|
|
255
|
+
],
|
|
256
|
+
"description": "Password for Directus authentication",
|
|
257
|
+
"env": "DIRECTUS_PASSWORD",
|
|
258
|
+
"exclusive": [
|
|
259
|
+
"directusToken"
|
|
260
|
+
],
|
|
261
|
+
"name": "userPassword",
|
|
262
|
+
"hasDynamicHelp": false,
|
|
263
|
+
"multiple": false,
|
|
264
|
+
"type": "option"
|
|
219
265
|
}
|
|
220
266
|
},
|
|
221
267
|
"hasDynamicHelp": false,
|
|
@@ -234,5 +280,5 @@
|
|
|
234
280
|
]
|
|
235
281
|
}
|
|
236
282
|
},
|
|
237
|
-
"version": "0.5.0
|
|
283
|
+
"version": "0.5.0"
|
|
238
284
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "directus-template-cli",
|
|
3
|
-
"version": "0.5.0
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "CLI Utility for applying templates to a Directus instance.",
|
|
5
5
|
"author": "bryantgillespie @bryantgillespie",
|
|
6
6
|
"bin": {
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@directus/sdk": "^17.0.1",
|
|
21
|
-
"@directus/types": "^12.0.1",
|
|
22
21
|
"@oclif/core": "^3.18.1",
|
|
23
22
|
"@oclif/plugin-help": "^6.0.12",
|
|
24
23
|
"@oclif/plugin-plugins": "^4.1.22",
|
|
@@ -31,6 +30,7 @@
|
|
|
31
30
|
"slugify": "^1.6.6"
|
|
32
31
|
},
|
|
33
32
|
"devDependencies": {
|
|
33
|
+
"@directus/types": "^12.0.1",
|
|
34
34
|
"@oclif/test": "^3.1.13",
|
|
35
35
|
"@types/chai": "^4.3.11",
|
|
36
36
|
"@types/mocha": "^10.0.6",
|
package/dist/lib/interfaces.d.ts
DELETED
package/dist/lib/interfaces.js
DELETED