create-tezos-smart-contract
Version:
Node.js toolset to write, test and deploy Tezos smart contracts
86 lines (85 loc) • 3.25 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = exports.addInitCommand = void 0;
const inquirer_1 = __importDefault(require("inquirer"));
const console_1 = require("../../console");
const config_1 = require("../../modules/config");
const ligo_1 = require("../../modules/ligo");
const contract_bundle_1 = require("./contract-bundle");
// Specifically instance a new Inquirer prompt
const prompt = inquirer_1.default.createPromptModule();
// Prepare our "empty" config
const config = config_1.defaultConfig;
// Grab repository name
const grabName = async () => {
const res = await prompt([{
type: "input",
name: "repoName",
message: "What will be the name of the repository?"
}]);
config.repoName = res.repoName;
};
// Grab LIGO flavor
const grabFlavor = async () => {
const availFlavors = {
[ligo_1.LIGOFlavors.JsLIGO]: "JsLIGO",
[ligo_1.LIGOFlavors.PascaLIGO]: "PascaLIGO",
[ligo_1.LIGOFlavors.CameLIGO]: "CameLIGO",
[ligo_1.LIGOFlavors.ReasonLIGO]: "ReasonLIGO",
};
const res = await prompt([{
type: "list",
default: config_1.defaultConfig.preferredLigoFlavor,
choices: Object.keys(availFlavors).map(value => ({ name: availFlavors[value], value })),
name: "preferredLigoFlavor",
message: "What LIGO flavor do you prefer to write your contract with?"
}]);
config.preferredLigoFlavor = res.preferredLigoFlavor;
};
// Ask for examples
const grabExamplesPreference = async () => {
const res = await prompt([{
type: "list",
default: true,
choices: [{ name: 'Yes', value: true }, { name: 'No', value: false }],
name: "hasExamples",
message: "Would you like to have some example code in the newly created repo?",
}]);
return res.hasExamples;
};
const addInitCommand = (program, debugHook) => {
program
.command('init')
.description('Starts a small configuration utility to create a new smart contract repo.')
.argument('[name]', "(Optional) The name of the new repo to be created")
.action((name) => {
(0, exports.init)(name);
})
.hook('preAction', debugHook);
};
exports.addInitCommand = addInitCommand;
// Full init command controller
const init = async (name) => {
(0, console_1.em)(`Welcome, let's create your Tezos smart-contract!\n`);
if (name) {
config.repoName = name;
(0, console_1.log)(`The name of the repository will be "${name}".\n`);
}
else {
await grabName();
}
await grabFlavor();
const hasExamples = await grabExamplesPreference();
await (0, contract_bundle_1.makeContractBundle)({
basePath: (0, console_1.getCWD)(),
config,
hasExamples,
});
(0, console_1.log)('\nRepository creation is done!\n\n\n');
(0, console_1.em)('Please install dependencies running the following command:\n\n');
(0, console_1.log)(`cd ${config.repoName} && npm i`);
};
exports.init = init;