as-test 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/init.js CHANGED
@@ -5,24 +5,27 @@ import { createInterface } from "readline";
5
5
  import { loadConfig } from "./util.js";
6
6
  const TARGETS = ["wasi", "bindings"];
7
7
  export async function init(args) {
8
- const rl = createInterface({
9
- input: process.stdin,
10
- output: process.stdout,
11
- });
12
- console.log(chalk.bold("as-test init v0.3.0") + "\n");
13
- console.log(chalk.dim("[1/3]") + " select a target [wasi/bindings]");
14
- const target = await ask(chalk.dim(" -> "), rl);
15
- if (!TARGETS.includes(target)) {
16
- console.log("Invalid target " + target + ". Exiting.");
17
- process.exit(0);
18
- }
19
- process.stdout.write(`\u001B[1A`);
20
- process.stdout.write("\x1B[2K");
21
- process.stdout.write("\x1B[0G");
22
- console.log("\n" +
23
- chalk.dim("[2/3]") +
24
- " attempting to create the following files. Continue? [y/n]\n");
25
- console.log(chalk.dim(` ├── 📂 assembly/
8
+ const rl = createInterface({
9
+ input: process.stdin,
10
+ output: process.stdout,
11
+ });
12
+ console.log(chalk.bold("as-test init v0.3.2") + "\n");
13
+ console.log(chalk.dim("[1/3]") + " select a target [wasi/bindings]");
14
+ const target = await ask(chalk.dim(" -> "), rl);
15
+ if (!TARGETS.includes(target)) {
16
+ console.log("Invalid target " + target + ". Exiting.");
17
+ process.exit(0);
18
+ }
19
+ process.stdout.write(`\u001B[1A`);
20
+ process.stdout.write("\x1B[2K");
21
+ process.stdout.write("\x1B[0G");
22
+ console.log(
23
+ "\n" +
24
+ chalk.dim("[2/3]") +
25
+ " attempting to create the following files. Continue? [y/n]\n",
26
+ );
27
+ console.log(
28
+ chalk.dim(` ├── 📂 assembly/
26
29
  │ └── 📂 __tests__/
27
30
  │ └── 🧪 example.spec.ts
28
31
  ├── 📂 build/
@@ -30,25 +33,27 @@ export async function init(args) {
30
33
  ├── 📂 tests/
31
34
  │ └── 📃 as-test.run.js
32
35
  ├── ⚙️ as-test.config.json
33
- └── ⚙️ package.json\n`));
34
- const cont = (await ask(chalk.dim(" -> "), rl)).toLowerCase().trim();
35
- if (cont == "n" || cont == "no") {
36
- console.log("Exiting.");
37
- process.exit(0);
38
- }
39
- let config = loadConfig(path.join(process.cwd(), "./as-test.config.json"));
40
- if (target == "wasi" && config.buildOptions.target != "wasi") {
41
- config.buildOptions.target = "wasi";
42
- config.runOptions.runtime.name = "wasmtime";
43
- config.runOptions.runtime.run = "wasmtime <file>";
44
- }
45
- else if (target == "bindings" && config.buildOptions.target != "bindings") {
46
- config.buildOptions.target = "bindings";
47
- config.runOptions.runtime.name = "node";
48
- config.runOptions.runtime.run = "node ./tests/<name>.run.js";
49
- }
50
- writeFile("./as-test.config.json", JSON.stringify(config, null, 2));
51
- writeFile("./assembly/__tests__/example.spec.ts", `import {
36
+ └── ⚙️ package.json\n`),
37
+ );
38
+ const cont = (await ask(chalk.dim(" -> "), rl)).toLowerCase().trim();
39
+ if (cont == "n" || cont == "no") {
40
+ console.log("Exiting.");
41
+ process.exit(0);
42
+ }
43
+ let config = loadConfig(path.join(process.cwd(), "./as-test.config.json"));
44
+ if (target == "wasi" && config.buildOptions.target != "wasi") {
45
+ config.buildOptions.target = "wasi";
46
+ config.runOptions.runtime.name = "wasmtime";
47
+ config.runOptions.runtime.run = "wasmtime <file>";
48
+ } else if (target == "bindings" && config.buildOptions.target != "bindings") {
49
+ config.buildOptions.target = "bindings";
50
+ config.runOptions.runtime.name = "node";
51
+ config.runOptions.runtime.run = "node ./tests/<name>.run.js";
52
+ }
53
+ writeFile("./as-test.config.json", JSON.stringify(config, null, 2));
54
+ writeFile(
55
+ "./assembly/__tests__/example.spec.ts",
56
+ `import {
52
57
  describe,
53
58
  expect,
54
59
  test,
@@ -138,79 +143,86 @@ run();
138
143
  function sleep(ms: i64): void {
139
144
  const target = Date.now() + ms;
140
145
  while (target > Date.now()) { }
141
- }`);
142
- writeDir("./build/");
143
- writeDir("./logs/");
144
- if (target == "bindings") {
145
- writeFile("./tests/example.run.js", `import { readFileSync } from "fs";
146
+ }`,
147
+ );
148
+ writeDir("./build/");
149
+ writeDir("./logs/");
150
+ if (target == "bindings") {
151
+ writeFile(
152
+ "./tests/example.run.js",
153
+ `import { readFileSync } from "fs";
146
154
  import { instantiate } from "../build/example.spec.js";
147
155
 
148
156
  const binary = readFileSync("./build/example.spec.wasm");
149
157
  const module = new WebAssembly.Module(binary);
150
158
 
151
- const exports = instantiate(module, {});`);
152
- }
153
- const PKG_PATH = path.join(process.cwd(), "./package.json");
154
- if (!hasDep(PKG_PATH, "assemblyscript")) {
155
- console.log(chalk.dim("AssemblyScript is not included in dependencies.\nInstall it with " +
156
- (process.env.npm_config_user_agent == "yarn"
157
- ? process.env.npm_config_user_agent + " add assemblyscript"
158
- : process.env.npm_config_user_agent + " install assemblyscript")));
159
- }
160
- const pkg = JSON.parse(existsSync(PKG_PATH) ? readFileSync(PKG_PATH).toString() : "{}");
161
- if (!pkg["scripts"])
162
- pkg["scripts"] = {};
163
- if (pkg.scripts["test"])
164
- process.exit(0);
165
- if (!pkg.scripts["pretest"]) {
166
- pkg.scripts["pretest"] = "as-test build";
167
- pkg.scripts["test"] = "as-test run";
168
- }
169
- else {
170
- pkg.scripts["test"] = "as-test test";
171
- }
172
- if (!pkg["devDependencies"])
173
- pkg["devDependencies"] = {};
174
- if (!pkg["devDependencies"]["as-test"])
175
- pkg["devDependencies"]["as-test"] = "^0.3.0";
176
- if (target == "bindings") {
177
- pkg["type"] = "module";
178
- }
179
- writeFileSync(PKG_PATH, JSON.stringify(pkg, null, 2));
180
- process.exit(0);
159
+ const exports = instantiate(module, {});`,
160
+ );
161
+ }
162
+ const PKG_PATH = path.join(process.cwd(), "./package.json");
163
+ if (!hasDep(PKG_PATH, "assemblyscript")) {
164
+ console.log(
165
+ chalk.dim(
166
+ "AssemblyScript is not included in dependencies.\nInstall it with " +
167
+ (process.env.npm_config_user_agent == "yarn"
168
+ ? process.env.npm_config_user_agent + " add assemblyscript"
169
+ : process.env.npm_config_user_agent + " install assemblyscript"),
170
+ ),
171
+ );
172
+ }
173
+ const pkg = JSON.parse(
174
+ existsSync(PKG_PATH) ? readFileSync(PKG_PATH).toString() : "{}",
175
+ );
176
+ if (!pkg["scripts"]) pkg["scripts"] = {};
177
+ if (pkg.scripts["test"]) process.exit(0);
178
+ if (!pkg.scripts["pretest"]) {
179
+ pkg.scripts["pretest"] = "as-test build";
180
+ pkg.scripts["test"] = "as-test run";
181
+ } else {
182
+ pkg.scripts["test"] = "as-test test";
183
+ }
184
+ if (!pkg["devDependencies"]) pkg["devDependencies"] = {};
185
+ if (!pkg["devDependencies"]["as-test"])
186
+ pkg["devDependencies"]["as-test"] = "^0.3.2";
187
+ if (target == "bindings") {
188
+ pkg["type"] = "module";
189
+ }
190
+ writeFileSync(PKG_PATH, JSON.stringify(pkg, null, 2));
191
+ process.exit(0);
181
192
  }
182
193
  function ask(question, face) {
183
- return new Promise((res, _) => {
184
- face.question(question, (answer) => {
185
- res(answer);
186
- });
194
+ return new Promise((res, _) => {
195
+ face.question(question, (answer) => {
196
+ res(answer);
187
197
  });
198
+ });
188
199
  }
189
200
  function writeFile(pth, data) {
190
- const fmtPath = path.join(process.cwd(), pth);
191
- if (existsSync(fmtPath))
192
- return;
193
- if (!existsSync(path.dirname(fmtPath)))
194
- mkdirSync(path.dirname(fmtPath), { recursive: true });
195
- writeFileSync(fmtPath, data);
201
+ const fmtPath = path.join(process.cwd(), pth);
202
+ if (existsSync(fmtPath)) return;
203
+ if (!existsSync(path.dirname(fmtPath)))
204
+ mkdirSync(path.dirname(fmtPath), { recursive: true });
205
+ writeFileSync(fmtPath, data);
196
206
  }
197
207
  function writeDir(pth) {
198
- const fmtPath = path.join(process.cwd(), pth);
199
- if (existsSync(fmtPath))
200
- return;
201
- mkdirSync(fmtPath);
208
+ const fmtPath = path.join(process.cwd(), pth);
209
+ if (existsSync(fmtPath)) return;
210
+ mkdirSync(fmtPath);
202
211
  }
203
212
  function hasDep(PKG_PATH, dep) {
204
- const pkg = JSON.parse(existsSync(PKG_PATH) ? readFileSync(PKG_PATH).toString() : "{}");
205
- if (existsSync(path.join(process.cwd(), "./node_modules/", dep)))
206
- return true;
207
- if (pkg.dependencies &&
208
- !Object.keys(pkg.dependencies).includes(dep) &&
209
- pkg.devDependencies &&
210
- !Object.keys(pkg.devDependencies).includes(dep) &&
211
- pkg.peerDependencies &&
212
- !Object.keys(pkg.peerDependencies).includes(dep)) {
213
- return false;
214
- }
215
- return true;
213
+ const pkg = JSON.parse(
214
+ existsSync(PKG_PATH) ? readFileSync(PKG_PATH).toString() : "{}",
215
+ );
216
+ if (existsSync(path.join(process.cwd(), "./node_modules/", dep))) return true;
217
+ if (
218
+ pkg.dependencies &&
219
+ !Object.keys(pkg.dependencies).includes(dep) &&
220
+ pkg.devDependencies &&
221
+ !Object.keys(pkg.devDependencies).includes(dep) &&
222
+ pkg.peerDependencies &&
223
+ !Object.keys(pkg.peerDependencies).includes(dep)
224
+ ) {
225
+ return false;
226
+ }
227
+ return true;
216
228
  }
package/bin/reporter.js CHANGED
@@ -1 +1 @@
1
- export function report() { }
1
+ export function report() {}