()
| 93 | ` |
| 94 | |
| 95 | const main = async () => { |
| 96 | const answers = await inquirer.prompt([ |
| 97 | { |
| 98 | type: 'input', |
| 99 | name: 'storeFileName', |
| 100 | message: 'Enter the name of the store file: (eg. device)', |
| 101 | }, |
| 102 | { |
| 103 | type: 'input', |
| 104 | name: 'actionName', |
| 105 | message: 'Enter the base name for the action: (eg. getDevice)', |
| 106 | }, |
| 107 | { |
| 108 | type: 'checkbox', |
| 109 | name: 'filesToGenerate', |
| 110 | message: 'Which files do you want to generate?', |
| 111 | choices: ['actions', 'reducers', 'selectors', 'middleware'], |
| 112 | default: ['actions', 'reducers', 'selectors', 'middleware'], |
| 113 | }, |
| 114 | ]) |
| 115 | |
| 116 | const { storeFileName, actionName, filesToGenerate } = answers |
| 117 | |
| 118 | if (filesToGenerate.includes('actions')) { |
| 119 | await createHeaderFile( |
| 120 | generateActionFile(actionName), |
| 121 | `pkg/webui/console/store/actions/${storeFileName}.js`, |
| 122 | ) |
| 123 | } |
| 124 | if (filesToGenerate.includes('reducers')) { |
| 125 | await createHeaderFile( |
| 126 | generateReducerFile(storeFileName, actionName), |
| 127 | `pkg/webui/console/store/reducers/${storeFileName}.js`, |
| 128 | ) |
| 129 | // Add the reducer to the index file |
| 130 | const reducerIndexFile = `pkg/webui/console/store/reducers/index.js` |
| 131 | originalReducerIndexContent = await fs.readFile(reducerIndexFile, 'utf8') |
| 132 | let reducerIndexContent = originalReducerIndexContent |
| 133 | // Find the last import statement and add the new import statement after it |
| 134 | const lastImportIndex = reducerIndexContent.lastIndexOf('import ') |
| 135 | const importStatement = `import ${snakeCaseToCamelCase(storeFileName)} from './${storeFileName}'\n` |
| 136 | reducerIndexContent = insertAtLineAtIndex(reducerIndexContent, lastImportIndex, importStatement) |
| 137 | // Find the last item of the exported array and add the new reducer after it |
| 138 | const lastExportIndex = reducerIndexContent.lastIndexOf('})') |
| 139 | const reducerExport = ` ${snakeCaseToCamelCase(storeFileName)},\n` |
| 140 | reducerIndexContent = insertAtLineAtIndex(reducerIndexContent, lastExportIndex, reducerExport) |
| 141 | |
| 142 | await fs.writeFile(reducerIndexFile, reducerIndexContent) |
| 143 | } |
| 144 | if (filesToGenerate.includes('selectors')) { |
| 145 | await createHeaderFile( |
| 146 | generateSelectorFile(actionName), |
| 147 | `pkg/webui/console/store/selectors/${storeFileName}.js`, |
| 148 | ) |
| 149 | } |
| 150 | if (filesToGenerate.includes('middleware')) { |
| 151 | await createHeaderFile( |
| 152 | generateMiddlewareFile(storeFileName, actionName), |
nothing calls this directly
no test coverage detected