lokuma-cli 1.0.3 → 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/dist/index.js +108 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import { Command } from "commander";
|
|
5
|
-
import { readFileSync as
|
|
5
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
6
6
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
7
|
-
import { dirname as
|
|
7
|
+
import { dirname as dirname3, join as join3 } from "path";
|
|
8
8
|
|
|
9
9
|
// src/commands/init.ts
|
|
10
10
|
import { mkdir, writeFile, access } from "node:fs/promises";
|
|
@@ -182,10 +182,110 @@ async function initCommand(options) {
|
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
+
// src/commands/auth.ts
|
|
186
|
+
import { writeFileSync, readFileSync as readFileSync2, existsSync, mkdirSync } from "node:fs";
|
|
187
|
+
import { dirname as dirname2, join as join2 } from "node:path";
|
|
188
|
+
import { createInterface } from "node:readline";
|
|
189
|
+
import chalk2 from "chalk";
|
|
190
|
+
function detectShellRc() {
|
|
191
|
+
const shell = process.env.SHELL ?? "";
|
|
192
|
+
const home = process.env.HOME ?? "";
|
|
193
|
+
if (shell.includes("zsh")) return join2(home, ".zshrc");
|
|
194
|
+
if (shell.includes("bash")) return process.platform === "darwin" ? join2(home, ".bash_profile") : join2(home, ".bashrc");
|
|
195
|
+
return join2(home, ".profile");
|
|
196
|
+
}
|
|
197
|
+
function persistKey(key) {
|
|
198
|
+
const rc = detectShellRc();
|
|
199
|
+
let content = existsSync(rc) ? readFileSync2(rc, "utf-8") : "";
|
|
200
|
+
content = content.replace(/\n?# Lokuma API key\nexport LOKUMA_API_KEY=.*\n?/g, "");
|
|
201
|
+
content += `
|
|
202
|
+
# Lokuma API key
|
|
203
|
+
export LOKUMA_API_KEY="${key}"
|
|
204
|
+
`;
|
|
205
|
+
writeFileSync(rc, content, "utf-8");
|
|
206
|
+
const envFile = join2(process.env.HOME ?? "", ".lokuma");
|
|
207
|
+
mkdirSync(dirname2(envFile), { recursive: true });
|
|
208
|
+
writeFileSync(envFile, `LOKUMA_API_KEY=${key}
|
|
209
|
+
`, "utf-8");
|
|
210
|
+
return rc;
|
|
211
|
+
}
|
|
212
|
+
async function prompt(question, hidden = false) {
|
|
213
|
+
return new Promise((resolve) => {
|
|
214
|
+
const rl = createInterface({
|
|
215
|
+
input: process.stdin,
|
|
216
|
+
output: hidden ? void 0 : process.stdout,
|
|
217
|
+
terminal: hidden
|
|
218
|
+
});
|
|
219
|
+
if (hidden) {
|
|
220
|
+
process.stdout.write(question);
|
|
221
|
+
process.stdin.setRawMode?.(true);
|
|
222
|
+
let input = "";
|
|
223
|
+
process.stdin.resume();
|
|
224
|
+
process.stdin.setEncoding("utf-8");
|
|
225
|
+
process.stdin.on("data", (char) => {
|
|
226
|
+
if (char === "\n" || char === "\r" || char === "") {
|
|
227
|
+
process.stdin.setRawMode?.(false);
|
|
228
|
+
process.stdout.write("\n");
|
|
229
|
+
rl.close();
|
|
230
|
+
resolve(input);
|
|
231
|
+
} else if (char === "") {
|
|
232
|
+
process.exit(0);
|
|
233
|
+
} else if (char === "\x7F") {
|
|
234
|
+
input = input.slice(0, -1);
|
|
235
|
+
} else {
|
|
236
|
+
input += char;
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
} else {
|
|
240
|
+
rl.question(question, (answer) => {
|
|
241
|
+
rl.close();
|
|
242
|
+
resolve(answer.trim());
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
async function authLoginCommand() {
|
|
248
|
+
console.log();
|
|
249
|
+
console.log(chalk2.bold(" Lokuma \u2014 API Key Setup"));
|
|
250
|
+
console.log(chalk2.dim(" Get your key at https://lokuma.ai"));
|
|
251
|
+
console.log();
|
|
252
|
+
const existing = process.env.LOKUMA_API_KEY;
|
|
253
|
+
if (existing) {
|
|
254
|
+
const masked = existing.slice(0, 10) + "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022";
|
|
255
|
+
console.log(chalk2.dim(` Current key: ${masked}`));
|
|
256
|
+
const overwrite = await prompt(" Overwrite? (y/N): ");
|
|
257
|
+
if (overwrite.toLowerCase() !== "y") {
|
|
258
|
+
console.log(chalk2.dim(" Keeping existing key."));
|
|
259
|
+
console.log();
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const key = await prompt(" Paste your API key: ", true);
|
|
264
|
+
if (!key) {
|
|
265
|
+
console.log(chalk2.yellow(" No key entered. Exiting."));
|
|
266
|
+
console.log();
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
if (!key.startsWith("lokuma_")) {
|
|
270
|
+
console.log(chalk2.red(" \u2717 Invalid key format (should start with lokuma_)"));
|
|
271
|
+
console.log(chalk2.dim(" Visit https://lokuma.ai to get a valid key."));
|
|
272
|
+
console.log();
|
|
273
|
+
process.exit(1);
|
|
274
|
+
}
|
|
275
|
+
const rc = persistKey(key);
|
|
276
|
+
console.log();
|
|
277
|
+
console.log(chalk2.green(" \u2713 API key saved!"));
|
|
278
|
+
console.log(chalk2.dim(` Written to: ${rc}`));
|
|
279
|
+
console.log();
|
|
280
|
+
console.log(chalk2.dim(" Reload your shell to apply:"));
|
|
281
|
+
console.log(chalk2.cyan(` source ${rc}`));
|
|
282
|
+
console.log();
|
|
283
|
+
}
|
|
284
|
+
|
|
185
285
|
// src/index.ts
|
|
186
286
|
var __filename = fileURLToPath2(import.meta.url);
|
|
187
|
-
var __dirname =
|
|
188
|
-
var pkg = JSON.parse(
|
|
287
|
+
var __dirname = dirname3(__filename);
|
|
288
|
+
var pkg = JSON.parse(readFileSync3(join3(__dirname, "../package.json"), "utf-8"));
|
|
189
289
|
var program = new Command();
|
|
190
290
|
program.name("lokuma").description("Install Lokuma design intelligence skill for AI coding assistants").version(pkg.version);
|
|
191
291
|
program.command("init").description("Install Lokuma skill to current project").option("-a, --ai <type>", `AI assistant type (${AI_TYPES.join(", ")})`).option("-f, --force", "Overwrite existing files").action(async (options) => {
|
|
@@ -199,4 +299,8 @@ program.command("init").description("Install Lokuma skill to current project").o
|
|
|
199
299
|
force: options.force
|
|
200
300
|
});
|
|
201
301
|
});
|
|
302
|
+
var auth = program.command("auth").description("Manage authentication");
|
|
303
|
+
auth.command("login").description("Set or update your Lokuma API key").action(async () => {
|
|
304
|
+
await authLoginCommand();
|
|
305
|
+
});
|
|
202
306
|
program.parse();
|