34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
import { readFile, writeFile } from 'node:fs/promises';
|
|
import { dirname, join, resolve } from 'node:path';
|
|
import process from 'node:process';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { format } from 'prettier';
|
|
import { toolboxAppDefinition } from '../src/toolboxApp.ts';
|
|
|
|
const repositoryRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
const packageJson = JSON.parse(
|
|
await readFile(join(repositoryRoot, 'package.json'), 'utf8')
|
|
);
|
|
const manifestPath = join(repositoryRoot, 'public', 'toolbox-app.json');
|
|
|
|
if (toolboxAppDefinition.version !== packageJson.version) {
|
|
throw new Error(
|
|
`Version mismatch: package.json is ${packageJson.version}, while src/toolboxApp.ts is ${toolboxAppDefinition.version}.`
|
|
);
|
|
}
|
|
|
|
const output = await format(JSON.stringify(toolboxAppDefinition), {
|
|
parser: 'json',
|
|
});
|
|
|
|
if (process.argv.includes('--check')) {
|
|
const existing = await readFile(manifestPath, 'utf8').catch(() => '');
|
|
if (existing !== output) {
|
|
throw new Error(
|
|
'public/toolbox-app.json is out of date. Run `npm run manifest:generate`.'
|
|
);
|
|
}
|
|
} else {
|
|
await writeFile(manifestPath, output);
|
|
}
|