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,18 +1,30 @@
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 inquirer_1 = tslib_1.__importDefault(require("inquirer"));
6
- const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
7
- const node_path_1 = tslib_1.__importDefault(require("node:path"));
8
- const slugify_1 = tslib_1.__importDefault(require("slugify"));
9
- const customFlags = tslib_1.__importStar(require("../flags/common"));
10
- const constants_1 = require("../lib/constants");
11
- const extract_1 = tslib_1.__importDefault(require("../lib/extract/"));
12
- const auth_1 = require("../lib/utils/auth");
13
- const catch_error_1 = tslib_1.__importDefault(require("../lib/utils/catch-error"));
14
- const template_defaults_1 = require("../lib/utils/template-defaults");
15
- class ExtractCommand extends core_1.Command {
1
+ import { text, password, select } from '@clack/prompts';
2
+ import { Command, ux } from '@oclif/core';
3
+ import slugify from '@sindresorhus/slugify';
4
+ import chalk from 'chalk';
5
+ import fs from 'node:fs';
6
+ import path from 'pathe';
7
+ import * as customFlags from '../flags/common.js';
8
+ import { DIRECTUS_PINK, DIRECTUS_PURPLE, SEPARATOR } from '../lib/constants.js';
9
+ import extract from '../lib/extract/index.js';
10
+ import { getDirectusToken, getDirectusUrl, initializeDirectusApi, validateAuthFlags } from '../lib/utils/auth.js';
11
+ import catchError from '../lib/utils/catch-error.js';
12
+ import { generatePackageJsonContent, generateReadmeContent, } from '../lib/utils/template-defaults.js';
13
+ export default class ExtractCommand extends Command {
14
+ static description = 'Extract a template from a Directus instance.';
15
+ static examples = [
16
+ '$ directus-template-cli extract',
17
+ '$ directus-template-cli extract -p --templateName="My Template" --templateLocation="./my-template" --directusToken="admin-token-here" --directusUrl="http://localhost:8055"',
18
+ ];
19
+ static flags = {
20
+ directusToken: customFlags.directusToken,
21
+ directusUrl: customFlags.directusUrl,
22
+ programmatic: customFlags.programmatic,
23
+ templateLocation: customFlags.templateLocation,
24
+ templateName: customFlags.templateName,
25
+ userEmail: customFlags.userEmail,
26
+ userPassword: customFlags.userPassword,
27
+ };
16
28
  /**
17
29
  * Main run method for the ExtractCommand
18
30
  * @returns {Promise<void>} - Returns nothing
@@ -31,29 +43,29 @@ class ExtractCommand extends core_1.Command {
31
43
  */
32
44
  async extractTemplate(templateName, directory, flags) {
33
45
  try {
34
- if (!node_fs_1.default.existsSync(directory)) {
35
- node_fs_1.default.mkdirSync(directory, { recursive: true });
46
+ if (!fs.existsSync(directory)) {
47
+ fs.mkdirSync(directory, { recursive: true });
36
48
  }
37
- const packageJSONContent = (0, template_defaults_1.generatePackageJsonContent)(templateName);
38
- const readmeContent = (0, template_defaults_1.generateReadmeContent)(templateName);
39
- const packageJSONPath = node_path_1.default.join(directory, 'package.json');
40
- const readmePath = node_path_1.default.join(directory, 'README.md');
41
- node_fs_1.default.writeFileSync(packageJSONPath, packageJSONContent);
42
- node_fs_1.default.writeFileSync(readmePath, readmeContent);
49
+ const packageJSONContent = generatePackageJsonContent(templateName);
50
+ const readmeContent = generateReadmeContent(templateName);
51
+ const packageJSONPath = path.join(directory, 'package.json');
52
+ const readmePath = path.join(directory, 'README.md');
53
+ fs.writeFileSync(packageJSONPath, packageJSONContent);
54
+ fs.writeFileSync(readmePath, readmeContent);
43
55
  }
44
56
  catch (error) {
45
- (0, catch_error_1.default)(error, {
57
+ catchError(error, {
46
58
  context: { function: 'extractTemplate' },
47
59
  fatal: true,
48
60
  logToFile: true,
49
61
  });
50
62
  }
51
- core_1.ux.log(constants_1.SEPARATOR);
52
- core_1.ux.action.start(`Extracting template - ${core_1.ux.colorize(constants_1.DIRECTUS_PINK, templateName)} from ${core_1.ux.colorize(constants_1.DIRECTUS_PINK, flags.directusUrl)} to ${core_1.ux.colorize(constants_1.DIRECTUS_PINK, directory)}`);
53
- await (0, extract_1.default)(directory);
54
- core_1.ux.action.stop();
55
- core_1.ux.log(constants_1.SEPARATOR);
56
- core_1.ux.log('Template extracted successfully.');
63
+ ux.stdout(SEPARATOR);
64
+ ux.action.start(`Extracting template - ${ux.colorize(DIRECTUS_PINK, templateName)} from ${ux.colorize(DIRECTUS_PINK, flags.directusUrl)} to ${ux.colorize(DIRECTUS_PINK, directory)}`);
65
+ await extract(directory);
66
+ ux.action.stop();
67
+ ux.stdout(SEPARATOR);
68
+ ux.stdout('Template extracted successfully.');
57
69
  this.exit(0);
58
70
  }
59
71
  /**
@@ -62,37 +74,45 @@ class ExtractCommand extends core_1.Command {
62
74
  * @returns {Promise<void>} - Returns nothing
63
75
  */
64
76
  async runInteractive(flags) {
65
- core_1.ux.styledHeader(core_1.ux.colorize(constants_1.DIRECTUS_PURPLE, 'Directus Template CLI - Extract'));
66
- const templateName = await core_1.ux.prompt('What is the name of the template you would like to extract?');
67
- const directory = await core_1.ux.prompt("What directory would you like to extract the template to? If it doesn't exist, it will be created.", { default: `templates/${(0, slugify_1.default)(templateName, { lower: true, strict: true })}` });
68
- core_1.ux.log(`You selected ${core_1.ux.colorize(constants_1.DIRECTUS_PINK, directory)}`);
69
- core_1.ux.log(constants_1.SEPARATOR);
77
+ this.styledHeader(chalk.hex(DIRECTUS_PURPLE)('Directus Template CLI - Extract'));
78
+ const templateName = await text({
79
+ message: 'What is the name of the template you would like to extract?',
80
+ placeholder: 'My Template',
81
+ });
82
+ const directory = await text({
83
+ placeholder: `templates/${slugify(templateName)}`,
84
+ defaultValue: `templates/${slugify(templateName)}`,
85
+ message: "What directory would you like to extract the template to? If it doesn't exist, it will be created.",
86
+ });
87
+ ux.stdout(`You selected ${ux.colorize(DIRECTUS_PINK, directory)}`);
88
+ ux.stdout(SEPARATOR);
70
89
  // Get Directus URL
71
- const directusUrl = await (0, auth_1.getDirectusUrl)();
90
+ const directusUrl = await getDirectusUrl();
72
91
  flags.directusUrl = directusUrl;
73
92
  // Prompt for login method
74
- const loginMethod = await inquirer_1.default.prompt([
75
- {
76
- choices: [
77
- { name: 'Directus Access Token', value: 'token' },
78
- { name: 'Email and Password', value: 'email' },
79
- ],
80
- default: 'token',
81
- message: 'How do you want to log in?',
82
- name: 'loginMethod',
83
- type: 'list',
84
- },
85
- ]);
86
- if (loginMethod.loginMethod === 'token') {
87
- const directusToken = await (0, auth_1.getDirectusToken)(directusUrl);
93
+ const loginMethod = await select({
94
+ options: [
95
+ { label: 'Directus Access Token', value: 'token' },
96
+ { label: 'Email and Password', value: 'email' },
97
+ ],
98
+ message: 'How do you want to log in?',
99
+ });
100
+ if (loginMethod === 'token') {
101
+ const directusToken = await getDirectusToken(directusUrl);
88
102
  flags.directusToken = directusToken;
89
103
  }
90
104
  else {
91
- flags.userEmail = await core_1.ux.prompt('What is your email?');
92
- flags.userPassword = await core_1.ux.prompt('What is your password?', { type: 'hide' });
105
+ const email = await text({
106
+ message: 'What is your email?',
107
+ });
108
+ flags.userEmail = email;
109
+ const userPassword = await password({
110
+ message: 'What is our password?',
111
+ });
112
+ flags.userPassword = userPassword;
93
113
  }
94
- core_1.ux.log(constants_1.SEPARATOR);
95
- await (0, auth_1.initializeDirectusApi)(flags);
114
+ ux.stdout(SEPARATOR);
115
+ await initializeDirectusApi(flags);
96
116
  await this.extractTemplate(templateName, directory, flags);
97
117
  }
98
118
  /**
@@ -103,9 +123,20 @@ class ExtractCommand extends core_1.Command {
103
123
  async runProgrammatic(flags) {
104
124
  this.validateProgrammaticFlags(flags);
105
125
  const { templateLocation, templateName } = flags;
106
- await (0, auth_1.initializeDirectusApi)(flags);
126
+ await initializeDirectusApi(flags);
107
127
  await this.extractTemplate(templateName, templateLocation, flags);
108
128
  }
129
+ /**
130
+ * Helper function to create styled headers since ux.styledHeader is removed in v4
131
+ * @param text - The text to style as a header
132
+ * @returns {void}
133
+ */
134
+ styledHeader(text) {
135
+ const padding = '═'.repeat(Math.max(0, text.length));
136
+ ux.stdout(`\n${padding}`);
137
+ ux.stdout(`${text}`);
138
+ ux.stdout(`${padding}\n`);
139
+ }
109
140
  /**
110
141
  * Validates the flags for programmatic mode
111
142
  * @param {ExtractFlags} flags - The command flags to validate
@@ -113,27 +144,12 @@ class ExtractCommand extends core_1.Command {
113
144
  * @returns {void}
114
145
  */
115
146
  validateProgrammaticFlags(flags) {
116
- (0, auth_1.validateAuthFlags)(flags);
147
+ validateAuthFlags(flags);
117
148
  if (!flags.templateLocation) {
118
- core_1.ux.error('Template location is required for programmatic mode.');
149
+ ux.error('Template location is required for programmatic mode.');
119
150
  }
120
151
  if (!flags.templateName) {
121
- core_1.ux.error('Template name is required for programmatic mode.');
152
+ ux.error('Template name is required for programmatic mode.');
122
153
  }
123
154
  }
124
155
  }
125
- ExtractCommand.description = 'Extract a template from a Directus instance.';
126
- ExtractCommand.examples = [
127
- '$ directus-template-cli extract',
128
- '$ directus-template-cli extract -p --templateName="My Template" --templateLocation="./my-template" --directusToken="admin-token-here" --directusUrl="http://localhost:8055"',
129
- ];
130
- ExtractCommand.flags = {
131
- directusToken: customFlags.directusToken,
132
- directusUrl: customFlags.directusUrl,
133
- programmatic: customFlags.programmatic,
134
- templateLocation: customFlags.templateLocation,
135
- templateName: customFlags.templateName,
136
- userEmail: customFlags.userEmail,
137
- userPassword: customFlags.userPassword,
138
- };
139
- exports.default = ExtractCommand;
@@ -1,19 +1,19 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default class InitCommand extends Command {
3
3
  static args: {
4
- directory: import("@oclif/core/lib/interfaces").Arg<string, {
4
+ directory: import("@oclif/core/interfaces").Arg<string, {
5
5
  exists?: boolean;
6
6
  }>;
7
7
  };
8
8
  static description: string;
9
9
  static examples: string[];
10
10
  static flags: {
11
- frontend: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
12
- gitInit: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
13
- installDeps: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
14
- overrideDir: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
15
- programmatic: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
16
- template: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
11
+ frontend: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
12
+ gitInit: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
+ installDeps: import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
+ overrideDir: import("@oclif/core/interfaces").BooleanFlag<boolean>;
15
+ programmatic: import("@oclif/core/interfaces").BooleanFlag<boolean>;
16
+ template: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
17
17
  };
18
18
  private targetDir;
19
19
  /**
@@ -1,19 +1,56 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const prompts_1 = require("@clack/prompts");
5
- const core_1 = require("@oclif/core");
6
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
7
- const node_path_1 = tslib_1.__importDefault(require("node:path"));
8
- const constants_1 = require("../lib/constants");
9
- const init_1 = require("../lib/init");
10
- const animated_bunny_1 = require("../lib/utils/animated-bunny");
11
- const github_1 = require("../services/github");
12
- class InitCommand extends core_1.Command {
13
- constructor() {
14
- super(...arguments);
15
- this.targetDir = '.';
16
- }
1
+ import { confirm, intro, select, text } from '@clack/prompts';
2
+ import { Args, Command, Flags, ux } from '@oclif/core';
3
+ import chalk from 'chalk';
4
+ import path from 'pathe';
5
+ import { DIRECTUS_PURPLE } from '../lib/constants.js';
6
+ import { init } from '../lib/init.js';
7
+ import { animatedBunny } from '../lib/utils/animated-bunny.js';
8
+ import { createGitHub } from '../services/github.js';
9
+ export default class InitCommand extends Command {
10
+ static args = {
11
+ directory: Args.directory({
12
+ default: '.',
13
+ description: 'Directory to create the project in',
14
+ required: false,
15
+ }),
16
+ };
17
+ static description = 'Initialize a new Directus + Frontend monorepo using official or community starters.';
18
+ static examples = [
19
+ '$ directus-template-cli init',
20
+ '$ directus-template-cli init my-project',
21
+ '$ directus-template-cli init --frontend=nextjs --template=simple-cms --programmatic',
22
+ '$ directus-template-cli init my-project --frontend=nextjs --template=simple-cms --programmatic',
23
+ ];
24
+ static flags = {
25
+ frontend: Flags.string({
26
+ description: 'Frontend framework to use (e.g., nextjs, nuxt, astro)',
27
+ }),
28
+ gitInit: Flags.boolean({
29
+ aliases: ['git-init'],
30
+ allowNo: true,
31
+ default: true,
32
+ description: 'Initialize a new Git repository',
33
+ }),
34
+ installDeps: Flags.boolean({
35
+ aliases: ['install-deps'],
36
+ allowNo: true,
37
+ default: true,
38
+ description: 'Install dependencies automatically',
39
+ }),
40
+ overrideDir: Flags.boolean({
41
+ default: false,
42
+ description: 'Override the default directory',
43
+ }),
44
+ programmatic: Flags.boolean({
45
+ char: 'p',
46
+ default: false,
47
+ description: 'Run in programmatic mode (non-interactive)',
48
+ }),
49
+ template: Flags.string({
50
+ description: 'Template name (e.g., simple-cms) or GitHub URL (e.g., https://github.com/directus-labs/starters/tree/main/simple-cms)',
51
+ }),
52
+ };
53
+ targetDir = '.';
17
54
  /**
18
55
  * Entrypoint for the command.
19
56
  * @returns Promise that resolves when the command is complete.
@@ -23,7 +60,7 @@ class InitCommand extends core_1.Command {
23
60
  const typedFlags = flags;
24
61
  const typedArgs = args;
25
62
  // Set the target directory and create it if it doesn't exist
26
- this.targetDir = node_path_1.default.resolve(args.directory);
63
+ this.targetDir = path.resolve(args.directory);
27
64
  // if (!fs.existsSync(this.targetDir)) {
28
65
  // fs.mkdirSync(this.targetDir, {recursive: true})
29
66
  // }
@@ -36,13 +73,13 @@ class InitCommand extends core_1.Command {
36
73
  * @returns void
37
74
  */
38
75
  async runInteractive(flags, args) {
39
- await (0, animated_bunny_1.animatedBunny)('Let\'s create a new Directus project!');
40
- (0, prompts_1.intro)(`${chalk_1.default.bgHex(constants_1.DIRECTUS_PURPLE).white.bold('Directus Template CLI 🐰')} - Create Project`);
76
+ await animatedBunny('Let\'s create a new Directus project!');
77
+ intro(`${chalk.bgHex(DIRECTUS_PURPLE).white.bold('Directus Template CLI')} - Create Project`);
41
78
  // Create GitHub service
42
- const github = (0, github_1.createGitHub)();
79
+ const github = createGitHub();
43
80
  // If no dir is provided, ask for it
44
81
  if (!args.directory || args.directory === '.') {
45
- this.targetDir = await (0, prompts_1.text)({
82
+ this.targetDir = await text({
46
83
  message: 'Enter the directory to create the project in:',
47
84
  placeholder: './my-directus-project',
48
85
  }).then(ans => ans);
@@ -52,7 +89,7 @@ class InitCommand extends core_1.Command {
52
89
  // 2. Prompt for template if not provided
53
90
  let { template } = flags;
54
91
  if (!template) {
55
- template = await (0, prompts_1.select)({
92
+ template = await select({
56
93
  message: 'Which Directus backend template would you like to use?',
57
94
  options: availableTemplates.map(template => ({
58
95
  label: template,
@@ -64,7 +101,12 @@ class InitCommand extends core_1.Command {
64
101
  let directories = await github.getTemplateDirectories(template);
65
102
  while (directories.length === 0) {
66
103
  this.log(`Template "${template}" doesn't seem to exist in directus-labs/directus-starters.`);
67
- template = await core_1.ux.prompt('Please enter a valid template name, or Ctrl+C to cancel:');
104
+ // ts-ignore no-await-in-loop
105
+ const templateName = await text({
106
+ message: 'Please enter a valid template name, or Ctrl+C to cancel:',
107
+ });
108
+ template = templateName;
109
+ // ts-ignore no-await-in-loop
68
110
  directories = await github.getTemplateDirectories(template);
69
111
  }
70
112
  flags.template = template;
@@ -74,9 +116,9 @@ class InitCommand extends core_1.Command {
74
116
  this.error(`No frontends found for template "${template}". Exiting.`);
75
117
  }
76
118
  // 4. If user hasn't specified a valid flags.frontend, ask from the list
77
- let chosenFrontend = flags.frontend;
119
+ let { frontend: chosenFrontend } = flags;
78
120
  if (!chosenFrontend || !potentialFrontends.includes(chosenFrontend)) {
79
- chosenFrontend = await (0, prompts_1.select)({
121
+ chosenFrontend = await select({
80
122
  message: 'Which frontend framework do you want to use?',
81
123
  options: potentialFrontends.map(frontend => ({
82
124
  label: frontend,
@@ -85,21 +127,21 @@ class InitCommand extends core_1.Command {
85
127
  }).then(ans => ans);
86
128
  }
87
129
  flags.frontend = chosenFrontend;
88
- const installDeps = await (0, prompts_1.confirm)({
130
+ const installDeps = await confirm({
89
131
  initialValue: true,
90
132
  message: 'Would you like to install project dependencies automatically?',
91
133
  }).then(ans => ans);
92
- const initGit = await (0, prompts_1.confirm)({
134
+ const initGit = await confirm({
93
135
  initialValue: true,
94
136
  message: 'Initialize a new Git repository?',
95
137
  }).then(ans => ans);
96
- await (0, init_1.init)(this.targetDir, {
138
+ await init(this.targetDir, {
97
139
  frontend: chosenFrontend,
98
140
  gitInit: initGit,
99
141
  installDeps,
100
142
  template,
101
143
  });
102
- core_1.ux.exit(0);
144
+ ux.exit(0);
103
145
  }
104
146
  /**
105
147
  * Programmatic mode: relies on flags only, with checks for template existence and valid frontend.
@@ -107,72 +149,28 @@ class InitCommand extends core_1.Command {
107
149
  * @returns void
108
150
  */
109
151
  async runProgrammatic(flags) {
110
- const github = (0, github_1.createGitHub)();
152
+ const github = createGitHub();
111
153
  if (!flags.template) {
112
- core_1.ux.error('Missing --template parameter for programmatic mode.');
154
+ ux.error('Missing --template parameter for programmatic mode.');
113
155
  }
114
156
  if (!flags.frontend) {
115
- core_1.ux.error('Missing --frontend parameter for programmatic mode.');
157
+ ux.error('Missing --frontend parameter for programmatic mode.');
116
158
  }
117
159
  const template = flags.template;
118
160
  const directories = await github.getTemplateDirectories(template);
119
161
  if (directories.length === 0) {
120
- core_1.ux.error(`Template "${template}" doesn't seem to exist in directus-labs/directus-starters.`);
162
+ ux.error(`Template "${template}" doesn't seem to exist in directus-labs/directus-starters.`);
121
163
  }
122
164
  const potentialFrontends = directories.filter(dir => dir !== 'directus');
123
165
  const frontend = flags.frontend;
124
166
  if (!potentialFrontends.includes(frontend)) {
125
- core_1.ux.error(`Frontend "${frontend}" doesn't exist in template "${template}". Available frontends: ${potentialFrontends.join(', ')}`);
167
+ ux.error(`Frontend "${frontend}" doesn't exist in template "${template}". Available frontends: ${potentialFrontends.join(', ')}`);
126
168
  }
127
- await (0, init_1.init)(this.targetDir, {
169
+ await init(this.targetDir, {
128
170
  frontend,
129
171
  installDeps: true,
130
172
  template,
131
173
  });
132
- core_1.ux.exit(0);
174
+ ux.exit(0);
133
175
  }
134
176
  }
135
- InitCommand.args = {
136
- directory: core_1.Args.directory({
137
- default: '.',
138
- description: 'Directory to create the project in',
139
- required: false,
140
- }),
141
- };
142
- InitCommand.description = 'Initialize a new Directus + Frontend monorepo using official or community starters.';
143
- InitCommand.examples = [
144
- '$ directus-template-cli init',
145
- '$ directus-template-cli init my-project',
146
- '$ directus-template-cli init --frontend=nextjs --template=simple-cms --programmatic',
147
- '$ directus-template-cli init my-project --frontend=nextjs --template=simple-cms --programmatic',
148
- ];
149
- InitCommand.flags = {
150
- frontend: core_1.Flags.string({
151
- description: 'Frontend framework to use (e.g., nextjs, nuxt, astro)',
152
- }),
153
- gitInit: core_1.Flags.boolean({
154
- aliases: ['git-init'],
155
- allowNo: true,
156
- default: true,
157
- description: 'Initialize a new Git repository',
158
- }),
159
- installDeps: core_1.Flags.boolean({
160
- aliases: ['install-deps'],
161
- allowNo: true,
162
- default: true,
163
- description: 'Install dependencies automatically',
164
- }),
165
- overrideDir: core_1.Flags.boolean({
166
- default: false,
167
- description: 'Override the default directory',
168
- }),
169
- programmatic: core_1.Flags.boolean({
170
- char: 'p',
171
- default: false,
172
- description: 'Run in programmatic mode (non-interactive)',
173
- }),
174
- template: core_1.Flags.string({
175
- description: 'Template name (e.g., simple-cms) or GitHub URL (e.g., https://github.com/directus-labs/starters/tree/main/simple-cms)',
176
- }),
177
- };
178
- exports.default = InitCommand;
@@ -1,7 +1,7 @@
1
- export declare const directusToken: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
2
- export declare const directusUrl: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
3
- export declare const userEmail: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
4
- export declare const userPassword: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
5
- export declare const programmatic: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
6
- export declare const templateLocation: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
7
- export declare const templateName: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
1
+ export declare const directusToken: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
2
+ export declare const directusUrl: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
3
+ export declare const userEmail: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
4
+ export declare const userPassword: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
5
+ export declare const programmatic: import("@oclif/core/interfaces").BooleanFlag<boolean>;
6
+ export declare const templateLocation: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
7
+ export declare const templateName: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
@@ -1,40 +1,37 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.templateName = exports.templateLocation = exports.programmatic = exports.userPassword = exports.userEmail = exports.directusUrl = exports.directusToken = void 0;
4
- const core_1 = require("@oclif/core");
5
- exports.directusToken = core_1.Flags.string({
1
+ import { Flags } from '@oclif/core';
2
+ export const directusToken = Flags.string({
6
3
  description: 'Token to use for the Directus instance',
7
4
  env: 'DIRECTUS_TOKEN',
8
5
  exclusive: ['userEmail', 'userPassword'],
9
6
  });
10
- exports.directusUrl = core_1.Flags.string({
7
+ export const directusUrl = Flags.string({
11
8
  description: 'URL of the Directus instance',
12
9
  env: 'DIRECTUS_URL',
13
10
  });
14
- exports.userEmail = core_1.Flags.string({
11
+ export const userEmail = Flags.string({
15
12
  dependsOn: ['userPassword'],
16
13
  description: 'Email for Directus authentication',
17
14
  env: 'DIRECTUS_EMAIL',
18
15
  exclusive: ['directusToken'],
19
16
  });
20
- exports.userPassword = core_1.Flags.string({
17
+ export const userPassword = Flags.string({
21
18
  dependsOn: ['userEmail'],
22
19
  description: 'Password for Directus authentication',
23
20
  env: 'DIRECTUS_PASSWORD',
24
21
  exclusive: ['directusToken'],
25
22
  });
26
- exports.programmatic = core_1.Flags.boolean({
23
+ export const programmatic = Flags.boolean({
27
24
  char: 'p',
28
25
  default: false,
29
26
  description: 'Run in programmatic mode (non-interactive) for use cases such as CI/CD pipelines.',
30
27
  summary: 'Run in programmatic mode',
31
28
  });
32
- exports.templateLocation = core_1.Flags.string({
29
+ export const templateLocation = Flags.string({
33
30
  dependsOn: ['programmatic'],
34
31
  description: 'Location of the template',
35
32
  env: 'TEMPLATE_LOCATION',
36
33
  });
37
- exports.templateName = core_1.Flags.string({
34
+ export const templateName = Flags.string({
38
35
  dependsOn: ['programmatic'],
39
36
  description: 'Name of the template',
40
37
  env: 'TEMPLATE_NAME',
package/dist/index.js CHANGED
@@ -1,5 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.run = void 0;
4
- var core_1 = require("@oclif/core");
5
- Object.defineProperty(exports, "run", { enumerable: true, get: function () { return core_1.run; } });
1
+ export { run } from '@oclif/core';
@@ -1,19 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_REPO = exports.STARTERS_TEMPLATE_REPO = exports.COMMUNITY_TEMPLATE_REPO = exports.SEPARATOR = exports.DIRECTUS_PINK = exports.DIRECTUS_PURPLE = void 0;
4
- exports.DIRECTUS_PURPLE = '#6644ff';
5
- exports.DIRECTUS_PINK = '#FF99DD';
6
- exports.SEPARATOR = '------------------';
7
- exports.COMMUNITY_TEMPLATE_REPO = {
1
+ export const DIRECTUS_PURPLE = '#6644ff';
2
+ export const DIRECTUS_PINK = '#FF99DD';
3
+ export const SEPARATOR = '------------------';
4
+ export const COMMUNITY_TEMPLATE_REPO = {
8
5
  string: 'github:directus-labs/directus-templates',
9
6
  url: 'https://github.com/directus-labs/directus-templates',
10
7
  };
11
- exports.STARTERS_TEMPLATE_REPO = {
8
+ export const STARTERS_TEMPLATE_REPO = {
12
9
  branch: 'cms-template',
13
10
  string: 'github:directus-labs/starters',
14
11
  url: 'https://github.com/directus-labs/starters',
15
12
  };
16
- exports.DEFAULT_REPO = {
13
+ export const DEFAULT_REPO = {
17
14
  owner: 'directus-labs',
18
15
  path: '',
19
16
  ref: 'cms-template',
@@ -1,15 +1,12 @@
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 write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
9
- async function extractAccess(dir) {
10
- core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, 'Extracting access'));
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 writeToFile from '../utils/write-to-file.js';
6
+ export default async function extractAccess(dir) {
7
+ ux.action.start(ux.colorize(DIRECTUS_PINK, 'Extracting access'));
11
8
  try {
12
- const response = await sdk_1.api.client.request(() => ({
9
+ const response = await api.client.request(() => ({
13
10
  method: 'GET',
14
11
  path: '/access?limit=-1',
15
12
  }));
@@ -17,11 +14,10 @@ async function extractAccess(dir) {
17
14
  // for (const access of response) {
18
15
  // delete access.id
19
16
  // }
20
- await (0, write_to_file_1.default)('access', response, dir);
17
+ await writeToFile('access', response, dir);
21
18
  }
22
19
  catch (error) {
23
- (0, catch_error_1.default)(error);
20
+ catchError(error);
24
21
  }
25
- core_1.ux.action.stop();
22
+ ux.action.stop();
26
23
  }
27
- exports.default = extractAccess;