package: package refactoring
This commit is contained in:
parent
92f7f1dba8
commit
fb768e12ef
145 changed files with 175 additions and 847 deletions
|
|
@ -1,31 +1,15 @@
|
|||
var browserify = require('browserify'),
|
||||
uglifyify = require('uglifyify'),
|
||||
through = require('through'),
|
||||
minimatch = require('minimatch').Minimatch,
|
||||
licensify = require('licensify'),
|
||||
exorcist = require('exorcist'),
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
var build = require('./build'),
|
||||
babelify = require('babelify'),
|
||||
prod = process.argv.indexOf('--prod') != -1,
|
||||
fast = process.argv.indexOf('--fast') != -1,
|
||||
watch = process.argv.indexOf('--watch') != -1,
|
||||
autoRefresh = process.argv.indexOf('--auto-refresh') != -1,
|
||||
b
|
||||
|
||||
var inputPath = path.resolve(__dirname + '/../src/browser/js/index.js'),
|
||||
outputPath = path.resolve(__dirname + '/../app/browser/scripts.js')
|
||||
watch = process.argv.includes('--watch'),
|
||||
prod = process.argv.includes('--prod'),
|
||||
through = require('through'),
|
||||
minimatch = require('minimatch').Minimatch
|
||||
|
||||
|
||||
var ignoreList = ['**/*.min.js', '**/jquery.ui.js'],
|
||||
ignoreWrapper = function(transform){
|
||||
var ignores = ['**/*.min.js', '**/jquery.ui.js', 'gyronorm.complete.min.js'],
|
||||
transformWrapper = function(transform){
|
||||
return function(file, opts){
|
||||
if (
|
||||
ignoreList.some(function(pattern) {
|
||||
var match = minimatch(pattern)
|
||||
return match.match(file)
|
||||
})
|
||||
) {
|
||||
if (ignores.some(pattern => minimatch(pattern).match(file))) {
|
||||
return through()
|
||||
} else {
|
||||
return transform(file, opts)
|
||||
|
|
@ -33,37 +17,34 @@ var ignoreList = ['**/*.min.js', '**/jquery.ui.js'],
|
|||
}
|
||||
}
|
||||
|
||||
if (prod) console.warn('\x1b[36m%s\x1b[0m', 'Building minified js bundle for production... This may take a while... ')
|
||||
var transforms = [
|
||||
[transformWrapper(babelify), {presets: ['env']}]
|
||||
]
|
||||
|
||||
|
||||
var plugins = [licensify]
|
||||
|
||||
if (watch) plugins.push(require('watchify'))
|
||||
|
||||
b = browserify(inputPath, {
|
||||
debug:!fast,
|
||||
insertGlobals:fast,
|
||||
noParse: ignoreList,
|
||||
cache: {},// needed by watchify
|
||||
packageCache: {},// needed by watchify
|
||||
plugin: plugins
|
||||
})
|
||||
|
||||
b = b.transform(ignoreWrapper(babelify), {presets: ["env"]})
|
||||
|
||||
if (prod) b = b.transform(ignoreWrapper(uglifyify), {global: true})
|
||||
|
||||
|
||||
if (watch) {
|
||||
b.on('update', bundle)
|
||||
b.on('log', function(msg) {console.warn('\x1b[36m%s\x1b[0m', msg)})
|
||||
if (prod) {
|
||||
console.warn('\x1b[36m%s\x1b[0m', 'Building minified js bundle for production... This may take a while... ')
|
||||
transforms.push([transformWrapper(require('uglifyify')), {global: true}])
|
||||
}
|
||||
|
||||
bundle()
|
||||
var bundle = build({
|
||||
input: '../src/browser/js/index.js',
|
||||
output: '../app/browser/open-stage-control-client.js',
|
||||
options: {
|
||||
debug: true,
|
||||
insertGlobals: false,
|
||||
noParse: ['**/*.min.js', '**/jquery.ui.js'],
|
||||
cache: {},
|
||||
packageCache: {}
|
||||
},
|
||||
plugins: watch ? [require('watchify')] : [],
|
||||
transforms: transforms
|
||||
})
|
||||
|
||||
if (watch) {
|
||||
|
||||
var ansiHTML = require('ansi-html'),
|
||||
WS = require('../node_modules/ws')
|
||||
|
||||
if (autoRefresh) {
|
||||
var ansiHTML = require('ansi-html')
|
||||
var WS = require('../app/node_modules/ws')
|
||||
function send(msg, data){
|
||||
var ipc = new WS('ws://127.0.0.1:8080/dev')
|
||||
ipc.on('error', ()=>{})
|
||||
|
|
@ -72,22 +53,22 @@ if (autoRefresh) {
|
|||
ipc.close()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
bundle.b.on('update', hotBundle)
|
||||
bundle.b.on('log', function(msg) {console.warn('\x1b[36m%s\x1b[0m', msg)})
|
||||
|
||||
function bundle() {
|
||||
function hotBundle() {
|
||||
|
||||
var output = b.bundle()
|
||||
var output = bundle()
|
||||
|
||||
output.on('end', (err)=> {
|
||||
console.log('Build successful', autoRefresh ? 'reloading...' : '')
|
||||
if (autoRefresh) send('reload')
|
||||
})
|
||||
output.on('end', (err)=> {
|
||||
console.log('Build successful reloading...')
|
||||
send('reload')
|
||||
})
|
||||
|
||||
output.on('error', (err)=> {
|
||||
output.on('error', (err)=> {
|
||||
|
||||
console.error(err.stack)
|
||||
if (autoRefresh) {
|
||||
console.error(err.stack)
|
||||
send('errorPopup',
|
||||
'<div class="error-stack">' +
|
||||
ansiHTML(
|
||||
|
|
@ -99,13 +80,16 @@ function bundle() {
|
|||
) +
|
||||
'</div>'
|
||||
)
|
||||
}
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (!fast) output = output.pipe(exorcist(outputPath + '.map'))
|
||||
hotBundle()
|
||||
|
||||
output.pipe(fs.createWriteStream(outputPath))
|
||||
} else {
|
||||
|
||||
bundle()
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ var sass = require('node-sass'),
|
|||
path = require('path'),
|
||||
fs = require('fs')
|
||||
|
||||
var indir = path.resolve(__dirname + '/../src/browser/scss/'),
|
||||
var indir = path.resolve(__dirname + '/../src/scss/'),
|
||||
outdir= path.resolve(__dirname + '/../app/browser/')
|
||||
|
||||
fs.readdirSync(indir + '/themes/').forEach(file => {
|
||||
|
|
@ -19,8 +19,11 @@ fs.readdirSync(indir + '/themes/').forEach(file => {
|
|||
})
|
||||
|
||||
var result = sass.renderSync({
|
||||
file: indir + '/style.scss',
|
||||
outputStyle: 'compressed'
|
||||
file: indir + '/index.scss',
|
||||
outFile: outdir + '/open-stage-control.css',
|
||||
outputStyle: 'compressed',
|
||||
sourceMap: true
|
||||
})
|
||||
|
||||
fs.writeFileSync(outdir + '/styles.css', result.css)
|
||||
fs.writeFileSync(outdir + '/open-stage-control.css', result.css)
|
||||
fs.writeFileSync(outdir + '/open-stage-control.css.map', result.map)
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
var browserify = require('browserify'),
|
||||
licensify = require('licensify'),
|
||||
path = require('path'),
|
||||
ignoreList = ['**/mathjs/dist/math.min.js']
|
||||
var build = require('./build')
|
||||
|
||||
|
||||
browserify(path.resolve(__dirname + '/../src/launcher/index.js'), {
|
||||
debug: true,
|
||||
ignoreMissing: false ,
|
||||
detectGlobals: false,
|
||||
bare: true,
|
||||
noParse: ignoreList
|
||||
})
|
||||
.plugin(licensify)
|
||||
.bundle()
|
||||
.pipe(process.stdout)
|
||||
build({
|
||||
input: '../src/launcher/index.js',
|
||||
output: '../app/launcher/open-stage-control-launcher.js',
|
||||
options: {
|
||||
debug: true,
|
||||
ignoreMissing: false,
|
||||
detectGlobals: false,
|
||||
bare: true,
|
||||
noParse: ['**/mathjs/dist/math.min.js']
|
||||
}
|
||||
})()
|
||||
|
|
|
|||
23
scripts/build-main.js
Normal file
23
scripts/build-main.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
var build = require('./build')
|
||||
|
||||
build({
|
||||
input: '../src/main/index.js',
|
||||
output: '../app/main/open-stage-control-server.js',
|
||||
options: {
|
||||
commonDir: false,
|
||||
ignoreMissing: true,
|
||||
debug: true,
|
||||
builtins: false,
|
||||
commondir: false,
|
||||
insertGlobalVars: {
|
||||
__filename: true,
|
||||
__dirname: true,
|
||||
process: true,
|
||||
electron: true,
|
||||
global: true
|
||||
},
|
||||
browserField: false,
|
||||
},
|
||||
ignore: 'serialport',
|
||||
exclude: 'electron'
|
||||
})()
|
||||
49
scripts/build.js
Normal file
49
scripts/build.js
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
var browserify = require('browserify'),
|
||||
exorcist = require('exorcist'),
|
||||
licensify = require('licensify'),
|
||||
fs = require('fs'),
|
||||
path = require('path')
|
||||
|
||||
|
||||
module.exports = (opt) => {
|
||||
|
||||
var {input, output, options, ignore, exclude, transforms, plugins} = opt,
|
||||
inputPath = path.resolve(__dirname + '/' + input),
|
||||
outputPath = path.resolve(__dirname + '/' + output),
|
||||
b
|
||||
|
||||
if (!plugins) plugins = []
|
||||
if (!plugins.includes(licensify)) plugins.push(licensify)
|
||||
|
||||
b = browserify(inputPath, options)
|
||||
|
||||
if (ignore) b.ignore(ignore)
|
||||
if (exclude) b.exclude(exclude)
|
||||
|
||||
for (var plugin of plugins) {
|
||||
b.plugin(plugin)
|
||||
}
|
||||
|
||||
if (transforms) {
|
||||
for (var transform of transforms) {
|
||||
var [t, opts] = transform
|
||||
b.transform(t, opts)
|
||||
}
|
||||
}
|
||||
|
||||
function bundle() {
|
||||
|
||||
var output = b.bundle()
|
||||
|
||||
output = output.pipe(exorcist(outputPath + '.map'))
|
||||
output.pipe(fs.createWriteStream(outputPath))
|
||||
|
||||
return output
|
||||
|
||||
}
|
||||
|
||||
bundle.b = b
|
||||
|
||||
return bundle
|
||||
|
||||
}
|
||||
|
|
@ -2,7 +2,8 @@ var cpr = require('cpr'),
|
|||
path = require('path'),
|
||||
files = [
|
||||
['../resources/images/logo-nobadge.png', '../app/browser/favicon.png'],
|
||||
['../resources/images/logo.png', '../app/browser/logo.png']
|
||||
['../resources/images/logo.png', '../app/browser/logo.png'],
|
||||
['../LICENSE', '../app/LICENSE'],
|
||||
]
|
||||
|
||||
for (var i in files) {
|
||||
|
|
|
|||
|
|
@ -5,13 +5,7 @@ var browserify = require('browserify'),
|
|||
cpr = require('cpr'),
|
||||
path = require('path'),
|
||||
files = [
|
||||
['../app/package.json', '../dist/open-stage-control-node/package.json'],
|
||||
['../app/index.js', '../dist/open-stage-control-node/index.js'],
|
||||
['../app/launcher', '../dist/open-stage-control-node/launcher'],
|
||||
['../app/browser', '../dist/open-stage-control-node/browser'],
|
||||
['../app/main/midi.py', '../dist/open-stage-control-node/main/midi.py'],
|
||||
['../app/examples', '../dist/open-stage-control-node/examples'],
|
||||
['../app/LICENSE', '../dist/open-stage-control-node/LICENSE']
|
||||
['../app', '../dist/open-stage-control-node']
|
||||
]
|
||||
|
||||
for (let i in files) {
|
||||
|
|
@ -19,52 +13,6 @@ for (let i in files) {
|
|||
cpr(...files[i].map(f => path.resolve(__dirname + '/' + f)), {
|
||||
filter: /node_modules\/(serialport|uws)/,
|
||||
overwrite: true
|
||||
}, ()=>{
|
||||
if (i == files.length - 1) bundleMain()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function bundleMain() {
|
||||
|
||||
var tmp = path.resolve(__dirname + '/../app/main/index-node.js'),
|
||||
index = fs.readFileSync(path.resolve(__dirname + '/../app/main/index.js'))
|
||||
|
||||
fs.writeFileSync(tmp, `require('source-map-support').install({handleUncaughtExceptions: false})\n` + index)
|
||||
|
||||
|
||||
var inputPath = tmp,
|
||||
outputPath = path.resolve(__dirname + '/../dist/open-stage-control-node/main/index.js')
|
||||
|
||||
b = browserify(inputPath, {
|
||||
commonDir: false,
|
||||
ignoreMissing: true,
|
||||
debug: true,
|
||||
plugin: [licensify],
|
||||
builtins: false,
|
||||
commondir: false,
|
||||
insertGlobalVars: {
|
||||
__filename: true,
|
||||
__dirname: true,
|
||||
process: true,
|
||||
electron: true,
|
||||
global: true
|
||||
},
|
||||
browserField: false,
|
||||
})
|
||||
.ignore('serialport')
|
||||
.exclude('electron')
|
||||
|
||||
var output = b.bundle()
|
||||
|
||||
output = output.pipe(exorcist(outputPath + '.map'))
|
||||
|
||||
var writer = fs.createWriteStream(outputPath)
|
||||
output.pipe(writer)
|
||||
|
||||
writer.once('finish', ()=>{
|
||||
fs.unlinkSync(tmp)
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue