@onsever/create-express-ts-app 1.0.0 → 1.0.2
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/README.md +12 -14
- package/bin/cli.js +65 -18
- package/package.json +1 -1
- package/tsconfig.json +2 -1
package/README.md
CHANGED
@@ -11,26 +11,24 @@ This is a starter template for [Express](https://expressjs.com/) web framework f
|
|
11
11
|
- Linting support with [ESLint](https://eslint.org/)
|
12
12
|
- Logging support with [Pino](https://getpino.io/)
|
13
13
|
|
14
|
-
## Getting Started
|
15
|
-
|
16
|
-
Please make sure you have [pnpm](https://pnpm.io/) installed.
|
17
|
-
|
18
14
|
## Usage
|
19
15
|
|
20
|
-
To use this template, run the following
|
16
|
+
To use this template, run one of the following commands:
|
21
17
|
|
22
18
|
```bash
|
23
19
|
npx @onsever/create-express-ts-app <project-name>
|
20
|
+
npx @onsever/create-express-ts-app .
|
21
|
+
npx @onsever/create-express-ts-app ./
|
24
22
|
```
|
25
23
|
|
26
24
|
## Commands
|
27
25
|
|
28
|
-
- `
|
29
|
-
- `
|
30
|
-
- `
|
31
|
-
- `
|
32
|
-
- `
|
33
|
-
- `
|
34
|
-
- `
|
35
|
-
- `
|
36
|
-
- `
|
26
|
+
- `npm run build` - Build the project
|
27
|
+
- `npm run start` - Start the server in production mode
|
28
|
+
- `npm run dev` - Start the server in development mode with live reload
|
29
|
+
- `npm run lint:check` - Check for linting errors
|
30
|
+
- `npm run lint:fix` - Fix linting errors
|
31
|
+
- `npm run prettier:check` - Check for formatting errors
|
32
|
+
- `npm run prettier:fix` - Fix formatting errors
|
33
|
+
- `npm run test` - Run tests
|
34
|
+
- `npm run test:watch` - Run tests in watch mode
|
package/bin/cli.js
CHANGED
@@ -14,17 +14,38 @@ const runCommand = (command) => {
|
|
14
14
|
return true;
|
15
15
|
};
|
16
16
|
|
17
|
-
|
17
|
+
let projectName;
|
18
|
+
const targetArgument = process.argv[2];
|
19
|
+
const directoryName = process.cwd();
|
20
|
+
|
21
|
+
if (checkTargetArgument()) {
|
22
|
+
projectName = directoryName.slice(directoryName.lastIndexOf('/') + 1);
|
23
|
+
} else {
|
24
|
+
projectName = targetArgument;
|
25
|
+
}
|
18
26
|
|
19
27
|
if (!projectName) {
|
20
|
-
console.error('Please specify a project name.');
|
28
|
+
console.error('Please specify a project name or provide a valid directory path.');
|
21
29
|
process.exit(1);
|
22
30
|
}
|
23
31
|
|
24
32
|
console.log(`Creating a new Express application with name ${projectName}...`);
|
25
33
|
|
26
|
-
|
27
|
-
|
34
|
+
let gitCheckoutCommand;
|
35
|
+
|
36
|
+
if (checkTargetArgument()) {
|
37
|
+
gitCheckoutCommand = `git clone --depth 1 https://github.com/onsever/create-express-ts-app .`;
|
38
|
+
} else {
|
39
|
+
gitCheckoutCommand = `git clone --depth 1 https://github.com/onsever/create-express-ts-app ${projectName}`;
|
40
|
+
}
|
41
|
+
|
42
|
+
let installDepsCommand;
|
43
|
+
|
44
|
+
if (checkTargetArgument()) {
|
45
|
+
installDepsCommand = `npm install`;
|
46
|
+
} else {
|
47
|
+
installDepsCommand = `cd ${projectName} && npm install`;
|
48
|
+
}
|
28
49
|
|
29
50
|
const checkedOut = runCommand(gitCheckoutCommand);
|
30
51
|
if (!checkedOut) process.exit(1);
|
@@ -34,7 +55,14 @@ console.log(`Installing dependencies for ${projectName}...`);
|
|
34
55
|
const installedDeps = runCommand(installDepsCommand);
|
35
56
|
if (!installedDeps) process.exit(1);
|
36
57
|
|
37
|
-
|
58
|
+
let packageJsonPath;
|
59
|
+
|
60
|
+
if (checkTargetArgument()) {
|
61
|
+
packageJsonPath = path.join(process.cwd(), 'package.json');
|
62
|
+
} else {
|
63
|
+
packageJsonPath = path.join(projectName, 'package.json');
|
64
|
+
}
|
65
|
+
|
38
66
|
try {
|
39
67
|
const packageJsonData = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
40
68
|
|
@@ -52,6 +80,7 @@ try {
|
|
52
80
|
console.error(`Failed to modify package.json: ${err.message}`);
|
53
81
|
process.exit(1);
|
54
82
|
}
|
83
|
+
|
55
84
|
console.log(`Removing the local Git repository...`);
|
56
85
|
|
57
86
|
const removeGitRepoCommand = `rm -rf ${projectName}/.git`;
|
@@ -60,7 +89,14 @@ if (!gitRepoRemoved) process.exit(1);
|
|
60
89
|
|
61
90
|
console.log(`Initializing a new Git repository for ${projectName}...`);
|
62
91
|
|
63
|
-
|
92
|
+
let createGitRepoCommand;
|
93
|
+
|
94
|
+
if (checkTargetArgument()) {
|
95
|
+
createGitRepoCommand = `git init`;
|
96
|
+
} else {
|
97
|
+
createGitRepoCommand = `cd ${projectName} && git init`;
|
98
|
+
}
|
99
|
+
|
64
100
|
const gitRepoCreated = runCommand(createGitRepoCommand);
|
65
101
|
if (!gitRepoCreated) process.exit(1);
|
66
102
|
|
@@ -69,26 +105,37 @@ console.log(`Clearing the folders...`);
|
|
69
105
|
removeGitKeepsSync(path.join(__dirname, './src'));
|
70
106
|
|
71
107
|
console.log(`Congratulations! ${projectName} is ready to go!`);
|
72
|
-
|
108
|
+
|
109
|
+
if (checkTargetArgument()) {
|
110
|
+
console.log(`npm run dev`);
|
111
|
+
} else {
|
112
|
+
console.log(`cd ${projectName} && npm run dev`);
|
113
|
+
}
|
73
114
|
|
74
115
|
function removeGitKeepsSync(directory) {
|
75
116
|
try {
|
76
|
-
|
117
|
+
if (fs.existsSync(directory)) {
|
118
|
+
const files = fs.readdirSync(directory);
|
77
119
|
|
78
|
-
|
79
|
-
|
120
|
+
files.forEach((file) => {
|
121
|
+
const filePath = path.join(directory, file);
|
80
122
|
|
81
|
-
|
123
|
+
const stat = fs.statSync(filePath);
|
82
124
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
125
|
+
if (stat.isDirectory()) {
|
126
|
+
const gitKeepPath = path.join(filePath, '.gitkeep');
|
127
|
+
if (fs.existsSync(gitKeepPath)) {
|
128
|
+
fs.unlinkSync(gitKeepPath);
|
129
|
+
}
|
130
|
+
removeGitKeepsSync(filePath);
|
87
131
|
}
|
88
|
-
|
89
|
-
|
90
|
-
});
|
132
|
+
});
|
133
|
+
}
|
91
134
|
} catch (err) {
|
92
135
|
console.error(`Error: ${err.message}`);
|
93
136
|
}
|
94
137
|
}
|
138
|
+
|
139
|
+
function checkTargetArgument() {
|
140
|
+
return targetArgument === '.' || targetArgument === './';
|
141
|
+
}
|
package/package.json
CHANGED