Skip to content

Commit

Permalink
tool/generateDataConverters.ts: 追加
Browse files Browse the repository at this point in the history
  • Loading branch information
nard-tech committed Mar 14, 2021
1 parent d604b49 commit 86404a0
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tool/generateDataConverters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { promises as fs } from 'fs'
import { camelCase, upperFirst } from 'lodash'
// eslint-disable-next-line import/order
import * as path from 'path'
import * as quicktype from 'quicktype'
// TODO: rimraf は Node v12.0.0 でビルトインに追加されたので
// Node.js のバージョンアップに合わせて除去する
import { sync as rimrafSync } from 'rimraf'

const basePath = path.dirname(__dirname)

const inputPath = path.resolve(basePath, 'data')
const outputPath = path.resolve(basePath, 'libraries', 'data_converter')

// ディレクトリ utils/data_converter を削除する
rimrafSync(outputPath)
;(async () => {
// ディレクトリ utils/data_converter を作成する
await fs.mkdir(outputPath, { recursive: true })
// ディレクトリ data 内のファイル名の配列
const dataFileNames = await fs.readdir(inputPath)

for (let index = 0; index < dataFileNames.length; index++) {
const dataFileName = dataFileNames[index]
const dataFileBaseName = path.parse(dataFileName).name
const pascalFileName = upperFirst(camelCase(dataFileBaseName))

const converterFilePath = path.resolve(
outputPath,
`convert${pascalFileName}.ts`
)
const dataFilePath = path.resolve(inputPath, dataFileName)

await quicktype.main({
lang: 'ts',
topLevel: pascalFileName,
out: converterFilePath,
src: [dataFilePath],
rendererOptions: { 'nice-property-names': 'true' },
})
}
})()

0 comments on commit 86404a0

Please sign in to comment.