diff --git a/packages/midway-bin/lib/cmd/build.js b/packages/midway-bin/lib/cmd/build.js index f8d91fe1c404..50ada6f482b4 100644 --- a/packages/midway-bin/lib/cmd/build.js +++ b/packages/midway-bin/lib/cmd/build.js @@ -5,6 +5,7 @@ const path = require('path'); const fs = require('fs'); const rimraf = require('mz-modules/rimraf'); const fse = require('fs-extra'); +const globby = require('globby'); class BuildCommand extends Command { constructor(rawArgv) { @@ -62,13 +63,27 @@ class BuildCommand extends Command { for (const file of pkg['midway-bin-build'].include) { const srcDir = path.join('src', file); const targetDir = path.join(outDir, file); - fse.copySync(path.join(cwd, srcDir), path.join(cwd, targetDir)); - console.log(`[midway-bin] copy ${srcDir} to ${targetDir} success!`); + const isSrcDir = (srcDir.indexOf('*') !== -1) || (srcDir.indexOf('?') !== -1) || (srcDir.replace(/.+\./, '') !== srcDir); + if (isSrcDir) { + const getPath = srcDir.lastIndexOf('/'); + const files = srcDir.substring(4, getPath); // remove src + const src = srcDir.substring(getPath + 1); // extension name + const cwdDir = path.join(cwd, srcDir.substring(0, getPath)); + const paths = globby.sync(cwdDir, { expandDirectories: { files: [ src ] } }); + paths.forEach(item => { + const fileName = item.substring(item.lastIndexOf('/') + 1, item.length); // get file name + const filePath = item.substring(item.indexOf(files), item.lastIndexOf('/')); // get file path + const targetDir = path.join(cwd, outDir, filePath, fileName); + fse.copySync(item, targetDir); + }); + } else { + fse.copySync(path.join(cwd, srcDir), path.join(cwd, targetDir)); + console.log(`[midway-bin] copy ${srcDir} to ${targetDir} success!`); + } } } } } - } }