Skip to content

Commit

Permalink
Angular now gets compiled by tsc, everything else is compiled by babe…
Browse files Browse the repository at this point in the history
…l-typescript

TODO: need to migrate app/angular/server to TS in order to work with tsc
  • Loading branch information
kroeder committed Jan 4, 2019
1 parent 8543bf0 commit 8c8775c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
1 change: 0 additions & 1 deletion .babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module.exports = {
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-proposal-export-default-from',
['@babel/plugin-proposal-decorators', { legacy: true }],
],
env: {
test: {
Expand Down
3 changes: 2 additions & 1 deletion app/angular/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
],
"compileOnSave": false,
"compilerOptions": {
"rootDir": "./src"
"rootDir": "./src",
"outDir": "./dist"
}
}
6 changes: 5 additions & 1 deletion scripts/compile-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ function handleExit(code, errorCallback) {
}

function babelify(options = {}) {
const { watch = false, silent = true, errorCallback } = options;
if (process.cwd().includes(path.join('app', 'angular'))) {
return;
}

const { watch = false, silent = false, errorCallback } = options;

if (!fs.existsSync('src')) {
if (!silent) console.log('No src dir');
Expand Down
10 changes: 7 additions & 3 deletions scripts/compile-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ const shell = require('shelljs');
function getCommand(watch) {
const tsc = path.join(__dirname, '..', 'node_modules', '.bin', 'tsc');

const args = ['--outDir ./dist', '--emitDeclarationOnly', '--listEmittedFiles true'];
const args = ['--outDir ./dist', '--listEmittedFiles true'];

if (!process.cwd().includes(path.join('app', 'angular'))) {
args.push('--emitDeclarationOnly');
}

if (watch) {
args.push('-w');
Expand All @@ -25,7 +29,7 @@ function handleExit(code, errorCallback) {
}
}

function generateTSDefinitionFiles(options = {}) {
function tscfy(options = {}) {
const { watch = false, silent = true, errorCallback } = options;
const tsConfigFile = 'tsconfig.json';

Expand All @@ -49,5 +53,5 @@ function generateTSDefinitionFiles(options = {}) {
}

module.exports = {
generateTSDefinitionFiles,
tscfy,
};
20 changes: 8 additions & 12 deletions scripts/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
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 { generateTSDefinitionFiles } = require('./compile-ts');
const { tscfy } = require('./compile-ts');

function getPackageJson() {
const modulePath = path.resolve('./');
Expand All @@ -21,11 +22,11 @@ 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

const files = shell.find('dist').filter(tsFile => tsFile.match(/\.(ts|tsx)$/));

if (files.length) {
shell.rm(files);
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);
}
}
}

Expand All @@ -38,13 +39,8 @@ function logError(type, packageJson) {
const packageJson = getPackageJson();

removeDist();
// if (packageJson && packageJson.types && packageJson.types.indexOf('d.ts') !== -1) {
// tscfy({ errorCallback: () => logError('ts', packageJson) });
// } else {
babelify({ errorCallback: () => logError('js', packageJson) });
cleanup();
generateTSDefinitionFiles({ errorCallback: () => logError('ts', packageJson) });

// }
tscfy({ errorCallback: () => logError('ts', packageJson) });

console.log(chalk.gray(`Built: ${chalk.bold(`${packageJson.name}@${packageJson.version}`)}`));

0 comments on commit 8c8775c

Please sign in to comment.