Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"extends": "./node_modules/@s-ui/lint/stylelint.config.js"
},
"dependencies": {
"logda": "^1.0.0",
"shelljs": "^0.8.3"
"logda": "1",
"shelljs": "0.8.3"
}
}
112 changes: 60 additions & 52 deletions src/main/versiona.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const versiona = ({
repoName,
host = 'github.com',
publish = NPM_PUBLISH,
masterCommand = MASTER_COMMAND,
test = false
} = {}) => {
const packageJSONPath = path.resolve(process.cwd(), PACKAGE_JSON)
Expand All @@ -17,14 +18,13 @@ const versiona = ({
log.error(() => 'repoOrg and repoName are required')
quit()
}

const isMaster =
process.env.TRAVIS_BRANCH === 'master' &&
process.env.TRAVIS_PULL_REQUEST === 'false'

const travisTag = process.env.TRAVIS_TAG
if (!travisTag) {
log.info(
() => 'TRAVIS_TAG is not present in process.env, stopping versiona'
)
return false
}
if (!REGEX.test(travisTag)) {
if (travisTag && !REGEX.test(travisTag)) {
log.info(() => [
'TRAVIS_TAG is not a semver format tag, stopping versiona',
{
Expand All @@ -34,59 +34,66 @@ const versiona = ({
])
return false
}
const ghToken = process.env.GH_TOKEN
if (!ghToken) {
log.error(() => 'GH_TOKEN is not in process env')
quit()
}

const releaseVersion = travisTag.replace('v', '')
if (travisTag) {
const ghToken = process.env.GH_TOKEN
if (!ghToken) {
log.error(() => 'GH_TOKEN is not in process env')
quit()
}

const releaseVersion = travisTag.replace('v', '')

const repoURL = `https://${ghToken}@${host}/${repoOrg}/${repoName}.git`
const message = `[skip travis] Update version to: ${releaseVersion}`
const repoURL = `https://${ghToken}@${host}/${repoOrg}/${repoName}.git`
const message = `[skip travis] Update version to: ${releaseVersion}`

const isBeta = releaseVersion.indexOf('-beta.') > -1
const isBeta = releaseVersion.indexOf('-beta.') > -1

const toBranch = isBeta
? `develop/v${releaseVersion.replace(/\.[0-9]+\.[0-9]+-beta\.[0-9]+/, '')}`
: 'master'
const toBranch = isBeta
? `develop/v${releaseVersion.replace(
/\.[0-9]+\.[0-9]+-beta\.[0-9]+/,
''
)}`
: 'master'

const oldVersion = packageJSON.version
const oldVersion = packageJSON.version

packageJSON.version = releaseVersion
const updatedJSON = `${JSON.stringify(packageJSON, null, 2)}
`
packageJSON.version = releaseVersion
const updatedJSON = `${JSON.stringify(packageJSON, null, 2)}`

log.info(() => [
'Updating...',
{
repoOrg,
repoName,
host,
travisTag,
isBeta,
toBranch,
oldversion: oldVersion,
newVersion: releaseVersion,
publish
}
])

addShell(`git remote rm origin`)
addShell(`git remote add origin ${repoURL}`)
addShell(`git checkout -b ${toBranch}`)
addFunction(`Update package.json to ${releaseVersion}`, () =>
fs.writeFileSync(packageJSONPath, updatedJSON)
)
addShell(`git add package.json`)
addShell(`git commit -m "${message}"`)
publish &&
addShell(
NPM_PUBLISH === publish
? `${publish}${isBeta ? ' --tag beta' : ''}`
: publish
log.info(() => [
'Updating...',
{
repoOrg,
repoName,
host,
travisTag,
isBeta,
toBranch,
oldversion: oldVersion,
newVersion: releaseVersion,
publish
}
])

addShell(`git remote rm origin`)
addShell(`git remote add origin ${repoURL}`)
addShell(`git checkout -b ${toBranch}`)
addFunction(`Update package.json to ${releaseVersion}`, () =>
fs.writeFileSync(packageJSONPath, updatedJSON)
)
addShell(`git push --repo=${repoURL} origin ${toBranch} --quiet`)
addShell(`git add package.json`)
addShell(`git commit -m "${message}"`)
publish &&
addShell(
NPM_PUBLISH === publish
? `${publish}${isBeta ? ' --tag beta' : ''}`
: publish
)
addShell(`git push --repo=${repoURL} origin ${toBranch} --quiet`)
} else if (isMaster) {
masterCommand && addShell(masterCommand)
}

if (test) {
log.info(() => 'Test finished')
Expand All @@ -97,6 +104,7 @@ const versiona = ({
}

const NPM_PUBLISH = 'npm publish'
const MASTER_COMMAND = 'echo Running on master'
const PACKAGE_JSON = 'package.json'
const REGEX_PATTERN = '^v[0-9]+.[0-9]+.[0-9]+(-beta.[0-9]+)?$'
const REGEX = new RegExp(REGEX_PATTERN)
Expand Down