directus-template-cli 0.6.0-beta.2 → 0.7.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.
Files changed (114) hide show
  1. package/README.md +0 -14
  2. package/bin/dev.js +6 -0
  3. package/bin/run.js +5 -0
  4. package/dist/commands/apply.d.ts +17 -17
  5. package/dist/commands/apply.js +166 -174
  6. package/dist/commands/base.d.ts +15 -0
  7. package/dist/commands/base.js +45 -0
  8. package/dist/commands/extract.d.ts +16 -9
  9. package/dist/commands/extract.js +81 -100
  10. package/dist/commands/init.d.ts +42 -0
  11. package/dist/commands/init.js +241 -0
  12. package/dist/flags/common.d.ts +8 -7
  13. package/dist/flags/common.js +13 -11
  14. package/dist/index.js +1 -5
  15. package/dist/lib/constants.d.ts +18 -0
  16. package/dist/lib/constants.js +25 -6
  17. package/dist/lib/extract/extract-access.js +11 -15
  18. package/dist/lib/extract/extract-assets.js +20 -25
  19. package/dist/lib/extract/extract-collections.js +12 -16
  20. package/dist/lib/extract/extract-content.d.ts +1 -1
  21. package/dist/lib/extract/extract-content.js +17 -26
  22. package/dist/lib/extract/extract-dashboards.js +22 -28
  23. package/dist/lib/extract/extract-extensions.js +12 -16
  24. package/dist/lib/extract/extract-fields.js +12 -16
  25. package/dist/lib/extract/extract-files.js +15 -19
  26. package/dist/lib/extract/extract-flows.js +22 -28
  27. package/dist/lib/extract/extract-folders.js +15 -19
  28. package/dist/lib/extract/extract-permissions.js +12 -16
  29. package/dist/lib/extract/extract-policies.js +12 -16
  30. package/dist/lib/extract/extract-presets.js +12 -16
  31. package/dist/lib/extract/extract-relations.js +14 -18
  32. package/dist/lib/extract/extract-roles.js +15 -19
  33. package/dist/lib/extract/extract-schema.js +17 -21
  34. package/dist/lib/extract/extract-settings.js +12 -16
  35. package/dist/lib/extract/extract-translations.js +12 -16
  36. package/dist/lib/extract/extract-users.js +15 -19
  37. package/dist/lib/extract/index.d.ts +1 -6
  38. package/dist/lib/extract/index.js +47 -58
  39. package/dist/lib/init/config.d.ts +3 -0
  40. package/dist/lib/init/config.js +12 -0
  41. package/dist/lib/init/index.d.ts +10 -0
  42. package/dist/lib/init/index.js +192 -0
  43. package/dist/lib/init/types.d.ts +30 -0
  44. package/dist/lib/init/types.js +1 -0
  45. package/dist/lib/load/apply-flags.js +17 -23
  46. package/dist/lib/load/index.d.ts +1 -12
  47. package/dist/lib/load/index.js +40 -44
  48. package/dist/lib/load/load-access.js +15 -20
  49. package/dist/lib/load/load-collections.d.ts +2 -0
  50. package/dist/lib/load/load-collections.js +29 -32
  51. package/dist/lib/load/load-dashboards.js +19 -25
  52. package/dist/lib/load/load-data.js +43 -49
  53. package/dist/lib/load/load-extensions.js +30 -38
  54. package/dist/lib/load/load-files.js +20 -24
  55. package/dist/lib/load/load-flows.js +23 -29
  56. package/dist/lib/load/load-folders.js +16 -20
  57. package/dist/lib/load/load-permissions.js +13 -17
  58. package/dist/lib/load/load-policies.js +14 -18
  59. package/dist/lib/load/load-presets.js +14 -18
  60. package/dist/lib/load/load-relations.d.ts +2 -0
  61. package/dist/lib/load/load-relations.js +16 -18
  62. package/dist/lib/load/load-roles.js +19 -23
  63. package/dist/lib/load/load-settings.js +18 -21
  64. package/dist/lib/load/load-translations.js +14 -18
  65. package/dist/lib/load/load-users.js +21 -25
  66. package/dist/lib/load/update-required-fields.js +13 -17
  67. package/dist/lib/sdk.d.ts +1 -2
  68. package/dist/lib/sdk.js +27 -27
  69. package/dist/lib/types/extension.js +1 -2
  70. package/dist/lib/types.d.ts +18 -0
  71. package/dist/lib/types.js +1 -0
  72. package/dist/lib/utils/animated-bunny.d.ts +2 -0
  73. package/dist/lib/utils/animated-bunny.js +62 -0
  74. package/dist/lib/utils/auth.d.ts +8 -6
  75. package/dist/lib/utils/auth.js +48 -39
  76. package/dist/lib/utils/catch-error.js +8 -11
  77. package/dist/lib/utils/check-template.js +4 -8
  78. package/dist/lib/utils/chunk-array.js +1 -5
  79. package/dist/lib/utils/ensure-dir.d.ts +2 -0
  80. package/dist/lib/utils/ensure-dir.js +11 -0
  81. package/dist/lib/utils/filter-fields.js +1 -4
  82. package/dist/lib/utils/get-role-ids.d.ts +1 -1
  83. package/dist/lib/utils/get-role-ids.js +7 -12
  84. package/dist/lib/utils/get-template.js +33 -36
  85. package/dist/lib/utils/logger.js +11 -13
  86. package/dist/lib/utils/open-url.js +5 -8
  87. package/dist/lib/utils/parse-github-url.d.ts +19 -0
  88. package/dist/lib/utils/parse-github-url.js +89 -0
  89. package/dist/lib/utils/path.js +6 -10
  90. package/dist/lib/utils/protected-domains.js +1 -4
  91. package/dist/lib/utils/read-file.js +8 -12
  92. package/dist/lib/utils/read-templates.js +9 -15
  93. package/dist/lib/utils/sanitize-flags.d.ts +3 -0
  94. package/dist/lib/utils/sanitize-flags.js +4 -0
  95. package/dist/lib/utils/system-fields.js +19 -22
  96. package/dist/lib/utils/template-config.d.ts +16 -0
  97. package/dist/lib/utils/template-config.js +34 -0
  98. package/dist/lib/utils/template-defaults.d.ts +1 -1
  99. package/dist/lib/utils/template-defaults.js +5 -14
  100. package/dist/lib/utils/transform-github-url.js +1 -5
  101. package/dist/lib/utils/validate-url.js +3 -6
  102. package/dist/lib/utils/wait.d.ts +7 -0
  103. package/dist/lib/utils/wait.js +9 -0
  104. package/dist/lib/utils/write-to-file.js +8 -11
  105. package/dist/services/docker.d.ts +23 -0
  106. package/dist/services/docker.js +187 -0
  107. package/dist/services/github.d.ts +18 -0
  108. package/dist/services/github.js +88 -0
  109. package/dist/services/posthog.d.ts +37 -0
  110. package/dist/services/posthog.js +104 -0
  111. package/oclif.manifest.json +102 -23
  112. package/package.json +46 -29
  113. package/bin/dev +0 -17
  114. package/bin/run +0 -5
@@ -1,19 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadPanels = 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 loadDashboards(dir) {
12
- const dashboards = (0, read_file_1.default)('dashboards', dir);
13
- core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Loading ${dashboards.length} dashboards`));
1
+ import { createDashboard, createPanel, readDashboards, readPanels } 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 loadDashboards(dir) {
8
+ const dashboards = readFile('dashboards', dir);
9
+ ux.action.start(ux.colorize(DIRECTUS_PINK, `Loading ${dashboards.length} dashboards`));
14
10
  if (dashboards && dashboards.length > 0) {
15
11
  // Fetch existing dashboards
16
- const existingDashboards = await sdk_2.api.client.request((0, sdk_1.readDashboards)({
12
+ const existingDashboards = await api.client.request(readDashboards({
17
13
  limit: -1,
18
14
  }));
19
15
  const existingDashboardIds = new Set(existingDashboards.map(dashboard => dashboard.id));
@@ -29,22 +25,21 @@ async function loadDashboards(dir) {
29
25
  });
30
26
  await Promise.all(filteredDashboards.map(async (dashboard) => {
31
27
  try {
32
- await sdk_2.api.client.request((0, sdk_1.createDashboard)(dashboard));
28
+ await api.client.request(createDashboard(dashboard));
33
29
  }
34
30
  catch (error) {
35
- (0, catch_error_1.default)(error);
31
+ catchError(error);
36
32
  }
37
33
  }));
38
34
  await loadPanels(dir);
39
- core_1.ux.action.stop();
35
+ ux.action.stop();
40
36
  }
41
37
  }
42
- exports.default = loadDashboards;
43
- async function loadPanels(dir) {
44
- const panels = (0, read_file_1.default)('panels', dir);
45
- core_1.ux.action.status = `Loading ${panels.length} panels`;
38
+ export async function loadPanels(dir) {
39
+ const panels = readFile('panels', dir);
40
+ ux.action.status = `Loading ${panels.length} panels`;
46
41
  // Fetch existing panels
47
- const existingPanels = await sdk_2.api.client.request((0, sdk_1.readPanels)({
42
+ const existingPanels = await api.client.request(readPanels({
48
43
  limit: -1,
49
44
  }));
50
45
  const existingPanelIds = new Set(existingPanels.map(panel => panel.id));
@@ -56,11 +51,10 @@ async function loadPanels(dir) {
56
51
  });
57
52
  await Promise.all(filteredPanels.map(async (panel) => {
58
53
  try {
59
- await sdk_2.api.client.request((0, sdk_1.createPanel)(panel));
54
+ await api.client.request(createPanel(panel));
60
55
  }
61
56
  catch (error) {
62
- (0, catch_error_1.default)(error);
57
+ catchError(error);
63
58
  }
64
59
  }));
65
60
  }
66
- exports.loadPanels = loadPanels;
@@ -1,27 +1,23 @@
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 node_path_1 = tslib_1.__importDefault(require("node:path"));
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 chunk_array_1 = require("../utils/chunk-array");
11
- const read_file_1 = tslib_1.__importDefault(require("../utils/read-file"));
1
+ import { createItems, readItems, updateItemsBatch, updateSingleton } from '@directus/sdk';
2
+ import { ux } from '@oclif/core';
3
+ import path from 'pathe';
4
+ import { DIRECTUS_PINK } from '../constants.js';
5
+ import { api } from '../sdk.js';
6
+ import catchError from '../utils/catch-error.js';
7
+ import { chunkArray } from '../utils/chunk-array.js';
8
+ import readFile from '../utils/read-file.js';
12
9
  const BATCH_SIZE = 50;
13
- async function loadData(dir) {
14
- const collections = (0, read_file_1.default)('collections', dir);
15
- core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Loading data for ${collections.length} collections`));
10
+ export default async function loadData(dir) {
11
+ const collections = readFile('collections', dir);
12
+ ux.action.start(ux.colorize(DIRECTUS_PINK, `Loading data for ${collections.length} collections`));
16
13
  await loadSkeletonRecords(dir);
17
14
  await loadFullData(dir);
18
15
  await loadSingletons(dir);
19
- core_1.ux.action.stop();
16
+ ux.action.stop();
20
17
  }
21
- exports.default = loadData;
22
18
  async function loadSkeletonRecords(dir) {
23
- core_1.ux.action.status = 'Loading skeleton records';
24
- const collections = (0, read_file_1.default)('collections', dir);
19
+ ux.action.status = 'Loading skeleton records';
20
+ const collections = readFile('collections', dir);
25
21
  const primaryKeyMap = await getCollectionPrimaryKeys(dir);
26
22
  const userCollections = collections
27
23
  .filter(item => !item.collection.startsWith('directus_', 0))
@@ -30,21 +26,21 @@ async function loadSkeletonRecords(dir) {
30
26
  await Promise.all(userCollections.map(async (collection) => {
31
27
  const name = collection.collection;
32
28
  const primaryKeyField = getPrimaryKey(primaryKeyMap, name);
33
- const sourceDir = node_path_1.default.resolve(dir, 'content');
34
- const data = (0, read_file_1.default)(name, sourceDir);
29
+ const sourceDir = path.resolve(dir, 'content');
30
+ const data = readFile(name, sourceDir);
35
31
  // Fetch existing primary keys
36
32
  const existingPrimaryKeys = await getExistingPrimaryKeys(name, primaryKeyField);
37
33
  // Filter out existing records
38
34
  const newData = data.filter(entry => !existingPrimaryKeys.has(entry[primaryKeyField]));
39
35
  if (newData.length === 0) {
40
- // ux.log(`${ux.colorize('dim', '--')} Skipping ${name}: No new records to add`)
36
+ // ux.stdout(`${ux.colorize('dim', '--')} Skipping ${name}: No new records to add`)
41
37
  return;
42
38
  }
43
- const batches = (0, chunk_array_1.chunkArray)(newData, BATCH_SIZE).map(batch => batch.map(entry => ({ [primaryKeyField]: entry[primaryKeyField] })));
44
- await Promise.all(batches.map(batch => uploadBatch(name, batch, sdk_1.createItems)));
45
- // ux.log(`${ux.colorize('dim', '--')} Added ${newData.length} new skeleton records to ${name}`)
39
+ const batches = chunkArray(newData, BATCH_SIZE).map(batch => batch.map(entry => ({ [primaryKeyField]: entry[primaryKeyField] })));
40
+ await Promise.all(batches.map(batch => uploadBatch(name, batch, createItems)));
41
+ // ux.stdout(`${ux.colorize('dim', '--')} Added ${newData.length} new skeleton records to ${name}`)
46
42
  }));
47
- core_1.ux.action.status = 'Loaded skeleton records';
43
+ ux.action.status = 'Loaded skeleton records';
48
44
  }
49
45
  async function getExistingPrimaryKeys(collection, primaryKeyField) {
50
46
  const existingKeys = new Set();
@@ -52,8 +48,8 @@ async function getExistingPrimaryKeys(collection, primaryKeyField) {
52
48
  const limit = 1000; // Adjust based on your needs and API limits
53
49
  while (true) {
54
50
  try {
55
- // @ts-expect-error string
56
- const response = await sdk_2.api.client.request((0, sdk_1.readItems)(collection, {
51
+ // @ts-ignore
52
+ const response = await api.client.request(readItems(collection, {
57
53
  fields: [primaryKeyField],
58
54
  limit,
59
55
  page,
@@ -67,7 +63,7 @@ async function getExistingPrimaryKeys(collection, primaryKeyField) {
67
63
  page++;
68
64
  }
69
65
  catch (error) {
70
- (0, catch_error_1.default)(error);
66
+ catchError(error);
71
67
  break;
72
68
  }
73
69
  }
@@ -75,55 +71,53 @@ async function getExistingPrimaryKeys(collection, primaryKeyField) {
75
71
  }
76
72
  async function uploadBatch(collection, batch, method) {
77
73
  try {
78
- await sdk_2.api.client.request(method(collection, batch));
74
+ await api.client.request(method(collection, batch));
79
75
  }
80
76
  catch (error) {
81
- (0, catch_error_1.default)(error);
77
+ catchError(error);
82
78
  }
83
79
  }
84
80
  async function loadFullData(dir) {
85
- core_1.ux.action.status = 'Updating records with full data';
86
- const collections = (0, read_file_1.default)('collections', dir);
81
+ ux.action.status = 'Updating records with full data';
82
+ const collections = readFile('collections', dir);
87
83
  const userCollections = collections
88
84
  .filter(item => !item.collection.startsWith('directus_', 0))
89
85
  .filter(item => item.schema !== null)
90
86
  .filter(item => !item.meta.singleton);
91
87
  await Promise.all(userCollections.map(async (collection) => {
92
88
  const name = collection.collection;
93
- const sourceDir = node_path_1.default.resolve(dir, 'content');
94
- const data = (0, read_file_1.default)(name, sourceDir);
95
- const batches = (0, chunk_array_1.chunkArray)(data, BATCH_SIZE).map(batch => batch.map(({ user_created, user_updated, ...cleanedRow }) => cleanedRow));
96
- await Promise.all(batches.map(batch => uploadBatch(name, batch, sdk_1.updateItemsBatch)));
89
+ const sourceDir = path.resolve(dir, 'content');
90
+ const data = readFile(name, sourceDir);
91
+ const batches = chunkArray(data, BATCH_SIZE).map(batch => batch.map(({ user_created, user_updated, ...cleanedRow }) => cleanedRow));
92
+ await Promise.all(batches.map(batch => uploadBatch(name, batch, updateItemsBatch)));
97
93
  }));
98
- core_1.ux.action.status = 'Updated records with full data';
94
+ ux.action.status = 'Updated records with full data';
99
95
  }
100
96
  async function loadSingletons(dir) {
101
- core_1.ux.action.status = 'Loading data for singleton collections';
102
- const collections = (0, read_file_1.default)('collections', dir);
97
+ ux.action.status = 'Loading data for singleton collections';
98
+ const collections = readFile('collections', dir);
103
99
  const singletonCollections = collections
104
100
  .filter(item => !item.collection.startsWith('directus_', 0))
105
101
  .filter(item => item.meta.singleton);
106
102
  await Promise.all(singletonCollections.map(async (collection) => {
107
103
  const name = collection.collection;
108
- const sourceDir = node_path_1.default.resolve(dir, 'content');
109
- const data = (0, read_file_1.default)(name, sourceDir);
104
+ const sourceDir = path.resolve(dir, 'content');
105
+ const data = readFile(name, sourceDir);
110
106
  try {
111
107
  const { user_created, user_updated, ...cleanedData } = data;
112
- // @ts-expect-error
113
- await sdk_2.api.client.request((0, sdk_1.updateSingleton)(name, cleanedData));
108
+ await api.client.request(updateSingleton(name, cleanedData));
114
109
  }
115
110
  catch (error) {
116
- (0, catch_error_1.default)(error);
111
+ catchError(error);
117
112
  }
118
113
  }));
119
- core_1.ux.action.status = 'Loaded data for singleton collections';
114
+ ux.action.status = 'Loaded data for singleton collections';
120
115
  }
121
116
  async function getCollectionPrimaryKeys(dir) {
122
- var _a;
123
- const fields = (0, read_file_1.default)('fields', dir);
117
+ const fields = readFile('fields', dir);
124
118
  const primaryKeys = {};
125
119
  for (const field of fields) {
126
- if (field.schema && ((_a = field.schema) === null || _a === void 0 ? void 0 : _a.is_primary_key)) {
120
+ if (field.schema && field.schema?.is_primary_key) {
127
121
  primaryKeys[field.collection] = field.field;
128
122
  }
129
123
  }
@@ -131,7 +125,7 @@ async function getCollectionPrimaryKeys(dir) {
131
125
  }
132
126
  function getPrimaryKey(collectionsMap, collection) {
133
127
  if (!collectionsMap[collection]) {
134
- (0, catch_error_1.default)(`Collection ${collection} not found in collections map`);
128
+ catchError(`Collection ${collection} not found in collections map`);
135
129
  }
136
130
  return collectionsMap[collection];
137
131
  }
@@ -1,14 +1,11 @@
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 { 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 sdk_2.api.client.request((0, sdk_1.customEndpoint)({
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
- core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, 'Loading extensions'));
17
+ export default async function loadExtensions(dir) {
18
+ ux.action.start(ux.colorize(DIRECTUS_PINK, 'Loading extensions'));
22
19
  try {
23
- const extensions = (0, read_file_1.default)('extensions', dir);
20
+ const extensions = readFile('extensions', dir);
24
21
  if (extensions && extensions.length > 0) {
25
- const installedExtensions = await sdk_2.api.client.request((0, sdk_1.readExtensions)());
26
- const registryExtensions = extensions.filter(ext => { var _a; return ((_a = ext.meta) === null || _a === void 0 ? void 0 : _a.source) === 'registry' && !ext.bundle; });
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 => { var _a; return ((_a = ext.meta) === null || _a === void 0 ? void 0 : _a.source) === 'local'; });
29
- const extensionsToInstall = extensions.filter(ext => {
30
- var _a;
31
- return ((_a = ext.meta) === null || _a === void 0 ? void 0 : _a.source) === 'registry'
32
- && !ext.bundle
33
- // @ts-expect-error
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
- core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Installing ${extensionsToInstall.length} extensions`));
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: (_a = ext.meta) === null || _a === void 0 ? void 0 : _a.folder,
38
+ version: ext.meta?.folder,
46
39
  });
47
- return `-- Installed ${(_b = ext.schema) === null || _b === void 0 ? void 0 : _b.name}`;
40
+ return `-- Installed ${ext.schema?.name}`;
48
41
  }
49
42
  catch (error) {
50
- (0, catch_error_1.default)(error);
51
- return `-- Failed to install ${(_c = ext.schema) === null || _c === void 0 ? void 0 : _c.name}`;
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
- core_1.ux.log(result.value);
49
+ ux.stdout(result.value);
57
50
  }
58
51
  }
59
- core_1.ux.action.stop();
60
- core_1.ux.log('Finished installing extensions');
52
+ ux.action.stop();
53
+ ux.stdout('Finished installing extensions');
61
54
  }
62
55
  else {
63
56
  // All extensions are already installed
64
- core_1.ux.log('All extensions are already installed');
57
+ ux.stdout('All extensions are already installed');
65
58
  }
66
59
  if (localExtensions.length > 0) {
67
- core_1.ux.log(`Note: ${localExtensions.length} local extensions need to be installed manually.`);
60
+ ux.stdout(`Note: ${localExtensions.length} local extensions need to be installed manually.`);
68
61
  }
69
62
  }
70
63
  }
71
64
  catch {
72
- core_1.ux.log(`${core_1.ux.colorize('dim', '--')} No extensions found or extensions file is empty. Skipping extension installation.`);
65
+ ux.stdout(`${ux.colorize('dim', '--')} No extensions found or extensions file is empty. Skipping extension installation.`);
73
66
  }
74
- core_1.ux.action.stop();
67
+ ux.action.stop();
75
68
  }
76
- exports.default = loadExtensions;
@@ -1,22 +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 formdata_node_1 = require("formdata-node");
7
- const node_fs_1 = require("node:fs");
8
- const node_path_1 = tslib_1.__importDefault(require("node:path"));
9
- const constants_1 = require("../constants");
10
- const sdk_2 = require("../sdk");
11
- const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
12
- const read_file_1 = tslib_1.__importDefault(require("../utils/read-file"));
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 sdk_2.api.client.request((0, sdk_1.readFiles)({
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 = node_path_1.default.resolve(dir, 'assets', fileName);
37
- const fileStream = new Blob([(0, node_fs_1.readFileSync)(assetPath)], { type: asset.type });
38
- const form = new formdata_node_1.FormData();
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 sdk_2.api.client.request((0, sdk_1.uploadFiles)(form));
45
+ await api.client.request(uploadFiles(form));
49
46
  }
50
47
  catch (error) {
51
- (0, catch_error_1.default)(error);
48
+ catchError(error);
52
49
  }
53
50
  }));
54
51
  }
55
52
  catch (error) {
56
- (0, catch_error_1.default)(error);
53
+ catchError(error);
57
54
  }
58
55
  }
59
- core_1.ux.action.stop();
56
+ ux.action.stop();
60
57
  }
61
- exports.default = loadFiles;
@@ -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;