UNPKG

@ctsj/build

Version:

一个基于webpack的打包工具

83 lines (74 loc) 1.78 kB
#!/usr/bin/env node /** * src - 原始目录 * targetsrc 目标目录 */ const path = require('path'); const { spawn } = require('child_process'); const args = require('../src/commandArgs'); const { getEnv, isWin32 } = require('../src/util'); // 运行脚本的路径 const runtimePath = process.cwd(); // 脚本的路径 const commandPath = path.join(__dirname, '../', 'node_modules', '.bin', path.sep); const tasks = [cpTask]; let index = 0; /** * cpTask * @return {Promise} */ function cpTask() { return new Promise((resolve) => { const command = isWin32() ? `cp-cli.cmd` : `cp-cli`; const cpProcess = spawn(command, args.getArgs(), { cwd: runtimePath, encoding: 'utf-8', env: getEnv(commandPath), }); cpProcess.stdout.on('data', (data) => { console.log(`stdout: ${data}`); }); cpProcess.stderr.on('data', (data) => { console.log(`stderr: ${data}`); }); cpProcess.on('close', (code) => { console.log(`cpClose:${code}`); resolve(); }); }); } /** * loopTask * @return {Promise} */ function loopTask() { return new Promise((resolve, reject) => { if (index >= tasks.length) { resolve(); } else { // eslint-disable-next-line no-plusplus const task = tasks[index++]; if (task) { task() .then(() => { loopTask().then(() => { resolve(); }); }) .catch((error) => { reject(error); }); } else { reject(); } } }); } loopTask() .then(() => { console.log('finish'); process.exit(); }) .catch((error) => { console.log(error); });