tscoverage/index.js

265 lines
11 KiB
JavaScript
Raw Normal View History

2016-01-14 18:31:53 +00:00
#!/usr/bin/env node
2016-01-16 13:33:09 +00:00
/// <reference path="./index.ts" />
var NpmtsPlugins;
(function (NpmtsPlugins) {
NpmtsPlugins.init = function () {
var plugins = {
beautylog: require("beautylog"),
2016-01-31 21:24:57 +00:00
fs: require("fs-extra"),
2016-01-16 13:33:09 +00:00
gulp: require("gulp"),
2016-01-18 14:15:15 +00:00
g: {
2016-01-18 18:11:42 +00:00
insert: require("gulp-insert"),
sequence: require("gulp-sequence"),
typescript: require("gulp-typescript")
2016-01-18 14:15:15 +00:00
},
mathjs: require("mathjs"),
2016-01-18 14:15:15 +00:00
mergeStream: require("merge2"),
2016-01-30 04:29:54 +00:00
mocha: require("mocha"),
2016-01-16 13:33:09 +00:00
path: require("path"),
2016-01-30 04:29:54 +00:00
q: require("q"),
2016-01-31 21:24:57 +00:00
smartcli: require("smartcli"),
2016-02-04 19:41:34 +00:00
smartfile: require("smartfile"),
2016-01-31 21:24:57 +00:00
typings: require("typings")
2016-01-16 13:33:09 +00:00
};
return plugins;
};
})(NpmtsPlugins || (NpmtsPlugins = {}));
/// <reference path="./index.ts" />
/// <reference path="./index.ts" />
var NpmtsPaths;
(function (NpmtsPaths) {
NpmtsPaths.init = function () {
var paths = {};
paths.cwd = plugins.smartcli.get.cwd().path;
2016-01-31 21:24:57 +00:00
paths.tsDir = plugins.path.join(paths.cwd, "ts/");
2016-01-16 13:33:09 +00:00
paths.indexTS = plugins.path.join(paths.cwd, "ts/index.ts");
paths.testTS = plugins.path.join(paths.cwd, "ts/test.ts");
2016-01-30 04:29:54 +00:00
paths.testDir = plugins.path.join(paths.cwd, "test/");
2016-01-16 13:33:09 +00:00
return paths;
};
})(NpmtsPaths || (NpmtsPaths = {}));
2016-01-30 04:29:54 +00:00
/// <reference path="./index.ts" />
var NpmtsOptions;
(function (NpmtsOptions) {
2016-02-04 19:41:34 +00:00
NpmtsOptions.config = {};
2016-01-30 04:29:54 +00:00
NpmtsOptions.run = function () {
var done = plugins.q.defer();
2016-02-04 19:41:34 +00:00
var configPath = plugins.path.join(paths.cwd, "npmts.json");
if (plugins.smartfile.checks.fileExistsSync(configPath)) {
plugins.beautylog.info("npmts.json".blue + " config file found!");
NpmtsOptions.config = plugins.smartfile.readFileToObject(configPath);
switch (NpmtsOptions.config.mode) {
case "default":
plugins.beautylog.log("mode is " + NpmtsOptions.config.mode.yellow);
done.resolve();
break;
case "custom":
plugins.beautylog.log("mode is " + NpmtsOptions.config.mode.yellow);
done.resolve();
break;
default:
plugins.beautylog.error("mode " + NpmtsOptions.config.mode.yellow + " not recognised!".red);
}
;
}
else {
plugins.beautylog.log("no config file found: so mode is " + "default".yellow);
NpmtsOptions.config.mode = "default";
done.resolve();
}
;
2016-01-30 04:29:54 +00:00
return done.promise;
};
})(NpmtsOptions || (NpmtsOptions = {}));
2016-01-31 21:24:57 +00:00
/// <reference path="./index.ts" />
2016-02-04 19:41:34 +00:00
var NpmtsCustom;
(function (NpmtsCustom) {
NpmtsCustom.run = function () {
2016-01-31 21:24:57 +00:00
var done = plugins.q.defer();
2016-02-04 19:41:34 +00:00
var config = NpmtsOptions.config;
if (config.mode === "custom") {
plugins.beautylog.log("now running custom tasks");
var moduleStream = plugins.mergeStream({ end: false });
/* -------------------------------------------------
* ----------- first install typings ---------------
* ----------------------------------------------- */
var typingsDone = plugins.q.defer();
var typingsCounter = 0;
var typingsCounterAdvance = function () {
typingsCounter++;
if (typeof config.typings[typingsCounter] != "undefined") {
installTypings();
}
else {
2016-02-04 19:41:34 +00:00
plugins.beautylog.success("custom typings installed successfully");
typingsDone.resolve();
}
};
var installTypings = function () {
plugins.beautylog.log("now installing " + "typings.json".yellow + " from " + config.typings[typingsCounter].blue);
plugins.typings.install({ production: false, cwd: plugins.path.join(paths.cwd, config.typings[typingsCounter]) })
2016-02-04 19:41:34 +00:00
.then(function () {
typingsCounterAdvance();
}, function () {
plugins.beautylog.error("something went wrong: Check if path is correct: " + config.typings[typingsCounter].blue);
typingsCounterAdvance();
2016-02-04 19:41:34 +00:00
});
};
installTypings();
2016-02-04 19:41:34 +00:00
/* -------------------------------------------------
* ----------- second compile TS -------------------
* ----------------------------------------------- */
typingsDone.promise.then(function () {
for (var key in config.ts) {
plugins.beautylog.log("now compiling" + key.blue);
2016-02-06 17:06:55 +00:00
var outputPathIsDir;
try {
if (plugins.fs.statSync(plugins.path.join(paths.cwd, config.ts[key])).isDirectory()) {
outputPathIsDir = true;
}
}
catch (err) {
outputPathIsDir = false;
}
//do some evaluation of the environment
var outputNameSpecified = (!outputPathIsDir
&& (plugins.path.extname(config.ts[key]) == ".js"));
console.log("outputNameSpecified");
var outputName = (function () {
if (outputNameSpecified) {
return plugins.path.basename(config.ts[key]);
}
else {
return undefined;
}
})();
var outputDir = (function () {
if (outputNameSpecified) {
return plugins.path.dirname(plugins.path.join(paths.cwd, config.ts[key]));
}
else {
return plugins.path.join(paths.cwd, config.ts[key]);
}
})();
2016-02-04 19:41:34 +00:00
var tsStream = plugins.gulp.src(plugins.path.join(paths.cwd, key))
.pipe(plugins.g.typescript({
2016-02-06 17:06:55 +00:00
out: outputName,
2016-02-04 19:41:34 +00:00
declaration: true
}));
var stream = plugins.mergeStream([
2016-02-06 17:06:55 +00:00
tsStream.dts.pipe(plugins.gulp.dest(outputDir)),
2016-02-04 19:41:34 +00:00
tsStream.js
.pipe(plugins.g.insert.prepend('#!/usr/bin/env node\n\n'))
2016-02-06 17:06:55 +00:00
.pipe(plugins.gulp.dest(outputDir))
2016-02-04 19:41:34 +00:00
]);
moduleStream.add(stream);
}
moduleStream.on("queueDrain", function () {
plugins.beautylog.success("custom TypeScript installed successfully");
moduleStream.on("finish", function () {
done.resolve();
});
moduleStream.end();
});
});
}
2016-01-31 21:24:57 +00:00
return done.promise;
};
2016-02-04 19:41:34 +00:00
})(NpmtsCustom || (NpmtsCustom = {}));
2016-01-16 13:33:09 +00:00
/// <reference path="./index.ts" />
var NpmtsDefault;
(function (NpmtsDefault) {
2016-01-30 04:29:54 +00:00
NpmtsDefault.run = function () {
var done = plugins.q.defer();
2016-02-04 19:41:34 +00:00
plugins.gulp.task("defaultTypings", function (cb) {
plugins.beautylog.log("now installing default typings");
plugins.typings.install({ production: false, cwd: paths.tsDir })
.then(function () {
cb();
});
});
2016-01-18 18:11:42 +00:00
plugins.gulp.task("defaultIndexTS", function () {
plugins.beautylog.log("now compiling" + " ts/index.ts".blue);
2016-01-18 14:15:15 +00:00
var tsResult = plugins.gulp.src(paths.indexTS)
.pipe(plugins.g.typescript({
2016-02-04 19:41:34 +00:00
out: "./index.js",
2016-01-18 14:15:15 +00:00
declaration: true
}));
return plugins.mergeStream([
tsResult.dts.pipe(plugins.gulp.dest(paths.cwd)),
tsResult.js
.pipe(plugins.g.insert.prepend('#!/usr/bin/env node\n\n'))
.pipe(plugins.gulp.dest(paths.cwd))
]);
2016-01-16 13:33:09 +00:00
});
2016-01-18 18:11:42 +00:00
plugins.gulp.task("defaultTestTS", function () {
plugins.beautylog.log("now compiling" + " ts/test.ts".blue);
var stream = plugins.gulp.src(paths.testTS)
2016-01-18 14:15:15 +00:00
.pipe(plugins.g.typescript({
2016-01-16 13:33:09 +00:00
out: "test.js"
}))
2016-01-30 04:29:54 +00:00
.pipe(plugins.gulp.dest(paths.testDir));
return stream;
2016-01-16 13:33:09 +00:00
});
2016-01-18 18:11:42 +00:00
plugins.gulp.task("defaultCleanup", function (cb) {
2016-02-04 19:41:34 +00:00
plugins.beautylog.success("default TypeScript for this module compiled successfully.");
2016-01-30 04:29:54 +00:00
done.resolve();
2016-01-18 18:11:42 +00:00
cb();
});
plugins.gulp.task("default", function (cb) {
2016-02-04 19:41:34 +00:00
if (NpmtsOptions.config.mode == "default") {
plugins.g.sequence("defaultTypings", "defaultIndexTS", "defaultTestTS", "defaultCleanup", cb);
}
else {
cb();
done.resolve();
}
2016-01-16 13:33:09 +00:00
});
plugins.gulp.start.apply(plugins.gulp, ['default']);
2016-01-30 04:29:54 +00:00
return done.promise;
2016-01-16 13:33:09 +00:00
};
})(NpmtsDefault || (NpmtsDefault = {}));
2016-01-30 04:29:54 +00:00
/// <reference path="./index.ts" />
var NpmtsTests;
(function (NpmtsTests) {
NpmtsTests.run = function () {
var done = plugins.q.defer();
2016-01-31 21:24:57 +00:00
plugins.fs.ensureDirSync(paths.testDir); //make sure that mocha has a directory to look for tests
2016-01-30 04:29:54 +00:00
plugins.beautylog.info("Now running mocha tests");
2016-01-31 21:24:57 +00:00
var mocha = new plugins.mocha(); // Instantiate a Mocha instance.
2016-01-31 23:24:08 +00:00
mocha.addFile(plugins.path.join(paths.testDir, "test.js"));
2016-01-30 04:29:54 +00:00
mocha.run(function (failures) {
process.on('exit', function () {
process.exit(failures);
});
});
return done.promise;
};
})(NpmtsTests || (NpmtsTests = {}));
/// <reference path="./index.ts" />
var NpmtsPromisechain;
(function (NpmtsPromisechain) {
NpmtsPromisechain.init = function () {
var promisechain;
NpmtsOptions.run()
.then(NpmtsDefault.run)
2016-02-04 19:41:34 +00:00
.then(NpmtsCustom.run)
2016-01-30 04:29:54 +00:00
.then(NpmtsTests.run);
return promisechain;
};
})(NpmtsPromisechain || (NpmtsPromisechain = {}));
2016-01-31 21:24:57 +00:00
/// <reference path="./typings/main.d.ts" />
2016-01-16 13:33:09 +00:00
/// <reference path="./npmts.plugins.ts" />
/// <reference path="./npmts.cli.ts" />
/// <reference path="./npmts.paths.ts" />
2016-01-25 19:52:29 +00:00
/// <reference path="./npmts.options.ts" />
2016-01-16 13:33:09 +00:00
/// <reference path="./npmts.custom.ts" />
/// <reference path="./npmts.default.ts" />
2016-01-30 04:29:54 +00:00
/// <reference path="./npmts.tests.ts" />
/// <reference path="./npmts.promisechain.ts" />
2016-01-31 23:24:08 +00:00
console.log("**** starting NPMTS ****");
2016-01-16 13:33:09 +00:00
var plugins = NpmtsPlugins.init();
var paths = NpmtsPaths.init();
2016-01-30 04:29:54 +00:00
var promisechain = NpmtsPromisechain.init();