65 lines
1.9 KiB
JavaScript
65 lines
1.9 KiB
JavaScript
import { readFile, writeFile } from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
import process from 'node:process';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { parseToolboxApp } from '@add-ideas/toolbox-contract';
|
|
import { format } from 'prettier';
|
|
|
|
const projectRoot = path.resolve(
|
|
path.dirname(fileURLToPath(import.meta.url)),
|
|
'..'
|
|
);
|
|
const packageJsonPath = path.join(projectRoot, 'package.json');
|
|
const definitionPath = path.join(
|
|
projectRoot,
|
|
'src',
|
|
'toolbox',
|
|
'manifest.definition.json'
|
|
);
|
|
const versionSourcePath = path.join(projectRoot, 'src', 'version.ts');
|
|
const manifestPath = path.join(projectRoot, 'public', 'toolbox-app.json');
|
|
|
|
const [packageJson, definition, versionSource] = await Promise.all([
|
|
readJson(packageJsonPath),
|
|
readJson(definitionPath),
|
|
readFile(versionSourcePath, 'utf8'),
|
|
]);
|
|
|
|
const sourceVersion = versionSource.match(
|
|
/APP_VERSION\s*=\s*['"]([^'"]+)['"]/
|
|
)?.[1];
|
|
|
|
if (!sourceVersion) {
|
|
throw new Error('Could not read APP_VERSION from src/version.ts.');
|
|
}
|
|
if (sourceVersion !== packageJson.version) {
|
|
throw new Error(
|
|
`Version mismatch: package.json is ${packageJson.version}, while src/version.ts is ${sourceVersion}.`
|
|
);
|
|
}
|
|
|
|
const manifest = {
|
|
$schema:
|
|
'https://git.add-ideas.de/lotobo/toolbox-sdk/raw/branch/main/schemas/toolbox-app.v1.schema.json',
|
|
schemaVersion: 1,
|
|
...definition,
|
|
version: packageJson.version,
|
|
};
|
|
parseToolboxApp(manifest);
|
|
const output = await format(JSON.stringify(manifest), { 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);
|
|
}
|
|
|
|
async function readJson(filePath) {
|
|
return JSON.parse(await readFile(filePath, 'utf8'));
|
|
}
|