directus-template-cli 0.4.3 → 0.5.0-beta.10
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.d.ts +23 -1
- package/dist/commands/apply.js +281 -108
- package/dist/commands/extract.d.ts +12 -0
- package/dist/commands/extract.js +85 -17
- package/dist/lib/constants.d.ts +3 -0
- package/dist/lib/constants.js +6 -0
- package/dist/lib/extract/extract-access.d.ts +1 -0
- package/dist/lib/extract/extract-access.js +25 -0
- package/dist/lib/extract/extract-assets.d.ts +257 -25
- package/dist/lib/extract/extract-extensions.d.ts +4 -0
- package/dist/lib/extract/extract-extensions.js +22 -0
- package/dist/lib/extract/extract-fields.js +2 -3
- package/dist/lib/extract/extract-permissions.d.ts +3 -0
- package/dist/lib/extract/extract-permissions.js +11 -4
- package/dist/lib/extract/extract-policies.d.ts +4 -0
- package/dist/lib/extract/extract-policies.js +28 -0
- package/dist/lib/extract/extract-presets.js +1 -1
- package/dist/lib/extract/index.js +6 -0
- package/dist/lib/load/index.d.ts +13 -1
- package/dist/lib/load/index.js +38 -20
- package/dist/lib/load/load-access.d.ts +1 -0
- package/dist/lib/load/load-access.js +60 -0
- package/dist/lib/load/load-collections.js +47 -21
- package/dist/lib/load/load-dashboards.js +32 -11
- package/dist/lib/load/load-data.js +72 -46
- package/dist/lib/load/load-extensions.d.ts +1 -0
- package/dist/lib/load/load-extensions.js +76 -0
- package/dist/lib/load/load-files.d.ts +1 -2
- package/dist/lib/load/load-files.js +52 -24
- package/dist/lib/load/load-flows.d.ts +1 -1
- package/dist/lib/load/load-flows.js +48 -32
- package/dist/lib/load/load-folders.js +32 -11
- package/dist/lib/load/load-permissions.js +15 -12
- package/dist/lib/load/load-policies.d.ts +1 -0
- package/dist/lib/load/load-policies.js +37 -0
- package/dist/lib/load/load-presets.js +26 -10
- package/dist/lib/load/load-relations.js +17 -7
- package/dist/lib/load/load-roles.js +47 -16
- package/dist/lib/load/load-settings.js +44 -4
- package/dist/lib/load/load-translations.js +24 -7
- package/dist/lib/load/load-users.js +28 -5
- package/dist/lib/sdk.d.ts +1 -1
- package/dist/lib/sdk.js +10 -3
- package/dist/lib/types/extension.d.ts +42 -0
- package/dist/lib/types/extension.js +2 -0
- package/dist/lib/utils/auth.js +9 -3
- package/dist/lib/utils/catch-error.d.ts +6 -0
- package/dist/lib/utils/catch-error.js +35 -0
- package/dist/lib/utils/check-template.js +1 -16
- package/dist/lib/utils/chunk-array.d.ts +1 -0
- package/dist/lib/utils/chunk-array.js +7 -0
- package/dist/lib/utils/get-role-ids.d.ts +3 -53
- package/dist/lib/utils/get-role-ids.js +4 -2
- package/dist/lib/utils/get-template.d.ts +9 -0
- package/dist/lib/utils/get-template.js +99 -0
- package/dist/lib/utils/logger.d.ts +12 -0
- package/dist/lib/utils/logger.js +55 -0
- package/dist/lib/utils/read-file.js +2 -1
- package/dist/lib/utils/read-templates.js +4 -2
- package/oclif.manifest.json +192 -5
- package/package.json +4 -5
- package/dist/lib/load/load-schema.d.ts +0 -14
- package/dist/lib/load/load-schema.js +0 -95
- package/dist/lib/utils/log-error.d.ts +0 -14
- package/dist/lib/utils/log-error.js +0 -25
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "directus-template-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0-beta.10",
|
|
4
4
|
"description": "CLI Utility for applying templates to a Directus instance.",
|
|
5
5
|
"author": "bryantgillespie @bryantgillespie",
|
|
6
6
|
"bin": {
|
|
@@ -12,19 +12,18 @@
|
|
|
12
12
|
"repository": "directus-community/directus-template-cli",
|
|
13
13
|
"files": [
|
|
14
14
|
"/bin",
|
|
15
|
-
"/templates",
|
|
16
15
|
"/dist",
|
|
17
16
|
"/npm-shrinkwrap.json",
|
|
18
17
|
"/oclif.manifest.json"
|
|
19
18
|
],
|
|
20
19
|
"dependencies": {
|
|
21
|
-
"@directus/sdk": "^
|
|
22
|
-
"@directus/types": "^
|
|
20
|
+
"@directus/sdk": "^17.0.1",
|
|
21
|
+
"@directus/types": "^12.0.1",
|
|
23
22
|
"@oclif/core": "^3.18.1",
|
|
24
23
|
"@oclif/plugin-help": "^6.0.12",
|
|
25
24
|
"@oclif/plugin-plugins": "^4.1.22",
|
|
26
|
-
"axios": "^1.6.7",
|
|
27
25
|
"bottleneck": "^2.19.5",
|
|
26
|
+
"defu": "^6.1.4",
|
|
28
27
|
"dotenv": "^16.4.1",
|
|
29
28
|
"formdata-node": "^6.0.3",
|
|
30
29
|
"giget": "^1.2.1",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export default function loadSchema(dir: string): Promise<void>;
|
|
2
|
-
/**
|
|
3
|
-
* Indicates the kind of change based on comparisons by deep-diff package
|
|
4
|
-
*/
|
|
5
|
-
export declare const DiffKind: {
|
|
6
|
-
/** indicates a change occurred within an array */
|
|
7
|
-
A: string;
|
|
8
|
-
/** indicates a property/element was deleted */
|
|
9
|
-
D: string;
|
|
10
|
-
/** indicates a property/element was edited */
|
|
11
|
-
E: string;
|
|
12
|
-
/** indicates a newly added property/element */
|
|
13
|
-
N: string;
|
|
14
|
-
};
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DiffKind = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
/* eslint-disable unicorn/no-array-reduce */
|
|
6
|
-
/* eslint-disable perfectionist/sort-objects */
|
|
7
|
-
const sdk_1 = require("@directus/sdk");
|
|
8
|
-
const core_1 = require("@oclif/core");
|
|
9
|
-
const inquirer = tslib_1.__importStar(require("inquirer"));
|
|
10
|
-
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
11
|
-
const sdk_2 = require("../sdk");
|
|
12
|
-
const log_error_1 = tslib_1.__importDefault(require("../utils/log-error"));
|
|
13
|
-
const read_file_1 = tslib_1.__importDefault(require("../utils/read-file"));
|
|
14
|
-
async function loadSchema(dir) {
|
|
15
|
-
let diff;
|
|
16
|
-
try {
|
|
17
|
-
const schemaDir = node_path_1.default.resolve(dir, 'schema');
|
|
18
|
-
const schema = (0, read_file_1.default)('snapshot', schemaDir);
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
diff = await sdk_2.api.client.request((0, sdk_1.schemaDiff)(schema, true));
|
|
21
|
-
if (!diff) {
|
|
22
|
-
core_1.ux.log('No schema to apply');
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const diffKeys = ['collections', 'fields', 'relations'];
|
|
26
|
-
const changes = diffKeys.map(table => {
|
|
27
|
-
const tableDiff = diff.diff[table];
|
|
28
|
-
if (!tableDiff) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const tableChanges = tableDiff.reduce((acc, item) => {
|
|
32
|
-
const { kind } = item.diff[0];
|
|
33
|
-
acc[exports.DiffKind[kind]] = acc[exports.DiffKind[kind]] ? acc[exports.DiffKind[kind]] + 1 : 1;
|
|
34
|
-
return acc;
|
|
35
|
-
}, {});
|
|
36
|
-
return {
|
|
37
|
-
table,
|
|
38
|
-
...tableChanges,
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
// Display the changes to be applied in a table using the ux.table method. The table should have the following columns: Table, New, Edit, Delete
|
|
42
|
-
core_1.ux.log('Schema diff summary from current instance:');
|
|
43
|
-
core_1.ux.table(changes, {
|
|
44
|
-
table: {
|
|
45
|
-
get: (row) => row.table,
|
|
46
|
-
minWidth: 20,
|
|
47
|
-
},
|
|
48
|
-
create: {
|
|
49
|
-
get: (row) => row.new || 0,
|
|
50
|
-
minWidth: 5,
|
|
51
|
-
},
|
|
52
|
-
update: {
|
|
53
|
-
get: (row) => row.edit || 0,
|
|
54
|
-
minWidth: 5,
|
|
55
|
-
},
|
|
56
|
-
delete: {
|
|
57
|
-
get: (row) => row.delete || 0,
|
|
58
|
-
minWidth: 5,
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
(0, log_error_1.default)(error);
|
|
64
|
-
}
|
|
65
|
-
const proceed = await inquirer.prompt([{
|
|
66
|
-
message: 'Applying . This cannot be undone. Continue?',
|
|
67
|
-
name: 'continue',
|
|
68
|
-
type: 'confirm',
|
|
69
|
-
}]);
|
|
70
|
-
if (!proceed.continue) {
|
|
71
|
-
core_1.ux.log('Cancelled applying schema changes and exiting...');
|
|
72
|
-
core_1.ux.exit(0);
|
|
73
|
-
}
|
|
74
|
-
try {
|
|
75
|
-
await sdk_2.api.client.request((0, sdk_1.schemaApply)(diff));
|
|
76
|
-
core_1.ux.log('Loaded schema');
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
(0, log_error_1.default)(error);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
exports.default = loadSchema;
|
|
83
|
-
/**
|
|
84
|
-
* Indicates the kind of change based on comparisons by deep-diff package
|
|
85
|
-
*/
|
|
86
|
-
exports.DiffKind = {
|
|
87
|
-
/** indicates a change occurred within an array */
|
|
88
|
-
A: 'array',
|
|
89
|
-
/** indicates a property/element was deleted */
|
|
90
|
-
D: 'delete',
|
|
91
|
-
/** indicates a property/element was edited */
|
|
92
|
-
E: 'edit',
|
|
93
|
-
/** indicates a newly added property/element */
|
|
94
|
-
N: 'new',
|
|
95
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
interface Error {
|
|
2
|
-
errors: {
|
|
3
|
-
message: string;
|
|
4
|
-
}[];
|
|
5
|
-
response: {
|
|
6
|
-
status: number;
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
interface Options {
|
|
10
|
-
fatal?: boolean;
|
|
11
|
-
logToFile?: boolean;
|
|
12
|
-
}
|
|
13
|
-
export default function logError(error: Error, options?: Options): void;
|
|
14
|
-
export {};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const core_1 = require("@oclif/core");
|
|
5
|
-
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
|
-
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
7
|
-
function logError(error, options = {}) {
|
|
8
|
-
const errorMessage = `Status ${error.response.status} • ${JSON.stringify(error.errors[0].message)}\n`;
|
|
9
|
-
if (options.fatal) {
|
|
10
|
-
core_1.ux.error(errorMessage);
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
core_1.ux.warn(errorMessage);
|
|
14
|
-
}
|
|
15
|
-
if (options.logToFile) {
|
|
16
|
-
const logFilePath = node_path_1.default.join(__dirname, 'error.log');
|
|
17
|
-
try {
|
|
18
|
-
node_fs_1.default.appendFileSync(logFilePath, `${new Date().toISOString()} - ${errorMessage}`);
|
|
19
|
-
}
|
|
20
|
-
catch (fileError) {
|
|
21
|
-
console.error('Error writing to log file:', fileError);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.default = logError;
|