Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-ts

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-ts - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

test/subfolder/hello2.ts

112

index.js
/*jslint node:true */
/*jslint nomen: true */
// Requires
var map = require('map-stream');
// Native
var fs = require('fs');
var path = require('path');
// Gulp
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;
var File = gutil.File;
var map = require('map-stream');
var through = require('through');
var shell = require('shelljs');
var path = require('path');
var es = require('event-stream');
// rm -rf for Node.js
var rmdir = require('rimraf');
"use strict";

@@ -15,4 +28,3 @@

var tsPlugin = function(options) {
var tscPath = path.join(__dirname, 'node_modules/typescript/bin/tsc'),
bufferFiles,
var bufferFiles,
compileFiles,

@@ -36,4 +48,9 @@ files = [];

// Using path.relative doesn't seem safe, but we need the relative path
// to the 'base', e.g. if we have 'a.ts' and 'b/b.ts' from src, the relative
// property tells the path from cwd to path.
file.relativePath = path.relative(file.cwd, file.path)
// Add file to the list of source files
files.push(file.path);
files.push(file);
};

@@ -43,4 +60,16 @@

compileFiles = function() {
var compileCmd = ' ' + files.join(' ');
// 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
tscPath = path.join(__dirname, 'node_modules/typescript/bin/tsc'),
// ES6 plz
that = this;
// Add source file full paths to the compile command
files.forEach(function (file) {
compileCmd += ' ' + file.path;
});
// Basic options

@@ -69,14 +98,13 @@ if (options.sourceMap) {

// Not supported yet.
// Output file
if (options.out) {
/* if (options.out) {
compileCmd += ' --out ' + options.out;
}
} */
// Output directory
if (options.outDir) {
if (options.out) {
console.log('Warning: Don\'t use out with outDir!');
}
compileCmd += ' --outDir ' + options.outDir;
}
// Compile all files to output directory. After compilation they're read to
// memory and the directory is destroyed. The reason for this 'hack' is that the
// TypeScript compiler doesn't easily support in-memory compilation.
// The use of --outDir for other means doesn't seem necessary.
compileCmd += ' --outDir ' + path.join(__dirname, compiledir);

@@ -93,10 +121,56 @@ // Source root

var compileSuccess = shell.exec('node ' + tscPath + compileCmd)
// Remove compiledir if it already exists
rmdir(path.join(__dirname, compiledir), function (err) {
// Remove failed
if (err) {
throw err;
}
// Compile
console.log("Compiling..");
// shell.exec returns { code: , output: }
// silent is set to true to prevent console output
shell.exec('node ' + tscPath + compileCmd, { silent: true }, function (code, output) {
if (code) {
return that.emit('error', new PluginError('gulp-ts',
'Error during compilation!\n\n' + output));
}
// Read output files
files.forEach(function (file) {
// Read from compiledir and replace .ts -> .js
fs.readFile(path.join(__dirname, compiledir, file.relativePath.replace(".ts", ".js")), function (err, data) {
// Read failed
if (err) {
throw err;
}
// Bug: Gulp flattens the output directory
that.push(new File({
cwd: file.cwd,
base: file.base,
path: path.join(file.cwd, file.relativePath.replace(".ts", ".js")),
contents: data
}));
});
});
// Remove the resulting files
rmdir(path.join(__dirname, compiledir), function (err) {
if (err) {
throw err;
}
// Return buffers
that.emit('end');
});
});
});
};
// bufferFiles is executed once per each file, compileFiles is called once at the end
return through(bufferFiles, compileFiles);
};
module.exports = tsPlugin;
module.exports = tsPlugin;

6

package.json
{
"name": "gulp-ts",
"preferGlobal": false,
"version": "0.0.3",
"version": "0.0.4",
"author": "Panu Horsmalahti <panu.horsmalahti@iki.fi>",

@@ -32,3 +32,5 @@ "description": "TypeScript compiler Gulp plugin",

"analyze": true,
"devDependencies": {},
"devDependencies": {
"rimraf": "~2.2.6"
},
"license": "MIT",

@@ -35,0 +37,0 @@ "engines": {

@@ -6,2 +6,4 @@ gulp-ts

Note: This is in heavy development.
First install gulp-ts

@@ -45,10 +47,8 @@ ```shell

// Specify ECMAScript target version: 'ES3' (default), or 'ES5'
target : 'ES3', // or 'ES5'
target : 'ES3',
// Not supported yet!
// Concatenate and emit output to single file.
out : '', // output file name
// Redirect output structure to the directory.
outDir : '',
// Specifies the location where debugger should locate TypeScript files instead of source locations.

@@ -60,2 +60,2 @@ sourceRoot : '',

}));
```
```

@@ -9,7 +9,8 @@ // Simple Gulpfile

gulp.task('default', function(){
gulp.src('hello.ts')
gulp.src(['hello.ts', 'subfolder/hello3.ts'])
.pipe(ts({
module: 'commonjs',
module: 'amd',
removeComments: true
}));
}))
.pipe(gulp.dest('out'));;
});
// Test file
var foo : string = "bar";
import hello = require("hello2");
import hello = require("subfolder/hello2");
hello.tester();

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc