Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parjs-211-expose-compiler-as-library #3304

Merged
merged 6 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/soft-chairs-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
"@inlang/paraglide-js": minor
---

feat: expose compiler as library

closes https://github.com/opral/inlang-paraglide-js/issues/206

The Paraglide compiler is now exposed as a library. This allows you to use and extend the compiler however you need.

```ts
import { compile } from '@inlang/paraglide-js/compiler';

await compile({
path: "/path/to/project.inlang",
outdir: "/path/to/output",
});
```
7 changes: 7 additions & 0 deletions .changeset/stupid-tips-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@lix-js/server-api-schema": patch
---

fix: emit .js file for node js

Otherwise, node js will throw "UNKNOWN FILE EXTENSION .ts".
18 changes: 0 additions & 18 deletions packages/inlang-paraglide-js/example/package.json

This file was deleted.

This file was deleted.

16 changes: 16 additions & 0 deletions packages/inlang-paraglide-js/examples/cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@inlang/paraglide-js-example-cli",
"type": "module",
"version": "0.0.0",
"private": true,
"scripts": {
"_dev": "paraglide-js compile --project ./project.inlang --watch",
"build": "paraglide-js compile --project ./project.inlang",
"pretest": "paraglide-js compile --project ./project.inlang"
},
"devDependencies": {
"@inlang/paraglide-js": "workspace:*",
"typescript": "^5.5.2",
"vitest": "^2.0.5"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://inlang.com/schema/project-settings",
"baseLocale": "en",
"locales": ["en", "de", "en-US"],
"modules": [
"https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@latest/dist/index.js"
],
"plugin.inlang.messageFormat": {
"pathPattern": "./messages/{locale}.json"
}
}
44 changes: 23 additions & 21 deletions packages/inlang-paraglide-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,6 @@
"type": "git",
"url": "https://github.com/opral/inlang-paraglide-js"
},
"keywords": [
"paraglide",
"javascript i18n",
"i18n",
"l10n",
"translation",
"internationalization",
"svelte",
"localization",
"lint",
"react",
"vue",
"angular",
"nextjs",
"next i18n",
"astro",
"astro i18n",
"solid",
"solidstart"
],
"bin": {
"paraglide-js": "./bin/run.js"
},
Expand Down Expand Up @@ -77,6 +57,8 @@
"vitest": "2.0.5"
},
"exports": {
"./cli": "./dist/cli/index.js",
"./compiler": "./dist/compiler/index.js",
".": {
"import": "./default/index.js",
"types": "./default/index.d.ts"
Expand All @@ -93,5 +75,25 @@
"import": "./dist/adapter-utils/index.js",
"types": "./dist/adapter-utils/index.d.ts"
}
}
},
"keywords": [
"paraglide",
"javascript i18n",
"i18n",
"l10n",
"translation",
"internationalization",
"svelte",
"localization",
"lint",
"react",
"vue",
"angular",
"nextjs",
"next i18n",
"astro",
"astro i18n",
"solid",
"solidstart"
]
}
13 changes: 5 additions & 8 deletions packages/inlang-paraglide-js/src/cli/steps/run-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { selectBundleNested, type InlangProject } from "@inlang/sdk";
import { type InlangProject } from "@inlang/sdk";
import type { CliStep } from "../utils.js";
import path from "node:path";
import { compile } from "../../compiler/compile.js";
import { writeOutput } from "../../services/file-handling/write-output.js";
import fs from "node:fs";
import { compileProject } from "../../compiler/compileProject.js";

export const runCompiler: CliStep<
{
Expand All @@ -14,14 +14,11 @@ export const runCompiler: CliStep<
unknown
> = async (ctx) => {
const absoluteOutdir = path.resolve(process.cwd(), ctx.outdir);
const bundles = await selectBundleNested(ctx.project.db).execute();
const settings = await ctx.project.settings.get();

const output = await compile({
bundles,
settings,
const output = await compileProject({
project: ctx.project,
});

await writeOutput(absoluteOutdir, output, ctx.fs);
return { ...ctx, bundles };
return { ...ctx };
};
Loading
Loading