-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtscfy.js
52 lines (42 loc) · 1.35 KB
/
tscfy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const chalk = require('chalk');
const execa = require('execa');
const fs = require('fs-extra');
const { run } = require('./run');
function getCommand(watch) {
const args = [
'--project tsconfig.build.json',
'--outDir ./lib/ts4.2',
'--listEmittedFiles false',
'--declaration true',
'--noErrorTruncation',
'--pretty',
'--emitDeclarationOnly',
];
if (watch) {
args.push('-w', '--preserveWatchOutput');
}
return `npx tsc ${args.join(' ')}`;
}
async function tscfy(options = {}) {
const { watch = false, silent = false, errorCallback } = options;
const tsConfigFile = 'tsconfig.build.json';
if (!(await fs.pathExists(tsConfigFile))) {
if (!silent) {
console.log(`No '${chalk.yellow(tsConfigFile)}'`);
}
return;
}
const tsConfig = await fs.readJSON(tsConfigFile);
if (!(tsConfig && tsConfig.lerna && tsConfig.lerna.disabled === true)) {
const command = getCommand(watch);
await run({ watch, command, silent, errorCallback });
}
await execa.command('npx copyfiles -u 1 src/**/*.d.ts lib/ts4.2');
if (!watch) {
await execa.command('npx downlevel-dts lib/ts4.2 lib/ts3.9 --to=3.9');
await execa.command('npx downlevel-dts lib/ts4.2 lib/ts3.4 --to=3.4');
}
}
module.exports = {
tscfy,
};