lakebed 0.0.9 → 0.0.10
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/README.md +4 -1
- package/package.json +5 -5
- package/src/anonymous-server.js +1059 -329
- package/src/cli.js +52 -2
- package/src/version.js +1 -1
package/src/cli.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
2
3
|
import { createServer } from "node:http";
|
|
3
4
|
import { existsSync, realpathSync } from "node:fs";
|
|
4
5
|
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
5
6
|
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
6
7
|
import { createInterface } from "node:readline/promises";
|
|
8
|
+
import { promisify } from "node:util";
|
|
7
9
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
8
10
|
import * as esbuild from "esbuild";
|
|
9
11
|
import { WebSocketServer } from "ws";
|
|
@@ -28,12 +30,14 @@ const packageDir = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
|
28
30
|
const packageNodeModules = resolve(packageDir, "node_modules");
|
|
29
31
|
const sourceNamespace = "lakebed-source";
|
|
30
32
|
const defaultDeployApiUrl = "https://api.lakebed.app";
|
|
33
|
+
const execFileAsync = promisify(execFile);
|
|
31
34
|
|
|
32
35
|
function usage() {
|
|
33
36
|
console.log(`lakebed
|
|
34
37
|
|
|
35
38
|
Usage:
|
|
36
|
-
lakebed new [name] [--template todo]
|
|
39
|
+
lakebed new [name] [--template todo] [--no-git]
|
|
40
|
+
lakebed create [name] [--template todo] [--no-git]
|
|
37
41
|
lakebed dev <capsule-dir> [--port 3000]
|
|
38
42
|
lakebed build <capsule-dir> --target anonymous [--out .lakebed/artifacts/app.json] [--json]
|
|
39
43
|
lakebed deploy [capsule-dir] [--ttl 7d] [--api <url>] [--json]
|
|
@@ -1311,6 +1315,7 @@ pnpm lakebed dev ${name}
|
|
|
1311
1315
|
async function newCommand(args) {
|
|
1312
1316
|
const [nameArg] = positionals(args);
|
|
1313
1317
|
const template = readArg(args, "--template", "todo");
|
|
1318
|
+
const shouldInitGit = !hasFlag(args, "--no-git");
|
|
1314
1319
|
|
|
1315
1320
|
if (template !== "todo") {
|
|
1316
1321
|
throw new Error(`Unknown template: ${template}`);
|
|
@@ -1334,6 +1339,51 @@ async function newCommand(args) {
|
|
|
1334
1339
|
}
|
|
1335
1340
|
|
|
1336
1341
|
console.log(`Created Lakebed capsule at ${targetDir}`);
|
|
1342
|
+
const gitStatus = shouldInitGit ? await initializeGitRepository(targetDir) : "Skipped git setup (--no-git).";
|
|
1343
|
+
console.log(gitStatus);
|
|
1344
|
+
console.log(`
|
|
1345
|
+
Next:
|
|
1346
|
+
cd ${shellQuote(name)}
|
|
1347
|
+
npx lakebed dev
|
|
1348
|
+
|
|
1349
|
+
deploy instantly for free with:
|
|
1350
|
+
npx lakebed deploy`);
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
async function initializeGitRepository(targetDir) {
|
|
1354
|
+
if (await isInsideGitWorkTree(dirname(targetDir))) {
|
|
1355
|
+
return "Skipped git setup because the capsule is inside an existing git repository.";
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
try {
|
|
1359
|
+
await execFileAsync("git", ["init"], { cwd: targetDir });
|
|
1360
|
+
await execFileAsync("git", ["add", "."], { cwd: targetDir });
|
|
1361
|
+
await execFileAsync(
|
|
1362
|
+
"git",
|
|
1363
|
+
["-c", "user.name=Lakebed", "-c", "user.email=lakebed@example.invalid", "commit", "-m", "Initial Lakebed capsule"],
|
|
1364
|
+
{ cwd: targetDir }
|
|
1365
|
+
);
|
|
1366
|
+
return "Initialized git repository and created initial commit.";
|
|
1367
|
+
} catch (error) {
|
|
1368
|
+
return `Skipped git setup: ${error instanceof Error ? error.message : String(error)}`;
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
async function isInsideGitWorkTree(cwd) {
|
|
1373
|
+
try {
|
|
1374
|
+
const { stdout } = await execFileAsync("git", ["rev-parse", "--is-inside-work-tree"], { cwd });
|
|
1375
|
+
return stdout.trim() === "true";
|
|
1376
|
+
} catch {
|
|
1377
|
+
return false;
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
function shellQuote(value) {
|
|
1382
|
+
if (/^[A-Za-z0-9_./:-]+$/.test(value)) {
|
|
1383
|
+
return value;
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
1337
1387
|
}
|
|
1338
1388
|
|
|
1339
1389
|
async function promptForCapsuleName() {
|
|
@@ -1396,7 +1446,7 @@ async function runMany(args) {
|
|
|
1396
1446
|
async function main() {
|
|
1397
1447
|
const [command, ...args] = process.argv.slice(2);
|
|
1398
1448
|
|
|
1399
|
-
if (command === "new") {
|
|
1449
|
+
if (command === "new" || command === "create") {
|
|
1400
1450
|
await newCommand(args);
|
|
1401
1451
|
return;
|
|
1402
1452
|
}
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const LAKEBED_VERSION = "0.0.
|
|
1
|
+
export const LAKEBED_VERSION = "0.0.10";
|