directus-template-cli 0.7.0-beta.4 → 0.7.0-beta.6

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.
Files changed (105) hide show
  1. package/bin/dev.js +6 -0
  2. package/bin/run.js +5 -0
  3. package/dist/commands/apply.d.ts +17 -17
  4. package/dist/commands/apply.js +163 -173
  5. package/dist/commands/base.d.ts +15 -0
  6. package/dist/commands/base.js +45 -0
  7. package/dist/commands/extract.d.ts +16 -7
  8. package/dist/commands/extract.js +80 -73
  9. package/dist/commands/init.d.ts +20 -15
  10. package/dist/commands/init.js +189 -126
  11. package/dist/flags/common.d.ts +8 -7
  12. package/dist/flags/common.js +13 -11
  13. package/dist/index.js +1 -5
  14. package/dist/lib/constants.d.ts +3 -5
  15. package/dist/lib/constants.js +8 -13
  16. package/dist/lib/extract/extract-access.js +11 -15
  17. package/dist/lib/extract/extract-assets.js +20 -25
  18. package/dist/lib/extract/extract-collections.js +12 -16
  19. package/dist/lib/extract/extract-content.js +14 -19
  20. package/dist/lib/extract/extract-dashboards.js +22 -28
  21. package/dist/lib/extract/extract-extensions.js +12 -16
  22. package/dist/lib/extract/extract-fields.js +13 -17
  23. package/dist/lib/extract/extract-files.js +15 -19
  24. package/dist/lib/extract/extract-flows.js +22 -28
  25. package/dist/lib/extract/extract-folders.js +15 -19
  26. package/dist/lib/extract/extract-permissions.js +12 -16
  27. package/dist/lib/extract/extract-policies.js +12 -16
  28. package/dist/lib/extract/extract-presets.js +12 -16
  29. package/dist/lib/extract/extract-relations.js +14 -18
  30. package/dist/lib/extract/extract-roles.js +15 -19
  31. package/dist/lib/extract/extract-schema.js +17 -21
  32. package/dist/lib/extract/extract-settings.js +12 -16
  33. package/dist/lib/extract/extract-translations.js +12 -16
  34. package/dist/lib/extract/extract-users.js +15 -19
  35. package/dist/lib/extract/index.js +47 -51
  36. package/dist/lib/init/config.d.ts +1 -1
  37. package/dist/lib/init/config.js +3 -6
  38. package/dist/lib/init/index.d.ts +5 -9
  39. package/dist/lib/init/index.js +105 -85
  40. package/dist/lib/init/types.js +1 -2
  41. package/dist/lib/load/apply-flags.js +17 -23
  42. package/dist/lib/load/index.d.ts +1 -12
  43. package/dist/lib/load/index.js +40 -44
  44. package/dist/lib/load/load-access.js +15 -20
  45. package/dist/lib/load/load-collections.js +27 -32
  46. package/dist/lib/load/load-dashboards.js +19 -25
  47. package/dist/lib/load/load-data.js +43 -49
  48. package/dist/lib/load/load-extensions.js +30 -38
  49. package/dist/lib/load/load-files.js +20 -24
  50. package/dist/lib/load/load-flows.js +23 -29
  51. package/dist/lib/load/load-folders.js +16 -20
  52. package/dist/lib/load/load-permissions.js +13 -17
  53. package/dist/lib/load/load-policies.js +14 -18
  54. package/dist/lib/load/load-presets.js +14 -18
  55. package/dist/lib/load/load-relations.d.ts +2 -0
  56. package/dist/lib/load/load-relations.js +16 -18
  57. package/dist/lib/load/load-roles.js +19 -23
  58. package/dist/lib/load/load-settings.js +18 -21
  59. package/dist/lib/load/load-translations.js +14 -18
  60. package/dist/lib/load/load-users.js +21 -25
  61. package/dist/lib/load/update-required-fields.js +13 -17
  62. package/dist/lib/sdk.d.ts +1 -2
  63. package/dist/lib/sdk.js +27 -27
  64. package/dist/lib/types/extension.js +1 -2
  65. package/dist/lib/types.d.ts +18 -0
  66. package/dist/lib/types.js +1 -0
  67. package/dist/lib/utils/animated-bunny.js +9 -14
  68. package/dist/lib/utils/auth.d.ts +8 -6
  69. package/dist/lib/utils/auth.js +48 -39
  70. package/dist/lib/utils/catch-error.js +8 -11
  71. package/dist/lib/utils/check-template.js +4 -8
  72. package/dist/lib/utils/chunk-array.js +1 -5
  73. package/dist/lib/utils/ensure-dir.js +7 -12
  74. package/dist/lib/utils/filter-fields.js +1 -4
  75. package/dist/lib/utils/get-role-ids.d.ts +1 -1
  76. package/dist/lib/utils/get-role-ids.js +7 -12
  77. package/dist/lib/utils/get-template.js +33 -37
  78. package/dist/lib/utils/logger.js +11 -13
  79. package/dist/lib/utils/open-url.js +5 -8
  80. package/dist/lib/utils/parse-github-url.d.ts +10 -5
  81. package/dist/lib/utils/parse-github-url.js +80 -45
  82. package/dist/lib/utils/path.js +6 -10
  83. package/dist/lib/utils/protected-domains.js +1 -4
  84. package/dist/lib/utils/read-file.js +8 -12
  85. package/dist/lib/utils/read-templates.js +9 -15
  86. package/dist/lib/utils/sanitize-flags.d.ts +3 -0
  87. package/dist/lib/utils/sanitize-flags.js +4 -0
  88. package/dist/lib/utils/system-fields.js +19 -22
  89. package/dist/lib/utils/template-config.d.ts +16 -0
  90. package/dist/lib/utils/template-config.js +34 -0
  91. package/dist/lib/utils/template-defaults.d.ts +1 -1
  92. package/dist/lib/utils/template-defaults.js +5 -14
  93. package/dist/lib/utils/transform-github-url.js +1 -5
  94. package/dist/lib/utils/validate-url.js +3 -6
  95. package/dist/lib/utils/wait.js +1 -5
  96. package/dist/lib/utils/write-to-file.js +8 -11
  97. package/dist/services/docker.js +68 -21
  98. package/dist/services/github.d.ts +1 -1
  99. package/dist/services/github.js +53 -22
  100. package/dist/services/posthog.d.ts +37 -0
  101. package/dist/services/posthog.js +104 -0
  102. package/oclif.manifest.json +32 -13
  103. package/package.json +38 -33
  104. package/bin/dev +0 -17
  105. package/bin/run +0 -5
@@ -1,33 +1,29 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadOperations = void 0;
4
- const tslib_1 = require("tslib");
5
- const sdk_1 = require("@directus/sdk");
6
- const core_1 = require("@oclif/core");
7
- const constants_1 = require("../constants");
8
- const sdk_2 = require("../sdk");
9
- const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
10
- const read_file_1 = tslib_1.__importDefault(require("../utils/read-file"));
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 sdk_2.api.client.request((0, sdk_1.readFlows)({
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 => sdk_2.api.client.request((0, sdk_1.createFlow)(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
- (0, catch_error_1.default)(result.reason);
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
- (0, catch_error_1.default)(error);
34
+ catchError(error);
39
35
  }
40
36
  finally {
41
- core_1.ux.action.stop();
37
+ ux.action.stop();
42
38
  }
43
39
  }
44
40
  }
45
- exports.default = loadFlows;
46
- async function loadOperations(operations) {
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
- delete opCopy.reject;
52
- delete opCopy.resolve;
46
+ opCopy.reject = undefined;
47
+ opCopy.resolve = undefined;
53
48
  return opCopy;
54
49
  });
55
- await sdk_2.api.client.request((0, sdk_1.createOperations)(opsIds));
56
- const results = await Promise.allSettled(operations.map(operation => sdk_2.api.client.request((0, sdk_1.updateOperation)(operation.id, {
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
- (0, catch_error_1.default)(result.reason);
57
+ catchError(result.reason);
63
58
  }
64
59
  }
65
60
  }
66
61
  catch (error) {
67
- (0, catch_error_1.default)(error);
62
+ catchError(error);
68
63
  }
69
64
  }
70
- exports.loadOperations = loadOperations;
@@ -1,19 +1,16 @@
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 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 sdk_2.api.client.request((0, sdk_1.readFolders)({
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 sdk_2.api.client.request((0, sdk_1.createFolders)(folderSkeleton));
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 sdk_2.api.client.request((0, sdk_1.updateFolder)(id, rest));
31
+ await api.client.request(updateFolder(id, rest));
35
32
  }
36
33
  catch (error) {
37
- (0, catch_error_1.default)(error);
34
+ catchError(error);
38
35
  }
39
36
  }));
40
37
  }
41
38
  else {
42
- // ux.info('-- No new folders to create')
39
+ // ux.stdout('-- No new folders to create')
43
40
  }
44
41
  }
45
42
  catch (error) {
46
- (0, catch_error_1.default)(error);
43
+ catchError(error);
47
44
  }
48
45
  }
49
- core_1.ux.action.stop();
46
+ ux.action.stop();
50
47
  }
51
- exports.default = loadFolders;
@@ -1,31 +1,27 @@
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 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 sdk_2.api.client.request((0, sdk_1.readPermissions)({
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 sdk_2.api.client.request((0, sdk_1.createPermissions)(newPermissions));
19
+ await api.client.request(createPermissions(newPermissions));
23
20
  }
24
21
  }
25
22
  catch (error) {
26
- (0, catch_error_1.default)(error);
23
+ catchError(error);
27
24
  }
28
25
  }
29
- core_1.ux.action.stop();
26
+ ux.action.stop();
30
27
  }
31
- exports.default = loadPermissions;
@@ -1,18 +1,15 @@
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 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 sdk_2.api.client.request((0, sdk_1.readPolicies)({
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
- core_1.ux.action.status = `Skipping existing policy: ${policy.name}`;
21
+ ux.action.status = `Skipping existing policy: ${policy.name}`;
25
22
  continue;
26
23
  }
27
24
  // Create new policy
28
- await sdk_2.api.client.request((0, sdk_1.createPolicy)(policy));
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
- (0, catch_error_1.default)(error);
30
+ catchError(error);
34
31
  }
35
32
  }
36
33
  }
37
- core_1.ux.action.stop();
34
+ ux.action.stop();
38
35
  }
39
- exports.default = loadPolicies;
@@ -1,18 +1,15 @@
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 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 sdk_2.api.client.request((0, sdk_1.readPresets)({
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 sdk_2.api.client.request((0, sdk_1.createPresets)(presetsToAdd));
28
+ await api.client.request(createPresets(presetsToAdd));
32
29
  }
33
30
  catch (error) {
34
- (0, catch_error_1.default)(error);
31
+ catchError(error);
35
32
  }
36
33
  }
37
34
  else {
38
- // ux.info('-- No new presets to create')
35
+ // ux.stdout('-- No new presets to create')
39
36
  }
40
37
  }
41
- core_1.ux.action.stop();
38
+ ux.action.stop();
42
39
  }
43
- exports.default = loadPresets;
@@ -1,4 +1,6 @@
1
1
  /**
2
2
  * Load relationships into the Directus instance
3
+ * @param dir - The directory to read the relations from
4
+ * @returns {Promise<void>} - Returns nothing
3
5
  */
4
6
  export default function loadRelations(dir: string): Promise<void>;
@@ -1,21 +1,20 @@
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"));
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 = (0, read_file_1.default)('relations', dir);
15
- core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Loading ${relations.length} relations`));
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 sdk_2.api.client.request((0, sdk_1.readRelations)());
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
- delete cleanRelation.meta.id;
27
+ cleanRelation.meta.id = undefined;
29
28
  return cleanRelation;
30
29
  });
31
30
  await addRelations(relationsToAdd);
32
31
  }
33
- core_1.ux.action.stop();
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 sdk_2.api.client.request((0, sdk_1.createRelation)(relation));
37
+ await api.client.request(createRelation(relation));
40
38
  }
41
39
  catch (error) {
42
- (0, catch_error_1.default)(error);
40
+ catchError(error);
43
41
  }
44
42
  }
45
43
  }
@@ -1,20 +1,17 @@
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 get_role_ids_1 = tslib_1.__importDefault(require("../utils/get-role-ids"));
10
- const read_file_1 = tslib_1.__importDefault(require("../utils/read-file"));
11
- async function loadRoles(dir) {
12
- const roles = (0, read_file_1.default)('roles', dir);
13
- core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Loading ${roles.length} roles`));
1
+ import { createRole, readRoles, updateRole } 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 getRoleIds from '../utils/get-role-ids.js';
7
+ import readFile from '../utils/read-file.js';
8
+ export default async function loadRoles(dir) {
9
+ const roles = readFile('roles', dir);
10
+ ux.action.start(ux.colorize(DIRECTUS_PINK, `Loading ${roles.length} roles`));
14
11
  if (roles && roles.length > 0) {
15
- const { legacyAdminRoleId, newAdminRoleId } = await (0, get_role_ids_1.default)(dir);
12
+ const { legacyAdminRoleId, newAdminRoleId } = await getRoleIds(dir);
16
13
  // Fetch existing roles
17
- const existingRoles = await sdk_2.api.client.request((0, sdk_1.readRoles)({
14
+ const existingRoles = await api.client.request(readRoles({
18
15
  limit: -1,
19
16
  }));
20
17
  const existingRoleIds = new Set(existingRoles.map(role => role.id));
@@ -24,8 +21,8 @@ async function loadRoles(dir) {
24
21
  .filter(role => !existingRoleNames.has(role.name.toLowerCase())) // Filter out roles with existing names
25
22
  .map(role => {
26
23
  const r = { ...role };
27
- delete r.users; // Alias field. User roles will be applied when the users are loaded.
28
- delete r.parent; // We need to load all roles first
24
+ r.users = undefined; // Alias field. User roles will be applied when the users are loaded.
25
+ r.parent = undefined; // We need to load all roles first
29
26
  return r;
30
27
  });
31
28
  for await (const role of cleanedUpRoles) {
@@ -34,13 +31,13 @@ async function loadRoles(dir) {
34
31
  continue;
35
32
  }
36
33
  // Create new role
37
- await sdk_2.api.client.request((0, sdk_1.createRole)(role));
34
+ await api.client.request(createRole(role));
38
35
  // Add the new role ID and name to our sets of existing roles
39
36
  existingRoleIds.add(role.id);
40
37
  existingRoleNames.add(role.name.toLowerCase());
41
38
  }
42
39
  catch (error) {
43
- (0, catch_error_1.default)(error);
40
+ catchError(error);
44
41
  }
45
42
  }
46
43
  // Now add in any parent fields
@@ -52,13 +49,12 @@ async function loadRoles(dir) {
52
49
  role.parent = newAdminRoleId;
53
50
  }
54
51
  const simplifiedRole = { parent: role.parent };
55
- await sdk_2.api.client.request((0, sdk_1.updateRole)(role.id, simplifiedRole));
52
+ await api.client.request(updateRole(role.id, simplifiedRole));
56
53
  }
57
54
  catch (error) {
58
- (0, catch_error_1.default)(error);
55
+ catchError(error);
59
56
  }
60
57
  }
61
58
  }
62
- core_1.ux.action.stop();
59
+ ux.action.stop();
63
60
  }
64
- exports.default = loadRoles;
@@ -1,21 +1,19 @@
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 defu_1 = require("defu");
7
- const constants_1 = require("../constants");
8
- const sdk_2 = require("../sdk");
9
- const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
10
- const read_file_1 = tslib_1.__importDefault(require("../utils/read-file"));
11
- const customDefu = (0, defu_1.createDefu)((obj, key, value) => {
1
+ import { readSettings, updateSettings } from '@directus/sdk';
2
+ import { ux } from '@oclif/core';
3
+ import { createDefu } from 'defu';
4
+ import { DIRECTUS_PINK } from '../constants.js';
5
+ import { api } from '../sdk.js';
6
+ import catchError from '../utils/catch-error.js';
7
+ import readFile from '../utils/read-file.js';
8
+ // Cast ux to any to bypass type errors
9
+ const customDefu = createDefu((obj, key, value) => {
12
10
  if (Array.isArray(obj[key]) && Array.isArray(value)) {
13
- // @ts-expect-error
11
+ // @ts-ignore - ignore
14
12
  obj[key] = mergeArrays(key, obj[key], value);
15
13
  return true;
16
14
  }
17
15
  if (typeof obj[key] === 'string' && typeof value === 'string') {
18
- // @ts-expect-error
16
+ // @ts-ignore - ignore
19
17
  obj[key] = mergeJsonStrings(obj[key], value);
20
18
  return true;
21
19
  }
@@ -42,17 +40,16 @@ function mergeJsonStrings(current, incoming) {
42
40
  return incoming; // If not valid JSON, return the incoming value
43
41
  }
44
42
  }
45
- async function loadSettings(dir) {
46
- core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, 'Loading settings'));
47
- const settings = (0, read_file_1.default)('settings', dir);
43
+ export default async function loadSettings(dir) {
44
+ ux.action.start(ux.colorize(DIRECTUS_PINK, 'Loading settings'));
45
+ const settings = readFile('settings', dir);
48
46
  try {
49
- const currentSettings = await sdk_2.api.client.request((0, sdk_1.readSettings)());
47
+ const currentSettings = await api.client.request(readSettings());
50
48
  const mergedSettings = customDefu(currentSettings, settings);
51
- await sdk_2.api.client.request((0, sdk_1.updateSettings)(mergedSettings));
49
+ await api.client.request(updateSettings(mergedSettings));
52
50
  }
53
51
  catch (error) {
54
- (0, catch_error_1.default)(error);
52
+ catchError(error);
55
53
  }
56
- core_1.ux.action.stop();
54
+ ux.action.stop();
57
55
  }
58
- exports.default = loadSettings;
@@ -1,18 +1,15 @@
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 loadTranslations(dir) {
11
- const translations = (0, read_file_1.default)('translations', dir);
12
- core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Loading ${translations.length} translations`));
1
+ import { createTranslations, readTranslations } 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 loadTranslations(dir) {
8
+ const translations = readFile('translations', dir);
9
+ ux.action.start(ux.colorize(DIRECTUS_PINK, `Loading ${translations.length} translations`));
13
10
  if (translations && translations.length > 0) {
14
11
  // Fetch existing translations
15
- const existingTranslations = await sdk_2.api.client.request((0, sdk_1.readTranslations)({
12
+ const existingTranslations = await api.client.request(readTranslations({
16
13
  limit: -1,
17
14
  }));
18
15
  const existingTranslationKeys = new Set(existingTranslations.map(t => `${t.language}_${t.key}`));
@@ -25,16 +22,15 @@ async function loadTranslations(dir) {
25
22
  });
26
23
  if (newTranslations.length > 0) {
27
24
  try {
28
- await sdk_2.api.client.request((0, sdk_1.createTranslations)(newTranslations));
25
+ await api.client.request(createTranslations(newTranslations));
29
26
  }
30
27
  catch (error) {
31
- (0, catch_error_1.default)(error);
28
+ catchError(error);
32
29
  }
33
30
  }
34
31
  else {
35
- // ux.info('-- No new translations to create')
32
+ // ux.stdout('-- No new translations to create')
36
33
  }
37
34
  }
38
- core_1.ux.action.stop();
35
+ ux.action.stop();
39
36
  }
40
- exports.default = loadTranslations;