This repository has been archived by the owner on May 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
__run.js
94 lines (87 loc) · 2.42 KB
/
__run.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
import { AtRule, Comment } from "postcss";
import { extension, stylesHint } from "../scss/stuff.js";
/** @type {import("../..").AdderRun<import("./__info.js").Options>} */
export const run = async ({ install, updateCss }) => {
await updateCss({
path: `/src/variables.${extension}`,
async style({ postcss }) {
postcss.append(
new AtRule({
name: "import",
params: '"bootstrap/scss/functions"',
}),
);
postcss.append(
new Comment({
text: "Override Bootstrap's variables here",
}),
);
postcss.append(
new AtRule({
name: "import",
params: '"bootstrap/scss/variables"',
}),
);
postcss.append(
new AtRule({
name: "import",
params: '"bootstrap/scss/variables-dark"',
}),
);
postcss.append(
new AtRule({
name: "import",
params: '"bootstrap/scss/maps"',
}),
);
postcss.append(
new AtRule({
name: "import",
params: '"bootstrap/scss/mixins"',
}),
);
postcss.append(
new AtRule({
name: "import",
params: '"bootstrap/scss/utilities"',
}),
);
return {
postcss,
};
},
});
await updateCss({
path: `/src/app.${extension}`,
async style({ postcss }) {
const imports = ["root", "reboot", "type", "images", "containers", "grid", "tables", "forms", "buttons", "transitions", "dropdown", "button-group", "nav", "navbar", "card", "accordion", "breadcrumb", "pagination", "badge", "alert", "progress", "list-group", "close", "toasts", "modal", "tooltip", "popover", "carousel", "spinners", "offcanvas", "placeholders", "helpers", "utilities/api"];
// They will be added with .append or .after, so reverse first to maintain the expected order
imports.reverse();
const [stylesHintComment] = postcss.nodes.filter((node) => node.type === "comment" && node.text === stylesHint);
for (const import_ of imports) {
const importAtRule = new AtRule({
name: "import",
params: `"bootstrap/scss/${import_}"`,
});
if (stylesHintComment) {
stylesHintComment.after(importAtRule);
} else {
postcss.prepend(importAtRule);
}
}
const importHint = new Comment({
text: "Import only what you need from Bootstrap",
});
if (stylesHintComment) {
stylesHintComment.after(importHint);
} else {
postcss.prepend(importHint);
}
return {
postcss,
};
},
});
await install({ package: "bootstrap" });
await install({ package: "@popperjs/core" });
};