@newos/cli
Version:
Command-line interface for the NewOS
111 lines • 5.42 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
const upgrades_1 = require("@newos/upgrades");
const ProjectFile_1 = __importDefault(require("../models/files/ProjectFile"));
const add_1 = __importDefault(require("./add"));
const push_1 = __importDefault(require("../scripts/push"));
const Session_1 = __importDefault(require("../models/network/Session"));
const Compiler_1 = require("../models/compiler/Compiler");
const Dependency_1 = __importDefault(require("../models/dependency/Dependency"));
const ConfigManager_1 = __importDefault(require("../models/config/ConfigManager"));
const prompt_1 = require("../prompts/prompt");
const telemetry_1 = __importDefault(require("../telemetry"));
const name = 'push';
const signature = name;
const description = 'deploys your project to the specified <network>';
const register = program => program
.command(signature, undefined, { noHelp: true })
.description(description)
.usage('--network <network> [options]')
.option('--skip-compile', 'skips contract compilation')
.option('-d, --deploy-dependencies', 'deploys dependencies to the network if there is no existing deployment')
.option('--reset', 'redeploys all contracts (not only the ones that changed)')
.option('--force', 'ignores validation errors and deploys contracts')
.option('--deploy-proxy-admin', "eagerly deploys the project's proxy admin (if not deployed yet on the provided network)")
.option('--deploy-proxy-factory', "eagerly deploys the project's proxy factory (if not deployed yet on the provided network)")
.withNetworkOptions()
.withNonInteractiveOption()
.action(commandActions);
async function commandActions(options) {
await add_1.default.runActionIfNeeded(null, options);
const projectFile = new ProjectFile_1.default();
await action(Object.assign(Object.assign({}, options), { contracts: projectFile.contracts }));
}
async function action(options) {
const { contracts, force, deployDependencies, reset: reupload, network: networkInOpts, deployProxyAdmin, deployProxyFactory, interactive, } = options;
const { network: networkInSession, expired } = Session_1.default.getNetwork();
const opts = {
network: networkInOpts || (!expired ? networkInSession : undefined),
};
const defaults = { network: networkInSession };
const props = getCommandProps();
if (!options.skipCompile)
await Compiler_1.compile();
const prompted = await prompt_1.promptIfNeeded({ opts, defaults, props }, interactive);
const { network, txParams } = await ConfigManager_1.default.initNetworkConfiguration(Object.assign(Object.assign({}, options), prompted));
const promptDeployDependencies = await promptForDeployDependencies(deployDependencies, network, interactive);
const pushArguments = Object.assign(Object.assign({ deployProxyAdmin,
deployProxyFactory,
force,
reupload,
network,
txParams }, promptDeployDependencies), { contracts });
if (!options.skipTelemetry)
await telemetry_1.default.report('push', pushArguments, interactive);
await push_1.default(pushArguments);
if (!options.dontExitProcess && process.env.NODE_ENV !== 'test')
process.exit(0);
}
async function runActionIfRequested(externalOptions) {
var _a, _b;
if (!externalOptions.push)
return;
// if not contracts has been passed use all contracts explicitly from ProjectFile
if (!((_a = externalOptions.contracts) === null || _a === void 0 ? void 0 : _a.length)) {
const projectFile = new ProjectFile_1.default();
if (!!((_b = projectFile.contracts) === null || _b === void 0 ? void 0 : _b.length)) {
externalOptions.contracts = projectFile.contracts;
}
}
const options = lodash_1.omit(externalOptions, 'push');
const network = lodash_1.isString(externalOptions.push) ? externalOptions.push : undefined;
if (network)
options.network = network;
return action(options);
}
async function runActionIfNeeded(contracts, options) {
if (!options.interactive)
return;
await action(Object.assign(Object.assign({}, options), { dontExitProcess: true, skipTelemetry: true, contracts }));
}
async function promptForDeployDependencies(deployDependencies, network, interactive) {
if (await upgrades_1.ZWeb3.isGanacheNode())
return { deployDependencies: true };
if (Dependency_1.default.hasDependenciesForDeploy(network)) {
const opts = { deployDependencies };
const props = getCommandProps(network);
return prompt_1.promptIfNeeded({ opts, props }, interactive);
}
return { deployDependencies: undefined };
}
function getCommandProps(networkName) {
return Object.assign(Object.assign({}, prompt_1.networksList('network', 'list')), { deployDependencies: {
type: 'confirm',
message: `One or more linked dependencies are not yet deployed on ${networkName}.\nDo you want to deploy them now?`,
default: true,
} });
}
exports.default = {
name,
signature,
description,
register,
action,
runActionIfRequested,
runActionIfNeeded,
};
//# sourceMappingURL=push.js.map