@adamlui/scss-to-css 1.4.0 → 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,8 @@
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.0-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
+ <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>
8
9
 
9
10
  <img height=8px width="100%" src="https://github.com/adamlui/js-utils/blob/main/docs/images/aqua-separator.png">
10
11
 
@@ -27,21 +28,23 @@ npm install -D @adamlui/scss-to-css
27
28
  The basic **global command** is:
28
29
 
29
30
  ```
30
- scss-to-css
31
+ scsstocss
31
32
  ```
32
33
 
34
+ **💡 Note:** Pass `-n` or `--dry-run` to only see what files will be processed.
35
+
33
36
  Sample output:
34
37
 
35
38
  <img src="https://github.com/adamlui/js-utils/blob/main/scss-to-css/media/images/sample-output.png">
36
39
 
37
- **💡 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`.
38
41
 
39
42
  #
40
43
 
41
44
  To specify **input/output** paths:
42
45
 
43
46
  ```
44
- scss-to-css [input_path] [output_path]
47
+ scsstocss [input_path] [output_path]
45
48
  ```
46
49
 
47
50
  - `[input_path]`: Path to SCSS file or directory containing SCSS files to be compiled, relative to the current working directory.
@@ -51,7 +54,7 @@ scss-to-css [input_path] [output_path]
51
54
 
52
55
  #
53
56
 
54
- 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`:
55
58
 
56
59
  ```json
57
60
  "scripts": {
@@ -59,7 +62,7 @@ To use as a **package script**, edit your project's `package.json` like this:
59
62
  },
60
63
  ```
61
64
 
62
- Replace `<scss-to-css-cmd>` with `scss-to-css` + optional args. Then, `npm run build:css` can be used to run the command.
65
+ Replace `<scss-to-css-cmd>` with `scsstocss` + optional args. Then, `npm run build:css` can be used to run the command.
63
66
  <br><br>
64
67
 
65
68
  ## 📃 Example commands:
@@ -67,25 +70,25 @@ Replace `<scss-to-css-cmd>` with `scss-to-css` + optional args. Then, `npm run b
67
70
  - Compile all SCSS files in the **current directory** (outputs to `css/`):
68
71
 
69
72
  ```
70
- scss-to-css
73
+ scsstocss
71
74
  ```
72
75
 
73
76
  - Compile all SCSS files in a **specific directory** (outputs to `path/to/your/directory/css/`):
74
77
 
75
78
  ```
76
- scss-to-css path/to/your/directory
79
+ scsstocss path/to/your/directory
77
80
  ```
78
81
 
79
82
  - Compile a **specific file** (outputs to `path/to/your/css/file.min.css`):
80
83
 
81
84
  ```
82
- scss-to-css path/to/your/file.scss
85
+ scsstocss path/to/your/file.scss
83
86
  ```
84
87
 
85
88
  - Specify both **input and output** directories (outputs to `output_folder/`):
86
89
 
87
90
  ```
88
- scss-to-css input_folder output_folder
91
+ scsstocss input_folder output_folder
89
92
  ```
90
93
 
91
94
  ## 🏛️ MIT License
package/docs/SECURITY.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  If you find a vulnerability, please open a [draft security advisory](https://github.com/adamlui/js-utils/security/advisories/new).
4
4
 
5
- Pull requests are also welcome, but for safety reasons, send an email to adam@kudoai.com and wait for a response before making it public.
5
+ Pull requests are also welcome, but for safety reasons, send an email to <adam@kudoai.com> and wait for a response before making it public.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamlui/scss-to-css",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Recursively compile all SCSS files into minified CSS",
5
5
  "author": {
6
6
  "name": "Adam Lui",
@@ -11,6 +11,7 @@
11
11
  "license": "MIT",
12
12
  "main": "scss-to-css.js",
13
13
  "bin": {
14
+ "scsstocss": "scss-to-css.js",
14
15
  "scss-to-css": "scss-to-css.js"
15
16
  },
16
17
  "scripts": {
package/scss-to-css.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- // Import libs
3
+ // Import LIBS
4
4
  const fs = require('fs'),
5
5
  path = require('path'),
6
6
  sass = require('sass');
@@ -11,53 +11,32 @@ const nc = '\x1b[0m', // no color
11
11
  by = '\x1b[1;33m', // bright yellow
12
12
  bg = '\x1b[1;92m'; // bright green
13
13
 
14
- // Show help screen if -h or --help passed
14
+ // Show HELP screen if -h or --help passed
15
15
  if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
16
16
 
17
17
  // Print help
18
- console.info(`\n${by}scss-to-css [inputPath] [outputPath] [options]${nc}`);
18
+ console.info(`\n${by}scsstocss [inputPath] [outputPath] [options]${nc}`);
19
19
  console.info('\nPath arguments:');
20
- printWrappedMsg(' [input_path] '
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(' [output_path] '
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
-
33
- function printWrappedMsg(msg) { // indents 2nd+ lines
34
- const terminalWidth = process.stdout.columns || 80,
35
- indentation = 29, lines = [], words = msg.match(/\S+|\s+/g);
36
-
37
- // Split msg into lines of appropriate lengths
38
- let currentLine = '';
39
- words.forEach(word => {
40
- const lineLength = terminalWidth - ( lines.length === 0 ? 0 : indentation );
41
- if (currentLine.length + word.length > lineLength) { // cap/store it
42
- lines.push(lines.length === 0 ? currentLine : currentLine.trimStart());
43
- currentLine = '';
44
- }
45
- currentLine += word;
46
- });
47
- lines.push(lines.length === 0 ? currentLine : currentLine.trimStart());
32
+ printWrappedMsg(' -h, --help Display this help screen.');
33
+ printWrappedMsg(' -v, --version Show version number.');
48
34
 
49
- // Print formatted msg
50
- lines.forEach((line, index) => {
51
- if (index === 0) console.info(line); // print 1st line unindented
52
- else console.info(' '.repeat(indentation) + line); // print subsequent lines indented
53
- });
54
- }
55
-
56
- // Show version number if -v or --version passed
57
- } else if (process.argv.some(arg => /^--?v(?:er(?:s(?:ion)?)?)?$/.test(arg))) {
35
+ // Show VERSION number if -v or --version passed
36
+ } else if (process.argv.some(arg => /^--?ve?r?s?i?o?n?$/.test(arg))) {
58
37
  console.info('v' + require('./package.json').version);
59
38
 
60
- } else { // run main routine
39
+ } else { // run MAIN routine
61
40
 
62
41
  // Init I/O args
63
42
  const [inputArg = '', outputArg = ''] = ( // default to empty strings for error-less handling
@@ -71,12 +50,13 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
71
50
  if (inputArg && !fs.existsSync(inputPath)) {
72
51
  console.error(`\n${br}Error: First arg must be an existing file or directory.`
73
52
  + `\n${ inputPath } does not exist.${nc}`
74
- + '\n\nExample valid command: \n>> scss-to-css . output.min.css');
53
+ + '\n\nExample valid command: \n>> scsstocss . output.min.css');
75
54
  process.exit(1);
76
55
  }
77
56
 
78
57
  // Load flag settings
79
58
  const config = {
59
+ dryRun: process.argv.some(arg => /^--?(?:n|dry-?run)$/.test(arg)),
80
60
  includeDotFolders: process.argv.some(arg =>
81
61
  /^--?(?:dd|(?:include-)?dot-?(?:folder|dir(?:ector(?:y|ie))?)s?)$/.test(arg)),
82
62
  disableSourceMaps: process.argv.some(arg =>
@@ -98,41 +78,71 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
98
78
  });
99
79
  })(inputPath);
100
80
 
101
- // Compile SCSS files to CSS
102
- let cssGenCnt = 0, srcMapGenCnt = 0;
103
- console.log(''); // line break before first log
104
- scssFiles.forEach(scssPath => {
105
- console.info(`Compiling ${ scssPath }...`);
106
- try { // to compile it
107
- const outputDir = path.join(
108
- path.dirname(scssPath), // path of file to be minified
109
- /(?:src|s[ac]ss)$/.test(path.dirname(scssPath)) ? '../css' // + ../css/ if in *(src|sass|scss)/
110
- : outputArg.endsWith('.css') ? path.dirname(outputArg) // or path from file output arg
111
- : outputArg || 'css' // or path from folder output arg or css/ if no output arg passed
112
- );
113
- const outputFilename = (
114
- outputArg.endsWith('.css') && inputArg.endsWith('.scss')
115
- ? path.basename(outputArg).replace(/(\.min)?\.css$/, '')
116
- : path.basename(scssPath, '.scss')
117
- ) + '.min.css';
118
- const outputPath = path.join(outputDir, outputFilename),
119
- compileResult = sass.compile(scssPath, { style: 'compressed', sourceMap: !config.disableSourceMaps });
120
- if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
121
- fs.writeFileSync(outputPath, compileResult.css, 'utf8'); cssGenCnt++;
122
- if (!config.disableSourceMaps) {
123
- fs.writeFileSync(outputPath + '.map', JSON.stringify(compileResult.sourceMap), 'utf8');
124
- 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}`);
125
114
  }
126
- } catch (err) {
127
- console.error(`${br}Error compiling ${ scssPath }: ${ err.message }${nc}`);
115
+ });
116
+
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
+ }
125
+ }
126
+
127
+ function printWrappedMsg(msg) { // truncates msg, indents 2nd+ lines
128
+ const terminalWidth = process.stdout.columns || 80,
129
+ indentation = 30, lines = [], words = msg.match(/\S+|\s+/g);
130
+
131
+ // Split msg into lines of appropriate lengths
132
+ let currentLine = '';
133
+ words.forEach(word => {
134
+ const lineLength = terminalWidth - ( lines.length === 0 ? 0 : indentation );
135
+ if (currentLine.length + word.length > lineLength) { // cap/store it
136
+ lines.push(lines.length === 0 ? currentLine : currentLine.trimStart());
137
+ currentLine = '';
128
138
  }
139
+ currentLine += word;
129
140
  });
141
+ lines.push(lines.length === 0 ? currentLine : currentLine.trimStart());
130
142
 
131
- // Print final summary
132
- if (cssGenCnt) {
133
- console.info(`\n${bg}Compilation complete!${nc}`);
134
- console.info(`${ cssGenCnt } CSS file${ cssGenCnt > 1 ? 's' : '' }`
135
- + ( srcMapGenCnt ? ` + ${ srcMapGenCnt } source map${ srcMapGenCnt > 1 ? 's' : '' }` : '' )
136
- + ' generated.');
137
- } else console.info(`${by}No SCSS files found.${nc}`);
143
+ // Print formatted msg
144
+ lines.forEach((line, index) => console.info(
145
+ index === 0 ? line // print 1st line unindented
146
+ : ' '.repeat(indentation) + line // print subsequent lines indented
147
+ ));
138
148
  }