@diagramers/cli 1.0.11 → 1.0.12
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 +1 -1
- package/dist/services/project-initializer.d.ts.map +1 -1
- package/dist/services/project-initializer.js +20 -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 +20 -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,7 +6,7 @@ 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;
|
@@ -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,CAOnB;;IAMI,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;
|
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,CAOnB;;IAMI,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;YAiC5D,sBAAsB;YAetB,iBAAiB;YAwCjB,OAAO;YAcP,iBAAiB;YAiBjB,eAAe;YAyDf,YAAY;CAqE3B"}
|
@@ -56,43 +56,45 @@ class ProjectInitializer {
|
|
56
56
|
}
|
57
57
|
async initialize(projectName, options) {
|
58
58
|
const projectPath = path.resolve(process.cwd(), projectName);
|
59
|
+
const templateType = options.template || 'api';
|
59
60
|
// Check if project directory already exists
|
60
61
|
if (await fs.pathExists(projectPath)) {
|
61
62
|
throw new Error(`Project directory ${projectName} already exists`);
|
62
63
|
}
|
63
64
|
// Create project directory
|
64
65
|
await fs.ensureDir(projectPath);
|
65
|
-
// Install the
|
66
|
-
await this.
|
66
|
+
// Install the appropriate template package
|
67
|
+
await this.installTemplatePackage(projectPath, templateType);
|
67
68
|
// Copy template files from the installed package
|
68
|
-
await this.copyTemplateFiles(projectPath);
|
69
|
+
await this.copyTemplateFiles(projectPath, templateType);
|
69
70
|
// Update package.json with project name
|
70
|
-
await this.updatePackageJson(projectPath, projectName);
|
71
|
+
await this.updatePackageJson(projectPath, projectName, templateType);
|
71
72
|
// Create .gitignore
|
72
73
|
await this.createGitignore(projectPath);
|
73
74
|
// Create README
|
74
|
-
await this.createReadme(projectPath, projectName);
|
75
|
+
await this.createReadme(projectPath, projectName, templateType);
|
75
76
|
// Clean up the temporary installation
|
76
77
|
await this.cleanup(projectPath);
|
77
78
|
console.log(chalk_1.default.green(`✅ Project structure created successfully`));
|
78
79
|
}
|
79
|
-
async
|
80
|
-
|
80
|
+
async installTemplatePackage(projectPath, templateType) {
|
81
|
+
const packageName = `@diagramers/${templateType}`;
|
82
|
+
console.log(chalk_1.default.blue(`📦 Installing ${packageName} template...`));
|
81
83
|
try {
|
82
|
-
// Install the
|
83
|
-
(0, child_process_1.execSync)(
|
84
|
+
// Install the template package temporarily
|
85
|
+
(0, child_process_1.execSync)(`npm install ${packageName} --no-save`, {
|
84
86
|
cwd: projectPath,
|
85
87
|
stdio: 'inherit'
|
86
88
|
});
|
87
89
|
}
|
88
90
|
catch (error) {
|
89
|
-
throw new Error(`Failed to install
|
91
|
+
throw new Error(`Failed to install ${packageName} package: ${error.message}`);
|
90
92
|
}
|
91
93
|
}
|
92
|
-
async copyTemplateFiles(projectPath) {
|
93
|
-
const nodeModulesPath = path.join(projectPath, 'node_modules', '@diagramers',
|
94
|
+
async copyTemplateFiles(projectPath, templateType) {
|
95
|
+
const nodeModulesPath = path.join(projectPath, 'node_modules', '@diagramers', templateType);
|
94
96
|
if (!await fs.pathExists(nodeModulesPath)) {
|
95
|
-
throw new Error(
|
97
|
+
throw new Error(`@diagramers/${templateType} package not found in node_modules`);
|
96
98
|
}
|
97
99
|
for (const pattern of this.templateFiles) {
|
98
100
|
try {
|
@@ -137,12 +139,12 @@ class ProjectInitializer {
|
|
137
139
|
await fs.remove(packageLockPath);
|
138
140
|
}
|
139
141
|
}
|
140
|
-
async updatePackageJson(projectPath, projectName) {
|
142
|
+
async updatePackageJson(projectPath, projectName, templateType) {
|
141
143
|
const packageJsonPath = path.join(projectPath, 'package.json');
|
142
144
|
if (await fs.pathExists(packageJsonPath)) {
|
143
145
|
const packageJson = await fs.readJson(packageJsonPath);
|
144
146
|
packageJson.name = projectName;
|
145
|
-
packageJson.description =
|
147
|
+
packageJson.description = `${templateType.toUpperCase()} project: ${projectName}`;
|
146
148
|
// Remove the bin field if it exists (this is for CLI packages)
|
147
149
|
if (packageJson.bin) {
|
148
150
|
delete packageJson.bin;
|
@@ -205,10 +207,11 @@ temp/
|
|
205
207
|
`.trim();
|
206
208
|
await fs.writeFile(path.join(projectPath, '.gitignore'), gitignoreContent);
|
207
209
|
}
|
208
|
-
async createReadme(projectPath, projectName) {
|
210
|
+
async createReadme(projectPath, projectName, templateType) {
|
211
|
+
const templateTitle = templateType.toUpperCase();
|
209
212
|
const readmeContent = `# ${projectName}
|
210
213
|
|
211
|
-
A Node.js
|
214
|
+
A Node.js ${templateType} project built with TypeScript and Firebase Functions.
|
212
215
|
|
213
216
|
## Features
|
214
217
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"project-initializer.js","sourceRoot":"","sources":["../../src/services/project-initializer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAC/B,2CAA6B;AAC7B,2CAA6B;AAC7B,kDAA0B;AAC1B,iDAAyC;AAOzC,MAAa,kBAAkB;IAU7B;QATQ,kBAAa,GAAa;YAChC,UAAU;YACV,cAAc;YACd,eAAe;YACf,mBAAmB;YACnB,SAAS;YACT,YAAY;SACb,CAAC;QAGA,qDAAqD;IACvD,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,WAAmB,EAAE,OAAoB;QACxD,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,WAAW,CAAC,CAAC;
|
1
|
+
{"version":3,"file":"project-initializer.js","sourceRoot":"","sources":["../../src/services/project-initializer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAC/B,2CAA6B;AAC7B,2CAA6B;AAC7B,kDAA0B;AAC1B,iDAAyC;AAOzC,MAAa,kBAAkB;IAU7B;QATQ,kBAAa,GAAa;YAChC,UAAU;YACV,cAAc;YACd,eAAe;YACf,mBAAmB;YACnB,SAAS;YACT,YAAY;SACb,CAAC;QAGA,qDAAqD;IACv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
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}`));
|
@@ -25,6 +25,7 @@ export class ProjectInitializer {
|
|
25
25
|
|
26
26
|
async initialize(projectName: string, options: InitOptions): Promise<void> {
|
27
27
|
const projectPath = path.resolve(process.cwd(), projectName);
|
28
|
+
const templateType = options.template || 'api';
|
28
29
|
|
29
30
|
// Check if project directory already exists
|
30
31
|
if (await fs.pathExists(projectPath)) {
|
@@ -34,20 +35,20 @@ export class ProjectInitializer {
|
|
34
35
|
// Create project directory
|
35
36
|
await fs.ensureDir(projectPath);
|
36
37
|
|
37
|
-
// Install the
|
38
|
-
await this.
|
38
|
+
// Install the appropriate template package
|
39
|
+
await this.installTemplatePackage(projectPath, templateType);
|
39
40
|
|
40
41
|
// Copy template files from the installed package
|
41
|
-
await this.copyTemplateFiles(projectPath);
|
42
|
+
await this.copyTemplateFiles(projectPath, templateType);
|
42
43
|
|
43
44
|
// Update package.json with project name
|
44
|
-
await this.updatePackageJson(projectPath, projectName);
|
45
|
+
await this.updatePackageJson(projectPath, projectName, templateType);
|
45
46
|
|
46
47
|
// Create .gitignore
|
47
48
|
await this.createGitignore(projectPath);
|
48
49
|
|
49
50
|
// Create README
|
50
|
-
await this.createReadme(projectPath, projectName);
|
51
|
+
await this.createReadme(projectPath, projectName, templateType);
|
51
52
|
|
52
53
|
// Clean up the temporary installation
|
53
54
|
await this.cleanup(projectPath);
|
@@ -55,25 +56,26 @@ export class ProjectInitializer {
|
|
55
56
|
console.log(chalk.green(`✅ Project structure created successfully`));
|
56
57
|
}
|
57
58
|
|
58
|
-
private async
|
59
|
-
|
59
|
+
private async installTemplatePackage(projectPath: string, templateType: string): Promise<void> {
|
60
|
+
const packageName = `@diagramers/${templateType}`;
|
61
|
+
console.log(chalk.blue(`📦 Installing ${packageName} template...`));
|
60
62
|
|
61
63
|
try {
|
62
|
-
// Install the
|
63
|
-
execSync(
|
64
|
+
// Install the template package temporarily
|
65
|
+
execSync(`npm install ${packageName} --no-save`, {
|
64
66
|
cwd: projectPath,
|
65
67
|
stdio: 'inherit'
|
66
68
|
});
|
67
69
|
} catch (error: any) {
|
68
|
-
throw new Error(`Failed to install
|
70
|
+
throw new Error(`Failed to install ${packageName} package: ${error.message}`);
|
69
71
|
}
|
70
72
|
}
|
71
73
|
|
72
|
-
private async copyTemplateFiles(projectPath: string): Promise<void> {
|
73
|
-
const nodeModulesPath = path.join(projectPath, 'node_modules', '@diagramers',
|
74
|
+
private async copyTemplateFiles(projectPath: string, templateType: string): Promise<void> {
|
75
|
+
const nodeModulesPath = path.join(projectPath, 'node_modules', '@diagramers', templateType);
|
74
76
|
|
75
77
|
if (!await fs.pathExists(nodeModulesPath)) {
|
76
|
-
throw new Error(
|
78
|
+
throw new Error(`@diagramers/${templateType} package not found in node_modules`);
|
77
79
|
}
|
78
80
|
|
79
81
|
for (const pattern of this.templateFiles) {
|
@@ -123,13 +125,13 @@ export class ProjectInitializer {
|
|
123
125
|
}
|
124
126
|
}
|
125
127
|
|
126
|
-
private async updatePackageJson(projectPath: string, projectName: string): Promise<void> {
|
128
|
+
private async updatePackageJson(projectPath: string, projectName: string, templateType: string): Promise<void> {
|
127
129
|
const packageJsonPath = path.join(projectPath, 'package.json');
|
128
130
|
|
129
131
|
if (await fs.pathExists(packageJsonPath)) {
|
130
132
|
const packageJson = await fs.readJson(packageJsonPath);
|
131
133
|
packageJson.name = projectName;
|
132
|
-
packageJson.description =
|
134
|
+
packageJson.description = `${templateType.toUpperCase()} project: ${projectName}`;
|
133
135
|
|
134
136
|
// Remove the bin field if it exists (this is for CLI packages)
|
135
137
|
if (packageJson.bin) {
|
@@ -197,10 +199,11 @@ temp/
|
|
197
199
|
await fs.writeFile(path.join(projectPath, '.gitignore'), gitignoreContent);
|
198
200
|
}
|
199
201
|
|
200
|
-
private async createReadme(projectPath: string, projectName: string): Promise<void> {
|
202
|
+
private async createReadme(projectPath: string, projectName: string, templateType: string): Promise<void> {
|
203
|
+
const templateTitle = templateType.toUpperCase();
|
201
204
|
const readmeContent = `# ${projectName}
|
202
205
|
|
203
|
-
A Node.js
|
206
|
+
A Node.js ${templateType} project built with TypeScript and Firebase Functions.
|
204
207
|
|
205
208
|
## Features
|
206
209
|
|