-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
153 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,72 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.build = build; | ||
const fs_1 = require("fs"); | ||
const types_1 = require("./types"); | ||
const glob_1 = require("glob"); | ||
const chalk_1 = require("chalk"); | ||
const child_process_1 = require("child_process"); | ||
const util_1 = require("./util"); | ||
async function build(args, flags) { | ||
const config = Object.assign(new types_1.Config(), JSON.parse((0, fs_1.readFileSync)("./as-test.config.json").toString())); | ||
const pkg = JSON.parse((0, fs_1.readFileSync)("./package.json").toString()); | ||
let buildCommands = []; | ||
if (config.buildOptions.wasi) { | ||
if (!(0, fs_1.existsSync)("./node_modules/@assemblyscript/wasi-shim/asconfig.json")) { | ||
console.log(chalk_1.default.bgRed(" ERROR ") + chalk_1.default.dim(":") + " " + "could not find @assemblyscript/wasi-shim! Add it to your dependencies to run with WASI!"); | ||
process.exit(1); | ||
} | ||
if ((pkg.dependencies && !Object.keys(pkg.dependencies).includes("@assemblyscript/wasi-shim")) | ||
|| (pkg.devDependencies && !Object.keys(pkg.devDependencies).includes("@assemblyscript/wasi-shim")) | ||
|| (pkg.peerDependencies && !Object.keys(pkg.peerDependencies).includes("@assemblyscript/wasi-shim"))) { | ||
if ((0, fs_1.existsSync)("./node_modules/@assemblyscript/wasi-shim/asconfig.json")) { | ||
console.log(chalk_1.default.bold.bgMagentaBright(" WARN ") + chalk_1.default.dim(": @assemblyscript/wasi-shim") + " is not included in project dependencies!"); | ||
} | ||
} | ||
} | ||
const inputFiles = await (0, glob_1.glob)(config.input); | ||
for (const file of inputFiles) { | ||
console.log(chalk_1.default.dim("Including " + file)); | ||
let command = `npx asc ${file}${args.length ? " " + args.join(" ") : ""}`; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
import { existsSync, readFileSync } from "fs"; | ||
import { Config } from "./types.js"; | ||
import { glob } from "glob"; | ||
import chalk from "chalk"; | ||
import { exec } from "child_process"; | ||
import { formatTime } from "./util.js"; | ||
export function build(args, flags) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const config = Object.assign(new Config(), JSON.parse(readFileSync("./as-test.config.json").toString())); | ||
const pkg = JSON.parse(readFileSync("./package.json").toString()); | ||
let buildCommands = []; | ||
if (config.buildOptions.wasi) { | ||
command += " --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json"; | ||
if (!existsSync("./node_modules/@assemblyscript/wasi-shim/asconfig.json")) { | ||
console.log(chalk.bgRed(" ERROR ") + chalk.dim(":") + " " + "could not find @assemblyscript/wasi-shim! Add it to your dependencies to run with WASI!"); | ||
process.exit(1); | ||
} | ||
if ((pkg.dependencies && !Object.keys(pkg.dependencies).includes("@assemblyscript/wasi-shim")) | ||
|| (pkg.devDependencies && !Object.keys(pkg.devDependencies).includes("@assemblyscript/wasi-shim")) | ||
|| (pkg.peerDependencies && !Object.keys(pkg.peerDependencies).includes("@assemblyscript/wasi-shim"))) { | ||
if (existsSync("./node_modules/@assemblyscript/wasi-shim/asconfig.json")) { | ||
console.log(chalk.bold.bgMagentaBright(" WARN ") + chalk.dim(": @assemblyscript/wasi-shim") + " is not included in project dependencies!"); | ||
} | ||
} | ||
} | ||
const outFile = config.outDir + "/" + file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm"); | ||
if (config.outDir) { | ||
command += " -o " + outFile; | ||
const inputFiles = yield glob(config.input); | ||
for (const file of inputFiles) { | ||
console.log(chalk.dim("Including " + file)); | ||
let command = `npx asc ${file}${args.length ? " " + args.join(" ") : ""}`; | ||
if (config.buildOptions.wasi) { | ||
command += " --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json"; | ||
} | ||
const outFile = config.outDir + "/" + file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm"); | ||
if (config.outDir) { | ||
command += " -o " + outFile; | ||
} | ||
buildCommands.push(command); | ||
} | ||
buildCommands.push(command); | ||
} | ||
const build = (command) => { | ||
return new Promise((resolve, _) => { | ||
(0, child_process_1.exec)(command, (err, stdout, stderr) => { | ||
if (config.buildOptions.verbose) { | ||
process.stdout.write(stdout); | ||
} | ||
if (err) { | ||
process.stderr.write(stderr + "\n"); | ||
process.exit(1); | ||
} | ||
resolve(); | ||
const build = (command) => { | ||
return new Promise((resolve, _) => { | ||
exec(command, (err, stdout, stderr) => { | ||
if (config.buildOptions.verbose) { | ||
process.stdout.write(stdout); | ||
} | ||
if (err) { | ||
process.stderr.write(stderr + "\n"); | ||
process.exit(1); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
}; | ||
if (config.buildOptions.parallel) { | ||
console.log(chalk_1.default.dim("Building sources in parallel...")); | ||
const start = performance.now(); | ||
let builders = []; | ||
for (const command of buildCommands) { | ||
builders.push(build(command)); | ||
}; | ||
if (config.buildOptions.parallel) { | ||
console.log(chalk.dim("Building sources in parallel...")); | ||
const start = performance.now(); | ||
let builders = []; | ||
for (const command of buildCommands) { | ||
builders.push(build(command)); | ||
} | ||
yield Promise.all(builders); | ||
console.log(chalk.dim("Compiled in " + formatTime(performance.now() - start)) + "\n"); | ||
} | ||
await Promise.all(builders); | ||
console.log(chalk_1.default.dim("Compiled in " + (0, util_1.formatTime)(performance.now() - start)) + "\n"); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,49 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.run = run; | ||
const fs_1 = require("fs"); | ||
const types_1 = require("./types"); | ||
const chalk_1 = require("chalk"); | ||
const child_process_1 = require("child_process"); | ||
const glob_1 = require("glob"); | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
import { readFileSync, readdirSync } from "fs"; | ||
import { Config } from "./types.js"; | ||
import chalk from "chalk"; | ||
import { exec } from "child_process"; | ||
import { glob } from "glob"; | ||
const installScripts = new Map([ | ||
["wasmtime", "curl https://wasmtime.dev/install.sh -sSf | bash"] | ||
]); | ||
async function run() { | ||
const config = Object.assign(new types_1.Config(), JSON.parse((0, fs_1.readFileSync)("./as-test.config.json").toString())); | ||
const inputFiles = await (0, glob_1.glob)(config.input); | ||
console.log(chalk_1.default.dim("Running tests using " + config.runOptions.runtime.name + "")); | ||
let execPath = ""; | ||
const PATH = process.env["PATH"]?.split(":"); | ||
for (const bin of PATH) { | ||
if (bin.startsWith("/mnt/")) | ||
continue; | ||
for (const file of (0, fs_1.readdirSync)(bin)) { | ||
if (file == config.runOptions.runtime.name || file == config.runOptions.runtime.name + ".exe") { | ||
execPath = bin + "/" + file; | ||
export function run() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
const config = Object.assign(new Config(), JSON.parse(readFileSync("./as-test.config.json").toString())); | ||
const inputFiles = yield glob(config.input); | ||
console.log(chalk.dim("Running tests using " + config.runOptions.runtime.name + "")); | ||
let execPath = ""; | ||
const PATH = (_a = process.env["PATH"]) === null || _a === void 0 ? void 0 : _a.split(":"); | ||
for (const bin of PATH) { | ||
if (bin.startsWith("/mnt/")) | ||
continue; | ||
for (const file of readdirSync(bin)) { | ||
if (file == config.runOptions.runtime.name || file == config.runOptions.runtime.name + ".exe") { | ||
execPath = bin + "/" + file; | ||
} | ||
} | ||
} | ||
} | ||
if (!execPath) { | ||
console.log(chalk_1.default.bgRed(" ERROR ") + chalk_1.default.dim(":") + " could not locate " + config.runOptions.runtime.name + " in your PATH variable. Either set it, or install it" + (config.runOptions.runtime.name ? "using " + chalk_1.default.dim(installScripts.get(config.runOptions.runtime.name)) : ".")); | ||
} | ||
for (const file of inputFiles) { | ||
const outFile = config.outDir + "/" + file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm"); | ||
(0, child_process_1.exec)(config.runOptions.runtime.run.replace(config.runOptions.runtime.name, execPath).replace("<file>", outFile), (err, stdout, stderr) => { | ||
process.stdout.write(stdout); | ||
process.stderr.write(stderr); | ||
if (err) { | ||
process.exit(err.code); | ||
} | ||
}); | ||
} | ||
if (!execPath) { | ||
console.log(chalk.bgRed(" ERROR ") + chalk.dim(":") + " could not locate " + config.runOptions.runtime.name + " in your PATH variable. Either set it, or install it" + (config.runOptions.runtime.name ? "using " + chalk.dim(installScripts.get(config.runOptions.runtime.name)) : ".")); | ||
} | ||
for (const file of inputFiles) { | ||
const outFile = config.outDir + "/" + file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm"); | ||
exec(config.runOptions.runtime.run.replace(config.runOptions.runtime.name, execPath).replace("<file>", outFile), (err, stdout, stderr) => { | ||
process.stdout.write(stdout); | ||
process.stderr.write(stderr); | ||
if (err) { | ||
process.exit(err.code); | ||
} | ||
}); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.