mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 10:04:05 +00:00
ef7a42649d
nuxt-start and nuxt/legacy are also coming!
70 lines
1.8 KiB
JavaScript
Executable File
70 lines
1.8 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
const { resolve } = require('path')
|
|
const { spawnSync } = require('child_process')
|
|
const { readFileSync, writeFileSync } = require('fs-extra')
|
|
|
|
// 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-edge'
|
|
|
|
// Get latest git commit id
|
|
const gitCommit = String(
|
|
spawnSync('git', 'rev-parse --short HEAD'.split(' ')).stdout
|
|
).trim()
|
|
|
|
// Version with latest git commit id
|
|
// 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}`
|
|
|
|
// Write package.json
|
|
writeFileSync(packagePath, JSON.stringify(p, null, 2) + '\r\n')
|
|
|
|
// Parse git branch to decide npm tag
|
|
let tag = String(
|
|
spawnSync('git', 'rev-parse --abbrev-ref HEAD'.split(' ')).stdout
|
|
).trim()
|
|
|
|
// dev ~> latest
|
|
if (tag === 'dev') {
|
|
tag = 'latest'
|
|
}
|
|
|
|
// Log
|
|
// eslint-disable-next-line no-console
|
|
console.log(`publishing ${p.name}@${p.version} with tag ${tag}`)
|
|
|
|
// Do publish
|
|
// eslint-disable-next-line no-console
|
|
console.log(
|
|
String(spawnSync('npm', `publish --tag ${tag}`.split(' ')).stdout).trim()
|
|
)
|
|
|
|
// Run make start
|
|
spawnSync('npm', 'run build:nuxt-start'.split(' '))
|
|
|
|
// Log
|
|
// eslint-disable-next-line no-console
|
|
console.log(`publishing ${p.name}-start@${p.version} with tag ${tag}`)
|
|
|
|
// Do publish
|
|
// eslint-disable-next-line no-console
|
|
console.log(
|
|
String(spawnSync('npm', `publish --tag ${tag}`.split(' '), {
|
|
cwd: resolve(__dirname, '..', 'start')
|
|
}).stdout).trim()
|
|
)
|