directus-template-cli 0.7.0-beta.3 → 0.7.0-beta.5
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/bin/dev +2 -3
- package/bin/dev.js +3 -0
- package/bin/run +0 -1
- package/bin/run.js +5 -0
- package/dist/commands/apply.d.ts +17 -17
- package/dist/commands/apply.js +160 -173
- package/dist/commands/extract.d.ts +13 -7
- package/dist/commands/extract.js +89 -73
- package/dist/commands/init.d.ts +7 -7
- package/dist/commands/init.js +78 -80
- package/dist/flags/common.d.ts +7 -7
- package/dist/flags/common.js +8 -11
- package/dist/index.js +1 -5
- package/dist/lib/constants.js +6 -9
- package/dist/lib/extract/extract-access.js +11 -15
- package/dist/lib/extract/extract-assets.js +20 -25
- package/dist/lib/extract/extract-collections.js +12 -16
- package/dist/lib/extract/extract-content.js +14 -19
- package/dist/lib/extract/extract-dashboards.js +22 -28
- package/dist/lib/extract/extract-extensions.js +12 -16
- package/dist/lib/extract/extract-fields.js +13 -17
- package/dist/lib/extract/extract-files.js +15 -19
- package/dist/lib/extract/extract-flows.js +22 -28
- package/dist/lib/extract/extract-folders.js +15 -19
- package/dist/lib/extract/extract-permissions.js +12 -16
- package/dist/lib/extract/extract-policies.js +12 -16
- package/dist/lib/extract/extract-presets.js +12 -16
- package/dist/lib/extract/extract-relations.js +14 -18
- package/dist/lib/extract/extract-roles.js +15 -19
- package/dist/lib/extract/extract-schema.js +17 -21
- package/dist/lib/extract/extract-settings.js +12 -16
- package/dist/lib/extract/extract-translations.js +12 -16
- package/dist/lib/extract/extract-users.js +15 -19
- package/dist/lib/extract/index.js +47 -51
- package/dist/lib/init/config.d.ts +1 -1
- package/dist/lib/init/config.js +2 -5
- package/dist/lib/init/index.js +54 -59
- package/dist/lib/init/types.js +1 -2
- package/dist/lib/init.d.ts +1 -0
- package/dist/lib/init.js +2 -0
- package/dist/lib/load/apply-flags.js +17 -23
- package/dist/lib/load/index.js +40 -44
- package/dist/lib/load/load-access.js +15 -20
- package/dist/lib/load/load-collections.js +27 -32
- package/dist/lib/load/load-dashboards.js +19 -25
- package/dist/lib/load/load-data.js +43 -49
- package/dist/lib/load/load-extensions.js +30 -38
- package/dist/lib/load/load-files.js +20 -24
- package/dist/lib/load/load-flows.js +23 -29
- package/dist/lib/load/load-folders.js +16 -20
- package/dist/lib/load/load-permissions.js +13 -17
- package/dist/lib/load/load-policies.js +14 -18
- package/dist/lib/load/load-presets.js +14 -18
- package/dist/lib/load/load-relations.d.ts +2 -0
- package/dist/lib/load/load-relations.js +16 -18
- package/dist/lib/load/load-roles.js +19 -23
- package/dist/lib/load/load-settings.js +18 -21
- package/dist/lib/load/load-translations.js +14 -18
- package/dist/lib/load/load-users.js +21 -25
- package/dist/lib/load/update-required-fields.js +13 -17
- package/dist/lib/sdk.d.ts +1 -2
- package/dist/lib/sdk.js +27 -27
- package/dist/lib/types/extension.js +1 -2
- package/dist/lib/utils/animated-bunny.js +9 -14
- package/dist/lib/utils/auth.d.ts +2 -2
- package/dist/lib/utils/auth.js +32 -33
- package/dist/lib/utils/catch-error.js +8 -11
- package/dist/lib/utils/check-template.js +4 -8
- package/dist/lib/utils/chunk-array.js +1 -5
- package/dist/lib/utils/ensure-dir.js +7 -12
- package/dist/lib/utils/filter-fields.js +1 -4
- package/dist/lib/utils/get-role-ids.d.ts +1 -1
- package/dist/lib/utils/get-role-ids.js +7 -12
- package/dist/lib/utils/get-template.js +33 -37
- package/dist/lib/utils/logger.js +11 -13
- package/dist/lib/utils/open-url.js +5 -8
- package/dist/lib/utils/parse-github-url.js +4 -9
- package/dist/lib/utils/path.js +6 -10
- package/dist/lib/utils/protected-domains.js +1 -4
- package/dist/lib/utils/read-file.js +8 -12
- package/dist/lib/utils/read-templates.js +9 -15
- package/dist/lib/utils/system-fields.js +19 -22
- package/dist/lib/utils/template-defaults.d.ts +1 -1
- package/dist/lib/utils/template-defaults.js +5 -14
- package/dist/lib/utils/transform-github-url.js +1 -5
- package/dist/lib/utils/validate-url.js +3 -6
- package/dist/lib/utils/wait.js +1 -5
- package/dist/lib/utils/write-to-file.js +8 -11
- package/dist/services/docker.js +19 -24
- package/dist/services/github.d.ts +1 -1
- package/dist/services/github.js +8 -12
- package/oclif.manifest.json +4 -4
- package/package.json +36 -32
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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"));
|
|
1
|
+
import { customEndpoint, readExtensions } from '@directus/sdk';
|
|
2
|
+
import { ux } from '@oclif/core';
|
|
3
|
+
import { DIRECTUS_PINK } from '../constants.js';
|
|
4
|
+
import { api } from '../sdk.js';
|
|
5
|
+
import catchError from '../utils/catch-error.js';
|
|
6
|
+
import readFile from '../utils/read-file.js';
|
|
10
7
|
async function installExtension(extension) {
|
|
11
|
-
await
|
|
8
|
+
await api.client.request(customEndpoint({
|
|
12
9
|
body: JSON.stringify({
|
|
13
10
|
extension: extension.id,
|
|
14
11
|
version: extension.version,
|
|
@@ -17,60 +14,55 @@ async function installExtension(extension) {
|
|
|
17
14
|
path: '/extensions/registry/install',
|
|
18
15
|
}));
|
|
19
16
|
}
|
|
20
|
-
async function loadExtensions(dir) {
|
|
21
|
-
|
|
17
|
+
export default async function loadExtensions(dir) {
|
|
18
|
+
ux.action.start(ux.colorize(DIRECTUS_PINK, 'Loading extensions'));
|
|
22
19
|
try {
|
|
23
|
-
const extensions = (
|
|
20
|
+
const extensions = readFile('extensions', dir);
|
|
24
21
|
if (extensions && extensions.length > 0) {
|
|
25
|
-
const installedExtensions = await
|
|
26
|
-
const registryExtensions = extensions.filter(ext =>
|
|
22
|
+
const installedExtensions = await api.client.request(readExtensions());
|
|
23
|
+
const registryExtensions = extensions.filter(ext => ext.meta?.source === 'registry' && !ext.bundle);
|
|
27
24
|
const bundles = [...new Set(extensions.filter(ext => ext.bundle).map(ext => ext.bundle))];
|
|
28
|
-
const localExtensions = extensions.filter(ext =>
|
|
29
|
-
const extensionsToInstall = extensions.filter(ext =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
&& !installedExtensions.some(installed => installed.id === ext.id);
|
|
35
|
-
});
|
|
36
|
-
core_1.ux.log(`Found ${extensions.length} extensions total: ${registryExtensions.length} registry extensions (including ${bundles.length} bundles), and ${localExtensions.length} local extensions`);
|
|
25
|
+
const localExtensions = extensions.filter(ext => ext.meta?.source === 'local');
|
|
26
|
+
const extensionsToInstall = extensions.filter(ext => ext.meta?.source === 'registry'
|
|
27
|
+
&& !ext.bundle
|
|
28
|
+
// @ts-ignore - ignore
|
|
29
|
+
&& !installedExtensions.some(installed => installed.id === ext.id));
|
|
30
|
+
ux.stdout(`Found ${extensions.length} extensions total: ${registryExtensions.length} registry extensions (including ${bundles.length} bundles), and ${localExtensions.length} local extensions`);
|
|
37
31
|
if (extensionsToInstall.length > 0) {
|
|
38
|
-
|
|
32
|
+
ux.action.start(ux.colorize(DIRECTUS_PINK, `Installing ${extensionsToInstall.length} extensions`));
|
|
39
33
|
const results = await Promise.allSettled(extensionsToInstall.map(async (ext) => {
|
|
40
|
-
var _a, _b, _c;
|
|
41
34
|
try {
|
|
42
35
|
await installExtension({
|
|
43
36
|
id: ext.id,
|
|
44
37
|
// The extension version UUID is the folder name
|
|
45
|
-
version:
|
|
38
|
+
version: ext.meta?.folder,
|
|
46
39
|
});
|
|
47
|
-
return `-- Installed ${
|
|
40
|
+
return `-- Installed ${ext.schema?.name}`;
|
|
48
41
|
}
|
|
49
42
|
catch (error) {
|
|
50
|
-
(
|
|
51
|
-
return `-- Failed to install ${
|
|
43
|
+
catchError(error);
|
|
44
|
+
return `-- Failed to install ${ext.schema?.name}`;
|
|
52
45
|
}
|
|
53
46
|
}));
|
|
54
47
|
for (const result of results) {
|
|
55
48
|
if (result.status === 'fulfilled') {
|
|
56
|
-
|
|
49
|
+
ux.stdout(result.value);
|
|
57
50
|
}
|
|
58
51
|
}
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
ux.action.stop();
|
|
53
|
+
ux.stdout('Finished installing extensions');
|
|
61
54
|
}
|
|
62
55
|
else {
|
|
63
56
|
// All extensions are already installed
|
|
64
|
-
|
|
57
|
+
ux.stdout('All extensions are already installed');
|
|
65
58
|
}
|
|
66
59
|
if (localExtensions.length > 0) {
|
|
67
|
-
|
|
60
|
+
ux.stdout(`Note: ${localExtensions.length} local extensions need to be installed manually.`);
|
|
68
61
|
}
|
|
69
62
|
}
|
|
70
63
|
}
|
|
71
64
|
catch {
|
|
72
|
-
|
|
65
|
+
ux.stdout(`${ux.colorize('dim', '--')} No extensions found or extensions file is empty. Skipping extension installation.`);
|
|
73
66
|
}
|
|
74
|
-
|
|
67
|
+
ux.action.stop();
|
|
75
68
|
}
|
|
76
|
-
exports.default = loadExtensions;
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
async function loadFiles(dir) {
|
|
14
|
-
const files = (0, read_file_1.default)('files', dir);
|
|
15
|
-
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Loading ${files.length} files`));
|
|
1
|
+
import { readFiles, uploadFiles } from '@directus/sdk';
|
|
2
|
+
import { ux } from '@oclif/core';
|
|
3
|
+
import { FormData } from 'formdata-node';
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
import path from 'pathe';
|
|
6
|
+
import { DIRECTUS_PINK } from '../constants.js';
|
|
7
|
+
import { api } from '../sdk.js';
|
|
8
|
+
import catchError from '../utils/catch-error.js';
|
|
9
|
+
import readFile from '../utils/read-file.js';
|
|
10
|
+
export default async function loadFiles(dir) {
|
|
11
|
+
const files = readFile('files', dir);
|
|
12
|
+
ux.action.start(ux.colorize(DIRECTUS_PINK, `Loading ${files.length} files`));
|
|
16
13
|
if (files && files.length > 0) {
|
|
17
14
|
try {
|
|
18
15
|
// Fetch only the files we're interested in
|
|
19
|
-
const existingFiles = await
|
|
16
|
+
const existingFiles = await api.client.request(readFiles({
|
|
20
17
|
fields: ['id', 'filename_disk'],
|
|
21
18
|
limit: -1,
|
|
22
19
|
}));
|
|
@@ -33,9 +30,9 @@ async function loadFiles(dir) {
|
|
|
33
30
|
});
|
|
34
31
|
await Promise.all(filesToUpload.map(async (asset) => {
|
|
35
32
|
const fileName = asset.filename_disk;
|
|
36
|
-
const assetPath =
|
|
37
|
-
const fileStream = new Blob([
|
|
38
|
-
const form = new
|
|
33
|
+
const assetPath = path.resolve(dir, 'assets', fileName);
|
|
34
|
+
const fileStream = new Blob([readFileSync(assetPath)], { type: asset.type });
|
|
35
|
+
const form = new FormData();
|
|
39
36
|
form.append('id', asset.id);
|
|
40
37
|
if (asset.title)
|
|
41
38
|
form.append('title', asset.title);
|
|
@@ -45,17 +42,16 @@ async function loadFiles(dir) {
|
|
|
45
42
|
form.append('folder', asset.folder);
|
|
46
43
|
form.append('file', fileStream, fileName);
|
|
47
44
|
try {
|
|
48
|
-
await
|
|
45
|
+
await api.client.request(uploadFiles(form));
|
|
49
46
|
}
|
|
50
47
|
catch (error) {
|
|
51
|
-
(
|
|
48
|
+
catchError(error);
|
|
52
49
|
}
|
|
53
50
|
}));
|
|
54
51
|
}
|
|
55
52
|
catch (error) {
|
|
56
|
-
(
|
|
53
|
+
catchError(error);
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
|
-
|
|
56
|
+
ux.action.stop();
|
|
60
57
|
}
|
|
61
|
-
exports.default = loadFiles;
|
|
@@ -1,33 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
async function loadFlows(dir) {
|
|
12
|
-
const flows = (0, read_file_1.default)('flows', dir);
|
|
13
|
-
const allOperations = (0, read_file_1.default)('operations', dir);
|
|
14
|
-
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Loading ${flows.length} flows`));
|
|
1
|
+
import { createFlow, createOperations, readFlows, updateOperation } from '@directus/sdk';
|
|
2
|
+
import { ux } from '@oclif/core';
|
|
3
|
+
import { DIRECTUS_PINK } from '../constants.js';
|
|
4
|
+
import { api } from '../sdk.js';
|
|
5
|
+
import catchError from '../utils/catch-error.js';
|
|
6
|
+
import readFile from '../utils/read-file.js';
|
|
7
|
+
export default async function loadFlows(dir) {
|
|
8
|
+
const flows = readFile('flows', dir);
|
|
9
|
+
const allOperations = readFile('operations', dir);
|
|
10
|
+
ux.action.start(ux.colorize(DIRECTUS_PINK, `Loading ${flows.length} flows`));
|
|
15
11
|
if (flows && flows.length > 0) {
|
|
16
12
|
try {
|
|
17
13
|
// Fetch existing flows
|
|
18
|
-
const existingFlows = await
|
|
14
|
+
const existingFlows = await api.client.request(readFlows({
|
|
19
15
|
limit: -1,
|
|
20
16
|
}));
|
|
21
17
|
const existingFlowIds = new Set(existingFlows.map(flow => flow.id));
|
|
22
18
|
const newFlows = flows.filter(flow => !existingFlowIds.has(flow.id));
|
|
23
|
-
const results = await Promise.allSettled(newFlows.map(flow =>
|
|
19
|
+
const results = await Promise.allSettled(newFlows.map(flow => api.client.request(createFlow(flow))));
|
|
24
20
|
const createdFlowIds = new Set();
|
|
25
21
|
for (const [index, result] of results.entries()) {
|
|
26
22
|
if (result.status === 'fulfilled') {
|
|
27
23
|
createdFlowIds.add(newFlows[index].id);
|
|
28
24
|
}
|
|
29
25
|
else {
|
|
30
|
-
(
|
|
26
|
+
catchError(result.reason);
|
|
31
27
|
}
|
|
32
28
|
}
|
|
33
29
|
// Filter operations for newly created flows
|
|
@@ -35,36 +31,34 @@ async function loadFlows(dir) {
|
|
|
35
31
|
await loadOperations(newOperations);
|
|
36
32
|
}
|
|
37
33
|
catch (error) {
|
|
38
|
-
(
|
|
34
|
+
catchError(error);
|
|
39
35
|
}
|
|
40
36
|
finally {
|
|
41
|
-
|
|
37
|
+
ux.action.stop();
|
|
42
38
|
}
|
|
43
39
|
}
|
|
44
40
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
core_1.ux.action.status = `Loading ${operations.length} operations`;
|
|
41
|
+
export async function loadOperations(operations) {
|
|
42
|
+
ux.action.status = `Loading ${operations.length} operations`;
|
|
48
43
|
try {
|
|
49
44
|
const opsIds = operations.map(operation => {
|
|
50
45
|
const opCopy = { ...operation };
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
opCopy.reject = undefined;
|
|
47
|
+
opCopy.resolve = undefined;
|
|
53
48
|
return opCopy;
|
|
54
49
|
});
|
|
55
|
-
await
|
|
56
|
-
const results = await Promise.allSettled(operations.map(operation =>
|
|
50
|
+
await api.client.request(createOperations(opsIds));
|
|
51
|
+
const results = await Promise.allSettled(operations.map(operation => api.client.request(updateOperation(operation.id, {
|
|
57
52
|
reject: operation.reject,
|
|
58
53
|
resolve: operation.resolve,
|
|
59
54
|
}))));
|
|
60
55
|
for (const [index, result] of results.entries()) {
|
|
61
56
|
if (result.status === 'rejected') {
|
|
62
|
-
(
|
|
57
|
+
catchError(result.reason);
|
|
63
58
|
}
|
|
64
59
|
}
|
|
65
60
|
}
|
|
66
61
|
catch (error) {
|
|
67
|
-
(
|
|
62
|
+
catchError(error);
|
|
68
63
|
}
|
|
69
64
|
}
|
|
70
|
-
exports.loadOperations = loadOperations;
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
async function loadFolders(dir) {
|
|
11
|
-
const folders = (0, read_file_1.default)('folders', dir);
|
|
12
|
-
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Loading ${folders.length} folders`));
|
|
1
|
+
import { createFolders, readFolders, updateFolder } from '@directus/sdk';
|
|
2
|
+
import { ux } from '@oclif/core';
|
|
3
|
+
import { DIRECTUS_PINK } from '../constants.js';
|
|
4
|
+
import { api } from '../sdk.js';
|
|
5
|
+
import catchError from '../utils/catch-error.js';
|
|
6
|
+
import readFile from '../utils/read-file.js';
|
|
7
|
+
export default async function loadFolders(dir) {
|
|
8
|
+
const folders = readFile('folders', dir);
|
|
9
|
+
ux.action.start(ux.colorize(DIRECTUS_PINK, `Loading ${folders.length} folders`));
|
|
13
10
|
if (folders && folders.length > 0) {
|
|
14
11
|
try {
|
|
15
12
|
// Fetch existing folders
|
|
16
|
-
const existingFolders = await
|
|
13
|
+
const existingFolders = await api.client.request(readFolders({
|
|
17
14
|
limit: -1,
|
|
18
15
|
}));
|
|
19
16
|
const existingFolderIds = new Set(existingFolders.map(folder => folder.id));
|
|
@@ -26,26 +23,25 @@ async function loadFolders(dir) {
|
|
|
26
23
|
if (foldersToAdd.length > 0) {
|
|
27
24
|
const folderSkeleton = foldersToAdd.map(folder => ({ id: folder.id, name: folder.name }));
|
|
28
25
|
// Create the folders
|
|
29
|
-
await
|
|
26
|
+
await api.client.request(createFolders(folderSkeleton));
|
|
30
27
|
// Update the folders with relationships concurrently
|
|
31
28
|
await Promise.all(foldersToAdd.map(async (folder) => {
|
|
32
29
|
const { id, ...rest } = folder;
|
|
33
30
|
try {
|
|
34
|
-
await
|
|
31
|
+
await api.client.request(updateFolder(id, rest));
|
|
35
32
|
}
|
|
36
33
|
catch (error) {
|
|
37
|
-
(
|
|
34
|
+
catchError(error);
|
|
38
35
|
}
|
|
39
36
|
}));
|
|
40
37
|
}
|
|
41
38
|
else {
|
|
42
|
-
// ux.
|
|
39
|
+
// ux.stdout('-- No new folders to create')
|
|
43
40
|
}
|
|
44
41
|
}
|
|
45
42
|
catch (error) {
|
|
46
|
-
(
|
|
43
|
+
catchError(error);
|
|
47
44
|
}
|
|
48
45
|
}
|
|
49
|
-
|
|
46
|
+
ux.action.stop();
|
|
50
47
|
}
|
|
51
|
-
exports.default = loadFolders;
|
|
@@ -1,31 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
async function loadPermissions(dir) {
|
|
11
|
-
const permissions = (0, read_file_1.default)('permissions', dir);
|
|
12
|
-
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Loading ${permissions.length} permissions`));
|
|
1
|
+
import { createPermissions, readPermissions } from '@directus/sdk';
|
|
2
|
+
import { ux } from '@oclif/core';
|
|
3
|
+
import { DIRECTUS_PINK } from '../constants.js';
|
|
4
|
+
import { api } from '../sdk.js';
|
|
5
|
+
import catchError from '../utils/catch-error.js';
|
|
6
|
+
import readFile from '../utils/read-file.js';
|
|
7
|
+
export default async function loadPermissions(dir) {
|
|
8
|
+
const permissions = readFile('permissions', dir);
|
|
9
|
+
ux.action.start(ux.colorize(DIRECTUS_PINK, `Loading ${permissions.length} permissions`));
|
|
13
10
|
if (permissions && permissions.length > 0) {
|
|
14
11
|
try {
|
|
15
|
-
const existingPermissions = await
|
|
12
|
+
const existingPermissions = await api.client.request(readPermissions({
|
|
16
13
|
limit: -1,
|
|
17
14
|
}));
|
|
18
15
|
const existingPermissionKeys = new Set(existingPermissions.map(p => `${p.collection}:${p.action}:${p.policy}`));
|
|
19
16
|
// Filter out duplicates
|
|
20
17
|
const newPermissions = permissions.filter(newPerm => !existingPermissionKeys.has(`${newPerm.collection}:${newPerm.action}:${newPerm.policy}`));
|
|
21
18
|
if (newPermissions.length > 0) {
|
|
22
|
-
await
|
|
19
|
+
await api.client.request(createPermissions(newPermissions));
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
22
|
catch (error) {
|
|
26
|
-
(
|
|
23
|
+
catchError(error);
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
|
-
|
|
26
|
+
ux.action.stop();
|
|
30
27
|
}
|
|
31
|
-
exports.default = loadPermissions;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
async function loadPolicies(dir) {
|
|
11
|
-
const policies = (0, read_file_1.default)('policies', dir);
|
|
12
|
-
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Loading ${policies.length} policies`));
|
|
1
|
+
import { createPolicy, readPolicies } from '@directus/sdk';
|
|
2
|
+
import { ux } from '@oclif/core';
|
|
3
|
+
import { DIRECTUS_PINK } from '../constants.js';
|
|
4
|
+
import { api } from '../sdk.js';
|
|
5
|
+
import catchError from '../utils/catch-error.js';
|
|
6
|
+
import readFile from '../utils/read-file.js';
|
|
7
|
+
export default async function loadPolicies(dir) {
|
|
8
|
+
const policies = readFile('policies', dir);
|
|
9
|
+
ux.action.start(ux.colorize(DIRECTUS_PINK, `Loading ${policies.length} policies`));
|
|
13
10
|
if (policies && policies.length > 0) {
|
|
14
11
|
// Fetch existing policies
|
|
15
|
-
const existingPolicies = await
|
|
12
|
+
const existingPolicies = await api.client.request(readPolicies({
|
|
16
13
|
limit: -1,
|
|
17
14
|
}));
|
|
18
15
|
const existingPolicyIds = new Set(existingPolicies.map(policy => policy.id));
|
|
@@ -21,19 +18,18 @@ async function loadPolicies(dir) {
|
|
|
21
18
|
for await (const policy of policiesWithoutPublic) {
|
|
22
19
|
try {
|
|
23
20
|
if (existingPolicyIds.has(policy.id)) {
|
|
24
|
-
|
|
21
|
+
ux.action.status = `Skipping existing policy: ${policy.name}`;
|
|
25
22
|
continue;
|
|
26
23
|
}
|
|
27
24
|
// Create new policy
|
|
28
|
-
await
|
|
25
|
+
await api.client.request(createPolicy(policy));
|
|
29
26
|
// Add the new policy ID to our set of existing policies
|
|
30
27
|
existingPolicyIds.add(policy.id);
|
|
31
28
|
}
|
|
32
29
|
catch (error) {
|
|
33
|
-
(
|
|
30
|
+
catchError(error);
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
33
|
}
|
|
37
|
-
|
|
34
|
+
ux.action.stop();
|
|
38
35
|
}
|
|
39
|
-
exports.default = loadPolicies;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
async function loadPresets(dir) {
|
|
11
|
-
const presets = (0, read_file_1.default)('presets', dir);
|
|
12
|
-
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Loading ${presets.length} presets`));
|
|
1
|
+
import { createPresets, readPresets } from '@directus/sdk';
|
|
2
|
+
import { ux } from '@oclif/core';
|
|
3
|
+
import { DIRECTUS_PINK } from '../constants.js';
|
|
4
|
+
import { api } from '../sdk.js';
|
|
5
|
+
import catchError from '../utils/catch-error.js';
|
|
6
|
+
import readFile from '../utils/read-file.js';
|
|
7
|
+
export default async function loadPresets(dir) {
|
|
8
|
+
const presets = readFile('presets', dir);
|
|
9
|
+
ux.action.start(ux.colorize(DIRECTUS_PINK, `Loading ${presets.length} presets`));
|
|
13
10
|
if (presets && presets.length > 0) {
|
|
14
11
|
// Fetch existing presets
|
|
15
|
-
const existingPresets = await
|
|
12
|
+
const existingPresets = await api.client.request(readPresets({
|
|
16
13
|
limit: -1,
|
|
17
14
|
}));
|
|
18
15
|
const existingPresetIds = new Set(existingPresets.map(preset => preset.id));
|
|
@@ -28,16 +25,15 @@ async function loadPresets(dir) {
|
|
|
28
25
|
});
|
|
29
26
|
if (presetsToAdd.length > 0) {
|
|
30
27
|
try {
|
|
31
|
-
await
|
|
28
|
+
await api.client.request(createPresets(presetsToAdd));
|
|
32
29
|
}
|
|
33
30
|
catch (error) {
|
|
34
|
-
(
|
|
31
|
+
catchError(error);
|
|
35
32
|
}
|
|
36
33
|
}
|
|
37
34
|
else {
|
|
38
|
-
// ux.
|
|
35
|
+
// ux.stdout('-- No new presets to create')
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
|
-
|
|
38
|
+
ux.action.stop();
|
|
42
39
|
}
|
|
43
|
-
exports.default = loadPresets;
|
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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"));
|
|
1
|
+
import { createRelation, readRelations } from '@directus/sdk';
|
|
2
|
+
import { ux } from '@oclif/core';
|
|
3
|
+
import { DIRECTUS_PINK } from '../constants.js';
|
|
4
|
+
import { api } from '../sdk.js';
|
|
5
|
+
import catchError from '../utils/catch-error.js';
|
|
6
|
+
import readFile from '../utils/read-file.js';
|
|
10
7
|
/**
|
|
11
8
|
* Load relationships into the Directus instance
|
|
9
|
+
* @param dir - The directory to read the relations from
|
|
10
|
+
* @returns {Promise<void>} - Returns nothing
|
|
12
11
|
*/
|
|
13
|
-
async function loadRelations(dir) {
|
|
14
|
-
const relations = (
|
|
15
|
-
|
|
12
|
+
export default async function loadRelations(dir) {
|
|
13
|
+
const relations = readFile('relations', dir);
|
|
14
|
+
ux.action.start(ux.colorize(DIRECTUS_PINK, `Loading ${relations.length} relations`));
|
|
16
15
|
if (relations && relations.length > 0) {
|
|
17
16
|
// Fetch existing relations
|
|
18
|
-
const existingRelations = await
|
|
17
|
+
const existingRelations = await api.client.request(readRelations());
|
|
19
18
|
const existingRelationKeys = new Set(existingRelations.map(relation => `${relation.collection}:${relation.field}:${relation.related_collection}`));
|
|
20
19
|
const relationsToAdd = relations.filter(relation => {
|
|
21
20
|
const key = `${relation.collection}:${relation.field}:${relation.related_collection}`;
|
|
@@ -25,21 +24,20 @@ async function loadRelations(dir) {
|
|
|
25
24
|
return true;
|
|
26
25
|
}).map(relation => {
|
|
27
26
|
const cleanRelation = { ...relation };
|
|
28
|
-
|
|
27
|
+
cleanRelation.meta.id = undefined;
|
|
29
28
|
return cleanRelation;
|
|
30
29
|
});
|
|
31
30
|
await addRelations(relationsToAdd);
|
|
32
31
|
}
|
|
33
|
-
|
|
32
|
+
ux.action.stop();
|
|
34
33
|
}
|
|
35
|
-
exports.default = loadRelations;
|
|
36
34
|
async function addRelations(relations) {
|
|
37
35
|
for await (const relation of relations) {
|
|
38
36
|
try {
|
|
39
|
-
await
|
|
37
|
+
await api.client.request(createRelation(relation));
|
|
40
38
|
}
|
|
41
39
|
catch (error) {
|
|
42
|
-
(
|
|
40
|
+
catchError(error);
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
43
|
}
|