inputs.ts 763 B

1234567891011121314151617181920
  1. import path from 'path'
  2. import fs from 'fs'
  3. export const INPUTS_LOCATION = path.join(__dirname, '../../inputs')
  4. export const INPUT_TYPES = ['classes', 'schemas', 'entityBatches'] as const
  5. export type InputType = typeof INPUT_TYPES[number]
  6. export type FetchedInput<Schema = any> = { fileName: string; data: Schema }
  7. export const getInputsLocation = (inputType: InputType) => path.join(INPUTS_LOCATION, inputType)
  8. export function getInputs<Schema = any>(inputType: InputType): FetchedInput<Schema>[] {
  9. return fs.readdirSync(getInputsLocation(inputType)).map((fileName) => {
  10. const inputJson = fs.readFileSync(path.join(INPUTS_LOCATION, inputType, fileName)).toString()
  11. return {
  12. fileName,
  13. data: JSON.parse(inputJson) as Schema,
  14. }
  15. })
  16. }