@quatronic/qore 0.4.0-rc.1 → 0.4.0-test.1f7e2c4
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 +19 -0
- package/dist/cli.js +172 -49
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -141,6 +141,19 @@ qore env pull
|
|
|
141
141
|
directory, then renamed over the target — it's never truncated in place.
|
|
142
142
|
(On Windows, POSIX file modes don't apply — setting `0600` there is a
|
|
143
143
|
no-op; there's no equivalent file-permission hardening on that platform.)
|
|
144
|
+
- When the repository has a `mobile/` directory (an Expo app), the pull also
|
|
145
|
+
writes `mobile/.env.local` with the app's **public** staging config:
|
|
146
|
+
`EXPO_PUBLIC_SERVER_URL`, `EXPO_PUBLIC_SENTRY_DSN` and
|
|
147
|
+
`EXPO_PUBLIC_QORE_ENV=staging`. qore owns those three keys and overwrites
|
|
148
|
+
them; every other line in the file is kept. A value the portal does not have
|
|
149
|
+
yet is left out rather than written empty, because an empty `EXPO_PUBLIC_*`
|
|
150
|
+
value would override the one baked into `app.config.ts`. Until staging is
|
|
151
|
+
deployed there is no server URL; the pull says so, and running it again
|
|
152
|
+
after the deploy fills it in. A portal too old to serve this config is
|
|
153
|
+
skipped with a note, and a failed fetch warns without failing the pull.
|
|
154
|
+
`--json` reports it as
|
|
155
|
+
`mobile: { target, environment, serverUrl, sentryDsn: <set?>, written }`
|
|
156
|
+
(`null` without a `mobile/` directory). `qore dev` does not write this file.
|
|
144
157
|
|
|
145
158
|
**First use of a repository** requires confirmation — see "Trust on first
|
|
146
159
|
use" below. **Values are never printed**: not in `qore env pull`'s output,
|
|
@@ -280,6 +293,12 @@ a hint rather than leaving a bare error (spec §14.2):
|
|
|
280
293
|
- **A leftover `qore dev` holds the port**: in a TTY, offers to stop it
|
|
281
294
|
(`Stop the previous qore dev (pid N)?`); outside a TTY it's just
|
|
282
295
|
`QORE_PORT_IN_USE`.
|
|
296
|
+
- **Another checkout of the same module holds `DB_PORT`** (a worktree or a
|
|
297
|
+
second clone, whose compose project is named after its own folder): the
|
|
298
|
+
error names that checkout and suggests stopping its database there or
|
|
299
|
+
running `qore dev` from it. The two checkouts are matched on the managed
|
|
300
|
+
keys `QORE_MODULE` and `QORE_CUSTOMER_ID` in their env files, so this needs
|
|
301
|
+
no portal call. `qore doctor` reports the same.
|
|
283
302
|
- **The dev server exits within seconds of starting**: its tail output is
|
|
284
303
|
classified into a hint — a missing dependency (`Cannot find module`), an
|
|
285
304
|
invalid/missing env var (a `ZodError`'s keys, never values), a port taken
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
3
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="fdf8ddca-c1bb-5549-9d3b-a2a664c8a79c")}catch(e){}}();
|
|
4
4
|
import { createRequire as __qoreCreateRequire } from "node:module"; const require = __qoreCreateRequire(import.meta.url);
|
|
5
5
|
import {
|
|
6
6
|
addSecretValues,
|
|
@@ -135,6 +135,7 @@ function processIo(interactive, stderrTTY = Boolean(process.stderr.isTTY)) {
|
|
|
135
135
|
stderrTTY,
|
|
136
136
|
stderrRaw: process.stderr,
|
|
137
137
|
async select(message, choices) {
|
|
138
|
+
if (choices.length === 0) throw noChoices(message);
|
|
138
139
|
try {
|
|
139
140
|
return await select({ message, choices });
|
|
140
141
|
} catch (e) {
|
|
@@ -170,6 +171,11 @@ function processIo(interactive, stderrTTY = Boolean(process.stderr.isTTY)) {
|
|
|
170
171
|
openUrl: openBrowser
|
|
171
172
|
};
|
|
172
173
|
}
|
|
174
|
+
function noChoices(message) {
|
|
175
|
+
return new QoreError("QORE_RESOURCE_NOT_FOUND", `Nothing to choose from (${message}): the list is empty`, {
|
|
176
|
+
hint: "Run `qore whoami` to check what your account has access to, or pass the value as an argument."
|
|
177
|
+
});
|
|
178
|
+
}
|
|
173
179
|
function createWaitForEnter(input2, output) {
|
|
174
180
|
return (message, signal) => new Promise((resolve9, reject) => {
|
|
175
181
|
const rl = createInterface({ input: input2, output, terminal: true });
|
|
@@ -4615,9 +4621,9 @@ async function erdApp(ctx, f, ws) {
|
|
|
4615
4621
|
|
|
4616
4622
|
// src/cli/commands/dev.ts
|
|
4617
4623
|
import { randomBytes as randomBytes8 } from "crypto";
|
|
4618
|
-
import { realpath as
|
|
4624
|
+
import { realpath as realpath12 } from "fs/promises";
|
|
4619
4625
|
import { constants as constants5 } from "os";
|
|
4620
|
-
import { dirname as dirname10, join as
|
|
4626
|
+
import { dirname as dirname10, join as join29, relative as relative9 } from "path";
|
|
4621
4627
|
import { StringDecoder } from "string_decoder";
|
|
4622
4628
|
|
|
4623
4629
|
// src/core/diagnostics/node.ts
|
|
@@ -4901,6 +4907,10 @@ function noLocalRole(o) {
|
|
|
4901
4907
|
};
|
|
4902
4908
|
}
|
|
4903
4909
|
|
|
4910
|
+
// src/core/dev/preflight.ts
|
|
4911
|
+
import { realpath as realpath10 } from "fs/promises";
|
|
4912
|
+
import { join as join25 } from "path";
|
|
4913
|
+
|
|
4904
4914
|
// src/core/dev/project.ts
|
|
4905
4915
|
import { access, readFile as readFile7 } from "fs/promises";
|
|
4906
4916
|
import { join as join23 } from "path";
|
|
@@ -5189,6 +5199,24 @@ async function installIfNeeded(deps2, r, slug, onLine, report, signal) {
|
|
|
5189
5199
|
}
|
|
5190
5200
|
report({ module: slug, step: "install", status: "done", detail: secs(deps2.now().getTime() - began) });
|
|
5191
5201
|
}
|
|
5202
|
+
async function checkoutEnv(dir2) {
|
|
5203
|
+
const named2 = await readRepoConfig(dir2).then((c) => c.envFile, () => void 0);
|
|
5204
|
+
for (const file of [named2, ".env.local", ".env"]) {
|
|
5205
|
+
if (!file) continue;
|
|
5206
|
+
const text2 = await readOrNull(join25(dir2, file));
|
|
5207
|
+
if (text2 !== null) return Object.fromEntries(parseEnv(text2));
|
|
5208
|
+
}
|
|
5209
|
+
return null;
|
|
5210
|
+
}
|
|
5211
|
+
async function isOtherCheckoutOfModule(dir2, o) {
|
|
5212
|
+
const module = o.env?.QORE_MODULE;
|
|
5213
|
+
const customer = o.env?.QORE_CUSTOMER_ID;
|
|
5214
|
+
if (!module || !customer || !o.root) return false;
|
|
5215
|
+
const resolve9 = (p) => realpath10(p).catch(() => p);
|
|
5216
|
+
if (await resolve9(dir2) === await resolve9(o.root)) return false;
|
|
5217
|
+
const other = await checkoutEnv(dir2);
|
|
5218
|
+
return other?.QORE_MODULE === module && other.QORE_CUSTOMER_ID === customer;
|
|
5219
|
+
}
|
|
5192
5220
|
async function portInUseError(deps2, o) {
|
|
5193
5221
|
const owner = await deps2.ports.owner(o.port);
|
|
5194
5222
|
const qoreRun = (o.runs ?? []).find((r) => r.children.some((c) => c.port === o.port) || owner !== null && (r.qorePid === owner.pid || r.children.some((c) => c.pid === owner.pid)));
|
|
@@ -5201,6 +5229,12 @@ async function portInUseError(deps2, o) {
|
|
|
5201
5229
|
if (owner) {
|
|
5202
5230
|
if (/^(com\.docker\.backend|com\.docker\.vpnkit|docker-proxy|vpnkit|dockerd)$/.test(owner.command)) {
|
|
5203
5231
|
const pub = await deps2.ports.dockerPublisher(o.port);
|
|
5232
|
+
if (pub?.workingDir && await isOtherCheckoutOfModule(pub.workingDir, o)) {
|
|
5233
|
+
return new QoreError("QORE_PORT_IN_USE", `Port ${o.port} is held by ${o.slug}'s database from ${pub.workingDir}`, {
|
|
5234
|
+
hint: `That is another checkout of ${o.slug}, and both use port ${o.port}. Stop it there (docker compose down in ${pub.workingDir}, or docker stop ${pub.name}), or run qore dev from that checkout instead.`,
|
|
5235
|
+
details: { port: o.port, module: o.slug, key: o.key, owner: "docker", sameModule: true, ...pub }
|
|
5236
|
+
});
|
|
5237
|
+
}
|
|
5204
5238
|
if (pub) {
|
|
5205
5239
|
return new QoreError("QORE_PORT_IN_USE", `Port ${o.port} is held by the Docker container ${pub.name} (needed by ${o.slug})`, {
|
|
5206
5240
|
hint: `It belongs to compose project ${pub.project} in ${pub.workingDir} \u2014 typically another module's or tenant's database. Stop it there with docker compose down, or docker stop ${pub.name}.`,
|
|
@@ -5270,7 +5304,7 @@ async function startServices(deps2, r, slug, env, dbPort2, waitMs, signal, onLin
|
|
|
5270
5304
|
const res = await runTool(deps2, cmd, args, { cwd: r.root, env, onLine, signal });
|
|
5271
5305
|
if (res.code !== 0) {
|
|
5272
5306
|
if (dbPort2 !== null && /port is already allocated|address already in use/i.test(res.tail.join("\n"))) {
|
|
5273
|
-
throw await portInUseError(deps2, { slug, port: dbPort2, key: "DB_PORT" });
|
|
5307
|
+
throw await portInUseError(deps2, { slug, port: dbPort2, key: "DB_PORT", root: r.root, env });
|
|
5274
5308
|
}
|
|
5275
5309
|
throw await composeFailure(deps2, r, slug, env, signal, `${script} failed in ${slug}`, `${cmd} ${args.join(" ")}`, res.tail);
|
|
5276
5310
|
}
|
|
@@ -5444,11 +5478,11 @@ function hintContext(recipe, pkg, env) {
|
|
|
5444
5478
|
|
|
5445
5479
|
// src/core/dev/runFile.ts
|
|
5446
5480
|
import { readdir as readdir5, unlink as unlink2 } from "fs/promises";
|
|
5447
|
-
import { join as
|
|
5481
|
+
import { join as join26 } from "path";
|
|
5448
5482
|
async function runFilePath(deps2, root) {
|
|
5449
|
-
const dir2 =
|
|
5483
|
+
const dir2 = join26(deps2.config.dir, "run");
|
|
5450
5484
|
const name = `${await stateKey(deps2, root)}.json`;
|
|
5451
|
-
return { dir: dir2, name, path:
|
|
5485
|
+
return { dir: dir2, name, path: join26(dir2, name) };
|
|
5452
5486
|
}
|
|
5453
5487
|
async function writeRunFile(deps2, root, rec) {
|
|
5454
5488
|
const { dir: dir2, name } = await runFilePath(deps2, root);
|
|
@@ -5469,9 +5503,9 @@ async function leftoverRun(deps2, root, o = {}) {
|
|
|
5469
5503
|
return null;
|
|
5470
5504
|
}
|
|
5471
5505
|
async function listRunFiles(deps2) {
|
|
5472
|
-
const dir2 =
|
|
5506
|
+
const dir2 = join26(deps2.config.dir, "run");
|
|
5473
5507
|
const names = await readdir5(dir2).catch(() => []);
|
|
5474
|
-
const recs = await Promise.all(names.filter((n) => n.endsWith(".json")).map((n) => readJson(
|
|
5508
|
+
const recs = await Promise.all(names.filter((n) => n.endsWith(".json")).map((n) => readJson(join26(dir2, n)).catch(() => null)));
|
|
5475
5509
|
return recs.filter((r) => !!r && r.schemaVersion === 1 && Array.isArray(r.children));
|
|
5476
5510
|
}
|
|
5477
5511
|
|
|
@@ -5600,8 +5634,8 @@ async function inPreflight(signals, outer, fn) {
|
|
|
5600
5634
|
// src/cli/commands/devWorkspace.ts
|
|
5601
5635
|
import { randomBytes as randomBytes7 } from "crypto";
|
|
5602
5636
|
import { constants as constants4 } from "os";
|
|
5603
|
-
import { realpath as
|
|
5604
|
-
import { basename as basename7, join as
|
|
5637
|
+
import { realpath as realpath11 } from "fs/promises";
|
|
5638
|
+
import { basename as basename7, join as join28, relative as relative8 } from "path";
|
|
5605
5639
|
|
|
5606
5640
|
// src/core/dev/order.ts
|
|
5607
5641
|
function selectSkips(modules, sel) {
|
|
@@ -5922,7 +5956,7 @@ function supervise(o) {
|
|
|
5922
5956
|
|
|
5923
5957
|
// src/core/workspace/stray.ts
|
|
5924
5958
|
import { lstat as lstat4, readdir as readdir6 } from "fs/promises";
|
|
5925
|
-
import { join as
|
|
5959
|
+
import { join as join27 } from "path";
|
|
5926
5960
|
var VIEW_ENTRIES = /* @__PURE__ */ new Set(["qore.workspace.json", ".idea", ".claude", "CLAUDE.md", "README.md"]);
|
|
5927
5961
|
async function strayRepos(root, slugs, o = {}) {
|
|
5928
5962
|
let entries;
|
|
@@ -5936,8 +5970,8 @@ async function strayRepos(root, slugs, o = {}) {
|
|
|
5936
5970
|
if (slugs.has(name)) continue;
|
|
5937
5971
|
if (o.view && (VIEW_ENTRIES.has(name) || name.endsWith(".code-workspace"))) continue;
|
|
5938
5972
|
try {
|
|
5939
|
-
if ((await readEntry(
|
|
5940
|
-
await lstat4(
|
|
5973
|
+
if ((await readEntry(join27(root, name))).kind !== "dir") continue;
|
|
5974
|
+
await lstat4(join27(root, name, ".git"));
|
|
5941
5975
|
names.push(name);
|
|
5942
5976
|
} catch {
|
|
5943
5977
|
}
|
|
@@ -6141,7 +6175,7 @@ async function prepareWorkspace(ctx, ws, f, waitTimeout, p) {
|
|
|
6141
6175
|
let neutral;
|
|
6142
6176
|
const units = [];
|
|
6143
6177
|
for (const u of planned) {
|
|
6144
|
-
u.realDir = await
|
|
6178
|
+
u.realDir = await realpath11(u.dir).catch(() => u.dir);
|
|
6145
6179
|
const match = await findRunning(running, { moduleId: u.m.id, realDir: u.realDir, exceptPid: deps2.pid, exceptRoot: ws.root });
|
|
6146
6180
|
const port = match?.child.port ?? null;
|
|
6147
6181
|
if (!match) {
|
|
@@ -6255,7 +6289,7 @@ async function prepareWorkspace(ctx, ws, f, waitTimeout, p) {
|
|
|
6255
6289
|
workspace: ws,
|
|
6256
6290
|
module: { id: u.m.id, slug: u.m.slug, name: u.m.name, type: u.m.type, access: u.m.access, tenant: am.app.tenant, apps: [appRef] }
|
|
6257
6291
|
});
|
|
6258
|
-
const rootReal = await
|
|
6292
|
+
const rootReal = await realpath11(ws.root);
|
|
6259
6293
|
const withDocker = dockerRecovery(ctx, p.signal);
|
|
6260
6294
|
for (const u of units.filter((x) => x.recipe && x.trusted)) {
|
|
6261
6295
|
const slug = u.m.slug;
|
|
@@ -6281,7 +6315,7 @@ async function prepareWorkspace(ctx, ws, f, waitTimeout, p) {
|
|
|
6281
6315
|
warn(`${slug}: the portal is unreachable \u2014 starting from ${relative8(rootReal, dev.envFile)} as last written; values may be stale.`, { module: slug });
|
|
6282
6316
|
}
|
|
6283
6317
|
if (dev.ignored === false) {
|
|
6284
|
-
const repo = await
|
|
6318
|
+
const repo = await realpath11(u.dir);
|
|
6285
6319
|
warn(`${slug}: ${notIgnoredWarning(relative8(repo, dev.envFile), relative8(rootReal, repo))}`, { module: slug });
|
|
6286
6320
|
}
|
|
6287
6321
|
if (dev.kept.length) {
|
|
@@ -6337,7 +6371,7 @@ async function prepareWorkspace(ctx, ws, f, waitTimeout, p) {
|
|
|
6337
6371
|
if (online && units.every((u) => !u.dev.offline)) {
|
|
6338
6372
|
const envFile = (m) => {
|
|
6339
6373
|
const u = units.find((x) => x.m.id === m.id);
|
|
6340
|
-
return u ? relative8(rootReal, u.dev.envFile) :
|
|
6374
|
+
return u ? relative8(rootReal, u.dev.envFile) : join28(m.slug, moduleDefaults(m.type).envFile);
|
|
6341
6375
|
};
|
|
6342
6376
|
await saveLastStart(deps2, ws.root, {
|
|
6343
6377
|
schemaVersion: 1,
|
|
@@ -6622,7 +6656,7 @@ async function providerFindings(ctx, root, mc, app, env) {
|
|
|
6622
6656
|
let fix = `qore clone ${app.slug}`;
|
|
6623
6657
|
if (ws && ws.appId === app.id) fix = cdAndDev(deps2.home, ws.root);
|
|
6624
6658
|
else if (providers.length === 1) {
|
|
6625
|
-
const sibling =
|
|
6659
|
+
const sibling = join29(dirname10(root), providers[0].slug);
|
|
6626
6660
|
if ((await deps2.git.inspect(sibling)).isRepo) fix = cdAndDev(deps2.home, sibling);
|
|
6627
6661
|
}
|
|
6628
6662
|
return providerDown({
|
|
@@ -6758,7 +6792,7 @@ async function prepareModule(ctx, f, waitTimeout, p) {
|
|
|
6758
6792
|
if (c.offlineCause && isOffline(e)) throw c.offlineCause;
|
|
6759
6793
|
throw e;
|
|
6760
6794
|
}
|
|
6761
|
-
const envFile = relative9(await
|
|
6795
|
+
const envFile = relative9(await realpath12(root), dev.envFile);
|
|
6762
6796
|
if (dev.offline) io2.err(`! The portal is unreachable \u2014 starting from ${envFile} as last written; values may be stale.`);
|
|
6763
6797
|
if (dev.ignored === false) io2.err(`! ${notIgnoredWarning(envFile)}`);
|
|
6764
6798
|
if (dev.kept.length) {
|
|
@@ -6819,7 +6853,7 @@ function registerDebugTelemetry(program, ctx) {
|
|
|
6819
6853
|
import pc3 from "picocolors";
|
|
6820
6854
|
|
|
6821
6855
|
// src/core/doctor/checks.ts
|
|
6822
|
-
import { realpath as
|
|
6856
|
+
import { realpath as realpath13, stat as stat6 } from "fs/promises";
|
|
6823
6857
|
import { basename as basename8 } from "path";
|
|
6824
6858
|
|
|
6825
6859
|
// src/core/diagnostics/ssh.ts
|
|
@@ -6998,11 +7032,12 @@ function checkClock(meta) {
|
|
|
6998
7032
|
function ownerText(e) {
|
|
6999
7033
|
const d = e.details ?? {};
|
|
7000
7034
|
if (d.owner === "process") return ` by ${String(d.command)} (pid ${String(d.pid)})`;
|
|
7035
|
+
if (d.owner === "docker" && d.sameModule) return ` by another checkout of ${String(d.module)} (${String(d.workingDir)})`;
|
|
7001
7036
|
if (d.owner === "docker") return ` by the Docker container ${String(d.name)}`;
|
|
7002
7037
|
if (d.owner === "qore") return ` by a previous qore dev (pid ${String(d.pid)})`;
|
|
7003
7038
|
return "";
|
|
7004
7039
|
}
|
|
7005
|
-
var sameDir = async (a, b) => await
|
|
7040
|
+
var sameDir = async (a, b) => await realpath13(a).catch(() => a) === await realpath13(b).catch(() => b);
|
|
7006
7041
|
async function moduleBody(deps2, m, runs, signal) {
|
|
7007
7042
|
const parts = [];
|
|
7008
7043
|
const part = async (fn) => {
|
|
@@ -7045,7 +7080,7 @@ async function moduleBody(deps2, m, runs, signal) {
|
|
|
7045
7080
|
if (!await deps2.ports.inUse(dbPort2)) return { status: "ok", label: `db:up (DB_PORT ${dbPort2} free)` };
|
|
7046
7081
|
const pub = await deps2.ports.dockerPublisher(dbPort2);
|
|
7047
7082
|
if (pub?.workingDir && await sameDir(pub.workingDir, m.root)) return { status: "ok", label: "db running" };
|
|
7048
|
-
const e = await portInUseError(deps2, { slug: m.slug, port: dbPort2, key: "DB_PORT" });
|
|
7083
|
+
const e = await portInUseError(deps2, { slug: m.slug, port: dbPort2, key: "DB_PORT", root: m.root, env: env ?? void 0 });
|
|
7049
7084
|
return { status: "fail", label: `DB_PORT ${dbPort2} in use${ownerText(e)}`, error: e };
|
|
7050
7085
|
});
|
|
7051
7086
|
const status2 = parts.reduce((w, p) => RANK[p.status] > RANK[w] ? p.status : w, "ok");
|
|
@@ -7291,8 +7326,50 @@ function registerDoctor(program, ctx) {
|
|
|
7291
7326
|
|
|
7292
7327
|
// src/cli/commands/env.ts
|
|
7293
7328
|
import { randomBytes as randomBytes9 } from "crypto";
|
|
7294
|
-
import { chmod as
|
|
7295
|
-
import { dirname as dirname11, join as
|
|
7329
|
+
import { chmod as chmod4, realpath as realpath14 } from "fs/promises";
|
|
7330
|
+
import { dirname as dirname11, join as join31, relative as relative10 } from "path";
|
|
7331
|
+
|
|
7332
|
+
// src/core/env/mobile.ts
|
|
7333
|
+
import { chmod as chmod3, stat as stat7 } from "fs/promises";
|
|
7334
|
+
import { join as join30 } from "path";
|
|
7335
|
+
var MOBILE_ENV_FILE = "mobile/.env.local";
|
|
7336
|
+
var MOBILE_KEYS = ["EXPO_PUBLIC_SERVER_URL", "EXPO_PUBLIC_SENTRY_DSN", "EXPO_PUBLIC_QORE_ENV"];
|
|
7337
|
+
async function hasMobileApp(repoRoot) {
|
|
7338
|
+
try {
|
|
7339
|
+
return (await stat7(join30(repoRoot, "mobile"))).isDirectory();
|
|
7340
|
+
} catch {
|
|
7341
|
+
return false;
|
|
7342
|
+
}
|
|
7343
|
+
}
|
|
7344
|
+
async function fetchMobileConfig(deps2, mc, app) {
|
|
7345
|
+
if (!await hasCapability(deps2, mc.portal.apiOrigin, "module.mobile-config")) return null;
|
|
7346
|
+
return mc.session.api.get(
|
|
7347
|
+
`/api/cli/v1/modules/${encodeURIComponent(mc.module.id)}/mobile-config?app_id=${encodeURIComponent(app.id)}`
|
|
7348
|
+
);
|
|
7349
|
+
}
|
|
7350
|
+
function mobileEnvValues(config) {
|
|
7351
|
+
const values = {};
|
|
7352
|
+
if (config.serverUrl) values.EXPO_PUBLIC_SERVER_URL = config.serverUrl;
|
|
7353
|
+
if (config.sentryDsn) values.EXPO_PUBLIC_SENTRY_DSN = config.sentryDsn;
|
|
7354
|
+
values.EXPO_PUBLIC_QORE_ENV = config.environment;
|
|
7355
|
+
return values;
|
|
7356
|
+
}
|
|
7357
|
+
function planMobileEnv(existing, config) {
|
|
7358
|
+
const original = existing ?? "";
|
|
7359
|
+
const { merged } = planEnvUpdate({ current: parseEnv(original), fetched: mobileEnvValues(config), managed: [...MOBILE_KEYS] });
|
|
7360
|
+
const text2 = renderEnv(original, merged);
|
|
7361
|
+
return { text: text2, changed: existing === null || text2 !== existing };
|
|
7362
|
+
}
|
|
7363
|
+
async function writeMobileEnv(repoRoot, config) {
|
|
7364
|
+
const target = await resolveTarget(repoRoot, MOBILE_ENV_FILE);
|
|
7365
|
+
const existing = await readOrNull(target);
|
|
7366
|
+
const plan = planMobileEnv(existing, config);
|
|
7367
|
+
if (plan.changed) await writeSecurely(target, plan.text);
|
|
7368
|
+
else await chmod3(target, 384);
|
|
7369
|
+
return { target, written: plan.changed };
|
|
7370
|
+
}
|
|
7371
|
+
|
|
7372
|
+
// src/cli/commands/env.ts
|
|
7296
7373
|
var maskLen = (v) => v === void 0 ? "(unset)" : `\u2022\u2022\u2022\u2022 (${v.length} chars)`;
|
|
7297
7374
|
function registerEnv(program, ctx) {
|
|
7298
7375
|
const env = program.command("env").description("Local environment");
|
|
@@ -7311,7 +7388,7 @@ function registerEnv(program, ctx) {
|
|
|
7311
7388
|
const target = f.target ? await resolveTarget(mc.repoRoot, f.target, deps2.cwd) : await resolveTarget(mc.repoRoot, cfg.envFile ?? defaults.envFile);
|
|
7312
7389
|
await ensureTrusted(c, mc, app, { yes: f.yes });
|
|
7313
7390
|
const existing = await readOrNull(target);
|
|
7314
|
-
const example = existing === null ? await readOrNull(
|
|
7391
|
+
const example = existing === null ? await readOrNull(join31(dirname11(target), ".env.example")) : null;
|
|
7315
7392
|
const local = await fetchLocalEnv(deps2, mc, app);
|
|
7316
7393
|
const inputs = {
|
|
7317
7394
|
existing,
|
|
@@ -7348,11 +7425,12 @@ function registerEnv(program, ctx) {
|
|
|
7348
7425
|
plan = planPull({ ...inputs, choices });
|
|
7349
7426
|
}
|
|
7350
7427
|
if (existing !== null && plan.text === existing) {
|
|
7351
|
-
await
|
|
7428
|
+
await chmod4(target, 384);
|
|
7352
7429
|
} else {
|
|
7353
7430
|
await writeSecurely(target, plan.text);
|
|
7354
7431
|
}
|
|
7355
|
-
const rel = relative10(await
|
|
7432
|
+
const rel = relative10(await realpath14(mc.repoRoot), target);
|
|
7433
|
+
const mobile = await pullMobile(c, mc, app);
|
|
7356
7434
|
if (g.json) {
|
|
7357
7435
|
const names = {
|
|
7358
7436
|
created: plan.created,
|
|
@@ -7364,7 +7442,7 @@ function registerEnv(program, ctx) {
|
|
|
7364
7442
|
unchanged: plan.unchanged,
|
|
7365
7443
|
generated: plan.generated
|
|
7366
7444
|
};
|
|
7367
|
-
renderJson(io2, { context: contextJson(mc, app), target: rel, ...names });
|
|
7445
|
+
renderJson(io2, { context: contextJson(mc, app), target: rel, ...names, mobile: mobile && mobileJson(mobile) });
|
|
7368
7446
|
return;
|
|
7369
7447
|
}
|
|
7370
7448
|
if (await isGitIgnored(deps2.git, mc.repoRoot, target) === false) io2.err(`! ${notIgnoredWarning(rel)}`);
|
|
@@ -7379,8 +7457,48 @@ function registerEnv(program, ctx) {
|
|
|
7379
7457
|
plan.generated.length && `${plan.generated.length} generated`
|
|
7380
7458
|
].filter(Boolean);
|
|
7381
7459
|
io2.out(`\u2713 ${rel}${plan.seededFromExample ? " (created from .env.example)" : ""} \u2014 ${parts.length ? parts.join(", ") : "up to date"}`);
|
|
7460
|
+
if (mobile) await reportMobile(c, mc.repoRoot, mobile);
|
|
7382
7461
|
});
|
|
7383
7462
|
}
|
|
7463
|
+
async function pullMobile(c, mc, app) {
|
|
7464
|
+
if (!mc.repoRoot || !await hasMobileApp(mc.repoRoot)) return null;
|
|
7465
|
+
try {
|
|
7466
|
+
const config = await fetchMobileConfig(c.deps, mc, app);
|
|
7467
|
+
if (!config) return { kind: "unsupported" };
|
|
7468
|
+
return { kind: "written", config, ...await writeMobileEnv(mc.repoRoot, config) };
|
|
7469
|
+
} catch (e) {
|
|
7470
|
+
if (e instanceof QoreError) return { kind: "failed", error: e };
|
|
7471
|
+
throw e;
|
|
7472
|
+
}
|
|
7473
|
+
}
|
|
7474
|
+
function mobileJson(m) {
|
|
7475
|
+
if (m.kind === "unsupported") return { target: MOBILE_ENV_FILE, skipped: "unsupported-portal" };
|
|
7476
|
+
if (m.kind === "failed") return { target: MOBILE_ENV_FILE, error: { code: m.error.code, message: m.error.message } };
|
|
7477
|
+
return {
|
|
7478
|
+
target: MOBILE_ENV_FILE,
|
|
7479
|
+
environment: m.config.environment,
|
|
7480
|
+
serverUrl: m.config.serverUrl,
|
|
7481
|
+
sentryDsn: m.config.sentryDsn !== null,
|
|
7482
|
+
written: m.written
|
|
7483
|
+
};
|
|
7484
|
+
}
|
|
7485
|
+
async function reportMobile(c, repoRoot, m) {
|
|
7486
|
+
const { io: io2, deps: deps2 } = c;
|
|
7487
|
+
if (m.kind === "unsupported") {
|
|
7488
|
+
io2.err(`! ${MOBILE_ENV_FILE}: skipped \u2014 this portal cannot serve the mobile app's config yet`);
|
|
7489
|
+
return;
|
|
7490
|
+
}
|
|
7491
|
+
if (m.kind === "failed") {
|
|
7492
|
+
io2.err(`! ${MOBILE_ENV_FILE}: not updated \u2014 ${m.error.message}`);
|
|
7493
|
+
return;
|
|
7494
|
+
}
|
|
7495
|
+
if (await isGitIgnored(deps2.git, repoRoot, m.target) === false) io2.err(`! ${notIgnoredWarning(MOBILE_ENV_FILE)}`);
|
|
7496
|
+
if (m.config.serverUrl === null) {
|
|
7497
|
+
io2.err(`! ${MOBILE_ENV_FILE}: ${m.config.environment} has no server URL yet \u2014 deploy ${m.config.environment}, then run qore env pull again`);
|
|
7498
|
+
}
|
|
7499
|
+
const server = m.config.serverUrl ? `server ${m.config.serverUrl}` : "no server URL";
|
|
7500
|
+
io2.out(`\u2713 ${MOBILE_ENV_FILE} \u2014 ${server} (${m.config.environment})${m.written ? "" : ", up to date"}`);
|
|
7501
|
+
}
|
|
7384
7502
|
|
|
7385
7503
|
// src/core/observability/compose.ts
|
|
7386
7504
|
function pageWarnings(...pages) {
|
|
@@ -7859,7 +7977,7 @@ function registerErrors(program, ctx) {
|
|
|
7859
7977
|
}
|
|
7860
7978
|
|
|
7861
7979
|
// src/cli/commands/init.ts
|
|
7862
|
-
import { realpath as
|
|
7980
|
+
import { realpath as realpath15 } from "fs/promises";
|
|
7863
7981
|
|
|
7864
7982
|
// src/core/auth/oidc.ts
|
|
7865
7983
|
import * as oc from "openid-client";
|
|
@@ -8103,6 +8221,11 @@ async function useTenant(ctx, slug, known) {
|
|
|
8103
8221
|
const portal = resolvePortal(g.portal, cfg.defaultProfile);
|
|
8104
8222
|
const me = known ?? await (await openSession(deps2, portal, "tenant use", requestLog(ctx))).api.get("/api/cli/v1/me");
|
|
8105
8223
|
const candidates = me.tenants.map((t) => ({ kind: "tenant", id: t.id, slug: t.slug, name: t.name }));
|
|
8224
|
+
if (me.tenants.length === 0) {
|
|
8225
|
+
throw new QoreError("QORE_NO_DEVELOPER_ACCESS", "Your account is not a developer in any organisation", {
|
|
8226
|
+
hint: "Ask an admin to invite you as a developer."
|
|
8227
|
+
});
|
|
8228
|
+
}
|
|
8106
8229
|
let chosen;
|
|
8107
8230
|
if (slug) {
|
|
8108
8231
|
const found = me.tenants.find((t) => t.slug === slug);
|
|
@@ -8133,7 +8256,7 @@ async function rootStep(ctx, f) {
|
|
|
8133
8256
|
input2 = await io2.input("Projects folder", { default: current ?? "~/qore" }) || current || "~/qore";
|
|
8134
8257
|
}
|
|
8135
8258
|
const wanted = await checkRoot(deps2, input2);
|
|
8136
|
-
const asked = await
|
|
8259
|
+
const asked = await realpath15(wanted).catch(() => wanted);
|
|
8137
8260
|
if (current && asked !== current && io2.interactive && !await io2.confirm(`Change the projects folder from ${current} to ${asked}? Nothing is moved.`, ctx.signal)) {
|
|
8138
8261
|
return step("skipped", current);
|
|
8139
8262
|
}
|
|
@@ -8317,7 +8440,7 @@ function registerPortal(program, ctx) {
|
|
|
8317
8440
|
}
|
|
8318
8441
|
|
|
8319
8442
|
// src/core/roles/read.ts
|
|
8320
|
-
import { join as
|
|
8443
|
+
import { join as join32 } from "path";
|
|
8321
8444
|
|
|
8322
8445
|
// src/core/roles/extract.ts
|
|
8323
8446
|
var KNOWN = { user: "User", admin: "App admin" };
|
|
@@ -8348,11 +8471,11 @@ async function extractRoles(source) {
|
|
|
8348
8471
|
|
|
8349
8472
|
// src/core/roles/read.ts
|
|
8350
8473
|
var PERMISSIONS_FILE = "src/lib/permissions.ts";
|
|
8351
|
-
var SLUG = /^[
|
|
8474
|
+
var SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
8352
8475
|
var MAX_SLUG = 64;
|
|
8353
8476
|
var MAX_ROLES = 100;
|
|
8354
8477
|
async function readCodeRoles(repoRoot) {
|
|
8355
|
-
const source = await readOrNull(
|
|
8478
|
+
const source = await readOrNull(join32(repoRoot, PERMISSIONS_FILE));
|
|
8356
8479
|
if (source === null) {
|
|
8357
8480
|
throw new QoreError("QORE_CONTEXT_UNSUPPORTED", `No ${PERMISSIONS_FILE} in this module`, {
|
|
8358
8481
|
hint: "App roles live in the app's frontend module; run this there."
|
|
@@ -8367,7 +8490,7 @@ async function readCodeRoles(repoRoot) {
|
|
|
8367
8490
|
const invalid4 = roles.filter((r) => !SLUG.test(r.slug) || r.slug.length > MAX_SLUG).map((r) => r.slug);
|
|
8368
8491
|
if (invalid4.length) {
|
|
8369
8492
|
throw new QoreError("QORE_CONTEXT_INVALID", `The portal refuses these role names: ${invalid4.join(", ")}`, {
|
|
8370
|
-
hint: `Use
|
|
8493
|
+
hint: `Use letters, digits, - and _, starting with a letter or digit, at most ${MAX_SLUG} characters.`,
|
|
8371
8494
|
details: { invalid: invalid4 }
|
|
8372
8495
|
});
|
|
8373
8496
|
}
|
|
@@ -8543,8 +8666,8 @@ function registerStatus(program, ctx) {
|
|
|
8543
8666
|
}
|
|
8544
8667
|
|
|
8545
8668
|
// src/cli/commands/sync.ts
|
|
8546
|
-
import { realpath as
|
|
8547
|
-
import { basename as basename9, join as
|
|
8669
|
+
import { realpath as realpath16 } from "fs/promises";
|
|
8670
|
+
import { basename as basename9, join as join33, relative as relative11 } from "path";
|
|
8548
8671
|
import { Option as Option3 } from "commander";
|
|
8549
8672
|
function asFailure2(slug, e) {
|
|
8550
8673
|
if (e instanceof QoreError && e.code !== "QORE_GIT_UNAVAILABLE") {
|
|
@@ -8564,7 +8687,7 @@ async function syncInPlace(deps2, o) {
|
|
|
8564
8687
|
continue;
|
|
8565
8688
|
}
|
|
8566
8689
|
try {
|
|
8567
|
-
dirs[m.slug] = await deps2.git.inspect(
|
|
8690
|
+
dirs[m.slug] = await deps2.git.inspect(join33(root, m.slug));
|
|
8568
8691
|
modulesForPlan.push(m);
|
|
8569
8692
|
} catch (e) {
|
|
8570
8693
|
earlyFailures.push(asFailure2(m.slug, e));
|
|
@@ -8596,7 +8719,7 @@ async function syncTenant(ctx, o) {
|
|
|
8596
8719
|
const { deps: deps2, io: io2 } = ctx;
|
|
8597
8720
|
const { layout, app } = o;
|
|
8598
8721
|
const label3 = (root) => relative11(layout.tenantDir, root) || basename9(root);
|
|
8599
|
-
const own = await
|
|
8722
|
+
const own = await realpath16(o.wsRoot).catch(() => o.wsRoot);
|
|
8600
8723
|
const apps = [{ appSlug: app.app.slug, root: own, kind: o.kind, modules: app.modules }];
|
|
8601
8724
|
const views = [{ appSlug: app.app.slug, name: app.app.name, appId: app.app.id, modules: app.modules }];
|
|
8602
8725
|
const leftAlone = [];
|
|
@@ -9010,7 +9133,7 @@ async function maybeNotifyUpdate(deps2, io2, o, timeoutMs = DEFAULT_TIMEOUT_MS)
|
|
|
9010
9133
|
|
|
9011
9134
|
// src/core/config.ts
|
|
9012
9135
|
import { readFile as readFile8 } from "fs/promises";
|
|
9013
|
-
import { join as
|
|
9136
|
+
import { join as join34 } from "path";
|
|
9014
9137
|
var empty = () => ({ schemaVersion: 1, profiles: {} });
|
|
9015
9138
|
var ConfigStore = class {
|
|
9016
9139
|
constructor(dir2) {
|
|
@@ -9018,7 +9141,7 @@ var ConfigStore = class {
|
|
|
9018
9141
|
}
|
|
9019
9142
|
dir;
|
|
9020
9143
|
get file() {
|
|
9021
|
-
return
|
|
9144
|
+
return join34(this.dir, "config.json");
|
|
9022
9145
|
}
|
|
9023
9146
|
async read() {
|
|
9024
9147
|
let raw;
|
|
@@ -9049,9 +9172,9 @@ var ConfigStore = class {
|
|
|
9049
9172
|
|
|
9050
9173
|
// src/platform/git.ts
|
|
9051
9174
|
import { execFile, execFileSync } from "child_process";
|
|
9052
|
-
import { mkdir as mkdir6, readdir as readdir7, stat as
|
|
9175
|
+
import { mkdir as mkdir6, readdir as readdir7, stat as stat8 } from "fs/promises";
|
|
9053
9176
|
import { homedir } from "os";
|
|
9054
|
-
import { dirname as dirname12, join as
|
|
9177
|
+
import { dirname as dirname12, join as join35 } from "path";
|
|
9055
9178
|
function parseRemotes(stdout) {
|
|
9056
9179
|
const seen = /* @__PURE__ */ new Set();
|
|
9057
9180
|
const out = [];
|
|
@@ -9192,7 +9315,7 @@ async function stashCount(repoRoot) {
|
|
|
9192
9315
|
}
|
|
9193
9316
|
async function statOrThrow(path2) {
|
|
9194
9317
|
try {
|
|
9195
|
-
return await
|
|
9318
|
+
return await stat8(path2);
|
|
9196
9319
|
} catch (err) {
|
|
9197
9320
|
if (err.code === "ENOENT") return void 0;
|
|
9198
9321
|
throw new QoreError("QORE_INTERNAL", `could not stat ${path2}`, { cause: err });
|
|
@@ -9209,7 +9332,7 @@ async function inspect(dir2) {
|
|
|
9209
9332
|
throw new QoreError("QORE_INTERNAL", `could not read ${dir2}`, { cause: err });
|
|
9210
9333
|
}
|
|
9211
9334
|
const empty2 = entries.length === 0;
|
|
9212
|
-
const isRepo = await statOrThrow(
|
|
9335
|
+
const isRepo = await statOrThrow(join35(dir2, ".git")) !== void 0;
|
|
9213
9336
|
const dirRemotes = isRepo ? await remotes(dir2) : [];
|
|
9214
9337
|
return { exists: true, empty: empty2, isRepo, remotes: dirRemotes };
|
|
9215
9338
|
}
|
|
@@ -9342,13 +9465,13 @@ var OsKeychain = class extends ChunkedKeychain {
|
|
|
9342
9465
|
|
|
9343
9466
|
// src/platform/lock.ts
|
|
9344
9467
|
import { mkdir as mkdir7, writeFile as writeFile7 } from "fs/promises";
|
|
9345
|
-
import { join as
|
|
9468
|
+
import { join as join36 } from "path";
|
|
9346
9469
|
import lockfile from "proper-lockfile";
|
|
9347
9470
|
function fileLock(dir2) {
|
|
9348
9471
|
return async (name, fn) => {
|
|
9349
|
-
const locks =
|
|
9472
|
+
const locks = join36(dir2, "locks");
|
|
9350
9473
|
await mkdir7(locks, { recursive: true, mode: 448 });
|
|
9351
|
-
const target =
|
|
9474
|
+
const target = join36(locks, `${name}.lock`);
|
|
9352
9475
|
await writeFile7(target, "", { flag: "a" });
|
|
9353
9476
|
let release;
|
|
9354
9477
|
let compromised;
|
|
@@ -9801,4 +9924,4 @@ if (!drained) {
|
|
|
9801
9924
|
process.exit();
|
|
9802
9925
|
}
|
|
9803
9926
|
//# sourceMappingURL=cli.js.map
|
|
9804
|
-
//# debugId=
|
|
9927
|
+
//# debugId=fdf8ddca-c1bb-5549-9d3b-a2a664c8a79c
|