UNPKG

cr-react-cli

Version:

Create react files with a single command

39 lines (38 loc) 2.24 kB
var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); // Libs const path_1 = __importDefault(require("path")); // Helpers const path_2 = require("../../utils/path"); const object_1 = require("../../utils/object"); const template_1 = require("../../utils/template"); const file_path_1 = __importDefault(require("../../file-path")); // Configuration const configuration_1 = require("../../configuration"); // Templates const story_template_1 = __importDefault(require("../../templates/story/story.template")); // Base const base_action_1 = __importDefault(require("../base.action")); class CreateStoryAction extends base_action_1.default { async handle(inputs, options) { const config = (0, object_1.merge)(options, inputs === null || inputs === void 0 ? void 0 : inputs.configOverride, (0, configuration_1.loadScopeConfiguration)('storybook')); const filePath = new file_path_1.default({ config: config, relativeToFilePath: path_1.default.parse(inputs.filePath).dir, name: inputs.name || inputs.componentName, namePlaceholders: Object.assign({}, inputs.namePlaceholders), pathPlaceholders: { '{componentPath}': path_1.default.parse(inputs.filePath).dir, }, sourcePath: (0, configuration_1.getSourcePath)(), fileExtension: config.typescript ? 'tsx' : 'jsx', }); const relativeImportPath = (0, path_2.removeExtension)(path_1.default.join(path_1.default.relative(filePath.dir, path_1.default.parse(inputs.filePath).dir), path_1.default.parse(inputs.filePath).base)); const template = new story_template_1.default(inputs.componentName, (0, path_2.fixRelativePath)(relativeImportPath), config, inputs === null || inputs === void 0 ? void 0 : inputs.componentDefaultImport, inputs.componentType === 'default' ? 'component' : inputs.componentType).build(); await (0, path_2.handlePathCheck)(filePath.dir); await this.create(filePath.full, (0, template_1.formatTemplate)(template)); } } exports.default = CreateStoryAction;