Skip to content
This repository was archived by the owner on Dec 24, 2020. It is now read-only.

Commit

Permalink
Updated to newest google closure compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffpar committed May 16, 2019
1 parent 4e7d25f commit 6f58827
Show file tree
Hide file tree
Showing 154 changed files with 3,090 additions and 3,007 deletions.
69 changes: 31 additions & 38 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
* copyright
*
* Updates the copyright year in all project files to match the year contained in package.json.
*
* Options
*
* --rebuild will force the "compile" task to recompile the code for any or all the machines, even if the
* compiled code is up-to-date.
*/

"use strict";
Expand All @@ -84,14 +89,17 @@ var gulpConcat = require("gulp-concat");
var gulpForEach = require("gulp-foreach");
var gulpHeader = require("gulp-header");
var gulpReplace = require("gulp-replace");
var gulpClosureCompiler = require('google-closure-compiler-js').gulp();
var gulpClosureCompiler = require('google-closure-compiler').gulp();
var gulpSourceMaps = require('gulp-sourcemaps');
var merge = require('merge-stream');

var fs = require("fs");
var path = require("path");
var pkg = require("./package.json");

var proc = require("./modules/shared/lib/proclib.js");
var args = proc.getArgs();
var argv = args.argv;

/**
* @typedef {Object} MachineConfig
* @property {string} name
Expand All @@ -112,27 +120,11 @@ var pkg = require("./package.json");
* @type {Object.<string,MachineConfig>}
*/
var machines = require("./_data/machines.json");

var sExterns = "";

for (let i = 0; i < machines.shared.externs.length; i++) {
let sContents = "";
try {
sContents = fs.readFileSync(machines.shared.externs[i], "utf8");
} catch(err) {
console.log(err.message);
}
if (sContents) {
if (sExterns) sExterns += '\n';
sExterns += sContents;
}
}

var sSiteHost = "https://www.pcjs.org";
var siteHost = "https://www.pcjs.org";

if (pkg.homepage) {
let match = pkg.homepage.match(/^(https?:\/\/[^/]*)(.*)/);
if (match) sSiteHost = match[1];
if (match) siteHost = match[1];
}

var aMachines = Object.keys(machines);
Expand All @@ -152,34 +144,35 @@ aMachines.forEach(function(machineType) {
machineConfig = machines[machineConfig.alias];
}

let machineDefines = [];
let machineVersion = machineConfig.version || machines.shared.version;
let machineReleaseDir = "./versions/" + machineConfig['folder'] + "/" + machineVersion;
let machineReleaseFile = machineType + ".js";
let machineUncompiledFile = machineType + "-uncompiled.js";
let machineDefines = {};

if (machineConfig.defines) {
for (let i = 0; i < machineConfig.defines.length; i++) {
let define = machineConfig.defines[i];
let define = machineConfig.defines[i], value = undefined;
switch(define) {
case "APPVERSION":
case "VERSION":
machineDefines[define] = machineVersion;
value = machineVersion;
break;
case "SITEURL":
machineDefines[define] = sSiteHost;
value = siteHost;
break;
case "BACKTRACK":
case "DEBUG":
machineDefines[define] = false;
value = false;
break;
case "COMPILED":
case "DEBUGGER":
case "I386":
default:
machineDefines[define] = true;
value = true;
break;
}
machineDefines.push(define + '=' + value);
}
}

Expand All @@ -204,7 +197,7 @@ aMachines.forEach(function(machineType) {
let dstStat = fs.statSync(dstFile);
let srcTime = new Date(srcStat.mtime);
let dstTime = new Date(dstStat.mtime);
if (dstTime < srcTime) aMachinesOutdated.push(machineType);
if (dstTime < srcTime || argv['rebuild']) aMachinesOutdated.push(machineType);
} catch(err) {
// console.log(err.message);
}
Expand All @@ -224,7 +217,7 @@ aMachines.forEach(function(machineType) {
.pipe(gulpReplace(/^[ \t]*(if\s+\(NODE\)\s*|)module\.exports\s*=\s*[^;]*;/gm, ""))
.pipe(gulpReplace(/\/\*\*\s*\*\s*@fileoverview[\s\S]*?\*\/\s*/g, ""))
.pipe(gulpReplace(/[ \t]*if\s*\(NODE\)\s*({[^}]*}|[^\n]*)(\n|$)/gm, ""))
.pipe(gulpReplace(/[ \t]*if\s*\(typeof\s+module\s*!==\s*(['"])undefined\1\)\s*({[^}]*}|[^\n]*)(\n|$)/gm, ""))
.pipe(gulpReplace(/[ \t]*if\s*\(typeof\s+module\s*!==?\s*(['"])undefined\1\)\s*({[^}]*}|[^\n]*)(\n|$)/gm, ""))
.pipe(gulpReplace(/\/\*\*[^@]*@typedef\s*{([A-Z][A-Za-z0-9_<>.]+)}\s*(\S+)\s*([\s\S]*?)\*\//g, function(match, def, type, props) {
let sType = "/** @typedef {", sProps = "";
let reProps = /@property\s*{([^}]*)}\s*(\[|)([^\s\]]+)]?/g, matchProps;
Expand Down Expand Up @@ -254,16 +247,16 @@ aMachines.forEach(function(machineType) {
if (aMachinesOutdated.indexOf(machineType) >= 0) {
stream.pipe(gulpSourceMaps.init())
.pipe(gulpClosureCompiler({
assumeFunctionWrapper: true,
compilationLevel: 'ADVANCED',
defines: machineDefines,
externs: [{src: sExterns}],
warningLevel: 'VERBOSE',
languageIn: "ES6", // this is now the default, just documenting our requirements
languageOut: "ES5", // this is also the default
outputWrapper: '(function(){%output%})()',
jsOutputFile: machineReleaseFile, // NOTE: if we go back to doing debugger/non-debugger releases, this must be updated
createSourceMap: true
assume_function_wrapper: true,
compilation_level: 'ADVANCED',
define: machineDefines,
externs: machines.shared.externs,
warning_level: 'VERBOSE',
language_in: 'ES6', // this is now the default, just documenting our requirements
language_out: 'ES5', // this is also the default
output_wrapper: '(function(){%output%})()',
js_output_file: machineReleaseFile, // NOTE: if we go back to doing debugger/non-debugger releases, this must be updated
create_source_map: true
}))
.pipe(gulpSourceMaps.write('./')) // gulp-sourcemaps automatically adds the sourcemap url comment
.pipe(gulp.dest(machineReleaseDir));
Expand Down
2 changes: 1 addition & 1 deletion modules/c1pjs/lib/computer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

"use strict";

if (NODE) {
if (typeof module !== "undefined") {
var Web = require("../../shared/lib/weblib");
var Component = require("../../shared/lib/component");
}
Expand Down
2 changes: 1 addition & 1 deletion modules/c1pjs/lib/cpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

"use strict";

if (NODE) {
if (typeof module !== "undefined") {
var Str = require("../../shared/lib/strlib");
var Usr = require("../../shared/lib/usrlib");
var Web = require("../../shared/lib/weblib");
Expand Down
2 changes: 1 addition & 1 deletion modules/c1pjs/lib/debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

"use strict";

if (NODE) {
if (typeof module !== "undefined") {
var Str = require("../../shared/lib/strlib");
var Usr = require("../../shared/lib/usrlib");
var Web = require("../../shared/lib/weblib");
Expand Down
2 changes: 1 addition & 1 deletion modules/c1pjs/lib/disk.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

"use strict";

if (NODE) {
if (typeof module !== "undefined") {
var Str = require("../../shared/lib/strlib");
var Web = require("../../shared/lib/weblib");
var Component = require("../../shared/lib/component");
Expand Down
2 changes: 1 addition & 1 deletion modules/c1pjs/lib/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

"use strict";

if (NODE) {
if (typeof module !== "undefined") {
var Str = require("../../shared/lib/strlib");
var Web = require("../../shared/lib/weblib");
var Component = require("../../shared/lib/component");
Expand Down
2 changes: 1 addition & 1 deletion modules/c1pjs/lib/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

"use strict";

if (NODE) {
if (typeof module !== "undefined") {
var Web = require("../../shared/lib/weblib");
var Component = require("../../shared/lib/component");
}
Expand Down
2 changes: 1 addition & 1 deletion modules/c1pjs/lib/ram.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

"use strict";

if (NODE) {
if (typeof module !== "undefined") {
var Web = require("../../shared/lib/weblib");
var Component = require("../../shared/lib/component");
}
Expand Down
2 changes: 1 addition & 1 deletion modules/c1pjs/lib/rom.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

"use strict";

if (NODE) {
if (typeof module !== "undefined") {
var Str = require("../../shared/lib/strlib");
var Web = require("../../shared/lib/weblib");
var DumpAPI = require("../../shared/lib/dumpapi");
Expand Down
2 changes: 1 addition & 1 deletion modules/c1pjs/lib/serial.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

"use strict";

if (NODE) {
if (typeof module !== "undefined") {
var Str = require("../../shared/lib/strlib");
var Web = require("../../shared/lib/weblib");
var Component = require("../../shared/lib/component");
Expand Down
2 changes: 1 addition & 1 deletion modules/c1pjs/lib/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

"use strict";

if (NODE) {
if (typeof module !== "undefined") {
var Web = require("../../shared/lib/weblib");
var Component = require("../../shared/lib/component");
}
Expand Down
1 change: 1 addition & 0 deletions modules/diskdump/lib/diskdump.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"use strict";

if (typeof module != "undefined") { // we can't simply test for NODE, since defines.js hasn't been loaded yet
var NODE = true;
var fs = require("fs");
var path = require("path");
var glob = require("glob");
Expand Down
5 changes: 3 additions & 2 deletions modules/htmlout/lib/htmlout.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ var asFilesNonServed = [
];

/*
* Maximum blog entries increased from 20 to 100 for the new blog format.
* Maximum blog entries increased from 20 to 200 for the new blog format.
*/
var nBlogExcerpts = 100;
var nBlogExcerpts = 200;

/**
* HTMLOut()
Expand Down Expand Up @@ -488,6 +488,7 @@ HTMLOut.filter = function(req, res, next)
sData = sData.replace(/^([ \t]*export\s+default\s+\S+;)/gm, "// $1");
sData = sData.replace(/^([ \t]*var\s+\S+\s*=\s*require\(['"].*?['"]\)[^;]*;)/gm, "// $1");
sData = sData.replace(/^([ \t]*(if\s+\(NODE\)\s*|)module\.exports\s*=\s*[^;]*;)/gm, "// $1");
sData = sData.replace(/^([ \t]*(if\s+\(typeof\s+module\s*!==?\s*['"]undefined['"]\)\s*|)module\.exports\s*=\s*[^;]*;)/gm, "// $1");
res.set("Content-Type", "application/javascript");
res.status(200).send(sData);
}
Expand Down
4 changes: 2 additions & 2 deletions modules/pc6502/lib/bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

"use strict";

if (NODE) {
if (typeof module !== "undefined") {
var str = require("../../shared/lib/strlib");
var usr = require("../../shared/lib/usrlib");
var Component = require("../../shared/lib/component");
Expand Down Expand Up @@ -714,4 +714,4 @@ Bus.prototype.reportError = function(op, addr, size, fQuiet)
return false;
};

if (NODE) module.exports = Bus;
if (typeof module !== "undefined") module.exports = Bus;
4 changes: 2 additions & 2 deletions modules/pc6502/lib/computer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

"use strict";

if (NODE) {
if (typeof module !== "undefined") {
var str = require("../../shared/lib/strlib");
var usr = require("../../shared/lib/usrlib");
var web = require("../../shared/lib/weblib");
Expand Down Expand Up @@ -1630,4 +1630,4 @@ web.onInit(Computer.init);
web.onShow(Computer.show);
web.onExit(Computer.exit);

if (NODE) module.exports = Computer;
if (typeof module !== "undefined") module.exports = Computer;
4 changes: 2 additions & 2 deletions modules/pc6502/lib/cpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

"use strict";

if (NODE) {
if (typeof module !== "undefined") {
var str = require("../../shared/lib/strlib");
var usr = require("../../shared/lib/usrlib");
var Component = require("../../shared/lib/component");
Expand Down Expand Up @@ -1121,4 +1121,4 @@ CPU.prototype.yieldCPU = function()
this.updateCPU();
};

if (NODE) module.exports = CPU;
if (typeof module !== "undefined") module.exports = CPU;
2 changes: 1 addition & 1 deletion modules/pc6502/lib/cpudef.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ var CPUDef = {
}
};

if (NODE) module.exports = CPUDef;
if (typeof module !== "undefined") module.exports = CPUDef;
2 changes: 1 addition & 1 deletion modules/pc6502/lib/cpuops.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

"use strict";

if (NODE) {
if (typeof module !== "undefined") {
var str = require("../../shared/lib/strlib");
var Messages = require("./messages");
var CPUDef = require("./CPUDef");
Expand Down
4 changes: 2 additions & 2 deletions modules/pc6502/lib/cpustate.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

"use strict";

if (NODE) {
if (typeof module !== "undefined") {
var str = require("../../shared/lib/strlib");
var web = require("../../shared/lib/weblib");
var Component = require("../../shared/lib/component");
Expand Down Expand Up @@ -1427,4 +1427,4 @@ CPUState.init = function()
*/
web.onInit(CPUState.init);

if (NODE) module.exports = CPUState;
if (typeof module !== "undefined") module.exports = CPUState;
4 changes: 2 additions & 2 deletions modules/pc6502/lib/debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"use strict";

if (DEBUGGER) {
if (NODE) {
if (typeof module !== "undefined") {
var str = require("../../shared/lib/strlib");
var usr = require("../../shared/lib/usrlib");
var web = require("../../shared/lib/weblib");
Expand Down Expand Up @@ -4371,4 +4371,4 @@ if (DEBUGGER) {

} // endif DEBUGGER

if (NODE) module.exports = Debugger;
if (typeof module !== "undefined") module.exports = Debugger;
2 changes: 1 addition & 1 deletion modules/pc6502/lib/defines.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var PC6502 = {
XMLVERSION: XMLVERSION // shared
};

if (NODE) {
if (typeof module !== "undefined") {
global.APPCLASS = APPCLASS;
global.DEBUGGER = DEBUGGER;
global.BYTEARRAYS = BYTEARRAYS;
Expand Down
4 changes: 2 additions & 2 deletions modules/pc6502/lib/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

"use strict";

if (NODE) {
if (typeof module !== "undefined") {
var str = require("../../shared/lib/strlib");
var web = require("../../shared/lib/weblib");
var Component = require("../../shared/lib/component");
Expand Down Expand Up @@ -78,4 +78,4 @@ Keyboard.init = function()
*/
web.onInit(Keyboard.init);

if (NODE) module.exports = Keyboard;
if (typeof module !== "undefined") module.exports = Keyboard;
4 changes: 2 additions & 2 deletions modules/pc6502/lib/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

"use strict";

if (NODE) {
if (typeof module !== "undefined") {
var str = require("../../shared/lib/strlib");
var Component = require("../../shared/lib/component");
var Messages = require("./messages");
Expand Down Expand Up @@ -845,4 +845,4 @@ if (TYPEDARRAYS) {
];
}

if (NODE) module.exports = Memory;
if (typeof module !== "undefined") module.exports = Memory;
Loading

0 comments on commit 6f58827

Please sign in to comment.