-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.js
109 lines (89 loc) · 2.63 KB
/
next.config.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
// @ts-check
// This file is the main configuration of the MathHub nextjs app.
// It's read only once, and directly from within node.
// For this reason we can't use "import" statements, as node doesn't natively support them.
const { resolve } = require("path");
const { ProvidePlugin } = require("webpack");
const gitRevSync = require("git-rev-sync");
const localeManifest = require("./src/locales/data/manifest.json");
/** @type{import("./src/types/config").IMathHubConfig} */
const config = {
"MATHHUB_VERSION": mathhubversion(),
// read the rest of the environment variables from the real environment
// TODO: Consider moving these directly into NEXT_PUBLIC_ so that they're easier to setup
...readenv([
"LIBRARY_URL",
"NEWS_URL",
"GLOSSARY_URL",
"TRANSLATION_URL",
"ADMIN_URL",
"UPSTREAM_BASE_URL",
])
}
module.exports = {
i18n: {
locales: localeManifest,
defaultLocale: localeManifest[0],
},
poweredByHeader: false,
webpack,
env: {MATHHUB_CONFIG: config},
};
/**
* webpack updates the webpack configuration
* @param {import("webpack").Configuration} config
* @param {*} options
* @return {import("webpack").Configuration}
*/
function webpack(config, options) {
// when we are not on the server, we need to provide jquery
if (!options.isServer) {
config.plugins.push(new ProvidePlugin({ "$": "jQuery", "jQuery": "jquery" }));
}
return config;
}
/**
* Build version information about this version of MathHub.
*
* @returns {import("./src/types/config").IMathHubVersion}
*/
function mathhubversion() {
const pkg = require("./package.json").version; // TODO: Use readfile
const root = resolve(__dirname, "..");
/** @type {import("./src/types/config").IMathHubVersion["git"] | undefined} */
let git = undefined;
try {
const gitHash = gitRevSync.long(root);
if (!gitHash) {
throw new Error("no git hash");
}
git = { hash: gitHash };
try {
const branch = gitRevSync.branch(root);
git.branch = branch ? (branch + "") : undefined;
} catch (f) { }
try {
git.dirty = gitRevSync.isDirty();
} catch (f) { }
try {
git.time = gitRevSync.date().getTime();
} catch (f) { }
} catch (e) { }
return {
semantic: pkg,
configTime: new Date().getTime(),
git: git,
};
}
/**
* Readenv reads variables from the environment and returns a dictionary containing them.
*
* @param {string[]} variables
* @return {Object.<string, string>}
*/
function readenv(variables) {
/** @type Object.<string, string> */
const dict = {};
variables.forEach(v => dict[v] = process.env[v] || undefined);
return dict;
}