gulp-ts
Advanced tools
Comparing version 0.0.11 to 0.0.12
109
index.js
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
/*jslint node:true */ | ||
@@ -12,2 +13,3 @@ /*jslint nomen: true */ | ||
var gutil = require('gulp-util'); | ||
var log = gutil.log; | ||
var PluginError = gutil.PluginError; | ||
@@ -22,9 +24,9 @@ var File = gutil.File; | ||
"use strict"; | ||
var tsPlugin = function(options) { | ||
var tsPlugin = function (options) { | ||
var bufferFiles, | ||
compileFiles, | ||
files = []; | ||
handleDeclaration, | ||
files = [], | ||
// Files are compiled in this sub-directory | ||
compiledir = 'compiledir'; | ||
@@ -35,10 +37,13 @@ // Default options | ||
} | ||
if (options.debug) { | ||
options.verbose = true; | ||
} | ||
// Collect all files to an array | ||
bufferFiles = function(file) { | ||
bufferFiles = function (file) { | ||
// Null values and streams are skipped | ||
if (file.isNull()) { | ||
return; | ||
} else if (file.isStream()) { | ||
} | ||
if (file.isStream()) { | ||
return this.emit('error', new PluginError('gulp-ts', 'Streaming not supported')); | ||
@@ -50,3 +55,3 @@ } | ||
// property tells the path from cwd to path. | ||
file.relativePath = path.relative(file.cwd, file.path) | ||
file.relativePath = path.relative(file.cwd, file.path); | ||
@@ -58,7 +63,5 @@ // Add file to the list of source files | ||
// Compile all files defined in the files Array | ||
compileFiles = function() { | ||
compileFiles = function () { | ||
// Construct a compile command to be used with the shell TypeScript compiler | ||
var compileCmd = '', | ||
// Files are compiled in this sub-directory | ||
compiledir = 'compiledir', | ||
// Path to the TypeScript binary | ||
@@ -129,3 +132,6 @@ tscPath = path.join(__dirname, 'node_modules/typescript/bin/tsc'), | ||
// Compile | ||
console.log("Compiling.."); | ||
log('Compiling...'); | ||
if (options.verbose) { | ||
log(' compile cmd:', compileCmd); | ||
} | ||
@@ -135,2 +141,5 @@ // shell.exec returns { code: , output: } | ||
shell.exec('node ' + tscPath + compileCmd, { silent: true }, function (code, output) { | ||
if (options.debug) { | ||
log(' tsc output: [', output, ']'); | ||
} | ||
if (code) { | ||
@@ -143,3 +152,3 @@ return that.emit('error', new PluginError('gulp-ts', | ||
// Read from compiledir and replace .ts -> .js | ||
fs.readFile(path.join(__dirname, compiledir, relativePath.replace(".ts", ".js")), function (err, data) { | ||
fs.readFile(path.join(__dirname, compiledir, relativePath.replace('.ts', '.js')), function (err, data) { | ||
// Read failed | ||
@@ -154,3 +163,3 @@ if (err) { | ||
base: base, | ||
path: path.join(cwd, relativePath.replace(".ts", ".js")), | ||
path: path.join(cwd, relativePath.replace('.ts', '.js')), | ||
contents: data | ||
@@ -160,3 +169,3 @@ })); | ||
// Increase counter | ||
filesRead++; | ||
filesRead += 1; | ||
@@ -166,11 +175,15 @@ // Last file has been read, and the directory can be cleaned out | ||
if (options.out || filesRead === files.length) { | ||
rmdir(path.join(__dirname, compiledir), function (err) { | ||
if (err) { | ||
throw err; | ||
} | ||
// Return buffers | ||
if (!options.debug) { | ||
rmdir(path.join(__dirname, compiledir), function (err) { | ||
if (err) { | ||
throw err; | ||
} | ||
// Return buffers | ||
that.emit('end'); | ||
log('Compiling complete.'); | ||
}); | ||
} else { | ||
log('In debug mode, so compiledir was left for inspection.'); | ||
that.emit('end'); | ||
}); | ||
that.emit('end'); | ||
} | ||
} | ||
@@ -181,9 +194,11 @@ }); | ||
// Read output files | ||
if (options.out) { | ||
readSourceFile(options.out, '/', '/'); | ||
} else { | ||
files.forEach(function (file) { | ||
readSourceFile(file.relativePath, file.cwd, file.base); | ||
}); | ||
} | ||
handleDeclaration.call(that, function () { | ||
if (options.out) { | ||
readSourceFile(options.out, '/', '/'); | ||
} else { | ||
files.forEach(function (file) { | ||
readSourceFile(file.relativePath, file.cwd, file.base); | ||
}); | ||
} | ||
}); | ||
}); | ||
@@ -193,2 +208,34 @@ }); | ||
// Handles buffering the declaration file if necessary. | ||
handleDeclaration = function (done) { | ||
var that = this, | ||
srcPath, // relative path to file generated from tsc | ||
cwd = process.cwd(), | ||
fileConfig; | ||
if (options.declaration) { | ||
// NOTE: The declaration file generated by tsc is the same as the out file specified with --out or it seems it is the name of the root source file | ||
if (options.out) { | ||
srcPath = options.out.replace('.js', '.d.ts'); | ||
} else { | ||
srcPath = files[0].path.replace('.ts', '.d.ts'); | ||
} | ||
srcPath = path.relative(cwd, srcPath); | ||
// read in the generated file: | ||
fs.readFile(path.join(__dirname, compiledir, srcPath), function (err, data) { | ||
if (err) { | ||
throw err; | ||
} | ||
// buffer it: | ||
fileConfig = { | ||
base: path.dirname(srcPath), | ||
path: srcPath, | ||
contents: data | ||
}; | ||
that.push(new File(fileConfig)); | ||
done(); | ||
}); | ||
} | ||
done(); | ||
}; | ||
// bufferFiles is executed once per each file, compileFiles is called once at the end | ||
@@ -195,0 +242,0 @@ return through(bufferFiles, compileFiles); |
{ | ||
"name": "gulp-ts", | ||
"preferGlobal": false, | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"author": "Panu Horsmalahti <panu.horsmalahti@iki.fi>", | ||
@@ -18,2 +18,5 @@ "description": "TypeScript compiler Gulp plugin", | ||
}, | ||
"scripts": { | ||
"test": "jslint index.js && gulp --gulpfile ./test/gulpfile.js test" | ||
}, | ||
"keywords": [ | ||
@@ -35,3 +38,5 @@ "gulp", | ||
"analyze": true, | ||
"devDependencies": {}, | ||
"devDependencies": { | ||
"jslint": "^0.5.2" | ||
}, | ||
"license": "MIT", | ||
@@ -38,0 +43,0 @@ "engines": { |
// Simple Gulpfile | ||
var gulp = require('gulp'); | ||
var gutil = require('gulp-util'); | ||
var shell = require('shelljs'); | ||
// Gulp plugins | ||
var ts = require('../index'); | ||
var mocha = require('gulp-mocha'); | ||
gulp.task('default', function(){ | ||
gulp.task('clean', function() { | ||
shell.rm('-rf', 'out'); | ||
}); | ||
gulp.task('default', ['clean'], function(){ | ||
gulp.src(['hello.ts', 'subfolder/hello3.ts']) | ||
@@ -17,3 +23,3 @@ .pipe(ts({ | ||
gulp.task('singlefile', function(){ | ||
gulp.task('singlefile', ['clean'], function(){ | ||
gulp.src(['subfolder/hello4.ts', 'subfolder/hello3.ts', 'hello.ts', 'subfolder/hello2.ts']) | ||
@@ -27,1 +33,52 @@ .pipe(ts({ | ||
}); | ||
gulp.task('debug', ['clean'], function(){ | ||
gulp.src(['hello.ts', 'subfolder/hello3.ts']) | ||
.pipe(ts({ | ||
module: 'commonjs', | ||
removeComments: true, | ||
verbose: true, | ||
debug: true, | ||
})) | ||
.pipe(gulp.dest('out'));; | ||
}); | ||
gulp.task('declaration', ['clean'], function(){ | ||
return gulp.src(['log.ts']) | ||
.pipe(ts({ | ||
module: 'commonjs', | ||
removeComments: true, | ||
verbose: true, | ||
debug: true, | ||
declaration: true | ||
})) | ||
.pipe(gulp.dest('out')); | ||
}); | ||
gulp.task('declaration-singlefile', ['clean'], function(){ | ||
return gulp.src(['log.ts', 'subfolder/hello4.ts']) | ||
.pipe(ts({ | ||
module: 'commonjs', | ||
removeComments: true, | ||
verbose: true, | ||
debug: true, | ||
declaration: true, | ||
out: 'myindex.js' | ||
})) | ||
.pipe(gulp.dest('out')); | ||
}); | ||
gulp.task('subfolder-only', ['clean'], function(){ | ||
gulp.src(['subfolder/hello3.ts']) | ||
.pipe(ts({ | ||
module: 'commonjs' | ||
})) | ||
.pipe(gulp.dest('out'));; | ||
}); | ||
gulp.task('test', function() { | ||
return gulp.src('test.js') | ||
.pipe( | ||
mocha({ reporter: 'nyan' }) | ||
); | ||
}); |
@@ -5,4 +5,7 @@ { | ||
"devDependencies": { | ||
"gulp-mocha": "^0.4.1", | ||
"shelljs": "^0.3.0", | ||
"should": "^3.3.2", | ||
"typescript": "~0.9.5" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
15935
14
360
1
1
2
1