Nuxt/build/release-next.js

32 lines
898 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
p.name = 'nuxt-next'
// Get latest git commit id
const gitCommit = String(spawnSync('git', 'rev-parse --short HEAD'.split(' ')).stdout).trim()
// Version with git tag
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