-
Notifications
You must be signed in to change notification settings - Fork 31
/
bin.js
executable file
·57 lines (51 loc) · 1.96 KB
/
bin.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env node
var modules = process.argv.slice(2)
var browserify = require('browserify')
var through = require('through')
var fs = require('fs')
var path = require('path')
makeBuildInstructions(modules, includeModules)
function makeBuildInstructions (modules, cb) {
getWantedModules(modules, cb)
}
function getWantedModules (modules, cb) {
var npmModules = []
var writeFile = false
if (modules === '') console.log('Please include modules -maps/-m or -tables/-t')
modules.forEach(function whichModules (module) {
if (module === '-m' || module === '-maps') return npmModules.push('sheetsee-maps')
if (module === '-t' || module === '-tables') return npmModules.push('sheetsee-tables')
if (module === '--save') {
writeFile = true
return
}
console.error(module + ' does not exist, please use -maps/-m or -tables/-t')
})
cb(npmModules, writeFile)
}
function includeModules (npmModules, writeFile) {
if (npmModules.length === 0) return console.error('Aborted build, no modules required')
var extendString = "if (typeof window.Sheetsee === 'undefined') window.Sheetsee = {};" +
" window.Sheetsee = require('sheetsee-core'); var extend = require('lodash.assign'); extend(window.Sheetsee, "
var counter = npmModules.length
npmModules.forEach(function addModules (module) {
counter--
if (counter !== 0) extendString = extendString + "require('" + module + "'), "
if (counter === 0) extendString = extendString + "require('" + module + "')); module.exports = Sheetsee;"
})
runBuild(extendString, writeFile)
}
function runBuild (extendString, writeFile) {
var dataStream = through()
var origDir = process.cwd()
process.chdir(__dirname)
var b = browserify()
b.files.push(dataStream)
if (writeFile) {
var output = path.join(origDir, 'sheetsee.js')
b.bundle().pipe(fs.createWriteStream(output))
} else b.bundle().pipe(process.stdout)
dataStream.queue(extendString)
dataStream.queue(null)
process.chdir(origDir)
}