forked from codecombat/codecombat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-aether.js
140 lines (133 loc) · 3.5 KB
/
setup-aether.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* Set up and build Aether. We build Aether as a separate artifact using
* webpack. We also rename certain esper files here and move those files
* into the public directory to be loaded dynamically at runtime by the
* browser and service workers.
*
* Note:
* esper-modern requires modern language plugin to be loaded otherwise it won't
* work correctly.
*/
const fs = require("fs-extra");
const webpack = require("webpack");
const path = require("path");
// List of esper langauge plugins we want to move into the public directory.
const targets = ["lua", "python", "coffeescript"];
const aether_webpack_config = {
context: path.resolve(__dirname),
entry: {
aether: "./app/lib/aether/aether.coffee",
// We need to create the html parser ourselves and move it ourselves into
// `/javascripts/app/vendor/aether-html.js`
html: "./app/lib/aether/html.coffee"
},
output: {
filename: "./aether/build/[name].js",
path: path.resolve(__dirname, 'bower_components'),
},
module: {
rules: [
{
test: /\.coffee$/,
use: ["coffee-loader"]
},
{
test: /\.mjs$/, // https://github.com/formatjs/formatjs/issues/1395#issuecomment-518823361
include: /node_modules/,
type: "javascript/auto"
},
{ test: /\.js$/,
exclude: /(node_modules|bower_components|vendor)/,
use: [{
loader: 'babel-loader'
}]
}
]
},
resolve: {
extensions: [".coffee", ".json", ".js"]
},
externals: {
"esper.js": "esper",
lodash: "_",
"source-map": "SourceMap"
},
node: {
fs: "empty"
},
mode: process.env.BRUNCH_ENV === "production" ? 'production' : 'development'
};
webpack(aether_webpack_config, function(err, stats) {
if (err) {
console.log(err);
} else {
console.log("Packed aether!");
if (stats.compilation.errors.length) {
console.error("Compilation errors:", stats.compilation.errors);
}
copyLanguagesFromEsper(targets);
}
});
function copyLanguagesFromEsper(targets) {
// Get a list of the regular and modern language plugin paths.
const target_paths = targets
.map(lang => [
[
path.join(
__dirname,
"bower_components",
"esper.js",
`esper-plugin-lang-${lang}.js`
),
path.join(
__dirname,
"public",
"javascripts",
"app",
"vendor",
`aether-${lang}.js`
)
],
[
path.join(
__dirname,
"bower_components",
"esper.js",
`esper-plugin-lang-${lang}-modern.js`
),
path.join(
__dirname,
"public",
"javascripts",
"app",
"vendor",
`aether-${lang}.modern.js`
)
]
])
.reduce((l, paths) => l.concat(paths));
for (let [src, dest] of target_paths) {
// const src = path.join(__dirname, 'bower_components', 'esper.js', `esper-plugin-lang-${target}.js`);
// const dest = path.join(__dirname, 'bower_components', 'aether', 'build', `${target}.js`);
console.log(`Copy ${src}, ${dest}`);
fs.copySync(src, dest);
}
// Finally copy html as we globally load these within the html iframe.
const src = path.join(
__dirname,
"bower_components",
"aether",
"build",
"html.js"
);
const dest = path.join(
__dirname,
"public",
"javascripts",
"app",
"vendor",
"aether-html.js"
);
fs.copySync(src, dest);
console.log(`Copy ${src}, ${dest}`);
}