forked from Tokyo-Metro-Gov/covid19
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }, | ||
}) | ||
} | ||
})() |