remove typescript
This commit is contained in:
parent
3f826cc85d
commit
d1937fdb63
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
!/src
|
!/src
|
||||||
!/src/**/*
|
!/src/**/*
|
||||||
/src/assets/js/ts.js
|
|
||||||
|
|
||||||
!/doc
|
!/doc
|
||||||
!/doc/**/*
|
!/doc/**/*
|
||||||
@ -10,7 +9,6 @@
|
|||||||
!/tests
|
!/tests
|
||||||
!/tests/**/*
|
!/tests/**/*
|
||||||
|
|
||||||
|
|
||||||
!/.github
|
!/.github
|
||||||
!/.github/**/*
|
!/.github/**/*
|
||||||
|
|
||||||
|
127
build.js
127
build.js
@ -38,84 +38,6 @@ function run(suppressOutput, cmd, ...args) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downloadTypescript(outFile) {
|
|
||||||
try {
|
|
||||||
// Import the required libraries, without the need of a package.json
|
|
||||||
console.log('Importing modules...');
|
|
||||||
await run(true, 'npm', 'i', 'tar', 'zlib', 'uglify-js');
|
|
||||||
await fs.mkdir(pt.dirname(outFile), { recursive: true });
|
|
||||||
await fs.mkdir('tmp', { recursive: true });
|
|
||||||
|
|
||||||
const tar = require('tar');
|
|
||||||
const zlib = require('zlib');
|
|
||||||
const { minify } = await import('uglify-js');
|
|
||||||
|
|
||||||
// Download the package.json file of typescript
|
|
||||||
const packageDesc = await (await fetch('https://registry.npmjs.org/typescript/latest')).json();
|
|
||||||
const url = packageDesc.dist.tarball;
|
|
||||||
|
|
||||||
console.log('Extracting typescript...');
|
|
||||||
await new Promise(async (res, rej) => Readable.fromWeb((await fetch(url)).body)
|
|
||||||
.pipe(zlib.createGunzip())
|
|
||||||
.pipe(tar.x({ cwd: 'tmp', filter: v => v === 'package/lib/typescript.js' }))
|
|
||||||
.on('end', res)
|
|
||||||
.on('error', rej)
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log('Compiling typescript to ES5...');
|
|
||||||
|
|
||||||
const ts = require('./tmp/package/lib/typescript');
|
|
||||||
const program = ts.createProgram([ 'tmp/package/lib/typescript.js' ], {
|
|
||||||
outFile: "tmp/typescript-es5.js",
|
|
||||||
target: ts.ScriptTarget.ES5,
|
|
||||||
module: ts.ModuleKind.None,
|
|
||||||
downlevelIteration: true,
|
|
||||||
allowJs: true,
|
|
||||||
});
|
|
||||||
program.emit();
|
|
||||||
|
|
||||||
console.log('Minifying typescript...');
|
|
||||||
|
|
||||||
const minified = minify((await fs.readFile('tmp/typescript-es5.js')).toString());
|
|
||||||
// const minified = { code: (await fs.readFile('tmp/typescript-es5.js')).toString() };
|
|
||||||
if (minified.error) throw minified.error;
|
|
||||||
|
|
||||||
// Patch unsupported regex syntax
|
|
||||||
minified.code = minified.code.replaceAll('[-/\\\\^$*+?.()|[\\]{}]', '[-/\\\\^$*+?.()|\\[\\]{}]');
|
|
||||||
|
|
||||||
const stream = await fs.open(outFile, 'w');
|
|
||||||
|
|
||||||
// Write typescript's license
|
|
||||||
await stream.write(new TextEncoder().encode(`
|
|
||||||
/*! *****************************************************************************
|
|
||||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
||||||
this file except in compliance with the License. You may obtain a copy of the
|
|
||||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
||||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
||||||
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
||||||
|
|
||||||
See the Apache Version 2.0 License for specific language governing permissions
|
|
||||||
and limitations under the License.
|
|
||||||
|
|
||||||
The following is a minified version of the unmodified Typescript 5.2
|
|
||||||
***************************************************************************** */
|
|
||||||
`));
|
|
||||||
|
|
||||||
await stream.write(minified.code);
|
|
||||||
console.log('Typescript bundling done!');
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
// Clean up all stuff left from typescript bundling
|
|
||||||
await fs.rm('tmp', { recursive: true, force: true });
|
|
||||||
await fs.rm('package.json');
|
|
||||||
await fs.rm('package-lock.json');
|
|
||||||
await fs.rm('node_modules', { recursive: true });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async function compileJava(conf) {
|
async function compileJava(conf) {
|
||||||
try {
|
try {
|
||||||
await fs.writeFile('Metadata.java', (await fs.readFile('src/me/topchetoeu/jscript/common/Metadata.java')).toString()
|
await fs.writeFile('Metadata.java', (await fs.readFile('src/me/topchetoeu/jscript/common/Metadata.java')).toString()
|
||||||
@ -150,40 +72,31 @@ async function jar(conf, project, mainClass) {
|
|||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
if (argv[2] === 'init-ts') {
|
const conf = {
|
||||||
await downloadTypescript('src/me/topchetoeu/jscript/utils/assets/js/ts.js');
|
name: "java-jscript",
|
||||||
}
|
author: "TopchetoEU",
|
||||||
else {
|
javahome: "",
|
||||||
const conf = {
|
version: argv[3]
|
||||||
name: "java-jscript",
|
};
|
||||||
author: "TopchetoEU",
|
|
||||||
javahome: "",
|
|
||||||
version: argv[3]
|
|
||||||
};
|
|
||||||
|
|
||||||
if (conf.version.startsWith('refs/tags/')) conf.version = conf.version.substring(10);
|
if (conf.version.startsWith('refs/tags/')) conf.version = conf.version.substring(10);
|
||||||
if (conf.version.startsWith('v')) conf.version = conf.version.substring(1);
|
if (conf.version.startsWith('v')) conf.version = conf.version.substring(1);
|
||||||
|
|
||||||
try { await fs.rm('dst', { recursive: true }); } catch {}
|
try { await fs.rm('dst', { recursive: true }); } catch {}
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
(async () => {
|
copy('src', 'dst/classes', v => !v.endsWith('.java')),
|
||||||
await copy('src', 'dst/classes', v => !v.endsWith('.java'));
|
compileJava(conf),
|
||||||
await downloadTypescript('dst/classes/me/topchetoeu/jscript/utils/assets/js/ts.js');
|
]);
|
||||||
})(),
|
|
||||||
compileJava(conf),
|
|
||||||
]);
|
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
jar(conf, 'me.topchetoeu.jscript.common'),
|
jar(conf, 'me.topchetoeu.jscript.common'),
|
||||||
jar(conf, 'me.topchetoeu.jscript.core'),
|
jar(conf, 'me.topchetoeu.jscript.core'),
|
||||||
jar(conf, 'me.topchetoeu.jscript.lib'),
|
jar(conf, 'me.topchetoeu.jscript.utils'),
|
||||||
jar(conf, 'me.topchetoeu.jscript.utils'),
|
jar(conf, 'me.topchetoeu.jscript', 'me.topchetoeu.jscript.utils.JScriptRepl'),
|
||||||
jar(conf, 'me.topchetoeu.jscript', 'me.topchetoeu.jscript.utils.JScriptRepl'),
|
]);
|
||||||
]);
|
|
||||||
|
|
||||||
console.log('Done!');
|
console.log('Done!');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
if (argv[2] === 'debug') throw e;
|
if (argv[2] === 'debug') throw e;
|
||||||
|
@ -46,18 +46,15 @@ public class JScriptRepl {
|
|||||||
try {
|
try {
|
||||||
for (var arg : args) {
|
for (var arg : args) {
|
||||||
try {
|
try {
|
||||||
if (arg.equals("--ts")) initTypescript();
|
var file = Path.of(arg);
|
||||||
else {
|
var raw = Files.readString(file);
|
||||||
var file = Path.of(arg);
|
var res = engine.pushMsg(
|
||||||
var raw = Files.readString(file);
|
false, environment,
|
||||||
var res = engine.pushMsg(
|
Filename.fromFile(file.toFile()),
|
||||||
false, environment,
|
raw, null
|
||||||
Filename.fromFile(file.toFile()),
|
).await();
|
||||||
raw, null
|
Values.printValue(null, res);
|
||||||
).await();
|
System.out.println();
|
||||||
Values.printValue(null, res);
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (EngineException e) { Values.printError(e, null); }
|
catch (EngineException e) { Values.printError(e, null); }
|
||||||
}
|
}
|
||||||
@ -128,36 +125,6 @@ public class JScriptRepl {
|
|||||||
engineTask = engine.start();
|
engineTask = engine.start();
|
||||||
debugTask = debugServer.start(new InetSocketAddress("127.0.0.1", 9229), true);
|
debugTask = debugServer.start(new InetSocketAddress("127.0.0.1", 9229), true);
|
||||||
}
|
}
|
||||||
private static void initTypescript() throws IOException {
|
|
||||||
var tsEnv = Internals.apply(new Environment());
|
|
||||||
var bsEnv = Internals.apply(new Environment());
|
|
||||||
|
|
||||||
try {
|
|
||||||
tsEnv.global.define(null, "module", false, new ObjectValue());
|
|
||||||
|
|
||||||
engine.pushMsg(
|
|
||||||
false, tsEnv,
|
|
||||||
new Filename("jscript", "ts.js"),
|
|
||||||
Reading.resourceToString("me/topchetoeu/jscript/utils/assets/js/ts.js"), null
|
|
||||||
).await();
|
|
||||||
System.out.println("Loaded typescript!");
|
|
||||||
|
|
||||||
var typescript = tsEnv.global.get(new Context(engine, bsEnv), "ts");
|
|
||||||
var libs = new ArrayValue(null, Reading.resourceToString("me/topchetoeu/jscript/utils/assets/js/lib.d.ts"));
|
|
||||||
|
|
||||||
engine.pushMsg(
|
|
||||||
false, bsEnv,
|
|
||||||
new Filename("jscript", "bootstrap.js"), Reading.resourceToString("me/topchetoeu/jscript/utils/assets/js/bootstrap.js"), null,
|
|
||||||
typescript, new EnvironmentLib(environment), libs
|
|
||||||
).await();
|
|
||||||
}
|
|
||||||
catch (EngineException e) {
|
|
||||||
Values.printError(e, "(while initializing TS)");
|
|
||||||
}
|
|
||||||
|
|
||||||
bsEnv.add(Environment.HIDE_STACK, true);
|
|
||||||
tsEnv.add(Environment.HIDE_STACK, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
System.out.println(String.format("Running %s v%s by %s", Metadata.name(), Metadata.version(), Metadata.author()));
|
System.out.println(String.format("Running %s v%s by %s", Metadata.name(), Metadata.version(), Metadata.author()));
|
||||||
|
Loading…
Reference in New Issue
Block a user