forked from hoodiehq/hoodie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundle-client.js
34 lines (26 loc) · 1.14 KB
/
bundle-client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module.exports = bundleClient
var fs = require('fs')
var path = require('path')
var log = require('npmlog')
function bundleClient (config, callback) {
var hoodieClientModulePath = path.dirname(require.resolve('@hoodie/client/package.json'))
var hoodieClientPath = path.join(hoodieClientModulePath, 'dist/hoodie.js')
var bundleTargetPath = path.join(config.paths.data, 'client.js')
// https://github.com/hoodiehq/hoodie-client/issues/34
// var hoodieMinPath = path.join(hoodieClientModulePath, 'dist/hoodie.min.js')
log.silly('bundle', 'bundling ' + hoodieClientPath + ' into ' + bundleTargetPath)
var stream = fs.createReadStream(hoodieClientPath)
stream.pipe(fs.createWriteStream(bundleTargetPath))
stream.on('error', callback)
stream.on('end', function () {
// TODO: pass client configuration to constructor
fs.appendFile(bundleTargetPath, '\n\nhoodie = new Hoodie()', function (error) {
if (error) {
return callback(error)
}
log.silly('bundle', 'appended Hoodie init code to ' + bundleTargetPath)
log.info('bundle', 'bundled Hoodie client into ' + bundleTargetPath)
callback()
})
})
}