directus-template-cli 0.5.0-beta.2 → 0.5.0-beta.20
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 +176 -15
- package/dist/commands/apply.d.ts +41 -18
- package/dist/commands/apply.js +113 -122
- package/dist/commands/extract.d.ts +29 -1
- package/dist/commands/extract.js +76 -51
- package/dist/flags/common.d.ts +7 -0
- package/dist/flags/common.js +41 -0
- package/dist/lib/constants.d.ts +3 -0
- package/dist/lib/constants.js +6 -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 +5 -4
- 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 +47 -41
- package/dist/lib/load/load-collections.js +61 -17
- package/dist/lib/load/load-dashboards.js +30 -30
- package/dist/lib/load/load-data.js +47 -11
- package/dist/lib/load/load-extensions.js +49 -43
- package/dist/lib/load/load-files.js +44 -51
- package/dist/lib/load/load-flows.d.ts +1 -1
- package/dist/lib/load/load-flows.js +44 -38
- package/dist/lib/load/load-folders.js +34 -35
- package/dist/lib/load/load-permissions.js +15 -17
- package/dist/lib/load/load-policies.js +23 -21
- package/dist/lib/load/load-presets.js +27 -26
- package/dist/lib/load/load-relations.js +19 -18
- package/dist/lib/load/load-roles.js +45 -45
- package/dist/lib/load/load-settings.js +39 -2
- package/dist/lib/load/load-translations.js +24 -24
- package/dist/lib/load/load-users.js +44 -34
- 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/dist/lib/utils/get-template.d.ts +1 -0
- package/dist/lib/utils/get-template.js +42 -1
- package/dist/lib/utils/read-file.js +2 -1
- package/dist/lib/utils/read-templates.js +4 -2
- 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
|
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const sdk_1 = require("@directus/sdk");
|
|
5
5
|
const core_1 = require("@oclif/core");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
6
7
|
const sdk_2 = require("../sdk");
|
|
8
|
+
const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
|
|
7
9
|
const filter_fields_1 = tslib_1.__importDefault(require("../utils/filter-fields"));
|
|
8
10
|
const system_fields_1 = require("../utils/system-fields");
|
|
9
11
|
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
@@ -11,15 +13,15 @@ const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"
|
|
|
11
13
|
* Extract files from the API
|
|
12
14
|
*/
|
|
13
15
|
async function extractFiles(dir) {
|
|
16
|
+
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, 'Extracting files'));
|
|
14
17
|
try {
|
|
15
18
|
const response = await sdk_2.api.client.request((0, sdk_1.readFiles)({ limit: -1 }));
|
|
16
19
|
const files = (0, filter_fields_1.default)(response, system_fields_1.directusFileFields);
|
|
17
20
|
await (0, write_to_file_1.default)('files', files, dir);
|
|
18
|
-
core_1.ux.log('Extracted files');
|
|
19
21
|
}
|
|
20
22
|
catch (error) {
|
|
21
|
-
|
|
22
|
-
core_1.ux.warn(error.message);
|
|
23
|
+
(0, catch_error_1.default)(error);
|
|
23
24
|
}
|
|
25
|
+
core_1.ux.action.stop();
|
|
24
26
|
}
|
|
25
27
|
exports.default = extractFiles;
|
|
@@ -4,7 +4,9 @@ exports.extractOperations = exports.extractFlows = 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
|
+
const constants_1 = require("../constants");
|
|
7
8
|
const sdk_2 = require("../sdk");
|
|
9
|
+
const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
|
|
8
10
|
const filter_fields_1 = tslib_1.__importDefault(require("../utils/filter-fields"));
|
|
9
11
|
const system_fields_1 = require("../utils/system-fields");
|
|
10
12
|
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
@@ -12,31 +14,31 @@ const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"
|
|
|
12
14
|
* Extract flows from the Directus instance
|
|
13
15
|
*/
|
|
14
16
|
async function extractFlows(dir) {
|
|
17
|
+
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, 'Extracting flows'));
|
|
15
18
|
try {
|
|
16
19
|
const response = await sdk_2.api.client.request((0, sdk_1.readFlows)({ limit: -1 }));
|
|
17
20
|
const flows = (0, filter_fields_1.default)(response, system_fields_1.directusFlowFields);
|
|
18
21
|
await (0, write_to_file_1.default)('flows', flows, dir);
|
|
19
|
-
core_1.ux.log('Extracted flows');
|
|
20
22
|
}
|
|
21
23
|
catch (error) {
|
|
22
|
-
|
|
23
|
-
core_1.ux.warn(error.message);
|
|
24
|
+
(0, catch_error_1.default)(error);
|
|
24
25
|
}
|
|
26
|
+
core_1.ux.action.stop();
|
|
25
27
|
}
|
|
26
28
|
exports.extractFlows = extractFlows;
|
|
27
29
|
/**
|
|
28
30
|
* Extract operations from the Directus instance
|
|
29
31
|
*/
|
|
30
32
|
async function extractOperations(dir) {
|
|
33
|
+
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, 'Extracting operations'));
|
|
31
34
|
try {
|
|
32
35
|
const response = await sdk_2.api.client.request((0, sdk_1.readOperations)({ limit: -1 }));
|
|
33
36
|
const operations = (0, filter_fields_1.default)(response, system_fields_1.directusOperationFields);
|
|
34
37
|
await (0, write_to_file_1.default)('operations', operations, dir);
|
|
35
|
-
core_1.ux.log('Extracted operations');
|
|
36
38
|
}
|
|
37
39
|
catch (error) {
|
|
38
|
-
|
|
39
|
-
core_1.ux.warn(error.message);
|
|
40
|
+
(0, catch_error_1.default)(error);
|
|
40
41
|
}
|
|
42
|
+
core_1.ux.action.stop();
|
|
41
43
|
}
|
|
42
44
|
exports.extractOperations = extractOperations;
|
|
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const sdk_1 = require("@directus/sdk");
|
|
5
5
|
const core_1 = require("@oclif/core");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
6
7
|
const sdk_2 = require("../sdk");
|
|
8
|
+
const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
|
|
7
9
|
const filter_fields_1 = tslib_1.__importDefault(require("../utils/filter-fields"));
|
|
8
10
|
const system_fields_1 = require("../utils/system-fields");
|
|
9
11
|
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
@@ -11,15 +13,15 @@ const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"
|
|
|
11
13
|
* Extract folders from the Directus instance
|
|
12
14
|
*/
|
|
13
15
|
async function extractFolders(dir) {
|
|
16
|
+
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, 'Extracting folders'));
|
|
14
17
|
try {
|
|
15
18
|
const response = await sdk_2.api.client.request((0, sdk_1.readFolders)({ limit: -1 }));
|
|
16
19
|
const folders = (0, filter_fields_1.default)(response, system_fields_1.directusFolderFields);
|
|
17
20
|
await (0, write_to_file_1.default)('folders', folders, dir);
|
|
18
|
-
core_1.ux.log('Extracted folders');
|
|
19
21
|
}
|
|
20
22
|
catch (error) {
|
|
21
|
-
|
|
22
|
-
core_1.ux.warn(error.message);
|
|
23
|
+
(0, catch_error_1.default)(error);
|
|
23
24
|
}
|
|
25
|
+
core_1.ux.action.stop();
|
|
24
26
|
}
|
|
25
27
|
exports.default = extractFolders;
|
|
@@ -3,12 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const sdk_1 = require("@directus/sdk");
|
|
5
5
|
const core_1 = require("@oclif/core");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
6
7
|
const sdk_2 = require("../sdk");
|
|
8
|
+
const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
|
|
7
9
|
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
8
10
|
/**
|
|
9
11
|
* Extract Permissions from the API
|
|
10
12
|
*/
|
|
11
13
|
async function extractPermissions(dir) {
|
|
14
|
+
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, 'Extracting permissions'));
|
|
12
15
|
try {
|
|
13
16
|
let response = await sdk_2.api.client.request((0, sdk_1.readPermissions)({
|
|
14
17
|
limit: -1,
|
|
@@ -22,11 +25,10 @@ async function extractPermissions(dir) {
|
|
|
22
25
|
return i;
|
|
23
26
|
});
|
|
24
27
|
await (0, write_to_file_1.default)('permissions', response, dir);
|
|
25
|
-
core_1.ux.log('Extracted permissions');
|
|
26
28
|
}
|
|
27
29
|
catch (error) {
|
|
28
|
-
|
|
29
|
-
core_1.ux.warn(error.message);
|
|
30
|
+
(0, catch_error_1.default)(error);
|
|
30
31
|
}
|
|
32
|
+
core_1.ux.action.stop();
|
|
31
33
|
}
|
|
32
34
|
exports.default = extractPermissions;
|
|
@@ -3,12 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const sdk_1 = require("@directus/sdk");
|
|
5
5
|
const core_1 = require("@oclif/core");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
6
7
|
const sdk_2 = require("../sdk");
|
|
8
|
+
const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
|
|
7
9
|
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
8
10
|
/**
|
|
9
11
|
* Extract policies from the API
|
|
10
12
|
*/
|
|
11
13
|
async function extractPolicies(dir) {
|
|
14
|
+
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, 'Extracting policies'));
|
|
12
15
|
try {
|
|
13
16
|
const response = await sdk_2.api.client.request((0, sdk_1.readPolicies)({ limit: -1 }));
|
|
14
17
|
// Delete the id field from the permissions so we don't have to reset the autoincrement on the db
|
|
@@ -18,11 +21,10 @@ async function extractPolicies(dir) {
|
|
|
18
21
|
delete policies.permissions; // Alias Field
|
|
19
22
|
}
|
|
20
23
|
await (0, write_to_file_1.default)('policies', response, dir);
|
|
21
|
-
core_1.ux.log('Extracted policies');
|
|
22
24
|
}
|
|
23
25
|
catch (error) {
|
|
24
|
-
|
|
25
|
-
core_1.ux.warn(error.message);
|
|
26
|
+
(0, catch_error_1.default)(error);
|
|
26
27
|
}
|
|
28
|
+
core_1.ux.action.stop();
|
|
27
29
|
}
|
|
28
30
|
exports.default = extractPolicies;
|
|
@@ -3,12 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const sdk_1 = require("@directus/sdk");
|
|
5
5
|
const core_1 = require("@oclif/core");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
6
7
|
const sdk_2 = require("../sdk");
|
|
8
|
+
const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
|
|
7
9
|
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
8
10
|
/**
|
|
9
11
|
* Extract Presets from the API
|
|
10
12
|
*/
|
|
11
13
|
async function extractPresets(dir) {
|
|
14
|
+
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, 'Extracting presets'));
|
|
12
15
|
try {
|
|
13
16
|
const response = await sdk_2.api.client.request((0, sdk_1.readPresets)({
|
|
14
17
|
// Only get the global presets
|
|
@@ -23,11 +26,10 @@ async function extractPresets(dir) {
|
|
|
23
26
|
return preset;
|
|
24
27
|
});
|
|
25
28
|
await (0, write_to_file_1.default)('presets', presets, dir);
|
|
26
|
-
core_1.ux.log('Extracted presets');
|
|
27
29
|
}
|
|
28
30
|
catch (error) {
|
|
29
|
-
|
|
30
|
-
core_1.ux.warn(error.message);
|
|
31
|
+
(0, catch_error_1.default)(error);
|
|
31
32
|
}
|
|
33
|
+
core_1.ux.action.stop();
|
|
32
34
|
}
|
|
33
35
|
exports.default = extractPresets;
|
|
@@ -3,12 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const sdk_1 = require("@directus/sdk");
|
|
5
5
|
const core_1 = require("@oclif/core");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
6
7
|
const sdk_2 = require("../sdk");
|
|
8
|
+
const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
|
|
7
9
|
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
8
10
|
/**
|
|
9
11
|
* Extract relations from the Directus instance
|
|
10
12
|
*/
|
|
11
13
|
async function extractRelations(dir) {
|
|
14
|
+
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, 'Extracting relations'));
|
|
12
15
|
try {
|
|
13
16
|
const response = await sdk_2.api.client.request((0, sdk_1.readRelations)());
|
|
14
17
|
// Fetching fields to filter out system fields while retaining custom fields on system collections
|
|
@@ -23,11 +26,10 @@ async function extractRelations(dir) {
|
|
|
23
26
|
return i;
|
|
24
27
|
});
|
|
25
28
|
await (0, write_to_file_1.default)('relations', relations, dir);
|
|
26
|
-
core_1.ux.log('Extracted relations');
|
|
27
29
|
}
|
|
28
30
|
catch (error) {
|
|
29
|
-
|
|
30
|
-
core_1.ux.warn(error.message);
|
|
31
|
+
(0, catch_error_1.default)(error);
|
|
31
32
|
}
|
|
33
|
+
core_1.ux.action.stop();
|
|
32
34
|
}
|
|
33
35
|
exports.default = extractRelations;
|
|
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const sdk_1 = require("@directus/sdk");
|
|
5
5
|
const core_1 = require("@oclif/core");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
6
7
|
const sdk_2 = require("../sdk");
|
|
8
|
+
const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
|
|
7
9
|
const filter_fields_1 = tslib_1.__importDefault(require("../utils/filter-fields"));
|
|
8
10
|
const system_fields_1 = require("../utils/system-fields");
|
|
9
11
|
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
@@ -11,15 +13,15 @@ const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"
|
|
|
11
13
|
* Extract roles from the API
|
|
12
14
|
*/
|
|
13
15
|
async function extractRoles(dir) {
|
|
16
|
+
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, 'Extracting roles'));
|
|
14
17
|
try {
|
|
15
18
|
const response = await sdk_2.api.client.request((0, sdk_1.readRoles)({ limit: -1 }));
|
|
16
19
|
const roles = (0, filter_fields_1.default)(response, system_fields_1.directusRoleFields);
|
|
17
20
|
await (0, write_to_file_1.default)('roles', roles, dir);
|
|
18
|
-
core_1.ux.log('Extracted roles');
|
|
19
21
|
}
|
|
20
22
|
catch (error) {
|
|
21
|
-
|
|
22
|
-
core_1.ux.warn(error.message);
|
|
23
|
+
(0, catch_error_1.default)(error);
|
|
23
24
|
}
|
|
25
|
+
core_1.ux.action.stop();
|
|
24
26
|
}
|
|
25
27
|
exports.default = extractRoles;
|
|
@@ -5,25 +5,23 @@ const sdk_1 = require("@directus/sdk");
|
|
|
5
5
|
const core_1 = require("@oclif/core");
|
|
6
6
|
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
7
7
|
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
8
|
+
const constants_1 = require("../constants");
|
|
8
9
|
const sdk_2 = require("../sdk");
|
|
10
|
+
const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
|
|
9
11
|
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
10
12
|
async function extractSchema(dir) {
|
|
11
|
-
|
|
12
|
-
// Get the schema
|
|
13
|
+
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, 'Extracting schema snapshot'));
|
|
13
14
|
try {
|
|
14
|
-
|
|
15
|
+
const schemaDir = node_path_1.default.join(dir, 'schema');
|
|
15
16
|
if (!node_fs_1.default.existsSync(schemaDir)) {
|
|
16
|
-
console.log(`Attempting to create directory at: ${schemaDir}`);
|
|
17
17
|
node_fs_1.default.mkdirSync(schemaDir, { recursive: true });
|
|
18
18
|
}
|
|
19
19
|
const schema = await sdk_2.api.client.request((0, sdk_1.schemaSnapshot)());
|
|
20
|
-
// Write the schema to the specified directory
|
|
21
20
|
await (0, write_to_file_1.default)('schema/snapshot', schema, dir);
|
|
22
|
-
core_1.ux.log('Extracted schema snapshot');
|
|
23
21
|
}
|
|
24
22
|
catch (error) {
|
|
25
|
-
|
|
26
|
-
core_1.ux.warn(error.message);
|
|
23
|
+
(0, catch_error_1.default)(error);
|
|
27
24
|
}
|
|
25
|
+
core_1.ux.action.stop();
|
|
28
26
|
}
|
|
29
27
|
exports.default = extractSchema;
|
|
@@ -3,20 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const sdk_1 = require("@directus/sdk");
|
|
5
5
|
const core_1 = require("@oclif/core");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
6
7
|
const sdk_2 = require("../sdk");
|
|
8
|
+
const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
|
|
7
9
|
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
8
10
|
/**
|
|
9
11
|
* Extract settings from the Directus instance
|
|
10
12
|
*/
|
|
11
13
|
async function extractSettings(dir) {
|
|
14
|
+
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, 'Extracting settings'));
|
|
12
15
|
try {
|
|
13
16
|
const settings = await sdk_2.api.client.request((0, sdk_1.readSettings)({ limit: -1 }));
|
|
14
17
|
await (0, write_to_file_1.default)('settings', settings, dir);
|
|
15
|
-
core_1.ux.log('Extracted settings');
|
|
16
18
|
}
|
|
17
19
|
catch (error) {
|
|
18
|
-
|
|
19
|
-
core_1.ux.warn(error.message);
|
|
20
|
+
(0, catch_error_1.default)(error);
|
|
20
21
|
}
|
|
22
|
+
core_1.ux.action.stop();
|
|
21
23
|
}
|
|
22
24
|
exports.default = extractSettings;
|
|
@@ -3,22 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const sdk_1 = require("@directus/sdk");
|
|
5
5
|
const core_1 = require("@oclif/core");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
6
7
|
const sdk_2 = require("../sdk");
|
|
8
|
+
const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
|
|
7
9
|
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
8
10
|
/**
|
|
9
11
|
* Extract translations from the Directus instance
|
|
10
12
|
*/
|
|
11
13
|
async function extractTranslations(dir) {
|
|
14
|
+
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, 'Extracting translations'));
|
|
12
15
|
try {
|
|
13
|
-
const translations = await sdk_2.api.client.request((0, sdk_1.readTranslations)({
|
|
14
|
-
limit: -1,
|
|
15
|
-
}));
|
|
16
|
+
const translations = await sdk_2.api.client.request((0, sdk_1.readTranslations)({ limit: -1 }));
|
|
16
17
|
await (0, write_to_file_1.default)('translations', translations, dir);
|
|
17
|
-
core_1.ux.log('Extracted translations');
|
|
18
18
|
}
|
|
19
19
|
catch (error) {
|
|
20
|
-
|
|
21
|
-
core_1.ux.warn(error.message);
|
|
20
|
+
(0, catch_error_1.default)(error);
|
|
22
21
|
}
|
|
22
|
+
core_1.ux.action.stop();
|
|
23
23
|
}
|
|
24
24
|
exports.default = extractTranslations;
|
|
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const sdk_1 = require("@directus/sdk");
|
|
5
5
|
const core_1 = require("@oclif/core");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
6
7
|
const sdk_2 = require("../sdk");
|
|
8
|
+
const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
|
|
7
9
|
const filter_fields_1 = tslib_1.__importDefault(require("../utils/filter-fields"));
|
|
8
10
|
const system_fields_1 = require("../utils/system-fields");
|
|
9
11
|
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
@@ -11,17 +13,15 @@ const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"
|
|
|
11
13
|
* Extract users from the Directus instance
|
|
12
14
|
*/
|
|
13
15
|
async function extractUsers(dir) {
|
|
16
|
+
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, 'Extracting users'));
|
|
14
17
|
try {
|
|
15
|
-
const response = await sdk_2.api.client.request((0, sdk_1.readUsers)({
|
|
16
|
-
limit: -1,
|
|
17
|
-
}));
|
|
18
|
+
const response = await sdk_2.api.client.request((0, sdk_1.readUsers)({ limit: -1 }));
|
|
18
19
|
const users = (0, filter_fields_1.default)(response, system_fields_1.directusUserFields);
|
|
19
20
|
await (0, write_to_file_1.default)('users', users, dir);
|
|
20
|
-
core_1.ux.log('Extracted users');
|
|
21
21
|
}
|
|
22
22
|
catch (error) {
|
|
23
|
-
|
|
24
|
-
core_1.ux.warn(error.message);
|
|
23
|
+
(0, catch_error_1.default)(error);
|
|
25
24
|
}
|
|
25
|
+
core_1.ux.action.stop();
|
|
26
26
|
}
|
|
27
27
|
exports.default = extractUsers;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface ApplyFlags {
|
|
2
|
+
content: boolean;
|
|
3
|
+
dashboards: boolean;
|
|
4
|
+
directusToken: string;
|
|
5
|
+
directusUrl: string;
|
|
6
|
+
extensions: boolean;
|
|
7
|
+
files: boolean;
|
|
8
|
+
flows: boolean;
|
|
9
|
+
partial: boolean;
|
|
10
|
+
permissions: boolean;
|
|
11
|
+
programmatic: boolean;
|
|
12
|
+
schema: boolean;
|
|
13
|
+
settings: boolean;
|
|
14
|
+
templateLocation: string;
|
|
15
|
+
templateType: 'community' | 'github' | 'local';
|
|
16
|
+
userEmail: string;
|
|
17
|
+
userPassword: string;
|
|
18
|
+
users: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare const loadFlags: readonly ["content", "dashboards", "extensions", "files", "flows", "permissions", "schema", "settings", "users"];
|
|
21
|
+
export declare function validateProgrammaticFlags(flags: ApplyFlags): ApplyFlags;
|
|
22
|
+
export declare function validateInteractiveFlags(flags: ApplyFlags): ApplyFlags;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateInteractiveFlags = exports.validateProgrammaticFlags = exports.loadFlags = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@oclif/core");
|
|
6
|
+
const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
|
|
7
|
+
exports.loadFlags = [
|
|
8
|
+
'content',
|
|
9
|
+
'dashboards',
|
|
10
|
+
'extensions',
|
|
11
|
+
'files',
|
|
12
|
+
'flows',
|
|
13
|
+
'permissions',
|
|
14
|
+
'schema',
|
|
15
|
+
'settings',
|
|
16
|
+
'users',
|
|
17
|
+
];
|
|
18
|
+
function validateProgrammaticFlags(flags) {
|
|
19
|
+
const { directusToken, directusUrl, templateLocation, userEmail, userPassword } = flags;
|
|
20
|
+
if (!directusUrl)
|
|
21
|
+
core_1.ux.error('Directus URL is required for programmatic mode.');
|
|
22
|
+
if (!directusToken && (!userEmail || !userPassword))
|
|
23
|
+
core_1.ux.error('Either Directus token or email and password are required for programmatic mode.');
|
|
24
|
+
if (!templateLocation)
|
|
25
|
+
core_1.ux.error('Template location is required for programmatic mode.');
|
|
26
|
+
return flags.partial ? handlePartialFlags(flags) : setAllFlagsTrue(flags);
|
|
27
|
+
}
|
|
28
|
+
exports.validateProgrammaticFlags = validateProgrammaticFlags;
|
|
29
|
+
function validateInteractiveFlags(flags) {
|
|
30
|
+
return flags.partial ? handlePartialFlags(flags) : setAllFlagsTrue(flags);
|
|
31
|
+
}
|
|
32
|
+
exports.validateInteractiveFlags = validateInteractiveFlags;
|
|
33
|
+
function handlePartialFlags(flags) {
|
|
34
|
+
const enabledFlags = exports.loadFlags.filter(flag => flags[flag] === true);
|
|
35
|
+
const disabledFlags = exports.loadFlags.filter(flag => flags[flag] === false);
|
|
36
|
+
if (enabledFlags.length > 0) {
|
|
37
|
+
for (const flag of exports.loadFlags)
|
|
38
|
+
flags[flag] = enabledFlags.includes(flag);
|
|
39
|
+
}
|
|
40
|
+
else if (disabledFlags.length > 0) {
|
|
41
|
+
for (const flag of exports.loadFlags)
|
|
42
|
+
flags[flag] = !disabledFlags.includes(flag);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
setAllFlagsTrue(flags);
|
|
46
|
+
}
|
|
47
|
+
handleDependencies(flags);
|
|
48
|
+
if (!exports.loadFlags.some(flag => flags[flag])) {
|
|
49
|
+
(0, catch_error_1.default)(new Error('When using --partial, at least one component must be loaded.'), { fatal: true });
|
|
50
|
+
}
|
|
51
|
+
return flags;
|
|
52
|
+
}
|
|
53
|
+
function handleDependencies(flags) {
|
|
54
|
+
if (flags.content && (!flags.schema || !flags.files)) {
|
|
55
|
+
flags.schema = flags.files = true;
|
|
56
|
+
core_1.ux.warn('Content loading requires schema and files. Enabling schema and files flags.');
|
|
57
|
+
}
|
|
58
|
+
if (flags.users && !flags.permissions) {
|
|
59
|
+
flags.permissions = true;
|
|
60
|
+
core_1.ux.warn('User loading requires permissions. Enabling permissions flag.');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function setAllFlagsTrue(flags) {
|
|
64
|
+
for (const flag of exports.loadFlags)
|
|
65
|
+
flags[flag] = true;
|
|
66
|
+
return flags;
|
|
67
|
+
}
|
package/dist/lib/load/index.js
CHANGED
|
@@ -19,6 +19,7 @@ const load_roles_1 = tslib_1.__importDefault(require("./load-roles"));
|
|
|
19
19
|
const load_settings_1 = tslib_1.__importDefault(require("./load-settings"));
|
|
20
20
|
const load_translations_1 = tslib_1.__importDefault(require("./load-translations"));
|
|
21
21
|
const load_users_1 = tslib_1.__importDefault(require("./load-users"));
|
|
22
|
+
const update_required_fields_1 = tslib_1.__importDefault(require("./update-required-fields"));
|
|
22
23
|
async function apply(dir, flags) {
|
|
23
24
|
const source = dir + '/src';
|
|
24
25
|
const isTemplateOk = await (0, check_template_1.default)(source);
|
|
@@ -29,14 +30,14 @@ async function apply(dir, flags) {
|
|
|
29
30
|
await (0, load_collections_1.default)(source);
|
|
30
31
|
await (0, load_relations_1.default)(source);
|
|
31
32
|
}
|
|
32
|
-
if (flags.permissions) {
|
|
33
|
+
if (flags.permissions || flags.users) {
|
|
33
34
|
await (0, load_roles_1.default)(source);
|
|
34
35
|
await (0, load_policies_1.default)(source);
|
|
35
|
-
await (0, load_access_1.default)(source);
|
|
36
36
|
await (0, load_permissions_1.default)(source);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
if (flags.users) {
|
|
38
|
+
await (0, load_users_1.default)(source);
|
|
39
|
+
}
|
|
40
|
+
await (0, load_access_1.default)(source);
|
|
40
41
|
}
|
|
41
42
|
if (flags.files) {
|
|
42
43
|
await (0, load_folders_1.default)(source);
|
|
@@ -45,6 +46,9 @@ async function apply(dir, flags) {
|
|
|
45
46
|
if (flags.content) {
|
|
46
47
|
await (0, load_data_1.default)(source);
|
|
47
48
|
}
|
|
49
|
+
if (flags.schema) {
|
|
50
|
+
await (0, update_required_fields_1.default)(source);
|
|
51
|
+
}
|
|
48
52
|
if (flags.dashboards) {
|
|
49
53
|
await (0, load_dashboards_1.default)(source);
|
|
50
54
|
}
|
|
@@ -2,57 +2,63 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const core_1 = require("@oclif/core");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
5
6
|
const sdk_1 = require("../sdk");
|
|
6
7
|
const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
|
|
8
|
+
const get_role_ids_1 = tslib_1.__importDefault(require("../utils/get-role-ids"));
|
|
7
9
|
const read_file_1 = tslib_1.__importDefault(require("../utils/read-file"));
|
|
8
10
|
async function loadAccess(dir) {
|
|
9
11
|
const access = (0, read_file_1.default)('access', dir);
|
|
10
|
-
core_1.ux.action.start(`Loading ${access.length} accesses`);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Loading ${access.length} accesses`));
|
|
13
|
+
if (access && access.length > 0) {
|
|
14
|
+
// Fetch existing accesses
|
|
15
|
+
const existingAccesses = await sdk_1.api.client.request(() => ({
|
|
16
|
+
method: 'GET',
|
|
17
|
+
params: {
|
|
18
|
+
limit: -1,
|
|
19
|
+
},
|
|
20
|
+
path: '/access',
|
|
21
|
+
}));
|
|
22
|
+
const { legacyAdminRoleId, newAdminRoleId } = await (0, get_role_ids_1.default)(dir);
|
|
23
|
+
const existingAccessById = new Map(existingAccesses.map(acc => [acc.id, acc]));
|
|
24
|
+
const existingAccessByCompositeKey = new Map(existingAccesses.map(acc => [getCompositeKey(acc), acc]));
|
|
25
|
+
for await (const acc of access) {
|
|
26
|
+
try {
|
|
27
|
+
if (existingAccessById.has(acc.id)) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const compositeKey = getCompositeKey(acc);
|
|
31
|
+
if (existingAccessByCompositeKey.has(compositeKey)) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
// If the role is null, delete the role key to avoid errors
|
|
35
|
+
if (acc.role === null) {
|
|
36
|
+
delete acc.role;
|
|
37
|
+
}
|
|
38
|
+
// If the role is the legacy admin role, update it to the new admin role
|
|
39
|
+
if (acc.role === legacyAdminRoleId) {
|
|
40
|
+
acc.role = newAdminRoleId;
|
|
41
|
+
}
|
|
42
|
+
await sdk_1.api.client.request(() => ({
|
|
43
|
+
body: JSON.stringify(acc),
|
|
44
|
+
method: 'POST',
|
|
45
|
+
path: '/access',
|
|
46
|
+
}));
|
|
47
|
+
// Add the new access to our maps
|
|
48
|
+
existingAccessById.set(acc.id, acc);
|
|
49
|
+
existingAccessByCompositeKey.set(compositeKey, acc);
|
|
26
50
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
51
|
+
catch (error) {
|
|
52
|
+
(0, catch_error_1.default)(error, {
|
|
53
|
+
context: {
|
|
54
|
+
access: acc,
|
|
55
|
+
operation: 'createAccess',
|
|
56
|
+
},
|
|
57
|
+
});
|
|
31
58
|
}
|
|
32
|
-
// If the role is null, delete the role key to avoid errors
|
|
33
|
-
if (acc.role === null) {
|
|
34
|
-
delete acc.role;
|
|
35
|
-
}
|
|
36
|
-
await sdk_1.api.client.request(() => ({
|
|
37
|
-
body: JSON.stringify(acc),
|
|
38
|
-
method: 'POST',
|
|
39
|
-
path: '/access',
|
|
40
|
-
}));
|
|
41
|
-
// Add the new access to our maps
|
|
42
|
-
existingAccessById.set(acc.id, acc);
|
|
43
|
-
existingAccessByCompositeKey.set(compositeKey, acc);
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
(0, catch_error_1.default)(error, {
|
|
47
|
-
context: {
|
|
48
|
-
access: acc,
|
|
49
|
-
operation: 'createAccess',
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
59
|
}
|
|
53
60
|
}
|
|
54
61
|
core_1.ux.action.stop();
|
|
55
|
-
core_1.ux.log('Loaded Accesses');
|
|
56
62
|
}
|
|
57
63
|
exports.default = loadAccess;
|
|
58
64
|
// Helper function to generate a composite key for each access
|