@adamlui/scss-to-css 1.4.1 → 1.4.2

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
@@ -4,7 +4,7 @@
4
4
 
5
5
  <a href="https://www.npmjs.com/package/@adamlui/scss-to-css"><img height=31 src="https://img.shields.io/npm/dt/%40adamlui%2Fscss-to-css?logo=npm&logoColor=white&labelColor=464646&style=for-the-badge"></a>
6
6
  <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>
7
- <a href="https://www.npmjs.com/package/@adamlui/scss-to-css?activeTab=versions"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.4.1-fc7811.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
7
+ <a href="https://www.npmjs.com/package/@adamlui/scss-to-css?activeTab=versions"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.4.2-fc7811.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
8
8
  <a href="https://www.npmjs.com/package/@adamlui/scss-to-css?activeTab=code"><img height=31 src="https://img.shields.io/npm/unpacked-size/%40adamlui%2Fscss-to-css?style=for-the-badge&logo=ebox&logoColor=white&labelColor=464646"></a>
9
9
 
10
10
  <img height=8px width="100%" src="https://github.com/adamlui/js-utils/blob/main/docs/images/aqua-separator.png">
@@ -31,11 +31,13 @@ The basic **global command** is:
31
31
  scsstocss
32
32
  ```
33
33
 
34
+ **💡 Note:** Pass `-n` or `--dry-run` to only see what files will be processed.
35
+
34
36
  Sample output:
35
37
 
36
38
  <img src="https://github.com/adamlui/js-utils/blob/main/scss-to-css/media/images/sample-output.png">
37
39
 
38
- **💡 Note:** Source maps are also generated by default unless `-S` or `--disable-source-maps` is passed.
40
+ **💡 Note:** Source maps are also generated by default unless `-S` or `--disable-source-maps` is passed. To only see what files will be processed, pass `-n` or `--dry-run`.
39
41
 
40
42
  #
41
43
 
@@ -52,7 +54,7 @@ scsstocss [input_path] [output_path]
52
54
 
53
55
  #
54
56
 
55
- To use as a **package script**, edit your project's `package.json` like this:
57
+ To use as a **package script**, in your project's `package.json`:
56
58
 
57
59
  ```json
58
60
  "scripts": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamlui/scss-to-css",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
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
@@ -17,18 +17,20 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
17
17
  // Print help
18
18
  console.info(`\n${by}scsstocss [inputPath] [outputPath] [options]${nc}`);
19
19
  console.info('\nPath arguments:');
20
- printWrappedMsg(' [inputPath] '
20
+ printWrappedMsg(' [inputPath] '
21
21
  + 'Path to SCSS file or directory containing SCSS files to be compiled,'
22
22
  + ' relative to the current working directory.');
23
- printWrappedMsg(' [outputPath] '
23
+ printWrappedMsg(' [outputPath] '
24
24
  + 'Path to file or directory where CSS + sourcemap files will be stored,'
25
25
  + ' relative to original file location (if not provided, css/ is used).');
26
26
  console.info('\nConfig options:');
27
- printWrappedMsg(' -dd, --include-dotfolders Include dotfolders in file search.');
28
- printWrappedMsg(' -S, --disable-source-maps Prevent source maps from being generated.');
27
+ printWrappedMsg(' -n, --dry-run Don\'t actually compile the file(s),'
28
+ + ' just show if they will be processed.');
29
+ printWrappedMsg(' -dd, --include-dotfolders Include dotfolders in file search.');
30
+ printWrappedMsg(' -S, --disable-source-maps Prevent source maps from being generated.');
29
31
  console.info('\nInfo commands:');
30
- printWrappedMsg(' -h, --help Display this help screen.');
31
- printWrappedMsg(' -v, --version Show version number.');
32
+ printWrappedMsg(' -h, --help Display this help screen.');
33
+ printWrappedMsg(' -v, --version Show version number.');
32
34
 
33
35
  // Show VERSION number if -v or --version passed
34
36
  } else if (process.argv.some(arg => /^--?ve?r?s?i?o?n?$/.test(arg))) {
@@ -54,6 +56,7 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
54
56
 
55
57
  // Load flag settings
56
58
  const config = {
59
+ dryRun: process.argv.some(arg => /^--?(?:n|dry-?run)$/.test(arg)),
57
60
  includeDotFolders: process.argv.some(arg =>
58
61
  /^--?(?:dd|(?:include-)?dot-?(?:folder|dir(?:ector(?:y|ie))?)s?)$/.test(arg)),
59
62
  disableSourceMaps: process.argv.some(arg =>
@@ -75,48 +78,55 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
75
78
  });
76
79
  })(inputPath);
77
80
 
78
- // Compile SCSS files to CSS
79
- let cssGenCnt = 0, srcMapGenCnt = 0;
80
- console.log(''); // line break before first log
81
- scssFiles.forEach(scssPath => {
82
- console.info(`Compiling ${ scssPath }...`);
83
- try { // to compile it
84
- const outputDir = path.join(
85
- path.dirname(scssPath), // path of file to be minified
86
- /(?:src|s[ac]ss)$/.test(path.dirname(scssPath)) ? '../css' // + ../css/ if in *(src|sass|scss)/
87
- : outputArg.endsWith('.css') ? path.dirname(outputArg) // or path from file output arg
88
- : outputArg || 'css' // or path from folder output arg or css/ if no output arg passed
89
- );
90
- const outputFilename = (
91
- outputArg.endsWith('.css') && inputArg.endsWith('.scss')
92
- ? path.basename(outputArg).replace(/(\.min)?\.css$/, '')
93
- : path.basename(scssPath, '.scss')
94
- ) + '.min.css';
95
- const outputPath = path.join(outputDir, outputFilename),
96
- compileResult = sass.compile(scssPath, { style: 'compressed', sourceMap: !config.disableSourceMaps });
97
- if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
98
- fs.writeFileSync(outputPath, compileResult.css, 'utf8'); cssGenCnt++;
99
- if (!config.disableSourceMaps) {
100
- fs.writeFileSync(outputPath + '.map', JSON.stringify(compileResult.sourceMap), 'utf8');
101
- srcMapGenCnt++;
81
+ if (config.dryRun) { // print files to be processed
82
+ console.info('\nSCSS files to be compiled:');
83
+ scssFiles.forEach(file => console.info(file));
84
+
85
+ } else { // actually compile SCSS files
86
+
87
+ // Compile SCSS files to CSS
88
+ let cssGenCnt = 0, srcMapGenCnt = 0;
89
+ console.log(''); // line break before first log
90
+ scssFiles.forEach(scssPath => {
91
+ console.info(`Compiling ${ scssPath }...`);
92
+ try { // to compile it
93
+ const outputDir = path.join(
94
+ path.dirname(scssPath), // path of file to be minified
95
+ /(?:src|s[ac]ss)$/.test(path.dirname(scssPath)) ? '../css' // + ../css/ if in *(src|sass|scss)/
96
+ : outputArg.endsWith('.css') ? path.dirname(outputArg) // or path from file output arg
97
+ : outputArg || 'css' // or path from folder output arg or css/ if no output arg passed
98
+ );
99
+ const outputFilename = (
100
+ outputArg.endsWith('.css') && inputArg.endsWith('.scss')
101
+ ? path.basename(outputArg).replace(/(\.min)?\.css$/, '')
102
+ : path.basename(scssPath, '.scss')
103
+ ) + '.min.css';
104
+ const outputPath = path.join(outputDir, outputFilename),
105
+ compileResult = sass.compile(scssPath, { style: 'compressed', sourceMap: !config.disableSourceMaps });
106
+ if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
107
+ fs.writeFileSync(outputPath, compileResult.css, 'utf8'); cssGenCnt++;
108
+ if (!config.disableSourceMaps) {
109
+ fs.writeFileSync(outputPath + '.map', JSON.stringify(compileResult.sourceMap), 'utf8');
110
+ srcMapGenCnt++;
111
+ }
112
+ } catch (err) {
113
+ console.error(`${br}Error compiling ${ scssPath }: ${ err.message }${nc}`);
102
114
  }
103
- } catch (err) {
104
- console.error(`${br}Error compiling ${ scssPath }: ${ err.message }${nc}`);
105
- }
106
- });
115
+ });
107
116
 
108
- // Print final summary
109
- if (cssGenCnt) {
110
- console.info(`\n${bg}Compilation complete!${nc}`);
111
- console.info(`${ cssGenCnt } CSS file${ cssGenCnt > 1 ? 's' : '' }`
112
- + ( srcMapGenCnt ? ` + ${ srcMapGenCnt } source map${ srcMapGenCnt > 1 ? 's' : '' }` : '' )
113
- + ' generated.');
114
- } else console.info(`${by}No SCSS files found.${nc}`);
117
+ // Print final summary
118
+ if (cssGenCnt) {
119
+ console.info(`\n${bg}Compilation complete!${nc}`);
120
+ console.info(`${ cssGenCnt } CSS file${ cssGenCnt > 1 ? 's' : '' }`
121
+ + ( srcMapGenCnt ? ` + ${ srcMapGenCnt } source map${ srcMapGenCnt > 1 ? 's' : '' }` : '' )
122
+ + ' generated.');
123
+ } else console.info(`${by}No SCSS files found.${nc}`);
124
+ }
115
125
  }
116
126
 
117
127
  function printWrappedMsg(msg) { // truncates msg, indents 2nd+ lines
118
128
  const terminalWidth = process.stdout.columns || 80,
119
- indentation = 29, lines = [], words = msg.match(/\S+|\s+/g);
129
+ indentation = 30, lines = [], words = msg.match(/\S+|\s+/g);
120
130
 
121
131
  // Split msg into lines of appropriate lengths
122
132
  let currentLine = '';