petadep 1.0.2 → 1.0.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/cli.js +33 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "petadep",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Deploy GitHub repos to a VPS on push via webhooks",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli.js CHANGED
@@ -46,6 +46,19 @@ function createInterface() {
46
46
  });
47
47
  }
48
48
 
49
+ const colors = {
50
+ reset: "\u001b[0m",
51
+ bold: "\u001b[1m",
52
+ cyan: "\u001b[36m",
53
+ green: "\u001b[32m",
54
+ yellow: "\u001b[33m",
55
+ magenta: "\u001b[35m",
56
+ };
57
+
58
+ function color(text, code) {
59
+ return `${code}${text}${colors.reset}`;
60
+ }
61
+
49
62
  function prompt(rl, question, defaultValue) {
50
63
  const suffix = defaultValue ? ` (${defaultValue})` : "";
51
64
  return new Promise((resolve) => {
@@ -90,16 +103,30 @@ function promptHidden(question) {
90
103
  });
91
104
  }
92
105
 
106
+ async function promptRequired(rl, question) {
107
+ let value = "";
108
+ while (!value) {
109
+ const answer = await prompt(rl, question, "");
110
+ value = answer?.trim() || "";
111
+ if (!value) {
112
+ console.log(color("This value is required. Try again.", colors.yellow));
113
+ }
114
+ }
115
+ return value;
116
+ }
117
+
93
118
  export async function initConfigInteractive() {
94
119
  const rl = createInterface();
95
120
  try {
121
+ console.log(color("petadep setup", colors.bold + colors.magenta));
122
+ console.log(color("Let's create your webhook config.", colors.cyan));
96
123
  const port = await prompt(rl, "Port", "8787");
97
124
  const hookPath = await prompt(rl, "Webhook path", "/webhook");
98
125
  const secretInput = await promptHidden("Secret (leave blank to auto-generate)");
99
- const repo = await prompt(rl, "Repo (owner/repo)", "");
126
+ const repo = await promptRequired(rl, "Repo (owner/repo)");
100
127
  const branch = await prompt(rl, "Branch", "main");
101
128
  const env = await prompt(rl, "Env name", "production");
102
- const workdir = await prompt(rl, "Workdir", "");
129
+ const workdir = await promptRequired(rl, "Workdir");
103
130
  const script = await prompt(rl, "Script path", "./deploy.sh");
104
131
  const logsDir = await prompt(rl, "Logs dir", "./logs");
105
132
  const sshKeyPath = await prompt(rl, "SSH key path (optional)", "");
@@ -120,19 +147,15 @@ export async function initConfigInteractive() {
120
147
  delete config.sshKeyPath;
121
148
  }
122
149
 
123
- if (repo && workdir) {
124
- config.deployments = [
125
- { repo, branch, env, workdir, script },
126
- ];
127
- }
150
+ config.deployments = [{ repo, branch, env, workdir, script }];
128
151
 
129
152
  const resolvedPath = path.resolve(savePath);
130
153
  await fs.mkdir(path.dirname(resolvedPath), { recursive: true });
131
154
  await fs.writeFile(resolvedPath, JSON.stringify(config, null, 2));
132
155
 
133
- console.log("Config created:", resolvedPath);
134
- console.log("Webhook secret:", secret);
135
- console.log(`Start agent: petadep agent --config ${resolvedPath}`);
156
+ console.log(color("Config created:", colors.green), resolvedPath);
157
+ console.log(color("Webhook secret:", colors.green), secret);
158
+ console.log(color("Start agent:", colors.cyan), `petadep agent --config ${resolvedPath}`);
136
159
  } finally {
137
160
  rl.close();
138
161
  }