UNPKG

bixi

Version:

企业级中后台前端解决方案

113 lines (100 loc) 3.28 kB
const fs = require('fs'); const fse = require('fs-extra'); const path = require('path'); const ngPackage = require('ng-packagr'); const { PATH, VERSION, logger, getPackages } = require('../util'); const { copyIcons } = require('../icons/copy.js'); function clean() { logger.info('clean dist'); if (fse.pathExistsSync(PATH.bixi)) { fse.removeSync(PATH.dist); } } function copyLess(name) { let sourcePath = path.join(PATH.packages, `${name}`); let targetPath = path.join(PATH.bixi, `${name}`); // index.less if (name === 'core') { [`index.less`, 'dark.less'].forEach(fileName => { fse.copySync(`${sourcePath}/${fileName}`, `${targetPath}/${fileName}`); }); // modules less fs.readdirSync(targetPath).forEach(name => { if (name === 'style') { // 样式打包单独处理 fse.copySync(sourcePath + '/style', targetPath + '/style'); // fix-zorro-path const themeRoot = PATH.bixi + '/core/style'; const projectRoot = path.join(themeRoot, `../../../`); [`index.less`, `dark.less`].forEach(fileName => { const fullFilePath = path.join(themeRoot, fileName); const content = fse .readFileSync(fullFilePath) .toString('utf8') .replace(/ng\-zorro\-antd\//g, path.relative(fullFilePath, projectRoot) + '/node_modules/ng-zorro-antd/'); fse.writeFileSync(fullFilePath, content); }); } else { if (fs.existsSync(`${sourcePath}/${name}/style/index.less`)) { fse.copySync(`${sourcePath}/${name}/style`, `${targetPath}/${name}/style`); } } }); } } function buildPackage(package) { const target = path.resolve(PATH.packages, package); console.time(`${package}:time`); const ngPackageJson = path.resolve(target, `ng-package.json`); const tsConfigJson = path.resolve(target, 'tsconfig.lib.json'); return ngPackage .ngPackagr() .forProject(ngPackageJson) .withTsConfig(tsConfigJson) .build() .then(() => { copyLess(package); copyIcons(package); console.timeEnd(`${package}:time`); }) .catch(error => { console.error(error); process.exit(1); }); } function updateVersion() { logger.info('update version....'); const PACKAGES = getPackages(); PACKAGES.forEach((package) => { const jsonPath = path.resolve(PATH.bixi, package, './package.json') const json = fse.readJsonSync(jsonPath); json.version = VERSION; fse.writeJSONSync(jsonPath, json, { spaces: 2 }); }); } function copyLicense() { logger.info('copy license....'); const PACKAGES = getPackages(); PACKAGES.forEach((package) => { const license = path.resolve(PATH.root, 'LICENSE'); fse.copySync(license, path.resolve(PATH.bixi, package, 'LICENSE')); }); } function copyPdfAssets() { logger.info('copy pdf assets....'); const pdfAssets = path.resolve(PATH.root, 'node_modules/bixi-label/dist'); fse.copySync(pdfAssets, path.resolve(PATH.bixi, 'label/source')); } function buildPackages() { const PACKAGES = getPackages(); Promise.all([...PACKAGES.map(p => buildPackage(p))]) .then(() => { updateVersion(); copyLicense(); copyPdfAssets(); }); } clean(); buildPackages();