-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.js
76 lines (65 loc) · 1.65 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
//@ts-nocheck
const {stringify: $stringify, parse: $parse} = JSON
, {readFileSync} = require('fs')
, jsonImporter = require('node-sass-json-importer')
, ajv = require("ajv").default
, {langRec} = require("./utils/lang")
, Ajv = new ajv({
"strict": true,
"strictTypes": false,
"inlineRefs": true,
"allErrors": true,
"allowUnionTypes": true
})
module.exports = {
"assetPrefix": ".",
"sassOptions": {
"importer": jsonImporter()
},
"exportPathMap": (_, {dev}) => {
const {homepage, author: {name}, version} = require("./package.json")
, replacements = {
version,
name,
homepage: dev ? "" : homepage
}
, schema = readJsonSync("./public/schema.json")
, cv = readJsonSync("./public/cv.json", replacements)
, {$schema, ...data} = cv
, langs = {}
validate(schema, data)
for (const lang of schema.definitions.Langing.propertyNames.enum) {
const langed = langRec(lang, cv)
validate(schema, langed)
langs[lang] = langed
}
const page = "/"
, pathMap = {"/": {page, query: langs["en"]}}
for (const key in langs) {
pathMap[`/${key}`] = {page, query: langs[key]}
}
return pathMap
}
}
function readJsonSync(jsonPath, {homepage, name, version} = {}) {
return $parse(
readFileSync(jsonPath),
(_, v) => {
if (typeof v !== "string")
return v
// TODO require(project)
return eval("`"+ v.replace(/`/g, "\\`") + "`")
}
)
}
// Parameters<typeof Ajv.validate>
function validate(...args) {
if (!Ajv.validate(...args)) {
console.error($stringify(
Ajv.errors,
null,
2
))
process.exit(1)
}
}