directus-template-cli 0.7.0-beta.5 → 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.
- package/bin/dev.js +3 -0
- package/dist/commands/apply.js +9 -6
- package/dist/commands/base.d.ts +15 -0
- package/dist/commands/base.js +45 -0
- package/dist/commands/extract.d.ts +9 -6
- package/dist/commands/extract.js +4 -13
- package/dist/commands/init.d.ts +14 -9
- package/dist/commands/init.js +140 -75
- package/dist/flags/common.d.ts +1 -0
- package/dist/flags/common.js +5 -0
- package/dist/lib/constants.d.ts +3 -5
- package/dist/lib/constants.js +3 -5
- package/dist/lib/init/config.js +1 -1
- package/dist/lib/init/index.d.ts +5 -9
- package/dist/lib/init/index.js +71 -46
- package/dist/lib/load/index.d.ts +1 -12
- package/dist/lib/types.d.ts +18 -0
- package/dist/lib/types.js +1 -0
- package/dist/lib/utils/auth.d.ts +10 -8
- package/dist/lib/utils/auth.js +17 -7
- package/dist/lib/utils/parse-github-url.d.ts +10 -5
- package/dist/lib/utils/parse-github-url.js +80 -40
- package/dist/lib/utils/sanitize-flags.d.ts +3 -0
- package/dist/lib/utils/sanitize-flags.js +4 -0
- package/dist/lib/utils/template-config.d.ts +16 -0
- package/dist/lib/utils/template-config.js +34 -0
- package/dist/services/docker.js +57 -3
- package/dist/services/github.js +45 -10
- package/dist/services/posthog.d.ts +37 -0
- package/dist/services/posthog.js +104 -0
- package/oclif.manifest.json +29 -10
- package/package.json +4 -3
- package/bin/dev +0 -16
- package/bin/run +0 -4
- package/dist/lib/init.d.ts +0 -1
- package/dist/lib/init.js +0 -2
package/bin/dev.js
CHANGED
package/dist/commands/apply.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Command, Flags, ux } from '@oclif/core';
|
|
2
|
-
import { text, select, password } from '@clack/prompts';
|
|
2
|
+
import { text, select, password, log, intro } from '@clack/prompts';
|
|
3
3
|
import * as path from 'pathe';
|
|
4
|
+
import { animatedBunny } from '../lib/utils/animated-bunny.js';
|
|
4
5
|
import * as customFlags from '../flags/common.js';
|
|
5
|
-
import { DIRECTUS_PINK, SEPARATOR } from '../lib/constants.js';
|
|
6
|
+
import { DIRECTUS_PINK, DIRECTUS_PURPLE, SEPARATOR } from '../lib/constants.js';
|
|
6
7
|
import { validateInteractiveFlags, validateProgrammaticFlags } from '../lib/load/apply-flags.js';
|
|
7
8
|
import apply from '../lib/load/index.js';
|
|
8
9
|
import { getDirectusToken, getDirectusUrl, initializeDirectusApi } from '../lib/utils/auth.js';
|
|
@@ -10,6 +11,7 @@ import catchError from '../lib/utils/catch-error.js';
|
|
|
10
11
|
import { getCommunityTemplates, getGithubTemplate, getInteractiveLocalTemplate, getLocalTemplate } from '../lib/utils/get-template.js';
|
|
11
12
|
import { logger } from '../lib/utils/logger.js';
|
|
12
13
|
import openUrl from '../lib/utils/open-url.js';
|
|
14
|
+
import chalk from 'chalk';
|
|
13
15
|
export default class ApplyCommand extends Command {
|
|
14
16
|
static description = 'Apply a template to a blank Directus instance.';
|
|
15
17
|
static examples = [
|
|
@@ -102,7 +104,9 @@ export default class ApplyCommand extends Command {
|
|
|
102
104
|
*/
|
|
103
105
|
async runInteractive(flags) {
|
|
104
106
|
const validatedFlags = validateInteractiveFlags(flags);
|
|
105
|
-
//
|
|
107
|
+
// Show animated intro
|
|
108
|
+
await animatedBunny('Let\'s apply a template!');
|
|
109
|
+
intro(`${chalk.bgHex(DIRECTUS_PURPLE).white.bold('Directus Template CLI')} - Apply Template`);
|
|
106
110
|
const templateType = await select({
|
|
107
111
|
options: [
|
|
108
112
|
{ label: 'Community templates', value: 'community' },
|
|
@@ -139,12 +143,11 @@ export default class ApplyCommand extends Command {
|
|
|
139
143
|
}
|
|
140
144
|
case 'directus-plus': {
|
|
141
145
|
openUrl('https://directus.io/plus?utm_source=directus-template-cli&utm_content=apply-command');
|
|
142
|
-
|
|
146
|
+
log.info('Redirecting to Directus website.');
|
|
143
147
|
ux.exit(0);
|
|
144
148
|
}
|
|
145
149
|
}
|
|
146
|
-
|
|
147
|
-
ux.stdout(SEPARATOR);
|
|
150
|
+
log.info(`You selected ${ux.colorize(DIRECTUS_PINK, template.templateName)}`);
|
|
148
151
|
// Get Directus URL
|
|
149
152
|
const directusUrl = await getDirectusUrl();
|
|
150
153
|
validatedFlags.directusUrl = directusUrl;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Command, type Config } from '@oclif/core';
|
|
2
|
+
interface UserConfig {
|
|
3
|
+
distinctId?: string | null;
|
|
4
|
+
}
|
|
5
|
+
export declare abstract class BaseCommand extends Command {
|
|
6
|
+
runId: string;
|
|
7
|
+
userConfig: UserConfig;
|
|
8
|
+
constructor(argv: string[], config: Config);
|
|
9
|
+
private loadUserConfig;
|
|
10
|
+
/**
|
|
11
|
+
* Save the current user configuration to disk
|
|
12
|
+
*/
|
|
13
|
+
protected saveUserConfig(): void;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'pathe';
|
|
5
|
+
export class BaseCommand extends Command {
|
|
6
|
+
runId;
|
|
7
|
+
userConfig = {};
|
|
8
|
+
constructor(argv, config) {
|
|
9
|
+
super(argv, config);
|
|
10
|
+
this.runId = randomUUID();
|
|
11
|
+
this.loadUserConfig();
|
|
12
|
+
}
|
|
13
|
+
loadUserConfig() {
|
|
14
|
+
try {
|
|
15
|
+
const configPath = path.join(this.config.configDir, 'config.json');
|
|
16
|
+
if (fs.existsSync(configPath)) {
|
|
17
|
+
this.userConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
// Create default config if it doesn't exist
|
|
21
|
+
const defaultConfig = {
|
|
22
|
+
distinctId: randomUUID(),
|
|
23
|
+
};
|
|
24
|
+
fs.mkdirSync(this.config.configDir, { recursive: true });
|
|
25
|
+
fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));
|
|
26
|
+
this.userConfig = defaultConfig;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
this.warn(`Failed to load user config: ${error}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Save the current user configuration to disk
|
|
35
|
+
*/
|
|
36
|
+
saveUserConfig() {
|
|
37
|
+
try {
|
|
38
|
+
const configPath = path.join(this.config.configDir, 'config.json');
|
|
39
|
+
fs.writeFileSync(configPath, JSON.stringify(this.userConfig, null, 2));
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
this.warn(`Failed to save user config: ${error}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { Command } from '@oclif/core';
|
|
2
|
+
export interface ExtractFlags {
|
|
3
|
+
directusToken: string;
|
|
4
|
+
directusUrl: string;
|
|
5
|
+
programmatic: boolean;
|
|
6
|
+
templateLocation: string;
|
|
7
|
+
templateName: string;
|
|
8
|
+
userEmail: string;
|
|
9
|
+
userPassword: string;
|
|
10
|
+
}
|
|
2
11
|
export default class ExtractCommand extends Command {
|
|
3
12
|
static description: string;
|
|
4
13
|
static examples: string[];
|
|
@@ -36,12 +45,6 @@ export default class ExtractCommand extends Command {
|
|
|
36
45
|
* @returns {Promise<void>} - Returns nothing
|
|
37
46
|
*/
|
|
38
47
|
private runProgrammatic;
|
|
39
|
-
/**
|
|
40
|
-
* Helper function to create styled headers since ux.styledHeader is removed in v4
|
|
41
|
-
* @param text - The text to style as a header
|
|
42
|
-
* @returns {void}
|
|
43
|
-
*/
|
|
44
|
-
private styledHeader;
|
|
45
48
|
/**
|
|
46
49
|
* Validates the flags for programmatic mode
|
|
47
50
|
* @param {ExtractFlags} flags - The command flags to validate
|
package/dist/commands/extract.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { text, password, select } from '@clack/prompts';
|
|
1
|
+
import { text, password, select, intro } from '@clack/prompts';
|
|
2
2
|
import { Command, ux } from '@oclif/core';
|
|
3
3
|
import slugify from '@sindresorhus/slugify';
|
|
4
4
|
import chalk from 'chalk';
|
|
@@ -6,6 +6,7 @@ import fs from 'node:fs';
|
|
|
6
6
|
import path from 'pathe';
|
|
7
7
|
import * as customFlags from '../flags/common.js';
|
|
8
8
|
import { DIRECTUS_PINK, DIRECTUS_PURPLE, SEPARATOR } from '../lib/constants.js';
|
|
9
|
+
import { animatedBunny } from '../lib/utils/animated-bunny.js';
|
|
9
10
|
import extract from '../lib/extract/index.js';
|
|
10
11
|
import { getDirectusToken, getDirectusUrl, initializeDirectusApi, validateAuthFlags } from '../lib/utils/auth.js';
|
|
11
12
|
import catchError from '../lib/utils/catch-error.js';
|
|
@@ -74,7 +75,8 @@ export default class ExtractCommand extends Command {
|
|
|
74
75
|
* @returns {Promise<void>} - Returns nothing
|
|
75
76
|
*/
|
|
76
77
|
async runInteractive(flags) {
|
|
77
|
-
|
|
78
|
+
await animatedBunny('Let\'s extract a template!');
|
|
79
|
+
intro(`${chalk.bgHex(DIRECTUS_PURPLE).white.bold('Directus Template CLI')} - Extract Template`);
|
|
78
80
|
const templateName = await text({
|
|
79
81
|
message: 'What is the name of the template you would like to extract?',
|
|
80
82
|
placeholder: 'My Template',
|
|
@@ -126,17 +128,6 @@ export default class ExtractCommand extends Command {
|
|
|
126
128
|
await initializeDirectusApi(flags);
|
|
127
129
|
await this.extractTemplate(templateName, templateLocation, flags);
|
|
128
130
|
}
|
|
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
|
-
}
|
|
140
131
|
/**
|
|
141
132
|
* Validates the flags for programmatic mode
|
|
142
133
|
* @param {ExtractFlags} flags - The command flags to validate
|
package/dist/commands/init.d.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
1
|
+
import { BaseCommand } from './base.js';
|
|
2
|
+
export interface InitFlags {
|
|
3
|
+
frontend?: string;
|
|
4
|
+
gitInit?: boolean;
|
|
5
|
+
installDeps?: boolean;
|
|
6
|
+
overrideDir?: boolean;
|
|
7
|
+
template?: string;
|
|
8
|
+
disableTelemetry?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface InitArgs {
|
|
11
|
+
directory: string;
|
|
12
|
+
}
|
|
13
|
+
export default class InitCommand extends BaseCommand {
|
|
3
14
|
static args: {
|
|
4
15
|
directory: import("@oclif/core/interfaces").Arg<string, {
|
|
5
16
|
exists?: boolean;
|
|
@@ -12,8 +23,8 @@ export default class InitCommand extends Command {
|
|
|
12
23
|
gitInit: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
13
24
|
installDeps: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
14
25
|
overrideDir: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
15
|
-
programmatic: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
16
26
|
template: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
27
|
+
disableTelemetry: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
17
28
|
};
|
|
18
29
|
private targetDir;
|
|
19
30
|
/**
|
|
@@ -28,10 +39,4 @@ export default class InitCommand extends Command {
|
|
|
28
39
|
* @returns void
|
|
29
40
|
*/
|
|
30
41
|
private runInteractive;
|
|
31
|
-
/**
|
|
32
|
-
* Programmatic mode: relies on flags only, with checks for template existence and valid frontend.
|
|
33
|
-
* @param flags - The flags passed to the command.
|
|
34
|
-
* @returns void
|
|
35
|
-
*/
|
|
36
|
-
private runProgrammatic;
|
|
37
42
|
}
|
package/dist/commands/init.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import { confirm, intro, select, text } from '@clack/prompts';
|
|
2
|
-
import { Args,
|
|
1
|
+
import { confirm, intro, select, text, isCancel, cancel } from '@clack/prompts';
|
|
2
|
+
import { Args, Flags, ux } from '@oclif/core';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import os from 'node:os';
|
|
4
6
|
import path from 'pathe';
|
|
7
|
+
import { disableTelemetry } from '../flags/common.js';
|
|
5
8
|
import { DIRECTUS_PURPLE } from '../lib/constants.js';
|
|
6
|
-
import { init } from '../lib/init.js';
|
|
9
|
+
import { init } from '../lib/init/index.js';
|
|
7
10
|
import { animatedBunny } from '../lib/utils/animated-bunny.js';
|
|
8
11
|
import { createGitHub } from '../services/github.js';
|
|
9
|
-
|
|
12
|
+
import { readTemplateConfig } from '../lib/utils/template-config.js';
|
|
13
|
+
import { createGigetString, parseGitHubUrl } from '../lib/utils/parse-github-url.js';
|
|
14
|
+
import { downloadTemplate } from 'giget';
|
|
15
|
+
import { BaseCommand } from './base.js';
|
|
16
|
+
import { track, shutdown } from '../services/posthog.js';
|
|
17
|
+
export default class InitCommand extends BaseCommand {
|
|
10
18
|
static args = {
|
|
11
19
|
directory: Args.directory({
|
|
12
20
|
default: '.',
|
|
@@ -18,8 +26,8 @@ export default class InitCommand extends Command {
|
|
|
18
26
|
static examples = [
|
|
19
27
|
'$ directus-template-cli init',
|
|
20
28
|
'$ directus-template-cli init my-project',
|
|
21
|
-
'$ directus-template-cli init --frontend=nextjs --template=simple-cms
|
|
22
|
-
'$ directus-template-cli init my-project --frontend=nextjs --template=simple-cms
|
|
29
|
+
'$ directus-template-cli init --frontend=nextjs --template=simple-cms',
|
|
30
|
+
'$ directus-template-cli init my-project --frontend=nextjs --template=simple-cms',
|
|
23
31
|
];
|
|
24
32
|
static flags = {
|
|
25
33
|
frontend: Flags.string({
|
|
@@ -41,14 +49,10 @@ export default class InitCommand extends Command {
|
|
|
41
49
|
default: false,
|
|
42
50
|
description: 'Override the default directory',
|
|
43
51
|
}),
|
|
44
|
-
programmatic: Flags.boolean({
|
|
45
|
-
char: 'p',
|
|
46
|
-
default: false,
|
|
47
|
-
description: 'Run in programmatic mode (non-interactive)',
|
|
48
|
-
}),
|
|
49
52
|
template: Flags.string({
|
|
50
53
|
description: 'Template name (e.g., simple-cms) or GitHub URL (e.g., https://github.com/directus-labs/starters/tree/main/simple-cms)',
|
|
51
54
|
}),
|
|
55
|
+
disableTelemetry: disableTelemetry,
|
|
52
56
|
};
|
|
53
57
|
targetDir = '.';
|
|
54
58
|
/**
|
|
@@ -61,10 +65,7 @@ export default class InitCommand extends Command {
|
|
|
61
65
|
const typedArgs = args;
|
|
62
66
|
// Set the target directory and create it if it doesn't exist
|
|
63
67
|
this.targetDir = path.resolve(args.directory);
|
|
64
|
-
|
|
65
|
-
// fs.mkdirSync(this.targetDir, {recursive: true})
|
|
66
|
-
// }
|
|
67
|
-
await (typedFlags.programmatic ? this.runProgrammatic(typedFlags) : this.runInteractive(typedFlags, typedArgs));
|
|
68
|
+
await this.runInteractive(typedFlags, typedArgs);
|
|
68
69
|
}
|
|
69
70
|
/**
|
|
70
71
|
* Interactive mode: prompts the user for each piece of info, with added template checks.
|
|
@@ -73,104 +74,168 @@ export default class InitCommand extends Command {
|
|
|
73
74
|
* @returns void
|
|
74
75
|
*/
|
|
75
76
|
async runInteractive(flags, args) {
|
|
77
|
+
// Show animated intro
|
|
76
78
|
await animatedBunny('Let\'s create a new Directus project!');
|
|
77
79
|
intro(`${chalk.bgHex(DIRECTUS_PURPLE).white.bold('Directus Template CLI')} - Create Project`);
|
|
78
80
|
// Create GitHub service
|
|
79
81
|
const github = createGitHub();
|
|
80
82
|
// If no dir is provided, ask for it
|
|
81
83
|
if (!args.directory || args.directory === '.') {
|
|
82
|
-
|
|
84
|
+
const dirResponse = await text({
|
|
83
85
|
message: 'Enter the directory to create the project in:',
|
|
84
86
|
placeholder: './my-directus-project',
|
|
85
|
-
})
|
|
87
|
+
});
|
|
88
|
+
if (isCancel(dirResponse)) {
|
|
89
|
+
cancel('Project creation cancelled.');
|
|
90
|
+
process.exit(0);
|
|
91
|
+
}
|
|
92
|
+
this.targetDir = dirResponse;
|
|
93
|
+
}
|
|
94
|
+
if (fs.existsSync(this.targetDir) && !flags.overrideDir) {
|
|
95
|
+
const overrideDirResponse = await confirm({
|
|
96
|
+
message: 'Directory already exists. Would you like to overwrite it?',
|
|
97
|
+
});
|
|
98
|
+
if (isCancel(overrideDirResponse)) {
|
|
99
|
+
cancel('Project creation cancelled.');
|
|
100
|
+
process.exit(0);
|
|
101
|
+
}
|
|
102
|
+
if (overrideDirResponse) {
|
|
103
|
+
flags.overrideDir = true;
|
|
104
|
+
}
|
|
86
105
|
}
|
|
87
106
|
// 1. Fetch available templates
|
|
88
107
|
const availableTemplates = await github.getTemplates();
|
|
89
108
|
// 2. Prompt for template if not provided
|
|
90
109
|
let { template } = flags;
|
|
91
110
|
if (!template) {
|
|
92
|
-
|
|
111
|
+
const templateResponse = await select({
|
|
93
112
|
message: 'Which Directus backend template would you like to use?',
|
|
94
113
|
options: availableTemplates.map(template => ({
|
|
95
114
|
label: template,
|
|
96
115
|
value: template,
|
|
97
116
|
})),
|
|
98
|
-
})
|
|
117
|
+
});
|
|
118
|
+
if (isCancel(templateResponse)) {
|
|
119
|
+
cancel('Project creation cancelled.');
|
|
120
|
+
process.exit(0);
|
|
121
|
+
}
|
|
122
|
+
template = templateResponse;
|
|
99
123
|
}
|
|
100
124
|
// 3. Validate that the template exists, fetch subdirectories
|
|
101
125
|
let directories = await github.getTemplateDirectories(template);
|
|
102
|
-
|
|
126
|
+
const isDirectUrl = template?.startsWith('http');
|
|
127
|
+
while (!isDirectUrl && directories.length === 0) {
|
|
103
128
|
this.log(`Template "${template}" doesn't seem to exist in directus-labs/directus-starters.`);
|
|
104
|
-
|
|
105
|
-
const templateName = await text({
|
|
129
|
+
const templateNameResponse = await text({
|
|
106
130
|
message: 'Please enter a valid template name, or Ctrl+C to cancel:',
|
|
107
131
|
});
|
|
108
|
-
|
|
109
|
-
|
|
132
|
+
if (isCancel(templateNameResponse)) {
|
|
133
|
+
cancel('Project creation cancelled.');
|
|
134
|
+
process.exit(0);
|
|
135
|
+
}
|
|
136
|
+
template = templateNameResponse;
|
|
110
137
|
directories = await github.getTemplateDirectories(template);
|
|
111
138
|
}
|
|
112
139
|
flags.template = template;
|
|
113
|
-
//
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
140
|
+
// Download the template to a temporary directory to read its configuration
|
|
141
|
+
const tempDir = path.join(os.tmpdir(), `directus-template-${Date.now()}`);
|
|
142
|
+
let chosenFrontend = flags.frontend;
|
|
143
|
+
try {
|
|
144
|
+
await downloadTemplate(createGigetString(parseGitHubUrl(template)), {
|
|
145
|
+
dir: tempDir,
|
|
146
|
+
force: true,
|
|
147
|
+
});
|
|
148
|
+
// Read template configuration
|
|
149
|
+
const templateInfo = readTemplateConfig(tempDir);
|
|
150
|
+
// 4. If template has frontends and user hasn't specified a valid one, ask from the list
|
|
151
|
+
if (templateInfo?.frontendOptions.length > 0 && (!chosenFrontend || !templateInfo.frontendOptions.find(f => f.id === chosenFrontend))) {
|
|
152
|
+
const frontendResponse = await select({
|
|
153
|
+
message: 'Which frontend framework do you want to use?',
|
|
154
|
+
options: [
|
|
155
|
+
...templateInfo.frontendOptions.map(frontend => ({
|
|
156
|
+
label: frontend.name,
|
|
157
|
+
value: frontend.id,
|
|
158
|
+
})),
|
|
159
|
+
// { label: 'No frontend', value: '' },
|
|
160
|
+
],
|
|
161
|
+
});
|
|
162
|
+
if (isCancel(frontendResponse)) {
|
|
163
|
+
cancel('Project creation cancelled.');
|
|
164
|
+
process.exit(0);
|
|
165
|
+
}
|
|
166
|
+
chosenFrontend = frontendResponse;
|
|
167
|
+
}
|
|
168
|
+
flags.frontend = chosenFrontend;
|
|
117
169
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
options: potentialFrontends.map(frontend => ({
|
|
124
|
-
label: frontend,
|
|
125
|
-
value: frontend,
|
|
126
|
-
})),
|
|
127
|
-
}).then(ans => ans);
|
|
170
|
+
finally {
|
|
171
|
+
// Clean up temporary directory
|
|
172
|
+
if (fs.existsSync(tempDir)) {
|
|
173
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
174
|
+
}
|
|
128
175
|
}
|
|
129
|
-
|
|
130
|
-
const installDeps = await confirm({
|
|
176
|
+
const installDepsResponse = await confirm({
|
|
131
177
|
initialValue: true,
|
|
132
178
|
message: 'Would you like to install project dependencies automatically?',
|
|
133
|
-
})
|
|
134
|
-
|
|
179
|
+
});
|
|
180
|
+
if (isCancel(installDepsResponse)) {
|
|
181
|
+
cancel('Project creation cancelled.');
|
|
182
|
+
process.exit(0);
|
|
183
|
+
}
|
|
184
|
+
const installDeps = installDepsResponse;
|
|
185
|
+
const initGitResponse = await confirm({
|
|
135
186
|
initialValue: true,
|
|
136
187
|
message: 'Initialize a new Git repository?',
|
|
137
|
-
}).then(ans => ans);
|
|
138
|
-
await init(this.targetDir, {
|
|
139
|
-
frontend: chosenFrontend,
|
|
140
|
-
gitInit: initGit,
|
|
141
|
-
installDeps,
|
|
142
|
-
template,
|
|
143
188
|
});
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
* Programmatic mode: relies on flags only, with checks for template existence and valid frontend.
|
|
148
|
-
* @param flags - The flags passed to the command.
|
|
149
|
-
* @returns void
|
|
150
|
-
*/
|
|
151
|
-
async runProgrammatic(flags) {
|
|
152
|
-
const github = createGitHub();
|
|
153
|
-
if (!flags.template) {
|
|
154
|
-
ux.error('Missing --template parameter for programmatic mode.');
|
|
189
|
+
if (isCancel(initGitResponse)) {
|
|
190
|
+
cancel('Project creation cancelled.');
|
|
191
|
+
process.exit(0);
|
|
155
192
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
193
|
+
const initGit = initGitResponse;
|
|
194
|
+
// Track the command start unless telemetry is disabled
|
|
195
|
+
if (!flags.disableTelemetry) {
|
|
196
|
+
await track({
|
|
197
|
+
lifecycle: 'start',
|
|
198
|
+
distinctId: this.userConfig.distinctId,
|
|
199
|
+
command: 'init',
|
|
200
|
+
flags: {
|
|
201
|
+
frontend: chosenFrontend,
|
|
202
|
+
gitInit: initGit,
|
|
203
|
+
installDeps,
|
|
204
|
+
template,
|
|
205
|
+
},
|
|
206
|
+
runId: this.runId,
|
|
207
|
+
config: this.config,
|
|
208
|
+
});
|
|
168
209
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
210
|
+
// Initialize the project
|
|
211
|
+
await init({
|
|
212
|
+
dir: this.targetDir,
|
|
213
|
+
flags: {
|
|
214
|
+
frontend: chosenFrontend,
|
|
215
|
+
gitInit: initGit,
|
|
216
|
+
installDeps,
|
|
217
|
+
template,
|
|
218
|
+
overrideDir: flags.overrideDir,
|
|
219
|
+
},
|
|
173
220
|
});
|
|
221
|
+
// Track the command completion unless telemetry is disabled
|
|
222
|
+
if (!flags.disableTelemetry) {
|
|
223
|
+
await track({
|
|
224
|
+
command: 'init',
|
|
225
|
+
lifecycle: 'complete',
|
|
226
|
+
distinctId: this.userConfig.distinctId,
|
|
227
|
+
flags: {
|
|
228
|
+
frontend: chosenFrontend,
|
|
229
|
+
gitInit: initGit,
|
|
230
|
+
installDeps,
|
|
231
|
+
template,
|
|
232
|
+
overrideDir: flags.overrideDir,
|
|
233
|
+
},
|
|
234
|
+
runId: this.runId,
|
|
235
|
+
config: this.config,
|
|
236
|
+
});
|
|
237
|
+
await shutdown();
|
|
238
|
+
}
|
|
174
239
|
ux.exit(0);
|
|
175
240
|
}
|
|
176
241
|
}
|
package/dist/flags/common.d.ts
CHANGED
|
@@ -5,3 +5,4 @@ export declare const userPassword: import("@oclif/core/interfaces").OptionFlag<s
|
|
|
5
5
|
export declare const programmatic: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
6
6
|
export declare const templateLocation: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
7
|
export declare const templateName: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
export declare const disableTelemetry: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
package/dist/flags/common.js
CHANGED
package/dist/lib/constants.d.ts
CHANGED
|
@@ -5,11 +5,6 @@ export declare const COMMUNITY_TEMPLATE_REPO: {
|
|
|
5
5
|
string: string;
|
|
6
6
|
url: string;
|
|
7
7
|
};
|
|
8
|
-
export declare const STARTERS_TEMPLATE_REPO: {
|
|
9
|
-
branch: string;
|
|
10
|
-
string: string;
|
|
11
|
-
url: string;
|
|
12
|
-
};
|
|
13
8
|
export declare const DEFAULT_REPO: {
|
|
14
9
|
owner: string;
|
|
15
10
|
path: string;
|
|
@@ -17,3 +12,6 @@ export declare const DEFAULT_REPO: {
|
|
|
17
12
|
repo: string;
|
|
18
13
|
url: string;
|
|
19
14
|
};
|
|
15
|
+
export declare const POSTHOG_PUBLIC_KEY = "phc_STopE6gj6LDIjYonVF7493kQJK8S4v0Xrl6YPr2z9br";
|
|
16
|
+
export declare const POSTHOG_HOST = "https://us.i.posthog.com";
|
|
17
|
+
export declare const DEFAULT_BRANCH = "main";
|
package/dist/lib/constants.js
CHANGED
|
@@ -5,11 +5,6 @@ export const COMMUNITY_TEMPLATE_REPO = {
|
|
|
5
5
|
string: 'github:directus-labs/directus-templates',
|
|
6
6
|
url: 'https://github.com/directus-labs/directus-templates',
|
|
7
7
|
};
|
|
8
|
-
export const STARTERS_TEMPLATE_REPO = {
|
|
9
|
-
branch: 'cms-template',
|
|
10
|
-
string: 'github:directus-labs/starters',
|
|
11
|
-
url: 'https://github.com/directus-labs/starters',
|
|
12
|
-
};
|
|
13
8
|
export const DEFAULT_REPO = {
|
|
14
9
|
owner: 'directus-labs',
|
|
15
10
|
path: '',
|
|
@@ -17,3 +12,6 @@ export const DEFAULT_REPO = {
|
|
|
17
12
|
repo: 'starters',
|
|
18
13
|
url: 'https://github.com/directus-labs/starters',
|
|
19
14
|
};
|
|
15
|
+
export const POSTHOG_PUBLIC_KEY = 'phc_STopE6gj6LDIjYonVF7493kQJK8S4v0Xrl6YPr2z9br';
|
|
16
|
+
export const POSTHOG_HOST = 'https://us.i.posthog.com';
|
|
17
|
+
export const DEFAULT_BRANCH = 'main';
|
package/dist/lib/init/config.js
CHANGED
package/dist/lib/init/index.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { type DownloadTemplateResult } from 'giget';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
template?: string;
|
|
8
|
-
}
|
|
9
|
-
export declare function init(dir: string, flags: InitFlags): Promise<{
|
|
2
|
+
import type { InitFlags } from '../../commands/init.js';
|
|
3
|
+
export declare function init({ dir, flags }: {
|
|
4
|
+
dir: string;
|
|
5
|
+
flags: InitFlags;
|
|
6
|
+
}): Promise<{
|
|
10
7
|
directusDir: string;
|
|
11
8
|
frontendDir: string;
|
|
12
9
|
template: DownloadTemplateResult;
|
|
13
10
|
}>;
|
|
14
|
-
export {};
|