Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (await fs.exists(path.join(basePath, `./ct.libs/${lib}/includes/`))) {
await fs.copy(path.join(basePath, `./ct.libs/${lib}/includes/`), writeDir);
}
}));
/* Global injects, provided by modules */
for (const i in injects) {
buffer = buffer.replace(`/*%${i}%*/`, injects[i]);
}
/* Final touches and script output */
if (currentProject.settings.minifyjs) {
const preamble = '/* Made with ct.js http://ctjs.rocks/ */\n';
const ClosureCompiler = require('google-closure-compiler').jsCompiler;
const compiler = new ClosureCompiler({
/* eslint-disable camelcase */
compilation_level: 'SIMPLE',
use_types_for_optimization: false,
jscomp_off: '*', // Disable warnings to not to booo users
language_out: 'ECMASCRIPT3',
language_in: 'ECMASCRIPT_NEXT',
warning_level: 'QUIET'
/* eslint-enable camelcase */
});
const out = await new Promise((resolve, reject) => {
compiler.run([{
path: path.join(writeDir, '/ct.js'),
src: buffer
}], (exitCode, stdout, stderr) => {
if (stderr && !stdout) {
reject(stderr);
return new Promise((resolve, reject) => {
const closureCompiler = new ClosureCompiler({
// debug: true,
assumeFunctionWrapper: true,
compilationLevel: 'SIMPLE',
languageIn: 'ECMASCRIPT5_STRICT',
languageOut: 'ECMASCRIPT5_STRICT',
env: 'CUSTOM',
rewritePolyfills: false,
applyInputSourceMaps: false,
});
const compilerProcess = closureCompiler.run(
[
{
path: fileName,
src: source,
},
/*!
* node-minify
* Copyright(c) 2011-2019 Rodolphe Stoclin
* MIT Licensed
*/
/**
* Module dependencies.
*/
import compiler from 'google-closure-compiler';
import { utils } from '@node-minify/utils';
/**
* Module variables.
*/
const ClosureCompiler = compiler.jsCompiler;
// the allowed flags, taken from https://github.com/google/closure-compiler
const allowedFlags = [
'angularPass',
'applyInputSourceMaps',
'assumeFunctionWrapper',
'checksOnly',
'compilationLevel',
'createSourceMap',
'dartPass',
'defines',
'env',
'externs',
'exportLocalPropertyDefinitions',
'generateExports',
'languageIn',
const minResult = await new Promise(function (resolve, reject) {
const compilerProcess = new CLOSURE_COMPILER({
compilation_level: 'ADVANCED'
}).run([{
src: source
}], function (exitCode, result, stdErr) {
if (!result) {
console.error(COLORS.red(stdErr));
return reject(new Error(`Closure Compiler failed with exit code: ${exitCode}`));
}
return resolve(result[0]);
});
});
const minify = () => {
//performance('Minification');
info('Starting to minify...');
const uxr = getContent('dist/uxr.js');
const closureCompiler = new ClosureCompiler(flags)
closureCompiler.run([
{
src: uxr,
path: 'dist/uxr.js'
}
], (exitCode, stdOut, stdErr) => {
fs.writeFile('dist/uxr.min.js', stdOut[0].src, 'UTF8', error => {
if (error) {
throw error;
}
info('Minification Complete!');
//performance('Minification');
});
});