Nuxt/build/release-next.js

32 lines
914 B
JavaScript
Raw Normal View History

2017-11-24 16:17:27 +00:00
#!/usr/bin/env node
const { readFileSync, writeFileSync } = require('fs-extra')
const { resolve } = require('path')
const { spawnSync } = require('child_process')
// paths
const packagePath = resolve(__dirname, '..', 'package.json')
// Read original contents of package.json
const originalPackage = readFileSync(packagePath, 'utf-8')
// Write to backup file
// writeFileSync(packagePath + '.backup', originalPackage)
// Parse package.json
const p = JSON.parse(originalPackage)
// Change package name
2017-11-24 19:23:36 +00:00
// p.name = 'nuxt-next'
2017-11-24 16:17:27 +00:00
// Get latest git commit id
const gitCommit = String(spawnSync('git', 'rev-parse --short HEAD'.split(' ')).stdout).trim()
2017-11-24 19:23:36 +00:00
// Version with latest git commit id
2017-11-24 16:17:27 +00:00
p.version = p.version.split('-')[0] + '-gh-' + gitCommit
// Write package.json
writeFileSync(packagePath, JSON.stringify(p, null, 2) + '\r\n')
// Log
console.log(p.name + '@' + p.version) // eslint-disable-line no-console