index.js
async function compileModel (projectPath, model) {
  await copyExternalScripts(projectPath, model)
  deInlineScripts(projectPath, model)

  const lookup = resolveScriptPaths(projectPath, model)

  let imports = ''
  for (let moduleName in lookup) {
    let p = path.isAbsolute(lookup[moduleName]) ? lookup[moduleName] : `./${path.normalize(lookup[moduleName])}`
    imports += `import ${moduleName} from '${p}'\n`
  }

  const pre = JSON.stringify(model, null, 2)

  let post = pre
  for (let moduleName in lookup)
    post = replaceAll(post, moduleName)

  return `import substrate from 'substrate'

// imports generated by the compiler
${imports}

const dom = document.createElement('div')
dom.id = 'myapp'
document.body.appendChild(dom)

const model = ${post}

const app = substrate({ dom, node: model.rootNode, registry: model.registry })`
}
async function compileModel (projectPath, model) {
  await copyExternalScripts(projectPath, model)
  deInlineScripts(projectPath, model)

  const lookup = resolveScriptPaths(projectPath, model)

  let imports = ''
  for (let moduleName in lookup) {
    let p = path.isAbsolute(lookup[moduleName]) ? lookup[moduleName] : `./${path.normalize(lookup[moduleName])}`
    imports += `import ${moduleName} from '${p}'\n`
  }

  const pre = JSON.stringify(model, null, 2)

  let post = pre
  for (let moduleName in lookup)
    post = replaceAll(post, moduleName)

  return `import substrate from 'substrate'

// imports generated by the compiler
${imports}

const dom = document.createElement('div')
dom.id = 'myapp'
document.body.appendChild(dom)

const model = ${post}

const app = substrate({ dom, node: model.rootNode, registry: model.registry })`
}
async function compileModel ( projectPath , model ) { await copyExternalScripts ( projectPath , model ) deInlineScripts ( projectPath , model ) const lookup = resolveScriptPaths ( projectPath , model ) let imports = '' for ( let moduleName in lookup ) { let p = path . isAbsolute ( lookup [ moduleName ] ) ? lookup [ moduleName ] : ` ${ path . normalize ( lookup [ moduleName ] ) } ` imports += ` ${ moduleName } ${ p } \n ` } const pre = JSON . stringify ( model , null , 2 ) let post = pre for ( let moduleName in lookup ) post = replaceAll ( post , moduleName ) return ` ${ imports } ${ post } ` }
generate a build suitable for bundling by staticly compiling an input json model
generate a build suitable for bundling by staticly compiling an input json model