Skip to content

Commit 5204578

Browse files
committed
Remove constants file and retrieve values from twigUnusedCssFinder options
1 parent 3ae3c5e commit 5204578

File tree

6 files changed

+227
-101
lines changed

6 files changed

+227
-101
lines changed

index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
if (process.env.NODE_ENV === 'production') {
4+
module.exports = require('./dist/bundle.js');
5+
} else {
6+
module.exports = require('./dist/index.js');
7+
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
"name": "twig-unused-css-finder",
33
"version": "0.1.0",
44
"description": "A tool to find unused CSS in Twig templates",
5-
"main": "dist/bundle.js",
5+
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"scripts": {
8-
"build": "rollup -c",
8+
"build": "tsc && rollup -c",
9+
"prepublishOnly": "npm run build",
910
"start": "node dist/bundle.js",
1011
"dev": "rollup -c -w",
1112
"test": "echo \"Error: no test specified\" && exit 1"

src/constants.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/fileProcessors.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import * as fs from 'node:fs';
2-
import * as path from 'node:path';
1+
import * as fs from 'fs';
2+
import * as path from 'path';
33
import { extractClassesFromTemplate, extractClassesFromCss } from './extractors';
4-
import { UNCSS_TEMP_DIR } from './constants';
54

65
interface FileInfo {
76
name: string;
@@ -59,18 +58,20 @@ export function processCssFilesToExtractClasses(cssFiles: FileInfo[]): Extracted
5958
* Writes extracted template classes to a file
6059
* @param templateClasses - Array of objects containing extracted classes and file paths
6160
* @param fileName - Name of the output file
61+
* @param uncssTempDir - Temporary directory for uncss
6262
*/
63-
export function writeTemplateClassesToFile(templateClasses: ExtractedClasses[], fileName: string): void {
64-
const outputPath = path.join(UNCSS_TEMP_DIR, fileName);
63+
export function writeTemplateClassesToFile(templateClasses: ExtractedClasses[], fileName: string, uncssTempDir: string): void {
64+
const outputPath = path.join(uncssTempDir, fileName);
6565
fs.writeFileSync(outputPath, JSON.stringify(templateClasses, null, 2));
6666
}
6767

6868
/**
6969
* Writes extracted CSS selectors to a file
7070
* @param cssSelectors - Array of objects containing extracted selectors and file paths
7171
* @param fileName - Name of the output file
72+
* @param uncssTempDir - Temporary directory for uncss
7273
*/
73-
export function writeCssSelectorsToFile(cssSelectors: ExtractedSelectors[], fileName: string): void {
74-
const outputPath = path.join(UNCSS_TEMP_DIR, fileName);
74+
export function writeCssSelectorsToFile(cssSelectors: ExtractedSelectors[], fileName: string, uncssTempDir: string): void {
75+
const outputPath = path.join(uncssTempDir, fileName);
7576
fs.writeFileSync(outputPath, JSON.stringify(cssSelectors, null, 2));
7677
}

0 commit comments

Comments
 (0)