@inlang/paraglide-js 2.0.0-beta.6 → 2.0.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundler-plugins/rollup.d.ts +2 -2
- package/dist/bundler-plugins/rollup.d.ts.map +1 -1
- package/dist/bundler-plugins/unplugin.d.ts +1 -1
- package/dist/bundler-plugins/unplugin.d.ts.map +1 -1
- package/dist/bundler-plugins/unplugin.js +3 -3
- package/dist/bundler-plugins/vite.d.ts +1 -1
- package/dist/cli/commands/compile/command.js +1 -1
- package/dist/cli/commands/init/command.d.ts.map +1 -1
- package/dist/cli/commands/init/command.js +13 -5
- package/dist/cli/defaults.d.ts +1 -1
- package/dist/cli/defaults.d.ts.map +1 -1
- package/dist/cli/defaults.js +5 -10
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +2 -0
- package/dist/cli/steps/add-vite-plugin.d.ts +10 -0
- package/dist/cli/steps/add-vite-plugin.d.ts.map +1 -0
- package/dist/cli/steps/add-vite-plugin.js +61 -0
- package/dist/cli/steps/add-vite-plugin.test.d.ts +2 -0
- package/dist/cli/steps/add-vite-plugin.test.d.ts.map +1 -0
- package/dist/cli/steps/add-vite-plugin.test.js +69 -0
- package/dist/cli/steps/detect-bundler.d.ts +11 -0
- package/dist/cli/steps/detect-bundler.d.ts.map +1 -0
- package/dist/cli/steps/detect-bundler.js +21 -0
- package/dist/cli/steps/detect-bundler.test.d.ts +2 -0
- package/dist/cli/steps/detect-bundler.test.d.ts.map +1 -0
- package/dist/cli/steps/detect-bundler.test.js +28 -0
- package/dist/cli/steps/initialize-inlang-project.d.ts +1 -11
- package/dist/cli/steps/initialize-inlang-project.d.ts.map +1 -1
- package/dist/cli/steps/initialize-inlang-project.js +143 -119
- package/dist/cli/steps/maybe-add-sherlock.d.ts.map +1 -1
- package/dist/cli/steps/maybe-add-sherlock.js +13 -14
- package/dist/compiler/compile.bench.d.ts +2 -0
- package/dist/compiler/compile.bench.d.ts.map +1 -0
- package/dist/compiler/compile.bench.js +39 -0
- package/dist/compiler/compile.d.ts +2 -2
- package/dist/compiler/compile.d.ts.map +1 -1
- package/dist/compiler/compile.js +6 -5
- package/dist/compiler/compile.test.js +24 -0
- package/dist/compiler/compileBundle.d.ts +1 -0
- package/dist/compiler/compileBundle.d.ts.map +1 -1
- package/dist/compiler/compileBundle.js +37 -11
- package/dist/compiler/compileBundle.test.d.ts +2 -0
- package/dist/compiler/compileBundle.test.d.ts.map +1 -0
- package/dist/compiler/compileBundle.test.js +57 -0
- package/dist/compiler/compileProject.d.ts +22 -4
- package/dist/compiler/compileProject.d.ts.map +1 -1
- package/dist/compiler/compileProject.js +8 -41
- package/dist/compiler/compileProject.test.js +50 -44
- package/dist/compiler/jsdoc-types.d.ts +9 -0
- package/dist/compiler/jsdoc-types.d.ts.map +1 -0
- package/dist/compiler/{jsDocComment.js → jsdoc-types.js} +4 -11
- package/dist/compiler/output-structure/locale-modules.d.ts +1 -1
- package/dist/compiler/output-structure/locale-modules.d.ts.map +1 -1
- package/dist/compiler/output-structure/locale-modules.js +11 -9
- package/dist/compiler/output-structure/locale-modules.test.js +6 -2
- package/dist/compiler/output-structure/message-modules.d.ts +1 -1
- package/dist/compiler/output-structure/message-modules.d.ts.map +1 -1
- package/dist/compiler/output-structure/message-modules.js +15 -12
- package/dist/compiler/output-structure/message-modules.test.js +3 -1
- package/dist/compiler/registry.d.ts +1 -1
- package/dist/compiler/registry.d.ts.map +1 -1
- package/dist/compiler/registry.js +36 -5
- package/dist/compiler/runtime.d.ts +1 -1
- package/dist/compiler/runtime.d.ts.map +1 -1
- package/dist/compiler/runtime.js +159 -11
- package/dist/services/env-variables/index.js +1 -1
- package/dist/services/file-handling/write-output.d.ts.map +1 -1
- package/dist/services/file-handling/write-output.js +2 -8
- package/dist/services/file-handling/write-output.test.js +45 -47
- package/dist/services/logger/index.d.ts +0 -4
- package/dist/services/logger/index.d.ts.map +1 -1
- package/dist/services/logger/index.js +0 -9
- package/package.json +18 -16
- package/dist/compiler/emit-dts.d.ts +0 -7
- package/dist/compiler/emit-dts.d.ts.map +0 -1
- package/dist/compiler/emit-dts.js +0 -56
- package/dist/compiler/jsDocComment.d.ts +0 -9
- package/dist/compiler/jsDocComment.d.ts.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const paraglideRollupPlugin: (options: {
|
|
2
2
|
project: string;
|
|
3
3
|
outdir: string;
|
|
4
|
-
|
|
5
|
-
}) => import("
|
|
4
|
+
compilerOptions?: import("../compiler/compileProject.js").ParaglideCompilerOptions;
|
|
5
|
+
}) => import("unplugin").RollupPlugin<any> | import("unplugin").RollupPlugin<any>[];
|
|
6
6
|
//# sourceMappingURL=rollup.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollup.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/rollup.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB;;;;
|
|
1
|
+
{"version":3,"file":"rollup.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/rollup.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB;;;;mFAAsC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unplugin.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/unplugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAO9E,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC;IAC7C;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,
|
|
1
|
+
{"version":3,"file":"unplugin.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/unplugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAO9E,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC;IAC7C;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,wBAAwB,CAAC;CAC3C,CAwCC,CAAC"}
|
|
@@ -10,7 +10,7 @@ export const unpluginFactory = (args) => ({
|
|
|
10
10
|
await compile({
|
|
11
11
|
project: args.project,
|
|
12
12
|
outdir: args.outdir,
|
|
13
|
-
|
|
13
|
+
compilerOptions: args.compilerOptions,
|
|
14
14
|
fs: wrappedFs,
|
|
15
15
|
});
|
|
16
16
|
for (const path of Array.from(readFiles)) {
|
|
@@ -24,7 +24,7 @@ export const unpluginFactory = (args) => ({
|
|
|
24
24
|
await compile({
|
|
25
25
|
project: args.project,
|
|
26
26
|
outdir: args.outdir,
|
|
27
|
-
|
|
27
|
+
compilerOptions: args.compilerOptions,
|
|
28
28
|
fs: wrappedFs,
|
|
29
29
|
});
|
|
30
30
|
}
|
|
@@ -36,7 +36,7 @@ export const unpluginFactory = (args) => ({
|
|
|
36
36
|
await compile({
|
|
37
37
|
project: args.project,
|
|
38
38
|
outdir: args.outdir,
|
|
39
|
-
|
|
39
|
+
compilerOptions: args.compilerOptions,
|
|
40
40
|
fs: wrappedFs,
|
|
41
41
|
});
|
|
42
42
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const paraglideVitePlugin: (options: {
|
|
2
2
|
project: string;
|
|
3
3
|
outdir: string;
|
|
4
|
-
|
|
4
|
+
compilerOptions?: import("../compiler/compileProject.js").ParaglideCompilerOptions;
|
|
5
5
|
}) => import("vite").Plugin<any> | import("vite").Plugin<any>[];
|
|
6
6
|
//# sourceMappingURL=vite.d.ts.map
|
|
@@ -31,7 +31,7 @@ export const compileCommand = new Command()
|
|
|
31
31
|
if (errors.length > 0) {
|
|
32
32
|
logger.warn(`But the project reported the following warnings and/or errors that might have influenced compilation:`);
|
|
33
33
|
for (const error of errors) {
|
|
34
|
-
logger.
|
|
34
|
+
logger.error(`${error}`);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
process.exit(0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/init/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAS3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/init/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAS3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAM9C,eAAO,MAAM,WAAW,SA8DrB,CAAC;AAEJ,eAAO,MAAM,+BAA+B,EAAE,OAAO,CACpD;IACC,EAAE,EAAE,cAAc,kBAAkB,CAAC,CAAC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;CACxB,EACD,OAAO,CAYP,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,OAAO,CAC7C;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,cAAc,kBAAkB,CAAC,CAAA;CAAE,EACzD;IAAE,eAAe,EAAE,MAAM,CAAA;CAAE,CAU3B,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,OAAO,CAChD;IACC,EAAE,EAAE,cAAc,kBAAkB,CAAC,CAAC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;CACxB,EACD,OAAO,CAuDP,CAAC"}
|
|
@@ -12,12 +12,14 @@ import { updatePackageJson } from "../../steps/update-package-json.js";
|
|
|
12
12
|
import { runCompiler } from "../../steps/run-compiler.js";
|
|
13
13
|
import nodeFs from "node:fs";
|
|
14
14
|
import { ENV_VARIABLES } from "../../../services/env-variables/index.js";
|
|
15
|
+
import { detectBundler } from "../../steps/detect-bundler.js";
|
|
16
|
+
import { addVitePlugin } from "../../steps/add-vite-plugin.js";
|
|
15
17
|
export const initCommand = new Command()
|
|
16
18
|
.name("init")
|
|
17
19
|
.summary("Initializes inlang Paraglide-JS.")
|
|
18
20
|
.action(async () => {
|
|
19
21
|
const logger = new Logger({ silent: false, prefix: false });
|
|
20
|
-
logger.box("Welcome to inlang Paraglide
|
|
22
|
+
logger.box("Welcome to inlang Paraglide JS 🪂");
|
|
21
23
|
const ctx = {
|
|
22
24
|
logger,
|
|
23
25
|
fs: nodeFs.promises,
|
|
@@ -29,7 +31,13 @@ export const initCommand = new Command()
|
|
|
29
31
|
const ctx3 = await initializeInlangProject(ctx2);
|
|
30
32
|
const ctx4 = await promptForOutdir(ctx3);
|
|
31
33
|
const ctx5 = await addParaglideJsToDevDependencies(ctx4);
|
|
32
|
-
const ctx6 = await
|
|
34
|
+
const ctx6 = await detectBundler(ctx5);
|
|
35
|
+
if (ctx6.bundler === "vite") {
|
|
36
|
+
await addVitePlugin(ctx6);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
await addCompileStepToPackageJSON(ctx6);
|
|
40
|
+
}
|
|
33
41
|
const ctx7 = await maybeChangeTsConfig(ctx6);
|
|
34
42
|
const ctx8 = await maybeAddSherlock(ctx7);
|
|
35
43
|
try {
|
|
@@ -45,15 +53,15 @@ export const initCommand = new Command()
|
|
|
45
53
|
`inlang Paraglide-JS has been set up sucessfully.`,
|
|
46
54
|
"\n",
|
|
47
55
|
`1. Run your install command (npm i, yarn install, etc)`,
|
|
48
|
-
`2.
|
|
49
|
-
`3.
|
|
50
|
-
`4. Done :) Happy paragliding 🪂`,
|
|
56
|
+
`2. Run the build script (npm run build, or similar.)`,
|
|
57
|
+
`3. Define the locales in ${relativeSettingsFilePath}`,
|
|
51
58
|
"\n",
|
|
52
59
|
"\n",
|
|
53
60
|
`For questions and feedback, visit`,
|
|
54
61
|
`https://github.com/opral/inlang-paraglide-js/issues`,
|
|
55
62
|
].join("\n");
|
|
56
63
|
ctx.logger.box(successMessage);
|
|
64
|
+
process.exit(0);
|
|
57
65
|
});
|
|
58
66
|
export const addParaglideJsToDevDependencies = async (ctx) => {
|
|
59
67
|
const ctx1 = await updatePackageJson({
|
package/dist/cli/defaults.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/cli/defaults.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/cli/defaults.ts"],"names":[],"mappings":"AAmBA;;GAEG;AACH,wBAAgB,qBAAqB;;;;;;;;EAEpC;AAED,eAAO,MAAM,oBAAoB,qBAAqB,CAAC;AACvD,eAAO,MAAM,cAAc,oBAAoB,CAAC"}
|
package/dist/cli/defaults.js
CHANGED
|
@@ -5,8 +5,11 @@
|
|
|
5
5
|
const defaultProjectSettings = {
|
|
6
6
|
$schema: "https://inlang.com/schema/project-settings",
|
|
7
7
|
baseLocale: "en",
|
|
8
|
-
locales: ["en"],
|
|
9
|
-
modules: [
|
|
8
|
+
locales: ["en", "de"],
|
|
9
|
+
modules: [
|
|
10
|
+
"https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@3/dist/index.js",
|
|
11
|
+
"https://cdn.jsdelivr.net/npm/@inlang/plugin-m-function-matcher@1/dist/index.js",
|
|
12
|
+
],
|
|
10
13
|
"plugin.inlang.messageFormat": {
|
|
11
14
|
pathPattern: "./messages/{locale}.json",
|
|
12
15
|
},
|
|
@@ -15,14 +18,6 @@ const defaultProjectSettings = {
|
|
|
15
18
|
* @returns A new copy of the default project template that is safe to mutate.
|
|
16
19
|
*/
|
|
17
20
|
export function getNewProjectTemplate() {
|
|
18
|
-
if (!("structuredClone" in globalThis)) {
|
|
19
|
-
try {
|
|
20
|
-
return JSON.parse(JSON.stringify(defaultProjectSettings));
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
throw new Error("structuredClone is not supported in your Node Version. Please use version 17 or higher");
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
21
|
return structuredClone(defaultProjectSettings);
|
|
27
22
|
}
|
|
28
23
|
export const DEFAULT_PROJECT_PATH = "./project.inlang";
|
package/dist/cli/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,eAAO,MAAM,GAAG,SAK8B,CAAC;AAE/C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC"}
|
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
import { compileCommand } from "./commands/compile/command.js";
|
|
3
3
|
import { ENV_VARIABLES } from "../services/env-variables/index.js";
|
|
4
|
+
import { initCommand } from "./commands/init/command.js";
|
|
4
5
|
export { checkForUncommittedChanges } from "./steps/check-for-uncomitted-changes.js";
|
|
5
6
|
export { initializeInlangProject } from "./steps/initialize-inlang-project.js";
|
|
6
7
|
export { maybeAddSherlock } from "./steps/maybe-add-sherlock.js";
|
|
@@ -11,6 +12,7 @@ export { runCompiler } from "./steps/run-compiler.js";
|
|
|
11
12
|
export const cli = new Command()
|
|
12
13
|
.name("paraglide-js")
|
|
13
14
|
.addCommand(compileCommand)
|
|
15
|
+
.addCommand(initCommand)
|
|
14
16
|
.showHelpAfterError()
|
|
15
17
|
.version(ENV_VARIABLES.PARJS_PACKAGE_VERSION);
|
|
16
18
|
export * as Utils from "./utils.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Logger } from "../../services/logger/index.js";
|
|
2
|
+
import type { CliStep } from "../utils.js";
|
|
3
|
+
export declare const addVitePlugin: CliStep<{
|
|
4
|
+
fs: typeof import("node:fs/promises");
|
|
5
|
+
projectPath: string;
|
|
6
|
+
outdir: string;
|
|
7
|
+
logger?: Logger;
|
|
8
|
+
configPath: string;
|
|
9
|
+
}, unknown>;
|
|
10
|
+
//# sourceMappingURL=add-vite-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-vite-plugin.d.ts","sourceRoot":"","sources":["../../../src/cli/steps/add-vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,eAAO,MAAM,aAAa,EAAE,OAAO,CAClC;IACC,EAAE,EAAE,cAAc,kBAAkB,CAAC,CAAC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACnB,EACD,OAAO,CAoCP,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export const addVitePlugin = async (ctx) => {
|
|
2
|
+
try {
|
|
3
|
+
const fileContent = await ctx.fs.readFile(ctx.configPath, {
|
|
4
|
+
encoding: "utf-8",
|
|
5
|
+
});
|
|
6
|
+
const result = updateViteConfig({
|
|
7
|
+
config: fileContent,
|
|
8
|
+
projectPath: ctx.projectPath,
|
|
9
|
+
outdir: ctx.outdir,
|
|
10
|
+
});
|
|
11
|
+
if (result.ok) {
|
|
12
|
+
await ctx.fs.writeFile(ctx.configPath, result.updated);
|
|
13
|
+
ctx.logger?.success("Added the Paraglide JS vite plugin to the vite config.");
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
const msg = [
|
|
17
|
+
"Failed to add the Paraglide JS vite plugin in vite.config.js.",
|
|
18
|
+
"Reason: " + result.reason,
|
|
19
|
+
"",
|
|
20
|
+
"Please add the plugin manually.",
|
|
21
|
+
].join("\n");
|
|
22
|
+
ctx.logger?.warn(msg);
|
|
23
|
+
return ctx;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
ctx.logger?.error(`Failed to add the Paraglide JS vite plugin to ${ctx.configPath}.`);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
return ctx;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* @private Only exported for testings
|
|
34
|
+
*/
|
|
35
|
+
function updateViteConfig(args) {
|
|
36
|
+
if (args.config.includes("@inlang/paraglide-js")) {
|
|
37
|
+
return {
|
|
38
|
+
ok: false,
|
|
39
|
+
reason: "Already present",
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const PLUGINS_REGEX = /plugins\s*:\s*\[/g;
|
|
43
|
+
const match = PLUGINS_REGEX.exec(args.config);
|
|
44
|
+
if (!match) {
|
|
45
|
+
return {
|
|
46
|
+
ok: false,
|
|
47
|
+
reason: "Could not find the plugins array",
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const endIndex = match.index + match[0].length;
|
|
51
|
+
const before = args.config.slice(0, endIndex);
|
|
52
|
+
const after = args.config.slice(endIndex);
|
|
53
|
+
const updatedConfig = "import { paraglideVitePlugin } from '@inlang/paraglide-js'\n" +
|
|
54
|
+
before +
|
|
55
|
+
`paraglideVitePlugin({ project: '${args.projectPath}', outdir: '${args.outdir}' }),` +
|
|
56
|
+
after;
|
|
57
|
+
return {
|
|
58
|
+
ok: true,
|
|
59
|
+
updated: updatedConfig,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-vite-plugin.test.d.ts","sourceRoot":"","sources":["../../../src/cli/steps/add-vite-plugin.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { addVitePlugin } from "./add-vite-plugin.js";
|
|
3
|
+
import { memfs } from "memfs";
|
|
4
|
+
test("updates a vite.config.ts", async () => {
|
|
5
|
+
const config = `import { sveltekit } from "@sveltejs/kit/vite"
|
|
6
|
+
import { defineConfig } from "vite"
|
|
7
|
+
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
plugins: [sveltekit()],
|
|
10
|
+
})
|
|
11
|
+
`;
|
|
12
|
+
const fs = memfs({
|
|
13
|
+
"/vite.config.ts": config,
|
|
14
|
+
}).fs;
|
|
15
|
+
await addVitePlugin({
|
|
16
|
+
fs: fs.promises,
|
|
17
|
+
outdir: "./src/paraglide",
|
|
18
|
+
projectPath: "./project.inlang",
|
|
19
|
+
configPath: "/vite.config.ts",
|
|
20
|
+
});
|
|
21
|
+
const updatedConfig = await fs.promises.readFile("/vite.config.ts", {
|
|
22
|
+
encoding: "utf-8",
|
|
23
|
+
});
|
|
24
|
+
expect(updatedConfig).toMatchInlineSnapshot(`
|
|
25
|
+
"import { paraglideVitePlugin } from '@inlang/paraglide-js'
|
|
26
|
+
import { sveltekit } from "@sveltejs/kit/vite"
|
|
27
|
+
import { defineConfig } from "vite"
|
|
28
|
+
|
|
29
|
+
export default defineConfig({
|
|
30
|
+
plugins: [paraglideVitePlugin({ project: './project.inlang', outdir: './src/paraglide' }),sveltekit()],
|
|
31
|
+
})
|
|
32
|
+
"
|
|
33
|
+
`);
|
|
34
|
+
});
|
|
35
|
+
test("doesn't update configs where the paraglide plugin is already present", async () => {
|
|
36
|
+
const config = `
|
|
37
|
+
import { sveltekit } from "@sveltejs/kit/vite"
|
|
38
|
+
import { paraglideVitePlugin } from "@inlang/paraglide-js"
|
|
39
|
+
import { visualizer } from "rollup-plugin-visualizer"
|
|
40
|
+
import { defineConfig } from "vite"
|
|
41
|
+
|
|
42
|
+
export default defineConfig({
|
|
43
|
+
plugins: [
|
|
44
|
+
paraglideVitePlugin({
|
|
45
|
+
project: "./project.inlang",
|
|
46
|
+
outdir: "./src/paraglide",
|
|
47
|
+
}),
|
|
48
|
+
sveltekit(),
|
|
49
|
+
visualizer({
|
|
50
|
+
filename: "stats.html",
|
|
51
|
+
emitFile: true,
|
|
52
|
+
}),
|
|
53
|
+
],
|
|
54
|
+
})
|
|
55
|
+
`;
|
|
56
|
+
const fs = memfs({
|
|
57
|
+
"/vite.config.ts": config,
|
|
58
|
+
}).fs;
|
|
59
|
+
await addVitePlugin({
|
|
60
|
+
fs: fs.promises,
|
|
61
|
+
outdir: "./src/paraglide",
|
|
62
|
+
projectPath: "./project.inlang",
|
|
63
|
+
configPath: "/vite.config.ts",
|
|
64
|
+
});
|
|
65
|
+
const updatedConfig = await fs.promises.readFile("/vite.config.ts", {
|
|
66
|
+
encoding: "utf-8",
|
|
67
|
+
});
|
|
68
|
+
expect(updatedConfig).toMatch(config);
|
|
69
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CliStep } from "../utils.js";
|
|
2
|
+
export declare const detectBundler: CliStep<{
|
|
3
|
+
fs: typeof import("node:fs/promises");
|
|
4
|
+
}, {
|
|
5
|
+
bundler?: undefined;
|
|
6
|
+
configPath?: undefined;
|
|
7
|
+
} | {
|
|
8
|
+
bundler: "vite";
|
|
9
|
+
configPath: string;
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=detect-bundler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect-bundler.d.ts","sourceRoot":"","sources":["../../../src/cli/steps/detect-bundler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,eAAO,MAAM,aAAa,EAAE,OAAO,CAClC;IAAE,EAAE,EAAE,cAAc,kBAAkB,CAAC,CAAA;CAAE,EACvC;IACA,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,UAAU,CAAC,EAAE,SAAS,CAAC;CACtB,GACD;IACA,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CAClB,CA0BH,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const detectBundler = async (ctx) => {
|
|
2
|
+
const potentialViteConfigPaths = ["./vite.config.js", "./vite.config.ts"];
|
|
3
|
+
const viteConfigPath = await Promise.all(potentialViteConfigPaths.map(async (path) => ({
|
|
4
|
+
path,
|
|
5
|
+
exists: await ctx.fs
|
|
6
|
+
.access(path)
|
|
7
|
+
.then(() => true)
|
|
8
|
+
.catch(() => false),
|
|
9
|
+
}))).then((results) => results.find((result) => result.exists)?.path);
|
|
10
|
+
if (!viteConfigPath) {
|
|
11
|
+
return {
|
|
12
|
+
...ctx,
|
|
13
|
+
bundler: undefined,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
...ctx,
|
|
18
|
+
bundler: "vite",
|
|
19
|
+
configPath: viteConfigPath,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect-bundler.test.d.ts","sourceRoot":"","sources":["../../../src/cli/steps/detect-bundler.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { memfs } from "memfs";
|
|
3
|
+
import { describe } from "node:test";
|
|
4
|
+
import { detectBundler } from "./detect-bundler.js";
|
|
5
|
+
describe("vite", async () => {
|
|
6
|
+
test("detects vite.config.js ", async () => {
|
|
7
|
+
const fs = memfs({
|
|
8
|
+
"/vite.config.js": "mock",
|
|
9
|
+
}).fs;
|
|
10
|
+
process.cwd = () => "/";
|
|
11
|
+
const result = await detectBundler({
|
|
12
|
+
fs: fs.promises,
|
|
13
|
+
});
|
|
14
|
+
expect(result.bundler).toBe("vite");
|
|
15
|
+
expect(result.configPath).toBe("./vite.config.js");
|
|
16
|
+
});
|
|
17
|
+
test("detects vite.config.ts ", async () => {
|
|
18
|
+
const fs = memfs({
|
|
19
|
+
"/vite.config.ts": "mock",
|
|
20
|
+
}).fs;
|
|
21
|
+
process.cwd = () => "/";
|
|
22
|
+
const result = await detectBundler({
|
|
23
|
+
fs: fs.promises,
|
|
24
|
+
});
|
|
25
|
+
expect(result.bundler).toBe("vite");
|
|
26
|
+
expect(result.configPath).toBe("./vite.config.ts");
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -12,16 +12,6 @@ export declare const initializeInlangProject: CliStep<{
|
|
|
12
12
|
/** Relative path to the project */
|
|
13
13
|
projectPath: string;
|
|
14
14
|
}>;
|
|
15
|
-
export declare const existingProjectFlow: (ctx: {
|
|
16
|
-
/** An array of absolute paths to existing projects. */
|
|
17
|
-
existingProjectPaths: string[];
|
|
18
|
-
fs: typeof fs.promises;
|
|
19
|
-
syncFs: typeof fs;
|
|
20
|
-
logger: Logger;
|
|
21
|
-
}) => Promise<{
|
|
22
|
-
project: InlangProject;
|
|
23
|
-
projectPath: string;
|
|
24
|
-
}>;
|
|
25
15
|
export declare const createNewProjectFlow: (ctx: {
|
|
26
16
|
fs: typeof fs.promises;
|
|
27
17
|
syncFs: typeof fs;
|
|
@@ -43,7 +33,7 @@ export declare const createNewProjectFlow: (ctx: {
|
|
|
43
33
|
*/
|
|
44
34
|
export declare function getCommonPrefix(strings: string[]): string;
|
|
45
35
|
/**
|
|
46
|
-
* Follows the IETF BCP 47
|
|
36
|
+
* Follows the IETF BCP 47 locale schema with modifications.
|
|
47
37
|
*/
|
|
48
38
|
export declare const pattern = "^((?<grandfathered>(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((?<language>([A-Za-z]{2,3}(-(?<extlang>[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?))(-(?<script>[A-Za-z]{4}))?(-(?<region>[A-Za-z]{2}|[0-9]{3}))?(-(?<variant>[A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*))$";
|
|
49
39
|
//# sourceMappingURL=initialize-inlang-project.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize-inlang-project.d.ts","sourceRoot":"","sources":["../../../src/cli/steps/initialize-inlang-project.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"initialize-inlang-project.d.ts","sourceRoot":"","sources":["../../../src/cli/steps/initialize-inlang-project.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,KAAK,aAAa,EAClB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,EAAE,MAAM,SAAS,CAAC;AAGzB,eAAO,MAAM,uBAAuB,EAAE,OAAO,CAC5C;IACC,EAAE,EAAE,OAAO,EAAE,CAAC,QAAQ,CAAC;IACvB,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACb,EACD;IACC,OAAO,EAAE,aAAa,CAAC;IACvB,mCAAmC;IACnC,WAAW,EAAE,MAAM,CAAC;CACpB,CA2BD,CAAC;AAgHF,eAAO,MAAM,oBAAoB,QAAe;IAC/C,EAAE,EAAE,OAAO,EAAE,CAAC,QAAQ,CAAC;IACvB,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CACf,KAAG,OAAO,CAAC;IACX,OAAO,EAAE,aAAa,CAAC;IACvB,8CAA8C;IAC9C,WAAW,EAAE,MAAM,CAAC;CACpB,CA4EA,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAazD;AAcD;;GAEG;AACH,eAAO,MAAM,OAAO,sbACga,CAAC"}
|