Skip to content

Commit

Permalink
feat: compile typescript demos to javascript at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
vixalien committed Aug 20, 2024
1 parent 0ae9994 commit aa93014
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
21 changes: 21 additions & 0 deletions build-aux/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Gio._promisify(

Gio._promisify(Gio.File.prototype, "copy_async", "copy_finish");

Gio._promisify(Gio.Subprocess.prototype, "wait_async", "wait_finish");

const loop = new GLib.MainLoop(null, false);

const [pkgdatadir] = programArgs;
Expand Down Expand Up @@ -95,6 +97,9 @@ const demos = [];
demos.push(demo);
}

// compile TypeScript demos to JavaScript
await compileTypeScriptFiles();

await Gio.File.new_for_path(pkgdatadir)
.get_child("demos/index.json")
.replace_contents_async(
Expand All @@ -114,6 +119,22 @@ const demos = [];
loop.quit();
});

async function compileTypeScriptFiles() {
const tsc_launcher = new Gio.SubprocessLauncher();
tsc_launcher.set_cwd(
Gio.File.new_for_path(pkgdatadir).get_child("demos").get_path()
);

const tsc = tsc_launcher.spawnv(["tsc"]);
await tsc.wait_async(null);

// TODO: maybe throw when the result is false
const successful = tsc.get_successful();
tsc_launcher.close();

if (!successful) throw new Error("One or several errors happened while compiling TypeScript demos to JavaScript")
}

async function copyDemo(source, destination) {
try {
destination.make_directory_with_parents(null);
Expand Down
7 changes: 7 additions & 0 deletions src/langs/typescript/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ configure_file(
configuration: bin_conf,
)

configure_file(
input: 'template/tsconfig.demos.json',
output: 'tsconfig.json',
install_dir: join_paths(pkgdatadir, 'demos'),
configuration: bin_conf,
)

configure_file(
input: 'types/workbench.d.ts',
output: 'workbench.d.ts',
Expand Down
14 changes: 14 additions & 0 deletions src/langs/typescript/template/tsconfig.demos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "ES2022",
"moduleResolution": "Bundler",
"target": "ES2022",
"skipLibCheck": true,
"lib": ["ES2022"],
},
"include": [
"./**/*.ts",
"@pkgdatadir@/langs/typescript/gi-types/index.d.ts",
"@pkgdatadir@/langs/typescript/types/workbench.d.ts",
]
}

0 comments on commit aa93014

Please sign in to comment.