-
Notifications
You must be signed in to change notification settings - Fork 17
/
generate-infos.js
37 lines (33 loc) · 1.11 KB
/
generate-infos.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const {exec} = require('child_process')
const {readFile, writeFile} = require('fs').promises
function run(cmd) {
return new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => {
if (error) {
return reject(error)
}
if (stderr) {
return reject(stderr)
}
resolve(stdout)
})
})
}
// Usage example
(async () => {
let gitCurrentHash = await run('git rev-parse HEAD')
gitCurrentHash = gitCurrentHash.replace(/(\r\n|\n|\r)/gm, '')
console.log(gitCurrentHash)
const data = JSON.parse(await readFile('package.json', 'utf8'))
const packageNameDecoupageAdmin = '@etalab/decoupage-administratif'
const decoupageAdminPackageVersion = data.devDependencies[packageNameDecoupageAdmin]
const packageNameApiGeo = data.name
const apiGeoPackageVersion = data.version
console.log(decoupageAdminPackageVersion)
await writeFile('api_infos.json', JSON.stringify({
// eslint-disable-next-line camelcase
git_hash_api_geo: gitCurrentHash,
[packageNameApiGeo]: apiGeoPackageVersion,
[packageNameDecoupageAdmin]: decoupageAdminPackageVersion
}))
})()