(genPath)
| 229 | ` |
| 230 | |
| 231 | export async function helper(genPath) { |
| 232 | const testsPath = getTestRoot(genPath) |
| 233 | |
| 234 | output.print('Creating a new helper') |
| 235 | output.print('--------------------------') |
| 236 | |
| 237 | return inquirer |
| 238 | .prompt([ |
| 239 | { |
| 240 | type: 'input', |
| 241 | name: 'name', |
| 242 | message: 'Name of a Helper', |
| 243 | validate: val => !!val, |
| 244 | }, |
| 245 | { |
| 246 | type: 'input', |
| 247 | name: 'filename', |
| 248 | message: 'Where should it be stored', |
| 249 | default: answers => `./${answers.name.toLowerCase()}_helper.${extension}`, |
| 250 | }, |
| 251 | ]) |
| 252 | .then(result => { |
| 253 | const name = ucfirst(result.name) |
| 254 | const helperFile = path.join(testsPath, result.filename) |
| 255 | const dir = path.dirname(helperFile) |
| 256 | if (!fileExists(dir)) fs.mkdirSync(dir) |
| 257 | |
| 258 | if (!safeFileWrite(helperFile, helperTemplate.replace(/{{name}}/g, name))) return |
| 259 | output.success(`Helper for ${name} was created in ${helperFile}`) |
| 260 | output.print(`Update your config file (add to ${colors.cyan('helpers')} section): |
| 261 | |
| 262 | helpers: { |
| 263 | ${name}: { |
| 264 | require: '${result.filename}', |
| 265 | }, |
| 266 | }, |
| 267 | `) |
| 268 | }) |
| 269 | } |
| 270 | |
| 271 | import { fileURLToPath } from 'url' |
| 272 | const __dirname = path.dirname(fileURLToPath(import.meta.url)) |
nothing calls this directly
no test coverage detected