UNPKG

cpoo

Version:
59 lines (58 loc) 2.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const promises_1 = require("fs/promises"); const path_1 = require("path"); const prefix_1 = require("../../utils/prefix"); const inquirer_1 = require("inquirer"); class Init extends core_1.Command { async run() { try { await this.existConfig(); } catch (_) { await this.makeConfig(); } } async existConfig() { await (0, promises_1.stat)((0, path_1.join)(process.cwd(), '.cpoorc')); this.log('\n'); this.log((0, prefix_1.info)(), 'already exists config file.'); this.log((0, prefix_1.info)(), 'bye bye :3'); } async makeConfig() { this.log((0, prefix_1.info)(), 'the config file does not exist, so create it.\n'); const { fileExt } = await (0, inquirer_1.prompt)([{ name: 'fileExt', message: 'What file extensions do you use?', type: 'list', choices: [{ name: 'tsx', checked: true }, { name: 'jsx' }, { name: 'ts' }, { name: 'js' }], }]); const { fileTypes } = await (0, inquirer_1.prompt)([{ name: 'fileTypes', message: 'Which file types do you want to output? (default: component file only)', type: 'checkbox', choices: [{ name: 'index', checked: true }, { name: 'storybook' }, { name: 'test' }], }]); const { testMatch } = await (0, inquirer_1.prompt)([{ name: 'testMatch', message: 'What test matches do you use?', type: 'list', choices: [{ name: 'test', checked: true }, { name: 'spec' }], }]); const json = { extension: fileExt, types: fileTypes, testMatch, }; await (0, promises_1.writeFile)((0, path_1.join)(process.cwd(), '.cpoorc'), JSON.stringify(json, null, 2)); this.log((0, prefix_1.success)(), 'initialize "cpoo" :)'); this.log('\n'); this.log((0, prefix_1.info)(), 'next, you can use "cpoo generate"'); this.log((0, prefix_1.info)(), 'bye bye :3'); } } exports.default = Init; Init.description = 'initialize "cpoo"'; Init.examples = [`$ cpoo init `];