Skip to content

Commit

Permalink
feat(publish): add publish script (#1979)
Browse files Browse the repository at this point in the history
close #1925
  • Loading branch information
Wendell authored and Jason committed Sep 7, 2018
1 parent 1d5e06c commit 98cb651
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .editorconfig
Expand Up @@ -30,6 +30,10 @@ indent_size=2
indent_style=space
indent_size=2

[*.js]
indent_style=space
indent_size=2

[*.js.map]
indent_style=space
indent_size=2
Expand Down
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -23,7 +23,8 @@
"integration-webpack": "npm run generate && cd integration/webpack && npm run integration",
"integration-rollup": "npm run generate && cd integration/rollup && npm run integration",
"lint": "tslint -c tslint.json 'components/*/*.ts'",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s && node site_scripts/replace-scope-prefix.js"
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s && node site_scripts/replace-scope-prefix.js",
"publish": "node ./publish_scripts/publish.js"
},
"main": "./bundles/antd.umd.js",
"module": "./esm5/antd.js",
Expand Down Expand Up @@ -73,6 +74,7 @@
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"antd-theme-generator": "^1.0.7",
"chalk": "^2.4.1",
"classlist.js": "^1.1.20150312",
"codecov": "^3.0.0",
"codelyzer": "~4.2.1",
Expand All @@ -97,6 +99,7 @@
"parse5": "^4.0.0",
"prismjs": "^1.10.0",
"protractor": "~5.3.0",
"readline-sync": "^1.4.9",
"remark": "^8.0.0",
"rollup": "^0.49.2",
"rollup-plugin-node-resolve": "^3.0.0",
Expand Down
130 changes: 130 additions & 0 deletions publish_scripts/publish.js
@@ -0,0 +1,130 @@
const chalk = require('chalk');
const fs = require('fs-extra');
const read = require('readline-sync');
const path = require('path');

/* Shortcut methods */
const execSync = require('child_process').execSync;
const print = console.log;
const log = {
info : (msg) => {
print(chalk.bgBlue.black('INFO'), chalk.blue(msg));
},
warn : (msg) => {
print(chalk.bgYellow.black('WARN'), chalk.yellow(msg));
},
error : (msg) => {
print(chalk.bgRed.black('ERROR'), chalk.red(msg));
},
success: (msg) => {
print(chalk.bgGreen.black('SUCCESS'), chalk.green(msg));
}
};

/* The whole process */

log.info('Starting publishing process...');

let nextVersion;

fetchOlderVersions();
changeVersion();
generatingPublishNote();
preRelease();
checkout();

// publish();

/**
* Publisher should input the new version number. This script would check if the input is valid.
*/
function changeVersion() {
log.info('Updating version number...');

const packageJson = path.join(__dirname, '../package.json');
const appComponent = path.join(__dirname, '../site_scripts/_site/src/app/app.component.ts') ;
const codeBox = path.join(__dirname, '../site_scripts/_site/src/app/share/nz-codebox/nz-codebox.component.ts');
const currentVersion = fs.readFileSync(packageJson, 'utf-8').match(/"version": "([0-9.]+)"/)[ 1 ];

let versionNumberValid = false;
let version;

function checkVersionNumber(cur, next) {
const curArr = cur.split('.');
const nextArr = next.split('.');
const length = curArr.length;

if (nextArr.length !== nextArr.length) {
return false;
}

for (let i = 0; i < length; i++) {
if (curArr[ i ] < nextArr[ i ]) { return true; }
if (curArr[ i ] > nextArr[ i ]) { return false; }
if (i === length - 1 && curArr[ i ] === nextArr[ i ]) { return false; }
}
}

while (!versionNumberValid) {
version = read.question(chalk.bgYellow.black('Please input the new version:') + ' ');
if (checkVersionNumber(currentVersion, version)) {
versionNumberValid = true;
nextVersion = version;
} else {
log.error(`The current version ${currentVersion} is not ahead of your input. Please check it.`);
}
}

fs.writeFileSync(packageJson,
fs.readFileSync(packageJson, 'utf-8').replace(/"version": "[0-9.]+"/g, `"version": "${version}"`)
);
fs.writeFileSync(appComponent,
fs.readFileSync(appComponent, 'utf-8').replace(/currentVersion = '[0-9.]+';/g, `currentVersion = '${version}';`)
);
fs.writeFileSync(codeBox,
fs.readFileSync(codeBox, 'utf-8').replace(/'ng-zorro-antd' +: '\^[0-9.]+'/g, `'ng-zorro-antd' : '^${version}'`)
);
log.success('Version updated!');
}

function fetchOlderVersions() {
log.info('Fetching older versions...');
execSync('git checkout master');
execSync('git pull upstream master');
execSync('git fetch upstream master --prune --tags');
log.success('Older versions fetched!');
}

function generatingPublishNote() {
log.info('Generating changelog...');
execSync('npm run changelog');
log.success('Changelog generated!');

let completeEditing = false;

while (!completeEditing) {
const result = read.question(chalk.bgYellow.black('Please manually update docs/changelog. Press [Y] if you are done:') + ' ');
if (result.trim().toLowerCase() === 'y') {
completeEditing = true;
}
}

log.success('Change log finished!');
}

function preRelease() {
// FIXME: No command line output???
log.info('Running pre-release script... Be patient...');
execSync('npm run pre-release');
log.info('pre-release completed!');
}

function checkout() {
log.info('Checkout and push a new branch for publishing...');
execSync(`git checkout -b publish-${nextVersion}`);
execSync('git add .');
execSync(`git commit -m "release(${nextVersion}): release ${nextVersion}"`);
execSync(`git push origin publish-${nextVersion}`);
log.success('Please go to GitHub and make a pull request.');
log.success('Bye!');
}

0 comments on commit 98cb651

Please sign in to comment.