now using commonjs module system
This commit is contained in:
14
ts/index.ts
14
ts/index.ts
@ -1,14 +1,6 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
/// <reference path="./npmts.plugins.ts" />
|
||||
/// <reference path="./npmts.cli.ts" />
|
||||
/// <reference path="./npmts.paths.ts" />
|
||||
/// <reference path="./npmts.configfile.ts" />
|
||||
/// <reference path="./npmts.options.ts" />
|
||||
/// <reference path="./npmts.compile.ts" />
|
||||
/// <reference path="./npmts.tests.ts" />
|
||||
/// <reference path="./npmts.promisechain.ts" />
|
||||
console.log("**** starting NPMTS ****");
|
||||
var plugins = NpmtsPlugins.init();
|
||||
import plugins = require("./npmts.plugins");
|
||||
import promisechain = require("./npmts.promisechain");
|
||||
plugins.beautylog.figletSync("NPMTS");
|
||||
var paths = NpmtsPaths.init();
|
||||
var promisechain = NpmtsPromisechain.init();
|
||||
promisechain.run();
|
||||
|
@ -1 +1 @@
|
||||
/// <reference path="./index.ts" />
|
||||
/// <reference path="./typings/main.d.ts" />
|
@ -1,92 +1,92 @@
|
||||
/// <reference path="./index.ts" />
|
||||
module NpmtsCompile {
|
||||
export var run = function(configArg){
|
||||
var done = plugins.q.defer();
|
||||
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:number = 0;
|
||||
var typingsCounterAdvance = function(){
|
||||
typingsCounter++;
|
||||
if(typeof config.typings[typingsCounter] != "undefined"){
|
||||
installTypings();
|
||||
} else {
|
||||
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:boolean;
|
||||
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:boolean = (
|
||||
!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 stream = plugins.gulp.src([plugins.path.join(paths.cwd,key),"!**/typings/**"])
|
||||
.pipe(plugins.g.sourcemaps.init()) // This means sourcemaps will be generated
|
||||
.pipe(plugins.g.typescript({
|
||||
out: outputName,
|
||||
target: "ES5",
|
||||
module: "commonjs"
|
||||
}))
|
||||
.pipe(plugins.g.sourcemaps.write()) // Now the sourcemaps are added to the .js file
|
||||
//.pipe(plugins.g.header('#!/usr/bin/env node\n\n'))
|
||||
.pipe(plugins.gulp.dest(outputDir));
|
||||
moduleStream.add(stream);
|
||||
}
|
||||
moduleStream.on("queueDrain",function(){
|
||||
plugins.beautylog.success("custom TypeScript installed successfully");
|
||||
moduleStream.on("finish",function(){
|
||||
done.resolve(config);
|
||||
});
|
||||
moduleStream.end();
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
import plugins = require("./npmts.plugins");
|
||||
import paths = require("./npmts.paths");
|
||||
export var run = function(configArg){
|
||||
var done = plugins.q.defer();
|
||||
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:number = 0;
|
||||
var typingsCounterAdvance = function(){
|
||||
typingsCounter++;
|
||||
if(typeof config.typings[typingsCounter] != "undefined"){
|
||||
installTypings();
|
||||
} else {
|
||||
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:boolean;
|
||||
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:boolean = (
|
||||
!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 stream = plugins.gulp.src([plugins.path.join(paths.cwd,key),"!**/typings/**"])
|
||||
.pipe(plugins.g.sourcemaps.init()) // This means sourcemaps will be generated
|
||||
.pipe(plugins.g.typescript({
|
||||
out: outputName,
|
||||
target: "ES5",
|
||||
module: "commonjs"
|
||||
}))
|
||||
.pipe(plugins.g.sourcemaps.write()) // Now the sourcemaps are added to the .js file
|
||||
//.pipe(plugins.g.header('#!/usr/bin/env node\n\n'))
|
||||
.pipe(plugins.gulp.dest(outputDir));
|
||||
moduleStream.add(stream);
|
||||
}
|
||||
moduleStream.on("queueDrain",function(){
|
||||
plugins.beautylog.success("custom TypeScript installed successfully");
|
||||
moduleStream.on("finish",function(){
|
||||
done.resolve(config);
|
||||
});
|
||||
moduleStream.end();
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
}
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
|
@ -1,26 +1,26 @@
|
||||
/// <reference path="./index.ts" />
|
||||
module NpmtsConfigFile {
|
||||
export var run = function(){
|
||||
var done = plugins.q.defer();
|
||||
var config:any = {};
|
||||
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":
|
||||
case "custom":
|
||||
plugins.beautylog.log("mode is " + config.mode.yellow);
|
||||
done.resolve(config);
|
||||
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(config);
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
import plugins = require("./npmts.plugins");
|
||||
import paths = require("./npmts.paths");
|
||||
export var run = function(){
|
||||
var done = plugins.q.defer();
|
||||
var config:any = {};
|
||||
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":
|
||||
case "custom":
|
||||
plugins.beautylog.log("mode is " + config.mode.yellow);
|
||||
done.resolve(config);
|
||||
break;
|
||||
default:
|
||||
plugins.beautylog.error("mode " + config.mode.yellow + " not recognised!".red);
|
||||
};
|
||||
return done.promise;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
plugins.beautylog.log("no config file found: so mode is " + "default".yellow);
|
||||
config.mode = "default";
|
||||
done.resolve(config);
|
||||
};
|
||||
return done.promise;
|
||||
};
|
@ -1,24 +1,23 @@
|
||||
/// <reference path="./index.ts" />
|
||||
module NpmtsOptions {
|
||||
export var run = function(configArg){
|
||||
var done = plugins.q.defer();
|
||||
var config = configArg;
|
||||
if (typeof config.coveralls === "undefined"){
|
||||
config.coveralls = false;
|
||||
}
|
||||
if (config.mode == "default"){
|
||||
config.typings = [
|
||||
"./ts/"
|
||||
];
|
||||
config.ts = {
|
||||
["./ts/**/*.ts"]: "./dist/",
|
||||
["./test/test.ts"]: "./test/"
|
||||
};
|
||||
config.test = ["./index.js"];
|
||||
done.resolve(config);
|
||||
} else {
|
||||
done.resolve(config);
|
||||
}
|
||||
return done.promise;
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
import plugins = require("./npmts.plugins");
|
||||
export var run = function(configArg){
|
||||
var done = plugins.q.defer();
|
||||
var config = configArg;
|
||||
if (typeof config.coveralls === "undefined"){
|
||||
config.coveralls = false;
|
||||
}
|
||||
}
|
||||
if (config.mode == "default"){
|
||||
config.typings = [
|
||||
"./ts/"
|
||||
];
|
||||
config.ts = {
|
||||
["./ts/**/*.ts"]: "./dist/",
|
||||
["./test/test.ts"]: "./test/"
|
||||
};
|
||||
config.test = ["./index.js"];
|
||||
done.resolve(config);
|
||||
} else {
|
||||
done.resolve(config);
|
||||
}
|
||||
return done.promise;
|
||||
};
|
@ -1,12 +1,9 @@
|
||||
/// <reference path="./index.ts" />
|
||||
module NpmtsPaths {
|
||||
export var init = function() {
|
||||
var paths:any = {};
|
||||
paths.cwd = plugins.smartcli.get.cwd().path;
|
||||
paths.tsDir = plugins.path.join(paths.cwd,"ts/");
|
||||
paths.indexTS = plugins.path.join(paths.cwd,"ts/index.ts");
|
||||
paths.testTS = plugins.path.join(paths.cwd,"ts/test.ts");
|
||||
paths.testDir = plugins.path.join(paths.cwd,"test/");
|
||||
return paths;
|
||||
}
|
||||
}
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
import plugins = require("./npmts.plugins");
|
||||
var paths:any = {};
|
||||
paths.cwd = plugins.smartcli.get.cwd().path;
|
||||
paths.tsDir = plugins.path.join(paths.cwd,"ts/");
|
||||
paths.indexTS = plugins.path.join(paths.cwd,"ts/index.ts");
|
||||
paths.testTS = plugins.path.join(paths.cwd,"ts/test.ts");
|
||||
paths.testDir = plugins.path.join(paths.cwd,"test/");
|
||||
export = paths;
|
@ -1,26 +1,22 @@
|
||||
/// <reference path="./index.ts" />
|
||||
module NpmtsPlugins {
|
||||
export var init = function() {
|
||||
var plugins = {
|
||||
beautylog: require("beautylog"),
|
||||
fs: require("fs-extra"),
|
||||
gulp: require("gulp"),
|
||||
g: {
|
||||
coveralls: require("gulp-coveralls"),
|
||||
istanbul: require("gulp-istanbul"),
|
||||
mocha: require("gulp-mocha"),
|
||||
sourcemaps: require("gulp-sourcemaps"),
|
||||
typescript: require("gulp-typescript")
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
var plugins = {
|
||||
beautylog: require("beautylog"),
|
||||
fs: require("fs-extra"),
|
||||
gulp: require("gulp"),
|
||||
g: {
|
||||
coveralls: require("gulp-coveralls"),
|
||||
istanbul: require("gulp-istanbul"),
|
||||
mocha: require("gulp-mocha"),
|
||||
sourcemaps: require("gulp-sourcemaps"),
|
||||
typescript: require("gulp-typescript")
|
||||
|
||||
},
|
||||
mergeStream: require("merge2"),
|
||||
sourceMapSupport:require("source-map-support").install(),
|
||||
path: require("path"),
|
||||
q:require("q"),
|
||||
smartcli: require("smartcli"),
|
||||
smartfile: require("smartfile"),
|
||||
typings: require("typings")
|
||||
};
|
||||
return plugins;
|
||||
}
|
||||
}
|
||||
},
|
||||
mergeStream: require("merge2"),
|
||||
sourceMapSupport:require("source-map-support").install(),
|
||||
path: require("path"),
|
||||
q:require("q"),
|
||||
smartcli: require("smartcli"),
|
||||
smartfile: require("smartfile"),
|
||||
typings: require("typings")
|
||||
};
|
||||
export = plugins;
|
@ -1,11 +1,13 @@
|
||||
/// <reference path="./index.ts" />
|
||||
module NpmtsPromisechain {
|
||||
export var init = function(){
|
||||
var promisechain;
|
||||
NpmtsConfigFile.run()
|
||||
.then(NpmtsOptions.run)
|
||||
.then(NpmtsCompile.run)
|
||||
.then(NpmtsTests.run);
|
||||
return promisechain;
|
||||
}
|
||||
}
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
import NpmtsConfigFile = require("./npmts.configfile");
|
||||
import NpmtsOptions = require("./npmts.options");
|
||||
import NpmtsCompile = require("./npmts.compile");
|
||||
import NpmtsTests = require("./npmts.tests");
|
||||
export var run = function(){
|
||||
var promisechain;
|
||||
NpmtsConfigFile.run()
|
||||
.then(NpmtsOptions.run)
|
||||
.then(NpmtsCompile.run)
|
||||
.then(NpmtsTests.run);
|
||||
return promisechain;
|
||||
};
|
@ -1,44 +1,44 @@
|
||||
/// <reference path="./index.ts" />
|
||||
module NpmtsTests {
|
||||
export var run = function(configArg) {
|
||||
var done = plugins.q.defer();
|
||||
var config = configArg;
|
||||
var istanbul = function () {
|
||||
var stream = plugins.gulp.src([plugins.path.join(paths.cwd,"dist/*.js")])
|
||||
// Covering files
|
||||
.pipe(plugins.g.istanbul())
|
||||
// Force `require` to return covered files
|
||||
.pipe(plugins.g.istanbul.hookRequire());
|
||||
return stream;
|
||||
};
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
import plugins = require("./npmts.plugins");
|
||||
import paths = require("./npmts.paths");
|
||||
export var run = function(configArg) {
|
||||
var done = plugins.q.defer();
|
||||
var config = configArg;
|
||||
var istanbul = function () {
|
||||
var stream = plugins.gulp.src([plugins.path.join(paths.cwd,"dist/*.js")])
|
||||
// Covering files
|
||||
.pipe(plugins.g.istanbul())
|
||||
// Force `require` to return covered files
|
||||
.pipe(plugins.g.istanbul.hookRequire());
|
||||
return stream;
|
||||
};
|
||||
|
||||
var mocha = function () {
|
||||
var stream = plugins.gulp.src(["./test/test.js"])
|
||||
.pipe(plugins.g.mocha())
|
||||
// Creating the reports after tests ran
|
||||
.pipe(plugins.g.istanbul.writeReports())
|
||||
// Enforce a coverage of at least 90%
|
||||
.pipe(plugins.g.istanbul.enforceThresholds({ thresholds: { global: 30 } }));
|
||||
return stream;
|
||||
};
|
||||
var mocha = function () {
|
||||
var stream = plugins.gulp.src(["./test/test.js"])
|
||||
.pipe(plugins.g.mocha())
|
||||
// Creating the reports after tests ran
|
||||
.pipe(plugins.g.istanbul.writeReports())
|
||||
// Enforce a coverage of at least 90%
|
||||
.pipe(plugins.g.istanbul.enforceThresholds({ thresholds: { global: 30 } }));
|
||||
return stream;
|
||||
};
|
||||
|
||||
var coveralls = function(){
|
||||
var stream = plugins.gulp.src([plugins.path.join(paths.cwd,"./coverage/lcov.info")])
|
||||
.pipe(plugins.g.coveralls());
|
||||
return stream;
|
||||
};
|
||||
var coveralls = function(){
|
||||
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(){
|
||||
if(process.env.TRAVIS && config.coveralls){
|
||||
coveralls().on("finish",function(){
|
||||
done.resolve(config);
|
||||
})
|
||||
} else {
|
||||
istanbul().on("finish",function(){
|
||||
mocha().on("finish",function(){
|
||||
if(process.env.TRAVIS && config.coveralls){
|
||||
coveralls().on("finish",function(){
|
||||
done.resolve(config);
|
||||
}
|
||||
})
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
done.resolve(config);
|
||||
}
|
||||
})
|
||||
});
|
||||
return done.promise;
|
||||
};
|
Reference in New Issue
Block a user