bigbuffet-rw/app/soapbox/utils/code.js

28 lines
642 B
JavaScript
Raw Normal View History

2021-03-30 10:43:45 -07:00
// @preval
const pkg = require('../../../package.json');
const { execSync } = require('child_process');
2021-03-30 10:43:45 -07:00
const shortRepoName = url => new URL(url).pathname.substring(1);
const version = pkg => {
try {
const head = String(execSync('git rev-parse HEAD'));
const tag = String(execSync(`git rev-parse v${pkg.version}`));
if (head !== tag) {
return `${pkg.version}-${head.substring(0, 7)}`;
} else {
return pkg.version;
}
} catch (e) {
return pkg.version;
}
};
2021-03-30 10:43:45 -07:00
module.exports = {
name: pkg.name,
url: pkg.repository.url,
repository: shortRepoName(pkg.repository.url),
version: version(pkg),
2021-03-30 10:43:45 -07:00
};