Skip to content

Commit

Permalink
feat: Add build specified suffix file
Browse files Browse the repository at this point in the history
add globby
const globby = require('globby');
  • Loading branch information
ZQun authored Dec 9, 2018
1 parent 9258228 commit 1752cf9
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/midway-bin/lib/cmd/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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!`);
}
}
}
}
}

}
}

Expand Down

0 comments on commit 1752cf9

Please sign in to comment.