From bcc3057f9cf20cd7dda363305d4162f5b8e59f11 Mon Sep 17 00:00:00 2001 From: Michael Hladky Date: Fri, 20 Apr 2018 20:26:45 +0200 Subject: [PATCH] feat(automated release chain): fixed paths and versions Related to #78 --- chore/config.js | 19 ++++++++++--------- chore/scripts/release.js | 9 +++++---- chore/scripts/tasks/build.js | 14 ++------------ chore/scripts/tasks/changelog.js | 2 +- chore/scripts/tasks/ci-check.js | 7 +++---- chore/scripts/tasks/refresh.js | 7 ++++--- chore/scripts/tasks/release-npm.js | 3 ++- chore/scripts/tasks/version-bump.js | 2 +- chore/scripts/utils.js | 9 +++++---- package.json | 5 +++-- 10 files changed, 36 insertions(+), 41 deletions(-) diff --git a/chore/config.js b/chore/config.js index 77d7e98..fb964da 100644 --- a/chore/config.js +++ b/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 diff --git a/chore/scripts/release.js b/chore/scripts/release.js index 7a1a434..525af3d 100644 --- a/chore/scripts/release.js +++ b/chore/scripts/release.js @@ -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)) diff --git a/chore/scripts/tasks/build.js b/chore/scripts/tasks/build.js index be04059..1b4c817 100644 --- a/chore/scripts/tasks/build.js +++ b/chore/scripts/tasks/build.js @@ -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 @@ -20,9 +19,6 @@ function build () { .then(res => { return packaging() }) - .then((r) => { - return copyStyles() - }) .catch((e) => { console.error('BuildProcessError: '.red, e) }) @@ -32,7 +28,7 @@ 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) }) @@ -40,13 +36,7 @@ async function packaging () { 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')) -} diff --git a/chore/scripts/tasks/changelog.js b/chore/scripts/tasks/changelog.js index b2d9d63..2db6ab1 100644 --- a/chore/scripts/tasks/changelog.js +++ b/chore/scripts/tasks/changelog.js @@ -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(() => { diff --git a/chore/scripts/tasks/ci-check.js b/chore/scripts/tasks/ci-check.js index 7702473..4349165 100644 --- a/chore/scripts/tasks/ci-check.js +++ b/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 @@ -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) diff --git a/chore/scripts/tasks/refresh.js b/chore/scripts/tasks/refresh.js index 1f37fad..bae32c7 100644 --- a/chore/scripts/tasks/refresh.js +++ b/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')) @@ -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(() => { diff --git a/chore/scripts/tasks/release-npm.js b/chore/scripts/tasks/release-npm.js index e23d59a..8684c7a 100644 --- a/chore/scripts/tasks/release-npm.js +++ b/chore/scripts/tasks/release-npm.js @@ -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) }) diff --git a/chore/scripts/tasks/version-bump.js b/chore/scripts/tasks/version-bump.js index db3cd18..eda0703 100644 --- a/chore/scripts/tasks/version-bump.js +++ b/chore/scripts/tasks/version-bump.js @@ -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 diff --git a/chore/scripts/utils.js b/chore/scripts/utils.js index a69d168..6a2d7bb 100644 --- a/chore/scripts/utils.js +++ b/chore/scripts/utils.js @@ -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) @@ -33,6 +33,7 @@ function deleteFile (source) { }) } + function copyFile (source, target, cb) { cb = cb || function () { @@ -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}) @@ -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) } diff --git a/package.json b/package.json index 4746c5b..2a23a1b 100644 --- a/package.json +++ b/package.json @@ -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,