| 401 | * Get all the inputs declared in the inputs/index.ts file. |
| 402 | */ |
| 403 | export function getInputs() { |
| 404 | const inputsDir = resolve(packagesDir, 'inputs/src') |
| 405 | const exportFile = resolve(inputsDir, 'index.ts') |
| 406 | const file = fs.readFileSync(exportFile, { encoding: 'utf-8' }) |
| 407 | const results = file |
| 408 | .split(/\r?\n/) |
| 409 | .filter((line) => !!line.trim()) |
| 410 | .map((line) => { |
| 411 | const matches = line.match( |
| 412 | /^import {\s([a-zA-Z ]+)\s} from '\.\/inputs\/([a-zA-Z]+)'$/ |
| 413 | ) |
| 414 | if (matches) { |
| 415 | const [, rawName, fileName] = matches |
| 416 | return { rawName, fileName } |
| 417 | } |
| 418 | return false |
| 419 | }) |
| 420 | .filter((value) => !!value) |
| 421 | .map(({ rawName, fileName }) => { |
| 422 | const names = rawName.split(' ') |
| 423 | const name = names[names.length - 1] |
| 424 | const filePath = resolve(inputsDir, `./inputs/${fileName}.ts`) |
| 425 | return { |
| 426 | name, |
| 427 | filePath, |
| 428 | fileName, |
| 429 | } |
| 430 | }) |
| 431 | if (!results.length) { |
| 432 | msg.error(`Failed to parse exports from index.ts`) |
| 433 | process.exit(1) |
| 434 | } |
| 435 | return results |
| 436 | } |