Skip to content

Build your personal knowledge base with Trilium Notes

refactor(flatpak): expose manifest rendering and the generator command

Elian Doran8e1342033d02
diff --git a/scripts/flatpak/generate-sources.mts b/scripts/flatpak/generate-sources.mts
index 70a66d31df..b238e7d00c 100644
--- a/scripts/flatpak/generate-sources.mts
+++ b/scripts/flatpak/generate-sources.mts
@@ -39,10 +39,10 @@ interface Source {
[key: string]: unknown;
}
-export function main(argv: string[]) {
+export function main(argv: string[], generator = [ "flatpak-node-generator" ]) {
const outputPath = resolveOutputPath(argv[0]);
checkPnpm(readFileSync(PACKAGE_JSON_PATH, "utf-8"));
- generateSources(outputPath);
+ generateSources(outputPath, generator);
const sources: Source[] = JSON.parse(readFileSync(outputPath, "utf-8"));
const kept = filterSources(sources);
@@ -96,10 +96,11 @@ export function filterSources(sources: Source[]): Source[] {
return kept;
}
-function generateSources(outputPath: string) {
+function generateSources(outputPath: string, [ command, ...args ]: string[]) {
mkdirSync(dirname(outputPath), { recursive: true });
try {
- execFileSync("flatpak-node-generator", [
+ execFileSync(command, [
+ ...args,
"pnpm", LOCKFILE_PATH,
"--pnpm-store-version", STORE_VERSION,
"-o", outputPath
diff --git a/scripts/flatpak/update-repo.mts b/scripts/flatpak/update-repo.mts
index cd9a9bf38f..07b77eec67 100644
--- a/scripts/flatpak/update-repo.mts
+++ b/scripts/flatpak/update-repo.mts
@@ -25,7 +25,7 @@ import { join, resolve } from "node:path";
const REPO_ROOT = join(import.meta.dirname, "../..");
const FLATPAK_DIR = join(REPO_ROOT, "apps/desktop/flatpak");
-const MANIFEST_NAME = "org.triliumnotes.Trilium.yml";
+export const MANIFEST_NAME = "org.triliumnotes.Trilium.yml";
// The wrapper is a manifest source; flathub.json configures Flathub's bots and
// only takes effect on the packaging repo's default branch.
const COPIED_FILES = [ "trilium.sh", "flathub.json" ];
@@ -41,6 +41,24 @@ export async function main(argv: string[]) {
}
const repoDir = resolve(repoDirArg);
+ const { manifest, commit, tag, pnpmVersion } = await renderManifest(ref);
+ writePackagingFiles(repoDir, manifest);
+ // `git ls-files` keeps listing a deletion that is staged but not committed, so a
+ // re-run against the same checkout finds the file already gone.
+ for (const file of selectStaleFiles(gitIn(repoDir, "ls-files"))) {
+ if (existsSync(join(repoDir, file))) {
+ rmSync(join(repoDir, file));
+ console.log(`Removed ${file}, which the recipe no longer owns.`);
+ }
+ }
+ if (process.env.GITHUB_OUTPUT) {
+ appendFileSync(process.env.GITHUB_OUTPUT, formatOutputs(commit, tag, pnpmVersion));
+ }
+ console.log(`Updated ${repoDir}: ${tag ?? "beta"} @ ${commit}, pnpm ${pnpmVersion}.`);
+}
+
+/** The manifest with every placeholder filled in for `ref`, which must resolve to a commit. */
+export async function renderManifest(ref: string) {
const commit = git("rev-parse", `${ref}^{commit}`);
const tag = isTag(ref) ? ref : undefined;
@@ -53,23 +71,15 @@ export async function main(argv: string[]) {
arm64: await sha256OfUrl(pnpmExeUrl("arm64", pnpmVersion))
});
checkPlaceholdersFilled(manifest);
+ return { manifest, commit, tag, pnpmVersion };
+}
- writeFileSync(join(repoDir, MANIFEST_NAME), manifest);
+/** Writes the manifest and copies the files it names as sources next to it. */
+export function writePackagingFiles(dir: string, manifest: string) {
+ writeFileSync(join(dir, MANIFEST_NAME), manifest);
for (const file of COPIED_FILES) {
- copyFileSync(join(FLATPAK_DIR, file), join(repoDir, file));
+ copyFileSync(join(FLATPAK_DIR, file), join(dir, file));
}
- // `git ls-files` keeps listing a deletion that is staged but not committed, so a
- // re-run against the same checkout finds the file already gone.
- for (const file of selectStaleFiles(gitIn(repoDir, "ls-files"))) {
- if (existsSync(join(repoDir, file))) {
- rmSync(join(repoDir, file));
- console.log(`Removed ${file}, which the recipe no longer owns.`);
- }
- }
- if (process.env.GITHUB_OUTPUT) {
- appendFileSync(process.env.GITHUB_OUTPUT, formatOutputs(commit, tag, pnpmVersion));
- }
- console.log(`Updated ${repoDir}: ${tag ?? "beta"} @ ${commit}, pnpm ${pnpmVersion}.`);
}
/**