Kai Röder 8c8775c8f5 Angular now gets compiled by tsc, everything else is compiled by babel-typescript
TODO: need to migrate app/angular/server to TS in order to work with tsc
2019-01-04 14:13:23 +01:00

47 lines
1.3 KiB
JavaScript

/* eslint-disable no-console */
const path = require('path');
const shell = require('shelljs');
const chalk = require('chalk');
const fs = require('fs');
const log = require('npmlog');
const { babelify } = require('./compile-js');
const { tscfy } = require('./compile-ts');
function getPackageJson() {
const modulePath = path.resolve('./');
// eslint-disable-next-line global-require,import/no-dynamic-require
return require(path.join(modulePath, 'package.json'));
}
function removeDist() {
shell.rm('-rf', 'dist');
}
function cleanup() {
// add .ts filtering to babel args and remove after babel - 7 is adopted
// --copy-files option doesn't work with --ignore
// https://github.com/babel/babel/issues/5404
if (fs.existsSync(path.join(process.cwd(), 'dist'))) {
const files = shell.find('dist').filter(tsFile => tsFile.match(/\.(ts|tsx)$/));
if (files.length) {
shell.rm(files);
}
}
}
function logError(type, packageJson) {
log.error(
`FAILED to compile ${type}: ${chalk.bold(`${packageJson.name}@${packageJson.version}`)}`
);
}
const packageJson = getPackageJson();
removeDist();
babelify({ errorCallback: () => logError('js', packageJson) });
cleanup();
tscfy({ errorCallback: () => logError('ts', packageJson) });
console.log(chalk.gray(`Built: ${chalk.bold(`${packageJson.name}@${packageJson.version}`)}`));