@diagramers/cli 1.0.11 → 1.0.13
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/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +8 -4
- package/dist/commands/init.js.map +1 -1
- package/dist/services/project-initializer.d.ts +3 -1
- package/dist/services/project-initializer.d.ts.map +1 -1
- package/dist/services/project-initializer.js +75 -17
- package/dist/services/project-initializer.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/init.ts +9 -4
- package/src/services/project-initializer.ts +84 -17
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,QA2B3C"}
|
package/dist/commands/init.js
CHANGED
@@ -8,15 +8,19 @@ const project_initializer_1 = require("../services/project-initializer");
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
9
9
|
function initCommand(program) {
|
10
10
|
program
|
11
|
-
.command('init <project-name>')
|
11
|
+
.command('init <template-type> <project-name>')
|
12
12
|
.description('Initialize a new project from the template')
|
13
13
|
.option('-t, --template <template>', 'Template version to use', 'latest')
|
14
14
|
.option('-y, --yes', 'Skip prompts and use defaults')
|
15
|
-
.action(async (projectName, options) => {
|
15
|
+
.action(async (templateType, projectName, options) => {
|
16
16
|
try {
|
17
|
-
console.log(chalk_1.default.blue(`🚀 Initializing new project: ${projectName}`));
|
17
|
+
console.log(chalk_1.default.blue(`🚀 Initializing new ${templateType} project: ${projectName}`));
|
18
|
+
// Validate template type
|
19
|
+
if (templateType !== 'api' && templateType !== 'admin') {
|
20
|
+
throw new Error(`Unsupported template type: ${templateType}. Supported types: api, admin`);
|
21
|
+
}
|
18
22
|
const initializer = new project_initializer_1.ProjectInitializer();
|
19
|
-
await initializer.initialize(projectName, options);
|
23
|
+
await initializer.initialize(projectName, { ...options, template: templateType });
|
20
24
|
console.log(chalk_1.default.green(`✅ Project ${projectName} initialized successfully!`));
|
21
25
|
console.log(chalk_1.default.yellow(`📁 Navigate to the project: cd ${projectName}`));
|
22
26
|
console.log(chalk_1.default.yellow(`🔧 Install dependencies: npm install`));
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":";;;;;AAIA,
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":";;;;;AAIA,kCA2BC;AA9BD,yEAAqE;AACrE,kDAA0B;AAE1B,SAAgB,WAAW,CAAC,OAAgB;IAC1C,OAAO;SACJ,OAAO,CAAC,qCAAqC,CAAC;SAC9C,WAAW,CAAC,4CAA4C,CAAC;SACzD,MAAM,CAAC,2BAA2B,EAAE,yBAAyB,EAAE,QAAQ,CAAC;SACxE,MAAM,CAAC,WAAW,EAAE,+BAA+B,CAAC;SACpD,MAAM,CAAC,KAAK,EAAE,YAAoB,EAAE,WAAmB,EAAE,OAAY,EAAE,EAAE;QACxE,IAAI,CAAC;YACH,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,uBAAuB,YAAY,aAAa,WAAW,EAAE,CAAC,CAAC,CAAC;YAEvF,yBAAyB;YACzB,IAAI,YAAY,KAAK,KAAK,IAAI,YAAY,KAAK,OAAO,EAAE,CAAC;gBACvD,MAAM,IAAI,KAAK,CAAC,8BAA8B,YAAY,+BAA+B,CAAC,CAAC;YAC7F,CAAC;YAED,MAAM,WAAW,GAAG,IAAI,wCAAkB,EAAE,CAAC;YAC7C,MAAM,WAAW,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC,CAAC;YAElF,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,aAAa,WAAW,4BAA4B,CAAC,CAAC,CAAC;YAC/E,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,kCAAkC,WAAW,EAAE,CAAC,CAAC,CAAC;YAC3E,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,sCAAsC,CAAC,CAAC,CAAC;YAClE,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,qCAAqC,CAAC,CAAC,CAAC;QACnE,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,mCAAmC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAC7E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
@@ -6,11 +6,13 @@ export declare class ProjectInitializer {
|
|
6
6
|
private templateFiles;
|
7
7
|
constructor();
|
8
8
|
initialize(projectName: string, options: InitOptions): Promise<void>;
|
9
|
-
private
|
9
|
+
private installTemplatePackage;
|
10
10
|
private copyTemplateFiles;
|
11
11
|
private cleanup;
|
12
12
|
private updatePackageJson;
|
13
13
|
private createGitignore;
|
14
14
|
private createReadme;
|
15
|
+
private makeScriptsExecutable;
|
16
|
+
private processTemplate;
|
15
17
|
}
|
16
18
|
//# sourceMappingURL=project-initializer.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"project-initializer.d.ts","sourceRoot":"","sources":["../../src/services/project-initializer.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,aAAa,
|
1
|
+
{"version":3,"file":"project-initializer.d.ts","sourceRoot":"","sources":["../../src/services/project-initializer.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,aAAa,CASnB;;IAMI,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;YAuC5D,sBAAsB;YAetB,iBAAiB;YAwCjB,OAAO;YAcP,iBAAiB;YA8BjB,eAAe;YAyDf,YAAY;YAsEZ,qBAAqB;YAoBrB,eAAe;CAsB9B"}
|
@@ -45,7 +45,9 @@ const child_process_1 = require("child_process");
|
|
45
45
|
class ProjectInitializer {
|
46
46
|
constructor() {
|
47
47
|
this.templateFiles = [
|
48
|
+
'scripts',
|
48
49
|
'src/**/*',
|
50
|
+
'scripts/**/*',
|
49
51
|
'package.json',
|
50
52
|
'tsconfig.json',
|
51
53
|
'webpack.config.js',
|
@@ -56,43 +58,49 @@ class ProjectInitializer {
|
|
56
58
|
}
|
57
59
|
async initialize(projectName, options) {
|
58
60
|
const projectPath = path.resolve(process.cwd(), projectName);
|
61
|
+
const templateType = options.template || 'api';
|
59
62
|
// Check if project directory already exists
|
60
63
|
if (await fs.pathExists(projectPath)) {
|
61
64
|
throw new Error(`Project directory ${projectName} already exists`);
|
62
65
|
}
|
63
66
|
// Create project directory
|
64
67
|
await fs.ensureDir(projectPath);
|
65
|
-
// Install the
|
66
|
-
await this.
|
68
|
+
// Install the appropriate template package
|
69
|
+
await this.installTemplatePackage(projectPath, templateType);
|
67
70
|
// Copy template files from the installed package
|
68
|
-
await this.copyTemplateFiles(projectPath);
|
71
|
+
await this.copyTemplateFiles(projectPath, templateType);
|
69
72
|
// Update package.json with project name
|
70
|
-
await this.updatePackageJson(projectPath, projectName);
|
73
|
+
await this.updatePackageJson(projectPath, projectName, templateType);
|
71
74
|
// Create .gitignore
|
72
75
|
await this.createGitignore(projectPath);
|
73
76
|
// Create README
|
74
|
-
await this.createReadme(projectPath, projectName);
|
77
|
+
await this.createReadme(projectPath, projectName, templateType);
|
78
|
+
// Make scripts executable
|
79
|
+
await this.makeScriptsExecutable(projectPath);
|
80
|
+
// Process template for project name (update database names, etc.)
|
81
|
+
await this.processTemplate(projectPath, projectName);
|
75
82
|
// Clean up the temporary installation
|
76
83
|
await this.cleanup(projectPath);
|
77
84
|
console.log(chalk_1.default.green(`✅ Project structure created successfully`));
|
78
85
|
}
|
79
|
-
async
|
80
|
-
|
86
|
+
async installTemplatePackage(projectPath, templateType) {
|
87
|
+
const packageName = `@diagramers/${templateType}`;
|
88
|
+
console.log(chalk_1.default.blue(`📦 Installing ${packageName} template...`));
|
81
89
|
try {
|
82
|
-
// Install the
|
83
|
-
(0, child_process_1.execSync)(
|
90
|
+
// Install the template package temporarily
|
91
|
+
(0, child_process_1.execSync)(`npm install ${packageName} --no-save`, {
|
84
92
|
cwd: projectPath,
|
85
93
|
stdio: 'inherit'
|
86
94
|
});
|
87
95
|
}
|
88
96
|
catch (error) {
|
89
|
-
throw new Error(`Failed to install
|
97
|
+
throw new Error(`Failed to install ${packageName} package: ${error.message}`);
|
90
98
|
}
|
91
99
|
}
|
92
|
-
async copyTemplateFiles(projectPath) {
|
93
|
-
const nodeModulesPath = path.join(projectPath, 'node_modules', '@diagramers',
|
100
|
+
async copyTemplateFiles(projectPath, templateType) {
|
101
|
+
const nodeModulesPath = path.join(projectPath, 'node_modules', '@diagramers', templateType);
|
94
102
|
if (!await fs.pathExists(nodeModulesPath)) {
|
95
|
-
throw new Error(
|
103
|
+
throw new Error(`@diagramers/${templateType} package not found in node_modules`);
|
96
104
|
}
|
97
105
|
for (const pattern of this.templateFiles) {
|
98
106
|
try {
|
@@ -137,16 +145,27 @@ class ProjectInitializer {
|
|
137
145
|
await fs.remove(packageLockPath);
|
138
146
|
}
|
139
147
|
}
|
140
|
-
async updatePackageJson(projectPath, projectName) {
|
148
|
+
async updatePackageJson(projectPath, projectName, templateType) {
|
141
149
|
const packageJsonPath = path.join(projectPath, 'package.json');
|
142
150
|
if (await fs.pathExists(packageJsonPath)) {
|
143
151
|
const packageJson = await fs.readJson(packageJsonPath);
|
144
152
|
packageJson.name = projectName;
|
145
|
-
packageJson.description =
|
153
|
+
packageJson.description = `${templateType.toUpperCase()} project: ${projectName}`;
|
146
154
|
// Remove the bin field if it exists (this is for CLI packages)
|
147
155
|
if (packageJson.bin) {
|
148
156
|
delete packageJson.bin;
|
149
157
|
}
|
158
|
+
// Ensure CLI scripts are included
|
159
|
+
if (!packageJson.scripts) {
|
160
|
+
packageJson.scripts = {};
|
161
|
+
}
|
162
|
+
// Add CLI scripts if they don't exist
|
163
|
+
if (!packageJson.scripts['generate:module']) {
|
164
|
+
packageJson.scripts['generate:module'] = './scripts/generate-module.sh';
|
165
|
+
}
|
166
|
+
if (!packageJson.scripts['cli']) {
|
167
|
+
packageJson.scripts['cli'] = './scripts/cli-commands.sh';
|
168
|
+
}
|
150
169
|
await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
|
151
170
|
}
|
152
171
|
}
|
@@ -205,10 +224,11 @@ temp/
|
|
205
224
|
`.trim();
|
206
225
|
await fs.writeFile(path.join(projectPath, '.gitignore'), gitignoreContent);
|
207
226
|
}
|
208
|
-
async createReadme(projectPath, projectName) {
|
227
|
+
async createReadme(projectPath, projectName, templateType) {
|
228
|
+
const templateTitle = templateType.toUpperCase();
|
209
229
|
const readmeContent = `# ${projectName}
|
210
230
|
|
211
|
-
A Node.js
|
231
|
+
A Node.js ${templateType} project built with TypeScript and Firebase Functions.
|
212
232
|
|
213
233
|
## Features
|
214
234
|
|
@@ -272,6 +292,44 @@ MIT
|
|
272
292
|
`;
|
273
293
|
await fs.writeFile(path.join(projectPath, 'README.md'), readmeContent);
|
274
294
|
}
|
295
|
+
async makeScriptsExecutable(projectPath) {
|
296
|
+
const scriptsDir = path.join(projectPath, 'scripts');
|
297
|
+
if (await fs.pathExists(scriptsDir)) {
|
298
|
+
try {
|
299
|
+
const scripts = await fs.readdir(scriptsDir);
|
300
|
+
for (const script of scripts) {
|
301
|
+
if (script.endsWith('.sh')) {
|
302
|
+
const scriptPath = path.join(scriptsDir, script);
|
303
|
+
// Make script executable (chmod 755)
|
304
|
+
await fs.chmod(scriptPath, 0o755);
|
305
|
+
console.log(chalk_1.default.blue(`🔧 Made executable: ${script}`));
|
306
|
+
}
|
307
|
+
}
|
308
|
+
}
|
309
|
+
catch (error) {
|
310
|
+
console.log(chalk_1.default.yellow(`⚠️ Warning: Could not make scripts executable: ${error.message}`));
|
311
|
+
}
|
312
|
+
}
|
313
|
+
}
|
314
|
+
async processTemplate(projectPath, projectName) {
|
315
|
+
try {
|
316
|
+
console.log(chalk_1.default.blue(`🔧 Processing template for project: ${projectName}`));
|
317
|
+
// Change to project directory
|
318
|
+
const originalCwd = process.cwd();
|
319
|
+
process.chdir(projectPath);
|
320
|
+
// Run the template processor
|
321
|
+
(0, child_process_1.execSync)(`npm run cli process:template ${projectName}`, {
|
322
|
+
stdio: 'inherit'
|
323
|
+
});
|
324
|
+
// Change back to original directory
|
325
|
+
process.chdir(originalCwd);
|
326
|
+
console.log(chalk_1.default.green(`✅ Template processed successfully`));
|
327
|
+
}
|
328
|
+
catch (error) {
|
329
|
+
console.log(chalk_1.default.yellow(`⚠️ Warning: Could not process template: ${error.message}`));
|
330
|
+
console.log(chalk_1.default.yellow(` You can manually run: npm run cli process:template ${projectName}`));
|
331
|
+
}
|
332
|
+
}
|
275
333
|
}
|
276
334
|
exports.ProjectInitializer = ProjectInitializer;
|
277
335
|
//# sourceMappingURL=project-initializer.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"project-initializer.js","sourceRoot":"","sources":["../../src/services/project-initializer.ts"],"names":[],"mappings":";;;;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C,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,4CAA4C,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YACvF,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,yDAAyD,WAAW,EAAE,CAAC,CAAC,CAAC;QACpG,CAAC;IACH,CAAC;CACF;AAnUD,gDAmUC"}
|
package/package.json
CHANGED
package/src/commands/init.ts
CHANGED
@@ -4,16 +4,21 @@ import chalk from 'chalk';
|
|
4
4
|
|
5
5
|
export function initCommand(program: Command) {
|
6
6
|
program
|
7
|
-
.command('init <project-name>')
|
7
|
+
.command('init <template-type> <project-name>')
|
8
8
|
.description('Initialize a new project from the template')
|
9
9
|
.option('-t, --template <template>', 'Template version to use', 'latest')
|
10
10
|
.option('-y, --yes', 'Skip prompts and use defaults')
|
11
|
-
.action(async (projectName: string, options: any) => {
|
11
|
+
.action(async (templateType: string, projectName: string, options: any) => {
|
12
12
|
try {
|
13
|
-
console.log(chalk.blue(`🚀 Initializing new project: ${projectName}`));
|
13
|
+
console.log(chalk.blue(`🚀 Initializing new ${templateType} project: ${projectName}`));
|
14
|
+
|
15
|
+
// Validate template type
|
16
|
+
if (templateType !== 'api' && templateType !== 'admin') {
|
17
|
+
throw new Error(`Unsupported template type: ${templateType}. Supported types: api, admin`);
|
18
|
+
}
|
14
19
|
|
15
20
|
const initializer = new ProjectInitializer();
|
16
|
-
await initializer.initialize(projectName, options);
|
21
|
+
await initializer.initialize(projectName, { ...options, template: templateType });
|
17
22
|
|
18
23
|
console.log(chalk.green(`✅ Project ${projectName} initialized successfully!`));
|
19
24
|
console.log(chalk.yellow(`📁 Navigate to the project: cd ${projectName}`));
|
@@ -11,7 +11,9 @@ export interface InitOptions {
|
|
11
11
|
|
12
12
|
export class ProjectInitializer {
|
13
13
|
private templateFiles: string[] = [
|
14
|
+
'scripts',
|
14
15
|
'src/**/*',
|
16
|
+
'scripts/**/*',
|
15
17
|
'package.json',
|
16
18
|
'tsconfig.json',
|
17
19
|
'webpack.config.js',
|
@@ -25,6 +27,7 @@ export class ProjectInitializer {
|
|
25
27
|
|
26
28
|
async initialize(projectName: string, options: InitOptions): Promise<void> {
|
27
29
|
const projectPath = path.resolve(process.cwd(), projectName);
|
30
|
+
const templateType = options.template || 'api';
|
28
31
|
|
29
32
|
// Check if project directory already exists
|
30
33
|
if (await fs.pathExists(projectPath)) {
|
@@ -34,20 +37,26 @@ export class ProjectInitializer {
|
|
34
37
|
// Create project directory
|
35
38
|
await fs.ensureDir(projectPath);
|
36
39
|
|
37
|
-
// Install the
|
38
|
-
await this.
|
40
|
+
// Install the appropriate template package
|
41
|
+
await this.installTemplatePackage(projectPath, templateType);
|
39
42
|
|
40
43
|
// Copy template files from the installed package
|
41
|
-
await this.copyTemplateFiles(projectPath);
|
44
|
+
await this.copyTemplateFiles(projectPath, templateType);
|
42
45
|
|
43
46
|
// Update package.json with project name
|
44
|
-
await this.updatePackageJson(projectPath, projectName);
|
47
|
+
await this.updatePackageJson(projectPath, projectName, templateType);
|
45
48
|
|
46
49
|
// Create .gitignore
|
47
50
|
await this.createGitignore(projectPath);
|
48
51
|
|
49
52
|
// Create README
|
50
|
-
await this.createReadme(projectPath, projectName);
|
53
|
+
await this.createReadme(projectPath, projectName, templateType);
|
54
|
+
|
55
|
+
// Make scripts executable
|
56
|
+
await this.makeScriptsExecutable(projectPath);
|
57
|
+
|
58
|
+
// Process template for project name (update database names, etc.)
|
59
|
+
await this.processTemplate(projectPath, projectName);
|
51
60
|
|
52
61
|
// Clean up the temporary installation
|
53
62
|
await this.cleanup(projectPath);
|
@@ -55,25 +64,26 @@ export class ProjectInitializer {
|
|
55
64
|
console.log(chalk.green(`✅ Project structure created successfully`));
|
56
65
|
}
|
57
66
|
|
58
|
-
private async
|
59
|
-
|
67
|
+
private async installTemplatePackage(projectPath: string, templateType: string): Promise<void> {
|
68
|
+
const packageName = `@diagramers/${templateType}`;
|
69
|
+
console.log(chalk.blue(`📦 Installing ${packageName} template...`));
|
60
70
|
|
61
71
|
try {
|
62
|
-
// Install the
|
63
|
-
execSync(
|
72
|
+
// Install the template package temporarily
|
73
|
+
execSync(`npm install ${packageName} --no-save`, {
|
64
74
|
cwd: projectPath,
|
65
75
|
stdio: 'inherit'
|
66
76
|
});
|
67
77
|
} catch (error: any) {
|
68
|
-
throw new Error(`Failed to install
|
78
|
+
throw new Error(`Failed to install ${packageName} package: ${error.message}`);
|
69
79
|
}
|
70
80
|
}
|
71
81
|
|
72
|
-
private async copyTemplateFiles(projectPath: string): Promise<void> {
|
73
|
-
const nodeModulesPath = path.join(projectPath, 'node_modules', '@diagramers',
|
82
|
+
private async copyTemplateFiles(projectPath: string, templateType: string): Promise<void> {
|
83
|
+
const nodeModulesPath = path.join(projectPath, 'node_modules', '@diagramers', templateType);
|
74
84
|
|
75
85
|
if (!await fs.pathExists(nodeModulesPath)) {
|
76
|
-
throw new Error(
|
86
|
+
throw new Error(`@diagramers/${templateType} package not found in node_modules`);
|
77
87
|
}
|
78
88
|
|
79
89
|
for (const pattern of this.templateFiles) {
|
@@ -123,18 +133,31 @@ export class ProjectInitializer {
|
|
123
133
|
}
|
124
134
|
}
|
125
135
|
|
126
|
-
private async updatePackageJson(projectPath: string, projectName: string): Promise<void> {
|
136
|
+
private async updatePackageJson(projectPath: string, projectName: string, templateType: string): Promise<void> {
|
127
137
|
const packageJsonPath = path.join(projectPath, 'package.json');
|
128
138
|
|
129
139
|
if (await fs.pathExists(packageJsonPath)) {
|
130
140
|
const packageJson = await fs.readJson(packageJsonPath);
|
131
141
|
packageJson.name = projectName;
|
132
|
-
packageJson.description =
|
142
|
+
packageJson.description = `${templateType.toUpperCase()} project: ${projectName}`;
|
133
143
|
|
134
144
|
// Remove the bin field if it exists (this is for CLI packages)
|
135
145
|
if (packageJson.bin) {
|
136
146
|
delete packageJson.bin;
|
137
147
|
}
|
148
|
+
|
149
|
+
// Ensure CLI scripts are included
|
150
|
+
if (!packageJson.scripts) {
|
151
|
+
packageJson.scripts = {};
|
152
|
+
}
|
153
|
+
|
154
|
+
// Add CLI scripts if they don't exist
|
155
|
+
if (!packageJson.scripts['generate:module']) {
|
156
|
+
packageJson.scripts['generate:module'] = './scripts/generate-module.sh';
|
157
|
+
}
|
158
|
+
if (!packageJson.scripts['cli']) {
|
159
|
+
packageJson.scripts['cli'] = './scripts/cli-commands.sh';
|
160
|
+
}
|
138
161
|
|
139
162
|
await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
|
140
163
|
}
|
@@ -197,10 +220,11 @@ temp/
|
|
197
220
|
await fs.writeFile(path.join(projectPath, '.gitignore'), gitignoreContent);
|
198
221
|
}
|
199
222
|
|
200
|
-
private async createReadme(projectPath: string, projectName: string): Promise<void> {
|
223
|
+
private async createReadme(projectPath: string, projectName: string, templateType: string): Promise<void> {
|
224
|
+
const templateTitle = templateType.toUpperCase();
|
201
225
|
const readmeContent = `# ${projectName}
|
202
226
|
|
203
|
-
A Node.js
|
227
|
+
A Node.js ${templateType} project built with TypeScript and Firebase Functions.
|
204
228
|
|
205
229
|
## Features
|
206
230
|
|
@@ -265,4 +289,47 @@ MIT
|
|
265
289
|
|
266
290
|
await fs.writeFile(path.join(projectPath, 'README.md'), readmeContent);
|
267
291
|
}
|
292
|
+
|
293
|
+
private async makeScriptsExecutable(projectPath: string): Promise<void> {
|
294
|
+
const scriptsDir = path.join(projectPath, 'scripts');
|
295
|
+
|
296
|
+
if (await fs.pathExists(scriptsDir)) {
|
297
|
+
try {
|
298
|
+
const scripts = await fs.readdir(scriptsDir);
|
299
|
+
for (const script of scripts) {
|
300
|
+
if (script.endsWith('.sh')) {
|
301
|
+
const scriptPath = path.join(scriptsDir, script);
|
302
|
+
// Make script executable (chmod 755)
|
303
|
+
await fs.chmod(scriptPath, 0o755);
|
304
|
+
console.log(chalk.blue(`🔧 Made executable: ${script}`));
|
305
|
+
}
|
306
|
+
}
|
307
|
+
} catch (error: any) {
|
308
|
+
console.log(chalk.yellow(`⚠️ Warning: Could not make scripts executable: ${error.message}`));
|
309
|
+
}
|
310
|
+
}
|
311
|
+
}
|
312
|
+
|
313
|
+
private async processTemplate(projectPath: string, projectName: string): Promise<void> {
|
314
|
+
try {
|
315
|
+
console.log(chalk.blue(`🔧 Processing template for project: ${projectName}`));
|
316
|
+
|
317
|
+
// Change to project directory
|
318
|
+
const originalCwd = process.cwd();
|
319
|
+
process.chdir(projectPath);
|
320
|
+
|
321
|
+
// Run the template processor
|
322
|
+
execSync(`npm run cli process:template ${projectName}`, {
|
323
|
+
stdio: 'inherit'
|
324
|
+
});
|
325
|
+
|
326
|
+
// Change back to original directory
|
327
|
+
process.chdir(originalCwd);
|
328
|
+
|
329
|
+
console.log(chalk.green(`✅ Template processed successfully`));
|
330
|
+
} catch (error: any) {
|
331
|
+
console.log(chalk.yellow(`⚠️ Warning: Could not process template: ${error.message}`));
|
332
|
+
console.log(chalk.yellow(` You can manually run: npm run cli process:template ${projectName}`));
|
333
|
+
}
|
334
|
+
}
|
268
335
|
}
|