@adamlui/scss-to-css 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  ### Recursively compile all SCSS files into minified CSS.
4
4
 
5
5
  <a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-fcde7b.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
6
- <a href="https://www.npmjs.com/package/@adamlui/scss-to-css"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.1.1-fc7811.svg?logo=npm&logoColor=white&labelColor=464646&style=for-the-badge"></a>
6
+ <a href="https://www.npmjs.com/package/@adamlui/scss-to-css"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.2.0-fc7811.svg?logo=npm&logoColor=white&labelColor=464646&style=for-the-badge"></a>
7
7
 
8
8
  <img height=8px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/media/images/separators/aqua.png">
9
9
 
@@ -44,7 +44,7 @@ scss-to-css <input_path> <output_path>
44
44
  ```
45
45
 
46
46
  - `<input_path>`: Path to directory containing SCSS files to be compiled, relative to the current working directory.
47
- - `<output_path>`: Path to directory where CSS/sourcemap files will be stored, relative to original file location. (If not provided, same location is used.)
47
+ - `<output_path>`: Path to directory where CSS/sourcemap files will be stored, relative to original file location. (If not provided, `css/` is used.)
48
48
 
49
49
  **💡 Note:** The paths can be either folders or specific files. If folders are passed, files will be processed recursively.
50
50
 
@@ -63,19 +63,19 @@ Replace `<scss-to-css-cmd>` with `scss-to-css` + optional args. Then, `npm run b
63
63
 
64
64
  ## 📃 Example commands:
65
65
 
66
- - Compile all SCSS files in the **current directory** (outputs to same directory`):
66
+ - Compile all SCSS files in the **current directory** (outputs to `css/`):
67
67
 
68
68
  ```
69
69
  scss-to-css
70
70
  ```
71
71
 
72
- - Compile all SCSS files in a **specific directory** (outputs to `path/to/your/directory/`):
72
+ - Compile all SCSS files in a **specific directory** (outputs to `path/to/your/directory/css/`):
73
73
 
74
74
  ```
75
75
  scss-to-css path/to/your/directory
76
76
  ```
77
77
 
78
- - Compile a **specific file** (outputs to `path/to/your/minified/file.min.css`):
78
+ - Compile a **specific file** (outputs to `path/to/your/css/file.min.css`):
79
79
 
80
80
  ```
81
81
  scss-to-css path/to/your/file.scss
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamlui/scss-to-css",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Recursively compile all SCSS files into minified CSS",
5
5
  "author": {
6
6
  "name": "Adam Lui",
package/scss-to-css.js CHANGED
@@ -23,21 +23,19 @@ if (process.argv[2] && !fs.existsSync(inputArg)) {
23
23
  }
24
24
 
25
25
  // Recursively find all SCSS files or arg-passed file
26
- const inputPath = path.resolve(process.cwd(), inputArg);
27
- const scssFiles = inputArg.endsWith('.scss') ? [inputPath]
28
- : (() => {
29
- const fileList = [];
30
- (function findSCSSfiles(dir) {
31
- const files = fs.readdirSync(dir);
32
- files.forEach(file => {
33
- const filePath = path.resolve(dir, file);
34
- if (fs.statSync(filePath).isDirectory())
35
- findSCSSfiles(filePath); // recursively find SCSS
36
- else if (/\.scss$/.test(file)) // SCSS file found
37
- fileList.push(filePath); // store it for minification
38
- });
39
- })(inputPath); return fileList;
40
- })();
26
+ const inputPath = path.resolve(process.cwd(), inputArg),
27
+ scssFiles = [];
28
+ if (inputArg.endsWith('.scss')) scssFiles.push(inputPath);
29
+ else (function findSCSSfiles(dir) {
30
+ const files = fs.readdirSync(dir);
31
+ files.forEach(file => {
32
+ const filePath = path.resolve(dir, file);
33
+ if (fs.statSync(filePath).isDirectory())
34
+ findSCSSfiles(filePath); // recursively find SCSS
35
+ else if (/\.scss$/.test(file)) // SCSS file found
36
+ scssFiles.push(filePath); // store it for minification
37
+ });
38
+ })(inputPath);
41
39
 
42
40
  // Compile SCSS files to CSS
43
41
  let generatedCnt = 0;
@@ -46,8 +44,9 @@ scssFiles.forEach(scssPath => {
46
44
  try { // to compile it
47
45
  const outputDir = path.join(
48
46
  path.dirname(scssPath), // path of file to be minified
49
- outputArg.endsWith('.css') ? path.dirname(outputArg) : outputArg, // path from output arg
50
- path.dirname(scssPath).endsWith('scss') ? '../css' : '' // ../css/ if in scss/
47
+ /(src|s[ac]ss)$/.test(path.dirname(scssPath)) ? '../css' // + ../css/ if in *(src|sass|scss)/
48
+ : outputArg.endsWith('.css') ? path.dirname(outputArg) // or path from file output arg
49
+ : outputArg || 'css' // or path from path output arg or css/ from no arg
51
50
  );
52
51
  const outputFilename = (
53
52
  outputArg.endsWith('.css') && inputArg.endsWith('.scss')
@@ -67,5 +66,9 @@ scssFiles.forEach(scssPath => {
67
66
  });
68
67
 
69
68
  // Print final summary
70
- if (generatedCnt) console.info(`\n${bg}Compilation complete!${nc}\n${ generatedCnt } files generated.`);
71
- else console.info(`\n${by}No SCSS files found.${nc}`);
69
+ if (generatedCnt) {
70
+ const isPlural = generatedCnt/2 > 1;
71
+ console.info(`\n${bg}Compilation complete!${nc}`);
72
+ console.info(`\n${ generatedCnt/2 } CSS file${ isPlural ? 's' : '' }`
73
+ + ` + ${ generatedCnt/2 } source map${ isPlural ? 's' : '' } generated.`);
74
+ } else console.info(`\n${by}No SCSS files found.${nc}`);