From 698b2062d01b4a019152304c5a2f53e0692b45e5 Mon Sep 17 00:00:00 2001 From: romdotdog <70765447+romdotdog@users.noreply.github.com> Date: Mon, 19 Jul 2021 17:06:20 -0400 Subject: [PATCH 01/10] add web option to asinitOptions --- bin/asinit | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bin/asinit b/bin/asinit index 3722a84168..c98bf50c9f 100755 --- a/bin/asinit +++ b/bin/asinit @@ -47,6 +47,12 @@ const asinitOptions = { "description": "Answers all questions with their default option for non-interactive usage.", "type": "b", "alias": "y" + }, + "web": { + "category": "General", + "description": "Uses a template for web development rather than NodeJS development.", + "type": "b", + "alias": "w" } }; @@ -54,6 +60,9 @@ const cliOptions = options.parse(process.argv.slice(2), asinitOptions); if (cliOptions.options.help || cliOptions.arguments.length === 0) printHelp(); +const useWeb = cliOptions.options.web; +const useNode = !useWeb; + function printHelp() { console.log([ "Sets up a new AssemblyScript project or updates an existing one.", From 7515d939368cdd9716801dacb806c80175689e7e Mon Sep 17 00:00:00 2001 From: romdotdog <70765447+romdotdog@users.noreply.github.com> Date: Mon, 19 Jul 2021 17:07:40 -0400 Subject: [PATCH 02/10] list paths depending on environment --- bin/asinit | 53 ++++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/bin/asinit b/bin/asinit index c98bf50c9f..2e89565123 100755 --- a/bin/asinit +++ b/bin/asinit @@ -89,9 +89,34 @@ const buildDir = path.join(projectDir, "build"); const testsDir = path.join(projectDir, "tests"); const gitignoreFile = path.join(buildDir, ".gitignore"); const packageFile = path.join(projectDir, "package.json"); + +const indexHtml = path.join(projectDir, "index.html"); const indexFile = path.join(projectDir, "index.js"); const testsIndexFile = path.join(testsDir, "index.js"); +const basePaths = [ + [assemblyDir, "Directory holding the AssemblyScript sources being compiled to WebAssembly."], + [tsconfigFile, "TypeScript configuration inheriting recommended AssemblyScript settings."], + [entryFile, "Example entry file being compiled to WebAssembly to get you started."], + [buildDir, "Build artifact directory where compiled WebAssembly files are stored."], + [gitignoreFile, "Git configuration that excludes compiled binaries from source control."], + [asconfigFile, "Configuration file defining both a 'debug' and a 'release' target."], + [packageFile, "Package info containing the necessary commands to compile to WebAssembly."] +]; + +const nodePaths = [ + [indexFile, "Main file loading the WebAssembly module and exporting its exports."], + [testsIndexFile, "Example test to check that your module is indeed working."] +]; + +const webPaths = [ + [indexHtml, "Main file that hosts your webpage and loads your module."] +]; + +const paths = basePaths; +if (useNode) Array.prototype.push.apply(paths, nodePaths); +if (useWeb) Array.prototype.push.apply(paths, webPaths); + console.log([ "Version: " + version, "", @@ -99,33 +124,7 @@ console.log([ "This command will make sure that the following files exist in the project", "directory '" + projectDir + "':" ].join("\n")), - "", - colors.cyan(" ./assembly"), - " Directory holding the AssemblyScript sources being compiled to WebAssembly.", - "", - colors.cyan(" ./assembly/tsconfig.json"), - " TypeScript configuration inheriting recommended AssemblyScript settings.", - "", - colors.cyan(" ./assembly/index.ts"), - " Example entry file being compiled to WebAssembly to get you started.", - "", - colors.cyan(" ./build"), - " Build artifact directory where compiled WebAssembly files are stored.", - "", - colors.cyan(" ./build/.gitignore"), - " Git configuration that excludes compiled binaries from source control.", - "", - colors.cyan(" ./index.js"), - " Main file loading the WebAssembly module and exporting its exports.", - "", - colors.cyan(" ./tests/index.js"), - " Example test to check that your module is indeed working.", - "", - colors.cyan(" ./asconfig.json"), - " Configuration file defining both a 'debug' and a 'release' target.", - "", - colors.cyan(" ./package.json"), - " Package info containing the necessary commands to compile to WebAssembly.", + ...paths.map(([path, description]) => "\n " + colors.cyan(path.relative(projectDir, path)) + "\n " + description), "", "The command will try to update existing files to match the correct settings", "for this instance of the compiler in '" + compilerDir + "'.", From 789aab8f138523e850f0b2d05defd35a50a91a3d Mon Sep 17 00:00:00 2001 From: romdotdog <70765447+romdotdog@users.noreply.github.com> Date: Mon, 19 Jul 2021 17:09:13 -0400 Subject: [PATCH 03/10] isolate node-only ensurances --- bin/asinit | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bin/asinit b/bin/asinit index 2e89565123..415adb17d7 100755 --- a/bin/asinit +++ b/bin/asinit @@ -144,10 +144,14 @@ function createProject(answer) { ensureBuildDirectory(); ensureGitignore(); ensurePackageJson(); - ensureIndexJs(); - ensureTestsDirectory(); - ensureTestsIndexJs(); ensureAsconfigJson(); + + if (useNode) { + ensureIndexJs(); + ensureTestsDirectory(); + ensureTestsIndexJs(); + } + console.log([ colors.green("Done!"), "", From 8217fd5c8c76c58a2d336b49f0a661db1fecd8ec Mon Sep 17 00:00:00 2001 From: romdotdog <70765447+romdotdog@users.noreply.github.com> Date: Mon, 19 Jul 2021 17:09:54 -0400 Subject: [PATCH 04/10] add `ensureIndexHtml` --- bin/asinit | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/bin/asinit b/bin/asinit index 415adb17d7..bbbd8646bf 100755 --- a/bin/asinit +++ b/bin/asinit @@ -152,6 +152,10 @@ function createProject(answer) { ensureTestsIndexJs(); } + if (useWeb) { + ensureIndexHtml(); + } + console.log([ colors.green("Done!"), "", @@ -434,3 +438,34 @@ function ensureTestsIndexJs() { } console.log(); } + +function ensureIndexHtml() { + console.log("- Making sure that 'index.js' exists..."); + if (!fs.existsSync(indexHtml)) { + fs.writeFileSync(indexHtml, [ + "", + "", + "
", + " ", + " ", + " ", + " ", + "", + ].join("\n") + "\n"); + console.log(colors.green(" Created: ") + indexHtml); + } else { + console.log(colors.yellow(" Exists: ") + indexHtml); + } + console.log(); +} \ No newline at end of file From 45bdfaf9fc14f2fb460d9e449e4bd9e4b58a0006 Mon Sep 17 00:00:00 2001 From: romdotdog <70765447+romdotdog@users.noreply.github.com> Date: Mon, 19 Jul 2021 17:10:43 -0400 Subject: [PATCH 05/10] make testing passage node-only --- bin/asinit | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/asinit b/bin/asinit index bbbd8646bf..3b7f2b62c8 100755 --- a/bin/asinit +++ b/bin/asinit @@ -187,10 +187,12 @@ function createProject(answer) { " ^ The optimized WebAssembly module using default optimization settings.", " You can change the optimization settings in '" + colors.cyan("package.json")+ "'.", "", - "To run the tests, do:", - "", - colors.white(" " + commands[pm].test), - "", + ...(useNode ? [ + "To run the tests, do:", + "", + colors.white(" " + commands[pm].test), + "" + ] : []), "The AssemblyScript documentation covers all the details:", "", " https://docs.assemblyscript.org", From 1c035c0c4fa34f14f0cdb1152b63bc4373f9ccc1 Mon Sep 17 00:00:00 2001 From: romdotdog <70765447+romdotdog@users.noreply.github.com> Date: Mon, 19 Jul 2021 17:11:35 -0400 Subject: [PATCH 06/10] install @assemblyscript/loader only on node --- bin/asinit | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bin/asinit b/bin/asinit index 3b7f2b62c8..5cd88be700 100755 --- a/bin/asinit +++ b/bin/asinit @@ -344,11 +344,13 @@ function ensurePackageJson() { "asbuild:untouched": buildUntouched, "asbuild:optimized": buildOptimized, "asbuild": buildAll, - "test": "node tests" - }, - "dependencies": { - "@assemblyscript/loader": "^" + compilerVersion + ...(useNode && {"test": "node tests"}) }, + ...(useNode && { + "dependencies": { + "@assemblyscript/loader": "^" + compilerVersion + } + }), "devDependencies": { "assemblyscript": "^" + compilerVersion } @@ -365,13 +367,13 @@ function ensurePackageJson() { pkg["scripts"] = scripts; updated = true; } - if (!scripts["test"] || scripts["test"] == npmDefaultTest) { + if (!scripts["test"] || scripts["test"] == npmDefaultTest && useNode) { scripts["test"] = "node tests"; pkg["scripts"] = scripts; updated = true; } let dependencies = pkg["dependencies"] || {}; - if (!dependencies["@assemblyscript/loader"]) { + if (!dependencies["@assemblyscript/loader"] && useNode) { dependencies["@assemblyscript/loader"] = "^" + compilerVersion; pkg["dependencies"] = dependencies; updated = true; From 551fa6707ea5d54a6974a9a8a62e5e73eb7d0b2d Mon Sep 17 00:00:00 2001 From: romdotdog <70765447+romdotdog@users.noreply.github.com> Date: Mon, 19 Jul 2021 18:10:56 -0400 Subject: [PATCH 07/10] format paths correctly --- bin/asinit | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/asinit b/bin/asinit index 5cd88be700..c4f251d883 100755 --- a/bin/asinit +++ b/bin/asinit @@ -117,6 +117,8 @@ const paths = basePaths; if (useNode) Array.prototype.push.apply(paths, nodePaths); if (useWeb) Array.prototype.push.apply(paths, webPaths); +const formatPath = filePath => "./" + path.relative(projectDir, filePath).replace(/\\/g, "/"); + console.log([ "Version: " + version, "", @@ -124,7 +126,7 @@ console.log([ "This command will make sure that the following files exist in the project", "directory '" + projectDir + "':" ].join("\n")), - ...paths.map(([path, description]) => "\n " + colors.cyan(path.relative(projectDir, path)) + "\n " + description), + ...paths.map(([filePath, description]) => "\n " + colors.cyan(formatPath(filePath)) + "\n " + description), "", "The command will try to update existing files to match the correct settings", "for this instance of the compiler in '" + compilerDir + "'.", From 64576ac5c41372482b762dddcd3799447eee1984 Mon Sep 17 00:00:00 2001 From: romdotdog <70765447+romdotdog@users.noreply.github.com> Date: Mon, 19 Jul 2021 18:11:13 -0400 Subject: [PATCH 08/10] change index.html path description --- bin/asinit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/asinit b/bin/asinit index c4f251d883..7d46378eae 100755 --- a/bin/asinit +++ b/bin/asinit @@ -110,7 +110,7 @@ const nodePaths = [ ]; const webPaths = [ - [indexHtml, "Main file that hosts your webpage and loads your module."] + [indexHtml, "Starter HTML file that loads your module."] ]; const paths = basePaths; From a0a90710417b8968fd09be910156d318c129c0b1 Mon Sep 17 00:00:00 2001 From: romdotdog <70765447+romdotdog@users.noreply.github.com> Date: Mon, 19 Jul 2021 18:17:19 -0400 Subject: [PATCH 09/10] add --node flag --- bin/asinit | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/asinit b/bin/asinit index 7d46378eae..ad238a0445 100755 --- a/bin/asinit +++ b/bin/asinit @@ -50,9 +50,15 @@ const asinitOptions = { }, "web": { "category": "General", - "description": "Uses a template for web development rather than NodeJS development.", + "description": "Adds an index.html file that can load your module. (Disables node without --node/-n flag)", "type": "b", "alias": "w" + }, + "node": { + "category": "General", + "description": "Re-enables node files when using the --web/-w flag", + "type": "b", + "alias": "n" } }; @@ -61,7 +67,7 @@ const cliOptions = options.parse(process.argv.slice(2), asinitOptions); if (cliOptions.options.help || cliOptions.arguments.length === 0) printHelp(); const useWeb = cliOptions.options.web; -const useNode = !useWeb; +const useNode = cliOptions.options.node || !useWeb; function printHelp() { console.log([ From 4e5dd08676534198e560335f7bff5803ca443081 Mon Sep 17 00:00:00 2001 From: romdotdog <70765447+romdotdog@users.noreply.github.com> Date: Sun, 15 Aug 2021 22:07:28 -0500 Subject: [PATCH 10/10] correct extension in ensureIndexHtml --- bin/asinit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/asinit b/bin/asinit index ad238a0445..9b38303e2f 100755 --- a/bin/asinit +++ b/bin/asinit @@ -452,7 +452,7 @@ function ensureTestsIndexJs() { } function ensureIndexHtml() { - console.log("- Making sure that 'index.js' exists..."); + console.log("- Making sure that 'index.html' exists..."); if (!fs.existsSync(indexHtml)) { fs.writeFileSync(indexHtml, [ "",