Created
September 6, 2018 18:09
-
-
Save kdimatteo/38a1a550e8967008db7eb2b73f01744c to your computer and use it in GitHub Desktop.
Write a version-file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as rootRequire from 'root-require'; | |
import * as cp from 'child_process'; | |
import * as fs from 'fs'; | |
const packageLockJSON = rootRequire('./package-lock.json'); | |
const packageJSON = rootRequire('./package.json'); | |
const versionFile = 'dist/assets/version.json'; | |
const orgPrefix = '@mhe' | |
const output = { | |
repoName: packageJSON.name, | |
description: 'Selected dependency and exported package versions.', | |
lastCommitHash: '', | |
dependentPackages: [], | |
cdnAssets: [] | |
}; | |
function updateDependencyVersions() { | |
for (const depencency in packageLockJSON.dependencies) { | |
if (packageLockJSON.dependencies.hasOwnProperty(depencency)) { | |
if (depencency.slice(0, orgPrefix.length) === orgPrefix) { | |
output.dependentPackages.push({[depencency]: packageLockJSON.dependencies[depencency].version }); | |
} | |
} | |
} | |
} | |
cp.exec('git rev-parse --verify HEAD', (err, stdout) => { | |
output.repoName = packageJSON.name; | |
output.lastCommitHash = stdout.replace('\n', ''); | |
updateDependencyVersions(); | |
const versionJSON = JSON.stringify(output, null, 2); | |
fs.writeFile(versionFile, versionJSON, (err) => { | |
if (err) { | |
return console.log(err); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment