UNPKG

@modyo/cli

Version:

Modyo CLI Command line to expose local development tools

89 lines (88 loc) 4.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const path = tslib_1.__importStar(require("node:path")); const core_1 = require("@oclif/core"); const get_template_name_and_version_1 = tslib_1.__importDefault(require("../get/get-template-name-and-version")); const check_to_overrides_1 = tslib_1.__importDefault(require("../get/check-to-overrides")); const create_tmp_directory_1 = tslib_1.__importDefault(require("../get/create-tmp-directory")); const getting_template_1 = tslib_1.__importDefault(require("../get/getting-template")); const extracting_template_files_1 = tslib_1.__importDefault(require("../get/extracting-template-files")); const remove_tmp_zip_file_1 = tslib_1.__importDefault(require("../get/remove-tmp-zip-file")); const moving_files_to_final_destination_1 = tslib_1.__importDefault(require("../get/moving-files-to-final-destination")); class Get extends core_1.Command { async run() { try { this.debug('getting details from arguments'); const { args, flags } = await this.parse(Get); core_1.ux.action.start('Getting identifier information', 'initializing', { stdout: true }); const [templateName, templateVersion] = (0, get_template_name_and_version_1.default)(args.name); this.debug({ templateName, templateVersion }); core_1.ux.action.stop(`name: ${templateName} and version: ${templateVersion}`); if (!args.directory) { this.debug(`setting directory to initialize in ${templateName}`); // eslint-disable-next-line functional/immutable-data args.directory = templateName; } const finalPath = path.resolve(args.directory); this.debug(`template Path is ${finalPath} checking if needs overrides`); const override = await (0, check_to_overrides_1.default)(finalPath, flags.force); const tempDirectory = await (0, create_tmp_directory_1.default)(); const zipPath = await (0, getting_template_1.default)({ organization: flags.organization, templateName, templateVersion, tempDirectory, }); await (0, extracting_template_files_1.default)({ zipPath, finalPath, override }); await (0, remove_tmp_zip_file_1.default)(tempDirectory); await (0, moving_files_to_final_destination_1.default)(finalPath); core_1.ux.action.stop(); } catch (error) { if (error instanceof Error) { this.error(error.message || error); } } } } exports.default = Get; Get.summary = 'Pull a widget from our catalog into a new directory'; Get.description = 'In general, the `get` command is used to obtain a boilerplate widget.'; Get.examples = [ 'There are some public widget names that can be accessed via this command', { description: 'To initialize a widget', command: '<%= config.bin %> <%= command.id %> dynamic-react-base-template [DIRECTORY]', }, { description: `From this command and on you can continue using the widget like any other front-end widget. Your organization can create its own custom templates to initialize new widgets and use them with the \`organization\` option`, command: '<%= config.bin %> <%= command.id %> --organization=myOrganization my-custom-template-repo [DIRECTORY]', }, ]; Get.flags = { force: core_1.Flags.boolean({ char: 'f', description: 'Override folder if exist', }), help: core_1.Flags.help({ char: 'h', description: 'Output usage information', }), organization: core_1.Flags.string({ char: 'o', description: 'Github Organization', default: 'dynamic-framework', }), }; Get.args = { name: core_1.Args.string({ description: 'The name of the widget', required: true, }), directory: core_1.Args.string({ description: 'Name of directory to init', required: false, }), };