0
0
switched/scripts/build-pre.js

45 lines
1021 B
JavaScript
Raw Normal View History

/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
const fs = require('fs');
2024-08-20 20:59:15 +09:00
const packageJsonPath = __dirname + '/../package.json';
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');
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;
}
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');
} catch (e) {
2024-08-20 20:59:15 +09:00
console.error(e);
}
}
build();
2024-08-20 20:59:15 +09:00
if (process.argv.includes('--watch')) {
fs.watch(packageJsonPath, (event, filename) => {
2024-08-20 20:59:15 +09:00
console.log(`update ${filename} ...`);
build();
});
}