Skip to content

Commit

Permalink
chore: publish packages with the correct branch name in buildInfo (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
astone123 committed Oct 19, 2023
1 parent 1232bd0 commit 0b35e8e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cli/scripts/build.js
@@ -1,6 +1,7 @@
const _ = require('lodash')
const path = require('path')
const shell = require('shelljs')
const minimist = require('minimist')

const fs = require('../lib/fs')

Expand All @@ -24,7 +25,7 @@ function getStdout (cmd) {
return shell.exec(cmd).trim()
}

function preparePackageForNpmRelease (json) {
function preparePackageForNpmRelease (json, branchName) {
// modify the existing package.json
// to prepare it for releasing to npm
delete json.devDependencies
Expand All @@ -36,7 +37,7 @@ function preparePackageForNpmRelease (json) {
_.extend(json, {
version,
buildInfo: {
commitBranch: process.env.CIRCLE_BRANCH || getStdout('git branch --show-current'),
commitBranch: branchName || process.env.CIRCLE_BRANCH || getStdout('git branch --show-current'),
commitSha: getStdout('git rev-parse HEAD'),
commitDate: new Date(getStdout('git show -s --format=%ci')).toISOString(),
stable: false,
Expand All @@ -57,9 +58,9 @@ function preparePackageForNpmRelease (json) {
return json
}

function makeUserPackageFile () {
function makeUserPackageFile (branchName) {
return fs.readJsonAsync(packageJsonSrc)
.then(preparePackageForNpmRelease)
.then((json) => preparePackageForNpmRelease(json, branchName))
.then((json) => {
return fs.outputJsonAsync(packageJsonDest, json, {
spaces: 2,
Expand All @@ -71,7 +72,9 @@ function makeUserPackageFile () {
module.exports = makeUserPackageFile

if (!module.parent) {
makeUserPackageFile()
const args = minimist(process.argv)

makeUserPackageFile(args.branch)
.catch((err) => {
/* eslint-disable no-console */
console.error('Could not write user package file')
Expand Down

0 comments on commit 0b35e8e

Please sign in to comment.