directus-template-cli 0.3.0-beta.1 → 0.3.0-beta.2
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 +8 -10
- package/dist/lib/extract/extract-assets.js +1 -1
- package/dist/lib/extract/extract-files.d.ts +4 -0
- package/dist/lib/extract/extract-files.js +48 -0
- package/dist/lib/extract/extract-folders.d.ts +4 -0
- package/dist/lib/extract/extract-folders.js +26 -0
- package/dist/lib/extract/extract-from-endpoint.js +1 -1
- package/dist/lib/extract/extract-roles.d.ts +4 -0
- package/dist/lib/extract/extract-roles.js +36 -0
- package/dist/lib/extract/extract-users.d.ts +4 -0
- package/dist/lib/extract/extract-users.js +49 -0
- package/dist/lib/extract/index.js +13 -5
- package/dist/lib/utils/filter-fields.d.ts +1 -0
- package/dist/lib/utils/filter-fields.js +22 -0
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/dist/commands/apply.js
CHANGED
|
@@ -72,16 +72,14 @@ class ApplyCommand extends core_1.Command {
|
|
|
72
72
|
api_1.api.setAuthToken(directusToken);
|
|
73
73
|
this.log(separator);
|
|
74
74
|
// Check if Directus instance is empty, if not, throw error
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// );
|
|
84
|
-
// }
|
|
75
|
+
const { data } = await api_1.api.get("/collections");
|
|
76
|
+
// Look for collections that don't start with directus_
|
|
77
|
+
const collections = data.data.filter((collection) => {
|
|
78
|
+
return !collection.collection.startsWith("directus_");
|
|
79
|
+
});
|
|
80
|
+
if (collections.length > 0) {
|
|
81
|
+
core_2.ux.error("Directus instance is not empty. Please use a blank instance. Copying a template into an existing instance is not supported at this time.");
|
|
82
|
+
}
|
|
85
83
|
// Run load script
|
|
86
84
|
core_2.ux.action.start(`Applying template - ${chosenTemplate.template.templateName}`);
|
|
87
85
|
await (0, load_1.default)(chosenTemplate.template.directoryPath, this);
|
|
@@ -28,7 +28,7 @@ async function downloadFile(file, dir) {
|
|
|
28
28
|
response.data.pipe(writer);
|
|
29
29
|
return new Promise((resolve, reject) => {
|
|
30
30
|
writer.on("finish", () => {
|
|
31
|
-
console.log(`Wrote ${file.filename_disk}`);
|
|
31
|
+
// console.log(`Wrote ${file.filename_disk}`);
|
|
32
32
|
resolve(null);
|
|
33
33
|
});
|
|
34
34
|
writer.on("error", reject);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const api_1 = require("../api");
|
|
5
|
+
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
6
|
+
const filter_fields_1 = tslib_1.__importDefault(require("../utils/filter-fields"));
|
|
7
|
+
const systemFields = [
|
|
8
|
+
"id",
|
|
9
|
+
"storage",
|
|
10
|
+
"filename_disk",
|
|
11
|
+
"filename_download",
|
|
12
|
+
"title",
|
|
13
|
+
"type",
|
|
14
|
+
"folder",
|
|
15
|
+
"uploaded_by",
|
|
16
|
+
"uploaded_on",
|
|
17
|
+
"modified_by",
|
|
18
|
+
"modified_on",
|
|
19
|
+
"charset",
|
|
20
|
+
"filesize",
|
|
21
|
+
"width",
|
|
22
|
+
"height",
|
|
23
|
+
"duration",
|
|
24
|
+
"embed",
|
|
25
|
+
"description",
|
|
26
|
+
"location",
|
|
27
|
+
"tags",
|
|
28
|
+
"metadata",
|
|
29
|
+
];
|
|
30
|
+
/**
|
|
31
|
+
* Extract files from the API
|
|
32
|
+
*/
|
|
33
|
+
async function extractFiles(dir) {
|
|
34
|
+
try {
|
|
35
|
+
const { data } = await api_1.api.get("/files", {
|
|
36
|
+
params: {
|
|
37
|
+
limit: "-1",
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
const filteredData = (0, filter_fields_1.default)(data.data, systemFields);
|
|
41
|
+
// Use the dynamic dir parameter
|
|
42
|
+
await (0, write_to_file_1.default)("files", filteredData, dir);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.log("Error extracting Files:", error.response.data.errors);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.default = extractFiles;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const api_1 = require("../api");
|
|
5
|
+
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
6
|
+
const filter_fields_1 = tslib_1.__importDefault(require("../utils/filter-fields"));
|
|
7
|
+
const systemFields = ["id", "name", "parent"];
|
|
8
|
+
/**
|
|
9
|
+
* Extract folders from the API
|
|
10
|
+
*/
|
|
11
|
+
async function extractFolders(dir) {
|
|
12
|
+
try {
|
|
13
|
+
const { data } = await api_1.api.get("/folders", {
|
|
14
|
+
params: {
|
|
15
|
+
limit: "-1",
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
const filteredData = (0, filter_fields_1.default)(data.data, systemFields);
|
|
19
|
+
// Use the dynamic dir parameter
|
|
20
|
+
await (0, write_to_file_1.default)("folders", filteredData, dir);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
console.log("Error extracting Folders:", error.response.data.errors);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.default = extractFolders;
|
|
@@ -17,7 +17,7 @@ async function extractFromEndpoint(path, dir) {
|
|
|
17
17
|
await (0, write_to_file_1.default)(`${path}`, data.data, dir);
|
|
18
18
|
}
|
|
19
19
|
catch (error) {
|
|
20
|
-
console.log(`Error querying endpoint ${path}:`, error);
|
|
20
|
+
console.log(`Error querying endpoint ${path}:`, error.response.data.errors);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
exports.default = extractFromEndpoint;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const api_1 = require("../api");
|
|
5
|
+
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
6
|
+
const filter_fields_1 = tslib_1.__importDefault(require("../utils/filter-fields"));
|
|
7
|
+
const systemFields = [
|
|
8
|
+
"id",
|
|
9
|
+
"name",
|
|
10
|
+
"description",
|
|
11
|
+
"icon",
|
|
12
|
+
"enforce_tfa",
|
|
13
|
+
"external_id",
|
|
14
|
+
"ip_whitelist",
|
|
15
|
+
"app_access",
|
|
16
|
+
"admin_access",
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* Extract roles from the API
|
|
20
|
+
*/
|
|
21
|
+
async function extractRoles(dir) {
|
|
22
|
+
try {
|
|
23
|
+
const { data } = await api_1.api.get("/roles", {
|
|
24
|
+
params: {
|
|
25
|
+
limit: "-1",
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
const filteredData = (0, filter_fields_1.default)(data.data, systemFields);
|
|
29
|
+
// Use the dynamic dir parameter
|
|
30
|
+
await (0, write_to_file_1.default)("roles", filteredData, dir);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
console.log("Error extracting Roles:", error.response.data.errors);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.default = extractRoles;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const api_1 = require("../api");
|
|
5
|
+
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
6
|
+
const filter_fields_1 = tslib_1.__importDefault(require("../utils/filter-fields"));
|
|
7
|
+
const systemFields = [
|
|
8
|
+
"id",
|
|
9
|
+
"status",
|
|
10
|
+
"first_name",
|
|
11
|
+
"last_name",
|
|
12
|
+
"email",
|
|
13
|
+
"password",
|
|
14
|
+
"token",
|
|
15
|
+
"last_access",
|
|
16
|
+
"last_page",
|
|
17
|
+
"external_identifier",
|
|
18
|
+
"tfa_secret",
|
|
19
|
+
"auth_data",
|
|
20
|
+
"provider",
|
|
21
|
+
"theme",
|
|
22
|
+
"role",
|
|
23
|
+
"language",
|
|
24
|
+
"avatar",
|
|
25
|
+
"title",
|
|
26
|
+
"description",
|
|
27
|
+
"location",
|
|
28
|
+
"tags",
|
|
29
|
+
"email_notifications",
|
|
30
|
+
];
|
|
31
|
+
/**
|
|
32
|
+
* Extract users from the API
|
|
33
|
+
*/
|
|
34
|
+
async function extractUsers(dir) {
|
|
35
|
+
try {
|
|
36
|
+
const { data } = await api_1.api.get("/users", {
|
|
37
|
+
params: {
|
|
38
|
+
limit: "-1",
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
const filteredData = (0, filter_fields_1.default)(data.data, systemFields);
|
|
42
|
+
// Use the dynamic dir parameter
|
|
43
|
+
await (0, write_to_file_1.default)("users", filteredData, dir);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.log("Error extracting Users:", error.response.data.errors);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.default = extractUsers;
|
|
@@ -7,13 +7,17 @@ const extract_schema_1 = tslib_1.__importDefault(require("./extract-schema"));
|
|
|
7
7
|
const extract_from_endpoint_1 = tslib_1.__importDefault(require("./extract-from-endpoint"));
|
|
8
8
|
const public_permissions_1 = tslib_1.__importDefault(require("./public-permissions"));
|
|
9
9
|
const extract_content_1 = require("./extract-content");
|
|
10
|
+
const extract_folders_1 = tslib_1.__importDefault(require("./extract-folders"));
|
|
11
|
+
const extract_users_1 = tslib_1.__importDefault(require("./extract-users"));
|
|
12
|
+
const extract_roles_1 = tslib_1.__importDefault(require("./extract-roles"));
|
|
13
|
+
const extract_files_1 = tslib_1.__importDefault(require("./extract-files"));
|
|
10
14
|
const endpoints = [
|
|
11
|
-
"folders",
|
|
15
|
+
// "folders",
|
|
16
|
+
// "fields",
|
|
17
|
+
// "users",
|
|
18
|
+
// "roles",
|
|
19
|
+
// "files",
|
|
12
20
|
"operations",
|
|
13
|
-
"fields",
|
|
14
|
-
"users",
|
|
15
|
-
"roles",
|
|
16
|
-
"files",
|
|
17
21
|
"permissions",
|
|
18
22
|
"collections",
|
|
19
23
|
"flows",
|
|
@@ -32,6 +36,10 @@ async function extract(dir, cli) {
|
|
|
32
36
|
}
|
|
33
37
|
// Extract the schema
|
|
34
38
|
await (0, extract_schema_1.default)(destination);
|
|
39
|
+
await (0, extract_folders_1.default)(destination);
|
|
40
|
+
await (0, extract_users_1.default)(destination);
|
|
41
|
+
await (0, extract_roles_1.default)(destination);
|
|
42
|
+
await (0, extract_files_1.default)(destination);
|
|
35
43
|
// Iterate through the endpoints
|
|
36
44
|
for (const endpoint of endpoints) {
|
|
37
45
|
await (0, extract_from_endpoint_1.default)(endpoint, destination);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function filterFields(dataArray: any, systemFields: any): any;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// Utility function to filter out non-system fields
|
|
4
|
+
function filterFields(dataArray, systemFields) {
|
|
5
|
+
return dataArray.map((item) => {
|
|
6
|
+
for (const key of Object.keys(item)) {
|
|
7
|
+
if (!systemFields.includes(key)) {
|
|
8
|
+
const value = item[key];
|
|
9
|
+
if (Array.isArray(value)) {
|
|
10
|
+
const isArrayOfIntegers = value.every((v) => Number.isInteger(v));
|
|
11
|
+
const isArrayOfUUIDs = value.every((v) => typeof v === "string" &&
|
|
12
|
+
/[\dA-Fa-f]{8}(?:-[\dA-Fa-f]{4}){3}-[\dA-Fa-f]{12}/.test(v));
|
|
13
|
+
if (isArrayOfIntegers || isArrayOfUUIDs) {
|
|
14
|
+
item[key] = null; // or item[key] = [];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return item;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.default = filterFields;
|
package/oclif.manifest.json
CHANGED