Create environments #4
9
.gitattributes
vendored
9
.gitattributes
vendored
@ -1,9 +0,0 @@
|
||||
#
|
||||
# https://help.github.com/articles/dealing-with-line-endings/
|
||||
#
|
||||
# Linux start script should use lf
|
||||
/gradlew text eol=lf
|
||||
|
||||
# These are Windows script files and should use crlf
|
||||
*.bat text eol=crlf
|
||||
|
8
.github/workflows/tagged-release.yml
vendored
8
.github/workflows/tagged-release.yml
vendored
@ -18,13 +18,7 @@ jobs:
|
||||
repository: 'java-jscript'
|
||||
- name: "Build"
|
||||
run: |
|
||||
cd java-jscript;
|
||||
ls;
|
||||
mkdir -p dst/classes;
|
||||
rsync -av --exclude='*.java' src/ dst/classes;
|
||||
tsc --outDir dst/classes/me/topchetoeu/jscript/js --declarationDir dst/classes/me/topchetoeu/jscript/dts;
|
||||
find src -name "*.java" | xargs javac -d dst/classes;
|
||||
jar -c -f dst/jscript.jar -e me.topchetoeu.jscript.Main -C dst/classes .
|
||||
cd java-jscript; node ./build.js
|
||||
|
||||
- uses: "marvinpinto/action-automatic-releases@latest"
|
||||
with:
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -5,4 +5,5 @@ out
|
||||
build
|
||||
bin
|
||||
dst
|
||||
/*.js
|
||||
/*.js
|
||||
!/build.js
|
65
build.js
Normal file
65
build.js
Normal file
@ -0,0 +1,65 @@
|
||||
const { spawn } = require('child_process');
|
||||
const fs = require('fs/promises');
|
||||
const pt = require('path');
|
||||
const conf = require('./meta');
|
||||
const { argv } = require('process');
|
||||
|
||||
async function* find(src, dst, wildcard) {
|
||||
const stat = await fs.stat(src);
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
for (const el of await fs.readdir(src)) {
|
||||
for await (const res of find(pt.join(src, el), dst ? pt.join(dst, el) : undefined, wildcard)) yield res;
|
||||
}
|
||||
}
|
||||
else if (stat.isFile() && wildcard(src)) yield dst ? { src, dst } : src;
|
||||
}
|
||||
async function copy(src, dst, wildcard) {
|
||||
const promises = [];
|
||||
|
||||
for await (const el of find(src, dst, wildcard)) {
|
||||
promises.push((async () => {
|
||||
await fs.mkdir(pt.dirname(el.dst), { recursive: true });
|
||||
await fs.copyFile(el.src, el.dst);
|
||||
})());
|
||||
}
|
||||
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
function run(cmd, ...args) {
|
||||
return new Promise((res, rej) => {
|
||||
const proc = spawn(cmd, args, { stdio: 'inherit' });
|
||||
proc.once('exit', code => {
|
||||
if (code === 0) res(code);
|
||||
else rej(new Error(`Process ${cmd} exited with code ${code}.`));
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
async function compileJava() {
|
||||
await fs.writeFile('Metadata.java', (await fs.readFile('src/me/topchetoeu/jscript/Metadata.java')).toString()
|
||||
.replace('${VERSION}', conf.version)
|
||||
.replace('${NAME}', conf.name)
|
||||
.replace('${AUTHOR}', conf.author)
|
||||
);
|
||||
|
||||
const args = ['-d', 'dst/classes', 'Metadata.java'];
|
||||
for await (const path of find('src', undefined, v => v.endsWith('.java') && !v.endsWith('Metadata.java'))) args.push(path);
|
||||
await run('javac', ...args);
|
||||
await fs.rm('Metadata.java');
|
||||
}
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
fs.rm('dst', { recursive: true });
|
||||
await copy('src', 'dst/classes', v => !v.endsWith('.java'));
|
||||
await run('tsc', '-p', 'lib/tsconfig.json', '--outFile', 'dst/classes/me/topchetoeu/jscript/js/core.js'),
|
||||
await compileJava();
|
||||
await run('jar', '-c', '-f', 'dst/jscript.jar', '-e', 'me.topchetoeu.jscript.Main', '-C', 'dst/classes', '.');
|
||||
}
|
||||
catch (e) {
|
||||
if (argv.includes('debug')) throw e;
|
||||
else console.log(e.toString());
|
||||
}
|
||||
})();
|
33
lib/tsconfig.json
Normal file
33
lib/tsconfig.json
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"files": [
|
||||
"lib.d.ts",
|
||||
"modules.ts",
|
||||
"utils.ts",
|
||||
"values/object.ts",
|
||||
"values/symbol.ts",
|
||||
"values/function.ts",
|
||||
"values/errors.ts",
|
||||
"values/string.ts",
|
||||
"values/number.ts",
|
||||
"values/boolean.ts",
|
||||
"values/array.ts",
|
||||
"promise.ts",
|
||||
"map.ts",
|
||||
"set.ts",
|
||||
"regex.ts",
|
||||
"core.ts"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"outFile": "../bin/me/topchetoeu/jscript/js/core.js",
|
||||
// "declarationDir": "",
|
||||
// "declarationDir": "bin/me/topchetoeu/jscript/dts",
|
||||
"target": "ES5",
|
||||
"lib": [],
|
||||
"module": "None",
|
||||
"stripInternal": true,
|
||||
"downlevelIteration": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
}
|
||||
}
|
5
meta.json
Normal file
5
meta.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"version": "0.0.1-alpha",
|
||||
"name": "java-jscript",
|
||||
"author": "TopchetoEU"
|
||||
}
|
@ -50,6 +50,7 @@ public class Main {
|
||||
};
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.out.println(String.format("Running %s v%s by %s", Metadata.NAME, Metadata.VERSION, Metadata.AUTHOR));
|
||||
var in = new BufferedReader(new InputStreamReader(System.in));
|
||||
engine = new Engine();
|
||||
var scope = engine.global().globalChild();
|
||||
|
7
src/me/topchetoeu/jscript/Metadata.java
Normal file
7
src/me/topchetoeu/jscript/Metadata.java
Normal file
@ -0,0 +1,7 @@
|
||||
package me.topchetoeu.jscript;
|
||||
|
||||
public class Metadata {
|
||||
public static final String VERSION = "${VERSION}";
|
||||
public static final String AUTHOR = "${AUTHOR}";
|
||||
public static final String NAME = "${NAME}";
|
||||
}
|
@ -1,61 +1,61 @@
|
||||
package me.topchetoeu.jscript.polyfills;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import me.topchetoeu.jscript.engine.scope.GlobalScope;
|
||||
import me.topchetoeu.jscript.engine.values.ArrayValue;
|
||||
import me.topchetoeu.jscript.engine.values.FunctionValue;
|
||||
import me.topchetoeu.jscript.engine.values.NativeFunction;
|
||||
import me.topchetoeu.jscript.engine.values.Values;
|
||||
|
||||
public class TypescriptEngine extends PolyfillEngine {
|
||||
private FunctionValue ts;
|
||||
|
||||
@Override
|
||||
public FunctionValue compile(GlobalScope scope, String filename, String raw) throws InterruptedException {
|
||||
if (ts != null) {
|
||||
var res = Values.array(ts.call(context(), null, filename, raw));
|
||||
var src = Values.toString(context(), res.get(0));
|
||||
var func = Values.function(res.get(1));
|
||||
|
||||
var compiled = super.compile(scope, filename, src);
|
||||
|
||||
return new NativeFunction(null, (ctx, thisArg, args) -> {
|
||||
return func.call(context(), null, compiled, thisArg, new ArrayValue(args));
|
||||
});
|
||||
}
|
||||
return super.compile(scope, filename, raw);
|
||||
}
|
||||
|
||||
public TypescriptEngine(File root) {
|
||||
super(root);
|
||||
var scope = global().globalChild();
|
||||
|
||||
var decls = new ArrayList<Object>();
|
||||
decls.add(resourceToString("dts/core.d.ts"));
|
||||
decls.add(resourceToString("dts/iterators.d.ts"));
|
||||
decls.add(resourceToString("dts/map.d.ts"));
|
||||
decls.add(resourceToString("dts/promise.d.ts"));
|
||||
decls.add(resourceToString("dts/regex.d.ts"));
|
||||
decls.add(resourceToString("dts/require.d.ts"));
|
||||
decls.add(resourceToString("dts/set.d.ts"));
|
||||
decls.add(resourceToString("dts/values/array.d.ts"));
|
||||
decls.add(resourceToString("dts/values/boolean.d.ts"));
|
||||
decls.add(resourceToString("dts/values/number.d.ts"));
|
||||
decls.add(resourceToString("dts/values/errors.d.ts"));
|
||||
decls.add(resourceToString("dts/values/function.d.ts"));
|
||||
decls.add(resourceToString("dts/values/object.d.ts"));
|
||||
decls.add(resourceToString("dts/values/string.d.ts"));
|
||||
decls.add(resourceToString("dts/values/symbol.d.ts"));
|
||||
|
||||
scope.define("libs", true, ArrayValue.of(decls));
|
||||
scope.define(true, new NativeFunction("init", (el, t, args) -> {
|
||||
ts = Values.function(args[0]);
|
||||
return null;
|
||||
}));
|
||||
|
||||
pushMsg(false, scope, Map.of(), "bootstrap.js", resourceToString("js/bootstrap.js"), null);
|
||||
}
|
||||
}
|
||||
package me.topchetoeu.jscript.polyfills;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import me.topchetoeu.jscript.engine.scope.GlobalScope;
|
||||
import me.topchetoeu.jscript.engine.values.ArrayValue;
|
||||
import me.topchetoeu.jscript.engine.values.FunctionValue;
|
||||
import me.topchetoeu.jscript.engine.values.NativeFunction;
|
||||
import me.topchetoeu.jscript.engine.values.Values;
|
||||
|
||||
public class TypescriptEngine extends PolyfillEngine {
|
||||
private FunctionValue ts;
|
||||
|
||||
@Override
|
||||
public FunctionValue compile(GlobalScope scope, String filename, String raw) throws InterruptedException {
|
||||
if (ts != null) {
|
||||
var res = Values.array(ts.call(context(), null, filename, raw));
|
||||
var src = Values.toString(context(), res.get(0));
|
||||
var func = Values.function(res.get(1));
|
||||
|
||||
var compiled = super.compile(scope, filename, src);
|
||||
|
||||
return new NativeFunction(null, (ctx, thisArg, args) -> {
|
||||
return func.call(context(), null, compiled, thisArg, new ArrayValue(args));
|
||||
});
|
||||
}
|
||||
return super.compile(scope, filename, raw);
|
||||
}
|
||||
|
||||
public TypescriptEngine(File root) {
|
||||
super(root);
|
||||
var scope = global().globalChild();
|
||||
|
||||
var decls = new ArrayList<Object>();
|
||||
decls.add(resourceToString("dts/core.d.ts"));
|
||||
decls.add(resourceToString("dts/iterators.d.ts"));
|
||||
decls.add(resourceToString("dts/map.d.ts"));
|
||||
decls.add(resourceToString("dts/promise.d.ts"));
|
||||
decls.add(resourceToString("dts/regex.d.ts"));
|
||||
decls.add(resourceToString("dts/require.d.ts"));
|
||||
decls.add(resourceToString("dts/set.d.ts"));
|
||||
decls.add(resourceToString("dts/values/array.d.ts"));
|
||||
decls.add(resourceToString("dts/values/boolean.d.ts"));
|
||||
decls.add(resourceToString("dts/values/number.d.ts"));
|
||||
decls.add(resourceToString("dts/values/errors.d.ts"));
|
||||
decls.add(resourceToString("dts/values/function.d.ts"));
|
||||
decls.add(resourceToString("dts/values/object.d.ts"));
|
||||
decls.add(resourceToString("dts/values/string.d.ts"));
|
||||
decls.add(resourceToString("dts/values/symbol.d.ts"));
|
||||
|
||||
scope.define("libs", true, ArrayValue.of(decls));
|
||||
scope.define(true, new NativeFunction("init", (el, t, args) -> {
|
||||
ts = Values.function(args[0]);
|
||||
return null;
|
||||
}));
|
||||
|
||||
pushMsg(false, scope, Map.of(), "bootstrap.js", resourceToString("js/bootstrap.js"), null);
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
{
|
||||
"files": [
|
||||
"lib/lib.d.ts",
|
||||
"lib/modules.ts",
|
||||
"lib/utils.ts",
|
||||
"lib/values/object.ts",
|
||||
"lib/values/symbol.ts",
|
||||
"lib/values/function.ts",
|
||||
"lib/values/errors.ts",
|
||||
"lib/values/string.ts",
|
||||
"lib/values/number.ts",
|
||||
"lib/values/boolean.ts",
|
||||
"lib/values/array.ts",
|
||||
"lib/promise.ts",
|
||||
"lib/map.ts",
|
||||
"lib/set.ts",
|
||||
"lib/regex.ts",
|
||||
"lib/core.ts"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"outFile": "bin/me/topchetoeu/jscript/js/core.js",
|
||||
// "declarationDir": "",
|
||||
// "declarationDir": "bin/me/topchetoeu/jscript/dts",
|
||||
"target": "ES5",
|
||||
"lib": [],
|
||||
"module": "None",
|
||||
"stripInternal": true,
|
||||
"downlevelIteration": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user