Skip to content

Commit

Permalink
Ensure file are generated syncronously
Browse files Browse the repository at this point in the history
  • Loading branch information
emmenko committed Jun 11, 2014
1 parent e8e6646 commit 502878b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/coffee/producttypegenerator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ class ProductTypeGenerator
prettified = JSON.stringify productTypeDefinition, null, 4

fileName = "#{target}/#{prefix}-#{productTypeDefinition[@PRODUCT_TYPE_NAME]}.json"
fs.writeFile fileName, prettified, 'utf8', (error) ->
if error
console.error "Error while writing file #{fileName}: #{error}"
fs.writeFileSync fileName, prettified, 'utf8'

module.exports = ProductTypeGenerator
8 changes: 4 additions & 4 deletions src/coffee/run.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ readCsvPromise = (path) ->
zipFiles = (path, filename) ->
zip = new JSZip()
zip.folder('product-type-json')
generatedFiles = fs.readdirSync(path)
generatedFiles = fs.readdirSync(path).filter (file) -> file.match(/\.json/)
for file in generatedFiles
# TODO: filter only *.json files
zip.file("product-type-json/#{file}", fs.readFileSync("#{path}/#{file}"))
zip.file("product-type-json/#{file}", fs.readFileSync("#{path}/#{file}", 'utf8'))
buffer = zip.generate type: 'nodebuffer'
fs.writeFileSync "#{path}/#{filename}.zip", buffer
fs.writeFileSync "#{path}/#{filename}.zip", buffer, 'utf8'

Q.spread [readCsvPromise(argv.types), readCsvPromise(argv.attributes)], (types, attributes) ->
generator = new ProductTypeGenerator
# make sure everything runs syncronous, otherwise zipped files will be empty (they will be not there)
generator.run types, attributes, argv.target, argv.retailer
zipFiles(argv.target, argv.zipFileName) if argv.zip
.fail (error) ->
Expand Down

0 comments on commit 502878b

Please sign in to comment.