Footprint sideloading tests
This commit is contained in:
parent
24466eb01d
commit
0d73c59538
15 changed files with 315 additions and 14 deletions
15
src/cli.js
15
src/cli.js
|
@ -98,20 +98,25 @@ let injections = []
|
|||
|
||||
try {
|
||||
if (config_file.endsWith('.zip') || config_file.endsWith('.ekb')) {
|
||||
console.log('Analyzing bundle...');
|
||||
[config_text, injections] = await io.unpack(
|
||||
(new jszip()).loadAsync(fs.readFileSync(config_file))
|
||||
await (new jszip()).loadAsync(fs.readFileSync(config_file))
|
||||
)
|
||||
} else if (fs.statSync(config_file).isDirectory()) {
|
||||
[config_text, injections] = await io.unpack(zip_from_dir(config_file))
|
||||
console.log('Analyzing folder...');
|
||||
[config_text, injections] = await io.unpack(
|
||||
await zip_from_dir(config_file)
|
||||
)
|
||||
} else {
|
||||
config_text = fs.readFileSync(config_file).toString()
|
||||
// no injections...
|
||||
}
|
||||
for (const [type, value] of injections) {
|
||||
ergogen.inject(type, value)
|
||||
for (const [type, name, value] of injections) {
|
||||
ergogen.inject(type, name, value)
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`Could not read config file "${config_file}": ${err}`)
|
||||
console.error(`Could not read config file "${config_file}"!`)
|
||||
console.error(err)
|
||||
process.exit(2)
|
||||
}
|
||||
|
||||
|
|
11
src/io.js
11
src/io.js
|
@ -9,17 +9,22 @@ const kle = require('./kle')
|
|||
exports.unpack = async (zip) => {
|
||||
|
||||
// main config text (has to be called "config.ext" where ext is one of yaml/json/js)
|
||||
const config_text = await zip.file(/^config\.(yaml|json|js)$/).async('string')
|
||||
const candidates = zip.file(/^config\.(yaml|json|js)$/)
|
||||
if (candidates.length != 1) {
|
||||
throw new Error('Ambiguous config in bundle!')
|
||||
}
|
||||
const config_text = await candidates[0].async('string')
|
||||
const injections = []
|
||||
|
||||
// bundled footprints
|
||||
const fps = zip.folder('footprints')
|
||||
const module_prefix = 'const module = {};\n\n'
|
||||
const module_suffix = '\n\nreturn module.exports;'
|
||||
for (const fp in fps.file(/.*\.js$/)) {
|
||||
const name = fp.name.split('.')[0]
|
||||
for (const fp of fps.file(/.*\.js$/)) {
|
||||
const name = fp.name.slice('footprints/'.length).split('.')[0]
|
||||
const text = await fp.async('string')
|
||||
const parsed = new Function(module_prefix + text + module_suffix)()
|
||||
// TODO: some sort of footprint validation?
|
||||
injections.push(['footprint', name, parsed])
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue