mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 23:12:19 +00:00
Also create an 'index.js' to load the module when running asinit
This commit is contained in:
parent
59a22c1842
commit
3b50720603
24
bin/asinit
24
bin/asinit
@ -35,6 +35,7 @@ const entryFile = path.join(assemblyDir, "index.ts");
|
|||||||
const buildDir = path.join(projectDir, "build");
|
const buildDir = path.join(projectDir, "build");
|
||||||
const gitignoreFile = path.join(buildDir, ".gitignore");
|
const gitignoreFile = path.join(buildDir, ".gitignore");
|
||||||
const packageFile = path.join(projectDir, "package.json");
|
const packageFile = path.join(projectDir, "package.json");
|
||||||
|
const indexFile = path.join(projectDir, "index.js");
|
||||||
|
|
||||||
console.log([
|
console.log([
|
||||||
"Version: " + version,
|
"Version: " + version,
|
||||||
@ -59,6 +60,9 @@ console.log([
|
|||||||
chalk.cyan(" ./build/.gitignore"),
|
chalk.cyan(" ./build/.gitignore"),
|
||||||
" Git configuration that excludes compiled binaries from source control.",
|
" Git configuration that excludes compiled binaries from source control.",
|
||||||
"",
|
"",
|
||||||
|
chalk.cyan(" ./index.js"),
|
||||||
|
" Main file loading the WebAssembly module and exporting its exports.",
|
||||||
|
"",
|
||||||
chalk.cyan(" ./package.json"),
|
chalk.cyan(" ./package.json"),
|
||||||
" Package info containing the necessary commands to compile to WebAssembly.",
|
" Package info containing the necessary commands to compile to WebAssembly.",
|
||||||
"",
|
"",
|
||||||
@ -80,6 +84,7 @@ rl.question(chalk.white.bold("Do you want to proceed?") + " [Y/n] ", answer => {
|
|||||||
ensureBuildDirectory();
|
ensureBuildDirectory();
|
||||||
ensureGitignore();
|
ensureGitignore();
|
||||||
ensurePackageJson();
|
ensurePackageJson();
|
||||||
|
ensureIndexJs();
|
||||||
console.log([
|
console.log([
|
||||||
chalk.green("Done!"),
|
chalk.green("Done!"),
|
||||||
"",
|
"",
|
||||||
@ -192,6 +197,7 @@ function ensureGitignore() {
|
|||||||
if (!fs.existsSync(gitignoreFile)) {
|
if (!fs.existsSync(gitignoreFile)) {
|
||||||
fs.writeFileSync(gitignoreFile, [
|
fs.writeFileSync(gitignoreFile, [
|
||||||
"*.wasm",
|
"*.wasm",
|
||||||
|
"*.wasm.map",
|
||||||
"*.asm.js"
|
"*.asm.js"
|
||||||
].join("\n") + "\n");
|
].join("\n") + "\n");
|
||||||
console.log(chalk.green(" Created: ") + gitignoreFile);
|
console.log(chalk.green(" Created: ") + gitignoreFile);
|
||||||
@ -233,3 +239,21 @@ function ensurePackageJson() {
|
|||||||
}
|
}
|
||||||
console.log();
|
console.log();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ensureIndexJs() {
|
||||||
|
console.log("- Making sure that 'index.js' exists...");
|
||||||
|
if (!fs.existsSync(indexFile)) {
|
||||||
|
fs.writeFileSync(indexFile, [
|
||||||
|
"const fs = require(\"fs\");",
|
||||||
|
"const compiled = new WebAssembly.Module(fs.readFileSync(__dirname + \"/build/optimized.wasm\"));",
|
||||||
|
"const imports = {};",
|
||||||
|
"Object.defineProperty(module, \"exports\", {",
|
||||||
|
" get: () => new WebAssembly.Instance(compiled, imports).exports",
|
||||||
|
"});",
|
||||||
|
].join("\n") + "\n");
|
||||||
|
console.log(chalk.green(" Created: ") + indexFile);
|
||||||
|
} else {
|
||||||
|
console.log(chalk.yellow(" Exists: ") + indexFile);
|
||||||
|
}
|
||||||
|
console.log();
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user