From cbc281b1731454b9f2bf7d2153733691237bb4b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alfred=20W=C3=A4rns=C3=A4ter?= Date: Wed, 4 Aug 2021 09:25:36 +0200 Subject: [PATCH] added terser as compressor --- Objective-J/CFPropertyList.js | 3 ++- Objective-J/Jakefile | 29 +++++++++-------------------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/Objective-J/CFPropertyList.js b/Objective-J/CFPropertyList.js index 6148a1084..6953b1a81 100644 --- a/Objective-J/CFPropertyList.js +++ b/Objective-J/CFPropertyList.js @@ -20,7 +20,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -var fs = require("fs"); var OBJECT_COUNT = 0; @@ -84,6 +83,8 @@ CFPropertyList.stringFromPropertyList = function(/*CFPropertyList*/ aPropertyLis } #ifdef COMMONJS +var fs = require("fs"); + CFPropertyList.readPropertyListFromFile = function(/*String*/ aFilePath) { return CFPropertyList.propertyListFromString(fs.readFileSync(aFilePath, { encoding: "utf8" })); diff --git a/Objective-J/Jakefile b/Objective-J/Jakefile index f978c2508..67f2f3e4c 100644 --- a/Objective-J/Jakefile +++ b/Objective-J/Jakefile @@ -55,7 +55,7 @@ $OBJECTIVEJ_FILES = new FileList("*.js"); $BROWSER_FILES = new FileList($BROWSER_FILE).include($OBJECTIVEJ_FILES); -filedir($BUILD_BROWSER_FILE, $BROWSER_FILES, function(aTask) +filedir($BUILD_BROWSER_FILE, $BROWSER_FILES, async function(aTask) { gcc($BROWSER_FILE, $BUILD_BROWSER_FILE, @@ -70,7 +70,7 @@ filedir($BUILD_LICENSE, [$LICENSE], function() fs.copyFileSync($LICENSE, $BUILD_LICENSE); }); -new FileList("CommonJS/**/*").forEach(function(aFilename) +new FileList("CommonJS/**/*").forEach( async function(aFilename) { // . files should be left out of FileList... if (!fs.lstatSync(aFilename).isFile() || path.basename(aFilename).charAt(0) === ".") @@ -83,7 +83,6 @@ new FileList("CommonJS/**/*").forEach(function(aFilename) if (path.extname(aFilename) !== ".js") { term.stream.print("Copying... \0green(" + aFilename +"\0)"); - //console.log("Copying... \0green(" + aFilename +"\0)"); cp(aFilename, buildFilename); } else @@ -126,24 +125,20 @@ function environmentFlags() }).concat("-DENVIRONMENTS=" + JSON.stringify(environments)); } -function compressor(srcCode) { - return srcCode; +async function compressor(srcCode) { + return (await terser.minify(srcCode)).code; } -var headerText = fs.readFileSync("header.txt", { encoding: "utf8"}); -function gcc(inputFilePath, outputFilePath, flags, compress) +var headerText = fs.readFileSync("header.txt", { encoding: "utf8" }); +async function gcc(inputFilePath, outputFilePath, flags, compress) { term.stream.print("Building... \0green(" + outputFilePath +"\0)"); - //console.log("Building... \0green(" + outputFilePath +"\0)"); var source = fs.readFileSync(inputFilePath, { charset : "utf8" }).toString(); - //console.log(source.charCodeAt); var compilerOptions = compiler.parseGccCompilerFlags(flags.join(" ")); var acornOptions = compilerOptions.acornOptions || (compilerOptions.acornOptions = {}); acornOptions.preprocessGetIncludeFile = function(filePath, isQuoted) { var includeContent = fs.readFileSync(filePath, { charset : "utf8" }).toString(); - //print ("Include content for file '" + filePath + "': " + includeContent); - //print ("Include file '" + filePath + "'"); return {include: includeContent, sourceFile: filePath}; } @@ -162,17 +157,11 @@ function gcc(inputFilePath, outputFilePath, flags, compress) } if (anyErrors) throw "Compilation Error"; - debugger var code = c.code(); - //console.log(code); var contents = headerText + code; - - //console.log("code"); - //console.log(c); - - if (path.extname(inputFilePath) === ".js" && compress) - contents = compressor(contents); - + if (path.extname(inputFilePath) === ".js" && compress) { + contents = await compressor(contents); + } fs.writeFileSync(outputFilePath, contents, { encoding : "utf8" }); }