@inlang/paraglide-js 1.2.0 → 1.2.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.
- package/README.md +93 -100
- package/default/index.d.ts +1 -0
- package/default/index.js +1 -0
- package/default/why.txt +4 -0
- package/dist/cli/commands/init.d.ts +19 -11
- package/dist/index.js +334 -193
- package/dist/services/file-handling/write-output.d.ts +2 -3
- package/package.json +26 -9
package/dist/index.js
CHANGED
|
@@ -5808,7 +5808,7 @@ var require_dist_node2 = __commonJS({
|
|
|
5808
5808
|
}
|
|
5809
5809
|
return obj;
|
|
5810
5810
|
}
|
|
5811
|
-
function
|
|
5811
|
+
function merge2(defaults, route, options) {
|
|
5812
5812
|
var _a;
|
|
5813
5813
|
if (typeof route === "string") {
|
|
5814
5814
|
let [method, url] = route.split(" ");
|
|
@@ -6055,15 +6055,15 @@ var require_dist_node2 = __commonJS({
|
|
|
6055
6055
|
);
|
|
6056
6056
|
}
|
|
6057
6057
|
function endpointWithDefaults(defaults, route, options) {
|
|
6058
|
-
return parse(
|
|
6058
|
+
return parse(merge2(defaults, route, options));
|
|
6059
6059
|
}
|
|
6060
6060
|
function withDefaults(oldDefaults, newDefaults) {
|
|
6061
|
-
const DEFAULTS2 =
|
|
6061
|
+
const DEFAULTS2 = merge2(oldDefaults, newDefaults);
|
|
6062
6062
|
const endpoint2 = endpointWithDefaults.bind(null, DEFAULTS2);
|
|
6063
6063
|
return Object.assign(endpoint2, {
|
|
6064
6064
|
DEFAULTS: DEFAULTS2,
|
|
6065
6065
|
defaults: withDefaults.bind(null, DEFAULTS2),
|
|
6066
|
-
merge:
|
|
6066
|
+
merge: merge2.bind(null, DEFAULTS2),
|
|
6067
6067
|
parse
|
|
6068
6068
|
});
|
|
6069
6069
|
}
|
|
@@ -20428,7 +20428,7 @@ var require_package = __commonJS({
|
|
|
20428
20428
|
var require_main = __commonJS({
|
|
20429
20429
|
"../../../../node_modules/.pnpm/dotenv@16.3.1/node_modules/dotenv/lib/main.js"(exports, module) {
|
|
20430
20430
|
init_define_ENV_DEFINED_IN_BUILD_STEP();
|
|
20431
|
-
var
|
|
20431
|
+
var fs2 = __require("fs");
|
|
20432
20432
|
var path3 = __require("path");
|
|
20433
20433
|
var os = __require("os");
|
|
20434
20434
|
var crypto3 = __require("crypto");
|
|
@@ -20553,7 +20553,7 @@ var require_main = __commonJS({
|
|
|
20553
20553
|
}
|
|
20554
20554
|
}
|
|
20555
20555
|
try {
|
|
20556
|
-
const parsed = DotenvModule.parse(
|
|
20556
|
+
const parsed = DotenvModule.parse(fs2.readFileSync(dotenvPath, { encoding }));
|
|
20557
20557
|
let processEnv = process.env;
|
|
20558
20558
|
if (options && options.processEnv != null) {
|
|
20559
20559
|
processEnv = options.processEnv;
|
|
@@ -20572,7 +20572,7 @@ var require_main = __commonJS({
|
|
|
20572
20572
|
if (_dotenvKey(options).length === 0) {
|
|
20573
20573
|
return DotenvModule.configDotenv(options);
|
|
20574
20574
|
}
|
|
20575
|
-
if (!
|
|
20575
|
+
if (!fs2.existsSync(vaultPath)) {
|
|
20576
20576
|
_warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
|
|
20577
20577
|
return DotenvModule.configDotenv(options);
|
|
20578
20578
|
}
|
|
@@ -23847,7 +23847,7 @@ var createEffect4 = createEffect3;
|
|
|
23847
23847
|
// ../../../../lix/source-code/client/dist/git/commit.js
|
|
23848
23848
|
init_define_ENV_DEFINED_IN_BUILD_STEP();
|
|
23849
23849
|
import { walk, TREE, STAGE, writeTree, commit as doCommit } from "isomorphic-git";
|
|
23850
|
-
async function commit({ fs:
|
|
23850
|
+
async function commit({ fs: fs2, dir, ref, author, message }) {
|
|
23851
23851
|
const fileStates = {};
|
|
23852
23852
|
async function createTree(currentFolder, fileStates2) {
|
|
23853
23853
|
const entries = [];
|
|
@@ -23875,10 +23875,10 @@ async function commit({ fs: fs4, dir, ref, author, message }) {
|
|
|
23875
23875
|
});
|
|
23876
23876
|
}
|
|
23877
23877
|
}
|
|
23878
|
-
return await writeTree({ fs:
|
|
23878
|
+
return await writeTree({ fs: fs2, dir, tree: entries });
|
|
23879
23879
|
}
|
|
23880
23880
|
await walk({
|
|
23881
|
-
fs:
|
|
23881
|
+
fs: fs2,
|
|
23882
23882
|
dir,
|
|
23883
23883
|
// cache, gitdir,
|
|
23884
23884
|
trees: [TREE({ ref }), STAGE()],
|
|
@@ -23938,7 +23938,7 @@ async function commit({ fs: fs4, dir, ref, author, message }) {
|
|
|
23938
23938
|
});
|
|
23939
23939
|
const tree = await createTree("/", fileStates);
|
|
23940
23940
|
return doCommit({
|
|
23941
|
-
fs:
|
|
23941
|
+
fs: fs2,
|
|
23942
23942
|
dir,
|
|
23943
23943
|
author,
|
|
23944
23944
|
message,
|
|
@@ -23967,7 +23967,7 @@ async function hash(inputStr) {
|
|
|
23967
23967
|
}
|
|
23968
23968
|
|
|
23969
23969
|
// ../../../../lix/source-code/client/dist/openRepository.js
|
|
23970
|
-
var { clone, listRemotes, status, statusMatrix, push, pull, currentBranch, add, log, listServerRefs, checkout, addRemote, fetch: gitFetch, commit: isoCommit, findRoot } = isoGit;
|
|
23970
|
+
var { clone, listRemotes, status, statusMatrix, push, pull, currentBranch, add, log, listServerRefs, checkout, addRemote, fetch: gitFetch, commit: isoCommit, findRoot, merge } = isoGit;
|
|
23971
23971
|
var verbose = false;
|
|
23972
23972
|
var whitelistedExperimentalRepos = [
|
|
23973
23973
|
"inlang/example",
|
|
@@ -23988,6 +23988,12 @@ async function findRepoRoot(args) {
|
|
|
23988
23988
|
async function openRepository(url, args) {
|
|
23989
23989
|
var _a;
|
|
23990
23990
|
const rawFs = args.nodeishFs;
|
|
23991
|
+
if (!url) {
|
|
23992
|
+
throw new Error("repo url is required, use file:// for local repos");
|
|
23993
|
+
}
|
|
23994
|
+
if (verbose && typeof window !== "undefined") {
|
|
23995
|
+
window["rawFs"] = rawFs;
|
|
23996
|
+
}
|
|
23991
23997
|
const [errors, setErrors] = createSignal4([]);
|
|
23992
23998
|
let doLixClone = false;
|
|
23993
23999
|
let branchName = args.branch;
|
|
@@ -24011,8 +24017,8 @@ async function openRepository(url, args) {
|
|
|
24011
24017
|
}
|
|
24012
24018
|
}
|
|
24013
24019
|
const { protocol, lixHost, repoHost, owner, repoName, username, password } = parseLixUri(url);
|
|
24014
|
-
if (username || password) {
|
|
24015
|
-
console.
|
|
24020
|
+
if (verbose && (username || password)) {
|
|
24021
|
+
console.warn("username and password and providers other than github are not supported yet. Only local commands will work.");
|
|
24016
24022
|
}
|
|
24017
24023
|
const gitProxyUrl = lixHost ? `${protocol}//${lixHost}/git-proxy/` : "";
|
|
24018
24024
|
const gitHubProxyUrl = lixHost ? `${protocol}//${lixHost}/github-proxy/` : "";
|
|
@@ -24139,7 +24145,7 @@ async function openRepository(url, args) {
|
|
|
24139
24145
|
const repo = await this;
|
|
24140
24146
|
const { isFork, parent } = await repo.getMeta();
|
|
24141
24147
|
if (!isFork) {
|
|
24142
|
-
return { error: "could not get fork
|
|
24148
|
+
return { error: "could not get fork upstream or repo not a fork" };
|
|
24143
24149
|
}
|
|
24144
24150
|
const forkFs = withLazyFetching({
|
|
24145
24151
|
nodeishFs: rawFs,
|
|
@@ -24147,6 +24153,14 @@ async function openRepository(url, args) {
|
|
|
24147
24153
|
description: "forkStatus",
|
|
24148
24154
|
intercept: delayedAction
|
|
24149
24155
|
});
|
|
24156
|
+
const useBranchName = await isoGit.currentBranch({
|
|
24157
|
+
fs: forkFs,
|
|
24158
|
+
dir,
|
|
24159
|
+
fullname: false
|
|
24160
|
+
});
|
|
24161
|
+
if (!useBranchName) {
|
|
24162
|
+
return { error: "could not get fork status for detached head" };
|
|
24163
|
+
}
|
|
24150
24164
|
await addRemote({
|
|
24151
24165
|
dir,
|
|
24152
24166
|
remote: "upstream",
|
|
@@ -24158,7 +24172,7 @@ async function openRepository(url, args) {
|
|
|
24158
24172
|
depth: 1,
|
|
24159
24173
|
singleBranch: true,
|
|
24160
24174
|
dir,
|
|
24161
|
-
ref:
|
|
24175
|
+
ref: useBranchName,
|
|
24162
24176
|
remote: "upstream",
|
|
24163
24177
|
http: makeHttpClient({ verbose, description: "forkStatus" }),
|
|
24164
24178
|
fs: forkFs
|
|
@@ -24166,26 +24180,18 @@ async function openRepository(url, args) {
|
|
|
24166
24180
|
} catch (err) {
|
|
24167
24181
|
return { error: err };
|
|
24168
24182
|
}
|
|
24169
|
-
const branch = await isoGit.currentBranch({
|
|
24170
|
-
fs: forkFs,
|
|
24171
|
-
dir,
|
|
24172
|
-
fullname: false
|
|
24173
|
-
});
|
|
24174
|
-
if (typeof branch !== "string") {
|
|
24175
|
-
return { error: "could not get current branch" };
|
|
24176
|
-
}
|
|
24177
24183
|
const currentUpstreamCommit = await isoGit.resolveRef({
|
|
24178
24184
|
fs: forkFs,
|
|
24179
24185
|
dir: "/",
|
|
24180
|
-
ref: "upstream/" +
|
|
24186
|
+
ref: "upstream/" + useBranchName
|
|
24181
24187
|
});
|
|
24182
24188
|
const currentOriginCommit = await isoGit.resolveRef({
|
|
24183
24189
|
fs: forkFs,
|
|
24184
24190
|
dir: "/",
|
|
24185
|
-
ref:
|
|
24191
|
+
ref: useBranchName
|
|
24186
24192
|
});
|
|
24187
24193
|
if (currentUpstreamCommit === currentOriginCommit) {
|
|
24188
|
-
return { ahead: 0, behind: 0 };
|
|
24194
|
+
return { ahead: 0, behind: 0, conflicts: false };
|
|
24189
24195
|
}
|
|
24190
24196
|
const res = github.request("GET /repos/{owner}/{repo}/compare/{base}...{head}", {
|
|
24191
24197
|
owner,
|
|
@@ -24200,7 +24206,40 @@ async function openRepository(url, args) {
|
|
|
24200
24206
|
if ("error" in compare || !("data" in compare)) {
|
|
24201
24207
|
return { error: compare.error || "could not diff repos on github" };
|
|
24202
24208
|
}
|
|
24203
|
-
|
|
24209
|
+
await gitFetch({
|
|
24210
|
+
depth: compare.data.behind_by + 1,
|
|
24211
|
+
remote: "upstream",
|
|
24212
|
+
singleBranch: true,
|
|
24213
|
+
dir,
|
|
24214
|
+
ref: useBranchName,
|
|
24215
|
+
http: makeHttpClient({ verbose, description: "forkStatus" }),
|
|
24216
|
+
fs: forkFs
|
|
24217
|
+
});
|
|
24218
|
+
await gitFetch({
|
|
24219
|
+
depth: compare.data.ahead_by + 1,
|
|
24220
|
+
singleBranch: true,
|
|
24221
|
+
ref: useBranchName,
|
|
24222
|
+
dir,
|
|
24223
|
+
http: makeHttpClient({ verbose, description: "forkStatus" }),
|
|
24224
|
+
corsProxy: gitProxyUrl,
|
|
24225
|
+
fs: forkFs
|
|
24226
|
+
});
|
|
24227
|
+
let conflicts = false;
|
|
24228
|
+
try {
|
|
24229
|
+
await merge({
|
|
24230
|
+
fs: forkFs,
|
|
24231
|
+
author: { name: "lix" },
|
|
24232
|
+
dir,
|
|
24233
|
+
ours: useBranchName,
|
|
24234
|
+
dryRun: true,
|
|
24235
|
+
theirs: "upstream/" + useBranchName,
|
|
24236
|
+
noUpdateBranch: true,
|
|
24237
|
+
abortOnConflict: true
|
|
24238
|
+
});
|
|
24239
|
+
} catch (err) {
|
|
24240
|
+
conflicts = true;
|
|
24241
|
+
}
|
|
24242
|
+
return { ahead: compare.data.ahead_by, behind: compare.data.behind_by, conflicts };
|
|
24204
24243
|
},
|
|
24205
24244
|
statusMatrix(cmdArgs) {
|
|
24206
24245
|
return statusMatrix({
|
|
@@ -24418,7 +24457,7 @@ async function openRepository(url, args) {
|
|
|
24418
24457
|
if (lastHashInPage) {
|
|
24419
24458
|
firstCommitHash = lastHashInPage;
|
|
24420
24459
|
}
|
|
24421
|
-
if (commits.length <
|
|
24460
|
+
if (commits.length < 550) {
|
|
24422
24461
|
break;
|
|
24423
24462
|
}
|
|
24424
24463
|
}
|
|
@@ -24490,13 +24529,71 @@ async function generateProjectId(args) {
|
|
|
24490
24529
|
return void 0;
|
|
24491
24530
|
}
|
|
24492
24531
|
const firstCommitHash = await args.repo.getFirstCommitHash();
|
|
24493
|
-
const originHash = await args.repo.getOrigin({ safeHashOnly: true });
|
|
24494
24532
|
if (firstCommitHash) {
|
|
24495
|
-
return hash(`${firstCommitHash + args.projectPath
|
|
24533
|
+
return hash(`${firstCommitHash + args.projectPath}`);
|
|
24496
24534
|
}
|
|
24497
24535
|
return void 0;
|
|
24498
24536
|
}
|
|
24499
24537
|
|
|
24538
|
+
// ../../sdk/dist/telemetry/capture.js
|
|
24539
|
+
init_define_ENV_DEFINED_IN_BUILD_STEP();
|
|
24540
|
+
|
|
24541
|
+
// ../../sdk/dist/env-variables/index.js
|
|
24542
|
+
init_define_ENV_DEFINED_IN_BUILD_STEP();
|
|
24543
|
+
var ENV_VARIABLES = {
|
|
24544
|
+
PUBLIC_POSTHOG_TOKEN: "phc_m5yJZCxjOGxF8CJvP5sQ3H0d76xpnLrsmiZHduT4jDz"
|
|
24545
|
+
};
|
|
24546
|
+
|
|
24547
|
+
// ../../sdk/dist/telemetry/capture.js
|
|
24548
|
+
var capture = async (event, args) => {
|
|
24549
|
+
if (ENV_VARIABLES.PUBLIC_POSTHOG_TOKEN === void 0) {
|
|
24550
|
+
return;
|
|
24551
|
+
}
|
|
24552
|
+
try {
|
|
24553
|
+
await fetch("https://eu.posthog.com/capture/", {
|
|
24554
|
+
method: "POST",
|
|
24555
|
+
body: JSON.stringify({
|
|
24556
|
+
api_key: ENV_VARIABLES.PUBLIC_POSTHOG_TOKEN,
|
|
24557
|
+
event,
|
|
24558
|
+
// id is "unknown" because no user information is available
|
|
24559
|
+
distinct_id: "unknown",
|
|
24560
|
+
properties: {
|
|
24561
|
+
$groups: { project: args.projectId },
|
|
24562
|
+
...args.properties
|
|
24563
|
+
}
|
|
24564
|
+
})
|
|
24565
|
+
});
|
|
24566
|
+
} catch (e) {
|
|
24567
|
+
}
|
|
24568
|
+
};
|
|
24569
|
+
|
|
24570
|
+
// ../../sdk/dist/telemetry/groupIdentify.js
|
|
24571
|
+
init_define_ENV_DEFINED_IN_BUILD_STEP();
|
|
24572
|
+
var identifyProject = async (args) => {
|
|
24573
|
+
if (ENV_VARIABLES.PUBLIC_POSTHOG_TOKEN === void 0) {
|
|
24574
|
+
return;
|
|
24575
|
+
}
|
|
24576
|
+
try {
|
|
24577
|
+
await fetch("https://eu.posthog.com/capture/", {
|
|
24578
|
+
method: "POST",
|
|
24579
|
+
body: JSON.stringify({
|
|
24580
|
+
api_key: ENV_VARIABLES.PUBLIC_POSTHOG_TOKEN,
|
|
24581
|
+
event: "$groupidentify",
|
|
24582
|
+
// id is "unknown" because no user information is available
|
|
24583
|
+
distinct_id: "unknown",
|
|
24584
|
+
properties: {
|
|
24585
|
+
$group_type: "project",
|
|
24586
|
+
$group_key: args.projectId,
|
|
24587
|
+
$group_set: {
|
|
24588
|
+
...args.properties
|
|
24589
|
+
}
|
|
24590
|
+
}
|
|
24591
|
+
})
|
|
24592
|
+
});
|
|
24593
|
+
} catch (e) {
|
|
24594
|
+
}
|
|
24595
|
+
};
|
|
24596
|
+
|
|
24500
24597
|
// ../../sdk/dist/loadProject.js
|
|
24501
24598
|
var settingsCompiler = import_compiler3.TypeCompiler.Compile(ProjectSettings);
|
|
24502
24599
|
async function loadProject(args) {
|
|
@@ -24511,30 +24608,19 @@ Valid examples:
|
|
|
24511
24608
|
- "/path/to/green-elephant.inlang
|
|
24512
24609
|
`, { argument: "projectPath" });
|
|
24513
24610
|
}
|
|
24514
|
-
|
|
24515
|
-
if (args.nodeishFs) {
|
|
24516
|
-
fs4 = args.nodeishFs;
|
|
24517
|
-
} else if (args.repo) {
|
|
24518
|
-
fs4 = args.repo.nodeishFs;
|
|
24519
|
-
} else {
|
|
24520
|
-
throw new LoadProjectInvalidArgument(`Repo missing from arguments.`, { argument: "repo" });
|
|
24521
|
-
}
|
|
24611
|
+
const fs2 = args.repo.nodeishFs;
|
|
24522
24612
|
const nodeishFs = createNodeishFsWithAbsolutePaths({
|
|
24523
24613
|
projectPath,
|
|
24524
|
-
nodeishFs:
|
|
24614
|
+
nodeishFs: fs2
|
|
24525
24615
|
});
|
|
24526
|
-
await maybeMigrateToDirectory({ nodeishFs:
|
|
24616
|
+
await maybeMigrateToDirectory({ nodeishFs: fs2, projectPath });
|
|
24527
24617
|
await maybeCreateFirstProjectId({ projectPath, repo: args.repo });
|
|
24528
24618
|
return await createRoot2(async () => {
|
|
24619
|
+
const { data: projectId } = await tryCatch(() => fs2.readFile(args.projectPath + "/project_id", { encoding: "utf-8" }));
|
|
24529
24620
|
const [initialized, markInitAsComplete, markInitAsFailed] = createAwaitable();
|
|
24530
24621
|
const [settings, _setSettings] = createSignal2();
|
|
24531
24622
|
createEffect2(() => {
|
|
24532
|
-
loadSettings({ settingsFilePath: projectPath + "/settings.json", nodeishFs }).then((settings2) => {
|
|
24533
|
-
var _a;
|
|
24534
|
-
setSettings(settings2);
|
|
24535
|
-
const project_settings = settings2;
|
|
24536
|
-
(_a = args._capture) == null ? void 0 : _a.call(args, "SDK used settings", { project_settings });
|
|
24537
|
-
}).catch((err) => {
|
|
24623
|
+
loadSettings({ settingsFilePath: projectPath + "/settings.json", nodeishFs }).then((settings2) => setSettings(settings2)).catch((err) => {
|
|
24538
24624
|
markInitAsFailed(err);
|
|
24539
24625
|
});
|
|
24540
24626
|
});
|
|
@@ -24572,10 +24658,10 @@ Valid examples:
|
|
|
24572
24658
|
markInitAsFailed(void 0);
|
|
24573
24659
|
return;
|
|
24574
24660
|
}
|
|
24575
|
-
const loadAndSetMessages = async (
|
|
24661
|
+
const loadAndSetMessages = async (fs3) => {
|
|
24576
24662
|
makeTrulyAsync(_resolvedModules.resolvedPluginApi.loadMessages({
|
|
24577
24663
|
settings: settingsValue,
|
|
24578
|
-
nodeishFs:
|
|
24664
|
+
nodeishFs: fs3
|
|
24579
24665
|
})).then((messages2) => {
|
|
24580
24666
|
setMessages(messages2);
|
|
24581
24667
|
markInitAsComplete();
|
|
@@ -24644,7 +24730,30 @@ Valid examples:
|
|
|
24644
24730
|
createEffect2(() => {
|
|
24645
24731
|
debouncedSave(messagesQuery.getAll());
|
|
24646
24732
|
});
|
|
24733
|
+
let projectLoadedCapturedAlready = false;
|
|
24734
|
+
if (projectId && projectLoadedCapturedAlready === false) {
|
|
24735
|
+
projectLoadedCapturedAlready = true;
|
|
24736
|
+
await identifyProject({
|
|
24737
|
+
projectId,
|
|
24738
|
+
properties: {
|
|
24739
|
+
// using the id for now as a name but can be changed in the future
|
|
24740
|
+
// we need at least one property to make a project visible in the dashboard
|
|
24741
|
+
name: projectId
|
|
24742
|
+
}
|
|
24743
|
+
});
|
|
24744
|
+
await capture("SDK loaded project", {
|
|
24745
|
+
projectId,
|
|
24746
|
+
properties: {
|
|
24747
|
+
appId: args.appId,
|
|
24748
|
+
settings: settings(),
|
|
24749
|
+
installedPluginIds: installedPlugins().map((p) => p.id),
|
|
24750
|
+
installedMessageLintRuleIds: installedMessageLintRules().map((r) => r.id),
|
|
24751
|
+
numberOfMessages: messagesQuery.includedMessageIds().length
|
|
24752
|
+
}
|
|
24753
|
+
});
|
|
24754
|
+
}
|
|
24647
24755
|
return {
|
|
24756
|
+
id: projectId,
|
|
24648
24757
|
installed: {
|
|
24649
24758
|
plugins: createSubscribable(() => installedPlugins()),
|
|
24650
24759
|
messageLintRules: createSubscribable(() => installedMessageLintRules())
|
|
@@ -24652,8 +24761,6 @@ Valid examples:
|
|
|
24652
24761
|
errors: createSubscribable(() => [
|
|
24653
24762
|
...initializeError ? [initializeError] : [],
|
|
24654
24763
|
...resolvedModules() ? resolvedModules().errors : []
|
|
24655
|
-
// have a query error exposed
|
|
24656
|
-
//...(lintErrors() ?? []),
|
|
24657
24764
|
]),
|
|
24658
24765
|
settings: createSubscribable(() => settings()),
|
|
24659
24766
|
setSettings,
|
|
@@ -24795,6 +24902,7 @@ var solidAdapter = (project, arg) => {
|
|
|
24795
24902
|
return arg.from(observable2(signal));
|
|
24796
24903
|
};
|
|
24797
24904
|
return {
|
|
24905
|
+
id: project.id,
|
|
24798
24906
|
customApi: convert(project.customApi),
|
|
24799
24907
|
settings: convert(project.settings),
|
|
24800
24908
|
errors: convert(project.errors),
|
|
@@ -25202,7 +25310,7 @@ var messageIndexFunction = (args) => {
|
|
|
25202
25310
|
* This message has been compiled by [inlang paraglide](https://inlang.com/m/gerre34r/library-inlang-paraglideJs).
|
|
25203
25311
|
*
|
|
25204
25312
|
* - Don't edit the message's code. Use the [inlang ide extension](https://inlang.com/m/r7kp499g/app-inlang-ideExtension),
|
|
25205
|
-
* the [web editor](https://inlang.com/m/tdozzpar/app-inlang-
|
|
25313
|
+
* the [web editor](https://inlang.com/m/tdozzpar/app-inlang-finkLocalizationEditor) instead, or edit the translation files manually.
|
|
25206
25314
|
*
|
|
25207
25315
|
* - The params are NonNullable<unknown> because the inlang SDK does not provide information on the type of a param (yet).
|
|
25208
25316
|
*
|
|
@@ -25250,7 +25358,7 @@ init_define_ENV_DEFINED_IN_BUILD_STEP();
|
|
|
25250
25358
|
var import_dotenv = __toESM(require_main(), 1);
|
|
25251
25359
|
var privateEnv = getPrivateEnvVariables();
|
|
25252
25360
|
function getPrivateEnvVariables() {
|
|
25253
|
-
if (typeof process === "undefined") {
|
|
25361
|
+
if (typeof process === "undefined" || typeof process.cwd === "undefined") {
|
|
25254
25362
|
return new Proxy(
|
|
25255
25363
|
{},
|
|
25256
25364
|
{
|
|
@@ -25271,7 +25379,7 @@ function getPrivateEnvVariables() {
|
|
|
25271
25379
|
|
|
25272
25380
|
// ../../env-variables/dist/runtime/publicEnv.js
|
|
25273
25381
|
init_define_ENV_DEFINED_IN_BUILD_STEP();
|
|
25274
|
-
var define_PUBLIC_ENV_DEFINED_IN_BUILD_STEP_default = { PUBLIC_IS_DEV: "false", PUBLIC_GIT_PROXY_BASE_URL: "https://git.inlang.com", PUBLIC_POSTHOG_TOKEN: "phc_m5yJZCxjOGxF8CJvP5sQ3H0d76xpnLrsmiZHduT4jDz", PUBLIC_ALLOWED_AUTH_URLS: "https://inlang.com,https://manage.inlang.com,https://fink.inlang.com", PUBLIC_SERVER_BASE_URL: "https://inlang.com", PUBLIC_WEBSITE_SENTRY_DSN: "https://6ba3cb3bad464dd9a7f8700ed636c07a@o4504345873285120.ingest.sentry.io/4504346044006400", PUBLIC_HCAPTCHA_SITEKEY: "353a039d-fc34-40a6-a81d-91720e8851b0", PUBLIC_LIX_GITHUB_APP_NAME: "inlang", PUBLIC_LIX_GITHUB_APP_CLIENT_ID: "Iv1.436da58906364f96" };
|
|
25382
|
+
var define_PUBLIC_ENV_DEFINED_IN_BUILD_STEP_default = { PUBLIC_IS_DEV: "false", PUBLIC_GIT_PROXY_BASE_URL: "https://git.inlang.com", PUBLIC_POSTHOG_TOKEN: "phc_m5yJZCxjOGxF8CJvP5sQ3H0d76xpnLrsmiZHduT4jDz", PUBLIC_ALLOWED_AUTH_URLS: "https://inlang.com,https://manage.inlang.com,https://fink.inlang.com", PUBLIC_SERVER_BASE_URL: "https://inlang.com", PUBLIC_FINK_SENTRY_DSN: "https://00c275e250bb5a103cda12a76e5a7d98@o4504345873285120.ingest.sentry.io/4506599134461952", PUBLIC_WEBSITE_SENTRY_DSN: "https://6ba3cb3bad464dd9a7f8700ed636c07a@o4504345873285120.ingest.sentry.io/4504346044006400", PUBLIC_HCAPTCHA_SITEKEY: "353a039d-fc34-40a6-a81d-91720e8851b0", PUBLIC_LIX_GITHUB_APP_NAME: "inlang", PUBLIC_LIX_GITHUB_APP_CLIENT_ID: "Iv1.436da58906364f96" };
|
|
25275
25383
|
var publicEnv = new Proxy({}, {
|
|
25276
25384
|
get(target, prop) {
|
|
25277
25385
|
if (typeof prop === "string" && prop.startsWith("PUBLIC_") === false) {
|
|
@@ -29035,6 +29143,7 @@ var publicEnvVariablesSchema = z.object({
|
|
|
29035
29143
|
PUBLIC_LIX_GITHUB_APP_NAME: z.string(),
|
|
29036
29144
|
PUBLIC_GIT_PROXY_BASE_URL: z.string().startsWith("http").regex(/^(?!.*\/$).+$/, "Must not end with a slash").describe(`Must be a url including protocol`),
|
|
29037
29145
|
PUBLIC_WEBSITE_SENTRY_DSN: z.string().optional().describe("DSN for Sentry (in the browser)"),
|
|
29146
|
+
PUBLIC_FINK_SENTRY_DSN: z.string().optional().describe("DSN for Sentry (in the fink)"),
|
|
29038
29147
|
PUBLIC_POSTHOG_TOKEN: z.string().optional(),
|
|
29039
29148
|
PUBLIC_SERVER_BASE_URL: z.string().url().regex(/^(?!.*\/$).+$/, "Must not end with a slash").describe("The base url of the server e.g. https://inlang.com"),
|
|
29040
29149
|
PUBLIC_ALLOWED_AUTH_URLS: z.string().describe("List of allowed base urls eg https://inlang.com,https://manage.inlang.com"),
|
|
@@ -29066,15 +29175,18 @@ var posthog = new PostHog(publicEnv.PUBLIC_POSTHOG_TOKEN ?? "placeholder", {
|
|
|
29066
29175
|
});
|
|
29067
29176
|
var telemetry = new Proxy(posthog, {
|
|
29068
29177
|
get(target, prop) {
|
|
29069
|
-
if (publicEnv.PUBLIC_POSTHOG_TOKEN
|
|
29178
|
+
if (!publicEnv.PUBLIC_POSTHOG_TOKEN) {
|
|
29070
29179
|
return () => void 0;
|
|
29071
29180
|
} else if (prop === "capture") {
|
|
29072
|
-
return
|
|
29181
|
+
return capture2;
|
|
29073
29182
|
}
|
|
29074
29183
|
return target[prop];
|
|
29075
29184
|
}
|
|
29076
29185
|
});
|
|
29077
|
-
function
|
|
29186
|
+
function capture2(args) {
|
|
29187
|
+
if (!publicEnv.PUBLIC_POSTHOG_TOKEN) {
|
|
29188
|
+
return;
|
|
29189
|
+
}
|
|
29078
29190
|
return posthog.capture({
|
|
29079
29191
|
...args,
|
|
29080
29192
|
distinctId: "unknown"
|
|
@@ -29285,7 +29397,7 @@ export function isAvailableLanguageTag(thing) {
|
|
|
29285
29397
|
};
|
|
29286
29398
|
|
|
29287
29399
|
// src/cli/commands/compile.ts
|
|
29288
|
-
import
|
|
29400
|
+
import nodeFsPromises from "node:fs/promises";
|
|
29289
29401
|
import { resolve } from "node:path";
|
|
29290
29402
|
import { Command } from "commander";
|
|
29291
29403
|
|
|
@@ -29294,32 +29406,30 @@ init_define_ENV_DEFINED_IN_BUILD_STEP();
|
|
|
29294
29406
|
import path from "node:path";
|
|
29295
29407
|
import crypto2 from "node:crypto";
|
|
29296
29408
|
var previousOutputHash;
|
|
29297
|
-
async function writeOutput(outputDirectory, output,
|
|
29409
|
+
async function writeOutput(outputDirectory, output, fs2) {
|
|
29298
29410
|
const currentOutputHash = hashOutput(output, outputDirectory);
|
|
29299
29411
|
if (currentOutputHash === previousOutputHash)
|
|
29300
29412
|
return;
|
|
29301
|
-
await
|
|
29302
|
-
await
|
|
29413
|
+
await fs2.access(outputDirectory).catch(async () => {
|
|
29414
|
+
await fs2.mkdir(outputDirectory, { recursive: true });
|
|
29303
29415
|
});
|
|
29304
|
-
const files = await
|
|
29416
|
+
const files = await fs2.readdir(outputDirectory);
|
|
29305
29417
|
await Promise.allSettled(
|
|
29306
29418
|
files.map(async (file) => {
|
|
29307
|
-
await
|
|
29419
|
+
await fs2.unlink(outputDirectory + "/" + file);
|
|
29308
29420
|
})
|
|
29309
29421
|
);
|
|
29310
29422
|
await Promise.allSettled(
|
|
29311
29423
|
Object.keys(output).map(async (filePath) => {
|
|
29312
29424
|
const fullPath = path.resolve(outputDirectory, filePath);
|
|
29313
29425
|
const directory = path.dirname(fullPath);
|
|
29314
|
-
await
|
|
29426
|
+
await fs2.mkdir(directory, { recursive: true });
|
|
29315
29427
|
})
|
|
29316
29428
|
);
|
|
29317
29429
|
await Promise.allSettled(
|
|
29318
29430
|
Object.entries(output).map(async ([filePath, fileContent]) => {
|
|
29319
29431
|
const fullPath = path.resolve(outputDirectory, filePath);
|
|
29320
|
-
await
|
|
29321
|
-
encoding: "utf-8"
|
|
29322
|
-
});
|
|
29432
|
+
await fs2.writeFile(fullPath, fileContent);
|
|
29323
29433
|
})
|
|
29324
29434
|
);
|
|
29325
29435
|
previousOutputHash = currentOutputHash;
|
|
@@ -29399,51 +29509,22 @@ var compileCommand = new Command().name("compile").summary("Compiles inlang Para
|
|
|
29399
29509
|
const path3 = resolve(process.cwd(), options.project);
|
|
29400
29510
|
const outputDirectory = resolve(process.cwd(), options.outdir);
|
|
29401
29511
|
logger.info(`Compiling inlang project at "${options.project}".`);
|
|
29402
|
-
const repoRoot = await findRepoRoot({ nodeishFs:
|
|
29403
|
-
|
|
29512
|
+
const repoRoot = await findRepoRoot({ nodeishFs: nodeFsPromises, path: path3 });
|
|
29513
|
+
const repo = await openRepository(repoRoot || process.cwd(), {
|
|
29514
|
+
nodeishFs: nodeFsPromises
|
|
29515
|
+
});
|
|
29404
29516
|
if (!repoRoot) {
|
|
29405
29517
|
logger.warn(`Could not find repository root for path ${path3}`);
|
|
29406
|
-
project = exitIfErrors(
|
|
29407
|
-
await loadProject({
|
|
29408
|
-
projectPath: path3,
|
|
29409
|
-
nodeishFs: fs,
|
|
29410
|
-
_capture(id, props) {
|
|
29411
|
-
telemetry.capture({
|
|
29412
|
-
// @ts-ignore the event types
|
|
29413
|
-
event: id,
|
|
29414
|
-
properties: props
|
|
29415
|
-
});
|
|
29416
|
-
}
|
|
29417
|
-
}),
|
|
29418
|
-
logger
|
|
29419
|
-
);
|
|
29420
|
-
} else {
|
|
29421
|
-
const repo = await openRepository(repoRoot, {
|
|
29422
|
-
nodeishFs: fs
|
|
29423
|
-
});
|
|
29424
|
-
project = exitIfErrors(
|
|
29425
|
-
await loadProject({
|
|
29426
|
-
projectPath: path3,
|
|
29427
|
-
repo,
|
|
29428
|
-
_capture(id, props) {
|
|
29429
|
-
telemetry.capture({
|
|
29430
|
-
// @ts-ignore the event types
|
|
29431
|
-
event: id,
|
|
29432
|
-
properties: props
|
|
29433
|
-
});
|
|
29434
|
-
}
|
|
29435
|
-
}),
|
|
29436
|
-
logger
|
|
29437
|
-
);
|
|
29438
|
-
}
|
|
29439
|
-
async function execute() {
|
|
29440
|
-
const output = compile({
|
|
29441
|
-
messages: project.query.messages.getAll(),
|
|
29442
|
-
settings: project.settings()
|
|
29443
|
-
});
|
|
29444
|
-
await writeOutput(outputDirectory, output, fs);
|
|
29445
29518
|
}
|
|
29446
|
-
|
|
29519
|
+
const project = exitIfErrors(
|
|
29520
|
+
await loadProject({
|
|
29521
|
+
projectPath: path3,
|
|
29522
|
+
repo,
|
|
29523
|
+
appId: "library.inlang.paraglideJs"
|
|
29524
|
+
}),
|
|
29525
|
+
logger
|
|
29526
|
+
);
|
|
29527
|
+
await executeCompilation(project, outputDirectory, repo.nodeishFs);
|
|
29447
29528
|
if (options.watch) {
|
|
29448
29529
|
process.on("SIGINT", () => {
|
|
29449
29530
|
logger.ln().info("Stopping the watcher.");
|
|
@@ -29457,7 +29538,7 @@ var compileCommand = new Command().name("compile").summary("Compiles inlang Para
|
|
|
29457
29538
|
if (numChanges === 1)
|
|
29458
29539
|
return;
|
|
29459
29540
|
logger.info("Messages changed. Recompiling...");
|
|
29460
|
-
await
|
|
29541
|
+
await executeCompilation(project, outputDirectory, repo.nodeishFs);
|
|
29461
29542
|
});
|
|
29462
29543
|
while (true) {
|
|
29463
29544
|
await new Promise((resolve3) => setTimeout(resolve3, 1e4));
|
|
@@ -29465,6 +29546,13 @@ var compileCommand = new Command().name("compile").summary("Compiles inlang Para
|
|
|
29465
29546
|
}
|
|
29466
29547
|
logger.info("Sucessfully compiled the project.");
|
|
29467
29548
|
});
|
|
29549
|
+
async function executeCompilation(project, outputDirectory, fs2) {
|
|
29550
|
+
const output = compile({
|
|
29551
|
+
messages: project.query.messages.getAll(),
|
|
29552
|
+
settings: project.settings()
|
|
29553
|
+
});
|
|
29554
|
+
await writeOutput(outputDirectory, output, fs2);
|
|
29555
|
+
}
|
|
29468
29556
|
var exitIfErrors = (project, logger) => {
|
|
29469
29557
|
if (project.errors().length > 0) {
|
|
29470
29558
|
logger.warn(`The project has errors:`);
|
|
@@ -29479,8 +29567,6 @@ var exitIfErrors = (project, logger) => {
|
|
|
29479
29567
|
// src/cli/commands/init.ts
|
|
29480
29568
|
init_define_ENV_DEFINED_IN_BUILD_STEP();
|
|
29481
29569
|
import { Command as Command2 } from "commander";
|
|
29482
|
-
import fs3 from "node:fs/promises";
|
|
29483
|
-
import fsSync from "node:fs";
|
|
29484
29570
|
import consola2 from "consola";
|
|
29485
29571
|
import { resolve as resolve2 } from "node:path";
|
|
29486
29572
|
import { detectJsonFormatting } from "@inlang/detect-json-formatting";
|
|
@@ -29490,7 +29576,7 @@ import childProcess from "node:child_process";
|
|
|
29490
29576
|
// src/cli/state.ts
|
|
29491
29577
|
init_define_ENV_DEFINED_IN_BUILD_STEP();
|
|
29492
29578
|
import path2 from "node:path";
|
|
29493
|
-
import
|
|
29579
|
+
import fs from "node:fs";
|
|
29494
29580
|
import { fileURLToPath } from "node:url";
|
|
29495
29581
|
var version = (() => {
|
|
29496
29582
|
const currentFilePath = fileURLToPath(import.meta.url).split(path2.sep).join(path2.posix.sep);
|
|
@@ -29498,31 +29584,42 @@ var version = (() => {
|
|
|
29498
29584
|
0,
|
|
29499
29585
|
currentFilePath.indexOf("/paraglide-js/") + "/paraglide-js".length
|
|
29500
29586
|
);
|
|
29501
|
-
return JSON.parse(
|
|
29587
|
+
return JSON.parse(fs.readFileSync(`${paraglideDirectory}/package.json`, "utf-8")).version;
|
|
29502
29588
|
})();
|
|
29503
29589
|
|
|
29504
29590
|
// src/cli/commands/init.ts
|
|
29505
29591
|
import dedent2 from "dedent";
|
|
29592
|
+
import nodeFsPromises2 from "node:fs/promises";
|
|
29506
29593
|
var DEFAULT_PROJECT_PATH = "./project.inlang";
|
|
29507
29594
|
var initCommand = new Command2().name("init").summary("Initializes inlang Paraglide-JS.").action(async () => {
|
|
29508
|
-
const
|
|
29509
|
-
|
|
29595
|
+
const repoRoot = await findRepoRoot({
|
|
29596
|
+
nodeishFs: nodeFsPromises2,
|
|
29597
|
+
path: process.cwd()
|
|
29598
|
+
});
|
|
29599
|
+
const repo = await openRepository(repoRoot ?? process.cwd(), {
|
|
29600
|
+
nodeishFs: nodeFsPromises2
|
|
29601
|
+
});
|
|
29602
|
+
const ctx = {
|
|
29603
|
+
logger: new Logger({ silent: false, prefix: false }),
|
|
29604
|
+
repo
|
|
29605
|
+
};
|
|
29606
|
+
ctx.logger.box("Welcome to inlang Paraglide-JS \u{1FA82}");
|
|
29510
29607
|
telemetry.capture({ event: "PARAGLIDE-JS init started" });
|
|
29511
|
-
await checkIfUncommittedChanges(
|
|
29512
|
-
await checkIfPackageJsonExists(
|
|
29513
|
-
const projectPath = await initializeInlangProject(
|
|
29608
|
+
await checkIfUncommittedChanges(ctx);
|
|
29609
|
+
await checkIfPackageJsonExists(ctx);
|
|
29610
|
+
const projectPath = await initializeInlangProject(ctx);
|
|
29514
29611
|
telemetry.capture({ event: "PARAGLIDE-JS init project initialized" });
|
|
29515
|
-
await addParaglideJsToDevDependencies(
|
|
29612
|
+
await addParaglideJsToDevDependencies(ctx);
|
|
29516
29613
|
telemetry.capture({ event: "PARAGLIDE-JS init added to devDependencies" });
|
|
29517
|
-
await addCompileStepToPackageJSON({ projectPath },
|
|
29614
|
+
await addCompileStepToPackageJSON({ projectPath }, ctx);
|
|
29518
29615
|
telemetry.capture({ event: "PARAGLIDE-JS init added compile commands" });
|
|
29519
|
-
await maybeChangeTsConfigModuleResolution(
|
|
29520
|
-
await maybeChangeTsConfigAllowJs(
|
|
29521
|
-
await maybeAddVsCodeExtension({ projectPath },
|
|
29616
|
+
await maybeChangeTsConfigModuleResolution(ctx);
|
|
29617
|
+
await maybeChangeTsConfigAllowJs(ctx);
|
|
29618
|
+
await maybeAddVsCodeExtension({ projectPath }, ctx);
|
|
29522
29619
|
telemetry.capture({ event: "PARAGLIDE-JS init finished" });
|
|
29523
29620
|
const absoluteSettingsPath = resolve2(projectPath, "settings.json");
|
|
29524
29621
|
const relativeSettingsFilePath = absoluteSettingsPath.replace(process.cwd(), ".");
|
|
29525
|
-
logger.box(
|
|
29622
|
+
ctx.logger.box(
|
|
29526
29623
|
dedent2`inlang Paraglide-JS has been set up sucessfully.
|
|
29527
29624
|
|
|
29528
29625
|
1. Run your install command (npm i, yarn install, etc)
|
|
@@ -29534,28 +29631,31 @@ var initCommand = new Command2().name("init").summary("Initializes inlang Paragl
|
|
|
29534
29631
|
`
|
|
29535
29632
|
);
|
|
29536
29633
|
});
|
|
29537
|
-
var initializeInlangProject = async (
|
|
29538
|
-
const existingProjectPath = await findExistingInlangProjectPath();
|
|
29634
|
+
var initializeInlangProject = async (ctx) => {
|
|
29635
|
+
const existingProjectPath = await findExistingInlangProjectPath(ctx);
|
|
29539
29636
|
if (existingProjectPath) {
|
|
29540
|
-
await existingProjectFlow({ existingProjectPath },
|
|
29637
|
+
await existingProjectFlow({ existingProjectPath }, ctx);
|
|
29541
29638
|
return existingProjectPath;
|
|
29542
29639
|
} else {
|
|
29543
|
-
await createNewProjectFlow(
|
|
29640
|
+
await createNewProjectFlow(ctx);
|
|
29544
29641
|
return DEFAULT_PROJECT_PATH;
|
|
29545
29642
|
}
|
|
29546
29643
|
};
|
|
29547
|
-
var maybeAddVsCodeExtension = async (args,
|
|
29548
|
-
|
|
29549
|
-
|
|
29550
|
-
|
|
29551
|
-
|
|
29552
|
-
|
|
29553
|
-
|
|
29644
|
+
var maybeAddVsCodeExtension = async (args, ctx) => {
|
|
29645
|
+
var _a;
|
|
29646
|
+
const isCertainlyVsCode = ((_a = process == null ? void 0 : process.env) == null ? void 0 : _a.TERM_PROGRAM) === "vscode";
|
|
29647
|
+
let response = isCertainlyVsCode;
|
|
29648
|
+
if (!isCertainlyVsCode) {
|
|
29649
|
+
response = await prompt(`Are you using VSCode?`, {
|
|
29650
|
+
type: "confirm",
|
|
29651
|
+
initial: true
|
|
29652
|
+
});
|
|
29554
29653
|
}
|
|
29654
|
+
if (response === false)
|
|
29655
|
+
return;
|
|
29555
29656
|
const project = await loadProject({
|
|
29556
29657
|
projectPath: resolve2(process.cwd(), args.projectPath),
|
|
29557
|
-
|
|
29558
|
-
nodeishFs: fs3
|
|
29658
|
+
repo: ctx.repo
|
|
29559
29659
|
});
|
|
29560
29660
|
const settings = project.settings();
|
|
29561
29661
|
if (settings.modules.some((m) => m.includes("plugin-m-function-matcher")) === false) {
|
|
@@ -29566,7 +29666,9 @@ var maybeAddVsCodeExtension = async (args, logger) => {
|
|
|
29566
29666
|
}
|
|
29567
29667
|
let extensions = {};
|
|
29568
29668
|
try {
|
|
29569
|
-
extensions = JSON5.parse(
|
|
29669
|
+
extensions = JSON5.parse(
|
|
29670
|
+
await ctx.repo.nodeishFs.readFile("./.vscode/extensions.json", { encoding: "utf-8" })
|
|
29671
|
+
);
|
|
29570
29672
|
} catch {
|
|
29571
29673
|
}
|
|
29572
29674
|
if (extensions.recommendations === void 0) {
|
|
@@ -29574,34 +29676,45 @@ var maybeAddVsCodeExtension = async (args, logger) => {
|
|
|
29574
29676
|
}
|
|
29575
29677
|
if (extensions.recommendations.includes("inlang.vs-code-extension") === false) {
|
|
29576
29678
|
extensions.recommendations.push("inlang.vs-code-extension");
|
|
29577
|
-
if (
|
|
29578
|
-
await
|
|
29679
|
+
if (await fileExists("./.vscode", ctx.repo.nodeishFs) === false) {
|
|
29680
|
+
await ctx.repo.nodeishFs.mkdir("./.vscode");
|
|
29579
29681
|
}
|
|
29580
|
-
await
|
|
29581
|
-
|
|
29682
|
+
await ctx.repo.nodeishFs.writeFile(
|
|
29683
|
+
"./.vscode/extensions.json",
|
|
29684
|
+
JSON.stringify(extensions, void 0, 2)
|
|
29685
|
+
);
|
|
29686
|
+
ctx.logger.success("Added the inlang vs code extension to the workspace recommendations.");
|
|
29582
29687
|
}
|
|
29583
29688
|
};
|
|
29584
|
-
var addParaglideJsToDevDependencies = async (
|
|
29585
|
-
const file = await
|
|
29689
|
+
var addParaglideJsToDevDependencies = async (ctx) => {
|
|
29690
|
+
const file = await ctx.repo.nodeishFs.readFile("./package.json", { encoding: "utf-8" });
|
|
29586
29691
|
const stringify = detectJsonFormatting(file);
|
|
29587
|
-
|
|
29692
|
+
let pkg = {};
|
|
29693
|
+
try {
|
|
29694
|
+
pkg = JSON.parse(file);
|
|
29695
|
+
} catch {
|
|
29696
|
+
ctx.logger.error(
|
|
29697
|
+
`Your ./package.json does not contain valid JSON. Please fix it and try again.`
|
|
29698
|
+
);
|
|
29699
|
+
process.exit(1);
|
|
29700
|
+
}
|
|
29588
29701
|
if (pkg.devDependencies === void 0) {
|
|
29589
29702
|
pkg.devDependencies = {};
|
|
29590
29703
|
}
|
|
29591
29704
|
pkg.devDependencies["@inlang/paraglide-js"] = version;
|
|
29592
|
-
await
|
|
29593
|
-
logger.success("Added @inlang/paraglide-js to the devDependencies in package.json.");
|
|
29705
|
+
await ctx.repo.nodeishFs.writeFile("./package.json", stringify(pkg));
|
|
29706
|
+
ctx.logger.success("Added @inlang/paraglide-js to the devDependencies in package.json.");
|
|
29594
29707
|
};
|
|
29595
|
-
var findExistingInlangProjectPath = async () => {
|
|
29708
|
+
var findExistingInlangProjectPath = async (ctx) => {
|
|
29596
29709
|
for (const path3 of ["./project.inlang", "../project.inlang", "../../project.inlang"]) {
|
|
29597
|
-
if (
|
|
29710
|
+
if (await fileExists(path3, ctx.repo.nodeishFs)) {
|
|
29598
29711
|
return path3;
|
|
29599
29712
|
}
|
|
29600
29713
|
continue;
|
|
29601
29714
|
}
|
|
29602
29715
|
return void 0;
|
|
29603
29716
|
};
|
|
29604
|
-
var existingProjectFlow = async (args,
|
|
29717
|
+
var existingProjectFlow = async (args, ctx) => {
|
|
29605
29718
|
const selection = await prompt(
|
|
29606
29719
|
`Do you want to use the inlang project at "${args.existingProjectPath}" or create a new project?`,
|
|
29607
29720
|
{
|
|
@@ -29613,43 +29726,41 @@ var existingProjectFlow = async (args, logger) => {
|
|
|
29613
29726
|
}
|
|
29614
29727
|
);
|
|
29615
29728
|
if (selection === "newProject") {
|
|
29616
|
-
return createNewProjectFlow(
|
|
29729
|
+
return createNewProjectFlow(ctx);
|
|
29617
29730
|
}
|
|
29618
29731
|
const project = await loadProject({
|
|
29619
29732
|
projectPath: resolve2(process.cwd(), args.existingProjectPath),
|
|
29620
|
-
|
|
29621
|
-
nodeishFs: fs3
|
|
29733
|
+
repo: ctx.repo
|
|
29622
29734
|
});
|
|
29623
29735
|
if (project.errors().length > 0) {
|
|
29624
|
-
logger.error("The project contains errors: ");
|
|
29736
|
+
ctx.logger.error("The project contains errors: ");
|
|
29625
29737
|
for (const error of project.errors()) {
|
|
29626
|
-
logger.error(error);
|
|
29738
|
+
ctx.logger.error(error);
|
|
29627
29739
|
}
|
|
29628
29740
|
process.exit(1);
|
|
29629
29741
|
}
|
|
29630
29742
|
};
|
|
29631
|
-
var createNewProjectFlow = async (
|
|
29632
|
-
logger.info(`Creating a new inlang project in the current working directory.`);
|
|
29633
|
-
await
|
|
29634
|
-
await
|
|
29743
|
+
var createNewProjectFlow = async (ctx) => {
|
|
29744
|
+
ctx.logger.info(`Creating a new inlang project in the current working directory.`);
|
|
29745
|
+
await ctx.repo.nodeishFs.mkdir(DEFAULT_PROJECT_PATH, { recursive: true });
|
|
29746
|
+
await ctx.repo.nodeishFs.writeFile(
|
|
29635
29747
|
DEFAULT_PROJECT_PATH + "/settings.json",
|
|
29636
29748
|
JSON.stringify(newProjectTemplate, void 0, 2)
|
|
29637
29749
|
);
|
|
29638
29750
|
const project = await loadProject({
|
|
29639
29751
|
projectPath: resolve2(process.cwd(), DEFAULT_PROJECT_PATH),
|
|
29640
|
-
|
|
29641
|
-
nodeishFs: fs3
|
|
29752
|
+
repo: ctx.repo
|
|
29642
29753
|
});
|
|
29643
29754
|
if (project.errors().length > 0) {
|
|
29644
|
-
logger.warn(
|
|
29755
|
+
ctx.logger.warn(
|
|
29645
29756
|
"Failed to create a new inlang project.\n\nThis is likely an internal bug. Please file an issue at https://github.com/opral/monorepo."
|
|
29646
29757
|
);
|
|
29647
29758
|
for (const error of project.errors()) {
|
|
29648
|
-
logger.error(error);
|
|
29759
|
+
ctx.logger.error(error);
|
|
29649
29760
|
}
|
|
29650
29761
|
return process.exit(1);
|
|
29651
29762
|
} else {
|
|
29652
|
-
logger.success("Successfully created a new inlang project.");
|
|
29763
|
+
ctx.logger.success("Successfully created a new inlang project.");
|
|
29653
29764
|
}
|
|
29654
29765
|
};
|
|
29655
29766
|
var newProjectTemplate = {
|
|
@@ -29676,20 +29787,21 @@ var newProjectTemplate = {
|
|
|
29676
29787
|
pathPattern: "./messages/{languageTag}.json"
|
|
29677
29788
|
}
|
|
29678
29789
|
};
|
|
29679
|
-
var checkIfPackageJsonExists = async (
|
|
29680
|
-
|
|
29681
|
-
|
|
29790
|
+
var checkIfPackageJsonExists = async (ctx) => {
|
|
29791
|
+
const exists = await fileExists("./package.json", ctx.repo.nodeishFs);
|
|
29792
|
+
if (exists === false) {
|
|
29793
|
+
ctx.logger.warn(
|
|
29682
29794
|
"No package.json found in the current working directory. Please change the working directory to the directory with a package.json file."
|
|
29683
29795
|
);
|
|
29684
29796
|
return process.exit(0);
|
|
29685
29797
|
}
|
|
29686
29798
|
};
|
|
29687
|
-
var checkIfUncommittedChanges = async (
|
|
29799
|
+
var checkIfUncommittedChanges = async (ctx) => {
|
|
29688
29800
|
try {
|
|
29689
|
-
if (
|
|
29801
|
+
if ((await execAsync("git status --porcelain")).toString().length === 0) {
|
|
29690
29802
|
return;
|
|
29691
29803
|
}
|
|
29692
|
-
logger.info(
|
|
29804
|
+
ctx.logger.info(
|
|
29693
29805
|
`You have uncommitted changes.
|
|
29694
29806
|
|
|
29695
29807
|
Please commit your changes before initializing inlang Paraglide-JS. Committing outstanding changes ensures that you don't lose any work, and see the changes the paraglide-js init command introduces.`
|
|
@@ -29710,9 +29822,9 @@ Please commit your changes before initializing inlang Paraglide-JS. Committing o
|
|
|
29710
29822
|
return;
|
|
29711
29823
|
}
|
|
29712
29824
|
};
|
|
29713
|
-
var addCompileStepToPackageJSON = async (args,
|
|
29825
|
+
var addCompileStepToPackageJSON = async (args, ctx) => {
|
|
29714
29826
|
var _a, _b;
|
|
29715
|
-
const file = await
|
|
29827
|
+
const file = await ctx.repo.nodeishFs.readFile("./package.json", { encoding: "utf-8" });
|
|
29716
29828
|
const stringify = detectJsonFormatting(file);
|
|
29717
29829
|
const pkg = JSON.parse(file);
|
|
29718
29830
|
if (pkg.scripts === void 0) {
|
|
@@ -29728,7 +29840,7 @@ var addCompileStepToPackageJSON = async (args, logger) => {
|
|
|
29728
29840
|
} else if (((_b = pkg == null ? void 0 : pkg.scripts) == null ? void 0 : _b.build.includes("paraglide-js compile")) === false) {
|
|
29729
29841
|
pkg.scripts.build = `paraglide-js compile --project ${args.projectPath} && ${pkg.scripts.build}`;
|
|
29730
29842
|
} else {
|
|
29731
|
-
logger.warn(`The "build" script in the \`package.json\` already contains a "paraglide-js compile" command.
|
|
29843
|
+
ctx.logger.warn(`The "build" script in the \`package.json\` already contains a "paraglide-js compile" command.
|
|
29732
29844
|
|
|
29733
29845
|
Please add the following command to your build script manually:
|
|
29734
29846
|
|
|
@@ -29741,30 +29853,32 @@ Please add the following command to your build script manually:
|
|
|
29741
29853
|
}
|
|
29742
29854
|
);
|
|
29743
29855
|
if (response === false) {
|
|
29744
|
-
logger.log("Please add the paraglide-js compile to your build script and try again.");
|
|
29856
|
+
ctx.logger.log("Please add the paraglide-js compile to your build script and try again.");
|
|
29745
29857
|
return process.exit(0);
|
|
29746
29858
|
} else {
|
|
29747
29859
|
return;
|
|
29748
29860
|
}
|
|
29749
29861
|
}
|
|
29750
|
-
await
|
|
29751
|
-
logger.success("Successfully added the compile command to the build step in package.json.");
|
|
29862
|
+
await ctx.repo.nodeishFs.writeFile("./package.json", stringify(pkg));
|
|
29863
|
+
ctx.logger.success("Successfully added the compile command to the build step in package.json.");
|
|
29752
29864
|
};
|
|
29753
|
-
var maybeChangeTsConfigModuleResolution = async (
|
|
29865
|
+
var maybeChangeTsConfigModuleResolution = async (ctx) => {
|
|
29754
29866
|
var _a, _b, _c;
|
|
29755
|
-
if (
|
|
29867
|
+
if (await fileExists("./tsconfig.json", ctx.repo.nodeishFs) === false) {
|
|
29756
29868
|
return;
|
|
29757
29869
|
}
|
|
29758
|
-
const file = await
|
|
29870
|
+
const file = await ctx.repo.nodeishFs.readFile("./tsconfig.json", { encoding: "utf-8" });
|
|
29759
29871
|
const tsconfig = JSON5.parse(file);
|
|
29760
29872
|
let parentTsConfig;
|
|
29761
29873
|
if (tsconfig.extends) {
|
|
29762
29874
|
try {
|
|
29763
29875
|
const parentTsConfigPath = resolve2(process.cwd(), tsconfig.extends);
|
|
29764
|
-
const parentTsConfigFile = await
|
|
29876
|
+
const parentTsConfigFile = await ctx.repo.nodeishFs.readFile(parentTsConfigPath, {
|
|
29877
|
+
encoding: "utf-8"
|
|
29878
|
+
});
|
|
29765
29879
|
parentTsConfig = JSON5.parse(parentTsConfigFile);
|
|
29766
29880
|
} catch {
|
|
29767
|
-
logger.warn(
|
|
29881
|
+
ctx.logger.warn(
|
|
29768
29882
|
`The tsconfig.json is extended from a tsconfig that couldn't be read. Maybe the file doesn't exist yet or is a NPM package. Continuing without taking the extended from tsconfig into consideration.`
|
|
29769
29883
|
);
|
|
29770
29884
|
}
|
|
@@ -29774,7 +29888,7 @@ var maybeChangeTsConfigModuleResolution = async (logger) => {
|
|
|
29774
29888
|
if (moduleResolution && invalidOptions.includes(moduleResolution.toLowerCase()) === false) {
|
|
29775
29889
|
return;
|
|
29776
29890
|
}
|
|
29777
|
-
logger.info(
|
|
29891
|
+
ctx.logger.info(
|
|
29778
29892
|
`You need to set the \`compilerOptions.moduleResolution\` to "Bundler" in the \`tsconfig.json\` file:
|
|
29779
29893
|
|
|
29780
29894
|
\`{
|
|
@@ -29793,32 +29907,34 @@ var maybeChangeTsConfigModuleResolution = async (logger) => {
|
|
|
29793
29907
|
}
|
|
29794
29908
|
);
|
|
29795
29909
|
if (response === false) {
|
|
29796
|
-
logger.warn(
|
|
29910
|
+
ctx.logger.warn(
|
|
29911
|
+
"Continuing without adjusting the tsconfig.json. This may lead to type errors."
|
|
29912
|
+
);
|
|
29797
29913
|
return;
|
|
29798
29914
|
}
|
|
29799
|
-
const file2 = await
|
|
29915
|
+
const file2 = await ctx.repo.nodeishFs.readFile("./tsconfig.json", { encoding: "utf-8" });
|
|
29800
29916
|
const tsconfig2 = JSON5.parse(file2);
|
|
29801
29917
|
if (((_c = tsconfig2 == null ? void 0 : tsconfig2.compilerOptions) == null ? void 0 : _c.moduleResolution) && tsconfig2.compilerOptions.moduleResolution.toLowerCase() === "bundler") {
|
|
29802
29918
|
isValid2 = true;
|
|
29803
29919
|
return;
|
|
29804
29920
|
} else {
|
|
29805
|
-
logger.error(
|
|
29921
|
+
ctx.logger.error(
|
|
29806
29922
|
"The compiler options have not been adjusted. Please set the `compilerOptions.moduleResolution` to `Bundler`."
|
|
29807
29923
|
);
|
|
29808
29924
|
}
|
|
29809
29925
|
}
|
|
29810
29926
|
};
|
|
29811
|
-
var maybeChangeTsConfigAllowJs = async (
|
|
29927
|
+
var maybeChangeTsConfigAllowJs = async (ctx) => {
|
|
29812
29928
|
var _a, _b;
|
|
29813
|
-
if (
|
|
29929
|
+
if (await fileExists("./tsconfig.json", ctx.repo.nodeishFs) === false) {
|
|
29814
29930
|
return;
|
|
29815
29931
|
}
|
|
29816
|
-
const file = await
|
|
29932
|
+
const file = await ctx.repo.nodeishFs.readFile("./tsconfig.json", { encoding: "utf-8" });
|
|
29817
29933
|
const tsconfig = JSON5.parse(file);
|
|
29818
29934
|
if (((_a = tsconfig.compilerOptions) == null ? void 0 : _a.allowJs) === true) {
|
|
29819
29935
|
return;
|
|
29820
29936
|
}
|
|
29821
|
-
logger.info(
|
|
29937
|
+
ctx.logger.info(
|
|
29822
29938
|
`You need to set the \`compilerOptions.allowJs\` to \`true\` in the \`tsconfig.json\` file:
|
|
29823
29939
|
|
|
29824
29940
|
\`{
|
|
@@ -29834,16 +29950,18 @@ var maybeChangeTsConfigAllowJs = async (logger) => {
|
|
|
29834
29950
|
initial: true
|
|
29835
29951
|
});
|
|
29836
29952
|
if (response === false) {
|
|
29837
|
-
logger.warn(
|
|
29953
|
+
ctx.logger.warn(
|
|
29954
|
+
"Continuing without adjusting the tsconfig.json. This may lead to type errors."
|
|
29955
|
+
);
|
|
29838
29956
|
return;
|
|
29839
29957
|
}
|
|
29840
|
-
const file2 = await
|
|
29958
|
+
const file2 = await ctx.repo.nodeishFs.readFile("./tsconfig.json", { encoding: "utf-8" });
|
|
29841
29959
|
const tsconfig2 = JSON5.parse(file2);
|
|
29842
29960
|
if (((_b = tsconfig2 == null ? void 0 : tsconfig2.compilerOptions) == null ? void 0 : _b.allowJs) === true) {
|
|
29843
29961
|
isValid2 = true;
|
|
29844
29962
|
return;
|
|
29845
29963
|
} else {
|
|
29846
|
-
logger.error(
|
|
29964
|
+
ctx.logger.error(
|
|
29847
29965
|
"The compiler options have not been adjusted. Please set the `compilerOptions.allowJs` to `true`."
|
|
29848
29966
|
);
|
|
29849
29967
|
}
|
|
@@ -29856,6 +29974,29 @@ var prompt = async (message, options) => {
|
|
|
29856
29974
|
}
|
|
29857
29975
|
return response;
|
|
29858
29976
|
};
|
|
29977
|
+
async function fileExists(filePath, nodeishFs) {
|
|
29978
|
+
try {
|
|
29979
|
+
await nodeishFs.stat(filePath);
|
|
29980
|
+
return true;
|
|
29981
|
+
} catch (error) {
|
|
29982
|
+
if (error.code === "ENOENT") {
|
|
29983
|
+
return false;
|
|
29984
|
+
} else {
|
|
29985
|
+
throw new Error(`Failed to check if file exists: ${error}`, { cause: error });
|
|
29986
|
+
}
|
|
29987
|
+
}
|
|
29988
|
+
}
|
|
29989
|
+
function execAsync(command) {
|
|
29990
|
+
return new Promise((resolve3, reject) => {
|
|
29991
|
+
childProcess.exec(command, (error, stdout) => {
|
|
29992
|
+
if (error) {
|
|
29993
|
+
reject(error);
|
|
29994
|
+
} else {
|
|
29995
|
+
resolve3(stdout);
|
|
29996
|
+
}
|
|
29997
|
+
});
|
|
29998
|
+
});
|
|
29999
|
+
}
|
|
29859
30000
|
|
|
29860
30001
|
// src/cli/main.ts
|
|
29861
30002
|
var cli = new Command3().name("paraglide-js").addCommand(compileCommand).addCommand(initCommand).showHelpAfterError().version(version);
|