now accepts config file

This commit is contained in:
2016-02-04 20:41:34 +01:00
parent 7d18e92ff1
commit de4bbaed9f
18 changed files with 245 additions and 43 deletions

View File

@ -3,7 +3,6 @@
/// <reference path="./npmts.cli.ts" />
/// <reference path="./npmts.paths.ts" />
/// <reference path="./npmts.options.ts" />
/// <reference path="./npmts.typings.ts" />
/// <reference path="./npmts.custom.ts" />
/// <reference path="./npmts.default.ts" />
/// <reference path="./npmts.tests.ts" />

View File

@ -1 +1,60 @@
/// <reference path="./index.ts" />
/// <reference path="./index.ts" />
module NpmtsCustom {
export var run = function(){
var done = plugins.q.defer();
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 checkTypingsDone = function(indexArg:number,compareArray){
if((indexArg + 1) == compareArray.length){
plugins.beautylog.success("custom typings installed successfully");
typingsDone.resolve();
}
};
for (var key in config.typings) {
plugins.beautylog.log("now installing " + "typings.json".yellow + " from " + config.typings[key].blue);
plugins.typings.install({production: false, cwd: plugins.path.join(paths.cwd,config.typings[key])})
.then(function(){
checkTypingsDone(key,config.typings);
});
}
/* -------------------------------------------------
* ----------- second compile TS -------------------
* ----------------------------------------------- */
typingsDone.promise.then(function(){
for (var key in config.ts) {
plugins.beautylog.log("now compiling" + key.blue);
var tsStream = plugins.gulp.src(plugins.path.join(paths.cwd,key))
.pipe(plugins.g.typescript({
out: plugins.path.basename(config.ts[key]),
declaration: true
}));
var stream = plugins.mergeStream([
tsStream.dts.pipe(plugins.gulp.dest(paths.cwd)),
tsStream.js
.pipe(plugins.g.insert.prepend('#!/usr/bin/env node\n\n'))
.pipe(plugins.gulp.dest(
plugins.path.dirname(
plugins.path.join(paths.cwd,config.ts[key])
)
))
]);
moduleStream.add(stream);
}
moduleStream.on("queueDrain",function(){
plugins.beautylog.success("custom TypeScript installed successfully");
moduleStream.on("finish",function(){
done.resolve();
});
moduleStream.end();
});
});
}
return done.promise;
}
}

View File

@ -3,13 +3,18 @@
module NpmtsDefault {
export var run = function() {
var done = plugins.q.defer();
plugins.gulp.task("defaultTypings",function(cb){
plugins.beautylog.log("now installing default typings");
plugins.typings.install({production: false, cwd: paths.tsDir})
.then(function(){
cb();
});
});
plugins.gulp.task("defaultIndexTS", function(){
plugins.beautylog.log("now compiling" + " ts/index.ts".blue);
var tsResult = plugins.gulp.src(paths.indexTS)
.pipe(plugins.g.typescript({
out:"index.js",
out:"./index.js",
declaration:true
}));
@ -32,13 +37,19 @@ module NpmtsDefault {
});
plugins.gulp.task("defaultCleanup",function(cb){
plugins.beautylog.success("TypeScript for this module compiled successfully.");
plugins.beautylog.success("default TypeScript for this module compiled successfully.");
done.resolve();
cb();
});
plugins.gulp.task("default",function(cb){
plugins.g.sequence("defaultIndexTS","defaultTestTS","defaultCleanup",cb);
if(NpmtsOptions.config.mode == "default"){
plugins.g.sequence("defaultTypings","defaultIndexTS","defaultTestTS","defaultCleanup",cb);
} else {
cb();
done.resolve();
}
});
plugins.gulp.start.apply(plugins.gulp, ['default']);

View File

@ -1,8 +1,29 @@
/// <reference path="./index.ts" />
module NpmtsOptions {
export var config:any = {};
export var run = function(){
var done = plugins.q.defer();
done.resolve(); //TODO: check for options
var configPath = plugins.path.join(paths.cwd,"npmts.json");
if(plugins.smartfile.checks.fileExistsSync(configPath)){
plugins.beautylog.info("npmts.json".blue + " config file found!");
config = plugins.smartfile.readFileToObject(configPath);
switch (config.mode){
case "default":
plugins.beautylog.log("mode is " + config.mode.yellow);
done.resolve();
break;
case "custom":
plugins.beautylog.log("mode is " + config.mode.yellow);
done.resolve();
break;
default:
plugins.beautylog.error("mode " + config.mode.yellow + " not recognised!".red);
};
} else {
plugins.beautylog.log("no config file found: so mode is " + "default".yellow);
config.mode = "default";
done.resolve();
};
return done.promise;
}
}

View File

@ -16,6 +16,7 @@ module NpmtsPlugins {
path: require("path"),
q:require("q"),
smartcli: require("smartcli"),
smartfile: require("smartfile"),
typings: require("typings")
};
return plugins;

View File

@ -3,8 +3,8 @@ module NpmtsPromisechain {
export var init = function(){
var promisechain;
NpmtsOptions.run()
.then(NpmtsTypings.run)
.then(NpmtsDefault.run)
.then(NpmtsCustom.run)
.then(NpmtsTests.run);
return promisechain;
}

View File

@ -1,12 +0,0 @@
/// <reference path="./index.ts" />
module NpmtsTypings {
export var run = function(){
var done = plugins.q.defer();
plugins.beautylog.log("now installing typings");
plugins.typings.install({production: false, cwd: paths.tsDir})
.then(function(){
done.resolve();
});
return done.promise;
}
}