build: migrate build system to rollup & rm app/ from repository
This commit is contained in:
parent
291b1a0752
commit
bdfade96a7
65 changed files with 327 additions and 362 deletions
|
|
@ -1,98 +0,0 @@
|
|||
var build = require('./build'),
|
||||
path = require('path'),
|
||||
babelify = require('babelify'),
|
||||
nanohtml = require('nanohtml'),
|
||||
watch = process.argv.includes('--watch'),
|
||||
through = require('through'),
|
||||
minimatch = require('minimatch')
|
||||
|
||||
|
||||
var ignores = ['**/*.min.js', '**/jquery.ui.js', 'gyronorm.complete.min.js'],
|
||||
transformWrapper = function(transform){
|
||||
return function(file, opts){
|
||||
if (ignores.some(pattern => minimatch(file, pattern))) {
|
||||
return through()
|
||||
} else {
|
||||
return transform(file, opts)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var transforms = [
|
||||
[transformWrapper(nanohtml)],
|
||||
[transformWrapper(babelify)]
|
||||
]
|
||||
|
||||
console.warn('\033[36m=> Building compressed client scripts...\033[0m')
|
||||
transforms.push([transformWrapper(require('uglifyify')), {global: true, safari10: true}])
|
||||
|
||||
var bundle = build({
|
||||
input: '../src/client/index.js',
|
||||
output: '../app/client/open-stage-control-client.js',
|
||||
options: {
|
||||
debug: true,
|
||||
insertGlobals: false,
|
||||
noParse: ['**/*.min.js', '**/jquery.ui.js'],
|
||||
cache: {},
|
||||
packageCache: {},
|
||||
},
|
||||
plugins: watch ? [require('watchify')] : [],
|
||||
transforms: transforms,
|
||||
ignore: [
|
||||
'postcss' // only needed by sanitize-html if <style> is allowed; somehow fails at object spread syntax transpilation
|
||||
]
|
||||
})
|
||||
|
||||
if (watch) {
|
||||
|
||||
var ansiHTML = require('ansi-html'),
|
||||
WS = require('../node_modules/ws')
|
||||
|
||||
function send(msg, data){
|
||||
var ipc = new WS('ws://127.0.0.1:8080/dev/')
|
||||
ipc.on('error', ()=>{})
|
||||
ipc.on('open', ()=>{
|
||||
ipc.send(JSON.stringify([msg, data]))
|
||||
ipc.close()
|
||||
})
|
||||
}
|
||||
|
||||
bundle.b.on('update', hotBundle)
|
||||
bundle.b.on('log', function(msg) {console.warn('\x1b[36m%s\x1b[0m', msg)})
|
||||
|
||||
function hotBundle() {
|
||||
|
||||
var output = bundle()
|
||||
|
||||
output.on('end', (err)=> {
|
||||
console.log('Build successful reloading...')
|
||||
send('reload')
|
||||
})
|
||||
|
||||
output.on('error', (err)=> {
|
||||
|
||||
console.error(err.stack)
|
||||
send('errorPopup',
|
||||
'<div class="error-stack">' +
|
||||
ansiHTML(
|
||||
err.stack
|
||||
.replace(/^ at .*/gm, '') // remove useless stack
|
||||
.replace(new RegExp(path.resolve(__dirname + '/..'), 'g'),'.') // shorten file path
|
||||
.trim()
|
||||
.replace('\n','\n\n') // add 1 new line after 1st line
|
||||
) +
|
||||
'</div>'
|
||||
)
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
hotBundle()
|
||||
|
||||
} else {
|
||||
|
||||
bundle()
|
||||
|
||||
}
|
||||
|
|
@ -5,6 +5,8 @@ var sass = require('sass'),
|
|||
var indir = path.resolve(__dirname + '/../src/scss/'),
|
||||
outdir= path.resolve(__dirname + '/../app/assets/')
|
||||
|
||||
fs.mkdirSync(outdir + '/themes/', {recursive: true})
|
||||
|
||||
fs.readdirSync(indir + '/themes/').forEach(file => {
|
||||
|
||||
if (file.includes('.scss') && file !== 'default.scss') {
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
var build = require('./build')
|
||||
|
||||
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']
|
||||
},
|
||||
exclude: [
|
||||
'electron',
|
||||
]
|
||||
})()
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
var build = require('./build'),
|
||||
babelify = require('babelify')
|
||||
|
||||
build({
|
||||
input: '../src/server/index.js',
|
||||
output: '../app/server/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',
|
||||
'./fsevents.node' // osx binary module, to be copied as is
|
||||
]
|
||||
})()
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
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()
|
||||
|
||||
var toWrite = output.pipe(exorcist(outputPath + '.map'))
|
||||
toWrite.pipe(fs.createWriteStream(outputPath))
|
||||
|
||||
return output
|
||||
|
||||
}
|
||||
|
||||
bundle.b = b
|
||||
|
||||
return bundle
|
||||
|
||||
}
|
||||
40
scripts/client.plugin-watch.js
Normal file
40
scripts/client.plugin-watch.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
var ansiHTML = require('ansi-html'),
|
||||
WS = require('../node_modules/ws'),
|
||||
path = require('path')
|
||||
|
||||
function send(msg, data){
|
||||
var ipc = new WS('ws://127.0.0.1:8080/dev/')
|
||||
ipc.on('error', ()=>{})
|
||||
ipc.on('open', ()=>{
|
||||
ipc.send(JSON.stringify([msg, data]))
|
||||
ipc.close()
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = function watchChangePlugin() {
|
||||
|
||||
var reloadClient = false
|
||||
|
||||
return {
|
||||
|
||||
buildEnd(error) {
|
||||
|
||||
if (error) {
|
||||
var msg = `<div class="error-stack">
|
||||
${error.message.replace(path.resolve(__dirname + '/..'),'')} at line ${error.loc.line}\n${error.frame}
|
||||
</div>`
|
||||
send('errorPopup', msg.trim())
|
||||
reloadClient = false
|
||||
} else {
|
||||
reloadClient = true
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
writeBundle() {
|
||||
if (reloadClient) {
|
||||
send('reload')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
99
scripts/client.rollup.config.js
Normal file
99
scripts/client.rollup.config.js
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
var commonjs = require('@rollup/plugin-commonjs'),
|
||||
nodeResolve = require('@rollup/plugin-node-resolve'),
|
||||
json = require('@rollup/plugin-json'),
|
||||
babel = require('@rollup/plugin-babel'),
|
||||
terser = require('@rollup/plugin-terser'),
|
||||
copy = require('rollup-plugin-copy'),
|
||||
license = require('rollup-plugin-license'),
|
||||
watchChange = require('./client.plugin-watch'),
|
||||
package = require('../package.json'),
|
||||
path = require('path')
|
||||
|
||||
module.exports = {
|
||||
input: 'src/client/index.js',
|
||||
output: [
|
||||
{
|
||||
file: 'app/client/open-stage-control-client.js',
|
||||
inlineDynamicImports: true,
|
||||
format: 'iife',
|
||||
sourcemap: true,
|
||||
strict: false,
|
||||
name: '_'
|
||||
},
|
||||
],
|
||||
watch: {
|
||||
clearScreen: false
|
||||
},
|
||||
plugins: [
|
||||
json(),
|
||||
commonjs(),
|
||||
nodeResolve({
|
||||
browser: true
|
||||
}),
|
||||
babel({
|
||||
babelHelpers: 'bundled',
|
||||
exclude: [
|
||||
/node_modules\/core-js/,
|
||||
/node_modules\/ace-builds/
|
||||
],
|
||||
presets: [[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
targets: {
|
||||
ios: '10.3',
|
||||
chrome: '60'
|
||||
},
|
||||
useBuiltIns: 'usage',
|
||||
corejs: 3,
|
||||
modules:false
|
||||
}
|
||||
]]
|
||||
}),
|
||||
terser({
|
||||
safari10: true,
|
||||
sourceMap: true,
|
||||
output: {
|
||||
comments: false,
|
||||
},
|
||||
}),
|
||||
{
|
||||
name: 'remove-node-modules-from-source-map',
|
||||
enforce: 'post',
|
||||
transform(code, id) {
|
||||
if (id.includes('node_modules')) {
|
||||
return { code, map: { mappings: '' } }
|
||||
}
|
||||
}
|
||||
},
|
||||
license({
|
||||
banner: {
|
||||
content: {
|
||||
file: path.join(__dirname, 'license-header.txt'),
|
||||
},
|
||||
}
|
||||
}),
|
||||
copy({
|
||||
targets: [
|
||||
{src: 'resources/images/logo_nobadge.png', dest: 'app/assets/', rename: 'favicon.png'},
|
||||
{src: 'resources/images/logo.png', dest: 'app/assets/'},
|
||||
{src: 'resources/images/logo_tray.png', dest: 'app/assets/'},
|
||||
{src: 'resources/images/logo_tray@x2.png', dest: 'app/assets/'},
|
||||
{src: 'resources/images/logo_16x16.png', dest: 'app/assets/'},
|
||||
{src: 'resources/fonts/*', dest: 'app/assets/fonts/'},
|
||||
{src: 'node_modules/ace-builds/src-min/worker-css.js', dest: 'app/client/workers/'},
|
||||
{src: 'node_modules/ace-builds/src-min/worker-html.js', dest: 'app/client/workers/'},
|
||||
{src: 'node_modules/ace-builds/src-min/worker-javascript.js', dest: 'app/client/workers/'},
|
||||
{src: 'LICENSE', dest: 'app/'},
|
||||
{src: 'src/python/*', dest: 'app/server/python/'},
|
||||
{src: 'src/html/launcher.html', dest: 'app/launcher/', rename: 'index.html'},
|
||||
{src: 'node_modules/fsevents/fsevents.node', dest: 'app/server/'},
|
||||
{src: 'src/app/index.js', dest: 'app/'},
|
||||
{src: 'src/html/client.html', dest: 'app/client/', rename: 'index.html', transform: (contents)=>{
|
||||
return contents.toString().replace(/\$\{([^\}]+)\}/g, (m, p1)=>{return package[p1]})
|
||||
}},
|
||||
|
||||
]
|
||||
}),
|
||||
watchChange()
|
||||
]
|
||||
};
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
var cpr = require('cpr'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
files = [
|
||||
['../resources/images/logo_nobadge.png', '../app/assets/favicon.png'],
|
||||
['../resources/images/logo.png', '../app/assets/logo.png'],
|
||||
['../resources/images/logo_tray.png', '../app/assets/logo_tray.png'],
|
||||
['../resources/images/logo_tray@x2.png', '../app/assets/logo_tray@x2.png'],
|
||||
['../LICENSE', '../app/LICENSE'],
|
||||
['../src/python/', '../app/server/python/'],
|
||||
['../resources/fonts/', '../app/assets/fonts/'],
|
||||
['../src/html/launcher.html', '../app/launcher/index.html'],
|
||||
['../node_modules/fsevents/fsevents.node', '../app/server/fsevents.node'],
|
||||
['../node_modules/ace-builds/src-min/worker-css.js', '../app/client/workers/worker-css.js'],
|
||||
['../node_modules/ace-builds/src-min/worker-html.js', '../app/client/workers/worker-html.js'],
|
||||
['../node_modules/ace-builds/src-min/worker-javascript.js', '../app/client/workers/worker-javascript.js'],
|
||||
]
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
files.push(['../resources/images/logo_16x16.png', '../app/assets/logo_16x16.png'])
|
||||
}
|
||||
|
||||
for (var i in files) {
|
||||
cpr(...files[i].map(f => path.resolve(__dirname + '/' + f)), {
|
||||
overwrite: true
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
var packageJson = require('../package.json'),
|
||||
appJson = {},
|
||||
copiedProps = [
|
||||
"name",
|
||||
"productName",
|
||||
"description",
|
||||
"version",
|
||||
"author",
|
||||
"repository",
|
||||
"homepage",
|
||||
"license",
|
||||
"yargs",
|
||||
"engines"
|
||||
]
|
||||
|
||||
for (var k of copiedProps) {
|
||||
appJson[k] = packageJson[k]
|
||||
}
|
||||
|
||||
appJson.main = appJson.bin = "index.js"
|
||||
appJson.scripts = {
|
||||
"start": "electron index.js",
|
||||
"start-node": "node index.js"
|
||||
}
|
||||
|
||||
appJson.optionalDependencies = {
|
||||
electron: packageJson.optionalDependencies.electron
|
||||
}
|
||||
|
||||
fs.writeFileSync(path.resolve(__dirname + '/../app/package.json'), JSON.stringify(appJson, null, ' '))
|
||||
|
||||
var clientHtml = fs.readFileSync(path.resolve(__dirname + '/../src/html/client.html'))
|
||||
.toString()
|
||||
.replace(/\$\{([^\}]+)\}/g, (m, p1)=>{return appJson[p1]})
|
||||
|
||||
fs.writeFileSync(path.resolve(__dirname + '/../app/client/index.html'), clientHtml)
|
||||
47
scripts/launcher.rollup.config.js
Normal file
47
scripts/launcher.rollup.config.js
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
var commonjs = require('@rollup/plugin-commonjs'),
|
||||
nodeResolve = require('@rollup/plugin-node-resolve'),
|
||||
json = require('@rollup/plugin-json'),
|
||||
babel = require('@rollup/plugin-babel'),
|
||||
terser = require('@rollup/plugin-terser'),
|
||||
copy = require('rollup-plugin-copy'),
|
||||
license = require('rollup-plugin-license'),
|
||||
package = require('../package.json'),
|
||||
path = require('path')
|
||||
|
||||
module.exports = {
|
||||
input: 'src/launcher/index.js',
|
||||
output: [
|
||||
{
|
||||
file: 'app/launcher/open-stage-control-launcher.js',
|
||||
inlineDynamicImports: true,
|
||||
format: 'commonjs',
|
||||
strict: false,
|
||||
name: '_',
|
||||
},
|
||||
],
|
||||
external: ['electron'],
|
||||
watch: {
|
||||
clearScreen: false
|
||||
},
|
||||
plugins: [
|
||||
json(),
|
||||
commonjs({
|
||||
ignoreGlobal: true,
|
||||
ignoreDynamicRequires: true
|
||||
}),
|
||||
nodeResolve(),
|
||||
terser(),
|
||||
license({
|
||||
banner: {
|
||||
content: {
|
||||
file: path.join(__dirname, 'license-header.txt'),
|
||||
},
|
||||
}
|
||||
}),
|
||||
copy({
|
||||
targets: [
|
||||
{src: 'src/html/launcher.html', dest: 'app/launcher/', rename: 'index.html'},
|
||||
]
|
||||
})
|
||||
]
|
||||
};
|
||||
7
scripts/license-header.txt
Normal file
7
scripts/license-header.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Bundle of <%= pkg.name %>
|
||||
Generated: <%= moment().format('YYYY-MM-DD') %>
|
||||
Version: <%= pkg.version %>
|
||||
Dependencies:
|
||||
<% _.forEach(dependencies, function (dependency) { %>
|
||||
<%= dependency.text() %>
|
||||
<% }) %>
|
||||
|
|
@ -1,8 +1,4 @@
|
|||
var browserify = require('browserify'),
|
||||
exorcist = require('exorcist'),
|
||||
licensify = require('licensify'),
|
||||
fs = require('fs'),
|
||||
cpr = require('cpr'),
|
||||
var cpr = require('cpr'),
|
||||
path = require('path'),
|
||||
files = ['../app', '../dist/open-stage-control-node']
|
||||
|
||||
|
|
|
|||
58
scripts/server.rollup.config.js
Normal file
58
scripts/server.rollup.config.js
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
var commonjs = require('@rollup/plugin-commonjs'),
|
||||
nodeResolve = require('@rollup/plugin-node-resolve'),
|
||||
json = require('@rollup/plugin-json'),
|
||||
babel = require('@rollup/plugin-babel'),
|
||||
terser = require('@rollup/plugin-terser'),
|
||||
copy = require('rollup-plugin-copy'),
|
||||
license = require('rollup-plugin-license'),
|
||||
package = require('../package.json'),
|
||||
path = require('path')
|
||||
|
||||
module.exports = {
|
||||
input: 'src/server/index.js',
|
||||
output: [
|
||||
{
|
||||
file: 'app/server/open-stage-control-server.js',
|
||||
inlineDynamicImports: true,
|
||||
format: 'commonjs',
|
||||
strict: false,
|
||||
name: '_',
|
||||
},
|
||||
],
|
||||
external: ['electron'],
|
||||
watch: {
|
||||
clearScreen: false
|
||||
},
|
||||
plugins: [
|
||||
json(),
|
||||
commonjs({
|
||||
ignoreGlobal: true,
|
||||
ignoreDynamicRequires: true
|
||||
}),
|
||||
nodeResolve({
|
||||
preferBuiltins: true
|
||||
}),
|
||||
terser({
|
||||
sourceMap: true,
|
||||
output: {
|
||||
comments: false,
|
||||
},
|
||||
}),
|
||||
license({
|
||||
banner: {
|
||||
content: {
|
||||
file: path.join(__dirname, 'license-header.txt'),
|
||||
},
|
||||
}
|
||||
}),
|
||||
copy({
|
||||
targets: [
|
||||
{src: 'src/app/index.js', dest: 'app/'},
|
||||
{src: 'src/python/*', dest: 'app/server/python/'},
|
||||
{src: 'node_modules/fsevents/fsevents.node', dest: 'app/server/'},
|
||||
{src: 'LICENSE', dest: 'app/'},
|
||||
{src: 'package.json', dest: 'app/'},
|
||||
]
|
||||
})
|
||||
]
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue