mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-26 07:22:21 +00:00
Improve bundled asc example a bit, see #25
This commit is contained in:
parent
60728c38fd
commit
08d9ba12aa
@ -44,6 +44,7 @@ function main(argv, options, callback) {
|
|||||||
const readFile = options.readFile || readFileNode;
|
const readFile = options.readFile || readFileNode;
|
||||||
const writeFile = options.writeFile || writeFileNode;
|
const writeFile = options.writeFile || writeFileNode;
|
||||||
const listFiles = options.listFiles || listFilesNode;
|
const listFiles = options.listFiles || listFilesNode;
|
||||||
|
const stats = options.stats || createStats();
|
||||||
|
|
||||||
// All of the above must be specified in browser environments
|
// All of the above must be specified in browser environments
|
||||||
if (!stdout) throw Error("'options.stdout' must be specified");
|
if (!stdout) throw Error("'options.stdout' must be specified");
|
||||||
@ -54,9 +55,6 @@ function main(argv, options, callback) {
|
|||||||
if (listFiles === listFilesNode) throw Error("'options.listFiles' must be specified");
|
if (listFiles === listFilesNode) throw Error("'options.listFiles' must be specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record compilation times
|
|
||||||
const stats = createStats();
|
|
||||||
|
|
||||||
const args = parseArguments(argv);
|
const args = parseArguments(argv);
|
||||||
const indent = 24;
|
const indent = 24;
|
||||||
|
|
||||||
@ -507,6 +505,8 @@ function createStats() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.createStats = createStats;
|
||||||
|
|
||||||
if (!process.hrtime)
|
if (!process.hrtime)
|
||||||
process.hrtime = require("browser-process-hrtime");
|
process.hrtime = require("browser-process-hrtime");
|
||||||
|
|
||||||
|
@ -2,30 +2,40 @@ var asc = require("../dist/asc.js");
|
|||||||
|
|
||||||
var stdout = asc.createMemoryStream();
|
var stdout = asc.createMemoryStream();
|
||||||
var stderr = asc.createMemoryStream();
|
var stderr = asc.createMemoryStream();
|
||||||
|
var stats = asc.createStats();
|
||||||
|
|
||||||
process.exitCode = asc.main([
|
process.exitCode = asc.main([
|
||||||
"test.ts"
|
"test.ts",
|
||||||
|
"--validate",
|
||||||
|
"--optimize",
|
||||||
|
"--measure",
|
||||||
|
"--textFile", // -> stdout
|
||||||
|
"--binaryFile", "test.wasm",
|
||||||
|
"--sourceMap"
|
||||||
], {
|
], {
|
||||||
stdout: stdout,
|
stdout: stdout,
|
||||||
stderr: stderr,
|
stderr: stderr,
|
||||||
|
stats: stats,
|
||||||
readFile: function(filename) {
|
readFile: function(filename) {
|
||||||
console.log("readFile: " + filename);
|
console.log("<< readFile: " + filename);
|
||||||
if (filename === "/test.ts") { // sic: browser path
|
if (filename === "/test.ts") { // sic: browser path
|
||||||
return "export function foo(): void {}";
|
return "export function foo(): void {}";
|
||||||
}
|
}
|
||||||
throw Error("File not found: " + filename);
|
throw Error("File not found: " + filename);
|
||||||
},
|
},
|
||||||
writeFile: function(filename, contents) {
|
writeFile: function(filename, contents) {
|
||||||
console.log("writeFile: " + filename);
|
console.log(">> writeFile: " + filename + " (" + contents.length + " bytes)");
|
||||||
},
|
},
|
||||||
listFiles: function(dirname) {
|
listFiles: function(dirname) {
|
||||||
console.log("listFiles: " + dirname);
|
console.log("<< listFiles: " + dirname);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("stdout >>>");
|
console.log(">> stdout >>");
|
||||||
console.log(stdout.toString());
|
console.log(stdout.toString());
|
||||||
|
|
||||||
console.log("stderr >>>");
|
console.log(">> stderr >>");
|
||||||
console.error(stderr.toString());
|
console.error(stderr.toString());
|
||||||
|
|
||||||
|
console.log(">> stats >>", stats);
|
||||||
|
@ -68,6 +68,7 @@ const bin = {
|
|||||||
const libFiles = require("glob").sync("**/*.ts", { cwd: libDir });
|
const libFiles = require("glob").sync("**/*.ts", { cwd: libDir });
|
||||||
const lib = {};
|
const lib = {};
|
||||||
libFiles.forEach(file => {
|
libFiles.forEach(file => {
|
||||||
|
// console.log("bundling '(lib)/" + file + "'");
|
||||||
var source = fs.readFileSync(path.join(libDir, file), { encoding: "utf8" });
|
var source = fs.readFileSync(path.join(libDir, file), { encoding: "utf8" });
|
||||||
lib["(lib)/" + file.replace(/\.ts$/, "")] = JSON.stringify(source);
|
lib["(lib)/" + file.replace(/\.ts$/, "")] = JSON.stringify(source);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user