2023-07-27 14:31:52 +09:00
|
|
|
/*
|
2024-02-13 15:59:27 +00: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');
|
2023-12-14 20:16:02 +09:00
|
|
|
const packageJsonPath = __dirname + '/../package.json'
|
2025-06-25 09:13:17 +01:00
|
|
|
const { execFileSync } = require('node:child_process');
|
2022-12-20 13:05:36 +09:00
|
|
|
|
2025-08-02 10:54:00 +01:00
|
|
|
function callGit(args) {
|
|
|
|
return execFileSync('git', args, {
|
|
|
|
encoding: 'utf-8',
|
|
|
|
}).trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getGitVersion(versionFromPackageJson) {
|
|
|
|
const thisTag = callGit(['tag', '--points-at', 'HEAD']);
|
|
|
|
if (thisTag) {
|
|
|
|
// we're building from a tag, we don't care about extra details
|
|
|
|
return null;
|
2025-06-25 09:13:17 +01:00
|
|
|
}
|
|
|
|
|
2025-08-02 10:54:00 +01:00
|
|
|
const commitId = callGit(['rev-parse', '--short', 'HEAD']);
|
|
|
|
return `${versionFromPackageJson}+g${commitId}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
function build() {
|
2023-12-14 20:16:02 +09:00
|
|
|
try {
|
|
|
|
const json = fs.readFileSync(packageJsonPath, 'utf-8')
|
|
|
|
const meta = JSON.parse(json);
|
2025-08-02 10:54:00 +01:00
|
|
|
|
|
|
|
let gitVersion;
|
|
|
|
try {
|
|
|
|
gitVersion = getGitVersion(meta.version);
|
|
|
|
} catch (e) {
|
|
|
|
console.warn("couldn't get git commit details, ignoring",e);
|
|
|
|
}
|
|
|
|
|
2023-12-14 20:16:02 +09:00
|
|
|
fs.mkdirSync(__dirname + '/../built', { recursive: true });
|
2025-06-25 09:13:17 +01:00
|
|
|
fs.writeFileSync(__dirname + '/../built/meta.json', JSON.stringify({ version: meta.version, gitVersion }), 'utf-8');
|
2023-12-14 20:16:02 +09:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
build();
|
|
|
|
|
|
|
|
if (process.argv.includes("--watch")) {
|
|
|
|
fs.watch(packageJsonPath, (event, filename) => {
|
|
|
|
console.log(`update ${filename} ...`)
|
|
|
|
build()
|
|
|
|
})
|
|
|
|
}
|