/
githubmirror
/
TypeScript
Обзор
Документация
Войти
/
githubmirror
/
TypeScript
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
scripts/addPackageJsonGitHead.mjs
24 строки
716 B
Jake Bailey
Add gitHead to package.json in all release workflows (#58135)
20 апр 2024, 01:54
Не верифицирован
20 апр 2024, 01:54
c50ec79
Код
Авторство
О чём код?
import { execFileSync } from "child_process"; import { readFileSync, writeFileSync, } from "fs"; import { dirname, resolve, } from "path"; const packageJsonFilePath = process.argv[2]; if (!packageJsonFilePath) { console.error("Usage: node addPackageJsonGitHead.mjs <package.json location>"); process.exit(1); } const packageJsonValue = JSON.parse(readFileSync(packageJsonFilePath, "utf8")); const cwd = dirname(resolve(packageJsonFilePath)); const gitHead = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8" }).trim(); packageJsonValue.gitHead = gitHead; writeFileSync(packageJsonFilePath, JSON.stringify(packageJsonValue, undefined, 4) + "\n");