From 6a9d257136d188b06e7fde6c60759a10d1c401f3 Mon Sep 17 00:00:00 2001 From: Inga Lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Wed, 1 Mar 2017 11:27:36 +0300 Subject: [PATCH] Fixed crash in JS environments --- BuildServer/lib/tasks/index.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/BuildServer/lib/tasks/index.ts b/BuildServer/lib/tasks/index.ts index 3bc4051..e182886 100644 --- a/BuildServer/lib/tasks/index.ts +++ b/BuildServer/lib/tasks/index.ts @@ -1,16 +1,18 @@ "use strict"; import { readdirSync } from "fs"; +import * as _ from "underscore"; -const tasks = {}; +const taskNames = _.unique(readdirSync(__dirname).map((file) => { + if (file.match(/\.ts$/) !== null) { + return file.substr(0, file.length - 3); + } -// Code taken from http://stackoverflow.com/a/17204293 -readdirSync(__dirname) - .forEach((file) => { - if (file.match(/\.ts$/) !== null && file !== "index.ts") { - const name = file.replace(".ts", ""); - tasks[name] = require(`./${file}`).default; - } - }); + if (file.match(/\.js$/) !== null) { + return file.substr(0, file.length - 3); + } -export default tasks as Tasks; + return ""; +}).filter((file) => file && file !== "index")); + +export default _.object(taskNames.map((name) => [name, require(`./${name}`).default])) as Tasks;