@webhikers/cli 1.0.2 → 1.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.
- package/package.json +1 -1
- package/src/commands/create.js +97 -5
package/package.json
CHANGED
package/src/commands/create.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { execSync } from "child_process";
|
|
2
|
-
import { existsSync, writeFileSync } from "fs";
|
|
2
|
+
import { existsSync, writeFileSync, readFileSync } from "fs";
|
|
3
3
|
import { resolve } from "path";
|
|
4
4
|
import { loadConfig, getConfigPath } from "../utils/config-store.js";
|
|
5
5
|
|
|
6
6
|
const TEMPLATE_REPO = "Webhikers/nextjs-vibe-starter";
|
|
7
7
|
const GITHUB_ORG = "Webhikers";
|
|
8
|
+
const DOMAIN_SUFFIX = "preview.webhikers.dev";
|
|
8
9
|
|
|
9
10
|
function run(cmd, options = {}) {
|
|
10
11
|
console.log(` → ${cmd}`);
|
|
@@ -15,6 +16,28 @@ function runCapture(cmd) {
|
|
|
15
16
|
return execSync(cmd, { encoding: "utf-8" }).trim();
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
async function coolifyApi(config, method, path, body) {
|
|
20
|
+
const url = `${config.coolifyUrl}/api/v1${path}`;
|
|
21
|
+
const options = {
|
|
22
|
+
method,
|
|
23
|
+
headers: {
|
|
24
|
+
Authorization: `Bearer ${config.coolifyToken}`,
|
|
25
|
+
"Content-Type": "application/json",
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
if (body) options.body = JSON.stringify(body);
|
|
29
|
+
|
|
30
|
+
const res = await fetch(url, options);
|
|
31
|
+
const data = await res.json();
|
|
32
|
+
|
|
33
|
+
if (!res.ok) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`Coolify API error (${res.status}): ${JSON.stringify(data)}`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
|
|
18
41
|
export async function createCommand(name) {
|
|
19
42
|
console.log(`\nCreating project: ${name}\n`);
|
|
20
43
|
|
|
@@ -61,6 +84,8 @@ export async function createCommand(name) {
|
|
|
61
84
|
// --- 4. Generate .env ---
|
|
62
85
|
console.log("\nGenerating .env...");
|
|
63
86
|
const payloadSecret = runCapture("openssl rand -hex 32");
|
|
87
|
+
const domain = `${name}.${DOMAIN_SUFFIX}`;
|
|
88
|
+
const siteUrl = `https://${domain}`;
|
|
64
89
|
const envContent = [
|
|
65
90
|
`PAYLOAD_SECRET=${payloadSecret}`,
|
|
66
91
|
`SITE_URL=http://localhost:3000`,
|
|
@@ -70,18 +95,85 @@ export async function createCommand(name) {
|
|
|
70
95
|
writeFileSync(resolve(projectDir, ".env"), envContent, "utf-8");
|
|
71
96
|
console.log(" .env written (PAYLOAD_SECRET + SITE_URL)");
|
|
72
97
|
|
|
73
|
-
// --- 5.
|
|
98
|
+
// --- 5. Get git remote URL ---
|
|
99
|
+
let gitRepo;
|
|
100
|
+
try {
|
|
101
|
+
gitRepo = runCapture("git remote get-url origin", { cwd: projectDir });
|
|
102
|
+
} catch {
|
|
103
|
+
console.error("Error: No git remote 'origin' found.");
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// --- 6. Setup Coolify deployment ---
|
|
74
108
|
console.log("\nSetting up Coolify deployment...");
|
|
75
|
-
|
|
109
|
+
console.log(` Domain: ${domain}`);
|
|
110
|
+
console.log(` Git repo: ${gitRepo}`);
|
|
111
|
+
|
|
112
|
+
// Create project
|
|
113
|
+
console.log(" Creating Coolify project...");
|
|
114
|
+
const project = await coolifyApi(config, "POST", "/projects", {
|
|
115
|
+
name,
|
|
116
|
+
description: `${name} — deployed via webhikers CLI`,
|
|
117
|
+
});
|
|
118
|
+
const projectUuid = project.uuid;
|
|
119
|
+
console.log(` Project created: ${projectUuid}`);
|
|
120
|
+
|
|
121
|
+
// Create application
|
|
122
|
+
console.log(" Creating application...");
|
|
123
|
+
const app = await coolifyApi(config, "POST", "/applications/public", {
|
|
124
|
+
project_uuid: projectUuid,
|
|
125
|
+
server_uuid: config.serverUuid,
|
|
126
|
+
environment_name: "production",
|
|
127
|
+
git_repository: gitRepo,
|
|
128
|
+
git_branch: "master",
|
|
129
|
+
build_pack: "dockerfile",
|
|
130
|
+
ports_exposes: "3000",
|
|
131
|
+
instant_deploy: false,
|
|
132
|
+
});
|
|
133
|
+
const appUuid = app.uuid;
|
|
134
|
+
console.log(` Application created: ${appUuid}`);
|
|
135
|
+
|
|
136
|
+
// Set domain
|
|
137
|
+
console.log(` Setting domain to ${domain}...`);
|
|
138
|
+
await coolifyApi(config, "PATCH", `/applications/${appUuid}`, {
|
|
139
|
+
domains: `https://${domain}`,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Set environment variables
|
|
143
|
+
console.log(" Setting environment variables...");
|
|
144
|
+
await coolifyApi(config, "POST", `/applications/${appUuid}/envs`, {
|
|
145
|
+
key: "PAYLOAD_SECRET",
|
|
146
|
+
value: payloadSecret,
|
|
147
|
+
is_build_time: true,
|
|
148
|
+
});
|
|
149
|
+
await coolifyApi(config, "POST", `/applications/${appUuid}/envs`, {
|
|
150
|
+
key: "SITE_URL",
|
|
151
|
+
value: siteUrl,
|
|
152
|
+
is_build_time: true,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// --- 7. Write .deploy.json ---
|
|
156
|
+
const deployConfig = {
|
|
157
|
+
serverIp: config.serverIp,
|
|
158
|
+
domain,
|
|
159
|
+
coolifyProjectUuid: projectUuid,
|
|
160
|
+
coolifyAppUuid: appUuid,
|
|
161
|
+
};
|
|
162
|
+
writeFileSync(
|
|
163
|
+
resolve(projectDir, ".deploy.json"),
|
|
164
|
+
JSON.stringify(deployConfig, null, 2) + "\n",
|
|
165
|
+
"utf-8"
|
|
166
|
+
);
|
|
167
|
+
console.log(" .deploy.json written");
|
|
76
168
|
|
|
77
|
-
// ---
|
|
169
|
+
// --- 8. Summary ---
|
|
78
170
|
console.log("");
|
|
79
171
|
console.log("=========================================");
|
|
80
172
|
console.log(" Project created successfully!");
|
|
81
173
|
console.log("=========================================");
|
|
82
174
|
console.log("");
|
|
83
175
|
console.log(` Repo: https://github.com/${GITHUB_ORG}/${name}`);
|
|
84
|
-
console.log(` Domain: https://${
|
|
176
|
+
console.log(` Domain: https://${domain}`);
|
|
85
177
|
console.log(` Dir: ${projectDir}`);
|
|
86
178
|
console.log("");
|
|
87
179
|
console.log(" MANUAL STEP:");
|