This repository was archived by the owner on May 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path__info.js
92 lines (76 loc) · 2.98 KB
/
__info.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
import { extension } from "./stuff.js";
export const name = "PostCSS";
export const emoji = "🔺";
export const usageMarkdown = ['You can write PostCSS syntax in the `style lang="postcss"` blocks in Svelte files.', "You can write PostCSS syntax in the `src/app.pcss` file.\n\n This is your global stylesheet because it will be active on every page of your site.", "You can install more [PostCSS plugins](https://github.com/postcss/postcss/blob/main/docs/plugins.md) and configure them in the `postcss.config.cjs` file."];
/** @type {import("../..").Gatekeep} */
export const gatekeep = async () => {
return { able: true };
};
/** @typedef {{ autoprefixer: boolean }} Options */
/** @type {import("../..").AdderOptions<Options>} */
export const options = {
autoprefixer: {
context: "https://github.com/postcss/autoprefixer",
default: true,
descriptionMarkdown: "whether or not to install and set up [Autoprefixer](https://github.com/postcss/autoprefixer).",
question: "Do you want to use Autoprefixer?",
},
};
/** @type {import("../..").Heuristic[]} */
export const heuristics = [
{
description: "`postcss` is installed",
async detector({ folderInfo }) {
return "postcss" in folderInfo.allDependencies;
},
},
{
description: "`postcss-load-config` is installed",
async detector({ folderInfo }) {
return "postcss-load-config" in folderInfo.allDependencies;
},
},
{
description: "`vitePreprocess` reads PostCSS config implicitly in `svelte.config.js`",
async detector({ readFile }) {
const js = await readFile({ path: "/svelte.config.js" });
const cjs = await readFile({ path: "/svelte.config.cjs" });
/** @param {string} text */
const preprocessIsProbablySetup = (text) => {
if (!text.includes("vitePreprocess")) return false;
return true;
};
if (js.exists) return preprocessIsProbablySetup(js.text);
else if (cjs.exists) return preprocessIsProbablySetup(cjs.text);
return false;
},
},
{
description: "`postcss.config.cjs` exists and `postcss.config.js` does not exist",
async detector({ readFile }) {
const cjs = await readFile({ path: "/postcss.config.cjs" });
const js = await readFile({ path: "/postcss.config.js" });
return cjs.exists && !js.exists;
},
},
{
description: `\`src/app.${extension}\` exists`,
async detector({ readFile }) {
const postcss = await readFile({ path: `/src/app.${extension}` });
return postcss.exists;
},
},
{
description: `The main file (\`src/routes/+layout.svelte\` for SvelteKit, \`src/main.js\` or \`src/main.ts\` for Vite) imports \`src/app.${extension}\``,
async detector({ folderInfo, readFile }) {
if (folderInfo.kit) {
const { text } = await readFile({ path: "/src/routes/+layout.svelte" });
return text.includes(`../app.${extension}`);
}
const ts = await readFile({ path: "/src/main.ts" });
if (ts.exists) return ts.text.includes(`./app.${extension}`);
const js = await readFile({ path: "/src/main.js" });
return js.text.includes(`./app.${extension}`);
},
},
];