Skip to content

Commit

Permalink
fix: copy files by src dir
Browse files Browse the repository at this point in the history
  • Loading branch information
loadchange committed May 13, 2019
1 parent 96a6f0f commit ad7c28d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/midway-bin/lib/cmd/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class BuildCommand extends Command {
alias: 'p',
default: 'tsconfig.json',
},
srcDir: {
description: 'source code path',
type: 'string',
default: 'src',
},
};
}

Expand All @@ -44,7 +49,7 @@ class BuildCommand extends Command {
yield this.cleanDir(cwd, argv.project);
}

yield this.copyFiles(cwd, argv.project);
yield this.copyFiles(cwd, argv.project, argv);

const args = [];

Expand Down Expand Up @@ -78,7 +83,7 @@ class BuildCommand extends Command {
}
}

* copyFiles(cwd, projectFile) {
* copyFiles(cwd, projectFile, argv) {
const tsConfig = require(path.join(cwd, projectFile));

// if projectFile extended and without outDir,
Expand All @@ -88,7 +93,7 @@ class BuildCommand extends Command {
!tsConfig.compilerOptions ||
(tsConfig.compilerOptions && !tsConfig.compilerOptions.outDir)
) {
yield this.copyFiles(cwd, tsConfig.extends);
yield this.copyFiles(cwd, tsConfig.extends, argv);
return;
}
}
Expand All @@ -100,15 +105,15 @@ class BuildCommand extends Command {
if (pkg['midway-bin-build'] && pkg['midway-bin-build'].include) {
for (const file of pkg['midway-bin-build'].include) {
if (typeof file === 'string' && !/\*/.test(file)) {
const srcDir = path.join('src', file);
const srcDir = path.join(argv.srcDir, file);
const targetDir = path.join(outDir, file);
// 目录,或者不含通配符的普通文件
this.copyFile(srcDir, targetDir, cwd);
} else {
// 通配符的情况
const paths = yield globby([].concat(file), { cwd: path.join(cwd, 'src') });
const paths = yield globby([].concat(file), { cwd: path.join(cwd, argv.srcDir) });
for (const p of paths) {
this.copyFile(path.join('src', p), path.join(outDir, p), cwd);
this.copyFile(path.join(argv.srcDir, p), path.join(outDir, p), cwd);
}
}
}
Expand Down

0 comments on commit ad7c28d

Please sign in to comment.