Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fs.writeFile(jsFile, bundle, function (err) {
if (err) {
throw err
}
console.log('minify ', jsFile, ' -> ', minFile)
var closureCompiler = new ClosureCompiler({
js: jsFile,
compilation_level: 'SIMPLE',
js_output_file: minFile
})
closureCompiler.run(function (exitCode, stdOut, stdErr) {
fs.readFile(minFile, function (err, data) {
if (err) {
throw err
}
console.log('minified ', minFile)
console.log('stdout: ', stdOut)
console.log('stderr: ', stdErr)
writePage(file, data) // output as div tag here.
})
})
var ClosureCompiler = require('google-closure-compiler').compiler;
var opts = {
js: closurePrepareFilePath,
externs: EXTERNS_CORE,
language_out: 'ECMASCRIPT5',
compilation_level: 'ADVANCED_OPTIMIZATIONS',
assume_function_wrapper: 'true',
warning_level: 'QUIET',
rewrite_polyfills: 'false',
// formatting: 'PRETTY_PRINT',
// debug: 'true'
};
var closureCompiler = new ClosureCompiler(opts);
return new Promise((resolve, reject) => {
closureCompiler.run((exitCode: number, stdOut: string, stdErr: string) => {
if (stdErr) {
console.log('core, closureCompiler exitCode', exitCode, 'stdErr', stdErr);
reject(stdErr);
} else {
var content = stdOut;
var match = /function\(\){"tricks-are-for-closure"}/.exec(content);
if (!match) {
fs.writeFileSync(closurePrepareFilePath, content);
throw 'postClosure: something done changed!'
}
var ClosureCompiler = require('google-closure-compiler').compiler;
var opts = {
js: inputFilePath,
externs: path.join(__dirname, 'externs.js'),
language_out: 'ECMASCRIPT5',
compilation_level: 'ADVANCED_OPTIMIZATIONS',
assume_function_wrapper: 'true',
warning_level: 'VERBOSE',
rewrite_polyfills: 'false',
warning_level: 'QUIET',
// formatting: 'PRETTY_PRINT',
// debug: 'true'
};
var closureCompiler = new ClosureCompiler(opts);
return new Promise(function(resolve, reject) {
console.log(closureCompiler.commandArguments.join(' '));
closureCompiler.run(function(exitCode, stdOut, stdErr) {
if (stdErr) {
console.log('closureCompiler exitCode', exitCode, 'stdErr', stdErr);
reject(stdErr);
} else {
util.writeFile(outputFilePath, stdOut).then(() => {
resolve();
});
}
});
});
async function compile(
extendedOpts: ExtendedCompilerOptions
): Promise<{ stdout: string; stderr: string | undefined }> {
let opts = extendedOpts.compilerOptions;
if (isInAwsLambda()) {
rewriteNodePathForAwsLambda(opts);
}
// Avoid `spawn E2BIG` error for too large arguments
if (opts.js && opts.js.length > 100) {
opts = convertToFlagfile(opts);
}
if (extendedOpts.warningsWhitelist) {
opts.warnings_whitelist_file = createWarningsWhitelistFile(extendedOpts.warningsWhitelist);
}
const compiler = new ClosureCompiler(opts as any);
if (extendedOpts.batch) {
compiler.JAR_PATH = null;
try {
const { getNativeImagePath } = await import("google-closure-compiler/lib/utils");
compiler.javaPath = getNativeImagePath();
} catch {
throw new Error("Installed google-closure-compiler is too old for batch mode.");
}
}
return new Promise((resolve, reject) => {
compiler.run((exitCode: number, stdout: string, stderr?: string) => {
if (exitCode !== 0) {
return reject(new CompilerError(stderr || "No stderr", exitCode));
}
resolve({ stdout, stderr });
});
nailgunPort,
'org.ampproject.AmpCommandLineRunner',
'--',
].concat(compilerOptions);
pluginOptions.platform = ['native']; // nailgun-runner isn't a java binary
initOptions.extraArguments = null; // Already part of nailgun-server
} else {
// For other platforms, or if nailgun is explicitly disabled, use AMP's
// custom runner.jar
closureCompiler.compiler.JAR_PATH = require.resolve(
`../runner/dist/${nailgunPort}/runner.jar`
);
}
}
return closureCompiler.gulp(initOptions)(compilerOptions, pluginOptions);
}
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
'use strict';
/* eslint-env node */
/* eslint-disable no-console */
let gulp = require('gulp');
let compilerPackage = require('google-closure-compiler');
let sourcemaps = require('gulp-sourcemaps');
let rollup = require('rollup-stream');
let rename = require('gulp-rename');
let source = require('vinyl-source-stream');
let buffer = require('vinyl-buffer');
let closureCompiler = compilerPackage.gulp();
let uglify = require('gulp-uglify');
let buble = require('rollup-plugin-buble')
let header = require('gulp-header');
let licenseHeader =
`/*
@license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
`;
'use strict';
/**
*
*/
const closureCompiler = require('google-closure-compiler').gulp({
// extraArguments: ['-Xms2048m']
});
/**
* defaultCompile passes defaults to the closureCompiler
*
* @param {string} outName whatever defaultCompile produces.
*
* @return {object} whatever closureCompiler returns.
*/
var defaultCompile = function(outName) {
if (outName == '') {
throw new Error('Name is required but was not provided')
}
return closureCompiler({
src: ['*.js', '*.css', 'skins/*.css'],
dest: 'google-code-prettify/'
}]
}
},
// grunt-contrib-clean
clean: {
js: ['src/prettify.js', 'src/run_prettify.js', 'loader/*.js'],
css: ['loader/*.css', 'loader/skins/*.css'],
zip: ['distrib/*.zip']
}
});
// load plugins that provide tasks
require('google-closure-compiler').grunt(grunt);
grunt.loadTasks('./tasks');
grunt.loadNpmTasks('grunt-preprocess');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-clean');
// register task aliases
grunt.registerTask('default', [
//'clean',
'preprocess',
'copy:prettify',
'gcc',
'copy:langs',
'aliases',
src: ['*.js', '*.css', 'skins/*.css'],
dest: 'google-code-prettify/'
}]
}
},
// grunt-contrib-clean
clean: {
js: ['src/prettify.js', 'src/run_prettify.js', 'loader/*.js'],
css: ['loader/*.css', 'loader/skins/*.css'],
zip: ['distrib/*.zip']
}
});
// load plugins that provide tasks
require('google-closure-compiler').grunt(grunt);
grunt.loadTasks('./tasks');
grunt.loadNpmTasks('grunt-preprocess');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-clean');
// register task aliases
grunt.registerTask('default', [
//'clean',
'preprocess',
'copy:prettify',
'gcc',
'copy:langs',
'aliases',
'<%= minified %>': '<%= minified %>'
}
},
options: {
stripBanners: true,
banner: '<%= banner %>',
// Allow for the original banner to be stripped
process: function(src, filepath) {
return filepath === 'currency.js' ? src.replace(/^\/\*!/, '/*') : src;
}
}
}
});
require('google-closure-compiler').grunt(grunt);
require('matchdep').filterAll('grunt-*').forEach(grunt.loadNpmTasks);
grunt.registerTask('build', ['closure-compiler', 'concat', 'sync']);
grunt.registerTask('default', ['build']);
};