Skip to content

Commit

Permalink
feat: before build config option
Browse files Browse the repository at this point in the history
  • Loading branch information
ncpa0cpl committed May 14, 2024
1 parent d8699d6 commit 06ab07b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/config/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ export const ConfigSchema = DataType.RecordOf({
),
),
treeShake: OptionalField(DataType.Boolean),
beforeBuild: OptionalField(DataType.Custom((v): v is ((buildDir: string) => any) => {
return typeof v === "function";
})),
});

ConfigSchema.setTitle("Config");
Expand Down Expand Up @@ -182,6 +185,10 @@ ConfigSchema.recordOf.license.type.setDescription(
"The license of the application.\n\nDefault is `GPL-2.0`.",
);

ConfigSchema.recordOf.beforeBuild.type.setDescription(
"A function that will be called before the \"meson build\" command is executed. It will receive the build directory path as an argument.",
);

const polyfills = ConfigSchema.recordOf.polyfills.type;

polyfills.setDescription(
Expand Down
2 changes: 1 addition & 1 deletion src/programs/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { validatePrefix } from "../utils/validate-prefix";

export type DeepReadonly<T> = {
readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]>
: Readonly<T[P]>;
: T[P];
};

const WatchOpt = defineOption({
Expand Down
6 changes: 5 additions & 1 deletion src/programs/build-program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from "fs/promises";
import path from "path";
import rimraf from "rimraf";
import tar from "tar";
import { html, Output } from "termx-markup";
import { Output, html } from "termx-markup";
import { getAppData } from "../packaging/templates/data/appdata";
import { getDataBusname } from "../packaging/templates/data/busname";
import { getDataDesktopEntry } from "../packaging/templates/data/desktop-entry";
Expand Down Expand Up @@ -260,6 +260,10 @@ export class BuildProgram extends Program {
buildDirPath,
);

if (this.config.beforeBuild) {
await this.config.beforeBuild(buildDirPath);
}

await new Command("meson", ["setup", "_build"], {
cwd: buildDirPath,
}).run();
Expand Down
4 changes: 4 additions & 0 deletions src/programs/start-program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export class StartProgram extends BuildProgram {

await this.prepareBuildFiles(appName, buildDirPath);

if (this.config.beforeBuild) {
await this.config.beforeBuild(buildDirPath);
}

await new Command("meson", ["setup", "_build"], {
cwd: buildDirPath,
}).run();
Expand Down

0 comments on commit 06ab07b

Please sign in to comment.