Convert update octicons from script to grunt task

This commit is contained in:
Kevin Sawicki
2014-02-03 14:14:28 -08:00
parent a36cc3a609
commit e4a65ca810
3 changed files with 22 additions and 33 deletions

View File

@@ -25,7 +25,6 @@
"grunt-peg": "~1.1.0",
"grunt-shell": "~0.3.1",
"harmony-collections": "~0.3.8",
"js-yaml": "~2.1.0",
"json-front-matter": "~0.1.3",
"rcedit": "~0.1.2",
"request": "~2.27.0",

View File

@@ -0,0 +1,22 @@
path = require 'path'
module.exports = (grunt) ->
grunt.registerTask 'update-octicons', 'Update octicon font and LESS variables', ->
pathToOcticons = path.resolve('..', 'octicons')
if grunt.file.isDir(pathToOcticons)
# Copy font-file
fontSrc = path.join(pathToOcticons, 'octicons', 'octicons.woff')
fontDest = path.resolve('static', 'octicons.woff')
grunt.file.copy(fontSrc, fontDest)
# Update Octicon UTF codes
glyphsSrc = path.join(pathToOcticons, 'data', 'glyphs.yml')
output = []
for {css, code} in grunt.file.readYAML(glyphsSrc)
output.push "@#{css}: \"\\#{code}\";"
octiconUtfDest = path.resolve('static', 'variables', 'octicon-utf-codes.less')
grunt.file.write(octiconUtfDest, "#{output.join('\n')}\n")
else
grunt.log.error("octicons repo must be cloned to #{pathToOcticons}")
false

View File

@@ -1,32 +0,0 @@
#!/usr/bin/env coffee
usage = """
Usage:
update-octicons PATH-TO-OCTICONS
"""
path = require 'path'
fs = require 'fs'
YAML = require 'js-yaml'
scriptPath = process.argv[1]
pathToOcticons = process.argv[2] ? path.join(process.env.HOME, 'github', 'octicons')
atomDir = path.resolve(scriptPath, "../../..")
unless fs.existsSync(pathToOcticons)
console.error(usage)
process.exit(1)
# Copy font-file
fontSrc = path.join(pathToOcticons, 'octicons', 'octicons.woff')
fontDest = path.join(atomDir, 'static', 'octicons.woff')
fs.createReadStream(fontSrc).pipe(fs.createWriteStream(fontDest))
# Update Octicon UTF codes
glyphsSrc = path.join(pathToOcticons, 'data', 'glyphs.yml')
octiconUtfDest = path.join atomDir, 'static', 'variables', 'octicon-utf-codes.less'
output = []
for {css, code} in YAML.load(fs.readFileSync(glyphsSrc).toString())
output.push "@#{css}: \"\\#{code}\";"
fs.writeFileSync octiconUtfDest, "#{output.join('\n')}\n"