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

Mesdk 200 loadprojectfromdirectory #3136

Merged
merged 15 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions inlang/source-code/paraglide/paraglide-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
"prettier-plugin-jsdoc": "^1.3.0"
},
"devDependencies": {
"@inlang/sdk": "workspace:*",
"@lix-js/client": "workspace:*",
"@lix-js/fs": "workspace:*",
"@inlang/recommend-ninja": "workspace:*",
"@inlang/recommend-sherlock": "workspace:*",
"@inlang/sdk2": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Command } from "commander"
import nodeFsPromises from "node:fs/promises"
import { resolve } from "node:path"
import { Logger } from "~/services/logger/index.js"
import { runCompiler } from "~/cli/steps/run-compiler2.js"
import { DEFAULT_OUTDIR } from "~/cli/defaults.js"
import { classifyProjectErrors } from "~/services/error-handling.js"
import { loadProjectFromDirectoryInMemory } from "@inlang/sdk2"

export const compileCommand2 = new Command()
.name("compile")
.summary("Compiles inlang Paraglide-JS")
.requiredOption("--project <path>", 'The path to the inlang project. Example: "./project.inlang"')
.requiredOption(
"--outdir <path>",
'The path to the output directory. Example: "./src/paraglide"',
DEFAULT_OUTDIR
)
.requiredOption("--silent", "Only log errors to the console", false)
.action(async (options: { silent: boolean; project: string; outdir: string; watch: boolean }) => {
const logger = new Logger({ silent: options.silent, prefix: true })
const path = resolve(process.cwd(), options.project)

logger.info(`Compiling inlang project at "${options.project}".`)

const project = await loadProjectFromDirectoryInMemory({
path,
fs: nodeFsPromises,
})

const errors = await project.errors.get()

if (errors.length > 0) {
const { nonFatalErrors, fatalErrors } = classifyProjectErrors(errors as any)
if (fatalErrors.length > 0) {
logger.error(`The project has fatal errors:`)
for (const error of [...fatalErrors, ...nonFatalErrors]) {
logger.error(error)
}
process.exit(1)
}

if (nonFatalErrors.length > 0) {
logger.warn(`The project has warnings:`)
for (const error of nonFatalErrors) {
logger.warn(error)
}
}
}

await runCompiler({
project,
fs: nodeFsPromises,
outdir: options.outdir,
})

logger.info("Successfully compiled the project.")
process.exit(0)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { selectBundleNested, type InlangProject } from "@inlang/sdk2"
import type { CliStep } from "../utils.js"
import path from "node:path"
import { compile } from "~/compilerV2/compile.js"
import { writeOutput } from "~/services/file-handling/write-output.js"
import type { NodeishFilesystem } from "@lix-js/fs"

export const runCompiler: CliStep<
{
project: InlangProject
outdir: string
fs: NodeishFilesystem
},
unknown
> = async (ctx) => {
const absoluteOutdir = path.resolve(process.cwd(), ctx.outdir)
const bundles = await selectBundleNested(ctx.project.db).execute()

const output = await compile({
bundles: bundles,
settings: await ctx.project.settings.get(),
projectId: undefined,
outputStructure: "message-modules",
})

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