@kubiklabs/wasmkit
Version:
Wasmkit is a development environment to compile, deploy, test, run cosmwasm contracts on different networks.
45 lines (44 loc) • 2.62 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chalk_1 = __importDefault(require("chalk"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
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 task_names_1 = require("./task-names");
function default_1() {
(0, config_env_1.task)(task_names_1.TASK_CLEAN, "Clears the cache and deletes specified artifacts files")
.addOptionalVariadicPositionalParam("contractName", "Name of the contract to be cleaned", [])
.setAction(async ({ contractName }, env) => {
const contractNameNew = contractName.toString().replace(/-/g, '_');
const comp = './artifacts/contracts/' + contractNameNew + '.wasm';
if (!(0, project_structure_1.isCwdProjectDir)()) {
console.log(`Not in a valid WasmKit project repo, exiting`);
process.exit(1);
}
else if (!fs_extra_1.default.existsSync(`./${project_structure_1.ARTIFACTS_DIR}`) && contractName.length) {
throw new errors_1.WasmkitError(errors_list_1.ERRORS.GENERAL.ARTIFACTS_NOT_FOUND);
}
else if (contractNameNew.length !== 0 && fs_extra_1.default.existsSync(comp)) {
const artifactsAbsPath = path_1.default.resolve(process.cwd(), project_structure_1.ARTIFACTS_DIR);
console.log(`Cleaning Artifacts directory: ${chalk_1.default.gray(artifactsAbsPath)}`);
await fs_extra_1.default.remove(comp);
await fs_extra_1.default.remove('./artifacts/schema/' + contractNameNew + '/');
await fs_extra_1.default.remove('./artifacts/checkpoints/' + contractNameNew + '.yaml}');
}
else if (contractNameNew.length !== 0 && !(fs_extra_1.default.existsSync(comp))) {
throw new errors_1.WasmkitError(errors_list_1.ERRORS.GENERAL.INCORRECT_CONTRACT_NAME);
}
else {
const artifactsAbsPath = path_1.default.resolve(process.cwd(), project_structure_1.ARTIFACTS_DIR);
console.log(`Cleaning Artifacts directory: ${chalk_1.default.gray(artifactsAbsPath)}`);
await fs_extra_1.default.remove(project_structure_1.ARTIFACTS_DIR);
}
});
}
exports.default = default_1;