2017-11-24 16:17:27 +00:00
|
|
|
#!/usr/bin/env node
|
2017-12-12 10:02:39 +00:00
|
|
|
|
2017-11-24 16:17:27 +00:00
|
|
|
const { resolve } = require('path')
|
|
|
|
const { spawnSync } = require('child_process')
|
2018-03-27 22:28:17 +00:00
|
|
|
const { readFileSync, writeFileSync } = require('fs-extra')
|
2017-11-24 16:17:27 +00:00
|
|
|
|
|
|
|
// 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
|
2018-01-08 16:52:56 +00:00
|
|
|
p.name = 'nuxt-edge'
|
2017-11-24 16:17:27 +00:00
|
|
|
|
|
|
|
// Get latest git commit id
|
2018-01-13 05:22:11 +00:00
|
|
|
const gitCommit = String(
|
|
|
|
spawnSync('git', 'rev-parse --short HEAD'.split(' ')).stdout
|
|
|
|
).trim()
|
2017-11-24 16:17:27 +00:00
|
|
|
|
2017-11-24 19:23:36 +00:00
|
|
|
// Version with latest git commit id
|
2018-01-08 17:17:32 +00:00
|
|
|
// Using date.now() so latest push will be always choosen by npm/yarn
|
|
|
|
const date = Math.round(Date.now() / (1000 * 60))
|
|
|
|
const baseVersion = p.version.split('-')[0]
|
|
|
|
p.version = `${baseVersion}-${date}.${gitCommit}`
|
2017-11-24 16:17:27 +00:00
|
|
|
|
|
|
|
// Write package.json
|
|
|
|
writeFileSync(packagePath, JSON.stringify(p, null, 2) + '\r\n')
|
|
|
|
|
2018-01-08 16:52:56 +00:00
|
|
|
// Parse git branch to decide npm tag
|
2018-01-13 05:22:11 +00:00
|
|
|
let tag = String(
|
|
|
|
spawnSync('git', 'rev-parse --abbrev-ref HEAD'.split(' ')).stdout
|
|
|
|
).trim()
|
2018-01-08 16:52:56 +00:00
|
|
|
|
|
|
|
// dev ~> latest
|
|
|
|
if (tag === 'dev') {
|
|
|
|
tag = 'latest'
|
|
|
|
}
|
|
|
|
|
2017-11-24 16:17:27 +00:00
|
|
|
// Log
|
2018-01-08 16:52:56 +00:00
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log(`publishing ${p.name}@${p.version} with tag ${tag}`)
|
|
|
|
|
|
|
|
// Do publish
|
2018-07-29 18:01:05 +00:00
|
|
|
let { status, output } = spawnSync('npm', `publish --tag ${tag}`.split(' '))
|
|
|
|
|
2018-01-08 16:52:56 +00:00
|
|
|
// eslint-disable-next-line no-console
|
2018-07-29 18:01:05 +00:00
|
|
|
console.log(String(output.concat('\n')).trim())
|
|
|
|
|
|
|
|
if (status === 1) {
|
|
|
|
process.exit(1)
|
|
|
|
}
|
2018-03-27 22:28:17 +00:00
|
|
|
|
2018-07-29 18:09:01 +00:00
|
|
|
// // Run make start
|
|
|
|
// spawnSync('npm', 'run build:nuxt-start'.split(' '))
|
2018-03-27 22:28:17 +00:00
|
|
|
|
2018-07-29 18:09:01 +00:00
|
|
|
// // Log
|
|
|
|
// // eslint-disable-next-line no-console
|
|
|
|
// console.log(`publishing ${p.name}-start@${p.version} with tag ${tag}`);
|
2018-07-29 18:01:05 +00:00
|
|
|
|
2018-07-29 18:09:01 +00:00
|
|
|
// ({ status, output } = spawnSync('npm', `publish --tag ${tag}`.split(' '), {
|
|
|
|
// cwd: resolve(__dirname, '..', 'start')
|
|
|
|
// }))
|
2018-03-27 22:28:17 +00:00
|
|
|
|
2018-07-29 18:09:01 +00:00
|
|
|
// // Do publish
|
|
|
|
// // eslint-disable-next-line no-console
|
|
|
|
// console.log(String(output.concat('\n')).trim())
|
2018-07-29 18:01:05 +00:00
|
|
|
|
2018-07-29 18:09:01 +00:00
|
|
|
// if (status === 1) {
|
|
|
|
// process.exit(1)
|
|
|
|
// }
|