MCPcopy
hub / github.com/FullHuman/purgecss / run

Function run

packages/purgecss/src/bin.ts:145–175  ·  view source on GitHub ↗
(program: Command)

Source from the content-addressed store, hash-verified

143}
144
145export async function run(program: Command) {
146 const options = await getOptions(program);
147 const { preservePaths, ...purgeOptions } = options;
148 const purged = await new PurgeCSS().purge(purgeOptions);
149
150 // output results in specified directory
151 if (options.output) {
152 if (purged.length === 1 && options.output.endsWith(".css")) {
153 await writeCSSToFile(options.output, purged[0].css);
154 return;
155 }
156
157 for (const purgedResult of purged) {
158 let outputPath: string;
159 if (preservePaths && purgedResult?.file) {
160 // Preserve the folder hierarchy
161 outputPath = `${options.output}/${purgedResult.file}`;
162 } else {
163 // Default behavior: flatten to just the filename
164 const fileName = purgedResult?.file?.split("/").pop();
165 outputPath = `${options.output}/${fileName}`;
166 }
167 // Ensure the directory exists
168 const dir = outputPath.substring(0, outputPath.lastIndexOf("/"));
169 await fs.promises.mkdir(dir, { recursive: true });
170 await writeCSSToFile(outputPath, purgedResult.css);
171 }
172 } else {
173 console.log(JSON.stringify(purged));
174 }
175}
176
177export async function main() {
178 try {

Calls 3

getOptionsFunction · 0.85
writeCSSToFileFunction · 0.85
purgeMethod · 0.80

Tested by

no test coverage detected