Skip to content

Commit

Permalink
feat(automated release chain): fixed paths and versions
Browse files Browse the repository at this point in the history
Related to #78
  • Loading branch information
BioPhoton committed Apr 20, 2018
1 parent 9857a32 commit bcc3057
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 41 deletions.
19 changes: 10 additions & 9 deletions chore/config.js
@@ -1,15 +1,16 @@
'use strict'

global.__base = __dirname + '/../'
global.__base = __dirname + '/../';

const path = require('path')
const util = require('util')
const path = require('path');
const util = require('util');

const config = {}
config.libPath = path.join(__base, 'libs', 'angular-star-rating')
config.debugMode = true
config.validPreset = 'angular'
config.ci = {}
config.ci.validState = 'passed'
const config = {};
config.libPath = path.join(__base, 'libs', 'angular-star-rating');
config.packagedFolder = path.join(__base,'@packaged','angular-star-rating');
config.debugMode = true;
config.validPreset = 'angular';
config.ci = {};
config.ci.validState = 'passed\r\n';

module.exports = config
9 changes: 5 additions & 4 deletions chore/scripts/release.js
Expand Up @@ -17,11 +17,12 @@ process.env.DEBUG = config.debugMode

console.info('Start release'.gray)
return Promise.resolve()
.then(() => ciCheck())
//.then(() => ciCheck())
//.then(() => refresh())
//.then(() => build())
//.then(() => changelog())
//.then(() => versionBump())
.then(function(r) {console.log(r)})
.then(() => build())
.then(() => changelog())
.then(() => versionBump())
//.then(() => releaseGithub())
//.then(() => releaseNpm())
.catch((err) => console.info('release error'.red, err.red))
14 changes: 2 additions & 12 deletions chore/scripts/tasks/build.js
Expand Up @@ -9,7 +9,6 @@ const util = require('util')
const exec = util.promisify(require('child_process').exec)

// config
const ngPackagr = require(path.join(__base, 'node_modules/ng-packagr/lib/ng-packagr'))

process.env.DEBUG = config.debugMode

Expand All @@ -20,9 +19,6 @@ function build () {
.then(res => {
return packaging()
})
.then((r) => {
return copyStyles()
})
.catch((e) => {
console.error('BuildProcessError: '.red, e)
})
Expand All @@ -32,21 +28,15 @@ function build () {
// =============================================================================

async function packaging () {
await ngPackagr.ngPackage({project: path.join(config.libPath, 'package.json')})
await exec('npm run build:lib')
.then((res) => {
console.info('done packaging'.green)
})
.catch((err) => {
console.error('Build failed: '.red, err)
process.exit(1)
})
const {stdout, stderr} = await exec('npm pack', {cwd: path.join(config.libPath, 'dist')})
const {stdout, stderr} = await exec('npm pack', {cwd: config.libPath})
console.info('done npm pack'.green)
return {stdout, stderr}
}

function copyStyles () {
const source = path.join(config.libPath, 'src', 'styles.scss')
const target = path.join(config.libPath, 'dist', 'styles.scss')
return utils.copyFile(source, target, (r) => console.log('copy styles done'))
}
2 changes: 1 addition & 1 deletion chore/scripts/tasks/changelog.js
Expand Up @@ -60,7 +60,7 @@ function changelog () {
console.log('new version ', detectedVersion);
})
// copy package.json into dist because we want to have the new version in the dist folder also
.then(() => utils.copyFile(path.join(config.libPath, 'package.json'), path.join(config.libPath, 'dist', 'package.json')))
.then(() => utils.copyFile(path.join(config.libPath, 'package.json'), path.join(config.libPath, 'package.json')))
// Replace the already bumped package.json with the _package.json initial copy
.then(() => {
return utils.restorePackageJson().then(() => {
Expand Down
7 changes: 3 additions & 4 deletions chore/scripts/tasks/ci-check.js
@@ -1,10 +1,9 @@
'use strict'

const path = require('path')
const util = require('util')
console.log('util', util)
const exec = util.promisify(require('child_process').exec)
const {promisify} = require('util');

const exec = promisify(require('child_process').exec);
const config = require(path.join('..', '..', 'config'))

module.exports = ciCheck
Expand All @@ -13,7 +12,7 @@ module.exports = ciCheck
// --no-interactive disables the interactive mode
// source: https://github.com/travis-ci/travis.rb/blob/master/README.md
function ciCheck() {
return exec('travis status --no-interactive', {cwd: path.join(config.libPath, 'dist')})
return exec('travis status --no-interactive', {cwd: config.libPath})
.then((result) => {
if (result.stdout === config.ci.validState) {
return Promise.resolve(result)
Expand Down
7 changes: 4 additions & 3 deletions chore/scripts/tasks/refresh.js
@@ -1,8 +1,9 @@
'use strict'

const path = require('path')
const util = require('util')
const exec = util.promisify(require('child_process').exec)
const {promisify} = require('util');

const exec = promisify(require('child_process').exec);

const config = require(path.join('..', '..', 'config'))
const utils = require(path.join(__base, 'chore', 'scripts', 'utils'))
Expand All @@ -13,7 +14,7 @@ function refresh (hard) {
if(hard === true) {
utils.deleteFile(path.join(__base, 'node_modules'))
}

return Promise.resolve()
// pulls the latest version and rebases
.then(() => {
Expand Down
3 changes: 2 additions & 1 deletion chore/scripts/tasks/release-npm.js
Expand Up @@ -18,7 +18,8 @@ function releaseNpm () {
console.info('start npm release'.gray)
return utils.getPreset()
.then((preset) => {
return exec('npm publish', {cwd: path.join(config.libPath, 'dist')})

return exec('npm publish', {cwd: config.packagedFolder})
.then(() => {
console.info('published on npm'.green)
})
Expand Down
2 changes: 1 addition & 1 deletion chore/scripts/tasks/version-bump.js
Expand Up @@ -24,7 +24,7 @@ function versionBump () {
// npm version [detectedBump] bumps the version specified in detectedBump
// and write the new data back to package.json
.then(() => exec('npm --no-git-tag-version version ' + detectedBump, {cwd: config.libPath}))
.then(() => exec('git add .\\package.json', {cwd: config.libPath}))
.then(() => exec('git add .\\package.json', {cwd: config.packagedFolder}))
.then(() => utils.getPackageVersion())
.then((version) => {
detectedVersion = version
Expand Down
9 changes: 5 additions & 4 deletions chore/scripts/utils.js
Expand Up @@ -16,11 +16,11 @@ utils.copyFilePromise = copyFilePromise
utils.copyMultiFilePromise = copyMultiFilePromise
utils.backupPackageJson = backupPackageJson
utils.restorePackageJson = restorePackageJson
utils.getPreset = getCommitConvantion
utils.getPreset = getCommitConvention
utils.getBump = getBump
utils.getPackageVersion = getPackageVersion

module.exports = utils
module.exports = utils;

function deleteFile (source) {
console.info('start deleting ', source)
Expand All @@ -33,6 +33,7 @@ function deleteFile (source) {
})

}

function copyFile (source, target, cb) {

cb = cb || function () {
Expand Down Expand Up @@ -110,7 +111,7 @@ function restorePackageJson () {
//.then(() => utils.deleteFile(source2))
}

function getCommitConvantion () {
function getCommitConvention () {
// Detect what commit message convention your repository is using
// source: https://github.com/conventional-changelog/conventional-commits-detector/blob/master/README.md
return exec('conventional-commits-detector', {cwd: __base})
Expand Down Expand Up @@ -138,6 +139,6 @@ function getBump () {
}

function getPackageVersion () {
const packageJson = require(path.join(config.libPath, 'package.json'))
const packageJson = require(path.join(config.packagedFolder, 'package.json'))
return Promise.resolve(packageJson.version)
}
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -28,9 +28,10 @@
"docs:build": "compodoc -p ./src/tsconfig.api-doc.json -n angular-star-rating -d docs/api-doc/ --hideGenerator",
"docs:serve": "npm run docs:build -- -s",
"docs:watch": "npm run docs:build -- -s -w",
"changelog": "conventional-changelog -i CHANGELOG.md -s -p angular",
"changelog": "node ./chore/scripts/tasks/changelog",
"recommended-bump": "conventional-recommended-bump -p angular",
"github-release": "conventional-github-releaser -p angular",
"release": "node ./chore/scripts/release",
"github-release": "node ./chore/scripts/tasks/release-github",
"release:lib": "npm publish ./@packaged/angular-star-rating"
},
"private": true,
Expand Down

0 comments on commit bcc3057

Please sign in to comment.