@ali-i18n-fe/dada-component
Version:
52 lines (42 loc) • 1.36 kB
JavaScript
const path = require("path");
const fs = require("fs");
const { shellSyncExec } = require("./utils");
let binPath = path.resolve(__dirname, `..${path.sep}node_modules${path.sep}.bin`);
const getPathFromBinPath = (binPath) => {
const babelPath = path.resolve(binPath, "babel");
const tscPath = path.resolve(binPath, "tsc");
const cpxPath = path.resolve(binPath, "cpx");
const concurrentlyPath = path.resolve(binPath, "concurrently");
return {
babelPath,
tscPath,
cpxPath,
concurrentlyPath
};
}
if (!fs.existsSync(getPathFromBinPath(binPath).babelPath)) {
binPath = path.resolve(__dirname, `..${path.sep}..${path.sep}..${path.sep}.bin`);
}
const {
babelPath,
tscPath,
cpxPath,
concurrentlyPath
} = getPathFromBinPath(binPath);
const Babel = {
babelCmd: `${babelPath} src --out-dir lib --extensions ".ts,.js,.tsx" --config-file ${path.resolve(
__dirname,
`.${path.sep}constants${path.sep}component.babelrc.js`
)}`,
cssCmd: `${cpxPath} "src${path.sep}**${path.sep}*.{scss,css,json,png,jpg,svg}" lib`,
typesCmd: `${tscPath} --emitDeclarationOnly`,
async load() {
shellSyncExec(`${this.cssCmd} && ${this.babelCmd} && ${this.typesCmd}`);
},
async watch() {
shellSyncExec(
`${concurrentlyPath} '${this.babelCmd} --watch' '${this.cssCmd} --watch'`
);
}
};
module.exports = Babel;