| Server IP : 68.183.124.220 / Your IP : 216.73.216.141 Web Server : Apache/2.4.18 (Ubuntu) System : Linux Sandbox-A 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64 User : gavin ( 1000) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/gavin/workspace/happymandarin/node_modules/gulp-ng-annotate/ |
Upload File : |
"use strict";
var gutil = require("gulp-util");
var through = require("through2");
var ngAnnotate = require("ng-annotate");
var applySourceMap = require("vinyl-sourcemaps-apply");
var merge = require("merge");
var BufferStreams = require("bufferstreams");
var PLUGIN_NAME = "gulp-ng-annotate";
// Function which handle logic for both stream and buffer modes.
function transform(file, input, opts) {
var res = ngAnnotate(input.toString(), opts);
if (res.errors) {
var filename = "";
if (file.path) {
filename = file.relative + ": ";
}
throw new gutil.PluginError(PLUGIN_NAME, filename + res.errors.join("\n"));
}
if (opts.map && file.sourceMap) {
var sourceMap = JSON.parse(res.map);
sourceMap.file = file.relative;
applySourceMap(file, sourceMap);
}
return new Buffer(res.src);
}
module.exports = function (options) {
options = options || {};
if (!options.remove) {
options = merge({add: true}, options);
};
return through.obj(function (file, enc, done) {
// When null just pass through.
if (file.isNull()) {
this.push(file);
return done();
}
var opts = merge({map: !!file.sourceMap}, options);
if (opts.map) {
if (typeof opts.map === "boolean") {
opts.map = {};
}
if (file.path) {
opts.map.inFile = file.relative;
}
}
// Buffer input.
if (file.isBuffer()) {
try {
file.contents = transform(file, file.contents, opts);
} catch (e) {
this.emit("error", e);
return done();
}
// Dealing with stream input.
} else {
file.contents = file.contents.pipe(new BufferStreams(function(err, buf, cb) {
if (err) return cb(new gutil.PluginError(PLUGIN_NAME, err));
try {
var transformed = transform(file, buf, opts)
} catch (e) {
return cb(e);
}
cb(null, transformed);
}));
}
this.push(file);
done();
});
};