diff --git a/lib/import-associated-files.js b/lib/import-associated-files.js index 3b2db3c2..90bb9e0c 100644 --- a/lib/import-associated-files.js +++ b/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) => { @@ -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() } @@ -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 diff --git a/nodes/setup/object.js b/nodes/setup/object.js index 2032d71d..360cc6cf 100644 --- a/nodes/setup/object.js +++ b/nodes/setup/object.js @@ -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 @@ -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 }