livelocale 0.10.0 → 0.10.1
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 +30 -26
- package/dist/codemod/index.cjs +178 -48
- package/dist/codemod/index.cjs.map +1 -1
- package/dist/codemod/index.js +178 -48
- package/dist/codemod/index.js.map +1 -1
- package/dist/server/index.cjs +1 -1
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/studio/assets/index-BK-MBY6M.js +14 -0
- package/dist/studio/assets/index-GgcTqdBQ.css +1 -0
- package/dist/studio/index.html +2 -2
- package/dist/vite/index.cjs +9 -3
- package/dist/vite/index.cjs.map +1 -1
- package/dist/vite/index.js +9 -3
- package/dist/vite/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/studio/assets/index-FFC_lDHv.css +0 -1
- package/dist/studio/assets/index-yI6iF4xN.js +0 -14
package/dist/codemod/index.js
CHANGED
|
@@ -412,7 +412,7 @@ import * as path3 from "path";
|
|
|
412
412
|
|
|
413
413
|
// src/core/validate.ts
|
|
414
414
|
var LOCALE_RE = /^[a-zA-Z]{2,3}(-[a-zA-Z0-9]{2,4})?$/;
|
|
415
|
-
var KEY_RE = /^[
|
|
415
|
+
var KEY_RE = /^[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*$/;
|
|
416
416
|
var MAX_LOCALE_LENGTH = 10;
|
|
417
417
|
var MAX_KEY_LENGTH = 200;
|
|
418
418
|
var MAX_VALUE_LENGTH = 1e4;
|
|
@@ -1309,12 +1309,12 @@ function checkShareCsp(pages, origin) {
|
|
|
1309
1309
|
return { level: "ok", title, detail: "scripts from 'self' are allowed" };
|
|
1310
1310
|
}
|
|
1311
1311
|
function workerCandidates(root, base) {
|
|
1312
|
-
const
|
|
1312
|
+
const urls2 = [];
|
|
1313
1313
|
if (isAnswer(root)) {
|
|
1314
1314
|
const registered = /serviceWorker\s*\.\s*register\s*\(\s*["'`]([^"'`]+)["'`]/.exec(root.body);
|
|
1315
1315
|
if (registered) {
|
|
1316
1316
|
try {
|
|
1317
|
-
|
|
1317
|
+
urls2.push(new URL(registered[1], base).href);
|
|
1318
1318
|
} catch {
|
|
1319
1319
|
}
|
|
1320
1320
|
}
|
|
@@ -1324,9 +1324,9 @@ function workerCandidates(root, base) {
|
|
|
1324
1324
|
...names.map((name) => new URL(name, base).href),
|
|
1325
1325
|
...names.map((name) => new URL(`/${name}`, base).href)
|
|
1326
1326
|
]) {
|
|
1327
|
-
if (!
|
|
1327
|
+
if (!urls2.includes(url)) urls2.push(url);
|
|
1328
1328
|
}
|
|
1329
|
-
return
|
|
1329
|
+
return urls2;
|
|
1330
1330
|
}
|
|
1331
1331
|
async function checkServiceWorker(fetchImpl, root, base, origin) {
|
|
1332
1332
|
const title = "Service worker";
|
|
@@ -2530,6 +2530,10 @@ var EXISTING_FLAG_TAG = /<script\b[^>]*\bsrc="[^"]*livelocale\/flag\.js"[^>]*>\s
|
|
|
2530
2530
|
var HEAD_OPEN2 = /<head(?=[\s>])[^>]*>/i;
|
|
2531
2531
|
var HTML_OPEN2 = /<html(?=[\s>])[^>]*>/i;
|
|
2532
2532
|
var DOCTYPE2 = /<!doctype\b[^>]*>/i;
|
|
2533
|
+
var DOCUMENT_MARKUP = /<(?:!doctype\b|html(?=[\s>])|head(?=[\s>]))/i;
|
|
2534
|
+
function isHtmlDocument(html) {
|
|
2535
|
+
return DOCUMENT_MARKUP.test(html);
|
|
2536
|
+
}
|
|
2533
2537
|
function escapeAttribute(value) {
|
|
2534
2538
|
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
2535
2539
|
}
|
|
@@ -2768,10 +2772,12 @@ async function packOutput(options) {
|
|
|
2768
2772
|
}
|
|
2769
2773
|
await fs5.writeFile(path8.join(shareDir, SHARE_FLAG_FILE), FLAG_SCRIPT, "utf-8");
|
|
2770
2774
|
const inject = injectHtml === "auto" ? target.kind !== "next" && !existsSync5(path8.join(outDir, "_next")) : injectHtml;
|
|
2771
|
-
const htmlInjected =
|
|
2772
|
-
for (const rel of
|
|
2775
|
+
const htmlInjected = [];
|
|
2776
|
+
for (const rel of inject ? await findHtmlFiles(outDir, shareDir) : []) {
|
|
2773
2777
|
const file = path8.join(outDir, ...rel.split("/"));
|
|
2774
2778
|
const html = await fs5.readFile(file, "utf-8");
|
|
2779
|
+
if (!isHtmlDocument(html)) continue;
|
|
2780
|
+
htmlInjected.push(rel);
|
|
2775
2781
|
const injected = injectFlagScript(html, flagSrcFor(base, rel));
|
|
2776
2782
|
if (injected !== html) await fs5.writeFile(file, injected, "utf-8");
|
|
2777
2783
|
}
|
|
@@ -2832,6 +2838,55 @@ function parseShareArgs(argv) {
|
|
|
2832
2838
|
}
|
|
2833
2839
|
return args;
|
|
2834
2840
|
}
|
|
2841
|
+
var PACK_USAGE = "Usage: livelocale pack <outDir> [options]";
|
|
2842
|
+
var BUILD_USAGE = "Usage: livelocale build [--preview] -- <your build command>";
|
|
2843
|
+
function usageError(problem, usage) {
|
|
2844
|
+
return new PackError("USAGE", `${problem}
|
|
2845
|
+
${usage}`);
|
|
2846
|
+
}
|
|
2847
|
+
function checkPackArgs(args) {
|
|
2848
|
+
if (args.positional.length === 0) {
|
|
2849
|
+
throw usageError("Missing <outDir>: pass the built site folder, for example dist.", PACK_USAGE);
|
|
2850
|
+
}
|
|
2851
|
+
if (args.positional.length > 1) {
|
|
2852
|
+
throw usageError(
|
|
2853
|
+
`Unexpected argument "${args.positional[1]}": pack takes one <outDir>.`,
|
|
2854
|
+
PACK_USAGE
|
|
2855
|
+
);
|
|
2856
|
+
}
|
|
2857
|
+
if (args.out !== void 0) {
|
|
2858
|
+
throw usageError(
|
|
2859
|
+
"--out is not a pack option: pass the built site folder as <outDir>.",
|
|
2860
|
+
PACK_USAGE
|
|
2861
|
+
);
|
|
2862
|
+
}
|
|
2863
|
+
if (args.preview) {
|
|
2864
|
+
throw usageError(
|
|
2865
|
+
"--preview is not a pack option: use livelocale build --preview -- <your build command>.",
|
|
2866
|
+
PACK_USAGE
|
|
2867
|
+
);
|
|
2868
|
+
}
|
|
2869
|
+
if (args.command.length > 0) {
|
|
2870
|
+
throw usageError(
|
|
2871
|
+
"pack does not run a build command: use livelocale build -- <your build command>.",
|
|
2872
|
+
PACK_USAGE
|
|
2873
|
+
);
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
function checkBuildArgs(args) {
|
|
2877
|
+
if (args.positional.length > 0) {
|
|
2878
|
+
throw usageError(
|
|
2879
|
+
`Unexpected argument "${args.positional[0]}": put the build command after --.`,
|
|
2880
|
+
BUILD_USAGE
|
|
2881
|
+
);
|
|
2882
|
+
}
|
|
2883
|
+
if (!args.inject) {
|
|
2884
|
+
throw usageError(
|
|
2885
|
+
"--no-inject is not a build option: livelocale build links flag.js itself (never on Next.js).",
|
|
2886
|
+
BUILD_USAGE
|
|
2887
|
+
);
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2835
2890
|
var WINDOWS_NEEDS_QUOTES = /[\s"&|<>^()]/;
|
|
2836
2891
|
function quoteWindowsArg(arg) {
|
|
2837
2892
|
if (arg !== "" && !WINDOWS_NEEDS_QUOTES.test(arg)) return arg;
|
|
@@ -2864,7 +2919,6 @@ var spawnInherit = (command, args, { cwd, env }) => new Promise((resolve16, reje
|
|
|
2864
2919
|
});
|
|
2865
2920
|
child.on("close", (code) => resolve16(code ?? 1));
|
|
2866
2921
|
});
|
|
2867
|
-
var BUILD_USAGE = "Usage: livelocale build [--preview] -- <your build command>";
|
|
2868
2922
|
var NEXT_PREVIEW_WARNING = "Next.js pages have no watermarks without --preview; the Studio will open but nothing is editable.";
|
|
2869
2923
|
var NEXT_GITIGNORE_WARNING = "Add public/livelocale/ to .gitignore; it is generated on every build.";
|
|
2870
2924
|
var FRESH_SLACK_MS = 2e3;
|
|
@@ -2903,6 +2957,12 @@ async function runBuildCommand(options) {
|
|
|
2903
2957
|
const childEnv = preview ? { ...env, LIVELOCALE: "preview", NEXT_PUBLIC_LIVELOCALE: "preview" } : env;
|
|
2904
2958
|
const runBuild = () => run3(command[0], command.slice(1), { cwd: projectDir, env: childEnv });
|
|
2905
2959
|
if (target.kind === "next") {
|
|
2960
|
+
if (outDir !== void 0) {
|
|
2961
|
+
throw new PackError(
|
|
2962
|
+
"USAGE",
|
|
2963
|
+
"--out is not used for Next.js; the share folder goes to public/"
|
|
2964
|
+
);
|
|
2965
|
+
}
|
|
2906
2966
|
const blocking = target.staticExport ? findExportBlockingRoute(projectDir) : null;
|
|
2907
2967
|
if (blocking !== null) {
|
|
2908
2968
|
throw new PackError(
|
|
@@ -3112,6 +3172,13 @@ var URL_PATTERN = /\b(?:https?:\/\/|www\.)[^\s<>"')]+/gi;
|
|
|
3112
3172
|
var BIDI_CONTROL_PATTERN = /[\u202A-\u202E\u2066-\u2069]/g;
|
|
3113
3173
|
var tagNames = (text) => Array.from(text.matchAll(TAG_PATTERN), (m) => m[1].toLowerCase());
|
|
3114
3174
|
var allMatches = (pattern, text) => text.match(pattern) ?? [];
|
|
3175
|
+
var URL_PARTS_PATTERN = /^((?:https?:\/\/|www\.)[^/?#]*)(.*)$/i;
|
|
3176
|
+
var normalizeUrl = (url) => {
|
|
3177
|
+
const trimmed = url.replace(/[.,;:!?]+$/, "");
|
|
3178
|
+
const parts = URL_PARTS_PATTERN.exec(trimmed);
|
|
3179
|
+
return parts ? parts[1].toLowerCase() + parts[2] : trimmed;
|
|
3180
|
+
};
|
|
3181
|
+
var urls = (text) => allMatches(URL_PATTERN, text).map(normalizeUrl);
|
|
3115
3182
|
var hasNew = (known, found) => {
|
|
3116
3183
|
const set = new Set(known);
|
|
3117
3184
|
return found.some((item) => !set.has(item));
|
|
@@ -3123,7 +3190,7 @@ function detectRiskFlags(reference, value) {
|
|
|
3123
3190
|
if (SCRIPT_LINK_PATTERNS.some((pattern) => pattern.test(value) && !pattern.test(ref))) {
|
|
3124
3191
|
flags.push("javascript-url");
|
|
3125
3192
|
}
|
|
3126
|
-
if (hasNew(
|
|
3193
|
+
if (hasNew(urls(ref), urls(value))) flags.push("new-url");
|
|
3127
3194
|
if (hasNew(allMatches(BIDI_CONTROL_PATTERN, ref), allMatches(BIDI_CONTROL_PATTERN, value))) {
|
|
3128
3195
|
flags.push("bidi-control");
|
|
3129
3196
|
}
|
|
@@ -3482,13 +3549,39 @@ function buildFileChanges(localesDir, plan, remote, baseFiles) {
|
|
|
3482
3549
|
}
|
|
3483
3550
|
return changes;
|
|
3484
3551
|
}
|
|
3552
|
+
var MAX_FALLBACK_SUFFIX = 100;
|
|
3553
|
+
async function findOpenFallbackPull(rest, baseName, base) {
|
|
3554
|
+
const fallback = new RegExp(
|
|
3555
|
+
`^${baseName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}-\\d+(?:-\\d+)?$`
|
|
3556
|
+
);
|
|
3557
|
+
const res = await rest.api(
|
|
3558
|
+
"GET",
|
|
3559
|
+
"/pulls",
|
|
3560
|
+
{ query: { base, state: "open", per_page: "100" } }
|
|
3561
|
+
);
|
|
3562
|
+
for (const pull of res.data ?? []) {
|
|
3563
|
+
const ref = pull.head?.ref ?? "";
|
|
3564
|
+
const headRepo = pull.head?.repo?.full_name?.toLowerCase();
|
|
3565
|
+
if (headRepo !== rest.repo.toLowerCase() || !fallback.test(ref)) continue;
|
|
3566
|
+
const head = await rest.refSha(ref);
|
|
3567
|
+
if (head !== null) return { branch: ref, head };
|
|
3568
|
+
}
|
|
3569
|
+
return null;
|
|
3570
|
+
}
|
|
3485
3571
|
async function prepareBranch(rest, baseName, base, targetSha, runId) {
|
|
3486
3572
|
const head = await rest.refSha(baseName);
|
|
3487
3573
|
if (head === null) return { branch: baseName, parentSha: targetSha, mode: "new" };
|
|
3488
3574
|
if (await rest.findOpenPullRequest(baseName, base)) {
|
|
3489
3575
|
return { branch: baseName, parentSha: head, mode: "append" };
|
|
3490
3576
|
}
|
|
3491
|
-
|
|
3577
|
+
const open = await findOpenFallbackPull(rest, baseName, base);
|
|
3578
|
+
if (open) return { branch: open.branch, parentSha: open.head, mode: "append" };
|
|
3579
|
+
const fallback = `${baseName}-${runId}`;
|
|
3580
|
+
for (let n = 1; n <= MAX_FALLBACK_SUFFIX; n++) {
|
|
3581
|
+
const branch = n === 1 ? fallback : `${fallback}-${n}`;
|
|
3582
|
+
if (await rest.refSha(branch) === null) return { branch, parentSha: targetSha, mode: "new" };
|
|
3583
|
+
}
|
|
3584
|
+
throw new Error(`[livelocale] No free branch name after ${fallback}-${MAX_FALLBACK_SUFFIX}.`);
|
|
3492
3585
|
}
|
|
3493
3586
|
async function commitFiles(rest, input) {
|
|
3494
3587
|
const { branch, parentSha, mode } = input.branchPlan;
|
|
@@ -3533,7 +3626,7 @@ function noreplyAuthor(actor) {
|
|
|
3533
3626
|
// src/codemod/apply/github-trigger.ts
|
|
3534
3627
|
var APPLY_COMMAND_RE = /^\/livelocale\s+apply(\s+--force)?\s*$/;
|
|
3535
3628
|
var COMMAND_PREFIX = "/livelocale";
|
|
3536
|
-
var ISSUE_BRANCH_RE = /^livelocale\/issue-(\d+)(?:-\d+)
|
|
3629
|
+
var ISSUE_BRANCH_RE = /^livelocale\/issue-(\d+)(?:-\d+){0,2}$/;
|
|
3537
3630
|
var TRUSTED_ASSOCIATIONS = /* @__PURE__ */ new Set(["OWNER", "MEMBER", "COLLABORATOR"]);
|
|
3538
3631
|
var TRUSTED_PERMISSIONS = /* @__PURE__ */ new Set(["admin", "write"]);
|
|
3539
3632
|
var TRUSTED_ROLES = /* @__PURE__ */ new Set(["admin", "maintain", "write"]);
|
|
@@ -3577,7 +3670,8 @@ function parseTrigger(eventName, event) {
|
|
|
3577
3670
|
if (event?.action !== "created") return ignore("comment not created");
|
|
3578
3671
|
const issue = event.issue;
|
|
3579
3672
|
const comment = event.comment;
|
|
3580
|
-
if (issue
|
|
3673
|
+
if (!issue) return ignore("comment without an issue");
|
|
3674
|
+
if (issue.pull_request) return ignore("comment on a pull request");
|
|
3581
3675
|
if (comment?.user?.type === "Bot") return ignore("comment by a bot");
|
|
3582
3676
|
const body = textOf(comment?.body);
|
|
3583
3677
|
const firstLine = body.split(/\r\n|\r|\n/)[0] ?? "";
|
|
@@ -3647,7 +3741,9 @@ async function isTrustedActor(rest, login, association) {
|
|
|
3647
3741
|
function chooseTargetBranch(requested, allowList, defaultBranch) {
|
|
3648
3742
|
if (!requested) return { branch: defaultBranch, reason: "default" };
|
|
3649
3743
|
const allowed = allowList.length > 0 ? allowList : [defaultBranch];
|
|
3650
|
-
if (allowed.includes(requested))
|
|
3744
|
+
if (requested === defaultBranch || allowed.includes(requested)) {
|
|
3745
|
+
return { branch: requested, reason: "link" };
|
|
3746
|
+
}
|
|
3651
3747
|
return { branch: defaultBranch, reason: "not-allowed" };
|
|
3652
3748
|
}
|
|
3653
3749
|
function branchBaseName(t, runId) {
|
|
@@ -3670,7 +3766,7 @@ var STATUS_LABELS = {
|
|
|
3670
3766
|
"needs-force": "needs --force",
|
|
3671
3767
|
invalid: "rejected"
|
|
3672
3768
|
};
|
|
3673
|
-
var BIDI_CONTROL_RE = /[
|
|
3769
|
+
var BIDI_CONTROL_RE = /[\u202a-\u202e\u2066-\u2069]/g;
|
|
3674
3770
|
var NEWLINE_RE = /\r\n|\r|\n/g;
|
|
3675
3771
|
var SPAN_CONTROL_RE = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g;
|
|
3676
3772
|
var CONTROL_RE = /[\u0000-\u001f\u007f-\u009f]/g;
|
|
@@ -3990,8 +4086,13 @@ async function runGitHubEventApply(options) {
|
|
|
3990
4086
|
try {
|
|
3991
4087
|
return await applyLink(options, rest, trigger, { repo, runId, runUrl, server, log, report });
|
|
3992
4088
|
} catch (err) {
|
|
3993
|
-
|
|
3994
|
-
|
|
4089
|
+
const message = err instanceof ExpectedFailure ? err.message : errorMessage(err);
|
|
4090
|
+
try {
|
|
4091
|
+
const result = await report({ kind: "error", message });
|
|
4092
|
+
if (err instanceof ExpectedFailure) return result;
|
|
4093
|
+
} catch (reportErr) {
|
|
4094
|
+
log(`Could not post the error comment: ${errorMessage(reportErr)}`);
|
|
4095
|
+
}
|
|
3995
4096
|
throw err;
|
|
3996
4097
|
}
|
|
3997
4098
|
}
|
|
@@ -4916,6 +5017,7 @@ async function runLocalApply(options) {
|
|
|
4916
5017
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
4917
5018
|
const branch = await pickBranchName(git, root, utcStamp(now()));
|
|
4918
5019
|
await git(["switch", "-c", branch], root);
|
|
5020
|
+
let committed = false;
|
|
4919
5021
|
try {
|
|
4920
5022
|
const written = await writeEdits(mutator, plan, targets, localesDir, localesPath);
|
|
4921
5023
|
log(renderTerminalSummary(plan));
|
|
@@ -4933,6 +5035,7 @@ async function runLocalApply(options) {
|
|
|
4933
5035
|
checkSummary = `Check could not run: ${errorMessage2(err)}`;
|
|
4934
5036
|
}
|
|
4935
5037
|
await new GitClient().commit(localesDir, renderCommitMessage({ plan, by: set.by }));
|
|
5038
|
+
committed = true;
|
|
4936
5039
|
await git(["push", "-u", "origin", branch], root, { inherit: true });
|
|
4937
5040
|
const remote = (await tryRun(() => git(["remote", "get-url", "origin"], root)))?.trim();
|
|
4938
5041
|
const slug = remote ? GITHUB_REMOTE_RE.exec(remote)?.[1] : void 0;
|
|
@@ -4963,7 +5066,9 @@ async function runLocalApply(options) {
|
|
|
4963
5066
|
await git(["switch", original], root);
|
|
4964
5067
|
return { plan, written, branch, prUrl, exitCode };
|
|
4965
5068
|
} catch (err) {
|
|
4966
|
-
log(
|
|
5069
|
+
log(
|
|
5070
|
+
committed ? `You are on ${branch}; your changes are committed there.` : `You are on ${branch}; the edits are written but not committed.`
|
|
5071
|
+
);
|
|
4967
5072
|
throw err;
|
|
4968
5073
|
}
|
|
4969
5074
|
}
|
|
@@ -5171,6 +5276,37 @@ function renderWorkflow(o) {
|
|
|
5171
5276
|
""
|
|
5172
5277
|
].join("\n");
|
|
5173
5278
|
}
|
|
5279
|
+
function parseInitShareArgs(argv) {
|
|
5280
|
+
const args = {
|
|
5281
|
+
dir: ".",
|
|
5282
|
+
localesPath: void 0,
|
|
5283
|
+
sourceLocale: void 0,
|
|
5284
|
+
branches: void 0,
|
|
5285
|
+
overwrite: false
|
|
5286
|
+
};
|
|
5287
|
+
const valueAt = (i) => {
|
|
5288
|
+
const value = argv[i + 1];
|
|
5289
|
+
if (value === void 0 || value.startsWith("--")) {
|
|
5290
|
+
throw new Error(`${argv[i]} needs a value.`);
|
|
5291
|
+
}
|
|
5292
|
+
return value;
|
|
5293
|
+
};
|
|
5294
|
+
for (let i = 0; i < argv.length; i++) {
|
|
5295
|
+
const arg = argv[i];
|
|
5296
|
+
if (arg === "--dir") {
|
|
5297
|
+
args.dir = valueAt(i++);
|
|
5298
|
+
} else if (arg === "--locales") {
|
|
5299
|
+
args.localesPath = valueAt(i++);
|
|
5300
|
+
} else if (arg === "--source") {
|
|
5301
|
+
args.sourceLocale = valueAt(i++);
|
|
5302
|
+
} else if (arg === "--branches") {
|
|
5303
|
+
args.branches = valueAt(i++).split(",").map((b) => b.trim()).filter(Boolean);
|
|
5304
|
+
} else if (arg === "--overwrite") {
|
|
5305
|
+
args.overwrite = true;
|
|
5306
|
+
}
|
|
5307
|
+
}
|
|
5308
|
+
return args;
|
|
5309
|
+
}
|
|
5174
5310
|
function toPosix2(p) {
|
|
5175
5311
|
return p.split(path17.sep).join("/");
|
|
5176
5312
|
}
|
|
@@ -5207,14 +5343,17 @@ function findLocalesPath(projectDir) {
|
|
|
5207
5343
|
if (!found) throw new Error("Pass --locales <path>.");
|
|
5208
5344
|
return found;
|
|
5209
5345
|
}
|
|
5346
|
+
var REMOTE_HEAD = /^ref: refs\/heads\/(\S+)\s+HEAD$/m;
|
|
5210
5347
|
async function defaultBranchOf(git, cwd) {
|
|
5211
5348
|
const ref = await git(["symbolic-ref", "--short", "refs/remotes/origin/HEAD"], cwd);
|
|
5212
5349
|
if (ref?.startsWith("origin/") && ref.length > "origin/".length) {
|
|
5213
|
-
return ref.slice("origin/".length);
|
|
5350
|
+
return { branch: ref.slice("origin/".length), assumed: false };
|
|
5214
5351
|
}
|
|
5352
|
+
const remote = await git(["ls-remote", "--symref", "origin", "HEAD"], cwd);
|
|
5353
|
+
const remoteHead = REMOTE_HEAD.exec(remote ?? "");
|
|
5354
|
+
if (remoteHead) return { branch: remoteHead[1], assumed: false };
|
|
5215
5355
|
const head = await git(["rev-parse", "--abbrev-ref", "HEAD"], cwd);
|
|
5216
|
-
|
|
5217
|
-
return "main";
|
|
5356
|
+
return { branch: head && head !== "HEAD" ? head : "main", assumed: true };
|
|
5218
5357
|
}
|
|
5219
5358
|
function planWrite(projectDir, rel, content) {
|
|
5220
5359
|
const current = readText3(path17.join(projectDir, rel));
|
|
@@ -5239,7 +5378,7 @@ function planViteConfig(c) {
|
|
|
5239
5378
|
c.notes.push(addNote);
|
|
5240
5379
|
return [{ path: config, action: "skipped", reason: "liveLocaleVite(...) has no { options }" }];
|
|
5241
5380
|
}
|
|
5242
|
-
const source2 = c.sourceLocale === "en" ? "" : `sourceLocale: '${c.sourceLocale}', `;
|
|
5381
|
+
const source2 = c.sourceLocale === "en" || /\bsourceLocale\s*:/.test(source) ? "" : `sourceLocale: '${c.sourceLocale}', `;
|
|
5243
5382
|
const next = source.replace(call, () => `liveLocaleVite({ share: true, ${source2}`);
|
|
5244
5383
|
return [{ path: config, action: "update", content: next }];
|
|
5245
5384
|
}
|
|
@@ -5354,7 +5493,12 @@ async function planInitShare(o) {
|
|
|
5354
5493
|
const appRel = toPosix2(path17.relative(repoRoot, projectDir));
|
|
5355
5494
|
const dir = appRel === "" ? void 0 : appRel;
|
|
5356
5495
|
const repoLocales = dir === void 0 ? localesPath : `${dir}/${localesPath}`;
|
|
5357
|
-
const defaultBranch = await defaultBranchOf(git, projectDir);
|
|
5496
|
+
const { branch: defaultBranch, assumed } = await defaultBranchOf(git, projectDir);
|
|
5497
|
+
if (assumed) {
|
|
5498
|
+
notes.push(
|
|
5499
|
+
`Could not read the default branch from origin; assumed \`${defaultBranch}\`. Pass --branches <branch> if that is wrong.`
|
|
5500
|
+
);
|
|
5501
|
+
}
|
|
5358
5502
|
const branches = o.branches ?? [defaultBranch];
|
|
5359
5503
|
const workflow = renderWorkflow({
|
|
5360
5504
|
version: o.version,
|
|
@@ -5381,11 +5525,12 @@ async function planInitShare(o) {
|
|
|
5381
5525
|
return { stack, files, notes };
|
|
5382
5526
|
}
|
|
5383
5527
|
function writePlannedFiles(projectDir, files) {
|
|
5528
|
+
const root = realDir(projectDir);
|
|
5384
5529
|
for (const file of files) {
|
|
5385
5530
|
if (file.action !== "create" && file.action !== "update" || file.content === void 0) {
|
|
5386
5531
|
continue;
|
|
5387
5532
|
}
|
|
5388
|
-
const target = path17.resolve(
|
|
5533
|
+
const target = path17.resolve(root, file.path);
|
|
5389
5534
|
fs11.mkdirSync(path17.dirname(target), { recursive: true });
|
|
5390
5535
|
fs11.writeFileSync(target, file.content, "utf-8");
|
|
5391
5536
|
}
|
|
@@ -5859,7 +6004,6 @@ async function runCheckCommand(args) {
|
|
|
5859
6004
|
warns > 0 ? `\u2705 No problems, ${warns} warning(s) worth a look.` : `\u2705 Translations look good.`
|
|
5860
6005
|
);
|
|
5861
6006
|
}
|
|
5862
|
-
var PACK_USAGE = "Usage: livelocale pack <outDir> [options]";
|
|
5863
6007
|
function printPackSummary(result, projectDir, warnings) {
|
|
5864
6008
|
for (const warning of warnings) console.log(`\u26A0\uFE0F ${warning}`);
|
|
5865
6009
|
const outRel = path18.relative(projectDir, path18.dirname(result.shareDir)).split(path18.sep).join("/") || ".";
|
|
@@ -5871,9 +6015,7 @@ function printPackSummary(result, projectDir, warnings) {
|
|
|
5871
6015
|
async function runPackCommand(args) {
|
|
5872
6016
|
try {
|
|
5873
6017
|
const options = parseShareArgs(args.slice(1));
|
|
5874
|
-
|
|
5875
|
-
throw new PackError("USAGE", PACK_USAGE);
|
|
5876
|
-
}
|
|
6018
|
+
checkPackArgs(options);
|
|
5877
6019
|
const projectDir = path18.resolve(options.dir);
|
|
5878
6020
|
const result = await packOutput({
|
|
5879
6021
|
projectDir,
|
|
@@ -5894,9 +6036,7 @@ async function runPackCommand(args) {
|
|
|
5894
6036
|
async function runBuildCli(args) {
|
|
5895
6037
|
try {
|
|
5896
6038
|
const options = parseShareArgs(args.slice(1));
|
|
5897
|
-
|
|
5898
|
-
throw new PackError("USAGE", BUILD_USAGE);
|
|
5899
|
-
}
|
|
6039
|
+
checkBuildArgs(options);
|
|
5900
6040
|
const projectDir = path18.resolve(options.dir);
|
|
5901
6041
|
const result = await runBuildCommand({
|
|
5902
6042
|
projectDir,
|
|
@@ -5921,25 +6061,15 @@ async function runBuildCli(args) {
|
|
|
5921
6061
|
}
|
|
5922
6062
|
}
|
|
5923
6063
|
async function runInitShareCommand(args) {
|
|
5924
|
-
let
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
if (arg === "--dir") {
|
|
5932
|
-
dir = args[++i] || ".";
|
|
5933
|
-
} else if (arg === "--locales") {
|
|
5934
|
-
localesPath = args[++i];
|
|
5935
|
-
} else if (arg === "--source") {
|
|
5936
|
-
sourceLocale = args[++i];
|
|
5937
|
-
} else if (arg === "--branches") {
|
|
5938
|
-
branches = (args[++i] ?? "").split(",").map((b) => b.trim()).filter(Boolean);
|
|
5939
|
-
} else if (arg === "--overwrite") {
|
|
5940
|
-
overwrite = true;
|
|
5941
|
-
}
|
|
6064
|
+
let parsed;
|
|
6065
|
+
try {
|
|
6066
|
+
parsed = parseInitShareArgs(args.slice(1));
|
|
6067
|
+
} catch (err) {
|
|
6068
|
+
console.error(`\u274C ${err.message}`);
|
|
6069
|
+
process.exitCode = 1;
|
|
6070
|
+
return;
|
|
5942
6071
|
}
|
|
6072
|
+
const { dir, localesPath, sourceLocale, branches, overwrite } = parsed;
|
|
5943
6073
|
const projectDir = path18.resolve(dir);
|
|
5944
6074
|
if (!fs12.existsSync(projectDir)) {
|
|
5945
6075
|
console.error(`Error: Directory "${dir}" does not exist.`);
|