@fernir2/saas-kit-cli 0.1.2 → 0.1.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/create-saas-kit-app.js +98 -84
- package/package.json +1 -1
|
@@ -8,36 +8,37 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { execSync } from "child_process";
|
|
11
|
-
import { existsSync, mkdirSync } from "fs";
|
|
11
|
+
import { existsSync, mkdirSync, rmSync } from "fs";
|
|
12
12
|
import { fileURLToPath } from "url";
|
|
13
13
|
import path from "path";
|
|
14
|
+
import os from "os";
|
|
14
15
|
|
|
15
16
|
const __filename = fileURLToPath(import.meta.url);
|
|
16
17
|
const __dirname = path.dirname(__filename);
|
|
17
18
|
|
|
18
19
|
function log(message) {
|
|
19
|
-
|
|
20
|
+
console.log(`\x1b[36m[saas-kit-cli]\x1b[0m ${message}`);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
function logError(message) {
|
|
23
|
-
|
|
24
|
+
console.error(`\x1b[31m[saas-kit-cli ERROR]\x1b[0m ${message}`);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
function runCommand(command, cwd) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
try {
|
|
29
|
+
execSync(command, { stdio: "inherit", cwd: cwd || process.cwd() });
|
|
30
|
+
} catch (error) {
|
|
31
|
+
logError(`Command failed: ${command}`);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
async function main() {
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
const args = process.argv.slice(2);
|
|
38
|
+
const command = args[0];
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
if (!command || command === "help" || command === "--help" || command === "-h") {
|
|
41
|
+
console.log(`
|
|
41
42
|
╔═══════════════════════════════════════════════════════════╗
|
|
42
43
|
║ SaaS Kit CLI ║
|
|
43
44
|
║ by Fernir.io ║
|
|
@@ -56,90 +57,103 @@ This will:
|
|
|
56
57
|
|
|
57
58
|
More information: https://saaskit.us
|
|
58
59
|
`);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (command !== "create-saas-kit-app") {
|
|
63
|
-
logError(`Unknown command: ${command}`);
|
|
64
|
-
logError(`Run "npx @fernir2/saas-kit-cli help" for usage information`);
|
|
65
|
-
process.exit(1);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const projectName = args[1];
|
|
60
|
+
process.exit(0);
|
|
61
|
+
}
|
|
69
62
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const targetDir = path.resolve(process.cwd(), projectName);
|
|
63
|
+
if (command !== "create-saas-kit-app") {
|
|
64
|
+
logError(`Unknown command: ${command}`);
|
|
65
|
+
logError(`Run "npx @fernir2/saas-kit-cli help" for usage information`);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
77
68
|
|
|
78
|
-
|
|
79
|
-
logError(`Directory "${projectName}" already exists`);
|
|
80
|
-
process.exit(1);
|
|
81
|
-
}
|
|
69
|
+
const projectName = args[1];
|
|
82
70
|
|
|
83
|
-
|
|
84
|
-
|
|
71
|
+
if (!projectName) {
|
|
72
|
+
logError("Project name is required");
|
|
73
|
+
logError("Usage: npx @fernir2/saas-kit-cli create-saas-kit-app <project-name>");
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
85
76
|
|
|
86
|
-
|
|
87
|
-
const tempDir = path.join(process.cwd(), `.saas-kit-temp-${Date.now()}`);
|
|
88
|
-
mkdirSync(tempDir, { recursive: true });
|
|
77
|
+
const targetDir = path.resolve(process.cwd(), projectName);
|
|
89
78
|
|
|
90
|
-
|
|
91
|
-
|
|
79
|
+
if (existsSync(targetDir)) {
|
|
80
|
+
logError(`Directory "${projectName}" already exists`);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
log(`Creating SaaS Kit application: ${projectName}`);
|
|
85
|
+
log("This will take a few minutes...\n");
|
|
86
|
+
|
|
87
|
+
// Create temp directory for downloading the package in system temp
|
|
88
|
+
const tmpBase = os.tmpdir();
|
|
89
|
+
const tempDir = path.join(tmpBase, `saas-kit-temp-${Date.now()}-`);
|
|
90
|
+
// use mkdtempSync to create a safe unique temp directory
|
|
91
|
+
const mkdtemp = (prefix) => {
|
|
92
|
+
// Node's fs.mkdtempSync requires a real prefix, but we can emulate with mkdirSync
|
|
93
|
+
const dir = prefix + Math.random().toString(36).slice(2, 8);
|
|
94
|
+
const full = path.join(tmpBase, dir);
|
|
95
|
+
mkdirSync(full, { recursive: true });
|
|
96
|
+
return full;
|
|
97
|
+
};
|
|
98
|
+
const realTempDir = mkdtemp(tempDir);
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
log("Step 1/3: Installing @fernir2/saas-kit package...");
|
|
92
102
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
103
|
+
// Install the main package temporarily
|
|
104
|
+
runCommand("npm init -y", realTempDir);
|
|
105
|
+
runCommand("npm install @fernir2/saas-kit@latest", realTempDir);
|
|
96
106
|
|
|
97
|
-
|
|
107
|
+
log("\nStep 2/3: Creating your application...");
|
|
98
108
|
|
|
99
|
-
|
|
109
|
+
// Run the create-saas-kit-app binary from the installed package
|
|
100
110
|
const saasKitBinPath = path.join(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
// Clean up temp directory
|
|
119
|
-
runCommand(`rm -rf "${tempDir}"`, process.cwd());
|
|
120
|
-
|
|
121
|
-
log("\n✨ Success! Your SaaS Kit application is ready!");
|
|
122
|
-
log("\nNext steps:");
|
|
123
|
-
log(` cd ${projectName}`);
|
|
124
|
-
log(` npm install`);
|
|
125
|
-
log(` npm start`);
|
|
126
|
-
log("\n");
|
|
127
|
-
} catch (error) {
|
|
128
|
-
logError("Failed to create application");
|
|
111
|
+
realTempDir,
|
|
112
|
+
"node_modules",
|
|
113
|
+
"@fernir2",
|
|
114
|
+
"saas-kit",
|
|
115
|
+
"bin",
|
|
116
|
+
"index.js"
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
if (!existsSync(saasKitBinPath)) {
|
|
120
|
+
logError("Could not find create-saas-kit-app binary in @fernir2/saas-kit package");
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
runCommand(`node "${saasKitBinPath}" "${projectName}"`, process.cwd());
|
|
125
|
+
|
|
126
|
+
log("\nStep 3/3: Cleaning up...");
|
|
129
127
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
128
|
+
// Clean up temp directory
|
|
129
|
+
try {
|
|
130
|
+
rmSync(realTempDir, { recursive: true, force: true });
|
|
131
|
+
} catch (e) {
|
|
132
|
+
// ignore
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
log("\n✨ Success! Your SaaS Kit application is ready!");
|
|
136
|
+
log("\nNext steps:");
|
|
137
|
+
log(` cd ${projectName}`);
|
|
138
|
+
log(` npm install`);
|
|
139
|
+
log(` npm start`);
|
|
140
|
+
log("\n");
|
|
141
|
+
} catch (error) {
|
|
142
|
+
logError("Failed to create application");
|
|
137
143
|
|
|
138
|
-
|
|
144
|
+
// Clean up on error
|
|
145
|
+
try {
|
|
146
|
+
try { rmSync(realTempDir, { recursive: true, force: true }); } catch (e) {}
|
|
147
|
+
try { rmSync(targetDir, { recursive: true, force: true }); } catch (e) {}
|
|
148
|
+
} catch (cleanupError) {
|
|
149
|
+
// Ignore cleanup errors
|
|
139
150
|
}
|
|
151
|
+
|
|
152
|
+
process.exit(1);
|
|
153
|
+
}
|
|
140
154
|
}
|
|
141
155
|
|
|
142
156
|
main().catch((error) => {
|
|
143
|
-
|
|
144
|
-
|
|
157
|
+
logError(`Unexpected error: ${error.message}`);
|
|
158
|
+
process.exit(1);
|
|
145
159
|
});
|