gulp-sketch
Version:
SketchTool plugin for gulp
49 lines (39 loc) • 1.25 kB
text/coffeescript
{spawn} = require 'child_process'
through = require 'through2'
fs = require 'fs'
path = require 'path'
gutil = require 'gulp-util'
PLUGIN_NAME = 'gulp-sketch'
module.exports = (options = {}) ->
cmnd = 'sketchtool'
args = []
if options.export
args.push 'export'
args.push options.export
args.push '--formats=' + options.formats if options.formats
args.push '--scales=' + options.scales if options.scales
args.push '--items=' + options.items if options.items
args.push '--bounds=' + options.bounds if options.bounds
through.obj (file, encoding, callback) ->
unless file.isNull()
@push file
return callback()
src = file.path
tmp = path.dirname(src) + path.sep + '___tmp___' + path.basename(src).replace('.sketch', '')
program = spawn cmnd, args.concat src, '--output=' + tmp
program.stdout.on 'end', =>
for file_name in fs.readdirSync tmp
file_path = tmp + path.sep + file_name
f = new gutil.File
cwd: file.cwd
base: file.base
path: file.base + file_name
f.contents = fs.readFileSync file_path
@push f
fs.unlinkSync file_path
fs.rmdirSync tmp
callback()