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