2023-07-27 00:31:52 -05:00
|
|
|
/*
|
2024-02-13 09:59:27 -06:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 00:31:52 -05:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-12-19 22:05:36 -06:00
|
|
|
const fs = require('fs');
|
2024-11-10 00:41:40 -06:00
|
|
|
const child_process = require('child_process');
|
2023-12-14 05:16:02 -06:00
|
|
|
const packageJsonPath = __dirname + '/../package.json'
|
2022-12-19 22:05:36 -06:00
|
|
|
|
2023-12-14 05:16:02 -06:00
|
|
|
function build() {
|
|
|
|
try {
|
2024-11-10 00:41:40 -06:00
|
|
|
const gitDescribe = child_process.execSync('git describe --tags --always').toString().trim();
|
|
|
|
const gitCommit = child_process.execSync('git rev-parse HEAD').toString().trim();
|
2023-12-14 05:16:02 -06:00
|
|
|
const json = fs.readFileSync(packageJsonPath, 'utf-8')
|
|
|
|
const meta = JSON.parse(json);
|
|
|
|
fs.mkdirSync(__dirname + '/../built', { recursive: true });
|
2024-11-10 00:41:40 -06:00
|
|
|
fs.writeFileSync(__dirname + '/../built/meta.json',
|
|
|
|
JSON.stringify(
|
|
|
|
{
|
|
|
|
version: meta.version,
|
|
|
|
gitCommit: gitCommit,
|
|
|
|
gitDescribe: gitDescribe,
|
|
|
|
}), 'utf-8');
|
2023-12-14 05:16:02 -06:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
build();
|
|
|
|
|
|
|
|
if (process.argv.includes("--watch")) {
|
|
|
|
fs.watch(packageJsonPath, (event, filename) => {
|
|
|
|
console.log(`update ${filename} ...`)
|
|
|
|
build()
|
|
|
|
})
|
|
|
|
}
|