@newos/cli
Version:
Command-line interface for the NewOS
69 lines • 3.04 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const push_1 = __importDefault(require("./push"));
const add_1 = __importDefault(require("../scripts/add"));
const add_all_1 = __importDefault(require("../scripts/add-all"));
const ConfigManager_1 = __importDefault(require("../models/config/ConfigManager"));
const Compiler_1 = require("../models/compiler/Compiler");
const prompt_1 = require("../prompts/prompt");
const naming_1 = require("../utils/naming");
const ProjectFile_1 = __importDefault(require("../models/files/ProjectFile"));
const telemetry_1 = __importDefault(require("../telemetry"));
const name = 'add';
const signature = `${name} [contractNames...]`;
const description = 'add contract to your project. Provide a list of whitespace-separated contract names';
const register = program => program
.command(signature, undefined, { noHelp: true })
.usage('[contractName1 ... contractNameN] [options]')
.description(description)
.option('--all', 'add all contracts in your build directory')
.withPushOptions()
.withNonInteractiveOption()
.action(action);
async function action(contractNames, options) {
const { skipCompile, all, interactive } = options;
ConfigManager_1.default.initStaticConfiguration();
if (!skipCompile)
await Compiler_1.compile();
if (all)
add_all_1.default({});
else {
const args = { contractNames };
const props = getCommandProps();
const prompted = await prompt_1.promptIfNeeded({ args, props }, interactive);
const contracts = contractNames.length !== 0 ? contractNames : prompted.contractNames.map(contractName => ({ name: contractName }));
if (!options.skipTelemetry)
await telemetry_1.default.report('add', { contracts }, interactive);
add_1.default({ contracts });
}
await push_1.default.runActionIfRequested(Object.assign(Object.assign({}, options), { contracts: contractNames }));
}
async function runActionIfNeeded(contractFullName, options) {
const { interactive } = options;
const { contractName, package: packageName } = naming_1.fromContractFullName(contractFullName);
const projectFile = new ProjectFile_1.default();
options = Object.assign(Object.assign({}, options), { skipTelemetry: true });
if (interactive) {
if (!packageName && contractName && !projectFile.hasContract(contractName)) {
await action([contractName], options);
}
else if (!packageName && !projectFile.hasContracts()) {
await action([], options);
}
}
}
function getCommandProps() {
return prompt_1.contractsList('contractNames', 'Pick which contracts you want to add', 'checkbox', 'notAdded');
}
exports.default = {
name,
signature,
description,
register,
action,
runActionIfNeeded,
};
//# sourceMappingURL=add.js.map