@onsever/create-express-ts-app 1.0.1 → 1.0.3
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 +53 -13
- package/package.json +1 -1
package/bin/cli.js
CHANGED
@@ -16,18 +16,14 @@ const runCommand = (command) => {
|
|
16
16
|
|
17
17
|
let projectName;
|
18
18
|
const targetArgument = process.argv[2];
|
19
|
-
const directoryName =
|
19
|
+
const directoryName = process.cwd();
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
if (targetArgument === '.' || targetArgument === './') {
|
21
|
+
if (checkTargetArgument()) {
|
24
22
|
projectName = directoryName.slice(directoryName.lastIndexOf('/') + 1);
|
25
23
|
} else {
|
26
24
|
projectName = targetArgument;
|
27
25
|
}
|
28
26
|
|
29
|
-
console.log(projectName);
|
30
|
-
|
31
27
|
if (!projectName) {
|
32
28
|
console.error('Please specify a project name or provide a valid directory path.');
|
33
29
|
process.exit(1);
|
@@ -35,18 +31,38 @@ if (!projectName) {
|
|
35
31
|
|
36
32
|
console.log(`Creating a new Express application with name ${projectName}...`);
|
37
33
|
|
38
|
-
|
39
|
-
|
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
|
+
}
|
40
49
|
|
41
50
|
const checkedOut = runCommand(gitCheckoutCommand);
|
42
51
|
if (!checkedOut) process.exit(1);
|
43
52
|
|
44
53
|
console.log(`Installing dependencies for ${projectName}...`);
|
45
54
|
|
46
|
-
const installedDeps = runCommand(
|
55
|
+
const installedDeps = runCommand(installDepsCommand);
|
47
56
|
if (!installedDeps) process.exit(1);
|
48
57
|
|
49
|
-
|
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
|
+
|
50
66
|
try {
|
51
67
|
const packageJsonData = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
52
68
|
|
@@ -64,15 +80,30 @@ try {
|
|
64
80
|
console.error(`Failed to modify package.json: ${err.message}`);
|
65
81
|
process.exit(1);
|
66
82
|
}
|
83
|
+
|
67
84
|
console.log(`Removing the local Git repository...`);
|
68
85
|
|
69
|
-
|
86
|
+
let removeGitRepoCommand;
|
87
|
+
|
88
|
+
if (checkTargetArgument()) {
|
89
|
+
removeGitRepoCommand = `rm -rf .git`;
|
90
|
+
} else {
|
91
|
+
removeGitRepoCommand = `rm -rf ${projectName}/.git`;
|
92
|
+
}
|
93
|
+
|
70
94
|
const gitRepoRemoved = runCommand(removeGitRepoCommand);
|
71
95
|
if (!gitRepoRemoved) process.exit(1);
|
72
96
|
|
73
97
|
console.log(`Initializing a new Git repository for ${projectName}...`);
|
74
98
|
|
75
|
-
|
99
|
+
let createGitRepoCommand;
|
100
|
+
|
101
|
+
if (checkTargetArgument()) {
|
102
|
+
createGitRepoCommand = `git init`;
|
103
|
+
} else {
|
104
|
+
createGitRepoCommand = `cd ${projectName} && git init`;
|
105
|
+
}
|
106
|
+
|
76
107
|
const gitRepoCreated = runCommand(createGitRepoCommand);
|
77
108
|
if (!gitRepoCreated) process.exit(1);
|
78
109
|
|
@@ -81,7 +112,12 @@ console.log(`Clearing the folders...`);
|
|
81
112
|
removeGitKeepsSync(path.join(__dirname, './src'));
|
82
113
|
|
83
114
|
console.log(`Congratulations! ${projectName} is ready to go!`);
|
84
|
-
|
115
|
+
|
116
|
+
if (checkTargetArgument()) {
|
117
|
+
console.log(`npm run dev`);
|
118
|
+
} else {
|
119
|
+
console.log(`cd ${projectName} && npm run dev`);
|
120
|
+
}
|
85
121
|
|
86
122
|
function removeGitKeepsSync(directory) {
|
87
123
|
try {
|
@@ -106,3 +142,7 @@ function removeGitKeepsSync(directory) {
|
|
106
142
|
console.error(`Error: ${err.message}`);
|
107
143
|
}
|
108
144
|
}
|
145
|
+
|
146
|
+
function checkTargetArgument() {
|
147
|
+
return targetArgument === '.' || targetArgument === './';
|
148
|
+
}
|
package/package.json
CHANGED