Skip to content

Use CDN #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Prepare for CDN delivery
  • Loading branch information
graham-trott committed Apr 13, 2020
commit f7f4c396c501086a6fff5217135d29e8f70e227a
332 changes: 218 additions & 114 deletions easycoder/easycoder-min.js

Large diffs are not rendered by default.

10,590 changes: 7,285 additions & 3,305 deletions easycoder/easycoder.js

Large diffs are not rendered by default.

Binary file modified easycoder/easycoder.zip
Binary file not shown.
1 change: 1 addition & 0 deletions js/easycoder/Compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ const EasyCoder_Compiler = {
this.tokens = tokens;
this.index = 0;
this.program = [];
this.program.script = 0;
this.program.symbols = {};
this.symbols = this.program.symbols;
this.warnings = [];
Expand Down
42 changes: 0 additions & 42 deletions js/easycoder/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -870,46 +870,6 @@ const EasyCoder_Core = {
}
},

Load: {

compile: compiler => {
const lino = compiler.getLino();
const type = compiler.nextToken();
switch (type) {
case `plugin`:
const name = compiler.getNextValue();
compiler.addCommand({
domain: `core`,
keyword: `load`,
lino,
name
});
return true;
}
return false;
},

run: program => {
const command = program[program.pc];
const name = program.getValue(command.name);
switch (command.keyword) {
case `load`:
if (program.checkPlugin(name)) {
return command.pc + 1;
}
EasyCoder_Plugins.getLocalPlugin(
program.getPluginsPath,
name,
program.getPlugin,
program.addLocalPlugin,
function () {
program.run(command.pc + 1);
});
return 0;
}
}
},

Module: {

compile: compiler => {
Expand Down Expand Up @@ -2184,8 +2144,6 @@ const EasyCoder_Core = {
return EasyCoder_Core.Import;
case `index`:
return EasyCoder_Core.Index;
case `load`:
return EasyCoder_Core.Load;
case `module`:
return EasyCoder_Core.Module;
case `multiply`:
Expand Down
126 changes: 15 additions & 111 deletions js/easycoder/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ const EasyCoder = {
name: `EasyCoder_Main`,

domain: {
core: EasyCoder_Core
core: EasyCoder_Core,
browser: EasyCoder_Browser,
json: EasyCoder_Json,
rest: EasyCoder_Rest
},

elementId: 0,
Expand Down Expand Up @@ -144,22 +147,26 @@ const EasyCoder = {
},

require: function(type, src, cb) {
let prefix = ``;
if (src[0] == `/`) {
prefix = window.location + `/`;
}
const element = document.createElement(type === `css` ? `link` : `script`);
switch (type) {
case `css`:
element.type = `text/css`;
element.href = src;
element.href = `${prefix}${src}`;
element.rel = `stylesheet`;
break;
case `js`:
element.type = `text/javascript`;
element.src = src;
element.src = `${prefix}${src}`;
break;
default:
return;
}
element.onload = function () {
console.log(`${Date.now() - EasyCoder.timestamp} ms: Library ${src} loaded`);
console.log(`${Date.now() - EasyCoder.timestamp} ms: Library ${prefix}${src} loaded`);
cb();
};
document.head.appendChild(element);
Expand Down Expand Up @@ -239,10 +246,6 @@ const EasyCoder = {
program.require = this.require;
program.isUndefined = this.isUndefined;
program.isJsonString = this.isJsonString;
program.checkPlugin = this.checkPlugin;
program.getPlugin = this.getPlugin;
program.addLocalPlugin = this.addLocalPlugin;
program.getPluginsPath = this.getPluginsPath;
program.getSymbolRecord = this.getSymbolRecord;
program.verifySymbol = this.verifySymbol;
program.runtimeError = this.runtimeError;
Expand Down Expand Up @@ -325,9 +328,9 @@ const EasyCoder = {
const source = this.tokeniseFile(file);
try {
program = this.compileScript(source, imports, module, parent);
this.scriptIndex++;
if (!program.script) {
program.script = this.scriptIndex;
program.script = EasyCoder.scriptIndex;
EasyCoder.scriptIndex++;
}
const finishCompile = Date.now();
console.log(`${finishCompile - this.timestamp} ms: ` +
Expand Down Expand Up @@ -359,7 +362,8 @@ const EasyCoder = {
}
},

tokenise: function(source) {
start: function(source) {
EasyCoder.scriptIndex = 0;
const script = source.split(`\n`);
if (!this.tokenising) {
try {
Expand All @@ -370,104 +374,4 @@ const EasyCoder = {
this.tokenising = true;
}
},

setPluginCount: function(count) {
EasyCoder.plugins = [];
EasyCoder.pluginCount = count;
},

checkPlugin: function(name) {
return EasyCoder.domain[name];
},

getPlugin: function(name, src, onload) {
if (EasyCoder.domain[name]) {
onload();
return;
}
const script = document.createElement(`script`);
script.type = `text/javascript`;
let location = document.scripts[0].src;
location = location.substring(0, location.indexOf(`/easycoder.js`));
// script.src = `${location}/${src}?ver=${EasyCoder.version}`;
script.src = `${src}?ver=${EasyCoder.version}`;
script.onload = function () {
console.log(`${Date.now() - EasyCoder.timestamp} ms: Plugin ${src} loaded`);
onload();
};
document.head.appendChild(script);
},

addGlobalPlugin: function(name, handler) {
// alert(`Add plugin ${name}`);
EasyCoder.plugins.push({
name,
handler
});
if (EasyCoder.plugins.length === EasyCoder.pluginCount) {
EasyCoder.plugins.forEach(function (plugin) {
EasyCoder.domain[plugin.name] = plugin.handler;
});
EasyCoder.tokenise(EasyCoder.source);
}
},

addLocalPlugin: function(name, handler, callback) {
EasyCoder.domain[name] = handler;
callback();
},

getPluginsPath: function() {
return EasyCoder.pluginsPath;
},

loadPluginJs: function(path) {
console.log(`${Date.now() - this.timestamp} ms: Load ${path}/easycoder/plugins.js`);
const script = document.createElement(`script`);
script.src = `${window.location.origin}${path}/easycoder/plugins.js?ver=${this.version}`;
script.type = `text/javascript`;
script.onload = () => {
EasyCoder_Plugins.getGlobalPlugins(
this.timestamp,
path,
this.setPluginCount,
this.getPlugin,
this.addGlobalPlugin
);
};
script.onerror = () => {
if (path) {
this.loadPluginJs(path.slice(0, path.lastIndexOf(`/`)));
} else {
this.reportError({
message: `Can't load plugins.js`
}, this.program, this.source);
}
};
document.head.appendChild(script);
this.pluginsPath = path;
},

start: function(source) {
this.source = source;
this.scriptIndex = 0;
let pathname = window.location.pathname;
if (pathname.endsWith(`/`)) {
pathname = pathname.slice(0, -1);
} else {
pathname = ``;
}
if (typeof EasyCoder_Plugins === `undefined`) {
this.loadPluginJs(pathname);
} else {
this.pluginsPath = pathname;
EasyCoder_Plugins.getGlobalPlugins(
this.timestamp,
pathname,
this.setPluginCount,
this.getPlugin,
this.addGlobalPlugin
);
}
}
};
5 changes: 4 additions & 1 deletion js/plugins/anagrams.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ const EasyCoder_Anagrams = {

compile: () => {}
}
};
};

// eslint-disable-next-line no-unused-vars
EasyCoder.domain.anagrams = EasyCoder_Anagrams;
5 changes: 4 additions & 1 deletion js/plugins/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,7 @@ const EasyCoder_AWS = {

test: () => {}
}
};
};

// eslint-disable-next-line no-unused-vars
EasyCoder.domain.aws = EasyCoder_AWS;
Loading