Skip to content

Commit

Permalink
fix clone external chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
mmckegg committed Mar 31, 2017
1 parent 59b0e8c commit cae8111
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 32 deletions.
18 changes: 2 additions & 16 deletions lib/import-associated-files.js
@@ -1,8 +1,6 @@
var resolvePath = require('path').resolve
var getDirectory = require('path').dirname
var fs = require('fs')
var each = require('async-each')
var getExt = require('path').extname

module.exports = function (descriptor, originalDirectory, targetDirectory, cb) {
each(getFiles(descriptor), (file, next) => {
Expand All @@ -12,19 +10,7 @@ module.exports = function (descriptor, originalDirectory, targetDirectory, cb) {
if (exists) {
fs.exists(to, (exists) => {
if (!exists) {
if (getExt(from) === '.json') {
// handle external chunks
fs.readFile(from, 'utf8', (err, data) => {
if (err) return next(err)
module.exports(JSON.parse(data), getDirectory(from), getDirectory(to), (err) => {
if (err) return next(err)
fs.writeFile(to, data, next)
})
})
} else {
// handle samples, etc
copyFile(from, to, next)
}
copyFile(from, to, next)
} else {
next()
}
Expand All @@ -43,7 +29,7 @@ function copyFile (from, to, cb) {
function getFiles (descriptor) {
var result = []
JSON.stringify(descriptor, function (key, value) {
if (value && (value.node === 'AudioBuffer' || value.node === 'externalChunk')) {
if (value && (value.node === 'AudioBuffer')) {
result.push(value.src)
}
return value
Expand Down
35 changes: 19 additions & 16 deletions nodes/setup/object.js
Expand Up @@ -169,10 +169,7 @@ function Setup (parentContext) {
}

node.importChunk = function (descriptor, originalDirectory, cb) {
var info = context.nodeInfo.lookup[descriptor.node]
var id = node.chunks.resolveAvailable(descriptor.id)
var targetPath = join(context.cwd, id + '.json')

descriptor = extend(descriptor, { id: id })

// ensure has default output
Expand All @@ -186,24 +183,30 @@ function Setup (parentContext) {
}
}

importAssociatedFiles(descriptor, originalDirectory, context.cwd, function (err) {
if (err) return cb && cb(err)
if (info.external) {
// duplicate external file
context.fs.writeFile(targetPath, JSON.stringify(descriptor), function (err) {
if (descriptor.node === 'externalChunk') {
var originalPath = join(originalDirectory, descriptor.src)
var targetPath = join(context.cwd, id + '.json')
context.fs.readFile(originalPath, 'utf8', function (err, data) {
if (err) return cb && cb(err)
var externalDescriptor = JSON.parse(data)
importAssociatedFiles(externalDescriptor, originalDirectory, context.cwd, function (err) {
if (err) return cb && cb(err)
node.chunks.push({
node: 'externalChunk',
src: context.fileObject.relative(targetPath)
context.fs.writeFile(targetPath, JSON.stringify(externalDescriptor), function (err) {
if (err) return cb && cb(err)
node.chunks.push(extend(descriptor, {
src: context.fileObject.relative(targetPath)
}))
cb && cb(null, id)
})
cb && cb(null, id)
})
} else {
// duplicate local chunk
})
} else {
importAssociatedFiles(descriptor, originalDirectory, context.cwd, function (err) {
if (err) return cb && cb(err)
node.chunks.push(descriptor)
cb && cb(null, id)
}
})
})
}

return id
}
Expand Down

0 comments on commit cae8111

Please sign in to comment.