forked from svelte-add/sass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__run.js
86 lines (73 loc) · 2.14 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
import { Comment } from "postcss";
import { setupStyleLanguage, updateViteConfig } from "../../adder-tools.js";
import { setDefault, setPropertyValue } from "../../ast-tools.js";
import { extension, stylesHint, variablesHint } from "./stuff.js";
/** @type {import("../..").AdderRun<import("./__info.js").Options>} */
export const run = async ({ folderInfo, install, updateCss, updateJavaScript, updateSvelte }) => {
const importVariables = '@use "src/variables.sass" as *';
await setupStyleLanguage({
extension,
folderInfo,
mutateSveltePreprocessArgs() {},
stylesHint,
updateCss,
updateJavaScript,
updateSvelte,
});
await updateViteConfig({
mutateViteConfig(viteConfig) {
const cssConfigObject = setDefault({
object: viteConfig,
default: {
type: "ObjectExpression",
properties: [],
},
property: "css",
});
if (cssConfigObject.type !== "ObjectExpression") throw new Error("css in Vite config must be an object");
const preprocessorOptionsConfigObject = setDefault({
object: cssConfigObject,
default: {
type: "ObjectExpression",
properties: [],
},
property: "preprocessorOptions",
});
if (preprocessorOptionsConfigObject.type !== "ObjectExpression") throw new Error("preprocessorOptions in css in Vite config must be an object");
const sassConfigObject = setDefault({
object: preprocessorOptionsConfigObject,
default: {
type: "ObjectExpression",
properties: [],
},
property: "sass",
});
if (sassConfigObject.type !== "ObjectExpression") throw new Error("sass in preprocessorOptions in css in Vite config must be an object");
setPropertyValue({
object: sassConfigObject,
property: "additionalData",
value: {
type: "Literal",
value: importVariables,
},
});
},
updateJavaScript,
folderInfo,
});
await updateCss({
path: `/src/variables.${extension}`,
async style({ postcss }) {
postcss.prepend(
new Comment({
text: variablesHint,
})
);
return {
postcss,
};
},
});
await install({ package: "sass" });
if (!folderInfo.kit) await install({ package: "@sveltejs/vite-plugin-svelte" });
};