|
| 1 | +/** |
| 2 | + * Set up and build Aether. We build Aether as a separate artifact using |
| 3 | + * webpack. We also rename certain esper files here and move those files |
| 4 | + * into the public directory to be loaded dynamically at runtime by the |
| 5 | + * browser and service workers. |
| 6 | + * |
| 7 | + * Note: |
| 8 | + * esper-modern requires modern language plugin to be loaded otherwise it won't |
| 9 | + * work correctly. |
| 10 | + */ |
| 11 | +const fs = require('fs-extra'); |
| 12 | +const webpack = require('webpack'); |
| 13 | +const path = require('path'); |
| 14 | + |
| 15 | +// List of esper langauge plugins we want to move into the public directory. |
| 16 | +const targets = [ |
| 17 | + 'lua', |
| 18 | + 'python', |
| 19 | + 'coffeescript' |
| 20 | +]; |
| 21 | + |
| 22 | +// Get a list of the regular and modern language plugin paths. |
| 23 | +const target_paths = targets |
| 24 | + .map(lang => [ |
| 25 | + [ |
| 26 | + path.join(__dirname, 'bower_components', 'esper.js', `esper-plugin-lang-${lang}.js`), |
| 27 | + path.join(__dirname, 'public', 'javascripts', 'app', 'vendor', `aether-${lang}.js`) |
| 28 | + ], |
| 29 | + [ |
| 30 | + path.join(__dirname, 'bower_components', 'esper.js', `esper-plugin-lang-${lang}-modern.js`), |
| 31 | + path.join(__dirname, 'public', 'javascripts', 'app', 'vendor', `aether-${lang}.modern.js`) |
| 32 | + ] |
| 33 | + ]) |
| 34 | + .reduce((l, paths) => l.concat(paths)) |
| 35 | + |
| 36 | +for (let [src, dest] of target_paths) { |
| 37 | + // const src = path.join(__dirname, 'bower_components', 'esper.js', `esper-plugin-lang-${target}.js`); |
| 38 | + // const dest = path.join(__dirname, 'bower_components', 'aether', 'build', `${target}.js`); |
| 39 | + console.log(`Copy ${src}, ${dest}`); |
| 40 | + fs.copySync(src, dest); |
| 41 | +} |
| 42 | + |
| 43 | +const aether_webpack_config = { |
| 44 | + context: path.resolve(__dirname), |
| 45 | + entry: { |
| 46 | + aether: './app/lib/aether/aether.coffee' |
| 47 | + }, |
| 48 | + output: { |
| 49 | + filename: './bower_components/aether/build/aether.js' |
| 50 | + }, |
| 51 | + module: { |
| 52 | + rules: [ |
| 53 | + { |
| 54 | + test: /\.coffee$/, |
| 55 | + use: [ 'coffee-loader' ] |
| 56 | + } |
| 57 | + ] |
| 58 | + }, |
| 59 | + resolve: { |
| 60 | + extensions: [".coffee", ".json", ".js"] |
| 61 | + }, |
| 62 | + externals: { |
| 63 | + 'esper.js': 'esper', |
| 64 | + 'lodash': '_', |
| 65 | + 'source-map': 'SourceMap' |
| 66 | + }, |
| 67 | + |
| 68 | + node: { |
| 69 | + fs: "empty" |
| 70 | + } |
| 71 | +}; |
| 72 | + |
| 73 | + |
| 74 | +webpack(aether_webpack_config, function(err, stats) { |
| 75 | + if (err) { |
| 76 | + console.log(err); |
| 77 | + } else { |
| 78 | + console.log("Packed aether!"); |
| 79 | + if (stats.compilation.errors.length) { |
| 80 | + console.error("Compilation errors:", stats.compilation.errors); |
| 81 | + } |
| 82 | + } |
| 83 | +}); |
0 commit comments