@kubiklabs/wasmkit
Version:
Wasmkit is a development environment to compile, deploy, test, run cosmwasm contracts on different networks.
32 lines (31 loc) • 1.66 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.compress = void 0;
const chalk_1 = __importDefault(require("chalk"));
const child_process_1 = require("child_process");
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const project_structure_1 = require("../../internal/core/project-structure");
const compile_1 = require("../compile/compile");
async function compress(contractName, env) {
const srcPath = path_1.default.join(project_structure_1.CONTRACTS_OUT_DIR, `${contractName}.wasm`);
const destPath = path_1.default.join(project_structure_1.CONTRACTS_OUT_DIR, `${contractName}_compressed.wasm`);
if (fs_extra_1.default.existsSync(destPath)) {
console.log(`Compressed .wasm file exists for contract ${contractName}, skipping compression`);
return;
}
if (!fs_extra_1.default.existsSync(srcPath)) {
console.log(`${contractName}.wasm file does not exist in artifacts dir, compiling...`);
await (0, compile_1.compile)(false, [], false, false, false, env);
}
const compressCmd = `cp ${srcPath} ${destPath}`;
console.log(chalk_1.default.greenBright(`Creating compressed .wasm file for ${contractName}`));
(0, child_process_1.execSync)(compressCmd, { stdio: 'inherit' });
if (!fs_extra_1.default.existsSync(destPath)) {
(0, child_process_1.execSync)(`wasm-opt -Oz ${srcPath} -o ${destPath}`, { stdio: 'inherit' });
}
}
exports.compress = compress;