summaryrefslogtreecommitdiff
path: root/date-fns/scripts/release/writeVersion.js
diff options
context:
space:
mode:
Diffstat (limited to 'date-fns/scripts/release/writeVersion.js')
-rwxr-xr-xdate-fns/scripts/release/writeVersion.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/date-fns/scripts/release/writeVersion.js b/date-fns/scripts/release/writeVersion.js
new file mode 100755
index 0000000..c796d18
--- /dev/null
+++ b/date-fns/scripts/release/writeVersion.js
@@ -0,0 +1,35 @@
+#!/usr/bin/env node
+
+/**
+ * @file
+ * The script extracts the actual package version from $VERSION
+ * and writes it to package.json
+ *
+ * It's a part of the release process.
+ */
+
+const path = require('path')
+const fs = require('fs')
+const beautify = require('js-beautify')['js_beautify']
+
+// Extract version from VERSION
+let version
+try {
+ ;[, version] = process.env.VERSION.match(/v(.+)/)
+} catch (err) {
+ console.error(`Can not extract version from VERSION (${process.env.VERSION})`)
+ console.error(err)
+ process.exit(1)
+}
+
+console.log(`Version: ${version}`)
+
+console.log('Writing to package.json...')
+// Write package.json with the version equal to the version encoded in the tag name
+const packagePath = path.join(process.cwd(), 'package.json')
+const packageContent = JSON.parse(fs.readFileSync(packagePath).toString())
+Object.assign(packageContent, { version })
+const newPackageContentStr = beautify(JSON.stringify(packageContent), {
+ indent_size: 2,
+})
+fs.writeFileSync(packagePath, `${newPackageContentStr}\n`)