@onsever/create-express-ts-app 1.0.1 → 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.
Files changed (2) hide show
  1. package/bin/cli.js +45 -12
  2. 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 = path.resolve(path.dirname(''));
19
+ const directoryName = process.cwd();
20
20
 
21
- console.log(directoryName);
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
- const gitCheckoutCommand = `git clone --depth 1 https://github.com/onsever/create-express-ts-app ${projectName}`;
39
- const installDepsCommand = `cd ${projectName} && pnpm install`;
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(`cd ${projectName} && ${installDepsCommand}`);
55
+ const installedDeps = runCommand(installDepsCommand);
47
56
  if (!installedDeps) process.exit(1);
48
57
 
49
- const packageJsonPath = path.join(projectName, 'package.json');
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,6 +80,7 @@ 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
  const removeGitRepoCommand = `rm -rf ${projectName}/.git`;
@@ -72,7 +89,14 @@ if (!gitRepoRemoved) process.exit(1);
72
89
 
73
90
  console.log(`Initializing a new Git repository for ${projectName}...`);
74
91
 
75
- const createGitRepoCommand = `cd ${projectName} && git init`;
92
+ let createGitRepoCommand;
93
+
94
+ if (checkTargetArgument()) {
95
+ createGitRepoCommand = `git init`;
96
+ } else {
97
+ createGitRepoCommand = `cd ${projectName} && git init`;
98
+ }
99
+
76
100
  const gitRepoCreated = runCommand(createGitRepoCommand);
77
101
  if (!gitRepoCreated) process.exit(1);
78
102
 
@@ -81,7 +105,12 @@ console.log(`Clearing the folders...`);
81
105
  removeGitKeepsSync(path.join(__dirname, './src'));
82
106
 
83
107
  console.log(`Congratulations! ${projectName} is ready to go!`);
84
- console.log(`cd ${projectName} && pnpm dev`);
108
+
109
+ if (checkTargetArgument()) {
110
+ console.log(`npm run dev`);
111
+ } else {
112
+ console.log(`cd ${projectName} && npm run dev`);
113
+ }
85
114
 
86
115
  function removeGitKeepsSync(directory) {
87
116
  try {
@@ -106,3 +135,7 @@ function removeGitKeepsSync(directory) {
106
135
  console.error(`Error: ${err.message}`);
107
136
  }
108
137
  }
138
+
139
+ function checkTargetArgument() {
140
+ return targetArgument === '.' || targetArgument === './';
141
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onsever/create-express-ts-app",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "This is a starter template for Express.js with TypeScript that includes Jest, Prettier, ESLint, and more.",
5
5
  "bin": "./bin/cli.js",
6
6
  "main": "main.js",