Last active
August 29, 2015 14:27
-
-
Save kaustavha/f2ba6aded5d946813eef to your computer and use it in GitHub Desktop.
generator runner
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
# This script, when placed inside the meteor-kitchen-examples root project folder | |
# Can be used to run all the examples and generate output for jade, coffee and plain from json and yaml | |
fs = require 'fs' | |
{spawn} = require 'child_process' | |
path = require 'path' | |
async = require 'async' | |
dir = fs.readdirSync(__dirname) | |
dir = dir.filter((e, i, a) -> if e.indexOf('.') is -1 then return e) | |
humandirs = dir.filter((e, i, a) -> if e.indexOf('human') isnt -1 then return e) | |
dir = dir.filter((e, i, a) -> if e.indexOf('human') is -1 then return e) | |
iter = (e, cb) -> | |
console.log("Processing #{e}") | |
yamlconfig = "#{e}.yaml" | |
jsonconfig = "#{e}.json" | |
cwd = path.join(__dirname, e) | |
spawnConfig = {cwd: cwd, uid: 0} | |
out = path.join(cwd, e) | |
outjc = out + '_jade_coffee' | |
outjcyaml = outjc + '_yaml' | |
outyaml = out + '_yaml' | |
debug = 'debug_' | |
mkyamlstore = '' | |
mkyamljcstore = '' | |
mkjsonstore = '' | |
mkjsonjcstore = '' | |
done = 0 | |
handleEnd = (type, store) -> | |
fs.writeFileSync("#{cwd}/debug_#{type}_#{e}.txt", store) | |
if done is 3 then cb() else done++ | |
# yaml | |
mkyaml = spawn('meteor-kitchen', [yamlconfig, "#{outyaml}"], spawnConfig) | |
mkyamlstore += "Spawning: meteor-kitchen #{yamlconfig} #{outyaml} \n" | |
mkyaml.stdout.on('data', (d) -> mkyamlstore += d) | |
mkyaml.on('close', -> handleEnd('yaml', mkyamlstore)) | |
#yaml -> jade & coffescript | |
mkyamljc = spawn('meteor-kitchen', ['-jc', yamlconfig, "#{outjcyaml}"], spawnConfig) | |
mkyamljcstore += "Spawning: meteor-kitchen -jc #{yamlconfig} #{outjcyaml} \n" | |
mkyamljc.stdout.on('data', (d) -> mkyamljcstore += d) | |
mkyamljc.on('close', -> handleEnd('yaml_jc', mkyamljcstore)) | |
# json -> jade & coffescript | |
mkjsonjc = spawn('meteor-kitchen', ['-jc', jsonconfig, "#{outjc}"], spawnConfig) | |
mkjsonjcstore += "Spawning: meteor-kitchen -jc #{jsonconfig} #{outjc} \n" | |
mkjsonjc.stdout.on('data', (d) -> mkjsonjcstore += d) | |
mkjsonjc.on('close', -> handleEnd('json_jc', mkjsonjcstore)) | |
# json | |
mkjson = spawn('meteor-kitchen', [jsonconfig, "#{out}"], spawnConfig) | |
mkjsonstore += "Spawning: meteor-kitchen -jc #{jsonconfig} #{out} \n" | |
mkjson.stdout.on('data', (d) -> mkjsonstore += d) | |
mkjson.on('close', -> handleEnd('json', mkjsonjcstore)) | |
callback = () -> | |
humandirs.forEach((e, i, a) -> | |
console.log("Processing #{e}") | |
cwd = path.join(__dirname, e) | |
data = '' | |
outputfilepath = path.join(cwd, e) | |
inputfilepath = path.join(cwd, "#{e}.txt") | |
mkhuman = spawn('meteor-kitchen', [inputfilepath, outputfilepath], {cwd: cwd, uid: 0}) | |
data += "Spawning: meteor-kitchen #{inputfilepath} #{outputfilepath} \n" | |
mkhuman.stdout.on('data', (d) -> data += d) | |
mkhuman.on('close', -> fs.writeFileSync("#{cwd}/debug.txt", data)) | |
) | |
async.eachSeries(dir, iter, callback) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment