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.
- package/bin/dev +2 -3
- package/bin/dev.js +3 -0
- package/bin/run +0 -1
- package/bin/run.js +5 -0
- package/dist/commands/apply.d.ts +17 -17
- package/dist/commands/apply.js +160 -173
- package/dist/commands/extract.d.ts +13 -7
- package/dist/commands/extract.js +89 -73
- package/dist/commands/init.d.ts +7 -7
- package/dist/commands/init.js +78 -80
- package/dist/flags/common.d.ts +7 -7
- package/dist/flags/common.js +8 -11
- package/dist/index.js +1 -5
- package/dist/lib/constants.js +6 -9
- package/dist/lib/extract/extract-access.js +11 -15
- package/dist/lib/extract/extract-assets.js +20 -25
- package/dist/lib/extract/extract-collections.js +12 -16
- package/dist/lib/extract/extract-content.js +14 -19
- package/dist/lib/extract/extract-dashboards.js +22 -28
- package/dist/lib/extract/extract-extensions.js +12 -16
- package/dist/lib/extract/extract-fields.js +13 -17
- package/dist/lib/extract/extract-files.js +15 -19
- package/dist/lib/extract/extract-flows.js +22 -28
- package/dist/lib/extract/extract-folders.js +15 -19
- package/dist/lib/extract/extract-permissions.js +12 -16
- package/dist/lib/extract/extract-policies.js +12 -16
- package/dist/lib/extract/extract-presets.js +12 -16
- package/dist/lib/extract/extract-relations.js +14 -18
- package/dist/lib/extract/extract-roles.js +15 -19
- package/dist/lib/extract/extract-schema.js +17 -21
- package/dist/lib/extract/extract-settings.js +12 -16
- package/dist/lib/extract/extract-translations.js +12 -16
- package/dist/lib/extract/extract-users.js +15 -19
- package/dist/lib/extract/index.js +47 -51
- package/dist/lib/init/config.d.ts +1 -1
- package/dist/lib/init/config.js +2 -5
- package/dist/lib/init/index.js +54 -59
- package/dist/lib/init/types.js +1 -2
- package/dist/lib/init.d.ts +1 -0
- package/dist/lib/init.js +2 -0
- package/dist/lib/load/apply-flags.js +17 -23
- package/dist/lib/load/index.js +40 -44
- package/dist/lib/load/load-access.js +15 -20
- package/dist/lib/load/load-collections.js +27 -32
- package/dist/lib/load/load-dashboards.js +19 -25
- package/dist/lib/load/load-data.js +43 -49
- package/dist/lib/load/load-extensions.js +30 -38
- package/dist/lib/load/load-files.js +20 -24
- package/dist/lib/load/load-flows.js +23 -29
- package/dist/lib/load/load-folders.js +16 -20
- package/dist/lib/load/load-permissions.js +13 -17
- package/dist/lib/load/load-policies.js +14 -18
- package/dist/lib/load/load-presets.js +14 -18
- package/dist/lib/load/load-relations.d.ts +2 -0
- package/dist/lib/load/load-relations.js +16 -18
- package/dist/lib/load/load-roles.js +19 -23
- package/dist/lib/load/load-settings.js +18 -21
- package/dist/lib/load/load-translations.js +14 -18
- package/dist/lib/load/load-users.js +21 -25
- package/dist/lib/load/update-required-fields.js +13 -17
- package/dist/lib/sdk.d.ts +1 -2
- package/dist/lib/sdk.js +27 -27
- package/dist/lib/types/extension.js +1 -2
- package/dist/lib/utils/animated-bunny.js +9 -14
- package/dist/lib/utils/auth.d.ts +2 -2
- package/dist/lib/utils/auth.js +32 -33
- package/dist/lib/utils/catch-error.js +8 -11
- package/dist/lib/utils/check-template.js +4 -8
- package/dist/lib/utils/chunk-array.js +1 -5
- package/dist/lib/utils/ensure-dir.js +7 -12
- package/dist/lib/utils/filter-fields.js +1 -4
- package/dist/lib/utils/get-role-ids.d.ts +1 -1
- package/dist/lib/utils/get-role-ids.js +7 -12
- package/dist/lib/utils/get-template.js +33 -37
- package/dist/lib/utils/logger.js +11 -13
- package/dist/lib/utils/open-url.js +5 -8
- package/dist/lib/utils/parse-github-url.js +4 -9
- package/dist/lib/utils/path.js +6 -10
- package/dist/lib/utils/protected-domains.js +1 -4
- package/dist/lib/utils/read-file.js +8 -12
- package/dist/lib/utils/read-templates.js +9 -15
- package/dist/lib/utils/system-fields.js +19 -22
- package/dist/lib/utils/template-defaults.d.ts +1 -1
- package/dist/lib/utils/template-defaults.js +5 -14
- package/dist/lib/utils/transform-github-url.js +1 -5
- package/dist/lib/utils/validate-url.js +3 -6
- package/dist/lib/utils/wait.js +1 -5
- package/dist/lib/utils/write-to-file.js +8 -11
- package/dist/services/docker.js +11 -18
- package/dist/services/github.d.ts +1 -1
- package/dist/services/github.js +8 -12
- package/oclif.manifest.json +4 -4
- package/package.json +36 -32
package/dist/commands/extract.js
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 (!
|
|
35
|
-
|
|
46
|
+
if (!fs.existsSync(directory)) {
|
|
47
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
36
48
|
}
|
|
37
|
-
const packageJSONContent =
|
|
38
|
-
const readmeContent =
|
|
39
|
-
const packageJSONPath =
|
|
40
|
-
const readmePath =
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
(
|
|
57
|
+
catchError(error, {
|
|
46
58
|
context: { function: 'extractTemplate' },
|
|
47
59
|
fatal: true,
|
|
48
60
|
logToFile: true,
|
|
49
61
|
});
|
|
50
62
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
await (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
66
|
-
const templateName = await
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
|
90
|
+
const directusUrl = await getDirectusUrl();
|
|
72
91
|
flags.directusUrl = directusUrl;
|
|
73
92
|
// Prompt for login method
|
|
74
|
-
const loginMethod = await
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
92
|
-
|
|
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
|
-
|
|
95
|
-
await
|
|
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
|
|
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
|
-
|
|
147
|
+
validateAuthFlags(flags);
|
|
117
148
|
if (!flags.templateLocation) {
|
|
118
|
-
|
|
149
|
+
ux.error('Template location is required for programmatic mode.');
|
|
119
150
|
}
|
|
120
151
|
if (!flags.templateName) {
|
|
121
|
-
|
|
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;
|
package/dist/commands/init.d.ts
CHANGED
|
@@ -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/
|
|
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/
|
|
12
|
-
gitInit: import("@oclif/core/
|
|
13
|
-
installDeps: import("@oclif/core/
|
|
14
|
-
overrideDir: import("@oclif/core/
|
|
15
|
-
programmatic: import("@oclif/core/
|
|
16
|
-
template: import("@oclif/core/
|
|
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
|
/**
|
package/dist/commands/init.js
CHANGED
|
@@ -1,19 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 =
|
|
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
|
|
40
|
-
|
|
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 =
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
119
|
+
let { frontend: chosenFrontend } = flags;
|
|
78
120
|
if (!chosenFrontend || !potentialFrontends.includes(chosenFrontend)) {
|
|
79
|
-
chosenFrontend = await
|
|
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
|
|
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
|
|
134
|
+
const initGit = await confirm({
|
|
93
135
|
initialValue: true,
|
|
94
136
|
message: 'Initialize a new Git repository?',
|
|
95
137
|
}).then(ans => ans);
|
|
96
|
-
await
|
|
138
|
+
await init(this.targetDir, {
|
|
97
139
|
frontend: chosenFrontend,
|
|
98
140
|
gitInit: initGit,
|
|
99
141
|
installDeps,
|
|
100
142
|
template,
|
|
101
143
|
});
|
|
102
|
-
|
|
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 =
|
|
152
|
+
const github = createGitHub();
|
|
111
153
|
if (!flags.template) {
|
|
112
|
-
|
|
154
|
+
ux.error('Missing --template parameter for programmatic mode.');
|
|
113
155
|
}
|
|
114
156
|
if (!flags.frontend) {
|
|
115
|
-
|
|
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
|
-
|
|
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
|
-
|
|
167
|
+
ux.error(`Frontend "${frontend}" doesn't exist in template "${template}". Available frontends: ${potentialFrontends.join(', ')}`);
|
|
126
168
|
}
|
|
127
|
-
await
|
|
169
|
+
await init(this.targetDir, {
|
|
128
170
|
frontend,
|
|
129
171
|
installDeps: true,
|
|
130
172
|
template,
|
|
131
173
|
});
|
|
132
|
-
|
|
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;
|
package/dist/flags/common.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export declare const directusToken: import("@oclif/core/
|
|
2
|
-
export declare const directusUrl: import("@oclif/core/
|
|
3
|
-
export declare const userEmail: import("@oclif/core/
|
|
4
|
-
export declare const userPassword: import("@oclif/core/
|
|
5
|
-
export declare const programmatic: import("@oclif/core/
|
|
6
|
-
export declare const templateLocation: import("@oclif/core/
|
|
7
|
-
export declare const templateName: import("@oclif/core/
|
|
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>;
|
package/dist/flags/common.js
CHANGED
|
@@ -1,40 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
7
|
+
export const directusUrl = Flags.string({
|
|
11
8
|
description: 'URL of the Directus instance',
|
|
12
9
|
env: 'DIRECTUS_URL',
|
|
13
10
|
});
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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';
|
package/dist/lib/constants.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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
|
-
|
|
13
|
+
export const DEFAULT_REPO = {
|
|
17
14
|
owner: 'directus-labs',
|
|
18
15
|
path: '',
|
|
19
16
|
ref: 'cms-template',
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
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 (
|
|
17
|
+
await writeToFile('access', response, dir);
|
|
21
18
|
}
|
|
22
19
|
catch (error) {
|
|
23
|
-
(
|
|
20
|
+
catchError(error);
|
|
24
21
|
}
|
|
25
|
-
|
|
22
|
+
ux.action.stop();
|
|
26
23
|
}
|
|
27
|
-
exports.default = extractAccess;
|