@fernir2/saas-kit-cli 0.1.0

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.
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * @fernir2/saas-kit-cli
5
+ *
6
+ * This is a standalone CLI tool that downloads and uses the main @fernir2/saas-kit package
7
+ * to create a new SaaS Kit application.
8
+ */
9
+
10
+ import { execSync } from "child_process";
11
+ import { existsSync, mkdirSync } from "fs";
12
+ import { fileURLToPath } from "url";
13
+ import path from "path";
14
+
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = path.dirname(__filename);
17
+
18
+ function log(message) {
19
+ console.log(`\x1b[36m[saas-kit-cli]\x1b[0m ${message}`);
20
+ }
21
+
22
+ function logError(message) {
23
+ console.error(`\x1b[31m[saas-kit-cli ERROR]\x1b[0m ${message}`);
24
+ }
25
+
26
+ function runCommand(command, cwd) {
27
+ try {
28
+ execSync(command, { stdio: "inherit", cwd: cwd || process.cwd() });
29
+ } catch (error) {
30
+ logError(`Command failed: ${command}`);
31
+ process.exit(1);
32
+ }
33
+ }
34
+
35
+ async function main() {
36
+ const args = process.argv.slice(2);
37
+ const command = args[0];
38
+
39
+ if (!command || command === "help" || command === "--help" || command === "-h") {
40
+ console.log(`
41
+ ╔═══════════════════════════════════════════════════════════╗
42
+ ║ SaaS Kit CLI ║
43
+ ║ by Fernir.io ║
44
+ ╚═══════════════════════════════════════════════════════════╝
45
+
46
+ Usage:
47
+ npx @fernir2/saas-kit-cli create-saas-kit-app <project-name>
48
+
49
+ Example:
50
+ npx @fernir2/saas-kit-cli create-saas-kit-app my-awesome-app
51
+
52
+ This will:
53
+ 1. Download the latest @fernir2/saas-kit package
54
+ 2. Create a new SaaS Kit application
55
+ 3. Set up all necessary dependencies
56
+
57
+ More information: https://saaskit.us
58
+ `);
59
+ process.exit(0);
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];
69
+
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
+ }
75
+
76
+ const targetDir = path.resolve(process.cwd(), projectName);
77
+
78
+ if (existsSync(targetDir)) {
79
+ logError(`Directory "${projectName}" already exists`);
80
+ process.exit(1);
81
+ }
82
+
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 });
89
+
90
+ try {
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);
96
+
97
+ log("\nStep 2/3: Creating your application...");
98
+
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...");
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");
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
+ }
140
+ }
141
+
142
+ main().catch((error) => {
143
+ logError(`Unexpected error: ${error.message}`);
144
+ process.exit(1);
145
+ });
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@fernir2/saas-kit-cli",
3
+ "version": "0.1.0",
4
+ "description": "CLI for creating saas-kit apps",
5
+ "bin": {
6
+ "create-saas-kit-app": "bin/create-saas-kit-app.js"
7
+ },
8
+ "scripts": {
9
+ "start": "node bin/create-saas-kit-app.js"
10
+ },
11
+ "dependencies": {},
12
+ "type": "module",
13
+ "publishConfig": {
14
+ "access": "public"
15
+ }
16
+ }