Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
babel.transformFile(file, {
...options,
babelrc: false, // Keep the file origin smell
}, function (err, result) {
if (err) {
if (err.loc) {
console.log(`${file} syntax error:`)
console.log(codeFrame(readFileSync(file, 'utf8'), err.loc.line, err.loc.column))
}
reject(err)
return
}
writeFileSync(file, result.code)
try {
beautifulFile(file)
} catch (err) {
function loadJavascript (full_path, useBabel, cb) {
if (useBabel && useBabel != '0') {
// console.log('useBabel:true',useBabel)
babel.transformFile(
full_path,
{
presets: ['babel-preset-env', 'babel-preset-stage-0'].map(
require.resolve
),
sourceMaps: !inProd,
sourceRoot: process.cwd(),
sourceFileName: full_path,
babelrc: false,
ast: false,
resolveModuleSource: false
},
function (err, result) {
if (err) return cb(err)
if (inProd) {
result.code = UglifyJS.minify(result.code, { fromString: true }).code
files.forEach(function(filename) {
// Temporarily removed index.js from cjs
babel.transformFile('./lib/' + filename, esConfig, function(err, res) {
if (err) throw err
fs.writeFile('./es/' + filename, res.code, function(err) {
if (err) throw err
})
})
babel.transformFile('./lib/' + filename, cjsConfig, function(err, res) {
if (err) throw err
fs.writeFile('./cjs/' + filename, res.code, function(err) {
if (err) throw err
})
})
})
})
function babelTranspile(pathname, callback) {
if (babelIgnoreRegexes.some(function (re) { return re.test(pathname); })) return callback();
if (!babelCore.canCompile(pathname)) return callback();
var src = path.join(transpilationConfig.root, pathname);
var opts = objectAssign({ sourceFileName: '/source/' + pathname }, transpilationConfig.babelConfig);
babelCore.transformFile(src, opts, callback);
}
function BabelizeBeautifyMinify(inloc, outloc) {
babel.transformFile(inloc, BabelOptions, (err, result) => {
if (err) throw err;
let beautifiedCode = beautify(result.code, {
indent_size: 2
});
fs.writeFile(outloc, beautifiedCode, 'utf8', err => {
if (err) throw err;
console.log('Success -> Crafter.js Babelized!\n');
minjs(outloc).then(out => {
fs.writeFile(outloc.replace('.js', '.min.js'), out, 'utf8', err => {
if (err) throw err;
console.log('Success -> Crafter.js Babelized and Minified!\n')
})
});
});
transpile(pathname, callback) {
pathname = slash(pathname);
if (this.config.babelIgnoreRegexes.some((re) => re.test(pathname))) return callback();
if (!babelCore.canCompile(pathname)) return callback();
const src = path.join(this.config.root, pathname);
const opts = objectAssign({ sourceFileName: '/source/' + pathname }, this.config.babelConfig);
babelCore.transformFile(src, opts, callback);
}
function main() {
const filename = process.argv[2];
const opts = { plugins: [() => ({ visitor })], babelrc: false };
babel.transformFile(filename, opts, (err, result) => {
if (err !== null) {
throw err;
}
console.log(result.code);
});
}
return new Promise((resolve, reject) => {
babel.transformFile(file, conf, function(err, transpiled) {
if (err) {
reject(err)
} else {
resolve(transpiled.code)
}
})
})
}
const code = await new Promise((resolve, reject) => {
transformFile(src, babelOptions, (err, result) => {
if (err) return reject(err)
resolve(result.code)
})
})