@arkstack/console 0.14.0 → 0.14.2

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 +30 -4
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -85,7 +85,7 @@ var DevCommand = class extends Command {
85
85
  * APP_KEY is the unified secret used for signing JWTs and encrypting values
86
86
  * across the framework (exposed as `config('app.key')`).
87
87
  */
88
- var KeyGenerateCommand = class extends Command {
88
+ var KeyGenerateCommand = class KeyGenerateCommand extends Command {
89
89
  signature = `key:generate
90
90
  {--show : Display the generated key instead of writing it to the .env file.}
91
91
  {--force : Overwrite the existing APP_KEY without confirmation.}
@@ -103,19 +103,45 @@ var KeyGenerateCommand = class extends Command {
103
103
  return;
104
104
  }
105
105
  const contents = readFileSync(envPath, "utf-8");
106
- const existing = contents.match(/^APP_KEY=(.*)$/m);
107
- if (existing?.[1]?.trim() && !this.option("force")) {
106
+ if (KeyGenerateCommand.hasEnvValue(contents, "APP_KEY") && !this.option("force")) {
108
107
  if (!await this.confirm("An application key already exists. Overwrite it?", false)) {
109
108
  this.info("Application key generation aborted.");
110
109
  return;
111
110
  }
112
111
  }
113
- writeFileSync(envPath, existing ? contents.replace(/^APP_KEY=.*$/m, `APP_KEY=${key}`) : `${contents.replace(/\s*$/, "")}\nAPP_KEY=${key}\n`);
112
+ writeFileSync(envPath, KeyGenerateCommand.upsertEnvKey(contents, "APP_KEY", key));
114
113
  this.success("Application key set successfully.");
115
114
  }
116
115
  generateKey() {
117
116
  return randomBytes(32).toString("base64url");
118
117
  }
118
+ /**
119
+ * Whether the env file defines a non-empty value for `name`.
120
+ *
121
+ * An empty assignment (`APP_KEY=`), whitespace, or empty quotes (`APP_KEY=""`)
122
+ * all count as "not set" so a placeholder line is never mistaken for a real key.
123
+ *
124
+ * @param contents The raw `.env` contents.
125
+ * @param name The variable name.
126
+ */
127
+ static hasEnvValue = (contents, name) => {
128
+ const value = contents.match(new RegExp(`^${name}=(.*)$`, "m"))?.[1]?.trim().replace(/^(["'])(.*)\1$/, "$2").trim();
129
+ return Boolean(value);
130
+ };
131
+ /**
132
+ * Return `contents` with `name` set to `value`, replacing the line in place if
133
+ * it exists or appending it otherwise.
134
+ *
135
+ * @param contents The raw `.env` contents.
136
+ * @param name The variable name.
137
+ * @param value The value to set.
138
+ */
139
+ static upsertEnvKey = (contents, name, value) => {
140
+ const line = `${name}=${value}`;
141
+ const pattern = new RegExp(`^${name}=.*$`, "m");
142
+ if (pattern.test(contents)) return contents.replace(pattern, () => line);
143
+ return `${contents.replace(/\s*$/, "")}\n${line}\n`;
144
+ };
119
145
  };
120
146
 
121
147
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/console",
3
- "version": "0.14.0",
3
+ "version": "0.14.2",
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",
@@ -42,17 +42,17 @@
42
42
  }
43
43
  },
44
44
  "peerDependencies": {
45
- "arkormx": "^2.9.2",
45
+ "arkormx": "^2.9.3",
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/common": "^0.14.0",
55
- "@arkstack/contract": "^0.14.0"
54
+ "@arkstack/common": "^0.14.2",
55
+ "@arkstack/contract": "^0.14.2"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "tsdown",