b.task('build:web', ['build:vfs'], () => { b.copy('web/index.html', DIST) b.copy('web/reader.html', DIST) b.js('./web/editor.js', { output: [{ file: DIST + 'editor.js', format: 'umd', name: 'textureEditor', globals: { 'substance': 'substance', 'substance-texture': 'texture', 'katex': 'katex' } }], external: ['substance', 'substance-texture', 'katex'] }) b.js('./web/reader.js', { output: [{ file: DIST + 'reader.js', format: 'umd', name: 'textureReader', globals: { 'substance': 'substance', 'substance-texture': 'texture', 'katex': 'katex' } }], external: ['substance', 'substance-texture', 'katex'] }) b.copy('./data', DIST + 'data') })
b.task('build:assets', function () { b.copy('./node_modules/font-awesome', DIST + 'font-awesome') b.copy('./node_modules/inter-ui', DIST + 'inter-ui') b.copy('./node_modules/katex/dist', DIST + 'katex') b.copy('./node_modules/substance/dist', DIST + 'substance/dist') b.css('texture.css', DIST + 'texture.css') b.css('texture-reset.css', DIST + 'texture-reset.css') })
function copyAssets() { b.copy('./node_modules/font-awesome', DIST+'font-awesome') b.copy('./node_modules/katex/dist/', DIST+'katex') b.copy('./node_modules/plotly.js/dist/plotly*.js*', DIST+'lib/') b.copy('./node_modules/substance/dist/substance.js*', DIST+'lib/') b.copy('./node_modules/substance-texture/dist/texture.js*', DIST+'lib/') b.copy('./node_modules/stencila-mini/dist/stencila-mini.js*', DIST+'lib/') b.copy('./node_modules/stencila-libcore/build/stencila-libcore.*', DIST+'lib/') b.copy('./node_modules/rdc-js/dist/rdc.js*', DIST+'lib/') }
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') } }) })
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 }) })
function buildApp() { b.copy('./app/*.html', DIST, { root: './app/'}) // copy('./node_modules/substance/packages/** /*.css', 'dist/styles/', { root: './node_modules/substance/'}) // copy('./node_modules/substance/packages/** /*.css', 'dist/styles/', { root: './node_modules/substance/'}) b.js(`./app/app.js`, { dest: `${DIST}app.js`, format: 'umd', moduleName: `StencilaExample`, external: EXAMPLE_EXTERNALS }) }
b.task('build:test-browser', ['build:assets', 'build:test-assets'], () => { b.copy('test/index.html', 'dist/test/index.html') b.copy('node_modules/substance-test/dist/testsuite.js', 'dist/test/testsuite.js') b.copy('node_modules/substance-test/dist/test.css', 'dist/test/test.css') // NOTE: by declaring texture/index.js as external we manage to serve both environments, browser and nodejs // with the same code. // In the browser, texture is used via the regular texture bundle, in nodejs it is resolved in the regular way const INDEX_JS = path.join(__dirname, 'index.js') const TEST_VFS = path.join(__dirname, 'tmp', 'test-vfs.js') let globals = { 'substance': 'substance', 'substance-test': 'substanceTest', 'katex': 'katex', // TODO: this should be done in the same way as INDEX_JS and TEST_VFS 'vfs': 'vfs' } globals[INDEX_JS] = 'texture' globals[TEST_VFS] = 'testVfs' b.js('test/index.js', { output: [{ file: 'dist/test/tests.js', format: 'umd', name: 'tests', globals }], external: [ 'substance', 'substance-test', INDEX_JS, 'katex', 'vfs', TEST_VFS ] }) })
function buildExamples() { // TODO: we should also be able to map images //b.custom('Converting examples from external formats', { // src: ['./examples/rmarkdown/rmarkdown.Rmd'], // execute(files) { // fork(b, 'node_modules/.bin/stencila-convert', 'import', './examples/rmarkdown', { verbose: true }) // } //}) b.copy('./examples', DIST+'examples') vfs(b, { src: ['./examples/**/*'], dest: `${DIST}vfs.js`, format: 'umd', moduleName: 'vfs', rootDir: path.join(__dirname, 'examples') }) }
].forEach(f => { b.copy(`dist/${f}`, APPDIST + 'lib/') b.copy(`dist/${f}.map`, APPDIST + 'lib/') })