mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-03 20:30:04 +02:00
add some packages
This commit is contained in:
185
node_modules/babel-cli/lib/_babel-node.js
generated
vendored
Normal file
185
node_modules/babel-cli/lib/_babel-node.js
generated
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
"use strict";
|
||||
|
||||
var _pathIsAbsolute = require("path-is-absolute");
|
||||
|
||||
var _pathIsAbsolute2 = _interopRequireDefault(_pathIsAbsolute);
|
||||
|
||||
var _commander = require("commander");
|
||||
|
||||
var _commander2 = _interopRequireDefault(_commander);
|
||||
|
||||
var _module2 = require("module");
|
||||
|
||||
var _module3 = _interopRequireDefault(_module2);
|
||||
|
||||
var _util = require("util");
|
||||
|
||||
var _path = require("path");
|
||||
|
||||
var _path2 = _interopRequireDefault(_path);
|
||||
|
||||
var _repl = require("repl");
|
||||
|
||||
var _repl2 = _interopRequireDefault(_repl);
|
||||
|
||||
var _babelCore = require("babel-core");
|
||||
|
||||
var babel = _interopRequireWildcard(_babelCore);
|
||||
|
||||
var _vm = require("vm");
|
||||
|
||||
var _vm2 = _interopRequireDefault(_vm);
|
||||
|
||||
require("babel-polyfill");
|
||||
|
||||
var _babelRegister = require("babel-register");
|
||||
|
||||
var _babelRegister2 = _interopRequireDefault(_babelRegister);
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var program = new _commander2.default.Command("babel-node");
|
||||
|
||||
program.option("-e, --eval [script]", "Evaluate script");
|
||||
program.option("-p, --print [code]", "Evaluate script and print result");
|
||||
program.option("-o, --only [globs]", "");
|
||||
program.option("-i, --ignore [globs]", "");
|
||||
program.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js,.es,.jsx]");
|
||||
program.option("-w, --plugins [string]", "", _babelCore.util.list);
|
||||
program.option("-b, --presets [string]", "", _babelCore.util.list);
|
||||
|
||||
var pkg = require("../package.json");
|
||||
program.version(pkg.version);
|
||||
program.usage("[options] [ -e script | script.js ] [arguments]");
|
||||
program.parse(process.argv);
|
||||
|
||||
(0, _babelRegister2.default)({
|
||||
extensions: program.extensions,
|
||||
ignore: program.ignore,
|
||||
only: program.only,
|
||||
plugins: program.plugins,
|
||||
presets: program.presets
|
||||
});
|
||||
|
||||
var replPlugin = function replPlugin(_ref) {
|
||||
var t = _ref.types;
|
||||
return {
|
||||
visitor: {
|
||||
ModuleDeclaration: function ModuleDeclaration(path) {
|
||||
throw path.buildCodeFrameError("Modules aren't supported in the REPL");
|
||||
},
|
||||
VariableDeclaration: function VariableDeclaration(path) {
|
||||
if (path.node.kind !== "var") {
|
||||
throw path.buildCodeFrameError("Only `var` variables are supported in the REPL");
|
||||
}
|
||||
},
|
||||
Program: function Program(path) {
|
||||
if (path.get("body").some(function (child) {
|
||||
return child.isExpressionStatement();
|
||||
})) return;
|
||||
|
||||
path.pushContainer("body", t.expressionStatement(t.identifier("undefined")));
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var _eval = function _eval(code, filename) {
|
||||
code = code.trim();
|
||||
if (!code) return undefined;
|
||||
|
||||
code = babel.transform(code, {
|
||||
filename: filename,
|
||||
presets: program.presets,
|
||||
plugins: (program.plugins || []).concat([replPlugin])
|
||||
}).code;
|
||||
|
||||
return _vm2.default.runInThisContext(code, {
|
||||
filename: filename
|
||||
});
|
||||
};
|
||||
|
||||
if (program.eval || program.print) {
|
||||
var code = program.eval;
|
||||
if (!code || code === true) code = program.print;
|
||||
|
||||
global.__filename = "[eval]";
|
||||
global.__dirname = process.cwd();
|
||||
|
||||
var _module = new _module3.default(global.__filename);
|
||||
_module.filename = global.__filename;
|
||||
_module.paths = _module3.default._nodeModulePaths(global.__dirname);
|
||||
|
||||
global.exports = _module.exports;
|
||||
global.module = _module;
|
||||
global.require = _module.require.bind(_module);
|
||||
|
||||
var result = _eval(code, global.__filename);
|
||||
if (program.print) {
|
||||
var output = typeof result === "string" ? result : (0, _util.inspect)(result);
|
||||
process.stdout.write(output + "\n");
|
||||
}
|
||||
} else {
|
||||
if (program.args.length) {
|
||||
var args = process.argv.slice(2);
|
||||
|
||||
var i = 0;
|
||||
var ignoreNext = false;
|
||||
args.some(function (arg, i2) {
|
||||
if (ignoreNext) {
|
||||
ignoreNext = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg[0] === "-") {
|
||||
var parsedArg = program[arg.slice(2)];
|
||||
if (parsedArg && parsedArg !== true) {
|
||||
ignoreNext = true;
|
||||
}
|
||||
} else {
|
||||
i = i2;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
args = args.slice(i);
|
||||
|
||||
var filename = args[0];
|
||||
if (!(0, _pathIsAbsolute2.default)(filename)) args[0] = _path2.default.join(process.cwd(), filename);
|
||||
|
||||
process.argv = ["node"].concat(args);
|
||||
process.execArgv.unshift(__filename);
|
||||
|
||||
_module3.default.runMain();
|
||||
} else {
|
||||
replStart();
|
||||
}
|
||||
}
|
||||
|
||||
function replStart() {
|
||||
_repl2.default.start({
|
||||
prompt: "> ",
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
eval: replEval,
|
||||
useGlobal: true
|
||||
});
|
||||
}
|
||||
|
||||
function replEval(code, context, filename, callback) {
|
||||
var err = void 0;
|
||||
var result = void 0;
|
||||
|
||||
try {
|
||||
if (code[0] === "(" && code[code.length - 1] === ")") {
|
||||
code = code.slice(1, -1);
|
||||
}
|
||||
|
||||
result = _eval(code, filename);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
|
||||
callback(err, result);
|
||||
}
|
17
node_modules/babel-cli/lib/babel-external-helpers.js
generated
vendored
Executable file
17
node_modules/babel-cli/lib/babel-external-helpers.js
generated
vendored
Executable file
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
|
||||
var _commander = require("commander");
|
||||
|
||||
var _commander2 = _interopRequireDefault(_commander);
|
||||
|
||||
var _babelCore = require("babel-core");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
_commander2.default.option("-l, --whitelist [whitelist]", "Whitelist of helpers to ONLY include", _babelCore.util.list);
|
||||
_commander2.default.option("-t, --output-type [type]", "Type of output (global|umd|var)", "global");
|
||||
|
||||
_commander2.default.usage("[options]");
|
||||
_commander2.default.parse(process.argv);
|
||||
|
||||
console.log((0, _babelCore.buildExternalHelpers)(_commander2.default.whitelist, _commander2.default.outputType));
|
84
node_modules/babel-cli/lib/babel-node.js
generated
vendored
Executable file
84
node_modules/babel-cli/lib/babel-node.js
generated
vendored
Executable file
@@ -0,0 +1,84 @@
|
||||
"use strict";
|
||||
|
||||
var getV8Flags = require("v8flags");
|
||||
var path = require("path");
|
||||
|
||||
var args = [path.join(__dirname, "_babel-node")];
|
||||
|
||||
var babelArgs = process.argv.slice(2);
|
||||
var userArgs = void 0;
|
||||
|
||||
var argSeparator = babelArgs.indexOf("--");
|
||||
if (argSeparator > -1) {
|
||||
userArgs = babelArgs.slice(argSeparator);
|
||||
babelArgs = babelArgs.slice(0, argSeparator);
|
||||
}
|
||||
|
||||
function getNormalizedV8Flag(arg) {
|
||||
var matches = arg.match(/--(.+)/);
|
||||
|
||||
if (matches) {
|
||||
return "--" + matches[1].replace(/-/g, "_");
|
||||
}
|
||||
|
||||
return arg;
|
||||
}
|
||||
|
||||
getV8Flags(function (err, v8Flags) {
|
||||
babelArgs.forEach(function (arg) {
|
||||
var flag = arg.split("=")[0];
|
||||
|
||||
switch (flag) {
|
||||
case "-d":
|
||||
args.unshift("--debug");
|
||||
break;
|
||||
|
||||
case "debug":
|
||||
case "--debug":
|
||||
case "--debug-brk":
|
||||
case "--inspect":
|
||||
case "--inspect-brk":
|
||||
args.unshift(arg);
|
||||
break;
|
||||
|
||||
case "-gc":
|
||||
args.unshift("--expose-gc");
|
||||
break;
|
||||
|
||||
case "--nolazy":
|
||||
args.unshift(flag);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (v8Flags.indexOf(getNormalizedV8Flag(flag)) >= 0 || arg.indexOf("--trace") === 0) {
|
||||
args.unshift(arg);
|
||||
} else {
|
||||
args.push(arg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
if (argSeparator > -1) {
|
||||
args = args.concat(userArgs);
|
||||
}
|
||||
|
||||
try {
|
||||
var kexec = require("kexec");
|
||||
kexec(process.argv[0], args);
|
||||
} catch (err) {
|
||||
if (err.code !== "MODULE_NOT_FOUND") throw err;
|
||||
|
||||
var child_process = require("child_process");
|
||||
var proc = child_process.spawn(process.argv[0], args, { stdio: "inherit" });
|
||||
proc.on("exit", function (code, signal) {
|
||||
process.on("exit", function () {
|
||||
if (signal) {
|
||||
process.kill(process.pid, signal);
|
||||
} else {
|
||||
process.exit(code);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
97
node_modules/babel-cli/lib/babel/dir.js
generated
vendored
Normal file
97
node_modules/babel-cli/lib/babel/dir.js
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
"use strict";
|
||||
|
||||
var _stringify = require("babel-runtime/core-js/json/stringify");
|
||||
|
||||
var _stringify2 = _interopRequireDefault(_stringify);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var outputFileSync = require("output-file-sync");
|
||||
var slash = require("slash");
|
||||
var path = require("path");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
|
||||
module.exports = function (commander, filenames) {
|
||||
function write(src, relative) {
|
||||
relative = relative.replace(/\.(\w*?)$/, "") + ".js";
|
||||
|
||||
var dest = path.join(commander.outDir, relative);
|
||||
|
||||
var data = util.compile(src, {
|
||||
sourceFileName: slash(path.relative(dest + "/..", src)),
|
||||
sourceMapTarget: path.basename(relative)
|
||||
});
|
||||
if (!commander.copyFiles && data.ignored) return;
|
||||
|
||||
if (data.map && commander.sourceMaps && commander.sourceMaps !== "inline") {
|
||||
var mapLoc = dest + ".map";
|
||||
data.code = util.addSourceMappingUrl(data.code, mapLoc);
|
||||
outputFileSync(mapLoc, (0, _stringify2.default)(data.map));
|
||||
}
|
||||
|
||||
outputFileSync(dest, data.code);
|
||||
util.chmod(src, dest);
|
||||
|
||||
util.log(src + " -> " + dest);
|
||||
}
|
||||
|
||||
function handleFile(src, filename) {
|
||||
if (util.shouldIgnore(src)) return;
|
||||
|
||||
if (util.canCompile(filename, commander.extensions)) {
|
||||
write(src, filename);
|
||||
} else if (commander.copyFiles) {
|
||||
var dest = path.join(commander.outDir, filename);
|
||||
outputFileSync(dest, fs.readFileSync(src));
|
||||
util.chmod(src, dest);
|
||||
}
|
||||
}
|
||||
|
||||
function handle(filename) {
|
||||
if (!fs.existsSync(filename)) return;
|
||||
|
||||
var stat = fs.statSync(filename);
|
||||
|
||||
if (stat.isDirectory(filename)) {
|
||||
var dirname = filename;
|
||||
|
||||
util.readdir(dirname).forEach(function (filename) {
|
||||
var src = path.join(dirname, filename);
|
||||
handleFile(src, filename);
|
||||
});
|
||||
} else {
|
||||
write(filename, filename);
|
||||
}
|
||||
}
|
||||
|
||||
if (!commander.skipInitialBuild) {
|
||||
filenames.forEach(handle);
|
||||
}
|
||||
|
||||
if (commander.watch) {
|
||||
var chokidar = util.requireChokidar();
|
||||
|
||||
filenames.forEach(function (dirname) {
|
||||
var watcher = chokidar.watch(dirname, {
|
||||
persistent: true,
|
||||
ignoreInitial: true,
|
||||
awaitWriteFinish: {
|
||||
stabilityThreshold: 50,
|
||||
pollInterval: 10
|
||||
}
|
||||
});
|
||||
|
||||
["add", "change"].forEach(function (type) {
|
||||
watcher.on(type, function (filename) {
|
||||
var relative = path.relative(dirname, filename) || filename;
|
||||
try {
|
||||
handleFile(filename, relative);
|
||||
} catch (err) {
|
||||
console.error(err.stack);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
188
node_modules/babel-cli/lib/babel/file.js
generated
vendored
Normal file
188
node_modules/babel-cli/lib/babel/file.js
generated
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
"use strict";
|
||||
|
||||
var _stringify = require("babel-runtime/core-js/json/stringify");
|
||||
|
||||
var _stringify2 = _interopRequireDefault(_stringify);
|
||||
|
||||
var _set = require("babel-runtime/core-js/set");
|
||||
|
||||
var _set2 = _interopRequireDefault(_set);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var convertSourceMap = require("convert-source-map");
|
||||
var sourceMap = require("source-map");
|
||||
var slash = require("slash");
|
||||
var path = require("path");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
|
||||
module.exports = function (commander, filenames, opts) {
|
||||
if (commander.sourceMaps === "inline") {
|
||||
opts.sourceMaps = true;
|
||||
}
|
||||
|
||||
var results = [];
|
||||
|
||||
var buildResult = function buildResult() {
|
||||
var map = new sourceMap.SourceMapGenerator({
|
||||
file: path.basename(commander.outFile || "") || "stdout",
|
||||
sourceRoot: opts.sourceRoot
|
||||
});
|
||||
|
||||
var code = "";
|
||||
var offset = 0;
|
||||
|
||||
results.forEach(function (result) {
|
||||
code += result.code + "\n";
|
||||
|
||||
if (result.map) {
|
||||
var consumer = new sourceMap.SourceMapConsumer(result.map);
|
||||
var sources = new _set2.default();
|
||||
|
||||
consumer.eachMapping(function (mapping) {
|
||||
if (mapping.source != null) sources.add(mapping.source);
|
||||
|
||||
map.addMapping({
|
||||
generated: {
|
||||
line: mapping.generatedLine + offset,
|
||||
column: mapping.generatedColumn
|
||||
},
|
||||
source: mapping.source,
|
||||
original: mapping.source == null ? null : {
|
||||
line: mapping.originalLine,
|
||||
column: mapping.originalColumn
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
sources.forEach(function (source) {
|
||||
var content = consumer.sourceContentFor(source, true);
|
||||
if (content !== null) {
|
||||
map.setSourceContent(source, content);
|
||||
}
|
||||
});
|
||||
|
||||
offset = code.split("\n").length - 1;
|
||||
}
|
||||
});
|
||||
|
||||
if (commander.sourceMaps === "inline" || !commander.outFile && commander.sourceMaps) {
|
||||
code += "\n" + convertSourceMap.fromObject(map).toComment();
|
||||
}
|
||||
|
||||
return {
|
||||
map: map,
|
||||
code: code
|
||||
};
|
||||
};
|
||||
|
||||
var output = function output() {
|
||||
var result = buildResult();
|
||||
|
||||
if (commander.outFile) {
|
||||
if (commander.sourceMaps && commander.sourceMaps !== "inline") {
|
||||
var mapLoc = commander.outFile + ".map";
|
||||
result.code = util.addSourceMappingUrl(result.code, mapLoc);
|
||||
fs.writeFileSync(mapLoc, (0, _stringify2.default)(result.map));
|
||||
}
|
||||
|
||||
fs.writeFileSync(commander.outFile, result.code);
|
||||
} else {
|
||||
process.stdout.write(result.code + "\n");
|
||||
}
|
||||
};
|
||||
|
||||
var stdin = function stdin() {
|
||||
var code = "";
|
||||
|
||||
process.stdin.setEncoding("utf8");
|
||||
|
||||
process.stdin.on("readable", function () {
|
||||
var chunk = process.stdin.read();
|
||||
if (chunk !== null) code += chunk;
|
||||
});
|
||||
|
||||
process.stdin.on("end", function () {
|
||||
results.push(util.transform(commander.filename, code, {
|
||||
sourceFileName: "stdin"
|
||||
}));
|
||||
output();
|
||||
});
|
||||
};
|
||||
|
||||
var walk = function walk() {
|
||||
var _filenames = [];
|
||||
results = [];
|
||||
|
||||
filenames.forEach(function (filename) {
|
||||
if (!fs.existsSync(filename)) return;
|
||||
|
||||
var stat = fs.statSync(filename);
|
||||
if (stat.isDirectory()) {
|
||||
var dirname = filename;
|
||||
|
||||
util.readdirFilter(filename).forEach(function (filename) {
|
||||
_filenames.push(path.join(dirname, filename));
|
||||
});
|
||||
} else {
|
||||
_filenames.push(filename);
|
||||
}
|
||||
});
|
||||
|
||||
_filenames.forEach(function (filename) {
|
||||
if (util.shouldIgnore(filename)) return;
|
||||
|
||||
var sourceFilename = filename;
|
||||
if (commander.outFile) {
|
||||
sourceFilename = path.relative(path.dirname(commander.outFile), sourceFilename);
|
||||
}
|
||||
sourceFilename = slash(sourceFilename);
|
||||
|
||||
var data = util.compile(filename, {
|
||||
sourceFileName: sourceFilename
|
||||
});
|
||||
|
||||
if (data.ignored) return;
|
||||
results.push(data);
|
||||
});
|
||||
|
||||
output();
|
||||
};
|
||||
|
||||
var files = function files() {
|
||||
|
||||
if (!commander.skipInitialBuild) {
|
||||
walk();
|
||||
}
|
||||
|
||||
if (commander.watch) {
|
||||
var chokidar = util.requireChokidar();
|
||||
chokidar.watch(filenames, {
|
||||
persistent: true,
|
||||
ignoreInitial: true,
|
||||
awaitWriteFinish: {
|
||||
stabilityThreshold: 50,
|
||||
pollInterval: 10
|
||||
}
|
||||
}).on("all", function (type, filename) {
|
||||
if (util.shouldIgnore(filename) || !util.canCompile(filename, commander.extensions)) return;
|
||||
|
||||
if (type === "add" || type === "change") {
|
||||
util.log(type + " " + filename);
|
||||
try {
|
||||
walk();
|
||||
} catch (err) {
|
||||
console.error(err.stack);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if (filenames.length) {
|
||||
files();
|
||||
} else {
|
||||
stdin();
|
||||
}
|
||||
};
|
129
node_modules/babel-cli/lib/babel/index.js
generated
vendored
Executable file
129
node_modules/babel-cli/lib/babel/index.js
generated
vendored
Executable file
@@ -0,0 +1,129 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
|
||||
var _keys = require("babel-runtime/core-js/object/keys");
|
||||
|
||||
var _keys2 = _interopRequireDefault(_keys);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var fs = require("fs");
|
||||
var commander = require("commander");
|
||||
var kebabCase = require("lodash/kebabCase");
|
||||
var options = require("babel-core").options;
|
||||
var util = require("babel-core").util;
|
||||
var uniq = require("lodash/uniq");
|
||||
var glob = require("glob");
|
||||
|
||||
(0, _keys2.default)(options).forEach(function (key) {
|
||||
var option = options[key];
|
||||
if (option.hidden) return;
|
||||
|
||||
var arg = kebabCase(key);
|
||||
|
||||
if (option.type !== "boolean") {
|
||||
arg += " [" + (option.type || "string") + "]";
|
||||
}
|
||||
|
||||
if (option.type === "boolean" && option.default === true) {
|
||||
arg = "no-" + arg;
|
||||
}
|
||||
|
||||
arg = "--" + arg;
|
||||
|
||||
if (option.shorthand) {
|
||||
arg = "-" + option.shorthand + ", " + arg;
|
||||
}
|
||||
|
||||
var desc = [];
|
||||
if (option.deprecated) desc.push("[DEPRECATED] " + option.deprecated);
|
||||
if (option.description) desc.push(option.description);
|
||||
|
||||
commander.option(arg, desc.join(" "));
|
||||
});
|
||||
|
||||
commander.option("-x, --extensions [extensions]", "List of extensions to compile when a directory has been input [.es6,.js,.es,.jsx]");
|
||||
commander.option("-w, --watch", "Recompile files on changes");
|
||||
commander.option("--skip-initial-build", "Do not compile files before watching");
|
||||
commander.option("-o, --out-file [out]", "Compile all input files into a single file");
|
||||
commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory");
|
||||
commander.option("-D, --copy-files", "When compiling a directory copy over non-compilable files");
|
||||
commander.option("-q, --quiet", "Don't log anything");
|
||||
|
||||
|
||||
var pkg = require("../../package.json");
|
||||
commander.version(pkg.version + " (babel-core " + require("babel-core").version + ")");
|
||||
commander.usage("[options] <files ...>");
|
||||
commander.parse(process.argv);
|
||||
|
||||
if (commander.extensions) {
|
||||
commander.extensions = util.arrayify(commander.extensions);
|
||||
}
|
||||
|
||||
var errors = [];
|
||||
|
||||
var filenames = commander.args.reduce(function (globbed, input) {
|
||||
var files = glob.sync(input);
|
||||
if (!files.length) files = [input];
|
||||
return globbed.concat(files);
|
||||
}, []);
|
||||
|
||||
filenames = uniq(filenames);
|
||||
|
||||
filenames.forEach(function (filename) {
|
||||
if (!fs.existsSync(filename)) {
|
||||
errors.push(filename + " doesn't exist");
|
||||
}
|
||||
});
|
||||
|
||||
if (commander.outDir && !filenames.length) {
|
||||
errors.push("filenames required for --out-dir");
|
||||
}
|
||||
|
||||
if (commander.outFile && commander.outDir) {
|
||||
errors.push("cannot have --out-file and --out-dir");
|
||||
}
|
||||
|
||||
if (commander.watch) {
|
||||
if (!commander.outFile && !commander.outDir) {
|
||||
errors.push("--watch requires --out-file or --out-dir");
|
||||
}
|
||||
|
||||
if (!filenames.length) {
|
||||
errors.push("--watch requires filenames");
|
||||
}
|
||||
}
|
||||
|
||||
if (commander.skipInitialBuild && !commander.watch) {
|
||||
errors.push("--skip-initial-build requires --watch");
|
||||
}
|
||||
|
||||
if (errors.length) {
|
||||
console.error(errors.join(". "));
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
var opts = exports.opts = {};
|
||||
|
||||
(0, _keys2.default)(options).forEach(function (key) {
|
||||
var opt = options[key];
|
||||
if (commander[key] !== undefined && commander[key] !== opt.default) {
|
||||
opts[key] = commander[key];
|
||||
}
|
||||
});
|
||||
|
||||
opts.ignore = util.arrayify(opts.ignore, util.regexify);
|
||||
|
||||
if (opts.only) {
|
||||
opts.only = util.arrayify(opts.only, util.regexify);
|
||||
}
|
||||
|
||||
var fn = void 0;
|
||||
|
||||
if (commander.outDir) {
|
||||
fn = require("./dir");
|
||||
} else {
|
||||
fn = require("./file");
|
||||
}
|
||||
|
||||
fn(commander, filenames, exports.opts);
|
90
node_modules/babel-cli/lib/babel/util.js
generated
vendored
Normal file
90
node_modules/babel-cli/lib/babel/util.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.chmod = chmod;
|
||||
exports.readdirFilter = readdirFilter;
|
||||
exports.shouldIgnore = shouldIgnore;
|
||||
exports.addSourceMappingUrl = addSourceMappingUrl;
|
||||
exports.log = log;
|
||||
exports.transform = transform;
|
||||
exports.compile = compile;
|
||||
exports.requireChokidar = requireChokidar;
|
||||
var commander = require("commander");
|
||||
var defaults = require("lodash/defaults");
|
||||
var readdir = require("fs-readdir-recursive");
|
||||
var index = require("./index");
|
||||
var babel = require("babel-core");
|
||||
var util = require("babel-core").util;
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
|
||||
function chmod(src, dest) {
|
||||
fs.chmodSync(dest, fs.statSync(src).mode);
|
||||
}
|
||||
|
||||
function readdirFilter(filename) {
|
||||
return readdir(filename).filter(function (filename) {
|
||||
return util.canCompile(filename);
|
||||
});
|
||||
}
|
||||
|
||||
exports.readdir = readdir;
|
||||
var canCompile = exports.canCompile = util.canCompile;
|
||||
|
||||
function shouldIgnore(loc) {
|
||||
return util.shouldIgnore(loc, index.opts.ignore, index.opts.only);
|
||||
}
|
||||
|
||||
function addSourceMappingUrl(code, loc) {
|
||||
return code + "\n//# sourceMappingURL=" + path.basename(loc);
|
||||
}
|
||||
|
||||
function log(msg) {
|
||||
if (!commander.quiet) console.log(msg);
|
||||
}
|
||||
|
||||
function transform(filename, code, opts) {
|
||||
opts = defaults(opts || {}, index.opts);
|
||||
opts.filename = filename;
|
||||
|
||||
var result = babel.transform(code, opts);
|
||||
result.filename = filename;
|
||||
result.actual = code;
|
||||
return result;
|
||||
}
|
||||
|
||||
function compile(filename, opts) {
|
||||
try {
|
||||
var code = fs.readFileSync(filename, "utf8");
|
||||
return transform(filename, code, opts);
|
||||
} catch (err) {
|
||||
if (commander.watch) {
|
||||
console.error(toErrorStack(err));
|
||||
return { ignored: true };
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function toErrorStack(err) {
|
||||
if (err._babel && err instanceof SyntaxError) {
|
||||
return err.name + ": " + err.message + "\n" + err.codeFrame;
|
||||
} else {
|
||||
return err.stack;
|
||||
}
|
||||
}
|
||||
|
||||
process.on("uncaughtException", function (err) {
|
||||
console.error(toErrorStack(err));
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
function requireChokidar() {
|
||||
try {
|
||||
return require("chokidar");
|
||||
} catch (err) {
|
||||
console.error("The optional dependency chokidar failed to install and is required for " + "--watch. Chokidar is likely not supported on your platform.");
|
||||
throw err;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user