Skip to content

Commit

Permalink
fix: sort everything in api_start2 object
Browse files Browse the repository at this point in the history
  • Loading branch information
gakada committed Sep 7, 2018
1 parent c136410 commit a5d85f0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
31 changes: 8 additions & 23 deletions handle-api.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,23 @@
const { readFileSync, outputJsonSync } = require('fs-extra')
const { spawnSync } = require('child_process')
const sortKeys = require('sort-keys')

const apiResponse = readFileSync(`${__dirname}/dist/api_start2`).toString()
const parseApi = s => sortKeys(JSON.parse(s.replace(/^.*svdata=/, '')).api_data, { deep: true })

const parseApi = s => {
try {
return JSON.parse(s.replace(/^.*svdata=/, '')).api_data
} catch (_) {
return null
}
const sh = (command, ...args) => {
process.stdout.write(spawnSync(command, args).stdout.toString())
}

const sortKeys = o => {
Object.keys(o)
.sort()
.forEach(k => {
const v = o[k]
delete o[k]
o[k] = v
})
}
const apiResponse = readFileSync(`${__dirname}/dist/api_start2`).toString()

const api = parseApi(apiResponse)

sortKeys(api.api_mst_const)

outputJsonSync(`${__dirname}/../kancolle-data/dist/api_start2.json`, api, { spaces: 2 })

console.log('saved api_start2.json')

const ts = new Date().toISOString().split('T')[0]

spawnSync('git', ['-C', `${__dirname}/../kancolle-data`, 'add', '.'])
spawnSync('git', ['-C', `${__dirname}/../kancolle-data`, 'commit', '-m', `"chore: autoupdate api_start2 for ${ts}"`])
spawnSync('git', ['-C', `${__dirname}/../kancolle-data`, 'push'])

console.log('pushed api_start2.json to kancolle-data')
sh('git', '-C', `${__dirname}/../kancolle-data`, 'add', '.')
sh('git', '-C', `${__dirname}/../kancolle-data`, 'commit', '--short', '-m', `"chore: autoupdate api_start2 for ${ts}"`)
sh('git', '-C', `${__dirname}/../kancolle-data`, 'push', '-q')
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"electron": "^3.0.0-beta.5",
"fs-extra": "^7.0.0"
"fs-extra": "^7.0.0",
"sort-keys": "^2.0.0"
}
}
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,10 @@ is-path-inside@^1.0.0:
dependencies:
path-is-inside "^1.0.1"

is-plain-obj@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e"

is-promise@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/is-promise/-/is-promise-2.1.0.tgz#79a2a9ece7f096e80f36d2b2f3bc16c1ff4bf3fa"
Expand Down Expand Up @@ -1334,6 +1338,12 @@ slice-ansi@1.0.0:
dependencies:
is-fullwidth-code-point "^2.0.0"

sort-keys@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/sort-keys/-/sort-keys-2.0.0.tgz#658535584861ec97d730d6cf41822e1f56684128"
dependencies:
is-plain-obj "^1.0.0"

source-map@^0.5.0:
version "0.5.7"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
Expand Down

0 comments on commit a5d85f0

Please sign in to comment.