@arkstack/console 0.14.1 → 0.14.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/dist/index.js +38 -6
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -49,9 +49,12 @@ var BuildCommand = class extends Command {
49
49
  //#endregion
50
50
  //#region dist/commands/DevCommand.js
51
51
  var DevCommand = class extends Command {
52
- signature = "dev";
52
+ signature = `dev
53
+ {--t|tunnel : tunnel the dev server through Ngrok}
54
+ `;
53
55
  description = "Run the development server";
54
56
  async handle() {
57
+ const tunnel = this.option?.("tunnel");
55
58
  await new Promise((resolve, reject) => {
56
59
  const child = spawn(process.platform === "win32" ? "pnpm.cmd" : "pnpm", [
57
60
  "exec",
@@ -61,7 +64,10 @@ var DevCommand = class extends Command {
61
64
  ], {
62
65
  cwd: Arkstack.rootDir(),
63
66
  stdio: "inherit",
64
- env: Object.assign(process.env, { NODE_ENV: "development" })
67
+ env: Object.assign(process.env, {
68
+ NODE_ENV: "development",
69
+ TUNNEL: tunnel ? "true" : void 0
70
+ })
65
71
  });
66
72
  child.on("error", (error) => {
67
73
  reject(error);
@@ -85,7 +91,7 @@ var DevCommand = class extends Command {
85
91
  * APP_KEY is the unified secret used for signing JWTs and encrypting values
86
92
  * across the framework (exposed as `config('app.key')`).
87
93
  */
88
- var KeyGenerateCommand = class extends Command {
94
+ var KeyGenerateCommand = class KeyGenerateCommand extends Command {
89
95
  signature = `key:generate
90
96
  {--show : Display the generated key instead of writing it to the .env file.}
91
97
  {--force : Overwrite the existing APP_KEY without confirmation.}
@@ -103,19 +109,45 @@ var KeyGenerateCommand = class extends Command {
103
109
  return;
104
110
  }
105
111
  const contents = readFileSync(envPath, "utf-8");
106
- const existing = contents.match(/^APP_KEY=(.*)$/m);
107
- if (existing?.[1]?.trim() && !this.option("force")) {
112
+ if (KeyGenerateCommand.hasEnvValue(contents, "APP_KEY") && !this.option("force")) {
108
113
  if (!await this.confirm("An application key already exists. Overwrite it?", false)) {
109
114
  this.info("Application key generation aborted.");
110
115
  return;
111
116
  }
112
117
  }
113
- writeFileSync(envPath, existing ? contents.replace(/^APP_KEY=.*$/m, `APP_KEY=${key}`) : `${contents.replace(/\s*$/, "")}\nAPP_KEY=${key}\n`);
118
+ writeFileSync(envPath, KeyGenerateCommand.upsertEnvKey(contents, "APP_KEY", key));
114
119
  this.success("Application key set successfully.");
115
120
  }
116
121
  generateKey() {
117
122
  return randomBytes(32).toString("base64url");
118
123
  }
124
+ /**
125
+ * Whether the env file defines a non-empty value for `name`.
126
+ *
127
+ * An empty assignment (`APP_KEY=`), whitespace, or empty quotes (`APP_KEY=""`)
128
+ * all count as "not set" so a placeholder line is never mistaken for a real key.
129
+ *
130
+ * @param contents The raw `.env` contents.
131
+ * @param name The variable name.
132
+ */
133
+ static hasEnvValue = (contents, name) => {
134
+ const value = contents.match(new RegExp(`^${name}=(.*)$`, "m"))?.[1]?.trim().replace(/^(["'])(.*)\1$/, "$2").trim();
135
+ return Boolean(value);
136
+ };
137
+ /**
138
+ * Return `contents` with `name` set to `value`, replacing the line in place if
139
+ * it exists or appending it otherwise.
140
+ *
141
+ * @param contents The raw `.env` contents.
142
+ * @param name The variable name.
143
+ * @param value The value to set.
144
+ */
145
+ static upsertEnvKey = (contents, name, value) => {
146
+ const line = `${name}=${value}`;
147
+ const pattern = new RegExp(`^${name}=.*$`, "m");
148
+ if (pattern.test(contents)) return contents.replace(pattern, () => line);
149
+ return `${contents.replace(/\s*$/, "")}\n${line}\n`;
150
+ };
119
151
  };
120
152
 
121
153
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/console",
3
- "version": "0.14.1",
3
+ "version": "0.14.3",
4
4
  "type": "module",
5
5
  "description": "Console module for Arkstack, providing the command-line runtime and console integration layer.",
6
6
  "homepage": "https://arkstack.toneflix.net/guide/cli",
@@ -46,13 +46,13 @@
46
46
  "clear-router": "^2.8.8"
47
47
  },
48
48
  "dependencies": {
49
- "@h3ravel/musket": "^2.2.0",
49
+ "@h3ravel/musket": "^2.2.1",
50
50
  "@h3ravel/support": "^2.1.4",
51
51
  "chalk": "^5.6.2",
52
52
  "resora": "^1.3.26",
53
53
  "ts-morph": "^28.0.0",
54
- "@arkstack/contract": "^0.14.1",
55
- "@arkstack/common": "^0.14.1"
54
+ "@arkstack/common": "^0.14.3",
55
+ "@arkstack/contract": "^0.14.3"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "tsdown",