mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
32 lines
914 B
JavaScript
32 lines
914 B
JavaScript
#!/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 latest git commit id
|
|
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
|