sk-test-node-deploy 1.0.1 → 1.0.5

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 +54 -33
  2. package/package.json +6 -1
package/lib/index.js CHANGED
@@ -1,13 +1,50 @@
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");
39
+
40
+ // Debug: Check if template exists
41
+ if (!fs.existsSync(templatePath)) {
42
+ console.error(
43
+ chalk.red(`❌ Template directory not found at: ${templatePath}`),
44
+ );
45
+ console.error(chalk.yellow(`Looked in: ${templatePath}`));
46
+ process.exit(1);
47
+ }
11
48
 
12
49
  // Check if directory already exists
13
50
  if (fs.existsSync(targetPath)) {
@@ -45,7 +82,7 @@ async function createProject(projectName) {
45
82
  }
46
83
 
47
84
  // Step 3: Detect package manager
48
- const packageManager = detectPackageManager();
85
+ const packageManager = await detectPackageManager();
49
86
  console.log(chalk.gray(`Using package manager: ${packageManager}\n`));
50
87
 
51
88
  // Step 4: Install production dependencies
@@ -67,15 +104,12 @@ async function createProject(projectName) {
67
104
  "multer",
68
105
  ];
69
106
 
70
- const installCmd = packageManager === "npm" ? "install" : "add";
71
- const prodCmd = `${packageManager} ${installCmd} ${prodDeps.join(" ")}`;
107
+ await runCommand(
108
+ packageManager,
109
+ [packageManager === "npm" ? "install" : "add", ...prodDeps],
110
+ { cwd: targetPath },
111
+ );
72
112
 
73
- execSync(prodCmd, {
74
- cwd: targetPath,
75
- stdio: "pipe",
76
- shell: true,
77
- windowsHide: true,
78
- });
79
113
  installSpinner.succeed(chalk.green("Production dependencies installed!"));
80
114
  } catch (error) {
81
115
  installSpinner.fail(
@@ -104,15 +138,13 @@ async function createProject(projectName) {
104
138
  "nodemon",
105
139
  ];
106
140
 
107
- const devFlag = packageManager === "npm" ? "install -D" : "add -D";
108
- const devCmd = `${packageManager} ${devFlag} ${devDeps.join(" ")}`;
141
+ const devArgs =
142
+ packageManager === "npm"
143
+ ? ["install", "-D", ...devDeps]
144
+ : ["add", "-D", ...devDeps];
145
+
146
+ await runCommand(packageManager, devArgs, { cwd: targetPath });
109
147
 
110
- execSync(devCmd, {
111
- cwd: targetPath,
112
- stdio: "pipe",
113
- shell: true,
114
- windowsHide: true,
115
- });
116
148
  devInstallSpinner.succeed(chalk.green("Dev dependencies installed!"));
117
149
  } catch (error) {
118
150
  devInstallSpinner.fail(chalk.red("Failed to install dev dependencies"));
@@ -123,16 +155,9 @@ async function createProject(projectName) {
123
155
  // Step 6: Initialize git (optional)
124
156
  const gitSpinner = ora("Initializing git repository...").start();
125
157
  try {
126
- execSync("git --version", {
127
- stdio: "ignore",
128
- shell: true,
129
- windowsHide: true,
130
- });
131
- execSync("git init", {
158
+ await runCommand("git", ["init"], {
132
159
  cwd: targetPath,
133
160
  stdio: "ignore",
134
- shell: true,
135
- windowsHide: true,
136
161
  });
137
162
  gitSpinner.succeed(chalk.green("Git repository initialized!"));
138
163
  } catch (error) {
@@ -167,13 +192,9 @@ async function createProject(projectName) {
167
192
  }
168
193
 
169
194
  // Detect which package manager is available
170
- function detectPackageManager() {
195
+ async function detectPackageManager() {
171
196
  try {
172
- execSync("yarn --version", {
173
- stdio: "ignore",
174
- shell: true,
175
- windowsHide: true,
176
- });
197
+ await runCommand("yarn", ["--version"], { stdio: "ignore" });
177
198
  return "yarn";
178
199
  } catch {
179
200
  return "npm";
package/package.json CHANGED
@@ -1,11 +1,16 @@
1
1
  {
2
2
  "name": "sk-test-node-deploy",
3
- "version": "1.0.1",
3
+ "version": "1.0.5",
4
4
  "description": "CLI tool to quickly scaffold a Node.js boilerplate project",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
7
7
  "sk-test-node-deploy": "bin/cli.js"
8
8
  },
9
+ "files": [
10
+ "bin",
11
+ "lib",
12
+ "template"
13
+ ],
9
14
  "scripts": {
10
15
  "test": "echo \"No tests specified\"",
11
16
  "postinstall": "node -e \"try{const fs=require('fs');const path=require('path');const binPath=path.join(__dirname,'bin','cli.js');if(fs.existsSync(binPath)){fs.chmodSync(binPath,0o755);}}catch(e){}\""