Download wp-calypso/bin/codemods/src/remove-rgb-css-variables.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/bin/codemods/src/remove-rgb-css-variables.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/bin/codemods/src/remove-rgb-css-variables.js
-
curl -L -o remove-rgb-css-variables.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/bin/codemods/src/remove-rgb-css-variables.js
1.46 kB
| const fs = require( 'fs' ); | |
| const { glob } = require( 'glob' ); | |
| // Function to remove SCSS variables ending with '-rgb' | |
| const removeRgbVariables = ( scssContent ) => { | |
| // Regular expression to match lines that define '-rgb' variables along with comments | |
| const rgbVarRegex = /^\s*--.*-rgb\s*:\s*[^;]*;\s*(?:\/\/.*|\/\*[\s\S]*?\*\/)?\s*\n?/gm; | |
| // Remove lines with '-rgb' variables (will not leave empty lines) | |
| return scssContent.replace( rgbVarRegex, '\t' ); | |
| }; | |
| // Function to process files in a specific directory | |
| const processScssFiles = async ( rootDir ) => { | |
| const scssFiles = glob.sync( `${ rootDir }/**/*.scss`, { | |
| ignore: [ '**/node_modules/**' ], | |
| } ); | |
| console.log( `Processing ${ rootDir }/**/*.scss, found`, scssFiles.length, 'files' ); | |
| scssFiles.forEach( async ( filePath ) => { | |
| const scssCode = fs.readFileSync( filePath, 'utf8' ); | |
| const fixedScssCode = removeRgbVariables( scssCode ); | |
| if ( scssCode !== fixedScssCode ) { | |
| fs.writeFileSync( filePath, fixedScssCode, 'utf8' ); | |
| console.log( `Fixed SCSS: ${ filePath }` ); | |
| } | |
| } ); | |
| }; | |
| // Run the codemod with a specified directory | |
| const rootDir = process.argv[ 2 ]; | |
| if ( ! rootDir ) { | |
| console.error( 'Usage: node remove-rgb-css-variables.js <scss_directory>' ); | |
| process.exit( 1 ); | |
| } | |
| // Run the cleanup process | |
| processScssFiles( rootDir ) | |
| .then( () => console.log( 'CSS variable cleanup complete!' ) ) | |
| .catch( ( err ) => console.error( 'An error occurred:', err ) ); | |