forked from umijs/father
/
schema.ts
78 lines (72 loc) · 2.61 KB
/
schema.ts
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
import type { Root, SchemaLike } from '@umijs/utils/compiled/@hapi/joi';
import { IFatherPlatformTypes } from '../../types';
function getCommonSchemas(): Record<string, (Joi: Root) => any> {
return {
platform: (Joi) =>
Joi.equal(
IFatherPlatformTypes.BROWSER,
IFatherPlatformTypes.NODE,
).default(IFatherPlatformTypes.BROWSER),
define: (Joi) =>
Joi.object().pattern(Joi.string(), Joi.string()).optional(),
alias: (Joi) => Joi.object().pattern(Joi.string(), Joi.string()).optional(),
postcssOptions: (Joi) => Joi.object().optional(),
autoprefixer: (Joi) => Joi.object().optional(),
extraBabelPresets: (Joi) => Joi.array().optional(),
extraBabelPlugins: (Joi) => Joi.array().optional(),
sourcemap: (Joi) => Joi.boolean().optional(),
};
}
function getCommonSchemasJoi(Joi: Root) {
const schemas = getCommonSchemas();
return Object.keys(schemas).reduce((jois, key) => {
jois[key] = schemas[key](Joi);
return jois;
}, {} as Record<string, SchemaLike | SchemaLike[]>);
}
function getBundlessSchemas(Joi: Root) {
return Joi.object({
...getCommonSchemasJoi(Joi),
input: Joi.string(),
output: Joi.string(),
transformer: Joi.string(),
overrides: Joi.object(),
ignores: Joi.array().items(Joi.string()),
targets: Joi.alternatives().try(Joi.object(), Joi.string()).optional(),
});
}
export function getSchemas(): Record<string, (Joi: Root) => any> {
return {
...getCommonSchemas(),
extends: (Joi) => Joi.string(),
esm: (Joi) => getBundlessSchemas(Joi),
cjs: (Joi) => getBundlessSchemas(Joi),
umd: (Joi) =>
Joi.object({
...getCommonSchemasJoi(Joi),
entry: Joi.alternatives()
.try(Joi.string(), Joi.object().pattern(Joi.string(), Joi.object()))
.optional(),
output: Joi.string().optional(),
externals: Joi.object().pattern(Joi.string(), Joi.string()),
chainWebpack: Joi.function().optional(),
extractCSS: Joi.boolean().optional(),
name: Joi.string().optional(),
theme: Joi.object().pattern(Joi.string(), Joi.string()),
targets: Joi.object().optional(),
}),
prebundle: (Joi) =>
Joi.object({
output: Joi.string(),
deps: Joi.alternatives()
.try(Joi.array().items(Joi.string()), Joi.object())
.optional(),
extraDtsDeps: Joi.array().items(Joi.string()),
extraExternals: Joi.object()
.pattern(Joi.string(), Joi.string())
.optional(),
}),
plugins: (Joi) => Joi.array().items(Joi.string()),
presets: (Joi) => Joi.array().items(Joi.string()),
};
}