@waqarcoding/saas-server 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.
- package/bin/cli.js +34 -4
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
import { fileURLToPath } from 'node:url';
|
|
5
6
|
import { spawnSync } from 'node:child_process';
|
|
@@ -18,7 +19,7 @@ ${ownPkg.name} v${ownPkg.version}
|
|
|
18
19
|
${ownPkg.description}
|
|
19
20
|
|
|
20
21
|
Usage:
|
|
21
|
-
npx
|
|
22
|
+
npx ${ownPkg.name} [project-name] [options]
|
|
22
23
|
|
|
23
24
|
Options:
|
|
24
25
|
--no-install Do not run "npm install" after creating the project
|
|
@@ -26,7 +27,7 @@ Options:
|
|
|
26
27
|
-h, --help Show this help
|
|
27
28
|
|
|
28
29
|
Example:
|
|
29
|
-
npx
|
|
30
|
+
npx ${ownPkg.name} my-backend
|
|
30
31
|
`);
|
|
31
32
|
process.exit(0);
|
|
32
33
|
}
|
|
@@ -43,8 +44,37 @@ if (major < 18) {
|
|
|
43
44
|
process.exit(1);
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
// ---- Safe working folder check ----
|
|
48
|
+
function getSafeCwd() {
|
|
49
|
+
let cwd;
|
|
50
|
+
try {
|
|
51
|
+
cwd = process.cwd(); // throws if the folder was deleted or moved
|
|
52
|
+
} catch {
|
|
53
|
+
console.error('❌ The current folder no longer exists.');
|
|
54
|
+
console.error(' Run "cd ~/Documents/projects" (or any normal folder) and try again.');
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const real = fs.realpathSync(cwd);
|
|
59
|
+
const home = os.homedir();
|
|
60
|
+
const trashDirs = [
|
|
61
|
+
path.join(home, '.Trash'), // macOS
|
|
62
|
+
path.join(home, '.local', 'share', 'Trash') // Linux
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
if (trashDirs.some((t) => real === t || real.startsWith(t + path.sep))) {
|
|
66
|
+
console.error(`❌ You are inside the Trash (${real}).`);
|
|
67
|
+
console.error(' Run "cd ~/Documents/projects" (or any normal folder) and try again.');
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return real;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const cwd = getSafeCwd();
|
|
75
|
+
|
|
46
76
|
const targetName = positional[0] || 'server';
|
|
47
|
-
const targetDir = path.resolve(
|
|
77
|
+
const targetDir = path.resolve(cwd, targetName);
|
|
48
78
|
|
|
49
79
|
if (fs.existsSync(targetDir) && fs.readdirSync(targetDir).length > 0) {
|
|
50
80
|
console.error(`❌ Folder "${targetName}" already exists and is not empty.`);
|
|
@@ -76,4 +106,4 @@ Next steps:
|
|
|
76
106
|
cd ${targetName}
|
|
77
107
|
${noInstall ? 'npm install\n ' : ''}# edit .env: MONGO_URI, Firebase and SMTP values
|
|
78
108
|
npm run dev
|
|
79
|
-
`);
|
|
109
|
+
`);
|