+36
-15
@@ -13,6 +13,10 @@ const fs = require('fs'), | ||
| ERROR: colors.red.bold('[ERROR]'), | ||
| } | ||
| }; | ||
| const less2scss = (src, dst) => { | ||
| const less2scss = (src, dst, recursive) => { | ||
| if (src) { | ||
| console.info(`${MESSAGE_PREFIX.INFO} ${colors.yellow(`Recursive option is ${colors.yellow.bold(recursive ? 'ON' : 'OFF')}`)}`); | ||
| const pathList = src.split(','); | ||
@@ -26,6 +30,2 @@ let lessFiles = [], | ||
| /** | ||
| * Resolve ~ with NodeJs | ||
| */ | ||
| if (beginPath[0] === '~') { | ||
@@ -40,7 +40,15 @@ beginPath = path.join(os.homedir(), beginPath.slice(1)); | ||
| if (curPathType.isDirectory()) { | ||
| lessFiles = glob.sync(`${beginPath}/*.less`); | ||
| lessFiles = [...lessFiles, ...glob | ||
| .sync(`${beginPath}/${recursive ? '**/*' : '*'}.less`) | ||
| .map(lessFile => ({ | ||
| src: lessFile, | ||
| relativePath: path.relative(beginPath, lessFile) | ||
| }))]; | ||
| } | ||
| if (curPathType.isFile()) { | ||
| lessFiles.push(beginPath); | ||
| lessFiles = [...lessFiles, { | ||
| src: beginPath, | ||
| relativePath: '' | ||
| }]; | ||
| } | ||
@@ -50,8 +58,17 @@ | ||
| lessFiles = lessFiles | ||
| .filter( | ||
| ({src}, index) => lessFiles.map(lessFile => lessFile.src).indexOf(src) === index | ||
| ); | ||
| if (lessFiles.length) { | ||
| lessFiles.forEach(file => { | ||
| const scssContent = replaceLess(file); | ||
| writeFile(file, scssContent, destinationPath); | ||
| const {src, relativePath} = file; | ||
| const scssContent = replaceLess(src); | ||
| writeFile(src, scssContent, destinationPath, relativePath); | ||
| }); | ||
| console.log(`${MESSAGE_PREFIX.INFO} ${colors.green('Enjoy your SCSS files ;)')}`); | ||
| console.log(`${colors.blue(`\n★ Pull requests and stars are always welcome.`)}`); | ||
| console.log(`${colors.blue(`https://github.com/debba/less2scss`)}`); | ||
| } else { | ||
@@ -134,3 +151,3 @@ console.log(`${MESSAGE_PREFIX.ERROR} ${colors.red.bold('No LESS file found.')}`); | ||
| const writeFile = (file, scssContent, destinationPath) => { | ||
| const writeFile = (file, scssContent, destinationPath, relativePath) => { | ||
@@ -140,9 +157,13 @@ let outputFile; | ||
| if (destinationPath) { | ||
| if (!fs.existsSync(destinationPath)) { | ||
| mkdirp.sync(destinationPath); | ||
| const newPath = relativePath !== '' ? path.dirname( destinationPath+'/'+relativePath ) : destinationPath; | ||
| if (!fs.existsSync(newPath)) { | ||
| mkdirp.sync(newPath); | ||
| } | ||
| outputFile = path.resolve(destinationPath, path.basename(file)).replace('.less', '.scss'); | ||
| outputFile = path.resolve(newPath, path.basename(file)).replace('.less', '.scss'); | ||
| } else { | ||
| outputFile = file.replace('.less', '.scss') | ||
| outputFile = file.replace('.less', '.scss'); | ||
| console.log(outputFile); | ||
| } | ||
@@ -149,0 +170,0 @@ |
+1
-1
| { | ||
| "name": "less2scss", | ||
| "version": "1.2.1", | ||
| "version": "1.3.0", | ||
| "description": "This utility quickly converts all your less files to scss.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+36
-7
@@ -11,3 +11,3 @@ [](https://nodei.co/npm/less2scss.png/) | ||
| Installation | ||
| Install | ||
| ------------- | ||
@@ -17,15 +17,40 @@ | ||
| ``` | ||
| $ npm install -g less2scss | ||
| ```bash | ||
| $ npm install less2scss --global | ||
| ``` | ||
| Usage | ||
| ------ | ||
| Go to your terminal and type the following: | ||
| `less2scss` offers a single command line interface: | ||
| ```bash | ||
| $ less2scss | ||
| ``` | ||
| $ less2scss -s path1,path2,path3 -d [destinationFolder] | ||
| Will print an help: | ||
| ``` | ||
| Paths could be a mixture of SCSS files and directories. | ||
| Usage: less2scss [options] | ||
| It will convert all of the scss files of the corresponding paths provided and will store the SCSS files in the destinationFolder if it's provided or in the same directory. | ||
| This utility quickly converts all your less files to scss. | ||
| Options: | ||
| -V, --version output the version number | ||
| -s, --src <sourcePaths> source paths comma separated | ||
| -d, --dst <dstPath> destination path | ||
| -r, --recursive allow to recursively walk directories (default: false) | ||
| -h, --help display help for command | ||
| ``` | ||
| Options | ||
| -------- | ||
| You can pass the following options via CLI arguments. | ||
| | Description | Short command | Full command | Mandatory | Default value | | ||
| | --------------------------------------------------------------------------------------------------------------------------------------- | ------------- | ------------------ | ------------------ | ------------------ | | ||
| | Comma separated LESS files and paths | `-s` | `--src` | Yes | - | | ||
| | Destination path for converted SCSS files (if provided). If not provided, it will be the same directory | `-d` | `--dst` | No | Same directory of files provided | | ||
| | Allow to recursively walk directories | `-r` | `--recursive` | No | false | | ||
| Notice | ||
@@ -46,2 +71,6 @@ -------- | ||
| Contributing | ||
| -------- | ||
| If you have suggestions for enhancements or ideas for new features that could be useful, please open a pull request or open an issue. | ||
| License | ||
@@ -48,0 +77,0 @@ -------- |
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
22680
12.31%142
11.81%78
59.18%2
100%