sk-test-node-deploy 1.0.3 → 1.0.6

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/lib/index.js +124 -111
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -1,13 +1,41 @@
1
1
  const fs = require("fs-extra");
2
2
  const path = require("path");
3
- const { execSync } = require("child_process");
3
+ const { spawn } = require("child_process");
4
4
  const chalk = require("chalk");
5
5
  const ora = require("ora");
6
6
  const os = require("os");
7
7
 
8
+ // Helper function to run commands with proper Windows support
9
+ function runCommand(command, args, options = {}) {
10
+ return new Promise((resolve, reject) => {
11
+ const isWindows = os.platform() === "win32";
12
+ const cmd = isWindows ? "cmd" : command;
13
+ const cmdArgs = isWindows ? ["/c", command, ...args] : args;
14
+
15
+ const child = spawn(cmd, cmdArgs, {
16
+ ...options,
17
+ shell: false,
18
+ stdio: options.stdio || "inherit",
19
+ env: { ...process.env, ...options.env },
20
+ });
21
+
22
+ child.on("error", (error) => {
23
+ reject(error);
24
+ });
25
+
26
+ child.on("close", (code) => {
27
+ if (code !== 0) {
28
+ reject(new Error(`Command failed with exit code ${code}`));
29
+ } else {
30
+ resolve();
31
+ }
32
+ });
33
+ });
34
+ }
35
+
8
36
  async function createProject(projectName) {
9
37
  const targetPath = path.join(process.cwd(), projectName);
10
- const templatePath = path.join(__dirname, "../template");
38
+ const templatePath = path.join(__dirname, "..", "template");
11
39
 
12
40
  // Debug: Check if template exists
13
41
  if (!fs.existsSync(templatePath)) {
@@ -54,124 +82,109 @@ async function createProject(projectName) {
54
82
  }
55
83
 
56
84
  // Step 3: Detect package manager
57
- const packageManager = detectPackageManager();
85
+ const packageManager = await detectPackageManager();
58
86
  console.log(chalk.gray(`Using package manager: ${packageManager}\n`));
59
87
 
60
- // Step 4: Install production dependencies
61
- console.log(chalk.blue("šŸ“¦ Installing dependencies...\n"));
62
- const installSpinner = ora("Installing production dependencies...").start();
63
-
64
- try {
65
- const prodDeps = [
66
- "bcryptjs",
67
- "compression",
68
- "cors",
69
- "dotenv",
70
- "express",
71
- "helmet",
72
- "joi",
73
- "jsonwebtoken",
74
- "mongoose",
75
- "socket.io",
76
- "multer",
77
- ];
78
-
79
- const installCmd = packageManager === "npm" ? "install" : "add";
80
- const prodCmd = `${packageManager} ${installCmd} ${prodDeps.join(" ")}`;
81
-
82
- // Windows-specific execution options
83
- const execOptions = {
84
- cwd: targetPath,
85
- stdio: "inherit",
86
- shell: true,
87
- };
88
-
89
- // Add Windows-specific options
90
- if (os.platform() === "win32") {
91
- execOptions.windowsVerbatimArguments = false;
92
- }
93
-
94
- execSync(prodCmd, execOptions);
95
- installSpinner.succeed(chalk.green("Production dependencies installed!"));
96
- } catch (error) {
97
- installSpinner.fail(
98
- chalk.red("Failed to install production dependencies"),
99
- );
100
- console.error(chalk.red(error.message));
101
- throw error;
102
- }
103
-
104
- // Step 5: Install dev dependencies
105
- const devInstallSpinner = ora("Installing dev dependencies...").start();
106
-
107
- try {
108
- const devDeps = [
109
- "typescript",
110
- "ts-node",
111
- "@types/node",
112
- "@types/express",
113
- "@types/bcryptjs",
114
- "@types/compression",
115
- "@types/cors",
116
- "@types/jsonwebtoken",
117
- "@types/mongoose",
118
- "@types/socket.io",
119
- "@types/multer",
120
- "nodemon",
121
- ];
122
-
123
- const devFlag = packageManager === "npm" ? "install -D" : "add -D";
124
- const devCmd = `${packageManager} ${devFlag} ${devDeps.join(" ")}`;
125
-
126
- const execOptions = {
127
- cwd: targetPath,
128
- stdio: "inherit",
129
- shell: true,
130
- };
131
-
132
- if (os.platform() === "win32") {
133
- execOptions.windowsVerbatimArguments = false;
134
- }
135
-
136
- execSync(devCmd, execOptions);
137
- devInstallSpinner.succeed(chalk.green("Dev dependencies installed!"));
138
- } catch (error) {
139
- devInstallSpinner.fail(chalk.red("Failed to install dev dependencies"));
140
- console.error(chalk.red(error.message));
141
- throw error;
142
- }
143
-
144
- // Step 6: Initialize git (optional)
145
- const gitSpinner = ora("Initializing git repository...").start();
146
- try {
147
- execSync("git --version", { stdio: "ignore", shell: true });
148
- execSync("git init", { cwd: targetPath, stdio: "ignore", shell: true });
149
- gitSpinner.succeed(chalk.green("Git repository initialized!"));
150
- } catch (error) {
151
- gitSpinner.warn(chalk.yellow("Git not found or initialization skipped"));
152
- }
153
-
154
- // Step 7: Create .env from .env.example if exists
155
- const envExamplePath = path.join(targetPath, ".env.example");
156
- const envPath = path.join(targetPath, ".env");
157
-
158
- if (fs.existsSync(envExamplePath) && !fs.existsSync(envPath)) {
159
- await fs.copy(envExamplePath, envPath);
160
- console.log(chalk.green("āœ“ .env file created from .env.example"));
161
- }
88
+ // // Step 4: Install production dependencies
89
+ // console.log(chalk.blue("šŸ“¦ Installing dependencies...\n"));
90
+ // const installSpinner = ora("Installing production dependencies...").start();
91
+
92
+ // try {
93
+ // const prodDeps = [
94
+ // "bcryptjs",
95
+ // "compression",
96
+ // "cors",
97
+ // "dotenv",
98
+ // "express",
99
+ // "helmet",
100
+ // "joi",
101
+ // "jsonwebtoken",
102
+ // "mongoose",
103
+ // "socket.io",
104
+ // "multer",
105
+ // ];
106
+
107
+ // await runCommand(
108
+ // packageManager,
109
+ // [packageManager === "npm" ? "install" : "add", ...prodDeps],
110
+ // { cwd: targetPath },
111
+ // );
112
+
113
+ // installSpinner.succeed(chalk.green("Production dependencies installed!"));
114
+ // } catch (error) {
115
+ // installSpinner.fail(
116
+ // chalk.red("Failed to install production dependencies"),
117
+ // );
118
+ // console.error(chalk.red(error.message));
119
+ // throw error;
120
+ // }
121
+
122
+ // // Step 5: Install dev dependencies
123
+ // const devInstallSpinner = ora("Installing dev dependencies...").start();
124
+
125
+ // try {
126
+ // const devDeps = [
127
+ // "typescript",
128
+ // "ts-node",
129
+ // "@types/node",
130
+ // "@types/express",
131
+ // "@types/bcryptjs",
132
+ // "@types/compression",
133
+ // "@types/cors",
134
+ // "@types/jsonwebtoken",
135
+ // "@types/mongoose",
136
+ // "@types/socket.io",
137
+ // "@types/multer",
138
+ // "nodemon",
139
+ // ];
140
+
141
+ // const devArgs =
142
+ // packageManager === "npm"
143
+ // ? ["install", "-D", ...devDeps]
144
+ // : ["add", "-D", ...devDeps];
145
+
146
+ // await runCommand(packageManager, devArgs, { cwd: targetPath });
147
+
148
+ // devInstallSpinner.succeed(chalk.green("Dev dependencies installed!"));
149
+ // } catch (error) {
150
+ // devInstallSpinner.fail(chalk.red("Failed to install dev dependencies"));
151
+ // console.error(chalk.red(error.message));
152
+ // throw error;
153
+ // }
154
+
155
+ // // Step 6: Initialize git (optional)
156
+ // const gitSpinner = ora("Initializing git repository...").start();
157
+ // try {
158
+ // await runCommand("git", ["init"], {
159
+ // cwd: targetPath,
160
+ // stdio: "ignore",
161
+ // });
162
+ // gitSpinner.succeed(chalk.green("Git repository initialized!"));
163
+ // } catch (error) {
164
+ // gitSpinner.warn(chalk.yellow("Git not found or initialization skipped"));
165
+ // }
166
+
167
+ // // Step 7: Create .env from .env.example if exists
168
+ // const envExamplePath = path.join(targetPath, ".env.example");
169
+ // const envPath = path.join(targetPath, ".env");
170
+
171
+ // if (fs.existsSync(envExamplePath) && !fs.existsSync(envPath)) {
172
+ // await fs.copy(envExamplePath, envPath);
173
+ // console.log(chalk.green("āœ“ .env file created from .env.example"));
174
+ // }
162
175
 
163
176
  // Success message
164
177
  console.log(chalk.green.bold("\n✨ Project created successfully!\n"));
165
- console.log(chalk.cyan("To get started, run:"));
166
- console.log(chalk.white(` cd ${projectName}`));
167
- console.log(chalk.white(" npm run dev\n"));
178
+ // console.log(chalk.cyan("To get started, run:"));
179
+ // console.log(chalk.white(` cd ${projectName}`));
180
+ // console.log(chalk.white(" npm run dev\n"));
168
181
  } catch (error) {
169
182
  console.error(chalk.red("\nāŒ Error creating project:"), error.message);
170
183
 
171
184
  // Cleanup on error
172
185
  if (fs.existsSync(targetPath)) {
173
186
  console.log(chalk.yellow("Cleaning up..."));
174
- await fs.remove(targetPath);
187
+ // await fs.remove(targetPath);
175
188
  }
176
189
 
177
190
  process.exit(1);
@@ -179,9 +192,9 @@ async function createProject(projectName) {
179
192
  }
180
193
 
181
194
  // Detect which package manager is available
182
- function detectPackageManager() {
195
+ async function detectPackageManager() {
183
196
  try {
184
- execSync("yarn --version", { stdio: "ignore", shell: true });
197
+ await runCommand("yarn", ["--version"], { stdio: "ignore" });
185
198
  return "yarn";
186
199
  } catch {
187
200
  return "npm";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sk-test-node-deploy",
3
- "version": "1.0.3",
3
+ "version": "1.0.6",
4
4
  "description": "CLI tool to quickly scaffold a Node.js boilerplate project",
5
5
  "main": "lib/index.js",
6
6
  "bin": {