directus-template-cli 0.5.0-beta.15 → 0.5.0-beta.17
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/lib/extract/extract-assets.js +11 -5
- package/dist/lib/load/index.js +4 -0
- package/dist/lib/load/load-collections.js +8 -1
- package/dist/lib/load/load-files.js +0 -6
- package/dist/lib/load/load-users.js +0 -8
- package/dist/lib/load/update-required-fields.d.ts +1 -0
- package/dist/lib/load/update-required-fields.js +24 -0
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
|
@@ -6,7 +6,6 @@ const sdk_1 = require("@directus/sdk");
|
|
|
6
6
|
const core_1 = require("@oclif/core");
|
|
7
7
|
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
8
8
|
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
9
|
-
const promises_1 = require("node:stream/promises");
|
|
10
9
|
const constants_1 = require("../constants");
|
|
11
10
|
const sdk_2 = require("../sdk");
|
|
12
11
|
const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
|
|
@@ -14,11 +13,18 @@ async function getAssetList() {
|
|
|
14
13
|
return sdk_2.api.client.request((0, sdk_1.readFiles)({ limit: -1 }));
|
|
15
14
|
}
|
|
16
15
|
async function downloadFile(file, dir) {
|
|
17
|
-
const response = await sdk_2.api.client.request((
|
|
16
|
+
const response = await sdk_2.api.client.request(() => ({
|
|
17
|
+
method: 'GET',
|
|
18
|
+
path: `/assets/${file.id}`,
|
|
19
|
+
}));
|
|
18
20
|
const fullPath = node_path_1.default.join(dir, 'assets', file.filename_disk);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
if (typeof response === 'string') {
|
|
22
|
+
node_fs_1.default.writeFileSync(fullPath, response);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const data = await response.arrayBuffer();
|
|
26
|
+
node_fs_1.default.writeFileSync(fullPath, Buffer.from(data));
|
|
27
|
+
}
|
|
22
28
|
}
|
|
23
29
|
async function downloadAllFiles(dir) {
|
|
24
30
|
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, 'Downloading assets'));
|
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);
|
|
@@ -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
|
}
|
|
@@ -34,7 +34,14 @@ async function processCollections(collectionsToAdd, fieldsToAdd) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
async function addNewCollectionWithFields(collection, allFields) {
|
|
37
|
-
const collectionFields = allFields.filter(field => field.collection === collection.collection)
|
|
37
|
+
const collectionFields = allFields.filter(field => field.collection === collection.collection)
|
|
38
|
+
.map(field => {
|
|
39
|
+
var _a;
|
|
40
|
+
if ((_a = field.meta) === null || _a === void 0 ? void 0 : _a.required) {
|
|
41
|
+
field.meta.reqiured = false;
|
|
42
|
+
}
|
|
43
|
+
return field;
|
|
44
|
+
});
|
|
38
45
|
const collectionWithoutGroup = {
|
|
39
46
|
...collection,
|
|
40
47
|
fields: collectionFields,
|
|
@@ -15,15 +15,9 @@ async function loadFiles(dir) {
|
|
|
15
15
|
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Loading ${files.length} files`));
|
|
16
16
|
if (files && files.length > 0) {
|
|
17
17
|
try {
|
|
18
|
-
const fileIds = files.map(file => file.id);
|
|
19
18
|
// Fetch only the files we're interested in
|
|
20
19
|
const existingFiles = await sdk_2.api.client.request((0, sdk_1.readFiles)({
|
|
21
20
|
fields: ['id', 'filename_disk'],
|
|
22
|
-
filter: {
|
|
23
|
-
id: {
|
|
24
|
-
_in: fileIds,
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
21
|
limit: -1,
|
|
28
22
|
}));
|
|
29
23
|
const existingFileIds = new Set(existingFiles.map(file => file.id));
|
|
@@ -13,15 +13,7 @@ async function loadUsers(dir) {
|
|
|
13
13
|
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Loading ${users.length} users`));
|
|
14
14
|
if (users && users.length > 0) {
|
|
15
15
|
const { legacyAdminRoleId, newAdminRoleId } = await (0, get_role_ids_1.default)(dir);
|
|
16
|
-
const incomingUserEmails = users.map(user => user.email);
|
|
17
|
-
const incomingUserIds = users.map(user => user.id).filter(Boolean);
|
|
18
16
|
const existingUsers = await sdk_2.api.client.request((0, sdk_1.readUsers)({
|
|
19
|
-
filter: {
|
|
20
|
-
_or: [
|
|
21
|
-
{ email: { _in: incomingUserEmails } },
|
|
22
|
-
{ id: { _in: incomingUserIds } },
|
|
23
|
-
],
|
|
24
|
-
},
|
|
25
17
|
limit: -1,
|
|
26
18
|
}));
|
|
27
19
|
const filteredUsers = users.map(user => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function updateRequiredFields(dir: string): Promise<void>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const sdk_1 = require("@directus/sdk");
|
|
5
|
+
const core_1 = require("@oclif/core");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const sdk_2 = require("../sdk");
|
|
8
|
+
const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
|
|
9
|
+
const read_file_1 = tslib_1.__importDefault(require("../utils/read-file"));
|
|
10
|
+
async function updateRequiredFields(dir) {
|
|
11
|
+
const fieldsToUpdate = (0, read_file_1.default)('fields', dir)
|
|
12
|
+
.filter(field => field.meta.required === true);
|
|
13
|
+
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Updating ${fieldsToUpdate.length} fields to required`));
|
|
14
|
+
for await (const field of fieldsToUpdate) {
|
|
15
|
+
try {
|
|
16
|
+
await sdk_2.api.client.request((0, sdk_1.updateField)(field.collection, field.field, { meta: { required: true } }));
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
(0, catch_error_1.default)(error);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
core_1.ux.action.stop();
|
|
23
|
+
}
|
|
24
|
+
exports.default = updateRequiredFields;
|
package/oclif.manifest.json
CHANGED