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,71 +1,99 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.init = void 0;
4
- const tslib_1 = require("tslib");
5
- const prompts_1 = require("@clack/prompts");
6
- const core_1 = require("@oclif/core");
7
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
8
- const giget_1 = require("giget");
9
- const glob_1 = require("glob");
10
- const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
11
- const node_path_1 = tslib_1.__importDefault(require("node:path"));
12
- const nypm_1 = require("nypm");
13
- const apply_1 = tslib_1.__importDefault(require("../../commands/apply"));
14
- const docker_1 = require("../../services/docker");
15
- const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
16
- const parse_github_url_1 = require("../utils/parse-github-url");
17
- const config_1 = require("./config");
18
- async function init(dir, flags) {
1
+ import { note, outro, spinner } from '@clack/prompts';
2
+ import { ux } from '@oclif/core';
3
+ import chalk from 'chalk';
4
+ import { execa } from 'execa';
5
+ import { downloadTemplate } from 'giget';
6
+ import { glob } from 'glob';
7
+ import fs from 'node:fs';
8
+ import { detectPackageManager, installDependencies } from 'nypm';
9
+ import path from 'pathe';
10
+ import dotenv from 'dotenv';
11
+ import ApplyCommand from '../../commands/apply.js';
12
+ import { createDocker } from '../../services/docker.js';
13
+ import catchError from '../utils/catch-error.js';
14
+ import { createGigetString, parseGitHubUrl } from '../utils/parse-github-url.js';
15
+ import { readTemplateConfig } from '../utils/template-config.js';
16
+ import { DOCKER_CONFIG } from './config.js';
17
+ export async function init({ dir, flags }) {
19
18
  // Check target directory
20
19
  const shouldForce = flags.overrideDir;
21
- if (node_fs_1.default.existsSync(dir) && !shouldForce) {
20
+ if (fs.existsSync(dir) && !shouldForce) {
22
21
  throw new Error('Directory already exists. Use --override-dir to override.');
23
22
  }
24
- const frontendDir = node_path_1.default.join(dir, flags.frontend);
25
- const directusDir = node_path_1.default.join(dir, 'directus');
23
+ // If template is a URL, we need to handle it differently
24
+ const isDirectUrl = flags.template?.startsWith('http');
25
+ const directusDir = path.join(dir, 'directus');
26
26
  let template;
27
+ let packageManager = null;
27
28
  try {
28
29
  // Download the template from GitHub
29
- const parsedUrl = (0, parse_github_url_1.parseGitHubUrl)(flags.template);
30
- template = await (0, giget_1.downloadTemplate)((0, parse_github_url_1.createGigetString)(parsedUrl), {
30
+ const parsedUrl = parseGitHubUrl(flags.template);
31
+ // If it's a direct URL, we download the entire repository
32
+ // Otherwise, we use the template from the starters repo
33
+ template = await downloadTemplate(createGigetString(parsedUrl), {
31
34
  dir,
32
35
  force: shouldForce,
33
36
  });
34
- // Cleanup the template
35
- if (flags.frontend) {
36
- // Ensure directus directory exists before cleaning up
37
- if (!node_fs_1.default.existsSync(directusDir)) {
38
- node_fs_1.default.mkdirSync(directusDir, { recursive: true });
37
+ // For direct URLs, we need to check if there's a directus directory
38
+ // If not, assume the entire repo is a directus template
39
+ if (isDirectUrl) {
40
+ if (!fs.existsSync(directusDir)) {
41
+ // Move all files to directus directory
42
+ fs.mkdirSync(directusDir, { recursive: true });
43
+ const files = fs.readdirSync(dir);
44
+ for (const file of files) {
45
+ if (file !== 'directus') {
46
+ fs.renameSync(path.join(dir, file), path.join(directusDir, file));
47
+ }
48
+ }
39
49
  }
40
- // Read and parse package.json
41
- const packageJsonPath = node_path_1.default.join(dir, 'package.json');
42
- if (!node_fs_1.default.existsSync(packageJsonPath)) {
43
- throw new Error('package.json not found in template');
50
+ }
51
+ // Read template configuration
52
+ const templateInfo = readTemplateConfig(dir);
53
+ let frontendDir;
54
+ // Handle frontends based on template configuration
55
+ if (flags.frontend && templateInfo) {
56
+ // Find the selected frontend in the configuration
57
+ const selectedFrontend = templateInfo.frontendOptions.find(f => f.id === flags.frontend);
58
+ if (!selectedFrontend) {
59
+ throw new Error(`Frontend "${flags.frontend}" not found in template configuration`);
44
60
  }
45
- const packageJson = JSON.parse(node_fs_1.default.readFileSync(packageJsonPath, 'utf8'));
46
- const templateConfig = packageJson['directus:template'];
47
- // Get all frontend paths from the configuration
48
- const frontendPaths = Object.values((templateConfig === null || templateConfig === void 0 ? void 0 : templateConfig.frontends) || {})
49
- .map(frontend => frontend.path.replace(/^\.\//, ''))
50
- .filter(path => path !== flags.frontend); // Exclude the selected frontend
51
- // Remove unused frontend directories
52
- for (const frontendPath of frontendPaths) {
53
- const pathToRemove = node_path_1.default.join(dir, frontendPath);
54
- if (node_fs_1.default.existsSync(pathToRemove)) {
55
- node_fs_1.default.rmSync(pathToRemove, { recursive: true });
61
+ // Remove all frontend directories except the selected one
62
+ for (const frontend of templateInfo.frontendOptions) {
63
+ if (frontend.id !== flags.frontend) {
64
+ const pathToRemove = path.join(dir, frontend.path);
65
+ if (fs.existsSync(pathToRemove)) {
66
+ fs.rmSync(pathToRemove, { recursive: true });
67
+ }
56
68
  }
57
69
  }
70
+ // Move the selected frontend to the correct location if needed
71
+ frontendDir = path.join(dir, selectedFrontend.path);
72
+ if (frontendDir !== path.join(dir, flags.frontend)) {
73
+ fs.renameSync(frontendDir, path.join(dir, flags.frontend));
74
+ frontendDir = path.join(dir, flags.frontend);
75
+ }
58
76
  }
77
+ const directusInfo = {
78
+ email: '',
79
+ password: '',
80
+ url: '',
81
+ };
59
82
  // Find and copy all .env.example files
60
- const envFiles = glob_1.glob.sync(node_path_1.default.join(dir, '**', '.env.example'));
83
+ const envFiles = glob.sync(path.join(dir, '**', '.env.example'));
61
84
  for (const file of envFiles) {
62
85
  const envFile = file.replace('.env.example', '.env');
63
- node_fs_1.default.copyFileSync(file, envFile);
86
+ fs.copyFileSync(file, envFile);
87
+ // Read default Directus login info from .env
88
+ const parsedEnv = dotenv.parse(fs.readFileSync(file, 'utf8'));
89
+ directusInfo.email = parsedEnv.ADMIN_EMAIL;
90
+ directusInfo.password = parsedEnv.ADMIN_PASSWORD;
91
+ directusInfo.url = parsedEnv.PUBLIC_URL;
64
92
  }
65
93
  // Start Directus and apply template only if directus directory exists
66
- if (node_fs_1.default.existsSync(directusDir)) {
94
+ if (fs.existsSync(directusDir)) {
67
95
  // Initialize Docker service
68
- const dockerService = (0, docker_1.createDocker)(config_1.DOCKER_CONFIG);
96
+ const dockerService = createDocker(DOCKER_CONFIG);
69
97
  // Check if Docker is installed
70
98
  const dockerStatus = await dockerService.checkDocker();
71
99
  if (!dockerStatus.installed || !dockerStatus.running) {
@@ -73,66 +101,62 @@ async function init(dir, flags) {
73
101
  }
74
102
  try {
75
103
  await dockerService.startContainers(directusDir);
76
- const healthCheckUrl = `${config_1.DIRECTUS_CONFIG.url}:${config_1.DIRECTUS_CONFIG.port}${config_1.DOCKER_CONFIG.healthCheckEndpoint}`;
104
+ const healthCheckUrl = `${directusInfo.url}${DOCKER_CONFIG.healthCheckEndpoint}`;
77
105
  await dockerService.waitForHealthy(healthCheckUrl);
78
- const templatePath = node_path_1.default.join(directusDir, 'template');
79
- // const s = spinner()
80
- // s.start(`Attempting to apply template from: ${templatePath}`)
81
- // ux.log(`Attempting to apply template from: ${templatePath}`)
82
- await apply_1.default.run([
106
+ const templatePath = path.join(directusDir, 'template');
107
+ ux.stdout(`Attempting to apply template from: ${templatePath}`);
108
+ await ApplyCommand.run([
83
109
  '--directusUrl=http://localhost:8055',
84
110
  '-p',
85
111
  '--userEmail=admin@example.com',
86
112
  '--userPassword=d1r3ctu5',
87
- '--templateLocation=' + templatePath,
113
+ `--templateLocation=${templatePath}`,
88
114
  ]);
89
- // s.stop('Template applied!')
90
115
  }
91
116
  catch (error) {
92
- core_1.ux.error('Failed to start Directus containers or apply template');
117
+ ux.error('Failed to start Directus containers or apply template');
93
118
  throw error;
94
119
  }
95
120
  }
96
- // Install dependencies for frontend if it exists
97
- if (flags.installDeps && node_fs_1.default.existsSync(frontendDir)) {
98
- const s = (0, prompts_1.spinner)();
121
+ // Install dependencies if requested
122
+ if (flags.installDeps) {
123
+ const s = spinner();
99
124
  s.start('Installing dependencies');
100
- // ux.action.start('Installing dependencies')
101
125
  try {
102
- const packageManager = await (0, nypm_1.detectPackageManager)(frontendDir);
103
- await (0, nypm_1.installDependencies)({
104
- cwd: frontendDir,
105
- packageManager,
106
- silent: true,
107
- });
126
+ if (fs.existsSync(frontendDir)) {
127
+ packageManager = await detectPackageManager(frontendDir);
128
+ await installDependencies({
129
+ cwd: frontendDir,
130
+ packageManager,
131
+ silent: true,
132
+ });
133
+ }
108
134
  }
109
135
  catch (error) {
110
- core_1.ux.warn('Failed to install dependencies');
136
+ ux.warn('Failed to install dependencies');
111
137
  throw error;
112
138
  }
113
- // ux.action.stop()
114
139
  s.stop('Dependencies installed!');
115
140
  }
116
141
  // Initialize Git repo
117
142
  if (flags.gitInit) {
118
- const s = (0, prompts_1.spinner)();
143
+ const s = spinner();
119
144
  s.start('Initializing git repository');
120
- // ux.action.start('Initializing git repository')
121
145
  await initGit(dir);
122
- // ux.action.stop()
123
146
  s.stop('Git repository initialized!');
124
147
  }
125
148
  // Finishing up
126
- const relativeDir = node_path_1.default.relative(process.cwd(), dir);
127
- const nextSteps = `- Directus is running on http://localhost:8055 \n- Navigate to your project directory using ${chalk_1.default.cyan(`cd ${relativeDir}`)} and start developing! \n- Review the \`./README.md\` file for next steps.`;
128
- (0, prompts_1.note)(nextSteps, 'Next Steps');
129
- // ux.log('You\'ll find the following directories in your project:')
130
- // ux.log(' directus')
131
- // ux.log(`• ${flags.frontend}`)
132
- (0, prompts_1.outro)(`Problems? Join the community on Discord at ${chalk_1.default.underline(chalk_1.default.cyan('https://directus.chat'))}`);
149
+ const relativeDir = path.relative(process.cwd(), dir);
150
+ const directusText = `- Directus is running on ${directusInfo.url ?? 'http://localhost:8055'}. You can login with the email: ${chalk.cyan(directusInfo.email)} and password: ${chalk.cyan(directusInfo.password)}. \n`;
151
+ const frontendText = flags.frontend ? `- To start the frontend, run ${chalk.cyan(`cd ${flags.frontend}`)} and then ${chalk.cyan(`${packageManager?.name} run dev`)}. \n` : '';
152
+ const projectText = `- Navigate to your project directory using ${chalk.cyan(`cd ${relativeDir}`)}. \n`;
153
+ const readmeText = '- Review the \`./README.md\` file for more information and next steps.';
154
+ const nextSteps = chalk.white(`${directusText}${projectText}${frontendText}${readmeText}`);
155
+ note(nextSteps, 'Next Steps');
156
+ outro(`Problems or questions? Hop into the community on Discord at ${chalk.underline(chalk.cyan('https://directus.chat'))}`);
133
157
  }
134
158
  catch (error) {
135
- (0, catch_error_1.default)(error, {
159
+ catchError(error, {
136
160
  context: { dir, flags, function: 'init' },
137
161
  fatal: true,
138
162
  logToFile: true,
@@ -140,11 +164,10 @@ async function init(dir, flags) {
140
164
  }
141
165
  return {
142
166
  directusDir,
143
- frontendDir,
167
+ frontendDir: flags.frontend ? path.join(dir, flags.frontend) : undefined,
144
168
  template,
145
169
  };
146
170
  }
147
- exports.init = init;
148
171
  /**
149
172
  * Initialize a git repository
150
173
  * @param targetDir - The directory to initialize the git repository in
@@ -152,13 +175,10 @@ exports.init = init;
152
175
  */
153
176
  async function initGit(targetDir) {
154
177
  try {
155
- // ux.action.start('Initializing git repository')
156
- const { execa } = await Promise.resolve().then(() => tslib_1.__importStar(require('execa')));
157
178
  await execa('git', ['init'], { cwd: targetDir });
158
- // ux.action.stop()
159
179
  }
160
180
  catch (error) {
161
- (0, catch_error_1.default)(error, {
181
+ catchError(error, {
162
182
  context: { function: 'initGit', targetDir },
163
183
  fatal: false,
164
184
  logToFile: true,
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,10 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateInteractiveFlags = exports.validateProgrammaticFlags = exports.loadFlags = void 0;
4
- const tslib_1 = require("tslib");
5
- const core_1 = require("@oclif/core");
6
- const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
7
- exports.loadFlags = [
1
+ import { ux } from '@oclif/core';
2
+ import catchError from '../utils/catch-error.js';
3
+ export const loadFlags = [
8
4
  'content',
9
5
  'dashboards',
10
6
  'extensions',
@@ -15,53 +11,51 @@ exports.loadFlags = [
15
11
  'settings',
16
12
  'users',
17
13
  ];
18
- function validateProgrammaticFlags(flags) {
14
+ export function validateProgrammaticFlags(flags) {
19
15
  const { directusToken, directusUrl, templateLocation, userEmail, userPassword } = flags;
20
16
  if (!directusUrl)
21
- core_1.ux.error('Directus URL is required for programmatic mode.');
17
+ ux.error('Directus URL is required for programmatic mode.');
22
18
  if (!directusToken && (!userEmail || !userPassword))
23
- core_1.ux.error('Either Directus token or email and password are required for programmatic mode.');
19
+ ux.error('Either Directus token or email and password are required for programmatic mode.');
24
20
  if (!templateLocation)
25
- core_1.ux.error('Template location is required for programmatic mode.');
21
+ ux.error('Template location is required for programmatic mode.');
26
22
  return flags.partial ? handlePartialFlags(flags) : setAllFlagsTrue(flags);
27
23
  }
28
- exports.validateProgrammaticFlags = validateProgrammaticFlags;
29
- function validateInteractiveFlags(flags) {
24
+ export function validateInteractiveFlags(flags) {
30
25
  return flags.partial ? handlePartialFlags(flags) : setAllFlagsTrue(flags);
31
26
  }
32
- exports.validateInteractiveFlags = validateInteractiveFlags;
33
27
  function handlePartialFlags(flags) {
34
- const enabledFlags = exports.loadFlags.filter(flag => flags[flag] === true);
35
- const disabledFlags = exports.loadFlags.filter(flag => flags[flag] === false);
28
+ const enabledFlags = loadFlags.filter(flag => flags[flag] === true);
29
+ const disabledFlags = loadFlags.filter(flag => flags[flag] === false);
36
30
  if (enabledFlags.length > 0) {
37
- for (const flag of exports.loadFlags)
31
+ for (const flag of loadFlags)
38
32
  flags[flag] = enabledFlags.includes(flag);
39
33
  }
40
34
  else if (disabledFlags.length > 0) {
41
- for (const flag of exports.loadFlags)
35
+ for (const flag of loadFlags)
42
36
  flags[flag] = !disabledFlags.includes(flag);
43
37
  }
44
38
  else {
45
39
  setAllFlagsTrue(flags);
46
40
  }
47
41
  handleDependencies(flags);
48
- if (!exports.loadFlags.some(flag => flags[flag])) {
49
- (0, catch_error_1.default)(new Error('When using --partial, at least one component must be loaded.'), { fatal: true });
42
+ if (!loadFlags.some(flag => flags[flag])) {
43
+ catchError(new Error('When using --partial, at least one component must be loaded.'), { fatal: true });
50
44
  }
51
45
  return flags;
52
46
  }
53
47
  function handleDependencies(flags) {
54
48
  if (flags.content && (!flags.schema || !flags.files)) {
55
49
  flags.schema = flags.files = true;
56
- core_1.ux.warn('Content loading requires schema and files. Enabling schema and files flags.');
50
+ ux.warn('Content loading requires schema and files. Enabling schema and files flags.');
57
51
  }
58
52
  if (flags.users && !flags.permissions) {
59
53
  flags.permissions = true;
60
- core_1.ux.warn('User loading requires permissions. Enabling permissions flag.');
54
+ ux.warn('User loading requires permissions. Enabling permissions flag.');
61
55
  }
62
56
  }
63
57
  function setAllFlagsTrue(flags) {
64
- for (const flag of exports.loadFlags)
58
+ for (const flag of loadFlags)
65
59
  flags[flag] = true;
66
60
  return flags;
67
61
  }
@@ -1,13 +1,2 @@
1
- interface ApplyFlags {
2
- content: boolean;
3
- dashboards: boolean;
4
- extensions: boolean;
5
- files: boolean;
6
- flows: boolean;
7
- permissions: boolean;
8
- schema: boolean;
9
- settings: boolean;
10
- users: boolean;
11
- }
1
+ import type { ApplyFlags } from './apply-flags.js';
12
2
  export default function apply(dir: string, flags: ApplyFlags): Promise<{}>;
13
- export {};
@@ -1,68 +1,64 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const core_1 = require("@oclif/core");
5
- const check_template_1 = tslib_1.__importDefault(require("../utils/check-template"));
6
- const load_access_1 = tslib_1.__importDefault(require("./load-access"));
7
- const load_collections_1 = tslib_1.__importDefault(require("./load-collections"));
8
- const load_dashboards_1 = tslib_1.__importDefault(require("./load-dashboards"));
9
- const load_data_1 = tslib_1.__importDefault(require("./load-data"));
10
- const load_extensions_1 = tslib_1.__importDefault(require("./load-extensions"));
11
- const load_files_1 = tslib_1.__importDefault(require("./load-files"));
12
- const load_flows_1 = tslib_1.__importDefault(require("./load-flows"));
13
- const load_folders_1 = tslib_1.__importDefault(require("./load-folders"));
14
- const load_permissions_1 = tslib_1.__importDefault(require("./load-permissions"));
15
- const load_policies_1 = tslib_1.__importDefault(require("./load-policies"));
16
- const load_presets_1 = tslib_1.__importDefault(require("./load-presets"));
17
- const load_relations_1 = tslib_1.__importDefault(require("./load-relations"));
18
- const load_roles_1 = tslib_1.__importDefault(require("./load-roles"));
19
- const load_settings_1 = tslib_1.__importDefault(require("./load-settings"));
20
- const load_translations_1 = tslib_1.__importDefault(require("./load-translations"));
21
- const load_users_1 = tslib_1.__importDefault(require("./load-users"));
22
- const update_required_fields_1 = tslib_1.__importDefault(require("./update-required-fields"));
23
- async function apply(dir, flags) {
24
- const source = dir + '/src';
25
- const isTemplateOk = await (0, check_template_1.default)(source);
1
+ import { ux } from '@oclif/core';
2
+ import checkTemplate from '../utils/check-template.js';
3
+ import loadAccess from './load-access.js';
4
+ import loadCollections from './load-collections.js';
5
+ import loadDashboards from './load-dashboards.js';
6
+ import loadData from './load-data.js';
7
+ import loadExtensions from './load-extensions.js';
8
+ import loadFiles from './load-files.js';
9
+ import loadFlows from './load-flows.js';
10
+ import loadFolders from './load-folders.js';
11
+ import loadPermissions from './load-permissions.js';
12
+ import loadPolicies from './load-policies.js';
13
+ import loadPresets from './load-presets.js';
14
+ import loadRelations from './load-relations.js';
15
+ import loadRoles from './load-roles.js';
16
+ import loadSettings from './load-settings.js';
17
+ import loadTranslations from './load-translations.js';
18
+ import loadUsers from './load-users.js';
19
+ import updateRequiredFields from './update-required-fields.js';
20
+ export default async function apply(dir, flags) {
21
+ const source = `${dir}/src`;
22
+ const isTemplateOk = await checkTemplate(source);
26
23
  if (!isTemplateOk) {
27
- core_1.ux.error('The template is missing the collections, fields, or relations files. Older templates are not supported in v0.4 of directus-template-cli. Try using v0.3 to load older templates npx directus-template-cli@0.3 apply or extract the template using latest version before applying. Exiting...');
24
+ ux.error('The template is missing the collections, fields, or relations files. Older templates are not supported in v0.4 of directus-template-cli. Try using v0.3 to load older templates npx directus-template-cli@0.3 apply or extract the template using latest version before applying. Exiting...');
28
25
  }
29
26
  if (flags.schema) {
30
- await (0, load_collections_1.default)(source);
31
- await (0, load_relations_1.default)(source);
27
+ await loadCollections(source);
28
+ await loadRelations(source);
32
29
  }
33
30
  if (flags.permissions || flags.users) {
34
- await (0, load_roles_1.default)(source);
35
- await (0, load_policies_1.default)(source);
36
- await (0, load_permissions_1.default)(source);
31
+ await loadRoles(source);
32
+ await loadPolicies(source);
33
+ await loadPermissions(source);
37
34
  if (flags.users) {
38
- await (0, load_users_1.default)(source);
35
+ await loadUsers(source);
39
36
  }
40
- await (0, load_access_1.default)(source);
37
+ await loadAccess(source);
41
38
  }
42
39
  if (flags.files) {
43
- await (0, load_folders_1.default)(source);
44
- await (0, load_files_1.default)(source);
40
+ await loadFolders(source);
41
+ await loadFiles(source);
45
42
  }
46
43
  if (flags.content) {
47
- await (0, load_data_1.default)(source);
44
+ await loadData(source);
48
45
  }
49
46
  if (flags.schema) {
50
- await (0, update_required_fields_1.default)(source);
47
+ await updateRequiredFields(source);
51
48
  }
52
49
  if (flags.dashboards) {
53
- await (0, load_dashboards_1.default)(source);
50
+ await loadDashboards(source);
54
51
  }
55
52
  if (flags.flows) {
56
- await (0, load_flows_1.default)(source);
53
+ await loadFlows(source);
57
54
  }
58
55
  if (flags.settings) {
59
- await (0, load_settings_1.default)(source);
60
- await (0, load_translations_1.default)(source);
61
- await (0, load_presets_1.default)(source);
56
+ await loadSettings(source);
57
+ await loadTranslations(source);
58
+ await loadPresets(source);
62
59
  }
63
60
  if (flags.extensions) {
64
- await (0, load_extensions_1.default)(source);
61
+ await loadExtensions(source);
65
62
  }
66
63
  return {};
67
64
  }
68
- exports.default = apply;
@@ -1,25 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const core_1 = require("@oclif/core");
5
- const constants_1 = require("../constants");
6
- const sdk_1 = require("../sdk");
7
- const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
8
- const get_role_ids_1 = tslib_1.__importDefault(require("../utils/get-role-ids"));
9
- const read_file_1 = tslib_1.__importDefault(require("../utils/read-file"));
10
- async function loadAccess(dir) {
11
- const access = (0, read_file_1.default)('access', dir);
12
- core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Loading ${access.length} accesses`));
1
+ import { ux } from '@oclif/core';
2
+ import { DIRECTUS_PINK } from '../constants.js';
3
+ import { api } from '../sdk.js';
4
+ import catchError from '../utils/catch-error.js';
5
+ import getRoleIds from '../utils/get-role-ids.js';
6
+ import readFile from '../utils/read-file.js';
7
+ export default async function loadAccess(dir) {
8
+ const access = readFile('access', dir);
9
+ ux.action.start(ux.colorize(DIRECTUS_PINK, `Loading ${access.length} accesses`));
13
10
  if (access && access.length > 0) {
14
11
  // Fetch existing accesses
15
- const existingAccesses = await sdk_1.api.client.request(() => ({
12
+ const existingAccesses = await api.client.request(() => ({
16
13
  method: 'GET',
17
14
  params: {
18
15
  limit: -1,
19
16
  },
20
17
  path: '/access',
21
18
  }));
22
- const { legacyAdminRoleId, newAdminRoleId } = await (0, get_role_ids_1.default)(dir);
19
+ const { legacyAdminRoleId, newAdminRoleId } = await getRoleIds(dir);
23
20
  const existingAccessById = new Map(existingAccesses.map(acc => [acc.id, acc]));
24
21
  const existingAccessByCompositeKey = new Map(existingAccesses.map(acc => [getCompositeKey(acc), acc]));
25
22
  for await (const acc of access) {
@@ -39,7 +36,7 @@ async function loadAccess(dir) {
39
36
  if (acc.role === legacyAdminRoleId) {
40
37
  acc.role = newAdminRoleId;
41
38
  }
42
- await sdk_1.api.client.request(() => ({
39
+ await api.client.request(() => ({
43
40
  body: JSON.stringify(acc),
44
41
  method: 'POST',
45
42
  path: '/access',
@@ -49,7 +46,7 @@ async function loadAccess(dir) {
49
46
  existingAccessByCompositeKey.set(compositeKey, acc);
50
47
  }
51
48
  catch (error) {
52
- (0, catch_error_1.default)(error, {
49
+ catchError(error, {
53
50
  context: {
54
51
  access: acc,
55
52
  operation: 'createAccess',
@@ -58,11 +55,9 @@ async function loadAccess(dir) {
58
55
  }
59
56
  }
60
57
  }
61
- core_1.ux.action.stop();
58
+ ux.action.stop();
62
59
  }
63
- exports.default = loadAccess;
64
60
  // Helper function to generate a composite key for each access
65
61
  function getCompositeKey(acc) {
66
- var _a, _b;
67
- return `${(_a = acc.role) !== null && _a !== void 0 ? _a : 'null'}-${(_b = acc.user) !== null && _b !== void 0 ? _b : 'null'}-${acc.policy}`;
62
+ return `${acc.role ?? 'null'}-${acc.user ?? 'null'}-${acc.policy}`;
68
63
  }