UNPKG

@coderebus/react-archetype

Version:

React-archetype is a cli tool (or a generator) that will generate apps based on the rendering pattern (CSR,SSR, SSG, ISR etc) of your choice.

139 lines (138 loc) 5.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.commonQuestionsProjectSetup = void 0; const tslib_1 = require("tslib"); const fs_1 = tslib_1.__importDefault(require("fs")); const path_1 = tslib_1.__importDefault(require("path")); const constants_1 = require("./constants"); const fileDirOps_1 = require("./fileDirOps"); const helpers_1 = require("./helpers"); const filePath = path_1.default.join(process.cwd(), constants_1.appConstants.ARCHETYPE_CONFIG); let packages = {}; let apps = {}; let appNames = []; if ((0, fileDirOps_1.dirFileExists)(filePath)) { const archetypeJson = JSON.parse(fs_1.default.readFileSync(filePath, 'utf8')); packages = archetypeJson.packages; apps = archetypeJson.apps; appNames = Object.keys(apps); } const commonQuestionsProjectSetup = (isStandalone, monorepoWorkspace, directories) => [ { type: 'input', name: 'itemName', message: 'What would you like to name your app?', default: 'my_app', validate: (value) => { if (appNames.includes(value)) { return `${value} already exists. Please provide a different name...`; } else { return true; } }, }, { type: 'list', name: 'appType', message: 'What would you like to create today? (Use arrow keys to navigate)', choices: Object.keys(constants_1.appTypes), }, { when: (data) => data.appType === 'NEXT', type: 'list', name: 'nextVer', message: 'What version of Next.js would you like to use?', choices: constants_1.nextVersion, }, { when: (data) => data.nextVer === '13', type: 'confirm', name: 'isAppRouter', message: 'Do you want to use the new Next.js App Router?', default: true, }, { when: (data) => data.appType === 'NEXT' && false, type: 'list', name: 'archType', message: 'What type of next rendering pattern do you want to use?', choices: Object.values(constants_1.nextArchTypes), }, { when: (data) => data.appType === 'REACT', type: 'list', name: 'archType', message: 'What type of react rendering pattern do you want to use?', choices: Object.values(constants_1.reactArchTypes), }, { when: (data) => !Object.entries(constants_1.webpackArchTypes).some(([, v]) => v === data.archType) && !data.isAppRouter, name: 'isMfe', type: 'confirm', message: 'Do you want to setup Module Federation for your app?', default: true, }, { when: (data) => data.isMfe === true, name: 'mfeType', type: 'list', message: 'What kind of micro frontend is this app going to be?', choices: constants_1.mfeTypes, }, { when: !isStandalone && monorepoWorkspace, name: 'basePath', type: 'confirm', message: 'Do you want to run your application from deep/base path?', default: true, }, { when: (data) => data.basePath === true, type: 'input', name: 'customBasePath', message: 'Please enter the base path:', default: '/docs', }, { when: !isStandalone && monorepoWorkspace && !directories.includes('apps'), type: 'confirm', name: 'appsDir', message: 'We highly recommend to create your app in an "apps" directory. Do you want us to create the "apps" directory?', default: true, }, { when: (data) => data.appsDir === false && !isStandalone && monorepoWorkspace && !directories.includes('apps'), type: 'list', name: 'parentDir', message: 'Where would you like to create your app?', choices: directories, }, { when: isStandalone || (monorepoWorkspace && (0, helpers_1.identifyPackageManager)(process.cwd()).command === ''), type: 'list', name: 'cmdType', message: 'Which package manager would you like to use?', choices: Object.keys(constants_1.commandTypes), }, { when: !isStandalone && monorepoWorkspace && !Object.keys(constants_1.customPackages).every(p => p in packages), type: 'checkbox', name: 'customPackages', message: `Which packages do you want to add to your project?`, choices: Object.keys(constants_1.customPackages) .filter(p => !(p in packages)) .map(p => ({ name: `${p} - ${constants_1.customPackagesDescription[p]}`, value: p, })), }, { when: (data) => !isStandalone && monorepoWorkspace && data.customPackages && data.customPackages.length > 0, name: 'customPackagesRename', type: 'confirm', message: 'Do you want to rename the selected packages?', default: false, }, ]; exports.commonQuestionsProjectSetup = commonQuestionsProjectSetup;