tscoverage/ts/npmts.compile.ts

69 lines
2.6 KiB
TypeScript
Raw Permalink Normal View History

2016-09-06 15:21:25 +00:00
import 'typings-global'
import plugins = require('./npmts.plugins')
import paths = require('./npmts.paths')
import helpers = require('./npmts.compile.helpers')
import {npmtsOra} from './npmts.promisechain'
2016-09-06 15:21:25 +00:00
let promiseArray = []
let compileTs = (tsFileArrayArg: string[],tsOptionsArg = {}) => {
let done = plugins.Q.defer()
2016-03-12 09:21:16 +00:00
2016-07-27 14:08:33 +00:00
let compilerOptionsDefault = {
declaration: true,
2016-09-06 15:21:25 +00:00
module: 'CommonJS',
target: 'ES6'
}
/**
* merges default ts options with those found in npmts.json
*/
2016-09-06 15:21:25 +00:00
let compilerOptions = function (keyArg: string) {
let tsOptionsCombined = plugins.lodashObject.merge(compilerOptionsDefault, tsOptionsArg)
let compilerOptions: plugins.tsn.CompilerOptions = {
2016-07-27 14:08:33 +00:00
declaration: tsOptionsCombined.declaration,
module: plugins.tsn.ModuleKind[tsOptionsCombined.module],
2016-09-03 16:50:09 +00:00
target: plugins.tsn.ScriptTarget[tsOptionsCombined.target],
2016-09-06 15:21:25 +00:00
exclude: 'node_modules/**/*'
}
return compilerOptions
}
2016-06-07 06:49:22 +00:00
for (let keyArg in tsFileArrayArg) {
2016-09-06 15:21:25 +00:00
plugins.beautylog.info(`TypeScript assignment: transpile from ${keyArg.blue} to ${tsFileArrayArg[keyArg].blue}`)
2016-06-07 06:49:22 +00:00
if (helpers.checkOutputPath(tsFileArrayArg,keyArg)) {
2016-07-01 02:50:23 +00:00
let filesReadPromise = plugins.smartfile.fs.listFileTree(process.cwd(),keyArg)
.then((filesToConvertArg) => {
2016-09-06 15:21:25 +00:00
let filesToConvertAbsolute = plugins.smartpath.transform.toAbsolute(filesToConvertArg,process.cwd())
let destDir = plugins.smartpath.transform.toAbsolute(tsFileArrayArg[keyArg],process.cwd())
2016-07-01 02:50:23 +00:00
let filesCompiledPromise = plugins.tsn.compile(
filesToConvertAbsolute,
2016-07-27 14:08:33 +00:00
destDir,
compilerOptions(keyArg)
2016-09-06 15:21:25 +00:00
)
promiseArray.push(filesCompiledPromise)
})
promiseArray.push(filesReadPromise)
}
2016-07-01 02:50:23 +00:00
};
plugins.Q.all(promiseArray)
2016-09-06 15:21:25 +00:00
.then(done.resolve)
return done.promise
2016-06-07 06:49:22 +00:00
}
export let run = function (configArg) {
2016-09-06 15:21:25 +00:00
let done = plugins.Q.defer()
let config = configArg
npmtsOra.text('now compiling ' + 'TypeScript'.yellow)
2016-06-07 06:49:22 +00:00
compileTs(config.ts,config.tsOptions)
.then(() => {
2016-09-06 15:21:25 +00:00
plugins.beautylog.ok('compiled main TypeScript!')
plugins.beautylog.log('now compiling tests!')
return compileTs(config.testTs)
2016-06-07 06:49:22 +00:00
})
.then(function () {
2016-09-06 15:21:25 +00:00
plugins.beautylog.ok('compiled all TypeScript!')
done.resolve(config)
})
return done.promise
}