@inlang/paraglide-js 2.0.0-beta.9 → 2.0.0
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 +7 -56
- package/dist/bundler-plugins/esbuild.d.ts +2 -0
- package/dist/bundler-plugins/esbuild.d.ts.map +1 -0
- package/dist/bundler-plugins/esbuild.js +3 -0
- package/dist/bundler-plugins/index.d.ts +5 -1
- package/dist/bundler-plugins/index.d.ts.map +1 -1
- package/dist/bundler-plugins/index.js +5 -1
- package/dist/bundler-plugins/rolldown.d.ts +2 -0
- package/dist/bundler-plugins/rolldown.d.ts.map +1 -0
- package/dist/bundler-plugins/rolldown.js +3 -0
- package/dist/bundler-plugins/rollup.d.ts +1 -1
- package/dist/bundler-plugins/rollup.d.ts.map +1 -1
- package/dist/bundler-plugins/rspack.d.ts +2 -0
- package/dist/bundler-plugins/rspack.d.ts.map +1 -0
- package/dist/bundler-plugins/rspack.js +3 -0
- package/dist/bundler-plugins/unplugin.d.ts +2 -2
- package/dist/bundler-plugins/unplugin.d.ts.map +1 -1
- package/dist/bundler-plugins/unplugin.js +91 -28
- package/dist/bundler-plugins/vite.d.ts +1 -1
- package/dist/bundler-plugins/vite.d.ts.map +1 -1
- package/dist/bundler-plugins/webpack.d.ts +2 -0
- package/dist/bundler-plugins/webpack.d.ts.map +1 -0
- package/dist/bundler-plugins/webpack.js +3 -0
- package/dist/cli/commands/compile/command.d.ts.map +1 -1
- package/dist/cli/commands/compile/command.js +23 -24
- package/dist/cli/commands/init/command.d.ts +0 -20
- package/dist/cli/commands/init/command.d.ts.map +1 -1
- package/dist/cli/commands/init/command.js +18 -42
- package/dist/cli/defaults.js +2 -2
- package/dist/cli/index.d.ts +0 -9
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +0 -9
- package/dist/cli/steps/initialize-inlang-project.d.ts.map +1 -1
- package/dist/cli/steps/initialize-inlang-project.js +2 -3
- package/dist/cli/steps/maybe-add-machine-translation.d.ts +16 -0
- package/dist/cli/steps/maybe-add-machine-translation.d.ts.map +1 -0
- package/dist/cli/steps/maybe-add-machine-translation.js +48 -0
- package/dist/cli/steps/update-ts-config.d.ts +2 -2
- package/dist/cli/steps/update-ts-config.d.ts.map +1 -1
- package/dist/cli/steps/update-ts-config.js +100 -80
- package/dist/compiler/{compileBundle.d.ts → compile-bundle.d.ts} +2 -4
- package/dist/compiler/compile-bundle.d.ts.map +1 -0
- package/dist/compiler/compile-bundle.js +60 -0
- package/dist/compiler/compile-bundle.test.d.ts +2 -0
- package/dist/compiler/compile-bundle.test.d.ts.map +1 -0
- package/dist/compiler/compile-bundle.test.js +97 -0
- package/dist/compiler/compile-local-variable.d.ts +17 -0
- package/dist/compiler/compile-local-variable.d.ts.map +1 -0
- package/dist/compiler/compile-local-variable.js +38 -0
- package/dist/compiler/compile-local-variable.test.d.ts +2 -0
- package/dist/compiler/compile-local-variable.test.d.ts.map +1 -0
- package/dist/compiler/compile-local-variable.test.js +71 -0
- package/dist/compiler/compile-message.d.ts +8 -0
- package/dist/compiler/compile-message.d.ts.map +1 -0
- package/dist/compiler/compile-message.js +89 -0
- package/dist/compiler/compile-message.test.d.ts +2 -0
- package/dist/compiler/compile-message.test.d.ts.map +1 -0
- package/dist/compiler/compile-message.test.js +308 -0
- package/dist/compiler/compile-pattern.d.ts +20 -0
- package/dist/compiler/compile-pattern.d.ts.map +1 -0
- package/dist/compiler/compile-pattern.js +40 -0
- package/dist/compiler/compile-pattern.test.d.ts +2 -0
- package/dist/compiler/compile-pattern.test.d.ts.map +1 -0
- package/dist/compiler/compile-pattern.test.js +75 -0
- package/dist/compiler/compile-project.d.ts +18 -0
- package/dist/compiler/compile-project.d.ts.map +1 -0
- package/dist/compiler/compile-project.js +92 -0
- package/dist/compiler/compile-project.test.d.ts +2 -0
- package/dist/compiler/compile-project.test.d.ts.map +1 -0
- package/dist/compiler/{compileProject.test.js → compile-project.test.js} +380 -102
- package/dist/compiler/compile.d.ts +6 -27
- package/dist/compiler/compile.d.ts.map +1 -1
- package/dist/compiler/compile.js +53 -23
- package/dist/compiler/compile.test.js +156 -1
- package/dist/compiler/compiler-options.d.ts +232 -0
- package/dist/compiler/compiler-options.d.ts.map +1 -0
- package/dist/compiler/compiler-options.js +13 -0
- package/dist/compiler/create-paraglide.d.ts +37 -0
- package/dist/compiler/create-paraglide.d.ts.map +1 -0
- package/dist/compiler/create-paraglide.js +97 -0
- package/dist/compiler/create-paraglide.test.d.ts +2 -0
- package/dist/compiler/create-paraglide.test.d.ts.map +1 -0
- package/dist/compiler/create-paraglide.test.js +75 -0
- package/dist/compiler/index.d.ts +9 -6
- package/dist/compiler/index.d.ts.map +1 -1
- package/dist/compiler/index.js +6 -4
- package/dist/compiler/jsdoc-types.d.ts +9 -3
- package/dist/compiler/jsdoc-types.d.ts.map +1 -1
- package/dist/compiler/jsdoc-types.js +16 -13
- package/dist/compiler/output-structure/locale-modules.d.ts +3 -2
- package/dist/compiler/output-structure/locale-modules.d.ts.map +1 -1
- package/dist/compiler/output-structure/locale-modules.js +21 -26
- package/dist/compiler/output-structure/locale-modules.test.js +3 -9
- package/dist/compiler/output-structure/message-modules.d.ts +3 -2
- package/dist/compiler/output-structure/message-modules.d.ts.map +1 -1
- package/dist/compiler/output-structure/message-modules.js +60 -49
- package/dist/compiler/output-structure/message-modules.test.js +44 -7
- package/dist/compiler/registry.d.ts +11 -11
- package/dist/compiler/registry.d.ts.map +1 -1
- package/dist/compiler/registry.js +24 -66
- package/dist/compiler/runtime/assert-is-locale.d.ts +9 -0
- package/dist/compiler/runtime/assert-is-locale.d.ts.map +1 -0
- package/dist/compiler/runtime/assert-is-locale.js +15 -0
- package/dist/compiler/runtime/assert-is-locale.test.d.ts +2 -0
- package/dist/compiler/runtime/assert-is-locale.test.d.ts.map +1 -0
- package/dist/compiler/runtime/assert-is-locale.test.js +39 -0
- package/dist/compiler/runtime/create-runtime.d.ts +18 -0
- package/dist/compiler/runtime/create-runtime.d.ts.map +1 -0
- package/dist/compiler/runtime/create-runtime.js +103 -0
- package/dist/compiler/runtime/extract-locale-from-cookie.d.ts +10 -0
- package/dist/compiler/runtime/extract-locale-from-cookie.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-cookie.js +21 -0
- package/dist/compiler/runtime/extract-locale-from-cookie.test.d.ts +2 -0
- package/dist/compiler/runtime/extract-locale-from-cookie.test.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-cookie.test.js +58 -0
- package/dist/compiler/runtime/extract-locale-from-request.d.ts +17 -0
- package/dist/compiler/runtime/extract-locale-from-request.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-request.js +91 -0
- package/dist/compiler/runtime/extract-locale-from-request.test.d.ts +2 -0
- package/dist/compiler/runtime/extract-locale-from-request.test.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-request.test.js +260 -0
- package/dist/compiler/runtime/extract-locale-from-url.d.ts +8 -0
- package/dist/compiler/runtime/extract-locale-from-url.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-url.js +47 -0
- package/dist/compiler/runtime/extract-locale-from-url.test.d.ts +2 -0
- package/dist/compiler/runtime/extract-locale-from-url.test.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-url.test.js +137 -0
- package/dist/compiler/runtime/generate-static-localized-urls.d.ts +24 -0
- package/dist/compiler/runtime/generate-static-localized-urls.d.ts.map +1 -0
- package/dist/compiler/runtime/generate-static-localized-urls.js +91 -0
- package/dist/compiler/runtime/generate-static-localized-urls.test.d.ts +2 -0
- package/dist/compiler/runtime/generate-static-localized-urls.test.d.ts.map +1 -0
- package/dist/compiler/runtime/generate-static-localized-urls.test.js +190 -0
- package/dist/compiler/runtime/get-locale.d.ts +30 -0
- package/dist/compiler/runtime/get-locale.d.ts.map +1 -0
- package/dist/compiler/runtime/get-locale.js +120 -0
- package/dist/compiler/runtime/get-locale.test.d.ts +2 -0
- package/dist/compiler/runtime/get-locale.test.d.ts.map +1 -0
- package/dist/compiler/runtime/get-locale.test.js +200 -0
- package/dist/compiler/runtime/get-url-origin.d.ts +20 -0
- package/dist/compiler/runtime/get-url-origin.d.ts.map +1 -0
- package/dist/compiler/runtime/get-url-origin.js +30 -0
- package/dist/compiler/runtime/get-url-origin.test.d.ts +2 -0
- package/dist/compiler/runtime/get-url-origin.test.d.ts.map +1 -0
- package/dist/compiler/runtime/get-url-origin.test.js +28 -0
- package/dist/compiler/runtime/is-locale.d.ts +15 -0
- package/dist/compiler/runtime/is-locale.d.ts.map +1 -0
- package/dist/compiler/runtime/is-locale.js +17 -0
- package/dist/compiler/runtime/localize-href.d.ts +82 -0
- package/dist/compiler/runtime/localize-href.d.ts.map +1 -0
- package/dist/compiler/runtime/localize-href.js +108 -0
- package/dist/compiler/runtime/localize-href.test.d.ts +2 -0
- package/dist/compiler/runtime/localize-href.test.d.ts.map +1 -0
- package/dist/compiler/runtime/localize-href.test.js +160 -0
- package/dist/compiler/runtime/localize-url.d.ts +85 -0
- package/dist/compiler/runtime/localize-url.d.ts.map +1 -0
- package/dist/compiler/runtime/localize-url.js +311 -0
- package/dist/compiler/runtime/localize-url.test.d.ts +2 -0
- package/dist/compiler/runtime/localize-url.test.d.ts.map +1 -0
- package/dist/compiler/runtime/localize-url.test.js +617 -0
- package/dist/compiler/runtime/set-locale.d.ts +21 -0
- package/dist/compiler/runtime/set-locale.d.ts.map +1 -0
- package/dist/compiler/runtime/set-locale.js +107 -0
- package/dist/compiler/runtime/set-locale.test.d.ts +2 -0
- package/dist/compiler/runtime/set-locale.test.d.ts.map +1 -0
- package/dist/compiler/runtime/set-locale.test.js +215 -0
- package/dist/compiler/runtime/track-message-call.d.ts +6 -0
- package/dist/compiler/runtime/track-message-call.d.ts.map +1 -0
- package/dist/compiler/runtime/track-message-call.js +13 -0
- package/dist/compiler/runtime/track-message-call.test.d.ts +2 -0
- package/dist/compiler/runtime/track-message-call.test.d.ts.map +1 -0
- package/dist/compiler/runtime/track-message-call.test.js +26 -0
- package/dist/compiler/runtime/type.d.ts +33 -0
- package/dist/compiler/runtime/type.d.ts.map +1 -0
- package/dist/compiler/runtime/type.test.d.ts +2 -0
- package/dist/compiler/runtime/type.test.d.ts.map +1 -0
- package/dist/compiler/runtime/type.test.js +91 -0
- package/dist/compiler/runtime/variables.d.ts +88 -0
- package/dist/compiler/runtime/variables.d.ts.map +1 -0
- package/dist/compiler/runtime/variables.js +74 -0
- package/dist/compiler/safe-module-id.d.ts +8 -0
- package/dist/compiler/safe-module-id.d.ts.map +1 -0
- package/dist/{services/valid-js-identifier/reservedWords.js → compiler/safe-module-id.js} +22 -1
- package/dist/compiler/safe-module-id.test.d.ts +2 -0
- package/dist/compiler/safe-module-id.test.d.ts.map +1 -0
- package/dist/compiler/safe-module-id.test.js +30 -0
- package/dist/compiler/server/create-server-file.d.ts +12 -0
- package/dist/compiler/server/create-server-file.d.ts.map +1 -0
- package/dist/compiler/server/create-server-file.js +47 -0
- package/dist/compiler/server/middleware.d.ts +66 -0
- package/dist/compiler/server/middleware.d.ts.map +1 -0
- package/dist/compiler/server/middleware.js +185 -0
- package/dist/compiler/server/middleware.test.d.ts +2 -0
- package/dist/compiler/server/middleware.test.d.ts.map +1 -0
- package/dist/compiler/server/middleware.test.js +435 -0
- package/dist/compiler/server/type.d.ts +7 -0
- package/dist/compiler/server/type.d.ts.map +1 -0
- package/dist/compiler/server/type.js +1 -0
- package/dist/compiler/types.d.ts +6 -8
- package/dist/compiler/types.d.ts.map +1 -1
- package/dist/compiler/types.js +1 -28
- package/dist/services/env-variables/create-index-file.d.ts +2 -0
- package/dist/services/env-variables/create-index-file.d.ts.map +1 -0
- package/dist/services/env-variables/create-index-file.js +29 -0
- package/dist/services/env-variables/index.js +1 -1
- package/dist/services/file-handling/write-output.d.ts +7 -1
- package/dist/services/file-handling/write-output.d.ts.map +1 -1
- package/dist/services/file-handling/write-output.js +103 -21
- package/dist/services/file-handling/write-output.test.js +126 -16
- package/dist/services/logger/index.d.ts.map +1 -1
- package/dist/services/logger/index.js +11 -5
- package/dist/services/telemetry/capture.d.ts +1 -2
- package/dist/services/telemetry/capture.d.ts.map +1 -1
- package/dist/services/telemetry/stack-detection.d.ts +1 -1
- package/dist/services/telemetry/stack-detection.d.ts.map +1 -1
- package/dist/services/telemetry/stack-detection.js +3 -8
- package/dist/services/telemetry/stack-detection.test.js +9 -12
- package/dist/urlpattern-polyfill/index.d.ts +2 -0
- package/dist/urlpattern-polyfill/index.d.ts.map +1 -0
- package/dist/urlpattern-polyfill/index.js +1 -0
- package/dist/utilities/node-normalize-path.d.ts +2 -0
- package/dist/utilities/node-normalize-path.d.ts.map +1 -0
- package/dist/utilities/node-normalize-path.js +9 -0
- package/package.json +21 -29
- package/dist/adapter-utils/index.d.ts +0 -6
- package/dist/adapter-utils/index.d.ts.map +0 -1
- package/dist/adapter-utils/index.js +0 -5
- package/dist/adapter-utils/negotiation/language.d.ts +0 -10
- package/dist/adapter-utils/negotiation/language.d.ts.map +0 -1
- package/dist/adapter-utils/negotiation/language.js +0 -137
- package/dist/adapter-utils/negotiation/language.test.d.ts +0 -2
- package/dist/adapter-utils/negotiation/language.test.d.ts.map +0 -1
- package/dist/adapter-utils/negotiation/language.test.js +0 -24
- package/dist/adapter-utils/routing/detectLanguage.d.ts +0 -25
- package/dist/adapter-utils/routing/detectLanguage.d.ts.map +0 -1
- package/dist/adapter-utils/routing/detectLanguage.js +0 -32
- package/dist/adapter-utils/routing/detectLanguage.test.d.ts +0 -2
- package/dist/adapter-utils/routing/detectLanguage.test.d.ts.map +0 -1
- package/dist/adapter-utils/routing/detectLanguage.test.js +0 -37
- package/dist/adapter-utils/routing/resolveUserPathDefinition.test.d.ts +0 -2
- package/dist/adapter-utils/routing/resolveUserPathDefinition.test.d.ts.map +0 -1
- package/dist/adapter-utils/routing/resolveUserPathDefinition.test.js +0 -35
- package/dist/adapter-utils/routing/resolveUserPathDefinitions.d.ts +0 -40
- package/dist/adapter-utils/routing/resolveUserPathDefinitions.d.ts.map +0 -1
- package/dist/adapter-utils/routing/resolveUserPathDefinitions.js +0 -19
- package/dist/adapter-utils/routing/routeDefinitions.d.ts +0 -48
- package/dist/adapter-utils/routing/routeDefinitions.d.ts.map +0 -1
- package/dist/adapter-utils/routing/routeDefinitions.js +0 -224
- package/dist/adapter-utils/routing/routeDefinitions.test.d.ts +0 -2
- package/dist/adapter-utils/routing/routeDefinitions.test.d.ts.map +0 -1
- package/dist/adapter-utils/routing/routeDefinitions.test.js +0 -234
- package/dist/adapter-utils/routing/sortRoutes.d.ts +0 -2
- package/dist/adapter-utils/routing/sortRoutes.d.ts.map +0 -1
- package/dist/adapter-utils/routing/sortRoutes.js +0 -135
- package/dist/adapter-utils/routing/validatePathTranslations.d.ts +0 -15
- package/dist/adapter-utils/routing/validatePathTranslations.d.ts.map +0 -1
- package/dist/adapter-utils/routing/validatePathTranslations.js +0 -98
- package/dist/adapter-utils/routing/validatePathTranslations.test.d.ts +0 -2
- package/dist/adapter-utils/routing/validatePathTranslations.test.d.ts.map +0 -1
- package/dist/adapter-utils/routing/validatePathTranslations.test.js +0 -121
- package/dist/cli/steps/run-compiler.d.ts +0 -9
- package/dist/cli/steps/run-compiler.d.ts.map +0 -1
- package/dist/cli/steps/run-compiler.js +0 -13
- package/dist/compiler/compileBundle.d.ts.map +0 -1
- package/dist/compiler/compileBundle.js +0 -81
- package/dist/compiler/compileBundle.test.d.ts +0 -2
- package/dist/compiler/compileBundle.test.d.ts.map +0 -1
- package/dist/compiler/compileBundle.test.js +0 -57
- package/dist/compiler/compileExpression.d.ts +0 -5
- package/dist/compiler/compileExpression.d.ts.map +0 -1
- package/dist/compiler/compileExpression.js +0 -41
- package/dist/compiler/compileMessage.d.ts +0 -12
- package/dist/compiler/compileMessage.d.ts.map +0 -1
- package/dist/compiler/compileMessage.js +0 -64
- package/dist/compiler/compileMessage.test.d.ts +0 -2
- package/dist/compiler/compileMessage.test.d.ts.map +0 -1
- package/dist/compiler/compileMessage.test.js +0 -74
- package/dist/compiler/compilePattern.d.ts +0 -12
- package/dist/compiler/compilePattern.d.ts.map +0 -1
- package/dist/compiler/compilePattern.js +0 -28
- package/dist/compiler/compilePattern.test.d.ts +0 -2
- package/dist/compiler/compilePattern.test.d.ts.map +0 -1
- package/dist/compiler/compilePattern.test.js +0 -67
- package/dist/compiler/compileProject.d.ts +0 -61
- package/dist/compiler/compileProject.d.ts.map +0 -1
- package/dist/compiler/compileProject.js +0 -77
- package/dist/compiler/compileProject.test.d.ts +0 -2
- package/dist/compiler/compileProject.test.d.ts.map +0 -1
- 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
- package/dist/compiler/jsDocComment.js +0 -30
- package/dist/compiler/runtime.d.ts +0 -6
- package/dist/compiler/runtime.d.ts.map +0 -1
- package/dist/compiler/runtime.js +0 -257
- package/dist/services/codegen/identifier.d.ts +0 -6
- package/dist/services/codegen/identifier.d.ts.map +0 -1
- package/dist/services/codegen/identifier.js +0 -11
- package/dist/services/codegen/indentifier.test.d.ts +0 -2
- package/dist/services/codegen/indentifier.test.d.ts.map +0 -1
- package/dist/services/codegen/indentifier.test.js +0 -8
- package/dist/services/telemetry/events.d.ts +0 -7
- package/dist/services/telemetry/events.d.ts.map +0 -1
- package/dist/services/valid-js-identifier/index.d.ts +0 -6
- package/dist/services/valid-js-identifier/index.d.ts.map +0 -1
- package/dist/services/valid-js-identifier/index.js +0 -24
- package/dist/services/valid-js-identifier/index.test.d.ts +0 -2
- package/dist/services/valid-js-identifier/index.test.d.ts.map +0 -1
- package/dist/services/valid-js-identifier/index.test.js +0 -30
- package/dist/services/valid-js-identifier/reservedWords.d.ts +0 -2
- package/dist/services/valid-js-identifier/reservedWords.d.ts.map +0 -1
- /package/dist/{services/telemetry/events.js → compiler/runtime/type.js} +0 -0
package/README.md
CHANGED
|
@@ -1,63 +1,14 @@
|
|
|
1
1
|
[](https://inlang.com)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@inlang/paraglide-js)
|
|
4
|
+
[](https://github.com/opral/inlang-paraglide-js/issues)
|
|
5
|
+
[](https://github.com/opral/monorepo/graphs/contributors)
|
|
4
6
|
|
|
5
|
-
To auto setup Paraglide JS, run the following command:
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
npx @inlang/paraglide-js@latest init
|
|
9
|
-
```
|
|
8
|
+
A compiler-based i18n library that emits tree-shakable message functions. This means that only the messages you actually use are loaded without asynchronous waterfalls.
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
Visit https://inlang.com/m/gerre34r/library-inlang-paraglideJs to learn more.
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
- Install necessary dependencies
|
|
15
|
-
- Generate a `messages/` folder where your translation files live
|
|
12
|
+
## Contributing
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Messages are stored in `messages/{locale}.json` as key-value pairs. You can add parameters with curly braces.
|
|
20
|
-
|
|
21
|
-
```diff
|
|
22
|
-
// messages/en.json
|
|
23
|
-
{
|
|
24
|
-
+ "greeting": "Hello {name}!"
|
|
25
|
-
}
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Run the compiler via the CLI to generate the message functions.
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
npx @inlang/paraglide-js compile --project ./project.inlang --outdir ./src/paraglide
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
_If you are using a Bundler use one of the [Bundler Plugins](usage#usage-with-a-bundler) to recompile automatically._
|
|
35
|
-
|
|
36
|
-
## Using messages in code
|
|
37
|
-
|
|
38
|
-
After running the compiler import the messages with `import * as m from "./paraglide/messages"`. By convention, a wildcard import is used.
|
|
39
|
-
|
|
40
|
-
```js
|
|
41
|
-
import * as m from "./paraglide/messages.js";
|
|
42
|
-
|
|
43
|
-
m.greeting({ name: "Samuel" }); // Hello Samuel!
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
## Changing the locale
|
|
47
|
-
|
|
48
|
-
To change the locale, use the `setLocale` function.
|
|
49
|
-
|
|
50
|
-
```js
|
|
51
|
-
import { setLocale } from "./paraglide/runtime.js";
|
|
52
|
-
import * as m from "./paraglide/messages.js";
|
|
53
|
-
|
|
54
|
-
m.greeting({ name: "Samuel" }); // Hello Samuel!
|
|
55
|
-
|
|
56
|
-
setLocale("de");
|
|
57
|
-
|
|
58
|
-
m.greeting({ name: "Samuel" }); // Guten Tag Samuel!
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
## Define your strategy
|
|
62
|
-
|
|
63
|
-
In the last step, you need to define what strategy you want to use to resolve the locale. Visit the [strategy documentation](https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy) to learn more.
|
|
14
|
+
Read the [CONTRIBUTING.md](https://github.com/opral/monorepo/blob/main/inlang/packages/paraglide/paraglide-js/CONTRIBUTING.md) file to learn more on how to contribute.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/esbuild.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,sBAAsB,sFAAuC,CAAC"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { paraglideEsbuildPlugin } from "./esbuild.js";
|
|
2
|
+
export { paraglideRolldownPlugin } from "./rolldown.js";
|
|
2
3
|
export { paraglideRollupPlugin } from "./rollup.js";
|
|
4
|
+
export { paraglideRspackPlugin } from "./rspack.js";
|
|
5
|
+
export { paraglideVitePlugin } from "./vite.js";
|
|
6
|
+
export { paraglideWebpackPlugin } from "./webpack.js";
|
|
3
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { paraglideEsbuildPlugin } from "./esbuild.js";
|
|
2
|
+
export { paraglideRolldownPlugin } from "./rolldown.js";
|
|
2
3
|
export { paraglideRollupPlugin } from "./rollup.js";
|
|
4
|
+
export { paraglideRspackPlugin } from "./rspack.js";
|
|
5
|
+
export { paraglideVitePlugin } from "./vite.js";
|
|
6
|
+
export { paraglideWebpackPlugin } from "./webpack.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rolldown.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/rolldown.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,uBAAuB,uIAAwC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const paraglideRollupPlugin: (options: import("../index.js").
|
|
1
|
+
export declare const paraglideRollupPlugin: (options: import("../index.js").CompilerOptions) => import("unplugin").RollupPlugin<any> | import("unplugin").RollupPlugin<any>[];
|
|
2
2
|
//# 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,mIAAsC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rspack.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/rspack.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB,0EAAsC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { UnpluginFactory } from "unplugin";
|
|
2
|
-
import {
|
|
3
|
-
export declare const unpluginFactory: UnpluginFactory<
|
|
2
|
+
import type { CompilerOptions } from "../compiler/compiler-options.js";
|
|
3
|
+
export declare const unpluginFactory: UnpluginFactory<CompilerOptions>;
|
|
4
4
|
//# sourceMappingURL=unplugin.d.ts.map
|
|
@@ -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;
|
|
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;AAMhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAavE,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,eAAe,CAmG3D,CAAC"}
|
|
@@ -1,66 +1,129 @@
|
|
|
1
1
|
import { compile } from "../compiler/compile.js";
|
|
2
2
|
import fs from "node:fs";
|
|
3
|
-
import { resolve } from "node:path";
|
|
3
|
+
import { resolve, relative } from "node:path";
|
|
4
|
+
import { nodeNormalizePath } from "../utilities/node-normalize-path.js";
|
|
5
|
+
import { Logger } from "../services/logger/index.js";
|
|
4
6
|
const PLUGIN_NAME = "unplugin-paraglide-js";
|
|
7
|
+
const logger = new Logger();
|
|
8
|
+
/**
|
|
9
|
+
* Default isServer which differs per bundler.
|
|
10
|
+
*/
|
|
11
|
+
let isServer;
|
|
12
|
+
let previousCompilation;
|
|
5
13
|
export const unpluginFactory = (args) => ({
|
|
6
14
|
name: PLUGIN_NAME,
|
|
7
15
|
enforce: "pre",
|
|
8
16
|
async buildStart() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
logger.info("Compiling inlang project...");
|
|
18
|
+
try {
|
|
19
|
+
previousCompilation = await compile({
|
|
20
|
+
fs: wrappedFs,
|
|
21
|
+
previousCompilation,
|
|
22
|
+
// webpack invokes the `buildStart` api in watch mode,
|
|
23
|
+
// to avoid cleaning the output directory in watch mode,
|
|
24
|
+
// we only clean the output directory if there was no previous compilation
|
|
25
|
+
cleanOutdir: previousCompilation === undefined,
|
|
26
|
+
isServer,
|
|
27
|
+
...args,
|
|
28
|
+
});
|
|
29
|
+
logger.success("Compilation complete");
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
logger.error("Failed to compile project:", error.message);
|
|
33
|
+
logger.info("Please check your translation files for syntax errors.");
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
// in any case add the files to watch
|
|
37
|
+
for (const path of Array.from(readFiles)) {
|
|
38
|
+
this.addWatchFile(path);
|
|
39
|
+
}
|
|
18
40
|
}
|
|
19
41
|
},
|
|
20
42
|
async watchChange(path) {
|
|
21
|
-
|
|
22
|
-
|
|
43
|
+
const shouldCompile = readFiles.has(path) && !path.includes("cache");
|
|
44
|
+
if (shouldCompile === false) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const previouslyReadFiles = new Set(readFiles);
|
|
48
|
+
try {
|
|
49
|
+
logger.info(`Re-compiling inlang project... File "${relative(process.cwd(), path)}" has changed.`);
|
|
50
|
+
// Clear readFiles to track fresh file reads
|
|
23
51
|
readFiles.clear();
|
|
24
|
-
await compile({
|
|
25
|
-
project: args.project,
|
|
26
|
-
outdir: args.outdir,
|
|
27
|
-
compilerOptions: args.compilerOptions,
|
|
52
|
+
previousCompilation = await compile({
|
|
28
53
|
fs: wrappedFs,
|
|
54
|
+
previousCompilation,
|
|
55
|
+
cleanOutdir: false,
|
|
56
|
+
isServer,
|
|
57
|
+
...args,
|
|
29
58
|
});
|
|
59
|
+
logger.success("Re-compilation complete");
|
|
60
|
+
// Add any new files to watch
|
|
61
|
+
for (const filePath of Array.from(readFiles)) {
|
|
62
|
+
this.addWatchFile(filePath);
|
|
63
|
+
}
|
|
30
64
|
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
readFiles = previouslyReadFiles;
|
|
67
|
+
// Reset compilation result on error
|
|
68
|
+
previousCompilation = undefined;
|
|
69
|
+
logger.warn("Failed to re-compile project:", e.message);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
vite: {
|
|
73
|
+
config: {
|
|
74
|
+
handler: () => {
|
|
75
|
+
isServer = "import.meta.env?.SSR ?? typeof window === 'undefined'";
|
|
76
|
+
},
|
|
77
|
+
},
|
|
31
78
|
},
|
|
32
79
|
webpack(compiler) {
|
|
33
|
-
|
|
34
|
-
|
|
80
|
+
compiler.options.resolve = {
|
|
81
|
+
...compiler.options.resolve,
|
|
82
|
+
fallback: {
|
|
83
|
+
...compiler.options.resolve?.fallback,
|
|
84
|
+
// https://stackoverflow.com/a/72989932
|
|
85
|
+
async_hooks: false,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
35
88
|
compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
89
|
+
try {
|
|
90
|
+
previousCompilation = await compile({
|
|
91
|
+
fs: wrappedFs,
|
|
92
|
+
previousCompilation,
|
|
93
|
+
// clean dir needs to be false. otherwise webpack get's into a race condition
|
|
94
|
+
// of deleting the output directory and writing files at the same time for
|
|
95
|
+
// multi environment builds
|
|
96
|
+
cleanOutdir: false,
|
|
97
|
+
...args,
|
|
98
|
+
});
|
|
99
|
+
logger.success("Compilation complete");
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
logger.warn("Failed to compile project:", error.message);
|
|
103
|
+
logger.warn("Please check your translation files for syntax errors.");
|
|
104
|
+
}
|
|
42
105
|
});
|
|
43
106
|
},
|
|
44
107
|
});
|
|
45
|
-
|
|
108
|
+
let readFiles = new Set();
|
|
46
109
|
// Create a wrapper around the fs object to intercept and store read files
|
|
47
110
|
const wrappedFs = {
|
|
48
111
|
...fs,
|
|
49
112
|
// @ts-expect-error - Node's fs has too many overloads
|
|
50
113
|
readFile: (path, options, callback) => {
|
|
51
|
-
readFiles.add(resolve(process.cwd(), path.toString()));
|
|
114
|
+
readFiles.add(nodeNormalizePath(resolve(process.cwd(), path.toString())));
|
|
52
115
|
return fs.readFile(path, options, callback);
|
|
53
116
|
},
|
|
54
117
|
// @ts-expect-error - Node's fs has too many overloads
|
|
55
118
|
readFileSync: (path, options) => {
|
|
56
|
-
readFiles.add(resolve(process.cwd(), path.toString()));
|
|
119
|
+
readFiles.add(nodeNormalizePath(resolve(process.cwd(), path.toString())));
|
|
57
120
|
return fs.readFileSync(path, options);
|
|
58
121
|
},
|
|
59
122
|
promises: {
|
|
60
123
|
...fs.promises,
|
|
61
124
|
// @ts-expect-error - Node's fs.promises has too many overloads
|
|
62
125
|
readFile: async (path, options) => {
|
|
63
|
-
readFiles.add(resolve(process.cwd(), path.toString()));
|
|
126
|
+
readFiles.add(nodeNormalizePath(resolve(process.cwd(), path.toString())));
|
|
64
127
|
return fs.promises.readFile(path, options);
|
|
65
128
|
},
|
|
66
129
|
},
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const paraglideVitePlugin: (options: import("../index.js").
|
|
1
|
+
export declare const paraglideVitePlugin: (options: import("../index.js").CompilerOptions) => import("vite").Plugin<any> | import("vite").Plugin<any>[];
|
|
2
2
|
//# sourceMappingURL=vite.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/vite.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/vite.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,+GAAoC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webpack.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/webpack.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,sBAAsB,8FAAuC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/compile/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/compile/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUpC,eAAO,MAAM,cAAc,SAmDzB,CAAC"}
|
|
@@ -1,38 +1,37 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
import fs from "node:fs";
|
|
3
2
|
import { resolve } from "node:path";
|
|
4
3
|
import { Logger } from "../../../services/logger/index.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { ENV_VARIABLES } from "../../../services/env-variables/index.js";
|
|
4
|
+
import { DEFAULT_OUTDIR, DEFAULT_PROJECT_PATH } from "../../defaults.js";
|
|
5
|
+
import { compile } from "../../../compiler/compile.js";
|
|
6
|
+
import { defaultCompilerOptions, } from "../../../compiler/compiler-options.js";
|
|
9
7
|
export const compileCommand = new Command()
|
|
10
8
|
.name("compile")
|
|
11
9
|
.summary("Compiles inlang Paraglide-JS")
|
|
12
|
-
.requiredOption("--project <path>", 'The path to the inlang project. Example: "./project.inlang"')
|
|
10
|
+
.requiredOption("--project <path>", 'The path to the inlang project. Example: "./project.inlang"', DEFAULT_PROJECT_PATH)
|
|
13
11
|
.requiredOption("--outdir <path>", 'The path to the output directory. Example: "./src/paraglide"', DEFAULT_OUTDIR)
|
|
12
|
+
.option("--strategy <items...>", [
|
|
13
|
+
"The strategy to be used.",
|
|
14
|
+
"",
|
|
15
|
+
"Example: --strategy cookie globalVariable baseLocale",
|
|
16
|
+
"Read more on https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy",
|
|
17
|
+
].join("\n"))
|
|
14
18
|
.requiredOption("--silent", "Only log errors to the console", false)
|
|
15
19
|
.action(async (options) => {
|
|
16
20
|
const logger = new Logger({ silent: options.silent, prefix: true });
|
|
17
21
|
const path = resolve(process.cwd(), options.project);
|
|
18
|
-
logger.info(`Compiling inlang project
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
project,
|
|
26
|
-
fs: fs.promises,
|
|
27
|
-
outdir: options.outdir,
|
|
28
|
-
});
|
|
29
|
-
logger.success("Successfully compiled the project.");
|
|
30
|
-
const errors = await project.errors.get();
|
|
31
|
-
if (errors.length > 0) {
|
|
32
|
-
logger.warn(`But the project reported the following warnings and/or errors that might have influenced compilation:`);
|
|
33
|
-
for (const error of errors) {
|
|
34
|
-
logger.error(`${error}`);
|
|
35
|
-
}
|
|
22
|
+
logger.info(`Compiling inlang project ...`);
|
|
23
|
+
try {
|
|
24
|
+
await compile({
|
|
25
|
+
project: path,
|
|
26
|
+
outdir: options.outdir,
|
|
27
|
+
strategy: options.strategy ?? defaultCompilerOptions.strategy,
|
|
28
|
+
});
|
|
36
29
|
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
logger.error("Error while compiling inlang project.");
|
|
32
|
+
logger.error(e);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
logger.success(`Successfully compiled inlang project.`);
|
|
37
36
|
process.exit(0);
|
|
38
37
|
});
|
|
@@ -1,23 +1,3 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
import { Logger } from "../../../services/logger/index.js";
|
|
3
|
-
import type { CliStep } from "../../utils.js";
|
|
4
2
|
export declare const initCommand: Command;
|
|
5
|
-
export declare const addParaglideJsToDevDependencies: CliStep<{
|
|
6
|
-
fs: typeof import("node:fs/promises");
|
|
7
|
-
logger: Logger;
|
|
8
|
-
packageJsonPath: string;
|
|
9
|
-
}, unknown>;
|
|
10
|
-
export declare const enforcePackageJsonExists: CliStep<{
|
|
11
|
-
logger: Logger;
|
|
12
|
-
fs: typeof import("node:fs/promises");
|
|
13
|
-
}, {
|
|
14
|
-
packageJsonPath: string;
|
|
15
|
-
}>;
|
|
16
|
-
export declare const addCompileStepToPackageJSON: CliStep<{
|
|
17
|
-
fs: typeof import("node:fs/promises");
|
|
18
|
-
logger: Logger;
|
|
19
|
-
projectPath: string;
|
|
20
|
-
outdir: string;
|
|
21
|
-
packageJsonPath: string;
|
|
22
|
-
}, unknown>;
|
|
23
3
|
//# sourceMappingURL=command.d.ts.map
|
|
@@ -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;
|
|
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;AAkBpC,eAAO,MAAM,WAAW,SAwDrB,CAAC"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
import consola from "consola";
|
|
3
2
|
import * as nodePath from "node:path";
|
|
4
3
|
import { Logger } from "../../../services/logger/index.js";
|
|
5
4
|
import { findPackageJson } from "../../../services/environment/package.js";
|
|
6
5
|
import { checkForUncommittedChanges } from "../../steps/check-for-uncomitted-changes.js";
|
|
7
6
|
import { initializeInlangProject } from "../../steps/initialize-inlang-project.js";
|
|
8
7
|
import { maybeAddSherlock } from "../../steps/maybe-add-sherlock.js";
|
|
9
|
-
import {
|
|
8
|
+
import { maybeUpdateTsConfig } from "../../steps/update-ts-config.js";
|
|
10
9
|
import { promptForOutdir } from "../../steps/prompt-for-outdir.js";
|
|
11
10
|
import { updatePackageJson } from "../../steps/update-package-json.js";
|
|
12
|
-
import { runCompiler } from "../../steps/run-compiler.js";
|
|
13
11
|
import nodeFs from "node:fs";
|
|
14
12
|
import { ENV_VARIABLES } from "../../../services/env-variables/index.js";
|
|
15
13
|
import { detectBundler } from "../../steps/detect-bundler.js";
|
|
16
14
|
import { addVitePlugin } from "../../steps/add-vite-plugin.js";
|
|
15
|
+
import { compile } from "../../../compiler/compile.js";
|
|
16
|
+
import { maybeAddMachineTranslation } from "../../steps/maybe-add-machine-translation.js";
|
|
17
17
|
export const initCommand = new Command()
|
|
18
18
|
.name("init")
|
|
19
19
|
.summary("Initializes inlang Paraglide-JS.")
|
|
@@ -38,24 +38,25 @@ export const initCommand = new Command()
|
|
|
38
38
|
else {
|
|
39
39
|
await addCompileStepToPackageJSON(ctx6);
|
|
40
40
|
}
|
|
41
|
-
const ctx7 = await
|
|
41
|
+
const ctx7 = await maybeUpdateTsConfig(ctx6);
|
|
42
42
|
const ctx8 = await maybeAddSherlock(ctx7);
|
|
43
|
+
const ctx9 = await maybeAddMachineTranslation(ctx8);
|
|
43
44
|
try {
|
|
44
|
-
await
|
|
45
|
-
|
|
45
|
+
await compile({
|
|
46
|
+
project: ctx9.projectPath,
|
|
47
|
+
outdir: ctx9.outdir,
|
|
48
|
+
});
|
|
49
|
+
ctx.logger.success("Ran the paraglide compiler");
|
|
46
50
|
}
|
|
47
51
|
catch {
|
|
48
52
|
ctx.logger.warn("Failed to compile project automatically. You will need to run the compiler manually");
|
|
49
53
|
}
|
|
50
|
-
const absoluteSettingsPath = nodePath.resolve(ctx8.projectPath, "settings.json");
|
|
51
|
-
const relativeSettingsFilePath = absoluteSettingsPath.replace(process.cwd(), ".");
|
|
52
54
|
const successMessage = [
|
|
53
55
|
`inlang Paraglide-JS has been set up sucessfully.`,
|
|
54
56
|
"\n",
|
|
55
57
|
`1. Run your install command (npm i, yarn install, etc)`,
|
|
56
58
|
`2. Run the build script (npm run build, or similar.)`,
|
|
57
|
-
`3.
|
|
58
|
-
"\n",
|
|
59
|
+
`3. Visit https://inlang.com/m/gerre34r/library-inlang-paraglideJs/basics to get started.`,
|
|
59
60
|
"\n",
|
|
60
61
|
`For questions and feedback, visit`,
|
|
61
62
|
`https://github.com/opral/inlang-paraglide-js/issues`,
|
|
@@ -63,7 +64,7 @@ export const initCommand = new Command()
|
|
|
63
64
|
ctx.logger.box(successMessage);
|
|
64
65
|
process.exit(0);
|
|
65
66
|
});
|
|
66
|
-
|
|
67
|
+
const addParaglideJsToDevDependencies = async (ctx) => {
|
|
67
68
|
const ctx1 = await updatePackageJson({
|
|
68
69
|
devDependencies: async (devDeps) => ({
|
|
69
70
|
...devDeps,
|
|
@@ -73,7 +74,7 @@ export const addParaglideJsToDevDependencies = async (ctx) => {
|
|
|
73
74
|
ctx.logger.success("Added @inlang/paraglide-js to the devDependencies in package.json.");
|
|
74
75
|
return ctx1;
|
|
75
76
|
};
|
|
76
|
-
|
|
77
|
+
const enforcePackageJsonExists = async (ctx) => {
|
|
77
78
|
const packageJsonPath = await findPackageJson(ctx.fs, process.cwd());
|
|
78
79
|
if (!packageJsonPath) {
|
|
79
80
|
ctx.logger.warn("No package.json found in the current working directory. Please change the working directory to the directory with a package.json file.");
|
|
@@ -81,19 +82,11 @@ export const enforcePackageJsonExists = async (ctx) => {
|
|
|
81
82
|
}
|
|
82
83
|
return { ...ctx, packageJsonPath };
|
|
83
84
|
};
|
|
84
|
-
|
|
85
|
+
const addCompileStepToPackageJSON = async (ctx) => {
|
|
85
86
|
const projectPath = "./" + nodePath.relative(process.cwd(), ctx.projectPath);
|
|
86
87
|
const outdir = "./" + nodePath.relative(process.cwd(), ctx.outdir);
|
|
87
|
-
let shouldExit = false;
|
|
88
88
|
ctx = await updatePackageJson({
|
|
89
89
|
scripts: async (scripts) => {
|
|
90
|
-
// add the compile command to the postinstall script
|
|
91
|
-
// this isn't super important, so we won't interrupt the user if it fails
|
|
92
|
-
if (!scripts.postinstall?.includes("paraglide-js compile")) {
|
|
93
|
-
scripts.postinstall =
|
|
94
|
-
`paraglide-js compile --project ${projectPath} --outdir ${outdir}` +
|
|
95
|
-
(scripts.postinstall ? " && " + scripts.postinstall : "");
|
|
96
|
-
}
|
|
97
90
|
if (scripts.build === undefined) {
|
|
98
91
|
scripts.build = `paraglide-js compile --project ${projectPath} --outdir ${outdir}`;
|
|
99
92
|
}
|
|
@@ -101,30 +94,13 @@ export const addCompileStepToPackageJSON = async (ctx) => {
|
|
|
101
94
|
scripts.build = `paraglide-js compile --project ${projectPath} --outdir ${outdir} && ${scripts.build}`;
|
|
102
95
|
}
|
|
103
96
|
else {
|
|
104
|
-
|
|
105
|
-
.warn(`The "build" script in the \`package.json\` already contains a "paraglide-js compile" command.
|
|
106
|
-
|
|
107
|
-
Please add the following command to your build script manually:
|
|
108
|
-
|
|
109
|
-
\`paraglide-js compile --project ${ctx.projectPath}`);
|
|
110
|
-
const response = await consola.prompt("Have you added the compile command to your build script?", {
|
|
111
|
-
type: "confirm",
|
|
112
|
-
initial: false,
|
|
113
|
-
});
|
|
114
|
-
if (response === false) {
|
|
115
|
-
ctx.logger.log("Please add the paraglide-js compile to your build script and try again.");
|
|
116
|
-
shouldExit = true;
|
|
117
|
-
throw new Error("Skip write");
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
throw new Error("Skip write");
|
|
121
|
-
}
|
|
97
|
+
return scripts;
|
|
122
98
|
}
|
|
123
|
-
ctx.logger.success("
|
|
99
|
+
ctx.logger.success("Added the compile command to the build step in package.json.");
|
|
100
|
+
ctx.logger.info(`If you use a bundler like Vite, Rolldown, or Webpack, you can use a bundler plugin instead and remove the compile command from the build script.`);
|
|
101
|
+
ctx.logger.info(`Visit https://inlang.com/m/gerre34r/library-inlang-paraglideJs/compiling-messages for more information.`);
|
|
124
102
|
return scripts;
|
|
125
103
|
},
|
|
126
104
|
})(ctx);
|
|
127
|
-
if (shouldExit)
|
|
128
|
-
process.exit(1);
|
|
129
105
|
return ctx;
|
|
130
106
|
};
|
package/dist/cli/defaults.js
CHANGED
|
@@ -7,8 +7,8 @@ const defaultProjectSettings = {
|
|
|
7
7
|
baseLocale: "en",
|
|
8
8
|
locales: ["en", "de"],
|
|
9
9
|
modules: [
|
|
10
|
-
"https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@
|
|
11
|
-
"https://cdn.jsdelivr.net/npm/@inlang/plugin-m-function-matcher@
|
|
10
|
+
"https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@4/dist/index.js",
|
|
11
|
+
"https://cdn.jsdelivr.net/npm/@inlang/plugin-m-function-matcher@2/dist/index.js",
|
|
12
12
|
],
|
|
13
13
|
"plugin.inlang.messageFormat": {
|
|
14
14
|
pathPattern: "./messages/{locale}.json",
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
export { checkForUncommittedChanges } from "./steps/check-for-uncomitted-changes.js";
|
|
3
|
-
export { initializeInlangProject } from "./steps/initialize-inlang-project.js";
|
|
4
|
-
export { maybeAddSherlock } from "./steps/maybe-add-sherlock.js";
|
|
5
|
-
export { maybeChangeTsConfig } from "./steps/update-ts-config.js";
|
|
6
|
-
export { promptForOutdir } from "./steps/prompt-for-outdir.js";
|
|
7
|
-
export { updatePackageJson } from "./steps/update-package-json.js";
|
|
8
|
-
export { runCompiler } from "./steps/run-compiler.js";
|
|
9
2
|
export declare const cli: Command;
|
|
10
|
-
export * as Utils from "./utils.js";
|
|
11
|
-
export * as Defaults from "./defaults.js";
|
|
12
3
|
//# sourceMappingURL=index.d.ts.map
|
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;AAKpC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,eAAO,MAAM,GAAG,SAK8B,CAAC"}
|
package/dist/cli/index.js
CHANGED
|
@@ -2,18 +2,9 @@ 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
4
|
import { initCommand } from "./commands/init/command.js";
|
|
5
|
-
export { checkForUncommittedChanges } from "./steps/check-for-uncomitted-changes.js";
|
|
6
|
-
export { initializeInlangProject } from "./steps/initialize-inlang-project.js";
|
|
7
|
-
export { maybeAddSherlock } from "./steps/maybe-add-sherlock.js";
|
|
8
|
-
export { maybeChangeTsConfig } from "./steps/update-ts-config.js";
|
|
9
|
-
export { promptForOutdir } from "./steps/prompt-for-outdir.js";
|
|
10
|
-
export { updatePackageJson } from "./steps/update-package-json.js";
|
|
11
|
-
export { runCompiler } from "./steps/run-compiler.js";
|
|
12
5
|
export const cli = new Command()
|
|
13
6
|
.name("paraglide-js")
|
|
14
7
|
.addCommand(compileCommand)
|
|
15
8
|
.addCommand(initCommand)
|
|
16
9
|
.showHelpAfterError()
|
|
17
10
|
.version(ENV_VARIABLES.PARJS_PACKAGE_VERSION);
|
|
18
|
-
export * as Utils from "./utils.js";
|
|
19
|
-
export * as Defaults from "./defaults.js";
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,CAwEA,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAazD;AAcD;;GAEG;AACH,eAAO,MAAM,OAAO,sbACga,CAAC"}
|