clean up promise handling for ts compilation

This commit is contained in:
Philipp Kunz 2016-09-15 18:25:09 +02:00
parent 186460d437
commit d4c69071e4
2 changed files with 12 additions and 15 deletions

12
dist/npmts.compile.js vendored
View File

@ -28,22 +28,20 @@ var compileTs = function (tsFileArrayArg, tsOptionsArg) {
var _loop_1 = function (keyArg) { var _loop_1 = function (keyArg) {
plugins.beautylog.info("TypeScript assignment: transpile from " + keyArg.blue + " to " + tsFileArrayArg[keyArg].blue); plugins.beautylog.info("TypeScript assignment: transpile from " + keyArg.blue + " to " + tsFileArrayArg[keyArg].blue);
if (helpers.checkOutputPath(tsFileArrayArg, keyArg)) { if (helpers.checkOutputPath(tsFileArrayArg, keyArg)) {
var filesReadPromise = plugins.smartfile.fs.listFileTree(process.cwd(), keyArg) plugins.smartfile.fs.listFileTree(process.cwd(), keyArg)
.then(function (filesToConvertArg) { .then(function (filesToConvertArg) {
var filesToConvertAbsolute = plugins.smartpath.transform.toAbsolute(filesToConvertArg, process.cwd()); var filesToConvertAbsolute = plugins.smartpath.transform.toAbsolute(filesToConvertArg, process.cwd());
var destDir = plugins.smartpath.transform.toAbsolute(tsFileArrayArg[keyArg], process.cwd()); var destDir = plugins.smartpath.transform.toAbsolute(tsFileArrayArg[keyArg], process.cwd());
var filesCompiledPromise = plugins.tsn.compile(filesToConvertAbsolute, destDir, compilerOptions(keyArg)); return plugins.tsn.compile(filesToConvertAbsolute, destDir, compilerOptions(keyArg));
promiseArray.push(filesCompiledPromise); })
.then(function () {
done.resolve();
}); });
promiseArray.push(filesReadPromise);
} }
}; };
for (var keyArg in tsFileArrayArg) { for (var keyArg in tsFileArrayArg) {
_loop_1(keyArg); _loop_1(keyArg);
} }
;
plugins.Q.all(promiseArray)
.then(done.resolve);
return done.promise; return done.promise;
}; };
exports.run = function (configArg) { exports.run = function (configArg) {

View File

@ -30,22 +30,21 @@ let compileTs = (tsFileArrayArg: string[],tsOptionsArg = {}) => {
for (let keyArg in tsFileArrayArg) { for (let keyArg in tsFileArrayArg) {
plugins.beautylog.info(`TypeScript assignment: transpile from ${keyArg.blue} to ${tsFileArrayArg[keyArg].blue}`) plugins.beautylog.info(`TypeScript assignment: transpile from ${keyArg.blue} to ${tsFileArrayArg[keyArg].blue}`)
if (helpers.checkOutputPath(tsFileArrayArg,keyArg)) { if (helpers.checkOutputPath(tsFileArrayArg,keyArg)) {
let filesReadPromise = plugins.smartfile.fs.listFileTree(process.cwd(),keyArg) plugins.smartfile.fs.listFileTree(process.cwd(),keyArg)
.then((filesToConvertArg) => { .then((filesToConvertArg: string[]) => {
let filesToConvertAbsolute = plugins.smartpath.transform.toAbsolute(filesToConvertArg,process.cwd()) let filesToConvertAbsolute = plugins.smartpath.transform.toAbsolute(filesToConvertArg,process.cwd())
let destDir = plugins.smartpath.transform.toAbsolute(tsFileArrayArg[keyArg],process.cwd()) let destDir = plugins.smartpath.transform.toAbsolute(tsFileArrayArg[keyArg],process.cwd())
let filesCompiledPromise = plugins.tsn.compile( return plugins.tsn.compile(
filesToConvertAbsolute, filesToConvertAbsolute,
destDir, destDir,
compilerOptions(keyArg) compilerOptions(keyArg)
) )
promiseArray.push(filesCompiledPromise)
}) })
promiseArray.push(filesReadPromise) .then(() => {
done.resolve()
})
} }
}; }
plugins.Q.all(promiseArray)
.then(done.resolve)
return done.promise return done.promise
} }