create-express-kickstart 1.0.2 ā 1.1.1
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 +48 -8
- package/package.json +1 -1
- package/templates/Dockerfile +20 -0
- package/templates/docker-compose.yml +26 -0
package/bin/cli.js
CHANGED
|
@@ -65,6 +65,14 @@ 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
|
+
const initDocker = (await question('š Include Dockerfile & docker-compose.yml? [Y/n] ')).toLowerCase() !== 'n';
|
|
75
|
+
|
|
68
76
|
rl.close();
|
|
69
77
|
|
|
70
78
|
console.log(`\nš Creating a new Node.js Express API in ${projectPath}...`);
|
|
@@ -104,6 +112,18 @@ async function init() {
|
|
|
104
112
|
fs.copyFileSync(envExamplePath, path.join(projectPath, '.env'));
|
|
105
113
|
}
|
|
106
114
|
|
|
115
|
+
if (initDocker) {
|
|
116
|
+
console.log(`š³ Adding Docker files...`);
|
|
117
|
+
const dockerfilePath = path.join(__dirname, '..', 'templates', 'Dockerfile');
|
|
118
|
+
const dockerComposePath = path.join(__dirname, '..', 'templates', 'docker-compose.yml');
|
|
119
|
+
|
|
120
|
+
// Fallbacks if templates aren't bundled right
|
|
121
|
+
if (fs.existsSync(dockerfilePath)) fs.copyFileSync(dockerfilePath, path.join(projectPath, 'Dockerfile'));
|
|
122
|
+
if (fs.existsSync(dockerComposePath) && deps.mongoose) {
|
|
123
|
+
fs.copyFileSync(dockerComposePath, path.join(projectPath, 'docker-compose.yml'));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
107
127
|
// 3. Create package.json
|
|
108
128
|
console.log(`š¦ Setting up package.json...`);
|
|
109
129
|
const packageJsonTemplate = {
|
|
@@ -128,13 +148,13 @@ async function init() {
|
|
|
128
148
|
packageJsonTemplate.scripts.format = "prettier --write \"src/**/*.{js,json}\"";
|
|
129
149
|
}
|
|
130
150
|
|
|
131
|
-
//
|
|
151
|
+
// Write package.json
|
|
132
152
|
fs.writeFileSync(
|
|
133
153
|
path.join(projectPath, 'package.json'),
|
|
134
154
|
JSON.stringify(packageJsonTemplate, null, 2)
|
|
135
155
|
);
|
|
136
156
|
|
|
137
|
-
//
|
|
157
|
+
// Install Dependencies
|
|
138
158
|
const dependenciesToInstall = Object.keys(deps).filter(dep => deps[dep] && dep !== 'prettier');
|
|
139
159
|
if (deps['pino-http']) {
|
|
140
160
|
dependenciesToInstall.push('pino');
|
|
@@ -148,30 +168,50 @@ async function init() {
|
|
|
148
168
|
|
|
149
169
|
console.log(`\nā³ Installing selected core dependencies (${dependenciesToInstall.join(', ')}). This might take a minute...`);
|
|
150
170
|
try {
|
|
171
|
+
let installCmd = packageManager === 'yarn' ? 'yarn add'
|
|
172
|
+
: packageManager === 'pnpm' ? 'pnpm add'
|
|
173
|
+
: packageManager === 'bun' ? 'bun add'
|
|
174
|
+
: 'npm install';
|
|
175
|
+
|
|
176
|
+
let installDevCmd = packageManager === 'yarn' ? 'yarn add -D'
|
|
177
|
+
: packageManager === 'pnpm' ? 'pnpm add -D'
|
|
178
|
+
: packageManager === 'bun' ? 'bun add -d'
|
|
179
|
+
: 'npm install --save-dev';
|
|
180
|
+
|
|
151
181
|
if (depString) {
|
|
152
|
-
execSync(
|
|
182
|
+
execSync(`${installCmd} ${depString}`, {
|
|
153
183
|
cwd: projectPath,
|
|
154
184
|
stdio: 'inherit'
|
|
155
185
|
});
|
|
156
186
|
}
|
|
157
187
|
|
|
158
188
|
console.log(`\nā³ Installing latest dev dependencies (${devDepString})...`);
|
|
159
|
-
execSync(
|
|
189
|
+
execSync(`${installDevCmd} ${devDepString}`, {
|
|
160
190
|
cwd: projectPath,
|
|
161
191
|
stdio: 'inherit'
|
|
162
192
|
});
|
|
163
193
|
|
|
194
|
+
if (initGit) {
|
|
195
|
+
console.log(`\nš± Initializing Git repository...`);
|
|
196
|
+
execSync('git init', { cwd: projectPath, stdio: 'inherit' });
|
|
197
|
+
// Create .gitignore
|
|
198
|
+
const gitignoreContent = "node_modules\n.env\ndist\nbuild\ncoverage\n";
|
|
199
|
+
fs.writeFileSync(path.join(projectPath, '.gitignore'), gitignoreContent);
|
|
200
|
+
execSync('git add .', { cwd: projectPath, stdio: 'inherit' });
|
|
201
|
+
execSync('git commit -m "initial commit"', { cwd: projectPath, stdio: 'inherit' });
|
|
202
|
+
}
|
|
203
|
+
|
|
164
204
|
console.log(`\nā
Success! Created "${projectName}" at ${projectPath}`);
|
|
165
205
|
console.log('\nInside that directory, you can run several commands:');
|
|
166
|
-
console.log(
|
|
206
|
+
console.log(`\n ${packageManager === 'npm' ? 'npm run' : packageManager} dev`);
|
|
167
207
|
console.log(' Starts the development server on localhost.');
|
|
168
|
-
console.log(
|
|
208
|
+
console.log(`\n ${packageManager === 'npm' ? 'npm' : packageManager} start`);
|
|
169
209
|
console.log(' Starts the production server.');
|
|
170
210
|
console.log('\nWe suggest that you begin by typing:');
|
|
171
211
|
console.log(`\n cd ${projectName}`);
|
|
172
|
-
console.log('
|
|
212
|
+
console.log(` ${packageManager === 'npm' ? 'npm run' : packageManager} dev\n`);
|
|
173
213
|
} catch (err) {
|
|
174
|
-
console.error('\nā Failed to install dependencies. You may need to
|
|
214
|
+
console.error('\nā Failed to install dependencies. You may need to install them manually inside the folder.', err);
|
|
175
215
|
}
|
|
176
216
|
}
|
|
177
217
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Use official Node.js runtime as a parent image
|
|
2
|
+
FROM node:20-alpine
|
|
3
|
+
|
|
4
|
+
# Set working directory inside the container
|
|
5
|
+
WORKDIR /usr/src/app
|
|
6
|
+
|
|
7
|
+
# Copy package.json and lockfile based on package manager used
|
|
8
|
+
COPY package.json ./
|
|
9
|
+
|
|
10
|
+
# Install project dependencies
|
|
11
|
+
RUN npm install --production
|
|
12
|
+
|
|
13
|
+
# Bundle app source
|
|
14
|
+
COPY . .
|
|
15
|
+
|
|
16
|
+
# Expose port the app runs on
|
|
17
|
+
EXPOSE 3000
|
|
18
|
+
|
|
19
|
+
# Command to run your app
|
|
20
|
+
CMD [ "node", "src/server.js" ]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
version: '3.8'
|
|
2
|
+
|
|
3
|
+
services:
|
|
4
|
+
app:
|
|
5
|
+
build: .
|
|
6
|
+
ports:
|
|
7
|
+
- "3000:3000"
|
|
8
|
+
environment:
|
|
9
|
+
- NODE_ENV=development
|
|
10
|
+
- PORT=3000
|
|
11
|
+
- MONGO_URI=mongodb://mongo:27017/express-api
|
|
12
|
+
volumes:
|
|
13
|
+
- .:/usr/src/app
|
|
14
|
+
- /usr/src/app/node_modules
|
|
15
|
+
depends_on:
|
|
16
|
+
- mongo
|
|
17
|
+
|
|
18
|
+
mongo:
|
|
19
|
+
image: mongo:latest
|
|
20
|
+
ports:
|
|
21
|
+
- "27017:27017"
|
|
22
|
+
volumes:
|
|
23
|
+
- mongo-data:/data/db
|
|
24
|
+
|
|
25
|
+
volumes:
|
|
26
|
+
mongo-data:
|