@webhikers/cli 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Webhikers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # @webhikers/cli
2
+
3
+ CLI for creating and deploying webhikers projects.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install -g @webhikers/cli
9
+ ```
10
+
11
+ ## Setup (once per machine)
12
+
13
+ ```bash
14
+ webhikers config
15
+ ```
16
+
17
+ Configures Coolify API token, server credentials, and SSH key.
18
+
19
+ ## Create a new project
20
+
21
+ ```bash
22
+ webhikers create my-project
23
+ ```
24
+
25
+ This will:
26
+ 1. Create a private GitHub repo from the `nextjs-vibe-starter` template
27
+ 2. Clone it and install dependencies
28
+ 3. Generate `.env` with a random `PAYLOAD_SECRET`
29
+ 4. Create a Coolify project and configure the domain (`my-project.webhikers.site`)
30
+
31
+ After creation, add persistent volumes in Coolify UI, then start developing:
32
+
33
+ ```bash
34
+ cd my-project && npm run dev
35
+ ```
36
+
37
+ ## License
38
+
39
+ MIT
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { program } from "commander";
4
+ import { configCommand } from "../src/commands/config.js";
5
+ import { createCommand } from "../src/commands/create.js";
6
+
7
+ program
8
+ .name("webhikers")
9
+ .description("CLI for creating and deploying webhikers projects")
10
+ .version("1.0.0");
11
+
12
+ program
13
+ .command("config")
14
+ .description("Configure Coolify token, server, and SSH credentials")
15
+ .action(configCommand);
16
+
17
+ program
18
+ .command("create <name>")
19
+ .description("Create a new project from the nextjs-vibe-starter template")
20
+ .action(createCommand);
21
+
22
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@webhikers/cli",
3
+ "version": "1.0.0",
4
+ "description": "CLI for creating and deploying webhikers projects",
5
+ "type": "module",
6
+ "bin": {
7
+ "webhikers": "./bin/webhikers.js"
8
+ },
9
+ "dependencies": {
10
+ "commander": "^13.0.0",
11
+ "inquirer": "^12.0.0"
12
+ },
13
+ "engines": {
14
+ "node": ">=18"
15
+ },
16
+ "files": [
17
+ "bin",
18
+ "src"
19
+ ],
20
+ "license": "MIT",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/Webhikers/webhikers-cli.git"
24
+ }
25
+ }
@@ -0,0 +1,96 @@
1
+ import inquirer from "inquirer";
2
+ import {
3
+ loadConfig,
4
+ saveConfig,
5
+ maskValue,
6
+ getConfigPath,
7
+ } from "../utils/config-store.js";
8
+ import { saveSSHKey, getSSHKeyPath } from "../utils/ssh-key.js";
9
+
10
+ export async function configCommand() {
11
+ const existing = loadConfig();
12
+
13
+ if (existing) {
14
+ console.log("\nExisting configuration found:");
15
+ console.log(` Coolify URL: ${existing.coolifyUrl || "—"}`);
16
+ console.log(` Coolify Token: ${maskValue(existing.coolifyToken)}`);
17
+ console.log(` Server UUID: ${maskValue(existing.serverUuid)}`);
18
+ console.log(` Server IP: ${existing.serverIp || "—"}`);
19
+ console.log(` SSH User: ${existing.sshUser || "—"}`);
20
+ console.log(` SSH Key: ${getSSHKeyPath()}`);
21
+ console.log("");
22
+
23
+ const { overwrite } = await inquirer.prompt([
24
+ {
25
+ type: "confirm",
26
+ name: "overwrite",
27
+ message: "Overwrite existing configuration?",
28
+ default: false,
29
+ },
30
+ ]);
31
+
32
+ if (!overwrite) {
33
+ console.log("Configuration unchanged.");
34
+ return;
35
+ }
36
+ }
37
+
38
+ const answers = await inquirer.prompt([
39
+ {
40
+ type: "input",
41
+ name: "coolifyUrl",
42
+ message: "Coolify URL (e.g. https://coolify.your-server.de):",
43
+ validate: (v) => (v.startsWith("http") ? true : "Must start with http"),
44
+ },
45
+ {
46
+ type: "password",
47
+ name: "coolifyToken",
48
+ message: "Coolify API Token:",
49
+ mask: "*",
50
+ validate: (v) => (v.length > 0 ? true : "Token is required"),
51
+ },
52
+ {
53
+ type: "input",
54
+ name: "serverUuid",
55
+ message: "Server UUID (from Coolify UI → Servers):",
56
+ validate: (v) => (v.length > 0 ? true : "Server UUID is required"),
57
+ },
58
+ {
59
+ type: "input",
60
+ name: "serverIp",
61
+ message: "Server IP address:",
62
+ validate: (v) => (v.length > 0 ? true : "Server IP is required"),
63
+ },
64
+ {
65
+ type: "input",
66
+ name: "sshUser",
67
+ message: "SSH User:",
68
+ default: "root",
69
+ },
70
+ {
71
+ type: "editor",
72
+ name: "sshKey",
73
+ message:
74
+ "SSH Private Key (your editor will open — paste the key, save, and close):",
75
+ validate: (v) =>
76
+ v.includes("PRIVATE KEY") ? true : "Does not look like a valid SSH key",
77
+ },
78
+ ]);
79
+
80
+ const keyPath = saveSSHKey(answers.sshKey);
81
+
82
+ const config = {
83
+ coolifyUrl: answers.coolifyUrl.replace(/\/+$/, ""),
84
+ coolifyToken: answers.coolifyToken,
85
+ serverUuid: answers.serverUuid,
86
+ serverIp: answers.serverIp,
87
+ sshUser: answers.sshUser,
88
+ sshKeyPath: keyPath,
89
+ };
90
+
91
+ saveConfig(config);
92
+
93
+ console.log(`\nConfiguration saved to ${getConfigPath()}`);
94
+ console.log(`SSH key saved to ${keyPath}`);
95
+ console.log("\nDone! You can now run: webhikers create <project-name>");
96
+ }
@@ -0,0 +1,95 @@
1
+ import { execSync } from "child_process";
2
+ import { existsSync, writeFileSync } from "fs";
3
+ import { resolve } from "path";
4
+ import { loadConfig, getConfigPath } from "../utils/config-store.js";
5
+
6
+ const TEMPLATE_REPO = "Webhikers/nextjs-vibe-starter";
7
+ const GITHUB_ORG = "Webhikers";
8
+
9
+ function run(cmd, options = {}) {
10
+ console.log(` → ${cmd}`);
11
+ return execSync(cmd, { stdio: "inherit", ...options });
12
+ }
13
+
14
+ function runCapture(cmd) {
15
+ return execSync(cmd, { encoding: "utf-8" }).trim();
16
+ }
17
+
18
+ export async function createCommand(name) {
19
+ console.log(`\nCreating project: ${name}\n`);
20
+
21
+ // --- 1. Check prerequisites ---
22
+ const config = loadConfig();
23
+ if (!config) {
24
+ console.error(`Error: ${getConfigPath()} not found.`);
25
+ console.error("Run 'webhikers config' first.");
26
+ process.exit(1);
27
+ }
28
+
29
+ try {
30
+ runCapture("which gh");
31
+ } catch {
32
+ console.error("Error: GitHub CLI (gh) not found.");
33
+ console.error("Install it: https://cli.github.com");
34
+ process.exit(1);
35
+ }
36
+
37
+ try {
38
+ runCapture("gh auth status");
39
+ } catch {
40
+ console.error("Error: Not logged into GitHub CLI.");
41
+ console.error("Run: gh auth login");
42
+ process.exit(1);
43
+ }
44
+
45
+ // --- 2. Create GitHub repo from template ---
46
+ console.log("Creating GitHub repo from template...");
47
+ run(
48
+ `gh repo create ${GITHUB_ORG}/${name} --template ${TEMPLATE_REPO} --private --clone`
49
+ );
50
+
51
+ const projectDir = resolve(process.cwd(), name);
52
+ if (!existsSync(projectDir)) {
53
+ console.error(`Error: Expected directory ${projectDir} not found.`);
54
+ process.exit(1);
55
+ }
56
+
57
+ // --- 3. npm install ---
58
+ console.log("\nInstalling dependencies...");
59
+ run("npm install", { cwd: projectDir });
60
+
61
+ // --- 4. Generate .env ---
62
+ console.log("\nGenerating .env...");
63
+ const payloadSecret = runCapture("openssl rand -hex 32");
64
+ const envContent = [
65
+ `PAYLOAD_SECRET=${payloadSecret}`,
66
+ `SITE_URL=http://localhost:3000`,
67
+ "",
68
+ ].join("\n");
69
+
70
+ writeFileSync(resolve(projectDir, ".env"), envContent, "utf-8");
71
+ console.log(" .env written (PAYLOAD_SECRET + SITE_URL)");
72
+
73
+ // --- 5. Setup Coolify deployment ---
74
+ console.log("\nSetting up Coolify deployment...");
75
+ run(`npm run setup:deploy -- --name ${name}`, { cwd: projectDir });
76
+
77
+ // --- 6. Summary ---
78
+ console.log("");
79
+ console.log("=========================================");
80
+ console.log(" Project created successfully!");
81
+ console.log("=========================================");
82
+ console.log("");
83
+ console.log(` Repo: https://github.com/${GITHUB_ORG}/${name}`);
84
+ console.log(` Domain: https://${name}.webhikers.site`);
85
+ console.log(` Dir: ${projectDir}`);
86
+ console.log("");
87
+ console.log(" MANUAL STEP:");
88
+ console.log(" Open Coolify UI → Application → Storages");
89
+ console.log(" Add two volumes:");
90
+ console.log(" 1. /app/data (SQLite database)");
91
+ console.log(" 2. /app/public/media (uploaded images)");
92
+ console.log("");
93
+ console.log(` Ready! Run: cd ${name} && npm run dev`);
94
+ console.log("=========================================");
95
+ }
@@ -0,0 +1,32 @@
1
+ import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
2
+ import { join } from "path";
3
+ import { homedir } from "os";
4
+
5
+ const CONFIG_DIR = join(homedir(), ".config", "webhikers");
6
+ const CONFIG_FILE = join(CONFIG_DIR, "config.json");
7
+
8
+ export function getConfigDir() {
9
+ return CONFIG_DIR;
10
+ }
11
+
12
+ export function getConfigPath() {
13
+ return CONFIG_FILE;
14
+ }
15
+
16
+ export function loadConfig() {
17
+ if (!existsSync(CONFIG_FILE)) {
18
+ return null;
19
+ }
20
+ const raw = readFileSync(CONFIG_FILE, "utf-8");
21
+ return JSON.parse(raw);
22
+ }
23
+
24
+ export function saveConfig(config) {
25
+ mkdirSync(CONFIG_DIR, { recursive: true });
26
+ writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2) + "\n", "utf-8");
27
+ }
28
+
29
+ export function maskValue(value) {
30
+ if (!value || value.length < 8) return "***";
31
+ return value.slice(0, 4) + "..." + value.slice(-4);
32
+ }
@@ -0,0 +1,17 @@
1
+ import { writeFileSync, chmodSync } from "fs";
2
+ import { join } from "path";
3
+ import { getConfigDir } from "./config-store.js";
4
+
5
+ const SSH_KEY_FILENAME = "ssh_key";
6
+
7
+ export function getSSHKeyPath() {
8
+ return join(getConfigDir(), SSH_KEY_FILENAME);
9
+ }
10
+
11
+ export function saveSSHKey(keyContent) {
12
+ const keyPath = getSSHKeyPath();
13
+ const normalized = keyContent.trim() + "\n";
14
+ writeFileSync(keyPath, normalized, "utf-8");
15
+ chmodSync(keyPath, 0o600);
16
+ return keyPath;
17
+ }