forked from hpi-schul-cloud/nuxt-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aliases.config.js
93 lines (86 loc) · 2.37 KB
/
aliases.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
const path = require("path");
const fs = require("fs");
const prettier = require("prettier");
const themeName = process.env.SC_THEME || "default";
const variation = require("./variation")(themeName);
const aliases = {
...variation,
"@": "src",
"@@": ".",
"@locale": "locale",
"@assets": "src/assets",
"@components": "src/components",
"@storyComponents": "stories/components",
"@basecomponents": "src/components/base",
"@docs": "docs",
"@layouts": "src/layouts",
"@middleware": "src/middleware",
"@mixins": "src/mixins",
"@pages": "src/pages",
"@utils": "src/utils",
"@plugins": "src/plugins",
"@serverMiddleware": "src/serverMiddleware",
"@store": "src/store",
"@static": `src/themes/${themeName}/static`,
"@theme": `src/themes/${themeName}`,
"@styles": `src/themes/${themeName}/styles/index.scss`,
"@styles-default": `src/themes/default/styles`,
"@variables": `src/themes/${themeName}/styles/variables.scss`,
};
module.exports = {
webpack: {},
jest: {},
jsconfig: {},
};
for (const alias in aliases) {
const aliasTo = aliases[alias];
module.exports.webpack[alias] = resolveSrc(aliasTo);
const aliasHasExtension = /\.\w+$/.test(aliasTo);
module.exports.jest[`^${alias}$`] = aliasHasExtension
? `<rootDir>/${aliasTo}`
: `<rootDir>/${aliasTo}/index.js`;
module.exports.jest[`^${alias}/(.*)$`] = `<rootDir>/${aliasTo}/$1`;
module.exports.jsconfig[alias + "/*"] = [aliasTo + "/*"];
module.exports.jsconfig[alias] = aliasTo.includes("/index.")
? [aliasTo]
: [
aliasTo + "/index.js",
aliasTo + "/index.json",
aliasTo + "/index.vue",
aliasTo + "/index.scss",
aliasTo + "/index.css",
];
}
createConfigFile("./jsconfig.template", "jsconfig.json");
createConfigFile("./tsconfig.template", "tsconfig.json");
function createConfigFile(templateFilePath, configFilePath) {
const template = require(templateFilePath) || {};
const filePath = resolveSrc(configFilePath);
fs.writeFile(
filePath,
prettier.format(
JSON.stringify({
...template,
compilerOptions: {
...(template.compilerOptions || {}),
paths: module.exports.jsconfig,
},
}),
{
...require("./.prettierrc"),
parser: "json",
}
),
(error) => {
if (error) {
console.error(
`Error while creating ${configFilePath} from aliases.config.js.`
);
throw error;
}
}
);
}
function resolveSrc(_path) {
return path.resolve(__dirname, _path);
}