Skip to content

Commit

Permalink
feat: add tsConfig.json to tsc cmd line support (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lellansin authored Feb 19, 2020
1 parent 7288e22 commit 8e368fb
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions packages/midway-bin/lib/cmd/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class BuildCommand extends Command {
type: 'string',
default: 'release',
},
tsConfig: {
description: 'tsConfig json object data',
type: 'object',
},
};
}

Expand Down Expand Up @@ -98,6 +102,8 @@ class BuildCommand extends Command {
if (argv.project) {
args.push('-p');
args.push(argv.project);
} else if (argv.tsConfig) {
await this.tsCfg2CliArgs(argv.tsConfig, args);
}
await this.helper.forkNode(tscCli, args, { cwd, execArgv: [] });

Expand Down Expand Up @@ -284,6 +290,41 @@ class BuildCommand extends Command {
const map = Buffer.from(match[1], 'base64').toString('utf8');
return map;
}

async tsCfg2CliArgs(cfg, args) {
// https://www.typescriptlang.org/docs/handbook/tsconfig-json.html
/**
* Files
*/
for (const file of cfg.files) {
args.push(file);
}

/**
* include & exclude
*/
const files = await globby(
[].concat(
// include
cfg.include || [],
// exclude
(cfg.exclude || []).map(str => '!' + str)
),
{
cwd: path.join(this.options.srcDir, '..'),
}
);
for (const item of files) {
args.push(item);
}

/**
* compilerOptions
*/
for (const key in cfg.compilerOptions || {}) {
args.push(`--${key} ${cfg.compilerOptions[key]}`);
}
}
}

module.exports = BuildCommand;

0 comments on commit 8e368fb

Please sign in to comment.