2023-07-27 14:31:52 +09:00
|
|
|
/*
|
2024-02-14 00:59:27 +09:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 14:31:52 +09:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-12-20 13:05:36 +09:00
|
|
|
const fs = require('fs');
|
2024-08-20 20:59:15 +09:00
|
|
|
const packageJsonPath = __dirname + '/../package.json';
|
2022-12-20 13:05:36 +09:00
|
|
|
|
2023-12-14 20:16:02 +09:00
|
|
|
function build() {
|
|
|
|
try {
|
2024-08-20 20:59:15 +09:00
|
|
|
const commit = require('child_process')
|
|
|
|
.execSync('git rev-parse --short=7 HEAD', {
|
|
|
|
encoding: 'utf-8',
|
|
|
|
stdio: ['ignore', 'pipe', 'ignore']
|
|
|
|
})
|
|
|
|
.trim();
|
|
|
|
|
|
|
|
const json = fs.readFileSync(packageJsonPath, 'utf-8');
|
2023-12-14 20:16:02 +09:00
|
|
|
const meta = JSON.parse(json);
|
2024-08-20 20:59:15 +09:00
|
|
|
let version = meta.version;
|
|
|
|
|
|
|
|
if (meta.prefix) {
|
|
|
|
version += '+' + meta.prefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (commit !== 'unknown') {
|
|
|
|
version += meta.prefix ? '-' + commit : '+' + commit;
|
|
|
|
}
|
|
|
|
|
2023-12-14 20:16:02 +09:00
|
|
|
fs.mkdirSync(__dirname + '/../built', { recursive: true });
|
2024-08-20 20:59:15 +09:00
|
|
|
fs.writeFileSync(__dirname + '/../built/meta.json', JSON.stringify({ version: version }), 'utf-8');
|
2023-12-14 20:16:02 +09:00
|
|
|
} catch (e) {
|
2024-08-20 20:59:15 +09:00
|
|
|
console.error(e);
|
2023-12-14 20:16:02 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
build();
|
|
|
|
|
2024-08-20 20:59:15 +09:00
|
|
|
if (process.argv.includes('--watch')) {
|
2023-12-14 20:16:02 +09:00
|
|
|
fs.watch(packageJsonPath, (event, filename) => {
|
2024-08-20 20:59:15 +09:00
|
|
|
console.log(`update ${filename} ...`);
|
|
|
|
build();
|
|
|
|
});
|
2023-12-14 20:16:02 +09:00
|
|
|
}
|