@gjsify/cli 0.3.14 → 0.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/actions/build.d.ts +6 -2
- package/lib/actions/build.js +37 -8
- package/lib/commands/flatpak/build.d.ts +16 -0
- package/lib/commands/flatpak/build.js +187 -0
- package/lib/commands/flatpak/ci.d.ts +13 -0
- package/lib/commands/flatpak/ci.js +133 -0
- package/lib/commands/flatpak/deps.d.ts +12 -0
- package/lib/commands/flatpak/deps.js +96 -0
- package/lib/commands/flatpak/index.d.ts +7 -0
- package/lib/commands/flatpak/index.js +23 -0
- package/lib/commands/flatpak/init.d.ts +15 -0
- package/lib/commands/flatpak/init.js +154 -0
- package/lib/commands/flatpak/utils.d.ts +32 -0
- package/lib/commands/flatpak/utils.js +63 -0
- package/lib/commands/gsettings.d.ts +9 -0
- package/lib/commands/gsettings.js +72 -0
- package/lib/commands/index.d.ts +2 -0
- package/lib/commands/index.js +2 -0
- package/lib/commands/install.d.ts +1 -0
- package/lib/commands/install.js +66 -11
- package/lib/config.js +54 -2
- package/lib/index.js +3 -1
- package/lib/types/config-data.d.ts +145 -4
- package/lib/utils/install-global.d.ts +54 -0
- package/lib/utils/install-global.js +153 -0
- package/lib/utils/resolve-plugin-by-name.d.ts +21 -0
- package/lib/utils/resolve-plugin-by-name.js +75 -0
- package/package.json +10 -10
- package/src/actions/build.ts +41 -8
- package/src/commands/flatpak/build.ts +225 -0
- package/src/commands/flatpak/ci.ts +173 -0
- package/src/commands/flatpak/deps.ts +120 -0
- package/src/commands/flatpak/index.ts +53 -0
- package/src/commands/flatpak/init.ts +191 -0
- package/src/commands/flatpak/utils.ts +76 -0
- package/src/commands/gsettings.ts +87 -0
- package/src/commands/index.ts +2 -0
- package/src/commands/install.ts +90 -11
- package/src/config.ts +58 -2
- package/src/index.ts +4 -0
- package/src/types/config-data.ts +142 -4
- package/src/utils/install-global.ts +182 -0
- package/src/utils/resolve-plugin-by-name.ts +106 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
// `gjsify flatpak build` — wrap `flatpak-builder` with sensible defaults.
|
|
2
|
+
//
|
|
3
|
+
// Replaces the project-local `build-flatpak.sh`-style scripts: same flag
|
|
4
|
+
// shape (manifest, build-dir, install, repo, bundle), plus a `--tarball`
|
|
5
|
+
// helper for Flathub submissions.
|
|
6
|
+
|
|
7
|
+
import { spawn } from 'node:child_process';
|
|
8
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync } from 'node:fs';
|
|
9
|
+
import { dirname, resolve } from 'node:path';
|
|
10
|
+
import type { Command } from '../../types/index.js';
|
|
11
|
+
|
|
12
|
+
interface FlatpakBuildOptions {
|
|
13
|
+
manifest?: string;
|
|
14
|
+
buildDir?: string;
|
|
15
|
+
install?: boolean;
|
|
16
|
+
repo?: string;
|
|
17
|
+
bundle?: string;
|
|
18
|
+
tarball?: string;
|
|
19
|
+
forceClean?: boolean;
|
|
20
|
+
sandbox?: boolean;
|
|
21
|
+
deleteBuildDirs?: boolean;
|
|
22
|
+
installDepsFrom?: string;
|
|
23
|
+
verbose?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const flatpakBuildCommand: Command<unknown, FlatpakBuildOptions> = {
|
|
27
|
+
command: 'build [manifest]',
|
|
28
|
+
description:
|
|
29
|
+
'Build the Flatpak via `flatpak-builder`. Wraps a typical install + export + bundle + tarball pipeline.',
|
|
30
|
+
builder: (yargs) => {
|
|
31
|
+
return yargs
|
|
32
|
+
.positional('manifest', {
|
|
33
|
+
description: 'Path to the Flatpak manifest (default: first *.json that looks like a manifest in cwd)',
|
|
34
|
+
type: 'string',
|
|
35
|
+
normalize: true,
|
|
36
|
+
})
|
|
37
|
+
.option('build-dir', {
|
|
38
|
+
description: 'flatpak-builder working directory',
|
|
39
|
+
type: 'string',
|
|
40
|
+
default: 'flatpak-build',
|
|
41
|
+
normalize: true,
|
|
42
|
+
})
|
|
43
|
+
.option('install', {
|
|
44
|
+
description: 'After build, run `flatpak-builder --user --install` to install locally',
|
|
45
|
+
type: 'boolean',
|
|
46
|
+
default: false,
|
|
47
|
+
})
|
|
48
|
+
.option('repo', {
|
|
49
|
+
description: 'Export the build into the given OSTree repo (passes `--repo=<dir>` to flatpak-builder)',
|
|
50
|
+
type: 'string',
|
|
51
|
+
normalize: true,
|
|
52
|
+
})
|
|
53
|
+
.option('bundle', {
|
|
54
|
+
description: 'After --repo export, build a single-file bundle (`flatpak build-bundle`) at this path',
|
|
55
|
+
type: 'string',
|
|
56
|
+
normalize: true,
|
|
57
|
+
})
|
|
58
|
+
.option('tarball', {
|
|
59
|
+
description: 'Create a tarball of the build dir (parity with the legacy build-flatpak.sh tarball step)',
|
|
60
|
+
type: 'string',
|
|
61
|
+
normalize: true,
|
|
62
|
+
})
|
|
63
|
+
.option('force-clean', {
|
|
64
|
+
description: 'Pass --force-clean to flatpak-builder (default true)',
|
|
65
|
+
type: 'boolean',
|
|
66
|
+
default: true,
|
|
67
|
+
})
|
|
68
|
+
.option('sandbox', {
|
|
69
|
+
description: 'Pass --sandbox to flatpak-builder (default true)',
|
|
70
|
+
type: 'boolean',
|
|
71
|
+
default: true,
|
|
72
|
+
})
|
|
73
|
+
.option('delete-build-dirs', {
|
|
74
|
+
description: 'Pass --delete-build-dirs to flatpak-builder (default true)',
|
|
75
|
+
type: 'boolean',
|
|
76
|
+
default: true,
|
|
77
|
+
})
|
|
78
|
+
.option('install-deps-from', {
|
|
79
|
+
description: 'Pass --install-deps-from to flatpak-builder (e.g. `flathub`)',
|
|
80
|
+
type: 'string',
|
|
81
|
+
})
|
|
82
|
+
.option('verbose', {
|
|
83
|
+
description: 'Print the underlying flatpak-builder invocations',
|
|
84
|
+
type: 'boolean',
|
|
85
|
+
default: false,
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
handler: async (args) => {
|
|
89
|
+
const cwd = process.cwd();
|
|
90
|
+
const manifest = resolve(cwd, (args.manifest as string | undefined) ?? findDefaultManifest(cwd));
|
|
91
|
+
if (!existsSync(manifest)) {
|
|
92
|
+
throw new Error(`gjsify flatpak build: manifest ${manifest} not found`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const buildDir = resolve(cwd, args.buildDir ?? 'flatpak-build');
|
|
96
|
+
const sharedFlags: string[] = [];
|
|
97
|
+
if (args.forceClean !== false) sharedFlags.push('--force-clean');
|
|
98
|
+
if (args.sandbox !== false) sharedFlags.push('--sandbox');
|
|
99
|
+
if (args.deleteBuildDirs !== false) sharedFlags.push('--delete-build-dirs');
|
|
100
|
+
if (args.installDepsFrom) sharedFlags.push(`--install-deps-from=${args.installDepsFrom}`);
|
|
101
|
+
|
|
102
|
+
// Reset the build dir so re-runs don't pick up half-stale state.
|
|
103
|
+
if (existsSync(buildDir)) rmSync(buildDir, { recursive: true, force: true });
|
|
104
|
+
|
|
105
|
+
await runFlatpakBuilder([...sharedFlags, buildDir, manifest], { verbose: args.verbose });
|
|
106
|
+
|
|
107
|
+
if (args.install) {
|
|
108
|
+
await runFlatpakBuilder(
|
|
109
|
+
['--user', '--install', '--force-clean', buildDir, manifest],
|
|
110
|
+
{ verbose: args.verbose },
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (args.repo) {
|
|
115
|
+
const repoPath = resolve(cwd, args.repo);
|
|
116
|
+
mkdirSync(dirname(repoPath), { recursive: true });
|
|
117
|
+
await runFlatpakBuilder(
|
|
118
|
+
[`--repo=${repoPath}`, '--force-clean', buildDir, manifest],
|
|
119
|
+
{ verbose: args.verbose },
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (args.bundle) {
|
|
124
|
+
if (!args.repo) {
|
|
125
|
+
throw new Error(
|
|
126
|
+
'gjsify flatpak build: --bundle requires --repo (the bundle is built from the OSTree repo).',
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
const bundlePath = resolve(cwd, args.bundle);
|
|
130
|
+
mkdirSync(dirname(bundlePath), { recursive: true });
|
|
131
|
+
const repoPath = resolve(cwd, args.repo);
|
|
132
|
+
const appId = readManifestAppId(manifest);
|
|
133
|
+
await runFlatpak(
|
|
134
|
+
['build-bundle', repoPath, bundlePath, appId],
|
|
135
|
+
{ verbose: args.verbose },
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (args.tarball) {
|
|
140
|
+
const tarballPath = resolve(cwd, args.tarball);
|
|
141
|
+
mkdirSync(dirname(tarballPath), { recursive: true });
|
|
142
|
+
await runTar(['-czf', tarballPath, '-C', buildDir, '.'], { verbose: args.verbose });
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
console.log(`[gjsify flatpak build] done (${buildDir})`);
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/** Pick the first JSON file in cwd that looks like a Flatpak manifest. */
|
|
150
|
+
function findDefaultManifest(cwd: string): string {
|
|
151
|
+
return scanForManifest(cwd) ?? 'flatpak.json';
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function scanForManifest(cwd: string): string | undefined {
|
|
155
|
+
let entries: string[] = [];
|
|
156
|
+
try {
|
|
157
|
+
entries = readdirSync(cwd);
|
|
158
|
+
} catch {
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
for (const name of entries) {
|
|
162
|
+
if (!name.endsWith('.json')) continue;
|
|
163
|
+
if (name === 'package.json' || name === 'tsconfig.json' || name.startsWith('.')) continue;
|
|
164
|
+
try {
|
|
165
|
+
const json = JSON.parse(readFileSync(resolve(cwd, name), 'utf-8')) as Record<string, unknown>;
|
|
166
|
+
if (typeof json.id === 'string' && typeof json.runtime === 'string' && Array.isArray(json.modules)) {
|
|
167
|
+
return name;
|
|
168
|
+
}
|
|
169
|
+
} catch {
|
|
170
|
+
// Not JSON or unreadable — skip.
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function readManifestAppId(manifest: string): string {
|
|
177
|
+
const raw = readFileSync(manifest, 'utf-8');
|
|
178
|
+
const json = JSON.parse(raw) as { id?: unknown };
|
|
179
|
+
if (typeof json.id !== 'string') {
|
|
180
|
+
throw new Error(`gjsify flatpak build: ${manifest} has no string "id" field`);
|
|
181
|
+
}
|
|
182
|
+
return json.id;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async function runFlatpakBuilder(args: string[], opts: { verbose?: boolean }) {
|
|
186
|
+
return runProc('flatpak-builder', args, opts, {
|
|
187
|
+
notFoundHint:
|
|
188
|
+
'flatpak-builder not found. Install via your distro (Fedora: `sudo dnf install flatpak-builder`).',
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async function runFlatpak(args: string[], opts: { verbose?: boolean }) {
|
|
193
|
+
return runProc('flatpak', args, opts, {
|
|
194
|
+
notFoundHint: 'flatpak not found. Install via your distro and add Flathub: see https://flathub.org/setup.',
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async function runTar(args: string[], opts: { verbose?: boolean }) {
|
|
199
|
+
return runProc('tar', args, opts, { notFoundHint: 'tar not found.' });
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function runProc(
|
|
203
|
+
cmd: string,
|
|
204
|
+
args: string[],
|
|
205
|
+
opts: { verbose?: boolean },
|
|
206
|
+
extra: { notFoundHint: string },
|
|
207
|
+
): Promise<void> {
|
|
208
|
+
if (opts.verbose) {
|
|
209
|
+
console.log(`[gjsify flatpak] ${cmd} ${args.join(' ')}`);
|
|
210
|
+
}
|
|
211
|
+
return new Promise((res, rej) => {
|
|
212
|
+
const child = spawn(cmd, args, { stdio: 'inherit' });
|
|
213
|
+
child.on('error', (err: NodeJS.ErrnoException) => {
|
|
214
|
+
if (err.code === 'ENOENT') {
|
|
215
|
+
rej(new Error(`gjsify flatpak: ${extra.notFoundHint}`));
|
|
216
|
+
} else {
|
|
217
|
+
rej(err);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
child.on('exit', (code) => {
|
|
221
|
+
if (code === 0) res();
|
|
222
|
+
else rej(new Error(`gjsify flatpak: ${cmd} exited with status ${code}`));
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// `gjsify flatpak ci` — scaffold .github/workflows/flatpak.yml in the
|
|
2
|
+
// shape used by Flathub-hosted apps:
|
|
3
|
+
//
|
|
4
|
+
// * upstream `flatpak/flatpak-github-actions/flatpak-builder@v6` action
|
|
5
|
+
// * `ghcr.io/flathub-infra/flatpak-github-actions:<runtime>-<version>` container
|
|
6
|
+
// * cache key keyed by commit SHA
|
|
7
|
+
//
|
|
8
|
+
// Idempotent: refuses to overwrite an existing workflow without `--force`.
|
|
9
|
+
|
|
10
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
11
|
+
import { dirname, resolve } from 'node:path';
|
|
12
|
+
import type { Command, ConfigData, ConfigDataFlatpak } from '../../types/index.js';
|
|
13
|
+
import { Config } from '../../config.js';
|
|
14
|
+
import { defaultCiContainer, looksLikeAppId, readPackageJson, resolveRuntime } from './utils.js';
|
|
15
|
+
|
|
16
|
+
interface FlatpakCiOptions {
|
|
17
|
+
manifest?: string;
|
|
18
|
+
bundle?: string;
|
|
19
|
+
runtimeImage?: string;
|
|
20
|
+
branches?: string[];
|
|
21
|
+
out?: string;
|
|
22
|
+
force?: boolean;
|
|
23
|
+
cacheKey?: string;
|
|
24
|
+
verbose?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const flatpakCiCommand: Command<unknown, FlatpakCiOptions> = {
|
|
28
|
+
command: 'ci',
|
|
29
|
+
description:
|
|
30
|
+
'Scaffold .github/workflows/flatpak.yml using the flathub-infra container + flatpak-builder@v6 action.',
|
|
31
|
+
builder: (yargs) => {
|
|
32
|
+
return yargs
|
|
33
|
+
.option('manifest', {
|
|
34
|
+
description: 'Manifest path the workflow points at (default: <app-id>.json)',
|
|
35
|
+
type: 'string',
|
|
36
|
+
normalize: true,
|
|
37
|
+
})
|
|
38
|
+
.option('bundle', {
|
|
39
|
+
description: 'Bundle filename produced by the action (default: <app-id>.flatpak)',
|
|
40
|
+
type: 'string',
|
|
41
|
+
normalize: true,
|
|
42
|
+
})
|
|
43
|
+
.option('runtime-image', {
|
|
44
|
+
description:
|
|
45
|
+
'Container image override. Default derived from gjsify.flatpak.runtime + runtimeVersion (e.g. `ghcr.io/flathub-infra/flatpak-github-actions:gnome-50`).',
|
|
46
|
+
type: 'string',
|
|
47
|
+
})
|
|
48
|
+
.option('branches', {
|
|
49
|
+
description: 'Branches the workflow runs on push for (default: main)',
|
|
50
|
+
type: 'string',
|
|
51
|
+
array: true,
|
|
52
|
+
})
|
|
53
|
+
.option('out', {
|
|
54
|
+
description: 'Output path',
|
|
55
|
+
type: 'string',
|
|
56
|
+
default: '.github/workflows/flatpak.yml',
|
|
57
|
+
normalize: true,
|
|
58
|
+
})
|
|
59
|
+
.option('cache-key', {
|
|
60
|
+
description: 'Override the action `cache-key` (default: `flatpak-builder-${{ github.sha }}`)',
|
|
61
|
+
type: 'string',
|
|
62
|
+
})
|
|
63
|
+
.option('force', {
|
|
64
|
+
description: 'Overwrite an existing workflow file',
|
|
65
|
+
type: 'boolean',
|
|
66
|
+
default: false,
|
|
67
|
+
})
|
|
68
|
+
.option('verbose', {
|
|
69
|
+
description: 'Print resolved fields',
|
|
70
|
+
type: 'boolean',
|
|
71
|
+
default: false,
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
handler: async (args) => {
|
|
75
|
+
const cwd = process.cwd();
|
|
76
|
+
const cfg = new Config();
|
|
77
|
+
const configData = await cfg.forBuild({} as never).catch(() => ({} as ConfigData));
|
|
78
|
+
const flatpak: ConfigDataFlatpak = configData.flatpak ?? {};
|
|
79
|
+
const pkg = readPackageJson(cwd);
|
|
80
|
+
|
|
81
|
+
const appId =
|
|
82
|
+
flatpak.appId ??
|
|
83
|
+
(looksLikeAppId(pkg.name) ? (pkg.name as string) : undefined);
|
|
84
|
+
if (!appId) {
|
|
85
|
+
throw new Error(
|
|
86
|
+
'gjsify flatpak ci: no app id available. Set gjsify.flatpak.appId in package.json ' +
|
|
87
|
+
'or rename the package to a reverse-DNS id.',
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const manifest = (args.manifest as string | undefined) ?? `${appId}.json`;
|
|
92
|
+
const bundle = (args.bundle as string | undefined) ?? `${appId}.flatpak`;
|
|
93
|
+
|
|
94
|
+
const { runtime, runtimeVersion } = resolveRuntime(flatpak, {});
|
|
95
|
+
const runtimeImage =
|
|
96
|
+
(args.runtimeImage as string | undefined) ??
|
|
97
|
+
flatpak.ciContainer ??
|
|
98
|
+
defaultCiContainer(runtime, runtimeVersion);
|
|
99
|
+
|
|
100
|
+
const branches = (args.branches as string[] | undefined) ?? flatpak.ciBranches ?? ['main'];
|
|
101
|
+
const cacheKey = args.cacheKey ?? 'flatpak-builder-${{ github.sha }}';
|
|
102
|
+
|
|
103
|
+
const out = resolve(cwd, args.out ?? '.github/workflows/flatpak.yml');
|
|
104
|
+
if (existsSync(out) && !args.force) {
|
|
105
|
+
// Same content → silently skip; different content → fail with a hint.
|
|
106
|
+
const existing = readFileSync(out, 'utf-8');
|
|
107
|
+
const next = renderWorkflow({ manifest, bundle, runtimeImage, branches, cacheKey });
|
|
108
|
+
if (existing === next) {
|
|
109
|
+
console.log(`[gjsify flatpak ci] ${out} already up to date`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
throw new Error(
|
|
113
|
+
`gjsify flatpak ci: ${out} exists with different content. Pass --force to overwrite.`,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const content = renderWorkflow({ manifest, bundle, runtimeImage, branches, cacheKey });
|
|
118
|
+
mkdirSync(dirname(out), { recursive: true });
|
|
119
|
+
writeFileSync(out, content, 'utf-8');
|
|
120
|
+
|
|
121
|
+
if (args.verbose) {
|
|
122
|
+
console.log(
|
|
123
|
+
`[gjsify flatpak ci] runtime-image=${runtimeImage} manifest=${manifest} bundle=${bundle}`,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
console.log(`[gjsify flatpak ci] wrote ${out}`);
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
interface RenderInput {
|
|
131
|
+
manifest: string;
|
|
132
|
+
bundle: string;
|
|
133
|
+
runtimeImage: string;
|
|
134
|
+
branches: string[];
|
|
135
|
+
cacheKey: string;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Render the workflow YAML. Format string built explicitly (no template
|
|
140
|
+
* library) so the output is byte-stable for diff-based code review.
|
|
141
|
+
*/
|
|
142
|
+
function renderWorkflow(input: RenderInput): string {
|
|
143
|
+
const branchesYaml = `[${input.branches.map((b) => JSON.stringify(b)).join(', ')}]`;
|
|
144
|
+
return `name: Flatpak
|
|
145
|
+
|
|
146
|
+
on:
|
|
147
|
+
push:
|
|
148
|
+
branches: ${branchesYaml}
|
|
149
|
+
pull_request:
|
|
150
|
+
branches: ${branchesYaml}
|
|
151
|
+
|
|
152
|
+
jobs:
|
|
153
|
+
flatpak:
|
|
154
|
+
name: Flatpak Build
|
|
155
|
+
runs-on: ubuntu-latest
|
|
156
|
+
container:
|
|
157
|
+
image: ${input.runtimeImage}
|
|
158
|
+
options: --privileged
|
|
159
|
+
|
|
160
|
+
steps:
|
|
161
|
+
- name: Checkout repository
|
|
162
|
+
uses: actions/checkout@v4
|
|
163
|
+
with:
|
|
164
|
+
submodules: false
|
|
165
|
+
|
|
166
|
+
- name: Build Flatpak
|
|
167
|
+
uses: flatpak/flatpak-github-actions/flatpak-builder@v6
|
|
168
|
+
with:
|
|
169
|
+
manifest-path: ${input.manifest}
|
|
170
|
+
bundle: ${input.bundle}
|
|
171
|
+
cache-key: ${input.cacheKey}
|
|
172
|
+
`;
|
|
173
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// `gjsify flatpak deps` — wrap `flatpak-node-generator` to convert a
|
|
2
|
+
// yarn.lock / package-lock.json into the JSON sources file that the
|
|
3
|
+
// Flatpak manifest references for offline `yarn install` inside the
|
|
4
|
+
// build sandbox.
|
|
5
|
+
//
|
|
6
|
+
// flatpak-node-generator is a Python tool from
|
|
7
|
+
// https://github.com/flatpak/flatpak-builder-tools — installed via
|
|
8
|
+
// `pipx install flatpak-node-generator` or `pip install --user
|
|
9
|
+
// flatpak-node-generator`.
|
|
10
|
+
|
|
11
|
+
import { spawn } from 'node:child_process';
|
|
12
|
+
import { existsSync } from 'node:fs';
|
|
13
|
+
import { dirname, resolve } from 'node:path';
|
|
14
|
+
import { mkdirSync } from 'node:fs';
|
|
15
|
+
import type { Command } from '../../types/index.js';
|
|
16
|
+
|
|
17
|
+
interface FlatpakDepsOptions {
|
|
18
|
+
lockfile?: string;
|
|
19
|
+
type?: 'yarn' | 'npm';
|
|
20
|
+
out?: string;
|
|
21
|
+
xdgLayout?: boolean;
|
|
22
|
+
nodeChromedriverFromElectron?: string;
|
|
23
|
+
electronNodeHeaders?: boolean;
|
|
24
|
+
verbose?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const flatpakDepsCommand: Command<unknown, FlatpakDepsOptions> = {
|
|
28
|
+
command: 'deps',
|
|
29
|
+
description:
|
|
30
|
+
'Generate Flatpak offline-cache sources from a yarn.lock / package-lock.json (wraps `flatpak-node-generator`).',
|
|
31
|
+
builder: (yargs) => {
|
|
32
|
+
return yargs
|
|
33
|
+
.option('lockfile', {
|
|
34
|
+
description: 'Path to lockfile (default: yarn.lock or package-lock.json in cwd)',
|
|
35
|
+
type: 'string',
|
|
36
|
+
normalize: true,
|
|
37
|
+
})
|
|
38
|
+
.option('type', {
|
|
39
|
+
description: 'Lockfile type. Default: detected from filename.',
|
|
40
|
+
choices: ['yarn', 'npm'] as const,
|
|
41
|
+
})
|
|
42
|
+
.option('out', {
|
|
43
|
+
description: 'Output JSON sources file',
|
|
44
|
+
type: 'string',
|
|
45
|
+
default: 'flatpak-node-sources.json',
|
|
46
|
+
normalize: true,
|
|
47
|
+
})
|
|
48
|
+
.option('xdg-layout', {
|
|
49
|
+
description: 'Pass --xdg-layout (recommended for Yarn Berry / PnP setups)',
|
|
50
|
+
type: 'boolean',
|
|
51
|
+
default: true,
|
|
52
|
+
})
|
|
53
|
+
.option('electron-node-headers', {
|
|
54
|
+
description: 'Pass --electron-node-headers',
|
|
55
|
+
type: 'boolean',
|
|
56
|
+
default: false,
|
|
57
|
+
})
|
|
58
|
+
.option('verbose', {
|
|
59
|
+
description: 'Print the underlying flatpak-node-generator invocation',
|
|
60
|
+
type: 'boolean',
|
|
61
|
+
default: false,
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
handler: async (args) => {
|
|
65
|
+
const cwd = process.cwd();
|
|
66
|
+
const lockfile = resolve(
|
|
67
|
+
cwd,
|
|
68
|
+
(args.lockfile as string | undefined) ?? detectLockfile(cwd),
|
|
69
|
+
);
|
|
70
|
+
if (!existsSync(lockfile)) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`gjsify flatpak deps: lockfile ${lockfile} not found (use --lockfile to override)`,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const type =
|
|
77
|
+
(args.type as 'yarn' | 'npm' | undefined) ??
|
|
78
|
+
(lockfile.endsWith('package-lock.json') ? 'npm' : 'yarn');
|
|
79
|
+
|
|
80
|
+
const out = resolve(cwd, args.out ?? 'flatpak-node-sources.json');
|
|
81
|
+
mkdirSync(dirname(out), { recursive: true });
|
|
82
|
+
|
|
83
|
+
const cmdArgs = [type, lockfile, '-o', out];
|
|
84
|
+
if (args.xdgLayout !== false) cmdArgs.push('--xdg-layout');
|
|
85
|
+
if (args.electronNodeHeaders) cmdArgs.push('--electron-node-headers');
|
|
86
|
+
|
|
87
|
+
if (args.verbose) {
|
|
88
|
+
console.log(`[gjsify flatpak deps] flatpak-node-generator ${cmdArgs.join(' ')}`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
await new Promise<void>((res, rej) => {
|
|
92
|
+
const child = spawn('flatpak-node-generator', cmdArgs, { stdio: 'inherit' });
|
|
93
|
+
child.on('error', (err: NodeJS.ErrnoException) => {
|
|
94
|
+
if (err.code === 'ENOENT') {
|
|
95
|
+
rej(
|
|
96
|
+
new Error(
|
|
97
|
+
'gjsify flatpak deps: flatpak-node-generator not found. ' +
|
|
98
|
+
'Install via `pipx install flatpak-node-generator` ' +
|
|
99
|
+
'(see https://github.com/flatpak/flatpak-builder-tools/tree/master/node).',
|
|
100
|
+
),
|
|
101
|
+
);
|
|
102
|
+
} else {
|
|
103
|
+
rej(err);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
child.on('exit', (code) => {
|
|
107
|
+
if (code === 0) res();
|
|
108
|
+
else rej(new Error(`gjsify flatpak deps: flatpak-node-generator exited with status ${code}`));
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
console.log(`[gjsify flatpak deps] wrote ${out}`);
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
function detectLockfile(cwd: string): string {
|
|
117
|
+
if (existsSync(resolve(cwd, 'yarn.lock'))) return 'yarn.lock';
|
|
118
|
+
if (existsSync(resolve(cwd, 'package-lock.json'))) return 'package-lock.json';
|
|
119
|
+
return 'yarn.lock'; // surfaces a clear "not found" later
|
|
120
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// `gjsify flatpak` — yargs subcommand-group dispatcher.
|
|
2
|
+
//
|
|
3
|
+
// Wires {init, build, deps, ci}. Each subcommand is a self-contained
|
|
4
|
+
// `Command<>` so it composes the same way as `gresource` / `gettext` /
|
|
5
|
+
// `gsettings` at the top level.
|
|
6
|
+
|
|
7
|
+
import type { Command } from '../../types/index.js';
|
|
8
|
+
import { flatpakInitCommand } from './init.js';
|
|
9
|
+
import { flatpakBuildCommand } from './build.js';
|
|
10
|
+
import { flatpakDepsCommand } from './deps.js';
|
|
11
|
+
import { flatpakCiCommand } from './ci.js';
|
|
12
|
+
|
|
13
|
+
export const flatpakCommand: Command = {
|
|
14
|
+
command: 'flatpak <subcommand>',
|
|
15
|
+
description:
|
|
16
|
+
'Flatpak toolchain: init/build/deps/ci subcommands for shipping GJS apps and CLIs as Flatpaks.',
|
|
17
|
+
builder: (yargs) => {
|
|
18
|
+
return yargs
|
|
19
|
+
.command(
|
|
20
|
+
flatpakInitCommand.command as string,
|
|
21
|
+
flatpakInitCommand.description,
|
|
22
|
+
flatpakInitCommand.builder!,
|
|
23
|
+
flatpakInitCommand.handler!,
|
|
24
|
+
)
|
|
25
|
+
.command(
|
|
26
|
+
flatpakBuildCommand.command as string,
|
|
27
|
+
flatpakBuildCommand.description,
|
|
28
|
+
flatpakBuildCommand.builder!,
|
|
29
|
+
flatpakBuildCommand.handler!,
|
|
30
|
+
)
|
|
31
|
+
.command(
|
|
32
|
+
flatpakDepsCommand.command as string,
|
|
33
|
+
flatpakDepsCommand.description,
|
|
34
|
+
flatpakDepsCommand.builder!,
|
|
35
|
+
flatpakDepsCommand.handler!,
|
|
36
|
+
)
|
|
37
|
+
.command(
|
|
38
|
+
flatpakCiCommand.command as string,
|
|
39
|
+
flatpakCiCommand.description,
|
|
40
|
+
flatpakCiCommand.builder!,
|
|
41
|
+
flatpakCiCommand.handler!,
|
|
42
|
+
)
|
|
43
|
+
.demandCommand(1)
|
|
44
|
+
.strict();
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
flatpakInitCommand,
|
|
50
|
+
flatpakBuildCommand,
|
|
51
|
+
flatpakDepsCommand,
|
|
52
|
+
flatpakCiCommand,
|
|
53
|
+
};
|