bump dependencies and use filesystem for package

This commit is contained in:
Brendan Forster 2017-08-18 14:37:45 +10:00
parent a0c9fa6467
commit 176600b71d
2 changed files with 47 additions and 46 deletions

View file

@ -59,13 +59,13 @@
"express": "^4.15.0",
"extract-text-webpack-plugin": "^2.1.0",
"fs-extra": "^2.1.2",
"got": "^6.3.0",
"html-webpack-plugin": "^2.28.0",
"klaw-sync": "^1.1.2",
"legal-eagle": "0.15.0",
"mocha": "^3.4.2",
"node-native-loader": "^1.1.1",
"node-sass": "^4.5.2",
"octicons": "^6.0.1",
"parallel-webpack": "^1.6.1",
"request": "^2.72.0",
"rimraf": "^2.5.2",

View file

@ -12,62 +12,63 @@
const fs = require('fs')
const process = require('process')
const xml2js = require('xml2js')
const got = require('got')
const path = require('path')
const toCamelCase = require('to-camel-case')
console.log('Downloading latest version of octicon sprite svg')
const filePath = path.resolve(
__dirname,
'..',
'node_modules',
'octicons',
'build',
'sprite.octicons.svg'
)
got('https://github.com/primer/octicons/raw/master/build/sprite.octicons.svg')
.then(res => {
xml2js.parseString(res.body, function(err, result) {
const viewBoxRe = /0 0 (\d+) (\d+)/
const out = fs.createWriteStream(
path.resolve(__dirname, '../app/src/ui/octicons/octicons.generated.ts')
)
const file = fs.readFileSync(filePath)
out.write('/*\n')
out.write(
' * This file is automatically generated by the generate-octicons tool.\n'
)
out.write(' * Manually changing this file will only lead to sadness.\n')
out.write(' */\n\n')
xml2js.parseString(file, function(err, result) {
const viewBoxRe = /0 0 (\d+) (\d+)/
const out = fs.createWriteStream(
path.resolve(__dirname, '../app/src/ui/octicons/octicons.generated.ts')
)
out.write('export class OcticonSymbol {\n')
out.write('/*\n')
out.write(
' * This file is automatically generated by the generate-octicons tool.\n'
)
out.write(' * Manually changing this file will only lead to sadness.\n')
out.write(' */\n\n')
out.write(
'\n public constructor(public w: number, public h: number, public d: string) { }\n\n'
)
let count = 0
result.svg.symbol.forEach(function(symbol) {
count++
out.write('export class OcticonSymbol {\n')
const id = symbol.$.id
const viewBox = symbol.$.viewBox
const pathData = symbol.path[0].$.d
out.write(
'\n public constructor(public w: number, public h: number, public d: string) { }\n\n'
)
let count = 0
result.svg.symbol.forEach(function(symbol) {
count++
const viewBoxMatch = viewBoxRe.exec(viewBox)
const id = symbol.$.id
const viewBox = symbol.$.viewBox
const pathData = symbol.path[0].$.d
if (!viewBoxMatch) {
console.error(`Unexpected viewBox format for ${id}`)
process.exit(1)
}
const viewBoxMatch = viewBoxRe.exec(viewBox)
const [, w, h] = viewBoxMatch
const jsFriendlyName = toCamelCase(id)
if (!viewBoxMatch) {
console.error(`Unexpected viewBox format for ${id}`)
process.exit(1)
}
out.write(
` public static get ${jsFriendlyName}() { return new OcticonSymbol(${w}, ${h}, '${pathData}') }\n`
)
})
const [, w, h] = viewBoxMatch
const jsFriendlyName = toCamelCase(id)
out.write('}\n')
out.end()
console.log(`Wrote ${count} octicons`)
})
})
.catch(err => {
console.log(`Failed downloading octicon sprite svg: ${err.message}`)
process.exit(1)
out.write(
` public static get ${jsFriendlyName}() { return new OcticonSymbol(${w}, ${h}, '${pathData}') }\n`
)
})
out.write('}\n')
out.end()
console.log(`Wrote ${count} octicons`)
})