@kubiklabs/wasmkit
Version:
Wasmkit is a development environment to compile, deploy, test, run cosmwasm contracts on different networks.
117 lines (116 loc) • 5.69 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.filterNonExistent = void 0;
const chalk_1 = __importDefault(require("chalk"));
const debug_1 = __importDefault(require("debug"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const ts = __importStar(require("typescript"));
const playground_creation_1 = require("../internal/cli/playground-creation");
const config_env_1 = require("../internal/core/config/config-env");
const errors_1 = require("../internal/core/errors");
const errors_list_1 = require("../internal/core/errors-list");
const project_structure_1 = require("../internal/core/project-structure");
const script_runner_1 = require("../internal/util/script-runner");
const scripts_1 = require("../lib/compile/scripts");
const files_1 = require("../lib/files");
const task_names_1 = require("./task-names");
function filterNonExistent(scripts) {
return scripts.filter((script) => !fs_extra_1.default.pathExistsSync(script));
}
exports.filterNonExistent = filterNonExistent;
async function runScripts(runtimeEnv, scriptNames, force, logDebugTag, allowWrite) {
const log = (0, debug_1.default)(logDebugTag);
// log the details of network the script is running on
console.log(`Network: { RpcUrl: '${chalk_1.default.green(runtimeEnv.network.config.endpoint)}'` +
`, ChainId: '${chalk_1.default.green(runtimeEnv.network.config.chainId)}' }`);
console.log("===========================================");
// force boolean will be used when we have checkpoint support
for (const relativeScriptPath of scriptNames) {
log(`Running script ${relativeScriptPath}`);
await (0, script_runner_1.runScript)(relativeScriptPath, runtimeEnv);
}
}
async function executeRunTask({ scripts, skipCheckpoints }, runtimeEnv
// eslint-disable-next-line
) {
const logDebugTag = "wasmkit:tasks:run";
const currDir = process.cwd();
const nonExistent = filterNonExistent(scripts);
if (nonExistent.length !== 0) {
throw new errors_1.WasmkitError(errors_list_1.ERRORS.BUILTIN_TASKS.RUN_FILES_NOT_FOUND, {
scripts: nonExistent
});
}
if (skipCheckpoints) {
// used by Contract() class to skip checkpoints
runtimeEnv.runtimeArgs.useCheckpoints = false;
}
await (0, scripts_1.buildTsScripts)(scripts, {
baseUrl: currDir,
paths: {
"*": ["node_modules/*"]
},
target: ts.ScriptTarget.ES2020,
outDir: path_1.default.join(currDir, "build"),
experimentalDecorators: true,
esModuleInterop: true,
allowJs: true,
module: ts.ModuleKind.CommonJS,
resolveJsonModule: true,
noImplicitReturns: true,
noImplicitThis: true,
strict: true,
forceConsistentCasingInFileNames: true,
sourceMap: true,
declaration: true
});
await runScripts(runtimeEnv, (0, files_1.assertDirChildren)(project_structure_1.SCRIPTS_DIR, scripts), true, logDebugTag, false);
// TODO: checkpoint update in playground
const playgroundPath = path_1.default.join(currDir, "playground");
if (fs_extra_1.default.pathExistsSync(playgroundPath)) {
const checkpointsDir = path_1.default.join(currDir, "artifacts", "checkpoints");
const schemaDir = path_1.default.join(currDir, "artifacts", "typescript_schema");
const contractListPath = path_1.default.join(playgroundPath, "src", "contracts", "instantiateInfo");
const contractSchemaPath = path_1.default.join(playgroundPath, "src", "contracts", "schema");
if ((fs_extra_1.default.pathExistsSync(checkpointsDir)) && (fs_extra_1.default.pathExistsSync(schemaDir))) {
(0, playground_creation_1.createDir)(contractListPath);
(0, playground_creation_1.createDir)(contractSchemaPath);
(0, playground_creation_1.createContractListJson)(checkpointsDir, contractListPath, runtimeEnv);
(0, playground_creation_1.processFilesInFolder)(schemaDir, contractSchemaPath);
}
}
}
function default_1() {
(0, config_env_1.task)(task_names_1.TASK_RUN, "Runs a user-defined script after compiling the project")
.addVariadicPositionalParam("scripts", "A js file to be run within WasmKit's environment")
.addFlag("skipCheckpoints", "do not read from or write checkpoints")
.setAction((input, env) => executeRunTask(input, env));
}
exports.default = default_1;