Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tsConfig.json to tsc cmd line support #392

Merged
merged 1 commit into from
Feb 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;