create-express-kickstart 1.0.2 ā 1.1.0
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/cli.js +35 -8
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -65,6 +65,13 @@ async function init() {
|
|
|
65
65
|
installPinoPretty = (await question('Include pino-pretty for clean development logs? [Y/n] ')).toLowerCase() !== 'n';
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
const packageManagerChoice = await question('\nš Which package manager would you like to use? [npm/yarn/pnpm/bun] (default: npm): ');
|
|
69
|
+
const packageManager = ['yarn', 'pnpm', 'bun'].includes(packageManagerChoice.trim().toLowerCase())
|
|
70
|
+
? packageManagerChoice.trim().toLowerCase()
|
|
71
|
+
: 'npm';
|
|
72
|
+
|
|
73
|
+
const initGit = (await question('\nš Initialize a git repository? [Y/n] ')).toLowerCase() !== 'n';
|
|
74
|
+
|
|
68
75
|
rl.close();
|
|
69
76
|
|
|
70
77
|
console.log(`\nš Creating a new Node.js Express API in ${projectPath}...`);
|
|
@@ -128,13 +135,13 @@ async function init() {
|
|
|
128
135
|
packageJsonTemplate.scripts.format = "prettier --write \"src/**/*.{js,json}\"";
|
|
129
136
|
}
|
|
130
137
|
|
|
131
|
-
//
|
|
138
|
+
// Write package.json
|
|
132
139
|
fs.writeFileSync(
|
|
133
140
|
path.join(projectPath, 'package.json'),
|
|
134
141
|
JSON.stringify(packageJsonTemplate, null, 2)
|
|
135
142
|
);
|
|
136
143
|
|
|
137
|
-
//
|
|
144
|
+
// Install Dependencies
|
|
138
145
|
const dependenciesToInstall = Object.keys(deps).filter(dep => deps[dep] && dep !== 'prettier');
|
|
139
146
|
if (deps['pino-http']) {
|
|
140
147
|
dependenciesToInstall.push('pino');
|
|
@@ -148,30 +155,50 @@ async function init() {
|
|
|
148
155
|
|
|
149
156
|
console.log(`\nā³ Installing selected core dependencies (${dependenciesToInstall.join(', ')}). This might take a minute...`);
|
|
150
157
|
try {
|
|
158
|
+
let installCmd = packageManager === 'yarn' ? 'yarn add'
|
|
159
|
+
: packageManager === 'pnpm' ? 'pnpm add'
|
|
160
|
+
: packageManager === 'bun' ? 'bun add'
|
|
161
|
+
: 'npm install';
|
|
162
|
+
|
|
163
|
+
let installDevCmd = packageManager === 'yarn' ? 'yarn add -D'
|
|
164
|
+
: packageManager === 'pnpm' ? 'pnpm add -D'
|
|
165
|
+
: packageManager === 'bun' ? 'bun add -d'
|
|
166
|
+
: 'npm install --save-dev';
|
|
167
|
+
|
|
151
168
|
if (depString) {
|
|
152
|
-
execSync(
|
|
169
|
+
execSync(`${installCmd} ${depString}`, {
|
|
153
170
|
cwd: projectPath,
|
|
154
171
|
stdio: 'inherit'
|
|
155
172
|
});
|
|
156
173
|
}
|
|
157
174
|
|
|
158
175
|
console.log(`\nā³ Installing latest dev dependencies (${devDepString})...`);
|
|
159
|
-
execSync(
|
|
176
|
+
execSync(`${installDevCmd} ${devDepString}`, {
|
|
160
177
|
cwd: projectPath,
|
|
161
178
|
stdio: 'inherit'
|
|
162
179
|
});
|
|
163
180
|
|
|
181
|
+
if (initGit) {
|
|
182
|
+
console.log(`\nš± Initializing Git repository...`);
|
|
183
|
+
execSync('git init', { cwd: projectPath, stdio: 'inherit' });
|
|
184
|
+
// Create .gitignore
|
|
185
|
+
const gitignoreContent = "node_modules\n.env\ndist\nbuild\ncoverage\n";
|
|
186
|
+
fs.writeFileSync(path.join(projectPath, '.gitignore'), gitignoreContent);
|
|
187
|
+
execSync('git add .', { cwd: projectPath, stdio: 'inherit' });
|
|
188
|
+
execSync('git commit -m "initial commit"', { cwd: projectPath, stdio: 'inherit' });
|
|
189
|
+
}
|
|
190
|
+
|
|
164
191
|
console.log(`\nā
Success! Created "${projectName}" at ${projectPath}`);
|
|
165
192
|
console.log('\nInside that directory, you can run several commands:');
|
|
166
|
-
console.log(
|
|
193
|
+
console.log(`\n ${packageManager === 'npm' ? 'npm run' : packageManager} dev`);
|
|
167
194
|
console.log(' Starts the development server on localhost.');
|
|
168
|
-
console.log(
|
|
195
|
+
console.log(`\n ${packageManager === 'npm' ? 'npm' : packageManager} start`);
|
|
169
196
|
console.log(' Starts the production server.');
|
|
170
197
|
console.log('\nWe suggest that you begin by typing:');
|
|
171
198
|
console.log(`\n cd ${projectName}`);
|
|
172
|
-
console.log('
|
|
199
|
+
console.log(` ${packageManager === 'npm' ? 'npm run' : packageManager} dev\n`);
|
|
173
200
|
} catch (err) {
|
|
174
|
-
console.error('\nā Failed to install dependencies. You may need to
|
|
201
|
+
console.error('\nā Failed to install dependencies. You may need to install them manually inside the folder.', err);
|
|
175
202
|
}
|
|
176
203
|
}
|
|
177
204
|
|