directus-template-cli 0.7.0-beta.4 → 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.
Files changed (93) hide show
  1. package/bin/dev +2 -3
  2. package/bin/dev.js +3 -0
  3. package/bin/run +0 -1
  4. package/bin/run.js +5 -0
  5. package/dist/commands/apply.d.ts +17 -17
  6. package/dist/commands/apply.js +160 -173
  7. package/dist/commands/extract.d.ts +13 -7
  8. package/dist/commands/extract.js +89 -73
  9. package/dist/commands/init.d.ts +7 -7
  10. package/dist/commands/init.js +78 -80
  11. package/dist/flags/common.d.ts +7 -7
  12. package/dist/flags/common.js +8 -11
  13. package/dist/index.js +1 -5
  14. package/dist/lib/constants.js +6 -9
  15. package/dist/lib/extract/extract-access.js +11 -15
  16. package/dist/lib/extract/extract-assets.js +20 -25
  17. package/dist/lib/extract/extract-collections.js +12 -16
  18. package/dist/lib/extract/extract-content.js +14 -19
  19. package/dist/lib/extract/extract-dashboards.js +22 -28
  20. package/dist/lib/extract/extract-extensions.js +12 -16
  21. package/dist/lib/extract/extract-fields.js +13 -17
  22. package/dist/lib/extract/extract-files.js +15 -19
  23. package/dist/lib/extract/extract-flows.js +22 -28
  24. package/dist/lib/extract/extract-folders.js +15 -19
  25. package/dist/lib/extract/extract-permissions.js +12 -16
  26. package/dist/lib/extract/extract-policies.js +12 -16
  27. package/dist/lib/extract/extract-presets.js +12 -16
  28. package/dist/lib/extract/extract-relations.js +14 -18
  29. package/dist/lib/extract/extract-roles.js +15 -19
  30. package/dist/lib/extract/extract-schema.js +17 -21
  31. package/dist/lib/extract/extract-settings.js +12 -16
  32. package/dist/lib/extract/extract-translations.js +12 -16
  33. package/dist/lib/extract/extract-users.js +15 -19
  34. package/dist/lib/extract/index.js +47 -51
  35. package/dist/lib/init/config.d.ts +1 -1
  36. package/dist/lib/init/config.js +2 -5
  37. package/dist/lib/init/index.js +54 -59
  38. package/dist/lib/init/types.js +1 -2
  39. package/dist/lib/init.d.ts +1 -0
  40. package/dist/lib/init.js +2 -0
  41. package/dist/lib/load/apply-flags.js +17 -23
  42. package/dist/lib/load/index.js +40 -44
  43. package/dist/lib/load/load-access.js +15 -20
  44. package/dist/lib/load/load-collections.js +27 -32
  45. package/dist/lib/load/load-dashboards.js +19 -25
  46. package/dist/lib/load/load-data.js +43 -49
  47. package/dist/lib/load/load-extensions.js +30 -38
  48. package/dist/lib/load/load-files.js +20 -24
  49. package/dist/lib/load/load-flows.js +23 -29
  50. package/dist/lib/load/load-folders.js +16 -20
  51. package/dist/lib/load/load-permissions.js +13 -17
  52. package/dist/lib/load/load-policies.js +14 -18
  53. package/dist/lib/load/load-presets.js +14 -18
  54. package/dist/lib/load/load-relations.d.ts +2 -0
  55. package/dist/lib/load/load-relations.js +16 -18
  56. package/dist/lib/load/load-roles.js +19 -23
  57. package/dist/lib/load/load-settings.js +18 -21
  58. package/dist/lib/load/load-translations.js +14 -18
  59. package/dist/lib/load/load-users.js +21 -25
  60. package/dist/lib/load/update-required-fields.js +13 -17
  61. package/dist/lib/sdk.d.ts +1 -2
  62. package/dist/lib/sdk.js +27 -27
  63. package/dist/lib/types/extension.js +1 -2
  64. package/dist/lib/utils/animated-bunny.js +9 -14
  65. package/dist/lib/utils/auth.d.ts +2 -2
  66. package/dist/lib/utils/auth.js +32 -33
  67. package/dist/lib/utils/catch-error.js +8 -11
  68. package/dist/lib/utils/check-template.js +4 -8
  69. package/dist/lib/utils/chunk-array.js +1 -5
  70. package/dist/lib/utils/ensure-dir.js +7 -12
  71. package/dist/lib/utils/filter-fields.js +1 -4
  72. package/dist/lib/utils/get-role-ids.d.ts +1 -1
  73. package/dist/lib/utils/get-role-ids.js +7 -12
  74. package/dist/lib/utils/get-template.js +33 -37
  75. package/dist/lib/utils/logger.js +11 -13
  76. package/dist/lib/utils/open-url.js +5 -8
  77. package/dist/lib/utils/parse-github-url.js +4 -9
  78. package/dist/lib/utils/path.js +6 -10
  79. package/dist/lib/utils/protected-domains.js +1 -4
  80. package/dist/lib/utils/read-file.js +8 -12
  81. package/dist/lib/utils/read-templates.js +9 -15
  82. package/dist/lib/utils/system-fields.js +19 -22
  83. package/dist/lib/utils/template-defaults.d.ts +1 -1
  84. package/dist/lib/utils/template-defaults.js +5 -14
  85. package/dist/lib/utils/transform-github-url.js +1 -5
  86. package/dist/lib/utils/validate-url.js +3 -6
  87. package/dist/lib/utils/wait.js +1 -5
  88. package/dist/lib/utils/write-to-file.js +8 -11
  89. package/dist/services/docker.js +11 -18
  90. package/dist/services/github.d.ts +1 -1
  91. package/dist/services/github.js +8 -12
  92. package/oclif.manifest.json +4 -4
  93. package/package.json +36 -32
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const protected_domains_1 = require("./protected-domains");
4
- function validateUrl(url) {
1
+ import { protectedDomains } from './protected-domains.js';
2
+ export default function validateUrl(url) {
5
3
  try {
6
4
  const parsedUrl = new URL(url);
7
- return !protected_domains_1.protectedDomains.includes(parsedUrl.hostname);
5
+ return !protectedDomains.includes(parsedUrl.hostname);
8
6
  }
9
7
  catch {
10
8
  return false;
11
9
  }
12
10
  }
13
- exports.default = validateUrl;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.waitFor = void 0;
4
- async function waitFor(checkFn, options = {}) {
1
+ export async function waitFor(checkFn, options = {}) {
5
2
  const { errorMessage = 'Operation timed out', interval = 2000, maxAttempts = 30, } = options;
6
3
  for (let i = 0; i < maxAttempts; i++) {
7
4
  if (await checkFn())
@@ -10,4 +7,3 @@ async function waitFor(checkFn, options = {}) {
10
7
  }
11
8
  throw new Error(errorMessage);
12
9
  }
13
- exports.waitFor = waitFor;
@@ -1,23 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
5
- const node_path_1 = tslib_1.__importDefault(require("node:path"));
6
- exports.default = async (fileName, data, dir) => {
1
+ import fs from 'node:fs';
2
+ import path from 'pathe';
3
+ export default async (fileName, data, dir) => {
7
4
  const folders = fileName.split('/');
8
5
  const endFileName = folders.pop();
9
6
  const folderPath = folders.join('/');
10
7
  // Generate the full path where you want to write the file
11
- const fullPath = node_path_1.default.join(dir, folderPath);
8
+ const fullPath = path.join(dir, folderPath);
12
9
  // Check if the directory exists. Create if it doesn't.
13
- if (!node_fs_1.default.existsSync(fullPath)) {
14
- node_fs_1.default.mkdirSync(fullPath, { recursive: true });
10
+ if (!fs.existsSync(fullPath)) {
11
+ fs.mkdirSync(fullPath, { recursive: true });
15
12
  }
16
13
  // Construct the full file path
17
- const fullFilePath = node_path_1.default.join(fullPath, `${endFileName}.json`);
14
+ const fullFilePath = path.join(fullPath, `${endFileName}.json`);
18
15
  try {
19
16
  // Write the file
20
- await node_fs_1.default.promises.writeFile(fullFilePath, JSON.stringify(data, null, 2));
17
+ await fs.promises.writeFile(fullFilePath, JSON.stringify(data, null, 2));
21
18
  // console.log(`Wrote ${fullFilePath}`);
22
19
  }
23
20
  catch (error) {
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDocker = void 0;
4
- const tslib_1 = require("tslib");
5
- const prompts_1 = require("@clack/prompts");
6
- const catch_error_1 = tslib_1.__importDefault(require("../lib/utils/catch-error"));
7
- const wait_1 = require("../lib/utils/wait");
1
+ import { spinner } from '@clack/prompts';
2
+ import { execa } from 'execa';
3
+ import catchError from '../lib/utils/catch-error.js';
4
+ import { waitFor } from '../lib/utils/wait.js';
8
5
  /**
9
6
  * Check if Docker is installed and running
10
7
  * @returns {Promise<DockerCheckResult>} Docker installation and running status
@@ -12,7 +9,6 @@ const wait_1 = require("../lib/utils/wait");
12
9
  async function checkDocker() {
13
10
  try {
14
11
  // Check if Docker is installed
15
- const { execa } = await Promise.resolve().then(() => tslib_1.__importStar(require('execa')));
16
12
  const versionResult = await execa('docker', ['--version']);
17
13
  const isInstalled = versionResult.exitCode === 0;
18
14
  if (!isInstalled) {
@@ -43,9 +39,8 @@ async function checkDocker() {
43
39
  */
44
40
  async function startContainers(cwd) {
45
41
  try {
46
- const { execa } = await Promise.resolve().then(() => tslib_1.__importStar(require('execa')));
47
42
  // ux.action.start('Starting Docker containers')
48
- const s = (0, prompts_1.spinner)();
43
+ const s = spinner();
49
44
  s.start('Starting Docker containers');
50
45
  return execa('docker-compose', ['up', '-d'], {
51
46
  cwd,
@@ -55,7 +50,7 @@ async function startContainers(cwd) {
55
50
  });
56
51
  }
57
52
  catch (error) {
58
- (0, catch_error_1.default)(error, {
53
+ catchError(error, {
59
54
  context: { cwd, function: 'startContainers' },
60
55
  fatal: true,
61
56
  logToFile: true,
@@ -70,14 +65,13 @@ async function startContainers(cwd) {
70
65
  */
71
66
  async function stopContainers(cwd) {
72
67
  try {
73
- const { execa } = await Promise.resolve().then(() => tslib_1.__importStar(require('execa')));
74
68
  return execa('docker-compose', ['down'], {
75
69
  cwd,
76
70
  // stdio: 'inherit',
77
71
  }).then(() => { });
78
72
  }
79
73
  catch (error) {
80
- (0, catch_error_1.default)(error, {
74
+ catchError(error, {
81
75
  context: { cwd, function: 'stopContainers' },
82
76
  fatal: false,
83
77
  logToFile: true,
@@ -92,10 +86,10 @@ async function stopContainers(cwd) {
92
86
  */
93
87
  function createWaitForHealthy(config) {
94
88
  async function waitForHealthy(healthCheckUrl) {
95
- const s = (0, prompts_1.spinner)();
89
+ const s = spinner();
96
90
  s.start('Waiting for Directus to be ready.');
97
91
  try {
98
- await (0, wait_1.waitFor)(async () => {
92
+ await waitFor(async () => {
99
93
  try {
100
94
  const response = await fetch(healthCheckUrl);
101
95
  return response.ok;
@@ -113,7 +107,7 @@ function createWaitForHealthy(config) {
113
107
  }
114
108
  catch (error) {
115
109
  s.stop('');
116
- (0, catch_error_1.default)(error, {
110
+ catchError(error, {
117
111
  context: { function: 'waitForHealthy', url: healthCheckUrl },
118
112
  fatal: true,
119
113
  logToFile: true,
@@ -128,7 +122,7 @@ function createWaitForHealthy(config) {
128
122
  * @param {DockerConfig} config - The Docker configuration
129
123
  * @returns {DockerService} - Returns a Docker service instance
130
124
  */
131
- function createDocker(config) {
125
+ export function createDocker(config) {
132
126
  return {
133
127
  checkDocker,
134
128
  startContainers,
@@ -136,4 +130,3 @@ function createDocker(config) {
136
130
  waitForHealthy: createWaitForHealthy(config),
137
131
  };
138
132
  }
139
- exports.createDocker = createDocker;
@@ -1,4 +1,4 @@
1
- import { parseGitHubUrl } from '../lib/utils/parse-github-url';
1
+ import { parseGitHubUrl } from '../lib/utils/parse-github-url.js';
2
2
  interface GitHubUrlParts {
3
3
  owner: string;
4
4
  path?: string;
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createGitHub = void 0;
4
- const rest_1 = require("@octokit/rest");
5
- const constants_1 = require("../lib/constants");
6
- const parse_github_url_1 = require("../lib/utils/parse-github-url");
7
- function createGitHub(token) {
8
- const octokit = new rest_1.Octokit({
1
+ import { Octokit } from '@octokit/rest';
2
+ import { DEFAULT_REPO } from '../lib/constants.js';
3
+ import { parseGitHubUrl } from '../lib/utils/parse-github-url.js';
4
+ export function createGitHub(token) {
5
+ const octokit = new Octokit({
9
6
  auth: token,
10
7
  });
11
8
  /**
@@ -15,7 +12,7 @@ function createGitHub(token) {
15
12
  * @returns The directories for the template.
16
13
  */
17
14
  async function getTemplateDirectories(template, customUrl) {
18
- const repo = customUrl ? (0, parse_github_url_1.parseGitHubUrl)(customUrl) : constants_1.DEFAULT_REPO;
15
+ const repo = customUrl ? parseGitHubUrl(customUrl) : DEFAULT_REPO;
19
16
  const templatePath = repo.path ? `${repo.path}/${template}` : template;
20
17
  const { data } = await octokit.rest.repos.getContent({
21
18
  owner: repo.owner,
@@ -35,7 +32,7 @@ function createGitHub(token) {
35
32
  * @returns The templates for the repository.
36
33
  */
37
34
  async function getTemplates(customUrl) {
38
- const repo = customUrl ? (0, parse_github_url_1.parseGitHubUrl)(customUrl) : constants_1.DEFAULT_REPO;
35
+ const repo = customUrl ? parseGitHubUrl(customUrl) : DEFAULT_REPO;
39
36
  const { data } = await octokit.rest.repos.getContent({
40
37
  owner: repo.owner,
41
38
  path: repo.path || '',
@@ -51,7 +48,6 @@ function createGitHub(token) {
51
48
  return {
52
49
  getTemplateDirectories,
53
50
  getTemplates,
54
- parseGitHubUrl: parse_github_url_1.parseGitHubUrl,
51
+ parseGitHubUrl,
55
52
  };
56
53
  }
57
- exports.createGitHub = createGitHub;
@@ -169,7 +169,7 @@
169
169
  "pluginType": "core",
170
170
  "strict": true,
171
171
  "enableJsonFlag": false,
172
- "isESM": false,
172
+ "isESM": true,
173
173
  "relativePath": [
174
174
  "dist",
175
175
  "commands",
@@ -272,7 +272,7 @@
272
272
  "pluginType": "core",
273
273
  "strict": true,
274
274
  "enableJsonFlag": false,
275
- "isESM": false,
275
+ "isESM": true,
276
276
  "relativePath": [
277
277
  "dist",
278
278
  "commands",
@@ -351,7 +351,7 @@
351
351
  "pluginType": "core",
352
352
  "strict": true,
353
353
  "enableJsonFlag": false,
354
- "isESM": false,
354
+ "isESM": true,
355
355
  "relativePath": [
356
356
  "dist",
357
357
  "commands",
@@ -359,5 +359,5 @@
359
359
  ]
360
360
  }
361
361
  },
362
- "version": "0.7.0-beta.4"
362
+ "version": "0.7.0-beta.5"
363
363
  }
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "directus-template-cli",
3
- "version": "0.7.0-beta.4",
3
+ "version": "0.7.0-beta.5",
4
4
  "description": "CLI Utility for applying templates to a Directus instance.",
5
5
  "author": "bryantgillespie @bryantgillespie",
6
+ "type": "module",
6
7
  "bin": {
7
- "directus-template-cli": "./bin/run"
8
+ "directus-template-cli": "./bin/run.js"
8
9
  },
9
10
  "homepage": "https://github.com/directus-community/directus-template-cli",
10
11
  "license": "MIT",
@@ -18,42 +19,45 @@
18
19
  ],
19
20
  "dependencies": {
20
21
  "@clack/prompts": "^0.10.0",
21
- "@directus/sdk": "^17.0.1",
22
- "@oclif/core": "^3.18.1",
23
- "@oclif/plugin-help": "^6.0.12",
24
- "@oclif/plugin-plugins": "^4.1.22",
22
+ "@directus/sdk": "^19.0.1",
23
+ "@inquirer/prompts": "^7.3.3",
24
+ "@oclif/core": "^4.2.9",
25
+ "@oclif/plugin-help": "^6.2.26",
26
+ "@oclif/plugin-plugins": "^5.4.34",
25
27
  "@octokit/rest": "^21.1.1",
28
+ "@sindresorhus/slugify": "^2.2.1",
26
29
  "bottleneck": "^2.19.5",
27
- "chalk": "4.1.2",
30
+ "chalk": "5.4.1",
31
+ "cli-progress": "^3.12.0",
28
32
  "defu": "^6.1.4",
29
- "dotenv": "^16.4.1",
30
- "execa": "^9.5.2",
33
+ "dotenv": "^16.4.7",
34
+ "execa": "9.5.2",
31
35
  "formdata-node": "^6.0.3",
32
- "giget": "^1.2.1",
36
+ "giget": "^2.0.0",
33
37
  "glob": "^11.0.1",
34
- "inquirer": "^8.2.5",
35
38
  "log-update": "^6.1.0",
36
- "nypm": "^0.5.2",
37
- "picocolors": "^1.1.1",
38
- "pkg-types": "^1.3.1",
39
- "slugify": "^1.6.6"
39
+ "nypm": "^0.6.0",
40
+ "pathe": "^2.0.3",
41
+ "posthog-node": "^4.10.1"
40
42
  },
41
43
  "devDependencies": {
42
- "@directus/types": "^12.0.1",
43
- "@oclif/test": "^3.1.13",
44
- "@types/chai": "^4.3.11",
45
- "@types/mocha": "^10.0.6",
46
- "@types/node": "^20.11.10",
47
- "chai": "^5.0.3",
48
- "eslint": "^8.56.0",
49
- "eslint-config-oclif": "^5.0.0",
50
- "eslint-config-oclif-typescript": "^3.0.41",
51
- "mocha": "^10.2.0",
52
- "oclif": "^4.4.2",
44
+ "@oclif/prettier-config": "^0.2.1",
45
+ "@directus/types": "^13.0.0",
46
+ "@oclif/test": "^4",
47
+ "@types/chai": "^5.2.0",
48
+ "@types/mocha": "^10",
49
+ "@types/node": "^18",
50
+ "chai": "^5.2.0",
51
+ "eslint": "^9",
52
+ "eslint-config-oclif": "^5",
53
+ "eslint-config-oclif-typescript": "^3",
54
+ "eslint-config-prettier": "^9",
55
+ "mocha": "^10",
56
+ "oclif": "^4",
53
57
  "shx": "^0.3.3",
54
- "ts-node": "^10.9.2",
55
- "tslib": "^2.6.2",
56
- "typescript": "^5.3.3"
58
+ "ts-node": "^10",
59
+ "tslib": "^2.8.1",
60
+ "typescript": "^5.8.2"
57
61
  },
58
62
  "oclif": {
59
63
  "bin": "directus-template-cli",
@@ -70,11 +74,11 @@
70
74
  "build": "shx rm -rf dist && tsc -b",
71
75
  "lint": "eslint . --ext .ts --config .eslintrc",
72
76
  "postpack": "shx rm -f oclif.manifest.json",
73
- "posttest": "npm run lint",
74
- "prepack": "npm run build && oclif manifest && oclif readme",
77
+ "posttest": "pnpm run lint",
78
+ "prepack": "pnpm run build && oclif manifest && oclif readme",
75
79
  "test": "mocha --forbid-only \"test/**/*.test.ts\"",
76
80
  "version": "oclif readme && git add README.md",
77
- "run": "./bin/run"
81
+ "run": "./bin/run.js"
78
82
  },
79
83
  "engines": {
80
84
  "node": ">=18.0.0"