custom module: rm support for extra args (avoid path issues)
This commit is contained in:
parent
c367b70ceb
commit
a2f2f89aab
4 changed files with 16 additions and 34 deletions
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
## next
|
||||
|
||||
- custom module
|
||||
- remove support for extra args (avoid path issues)
|
||||
|
||||
- widgets
|
||||
- knob: add `solid` & `line` designs
|
||||
- fader: add `knobSize` property
|
||||
|
|
|
|||
|
|
@ -12,16 +12,16 @@ The **server** can be configured with many options, either from a terminal or wi
|
|||
|
||||
=== "load"
|
||||
|
||||
Path to a session file. All clients connecting the server will load it.
|
||||
Path to a session file (.json). All clients connecting the server will load it.
|
||||
|
||||
=== "state"
|
||||
|
||||
Path to a state file. All clients connecting the server will load it.
|
||||
Path to a state file (.state). All clients connecting the server will load it.
|
||||
|
||||
|
||||
=== "custom-module"
|
||||
|
||||
Path to a custom module file. Additional options can be passed after the path, they'll be accessible in the custom module's context.
|
||||
Path to a custom module file (.js).
|
||||
|
||||
|
||||
=== "port"
|
||||
|
|
|
|||
|
|
@ -7,31 +7,19 @@ module.exports = {
|
|||
'Targets must be ip:port or hostname:port pairs (port must be >= 1024) or midi:port_name pairs' : true
|
||||
}
|
||||
},
|
||||
'l': {alias: 'load', type: 'string', file: {name: 'OSC Session (.json)', extensions: ['json', 'js']}, describe: 'session file to load',
|
||||
'l': {alias: 'load', type: 'string', file: {name: 'OSC Session (.json)', extensions: ['json']}, describe: 'session file to load (.json)',
|
||||
check: (arg)=>{
|
||||
return fs.existsSync(arg) ? true : 'Session file not found: ' + arg
|
||||
}
|
||||
},
|
||||
'state': {type: 'string', file: {name: 'OSC State (.state)', extensions: ['state']}, describe: 'state file to load',
|
||||
'state': {type: 'string', file: {name: 'OSC State (.state)', extensions: ['state']}, describe: 'state file to load (.state)',
|
||||
check: (arg)=>{
|
||||
return fs.existsSync(arg) ? true : 'State file not found: ' + arg
|
||||
}
|
||||
},
|
||||
'c': {alias: 'custom-module', type: 'array', file: {name: 'OSC Custom module (.js)', extensions: ['js']}, describe: 'custom module file to load (custom options can be passed after the filename)',
|
||||
'c': {alias: 'custom-module', type: 'string', file: {name: 'OSC Custom module (.js)', extensions: ['js']}, describe: 'custom module file to load (.js)',
|
||||
check: (arg)=>{
|
||||
|
||||
var customModule = arg.slice()
|
||||
|
||||
// consolidate path containing whitespaces
|
||||
if (!customModule[0].includes('.js')) {
|
||||
var index = customModule.findIndex(x => typeof x === 'string' && x.includes('.js'))
|
||||
if (index !== undefined) {
|
||||
var _path = customModule.slice(0, index + 1).join(' ')
|
||||
customModule.splice(0, index + 1, _path)
|
||||
}
|
||||
}
|
||||
|
||||
return fs.existsSync(customModule[0]) ? true : 'Custom module file not found: ' + customModule[0]
|
||||
return fs.existsSync(arg) ? true : 'Custom module file not found: ' + arg
|
||||
},
|
||||
},
|
||||
'p': {alias: 'port', type: 'number', describe: 'http port of the server (default to 8080)',
|
||||
|
|
|
|||
|
|
@ -21,22 +21,14 @@ class OscServer {
|
|||
this.customModule = (()=>{
|
||||
|
||||
var customModule = settings.read('custom-module')
|
||||
if (!customModule) return false
|
||||
|
||||
// consolidate path containing whitespaces
|
||||
if (!customModule[0].includes('.js')) {
|
||||
var index = customModule.findIndex(x => typeof x === 'string' && x.includes('.js'))
|
||||
if (index !== undefined) {
|
||||
var _path = customModule.slice(0, index + 1).join(' ')
|
||||
customModule.splice(0, index + 1, _path)
|
||||
}
|
||||
}
|
||||
if (!customModule) return false
|
||||
|
||||
var file = (()=>{
|
||||
try {
|
||||
return fs.readFileSync(customModule[0], 'utf8')
|
||||
return fs.readFileSync(customModule, 'utf8')
|
||||
} catch(err) {
|
||||
console.error('(ERROR) Custom module not found: ' + customModule[0])
|
||||
console.error('(ERROR) Custom module not found: ' + customModule)
|
||||
return false
|
||||
}
|
||||
})(),
|
||||
|
|
@ -66,7 +58,7 @@ class OscServer {
|
|||
loadJSON: (url)=>{
|
||||
if (url.split('.').pop() === 'json') {
|
||||
try {
|
||||
url = path.resolve(path.dirname(customModule[0]), url)
|
||||
url = path.resolve(path.dirname(customModule), url)
|
||||
return JSON.parse(fs.readFileSync(url, 'utf8'))
|
||||
} catch(e) {
|
||||
console.error('(ERROR) could not load json file from ' + url)
|
||||
|
|
@ -78,7 +70,7 @@ class OscServer {
|
|||
},
|
||||
saveJSON: (url, data)=>{
|
||||
if (url.split('.').pop() === 'json') {
|
||||
url = path.resolve(path.dirname(customModule[0]), url)
|
||||
url = path.resolve(path.dirname(customModule), url)
|
||||
try {
|
||||
return fs.writeFileSync(url, JSON.stringify(data, null, ' '))
|
||||
} catch(e) {
|
||||
|
|
@ -93,7 +85,6 @@ class OscServer {
|
|||
setTimeout, clearTimeout,
|
||||
setInterval, clearInterval,
|
||||
settings,
|
||||
options: customModule.slice(1, customModule.length),
|
||||
module: {},
|
||||
})
|
||||
|
||||
|
|
@ -103,7 +94,7 @@ class OscServer {
|
|||
process.mainModule.require = process.dlopen = null
|
||||
// run
|
||||
mod = vm.runInContext(file, context, {
|
||||
filename: customModule[0]
|
||||
filename: customModule
|
||||
})
|
||||
if (context.module.exports) mod = context.module.exports
|
||||
} catch(err) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue