-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson-withmetadata.js
More file actions
26 lines (20 loc) · 884 Bytes
/
json-withmetadata.js
File metadata and controls
26 lines (20 loc) · 884 Bytes
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
/** @format */
const stringifyPackage = require('commit-and-tag-version/lib/stringify-package')
const detectIndent = require('detect-indent')
const detectNewline = require('detect-newline')
module.exports.readVersion = function (contents) {
return JSON.parse(contents).version
}
module.exports.writeVersion = function (contents, version) {
// Parse the current version as semver and extract the build metadata
buildmeta = JSON.parse(contents).version.split('+')[1] || ''
const json = JSON.parse(contents)
const indent = detectIndent(contents).indent
const newline = detectNewline(contents)
json.version = `${version}+${buildmeta}`
if (json.packages && json.packages['']) {
// package-lock v2 stores version there too
json.packages[''].version = `${version}+${buildmeta}`
}
return stringifyPackage(json, indent, newline)
}