Footprint sideloading tests
This commit is contained in:
parent
24466eb01d
commit
0d73c59538
15 changed files with 315 additions and 14 deletions
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