tscoverage/index.js

150 lines
5.5 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-30 04:29:54 +00:00
fs: require("fs"),
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"),
tsd: require("gulp-tsd"),
typescript: require("gulp-typescript")
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-16 13:33:09 +00:00
smartcli: require("smartcli")
};
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-18 18:11:42 +00:00
paths.tsd = plugins.path.join(paths.cwd, "ts/tsd.json");
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) {
NpmtsOptions.run = function () {
var done = plugins.q.defer();
done.resolve(); //TODO: check for options
return done.promise;
};
})(NpmtsOptions || (NpmtsOptions = {}));
2016-01-16 13:33:09 +00:00
/// <reference path="./index.ts" />
/// <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-01-18 18:11:42 +00:00
plugins.gulp.task("defaultTsd", function (cb) {
2016-01-25 19:52:29 +00:00
if (!process.env.TRAVIS) {
plugins.g.tsd({
command: 'reinstall',
config: paths.tsd
}, cb);
plugins.beautylog.log("now installing typings from" + " ts/tsd.json".blue);
}
else {
plugins.beautylog.warn("We are on TRAVIS. Typings will not be installed due to GitHub API restrictions.");
plugins.beautylog.log("Make sure the repo tracks " + "typings".blue + " directories");
}
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({
out: "index.js",
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);
2016-01-16 13:33:09 +00:00
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));
2016-01-16 13:33:09 +00:00
});
2016-01-18 18:11:42 +00:00
plugins.gulp.task("defaultCleanup", function (cb) {
plugins.beautylog.success("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) {
plugins.g.sequence("defaultTsd", "defaultIndexTS", "defaultTestTS", "defaultCleanup", cb);
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();
plugins.beautylog.info("Now running mocha tests");
// Instantiate a Mocha instance.
var mocha = new plugins.mocha();
var testDir = paths.testDir;
// Add each .js file to the mocha instance
plugins.fs.readdirSync(testDir).filter(function (file) {
// Only keep the .js files
return file.substr(-3) === '.js';
}).forEach(function (file) {
mocha.addFile(plugins.path.join(testDir, file));
});
// Run the tests.
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)
.then(NpmtsTests.run);
return promisechain;
};
})(NpmtsPromisechain || (NpmtsPromisechain = {}));
2016-01-14 18:25:36 +00:00
/// <reference path="./typings/tsd.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-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();