bixi
Version:
企业级中后台前端解决方案
83 lines (74 loc) • 2.78 kB
JavaScript
const chalk = require('chalk');
const fs = require('fs-extra');
const path = require('path');
const read = require('readline-sync');
const { execSync, logger, PATH, getPackages, VERSION } = require('../util');
logger.info('Starting publishing process...');
function syncRemote() {
logger.info('Fetching versions [Start]');
execSync('git checkout master');
execSync('git pull origin master');
execSync('git fetch origin master --prune --tags');
logger.success('Fetching versions [End]');
}
function genChangelog() {
logger.info('Generating changelog [Start]');
execSync('npm run changelog');
logger.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;
}
}
logger.success('Generating changelog [End]');
}
function syncChanglog() {
logger.info('Sync changelog [Start]');
const zhMdPath = path.resolve(PATH.root, 'docs/changelog.zh-CN.md');
const enMdPath = path.resolve(PATH.root, 'docs/changelog.en-US.md');
const zhMdTitle = fs.readFileSync(zhMdPath).toString().split('\n').slice(0, 5).join('\n');
const enMdTitle = fs.readFileSync(enMdPath).toString().split('\n').slice(0, 5).join('\n');
const log = fs.readFileSync(path.resolve(PATH.root, 'CHANGELOG.md')).toString();
fs.writeFileSync(zhMdPath, [zhMdTitle, log].join('\n\n'));
fs.writeFileSync(enMdPath, [enMdTitle, log].join('\n\n'));
logger.success('Sync changelog [End]');
}
function pushToRemote() {
execSync(`git checkout -b publish-${VERSION}`);
execSync('git add .');
execSync(`git commit -m "release(${VERSION}): release ${VERSION}"`);
execSync(`git push origin publish-${VERSION}`);
execSync(`git tag ${VERSION}`);
execSync(`git push origin ${VERSION}`);
logger.success('Please make a pull request, Thanks.');
}
function publish() {
if (!fs.pathExistsSync(PATH.bixi)) {
logger.error("You haven't built yet!!!");
return;
}
const PACKAGES = getPackages();
const isNext = process.argv[2] === 'next';
console.log('PACKAGES', PACKAGES);
PACKAGES.forEach(package => {
const version = require(path.resolve(PATH.bixi, `${package}/package.json`)).version;
logger.info(`Publishing @bixi/${package}:${version} ...`);
if (isNext) {
execSync(`cd dist/@bixi/${package} && npm publish --access public --tag next`);
} else {
execSync(`cd dist/@bixi/${package} && npm publish --access public`);
}
logger.success(`@bixi/${package}:${version} published.`);
});
}
syncRemote();
genChangelog();
syncChanglog();
publish();
pushToRemote();