tscoverage/index.js

258 lines
9.8 KiB
JavaScript
Raw Permalink 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-02-09 04:39:31 +00:00
coveralls: require("gulp-coveralls"),
2016-01-18 18:11:42 +00:00
insert: require("gulp-insert"),
2016-02-09 04:39:31 +00:00
istanbul: require("gulp-istanbul"),
mocha: require("gulp-mocha"),
2016-01-18 18:11:42 +00:00
typescript: require("gulp-typescript")
2016-01-18 14:15:15 +00:00
},
mergeStream: require("merge2"),
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" />
2016-02-09 04:39:31 +00:00
var NpmtsConfigFile;
(function (NpmtsConfigFile) {
NpmtsConfigFile.run = function () {
2016-01-30 04:29:54 +00:00
var done = plugins.q.defer();
2016-02-09 04:39:31 +00:00
var config = {};
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!");
2016-02-09 04:39:31 +00:00
config = plugins.smartfile.readFileToObject(configPath);
switch (config.mode) {
2016-02-04 19:41:34 +00:00
case "default":
case "custom":
2016-02-09 04:39:31 +00:00
plugins.beautylog.log("mode is " + config.mode.yellow);
done.resolve(config);
2016-02-04 19:41:34 +00:00
break;
default:
2016-02-09 04:39:31 +00:00
plugins.beautylog.error("mode " + config.mode.yellow + " not recognised!".red);
2016-02-04 19:41:34 +00:00
}
;
}
else {
plugins.beautylog.log("no config file found: so mode is " + "default".yellow);
2016-02-09 04:39:31 +00:00
config.mode = "default";
done.resolve(config);
2016-02-04 19:41:34 +00:00
}
;
2016-01-30 04:29:54 +00:00
return done.promise;
};
2016-02-09 04:39:31 +00:00
})(NpmtsConfigFile || (NpmtsConfigFile = {}));
2016-01-31 21:24:57 +00:00
/// <reference path="./index.ts" />
2016-02-09 04:39:31 +00:00
var NpmtsOptions;
(function (NpmtsOptions) {
NpmtsOptions.run = function (configArg) {
2016-01-31 21:24:57 +00:00
var done = plugins.q.defer();
2016-02-09 04:39:31 +00:00
var config = configArg;
2016-02-09 04:46:55 +00:00
if (typeof config.coveralls === "undefined") {
config.coveralls = false;
2016-02-09 04:46:55 +00:00
}
2016-02-09 04:39:31 +00:00
if (config.mode == "default") {
config.typings = [
"./ts/"
];
config.ts = (_a = {},
_a["./ts/index.ts"] = "./index.js",
_a["./ts/test.ts"] = "./test/test.js",
2016-02-09 04:39:31 +00:00
_a
);
config.test = ["./index.js"];
done.resolve(config);
}
else {
done.resolve(config);
2016-02-04 19:41:34 +00:00
}
2016-01-31 21:24:57 +00:00
return done.promise;
2016-02-09 04:39:31 +00:00
var _a;
2016-01-31 21:24:57 +00:00
};
2016-02-09 04:39:31 +00:00
})(NpmtsOptions || (NpmtsOptions = {}));
2016-01-16 13:33:09 +00:00
/// <reference path="./index.ts" />
2016-02-09 04:39:31 +00:00
var NpmtsCompile;
(function (NpmtsCompile) {
NpmtsCompile.run = function (configArg) {
2016-01-30 04:29:54 +00:00
var done = plugins.q.defer();
2016-02-09 04:39:31 +00:00
var config = configArg;
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();
2016-02-04 19:41:34 +00:00
}
else {
2016-02-09 04:39:31 +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]) })
.then(function () {
typingsCounterAdvance();
}, function () {
plugins.beautylog.error("something went wrong: Check if path is correct: " + config.typings[typingsCounter].blue);
typingsCounterAdvance();
});
};
installTypings();
/* -------------------------------------------------
* ----------- second compile TS -------------------
* ----------------------------------------------- */
typingsDone.promise.then(function () {
for (var key in config.ts) {
plugins.beautylog.log("now compiling" + key.blue);
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"));
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]);
}
})();
var tsStream = plugins.gulp.src(plugins.path.join(paths.cwd, key))
.pipe(plugins.g.typescript({
out: outputName,
2016-02-16 09:29:14 +00:00
declaration: true,
target: "ES5"
2016-02-09 04:39:31 +00:00
}));
var stream = plugins.mergeStream([
tsStream.dts.pipe(plugins.gulp.dest(outputDir)),
tsStream.js
.pipe(plugins.g.insert.prepend('#!/usr/bin/env node\n\n'))
.pipe(plugins.gulp.dest(outputDir))
]);
moduleStream.add(stream);
2016-02-04 19:41:34 +00:00
}
2016-02-09 04:39:31 +00:00
moduleStream.on("queueDrain", function () {
plugins.beautylog.success("custom TypeScript installed successfully");
moduleStream.on("finish", function () {
2016-02-09 16:01:37 +00:00
done.resolve(config);
2016-02-09 04:39:31 +00:00
});
moduleStream.end();
});
2016-01-16 13:33:09 +00:00
});
2016-01-30 04:29:54 +00:00
return done.promise;
2016-01-16 13:33:09 +00:00
};
2016-02-09 04:39:31 +00:00
})(NpmtsCompile || (NpmtsCompile = {}));
2016-01-30 04:29:54 +00:00
/// <reference path="./index.ts" />
var NpmtsTests;
(function (NpmtsTests) {
2016-02-09 04:46:55 +00:00
NpmtsTests.run = function (configArg) {
2016-01-30 04:29:54 +00:00
var done = plugins.q.defer();
2016-02-09 04:46:55 +00:00
var config = configArg;
var istanbul = function () {
var stream = plugins.gulp.src([plugins.path.join(paths.cwd, "index.js")])
2016-02-09 04:39:31 +00:00
.pipe(plugins.g.istanbul())
.pipe(plugins.g.istanbul.hookRequire());
return stream;
};
var mocha = function () {
var stream = plugins.gulp.src(["./test/test.js"])
2016-02-09 04:39:31 +00:00
.pipe(plugins.g.mocha())
.pipe(plugins.g.istanbul.writeReports())
2016-02-09 05:01:32 +00:00
.pipe(plugins.g.istanbul.enforceThresholds({ thresholds: { global: 30 } }));
return stream;
};
var coveralls = function () {
2016-02-09 16:26:25 +00:00
var stream = plugins.gulp.src([plugins.path.join(paths.cwd, "./coverage/lcov.info")])
.pipe(plugins.g.coveralls());
return stream;
};
istanbul().on("finish", function () {
mocha().on("finish", function () {
2016-02-09 16:26:25 +00:00
if (process.env.TRAVIS && config.coveralls) {
coveralls().on("finish", function () {
done.resolve(config);
});
}
else {
done.resolve(config);
2016-02-09 16:26:25 +00:00
}
2016-01-30 04:29:54 +00:00
});
});
return done.promise;
};
})(NpmtsTests || (NpmtsTests = {}));
/// <reference path="./index.ts" />
var NpmtsPromisechain;
(function (NpmtsPromisechain) {
NpmtsPromisechain.init = function () {
var promisechain;
2016-02-09 04:39:31 +00:00
NpmtsConfigFile.run()
.then(NpmtsOptions.run)
.then(NpmtsCompile.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-02-09 04:39:31 +00:00
/// <reference path="./npmts.configfile.ts" />
2016-01-25 19:52:29 +00:00
/// <reference path="./npmts.options.ts" />
2016-02-09 04:39:31 +00:00
/// <reference path="./npmts.compile.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();
2016-02-11 18:10:01 +00:00
plugins.beautylog.figletSync("NPMTS");
2016-01-16 13:33:09 +00:00
var paths = NpmtsPaths.init();
2016-01-30 04:29:54 +00:00
var promisechain = NpmtsPromisechain.init();