Exemple #1
0
function bundlePrism() {
  // Note: we stitch together a version that contains only what we need
  // and exposing it as an es6 module
  b.custom('Bundling prism...', {
    src: [
      'node_modules/prismjs/components/prism-core.js',
      'node_modules/prismjs/components/prism-clike.js',
      'node_modules/prismjs/components/prism-r.js',
      'node_modules/prismjs/components/prism-python.js',
      'node_modules/prismjs/components/prism-sql.js',
      'node_modules/prismjs/components/prism-javascript.js'
    ],
    dest: 'tmp/prism.js',
    execute(files) {
      let chunks = ['const _self = {}']
      files.forEach((file) => {
        let basename = path.basename(file)
        let content = fs.readFileSync(file, 'utf8')
        chunks.push(`/** START ${basename} **/`)
        if (basename === 'prism-core.js') {
          // cut out the core
          let start = content.indexOf('var Prism = (function(){')
          let end = content.lastIndexOf('})();')+5
          content = content.substring(start, end)
        }
        chunks.push(content)
        chunks.push(`/** END ${basename} **/`)
      })
      chunks.push('export default Prism')
      b.writeFileSync('tmp/prism.js', chunks.join('\n'))
    }
  })
}
Exemple #2
0
function _compileSchema (name, src, searchDirs, deps, options = {}) {
  const DEST = `tmp/${name}.data.js`
  const ISSUES = `tmp/${name}.issues.txt`
  const SCHEMA = `tmp/${name}.schema.md`
  const entry = path.basename(src)
  b.custom(`Compiling schema '${name}'...`, {
    src: [src].concat(deps),
    dest: DEST,
    execute () {
      return new Promise(resolve => {
        setTimeout(() => {
          const { compileRNG, checkSchema } = require('substance')
          const xmlSchema = compileRNG(fs, searchDirs, entry)
          b.writeFileSync(DEST, `export default ${JSON.stringify(xmlSchema)}`)
          b.writeFileSync(SCHEMA, xmlSchemaToMD(xmlSchema))
          if (options.debug) {
            const issues = checkSchema(xmlSchema)
            const issuesData = [`${issues.length} issues:`, ''].concat(issues).join('\n')
            b.writeFileSync(ISSUES, issuesData)
          }
          resolve()
        }, 250)
      })
    }
  })
}
Exemple #3
0
b.task('build:app', () => {
  b.copy('app/index.html', APPDIST)
  b.copy('app/build-resources', APPDIST)
  // TODO: we should pack folders from ./data
  b.copy('app/templates', APPDIST)
  // FIXME: this command leads to an extra run when a  file is updated
  // .. instead copying the files explicitly for now
  // b.copy('dist', APPDIST+'lib/')
  b.copy('dist/font-awesome', APPDIST + 'lib/')
  b.copy('dist/katex', APPDIST + 'lib/')
  b.copy('dist/inter-ui', APPDIST + 'lib/')
  b.copy('dist/substance', APPDIST + 'lib/')
  ;[
    'texture.js',
    'texture.css',
    'texture-reset.css'
  ].forEach(f => {
    b.copy(`dist/${f}`, APPDIST + 'lib/')
    b.copy(`dist/${f}.map`, APPDIST + 'lib/')
  })

  // TODO: maybe we could come up with an extension
  // that expands a source file using a given dict.
  b.custom('Creating application package.json...', {
    src: 'app/package.json.in',
    dest: APPDIST + 'package.json',
    execute () {
      let { version, dependencies, devDependencies } = require('./package.json')
      let tpl = fs.readFileSync('app/package.json.in', 'utf8')
      let out = tpl.replace('${version}', version)
        .replace('${electronVersion}', devDependencies.electron)
        .replace('${dependencies}', JSON.stringify(dependencies))
      fs.writeFileSync(APPDIST + 'package.json', out)
    }
  })
  b.js('app/main.js', {
    output: [{
      file: APPDIST + 'main.js',
      format: 'cjs'
    }],
    external: ['electron', 'path', 'url']
  })
  b.js('app/app.js', {
    output: [{
      file: APPDIST + 'app.js',
      format: 'umd',
      name: 'textureApp',
      globals: {
        'substance': 'substance',
        'substance-texture': 'texture',
        'katex': 'katex'
      }
    }],
    external: [ 'substance', 'substance-texture', 'katex' ]
  })
  // execute 'install-app-deps'
  fork(b, require.resolve('electron-builder/out/cli/cli.js'), 'install-app-deps', { verbose: true, cwd: APPDIST, await: true })
})
Exemple #4
0
b.task('schema:texture-article', () => {
  _compileSchema('TextureArticle', RNG_FILES[1], RNG_SEARCH_DIRS, RNG_FILES.slice(0, 2))
  b.custom(`Copy schema documentation...`, {
    src: './tmp/TextureArticle.schema.md',
    dest: './docs/TextureArticle.md',
    execute () {
      b.copy('./tmp/TextureArticle.schema.md', './docs/TextureArticle.md')
    }
  })
})
Exemple #5
0
// This is used to expose `STENCILA_XXXX` environment variables to the js app
function buildEnv() {
  b.custom('Creating environment variables (env.js)...', {
    dest: DIST+'env.js',
    execute() {
      const variables = []
      for (let name of Object.keys(process.env)) {
        if (name.match(/^STENCILA_/)) {
          variables.push(`window.${name} = "${process.env[name]}"`)
        }
      }
      b.writeFileSync(DIST+'env.js', variables.join('\n'), 'utf8')
    }
  })
}
Exemple #6
0
// reads all fixtures from /tests/ and writes them into a script
function buildTestBackend() {
  b.custom('Creating test backend...', {
    src: ['./tests/documents/**/*', './tests/function/fixtures/*'],
    dest: './tmp/test-vfs.js',
    execute(files) {
      const rootDir = b.rootDir
      const vfs = {}
      files.forEach((f) => {
        if (b.isDirectory(f)) return
        let content = fs.readFileSync(f).toString()
        let relPath = path.relative(rootDir, f).replace(/\\/g, '/')
        vfs[relPath] = content
      })
      const data = ['export default ', JSON.stringify(vfs, null, 2)].join('')
      b.writeFileSync('tmp/test-vfs.js', data)
    }
  })
}
Exemple #7
0
b.task('server', function() {
  b.custom('Running nodejs tests...', {
    execute: function() {
      return new Promise(function(resolve, reject) {
        const child = cp.fork(path.join(__dirname, '.test/run-cjs-tests.js'))
        child.on('message', function(msg) {
          if (msg === 'done') { resolve() }
        })
        child.on('error', function(error) {
          reject(new Error(error))
        })
        child.on('close', function(exitCode) {
          if (exitCode !== 0) {
            process.exit(exitCode)
          }
        })
      });
    }
  })
})
Exemple #8
0
function _compileSchema(name, src, options = {} ) {
  const DEST = `tmp/${name}.data.js`
  const ISSUES = `tmp/${name}.issues.txt`
  const SCHEMA = `tmp/${name}.schema.md`
  const entry = path.basename(src)
  b.custom(`Compiling schema '${name}'...`, {
    src: src,
    dest: DEST,
    execute() {
      const { compileRNG, checkSchema } = require('substance')
      const xmlSchema = compileRNG(fs, RNG_SEARCH_DIRS, entry)
      b.writeFileSync(DEST, `export default ${JSON.stringify(xmlSchema)}`)
      b.writeFileSync(SCHEMA, xmlSchema.toMD())
      if (options.debug) {
        const issues = checkSchema(xmlSchema)
        const issuesData = [`${issues.length} issues:`, ''].concat(issues).join('\n')
        b.writeFileSync(ISSUES, issuesData)
      }
    }
  })
}