@adamlui/scss-to-css 1.6.1 → 1.7.1
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 +64 -50
- package/docs/LICENSE.md +3 -1
- package/docs/SECURITY.md +3 -1
- package/package.json +1 -1
- package/scss-to-css.js +93 -52
package/README.md
CHANGED
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
<a href="https://github.com/adamlui/js-utils/tree/main/scss-to-css/docs/hi#readme">हिंदी</a> |
|
|
11
11
|
<a href="https://github.com/adamlui/js-utils/tree/main/scss-to-css/docs/bn#readme">বাংলা</a> |
|
|
12
12
|
<a href="https://github.com/adamlui/js-utils/tree/main/scss-to-css/docs/mr#readme">मराठी</a> |
|
|
13
|
-
<a href="https://github.com/adamlui/js-utils/tree/main/scss-to-css/docs/pa#readme">ਪੰਜਾਬੀ</a>
|
|
13
|
+
<a href="https://github.com/adamlui/js-utils/tree/main/scss-to-css/docs/pa#readme">ਪੰਜਾਬੀ</a> |
|
|
14
|
+
<a href="https://github.com/adamlui/js-utils/tree/main/scss-to-css/docs/es#readme">Español</a> |
|
|
15
|
+
<a href="https://github.com/adamlui/js-utils/tree/main/scss-to-css/docs/pt#readme">Português</a>
|
|
14
16
|
</h6>
|
|
15
17
|
</div>
|
|
16
18
|
|
|
@@ -18,40 +20,44 @@
|
|
|
18
20
|
|
|
19
21
|
### Recursively compile all SCSS files into minified CSS.
|
|
20
22
|
|
|
21
|
-
<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>
|
|
22
|
-
<a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-
|
|
23
|
-
<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.
|
|
23
|
+
<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&color=af68ff&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
24
|
+
<a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
25
|
+
<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.7.1-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
24
26
|
<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&color=blue&labelColor=464646"></a>
|
|
25
27
|
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:scss-to-css/scss-to-css.js"><img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_js-utils%3Ascss-to-css%2Fscss-to-css.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=Vulnerabilities&color=gold"></a>
|
|
26
28
|
|
|
27
|
-
<img height=
|
|
29
|
+
<img height=6px width="100%" src="https://github.com/adamlui/js-utils/blob/main/docs/images/aqua-separator.png">
|
|
28
30
|
|
|
29
31
|
## ⚡ Installation
|
|
30
32
|
|
|
31
33
|
As a **global utility**:
|
|
32
34
|
|
|
33
35
|
```
|
|
34
|
-
npm install -g @adamlui/scss-to-css
|
|
36
|
+
$ npm install -g @adamlui/scss-to-css
|
|
35
37
|
```
|
|
36
38
|
|
|
37
39
|
As a **dev dependency** (e.g. for build scripts), from your project root:
|
|
38
40
|
|
|
39
41
|
```
|
|
40
|
-
npm install -D @adamlui/scss-to-css
|
|
42
|
+
$ npm install -D @adamlui/scss-to-css
|
|
41
43
|
```
|
|
42
44
|
|
|
43
45
|
As a **runtime dependency** (e.g. for on-the-fly compilation), from your project root:
|
|
44
46
|
|
|
45
47
|
```
|
|
46
|
-
npm install @adamlui/scss-to-css
|
|
48
|
+
$ npm install @adamlui/scss-to-css
|
|
47
49
|
```
|
|
48
50
|
|
|
51
|
+
<br>
|
|
52
|
+
|
|
53
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
54
|
+
|
|
49
55
|
## 💻 Command line usage
|
|
50
56
|
|
|
51
57
|
The basic **global command** is:
|
|
52
58
|
|
|
53
59
|
```
|
|
54
|
-
scss-to-css
|
|
60
|
+
$ scss-to-css
|
|
55
61
|
```
|
|
56
62
|
|
|
57
63
|
Sample output:
|
|
@@ -65,7 +71,7 @@ Sample output:
|
|
|
65
71
|
To specify **input/output** paths:
|
|
66
72
|
|
|
67
73
|
```
|
|
68
|
-
scss-to-css [input_path] [output_path]
|
|
74
|
+
$ scss-to-css [input_path] [output_path]
|
|
69
75
|
```
|
|
70
76
|
|
|
71
77
|
- `[input_path]`: Path to SCSS file or directory containing SCSS files to be compiled, relative to the current working directory.
|
|
@@ -84,36 +90,38 @@ To use as a **package script**, in your project's `package.json`:
|
|
|
84
90
|
```
|
|
85
91
|
|
|
86
92
|
Replace `<scss-to-css-cmd>` with `scss-to-css` + optional args. Then, `npm run build:css` can be used to run the command.
|
|
87
|
-
|
|
93
|
+
|
|
94
|
+
#
|
|
88
95
|
|
|
89
96
|
### Example commands
|
|
90
97
|
|
|
91
98
|
Compile all SCSS files in the **current directory** (outputs to `css/`):
|
|
92
99
|
|
|
93
100
|
```
|
|
94
|
-
scss-to-css
|
|
101
|
+
$ scss-to-css
|
|
95
102
|
```
|
|
96
103
|
|
|
97
104
|
Compile all SCSS files in a **specific directory** (outputs to `path/to/your/directory/css/`):
|
|
98
105
|
|
|
99
106
|
```
|
|
100
|
-
scss-to-css path/to/your/directory
|
|
107
|
+
$ scss-to-css path/to/your/directory
|
|
101
108
|
```
|
|
102
109
|
|
|
103
110
|
Compile a **specific file** (outputs to `path/to/your/css/file.min.css`):
|
|
104
111
|
|
|
105
112
|
```
|
|
106
|
-
scss-to-css path/to/your/file.scss
|
|
113
|
+
$ scss-to-css path/to/your/file.scss
|
|
107
114
|
```
|
|
108
115
|
|
|
109
116
|
Specify both **input and output** directories (outputs to `output_folder/`):
|
|
110
117
|
|
|
111
118
|
```
|
|
112
|
-
scss-to-css input_folder output_folder
|
|
119
|
+
$ scss-to-css input_folder output_folder
|
|
113
120
|
```
|
|
114
121
|
|
|
115
122
|
**💡 Note:** Output CSS is minified unless `-M` or `--no-minify` is passed.
|
|
116
|
-
|
|
123
|
+
|
|
124
|
+
#
|
|
117
125
|
|
|
118
126
|
### Command line options
|
|
119
127
|
|
|
@@ -128,11 +136,15 @@ Config options:
|
|
|
128
136
|
-q, --quiet Suppress all logging except errors.
|
|
129
137
|
|
|
130
138
|
Info commands:
|
|
131
|
-
-h, --help Display
|
|
139
|
+
-h, --help Display help screen.
|
|
132
140
|
-v, --version Show version number.
|
|
133
141
|
```
|
|
134
142
|
|
|
135
|
-
|
|
143
|
+
<br>
|
|
144
|
+
|
|
145
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
146
|
+
|
|
147
|
+
## 🔌 API usage
|
|
136
148
|
|
|
137
149
|
You can also import **scss-to-css** into your app to use its API methods, both as an ECMAScript module or a CommonJS module.
|
|
138
150
|
|
|
@@ -148,71 +160,73 @@ import * as scssToCSS from '@adamlui/scss-to-css';
|
|
|
148
160
|
const scssToCSS = require('@adamlui/scss-to-css');
|
|
149
161
|
```
|
|
150
162
|
|
|
151
|
-
|
|
163
|
+
#
|
|
164
|
+
|
|
165
|
+
### `compile(inputPath[, options])`
|
|
152
166
|
|
|
153
|
-
|
|
167
|
+
Compiles SCSS found in the `inputPath` provided into CSS data.
|
|
154
168
|
|
|
155
169
|
If a **file path** is passed, the file's code is compiled to CSS, then an object containing `srcPath` + `code` + `error` is returned:
|
|
156
170
|
|
|
157
171
|
```js
|
|
158
172
|
const compileResult = scssToCSS.compile('assets/style.scss');
|
|
159
|
-
|
|
160
|
-
console.log(compileResult.
|
|
173
|
+
|
|
174
|
+
console.log(compileResult.error); // outputs runtime error, or `undefined` if no error
|
|
175
|
+
console.log(compileResult.code); // outputs compiled CSS from assets/style.scss
|
|
161
176
|
```
|
|
162
177
|
|
|
163
178
|
If a **directory path** is passed, SCSS files are searched for (recursively by default), each one's code is loaded then compiled, then an array of objects containing `srcPath` + `code` + `error` is returned:
|
|
164
179
|
|
|
165
180
|
```js
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
181
|
+
// Outputs paths to SCSS files in working directory + all nested directories
|
|
182
|
+
const compileResults = scssToCSS.compile('.');
|
|
183
|
+
compileResults.forEach(result => console.log(result.srcPath));
|
|
184
|
+
|
|
185
|
+
// Outputs compiled CSS from 2nd SCSS file if found, or `undefined` if not found
|
|
186
|
+
console.log(compileResults[1].code);
|
|
170
187
|
```
|
|
171
188
|
|
|
172
189
|
Options are boolean, passed as object properties. For example:
|
|
173
190
|
|
|
174
191
|
```js
|
|
192
|
+
// Returns array of data objects where `.code` contains unminified CSS
|
|
175
193
|
scssToCSS.compile(inputDir, { minify: false });
|
|
176
|
-
// returns data objects where `.code` contains unminified CSS
|
|
177
194
|
```
|
|
178
195
|
|
|
179
|
-
|
|
196
|
+
Available parameters (and their default settings) are:
|
|
180
197
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
```
|
|
198
|
+
Name | Desciption | Default value
|
|
199
|
+
-------------|---------------------------------------------------------|---------------
|
|
200
|
+
`recursive` | Recursively search for nested files if dir path passed. | `true`
|
|
201
|
+
`verbose` | Show logging in console/terminal. | `true`
|
|
202
|
+
`dotFolders` | Include dotfolders in file search. | `false`
|
|
203
|
+
`minify` | Minify output CSS. | `true`
|
|
204
|
+
`sourceMaps` | Generate CSS source maps. | `true`
|
|
189
205
|
|
|
190
|
-
|
|
206
|
+
#
|
|
207
|
+
|
|
208
|
+
### `findSCSS(searchDir[, options])`
|
|
191
209
|
|
|
192
|
-
|
|
210
|
+
Searches for all SCSS files within the `searchDir` string passed (useful for discovering what files [`compile()`](#compileinputpath-options) will process) and returns an array containing their filepaths.
|
|
193
211
|
|
|
194
212
|
Options are boolean, passed as object properties. For example:
|
|
195
213
|
|
|
196
214
|
```js
|
|
215
|
+
// Returns array containing filepaths to SCSS files in exactly `searchDir`
|
|
197
216
|
scssToCSS.findSCSS(searchDir, { recursive: false });
|
|
198
|
-
// returns array containing filepaths to SCSS files in exactly `searchDir`
|
|
199
217
|
```
|
|
200
218
|
|
|
201
|
-
|
|
219
|
+
Available parameters (and their default settings) are:
|
|
202
220
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
```
|
|
221
|
+
Name | Desciption | Default value
|
|
222
|
+
-------------|---------------------------------------------------------|---------------
|
|
223
|
+
`recursive` | Recursively search for nested files if dir path passed. | `true`
|
|
224
|
+
`verbose` | Show logging in console/terminal. | `true`
|
|
225
|
+
`dotFolders` | Include dotfolders in file search. | `false`
|
|
209
226
|
|
|
210
227
|
<br>
|
|
211
228
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
Please consider [giving a GitHub ⭐](https://github.com/adamlui/js-utils) if this helped you!
|
|
215
|
-
<br><br>
|
|
229
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
216
230
|
|
|
217
231
|
## 🏛️ MIT License
|
|
218
232
|
|
package/docs/LICENSE.md
CHANGED
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
<a href="hi/LICENSE.md">हिंदी</a> |
|
|
11
11
|
<a href="bn/LICENSE.md">বাংলা</a> |
|
|
12
12
|
<a href="mr/LICENSE.md">मराठी</a> |
|
|
13
|
-
<a href="pa/LICENSE.md">ਪੰਜਾਬੀ</a>
|
|
13
|
+
<a href="pa/LICENSE.md">ਪੰਜਾਬੀ</a> |
|
|
14
|
+
<a href="es/LICENSE.md">Español</a> |
|
|
15
|
+
<a href="pt/LICENSE.md">Português</a>
|
|
14
16
|
</h6>
|
|
15
17
|
</div>
|
|
16
18
|
|
package/docs/SECURITY.md
CHANGED
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
<a href="hi/SECURITY.md">हिंदी</a> |
|
|
11
11
|
<a href="bn/SECURITY.md">বাংলা</a> |
|
|
12
12
|
<a href="mr/SECURITY.md">मराठी</a> |
|
|
13
|
-
<a href="pa/SECURITY.md">ਪੰਜਾਬੀ</a>
|
|
13
|
+
<a href="pa/SECURITY.md">ਪੰਜਾਬੀ</a> |
|
|
14
|
+
<a href="es/SECURITY.md">Español</a> |
|
|
15
|
+
<a href="pt/SECURITY.md">Português</a>
|
|
14
16
|
</h6>
|
|
15
17
|
</div>
|
|
16
18
|
|
package/package.json
CHANGED
package/scss-to-css.js
CHANGED
|
@@ -8,29 +8,45 @@ const fs = require('fs'),
|
|
|
8
8
|
// Define MAIN functions
|
|
9
9
|
|
|
10
10
|
function findSCSS(searchDir, options = {}) {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
|
|
12
|
+
// Init options
|
|
13
|
+
const defaultOptions = { recursive: true, verbose: true, dotFolders: false };
|
|
14
|
+
options = { ...defaultOptions, ...options };
|
|
15
|
+
|
|
16
|
+
// Search for SCSS
|
|
13
17
|
const dirFiles = fs.readdirSync(searchDir), scssFiles = [];
|
|
18
|
+
if (options.verbose && !options.isRecursing) console.info('\nSearching for SCSS files...');
|
|
14
19
|
dirFiles.forEach(file => {
|
|
15
20
|
const filePath = path.resolve(searchDir, file);
|
|
16
21
|
if (fs.statSync(filePath).isDirectory() && file != 'node_modules'
|
|
17
|
-
&& (options.dotFolders || !file.startsWith('.')) && options.recursive)
|
|
18
|
-
if (options.verbose) console.info(`Searching for SCSS files in: ${filePath}...`);
|
|
22
|
+
&& (options.dotFolders || !file.startsWith('.')) && options.recursive)
|
|
19
23
|
scssFiles.push( // recursively find SCSS in eligible dir
|
|
20
24
|
...findSCSS(filePath, { ...options, isRecursing: true }));
|
|
21
|
-
|
|
25
|
+
else if (file.endsWith('.scss')) // SCSS file found
|
|
22
26
|
scssFiles.push(filePath); // store it for compilation
|
|
23
27
|
});
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
|
|
29
|
+
// Log/return final result
|
|
30
|
+
if (!options.isRecursing && options.verbose) {
|
|
31
|
+
console.info('Search complete. '
|
|
32
|
+
+ ( scssFiles.length === 0 ? 'No' : scssFiles.length )
|
|
33
|
+
+ ` file${ scssFiles.length > 1 ? 's' : '' } found.`);
|
|
34
|
+
}
|
|
35
|
+
return options.isRecursing || scssFiles.length > 0 ? scssFiles : [];
|
|
26
36
|
}
|
|
27
37
|
|
|
28
38
|
function compile(inputPath, options = {}) {
|
|
39
|
+
|
|
40
|
+
// Init options
|
|
29
41
|
const defaultOptions = { minify: true, sourceMaps: true, recursive: true, verbose: true, dotFolders: false };
|
|
30
42
|
options = { ...defaultOptions, ...options };
|
|
43
|
+
|
|
44
|
+
// Validate inputPath
|
|
31
45
|
if (typeof inputPath !== 'string')
|
|
32
46
|
return console.error('ERROR:'
|
|
33
47
|
+ ' First argument must be a string representing a file/folder path.');
|
|
48
|
+
|
|
49
|
+
// Compile SCSS based on inputPath
|
|
34
50
|
const compileOptions = { style: options.minify ? 'compressed' : 'expanded', sourceMap: options.sourceMaps };
|
|
35
51
|
if (fs.existsSync(inputPath)) { // compile based on path arg
|
|
36
52
|
if (inputPath.endsWith('.scss')) { // file path passed
|
|
@@ -40,9 +56,9 @@ function compile(inputPath, options = {}) {
|
|
|
40
56
|
return { code: compileResult.css, srcMap: compileResult.sourceMap, srcPath: inputPath };
|
|
41
57
|
} catch (err) { console.error(`\nERROR: ${ err.message }\n`); return { error: err }; }
|
|
42
58
|
} else { // dir path passed
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
?.map(scssPath => { // compile found SCSS files
|
|
59
|
+
return findSCSS(inputPath, { recursive: options.recursive, verbosity: options.verbose,
|
|
60
|
+
dotFolders: options.dotFolders
|
|
61
|
+
})?.map(scssPath => { // compile found SCSS files
|
|
46
62
|
if (options.verbose) console.info(`Compiling ${ scssPath }...`);
|
|
47
63
|
try { // to compile found file
|
|
48
64
|
const compileResult = sass.compile(scssPath, compileOptions);
|
|
@@ -60,52 +76,42 @@ if (require.main !== module) module.exports = { compile, findSCSS };
|
|
|
60
76
|
else { // run as CLI tool
|
|
61
77
|
|
|
62
78
|
// Init UI colors
|
|
63
|
-
const nc = '\x1b[0m',
|
|
79
|
+
const nc = '\x1b[0m', // no color
|
|
64
80
|
br = '\x1b[1;91m', // bright red
|
|
65
81
|
by = '\x1b[1;33m', // bright yellow
|
|
66
82
|
bg = '\x1b[1;92m'; // bright green
|
|
67
83
|
|
|
68
84
|
// Load FLAG settings
|
|
69
|
-
const config = {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
noSourceMaps:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
quietMode: process.argv.some(arg => /^--?q(?:uiet)?$/.test(arg))
|
|
85
|
+
const config = {};
|
|
86
|
+
const argRegex = {
|
|
87
|
+
'dryRun': /^--?(?:n|dry-?run)$/,
|
|
88
|
+
'includeDotFolders': /^--?(?:dd?|(?:include-?)?dot-?(?:folder|dir(?:ector(?:y|ie))?)s?=?(?:true|1)?)$/,
|
|
89
|
+
'noSourceMaps': /^--?(?:S|(?:exclude|disable|no)-?so?u?rce?-?maps?|so?u?rce?-?maps?=(?:false|0))$/,
|
|
90
|
+
'noRecursion': /^--?(?:R|(?:disable|no)-?recursion|recursion=(?:false|0))$/,
|
|
91
|
+
'noMinify': /^--?(?:M|(?:disable|no)-?minif(?:y|ication)|minif(?:y|ication)=(?:false|0))$/,
|
|
92
|
+
'quietMode': /^--?q(?:uiet)?(?:-?mode)?$/,
|
|
93
|
+
'help': /^--?h(?:elp)?$/,
|
|
94
|
+
'version': /^--?ve?r?s?i?o?n?$/
|
|
80
95
|
};
|
|
96
|
+
process.argv.forEach(arg => {
|
|
97
|
+
if (!arg.startsWith('-')) return;
|
|
98
|
+
const matchedFlag = Object.keys(argRegex).find(flag => argRegex[flag].test(arg));
|
|
99
|
+
if (matchedFlag) config[matchedFlag] = true;
|
|
100
|
+
else {
|
|
101
|
+
console.error(`\n${br}ERROR: Arg [${ arg }] not recognized.${nc}`);
|
|
102
|
+
console.info(`\n${by}Valid arguments are below.${nc}`);
|
|
103
|
+
printHelpScreen(['configOptions', 'infoCmds']);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}});
|
|
81
106
|
|
|
82
107
|
// Show HELP screen if -h or --help passed
|
|
83
|
-
if (process.argv.some(arg =>
|
|
84
|
-
printHelp(`\n${by}scss-to-css [inputPath] [outputPath] [options]${nc}`);
|
|
85
|
-
printHelp('\nPath arguments:');
|
|
86
|
-
printHelp(' [inputPath] '
|
|
87
|
-
+ 'Path to SCSS file or directory containing SCSS files to be compiled,'
|
|
88
|
-
+ ' relative to the current working directory.');
|
|
89
|
-
printHelp(' [outputPath] '
|
|
90
|
-
+ 'Path to file or directory where CSS + sourcemap files will be stored,'
|
|
91
|
-
+ ' relative to original file location (if not provided, css/ is used).');
|
|
92
|
-
printHelp('\nConfig options:');
|
|
93
|
-
printHelp(' -n, --dry-run Don\'t actually compile the file(s),'
|
|
94
|
-
+ ' just show if they will be processed.');
|
|
95
|
-
printHelp(' -d, --include-dotfolders Include dotfolders in file search.');
|
|
96
|
-
printHelp(' -S, --no-source-maps Prevent source maps from being generated.');
|
|
97
|
-
printHelp(' -M, --no-minify Disable minification of output CSS.');
|
|
98
|
-
printHelp(' -R, --no-recursion Disable recursive file searching.');
|
|
99
|
-
printHelp(' -q, --quiet Suppress all logging except errors.');
|
|
100
|
-
printHelp('\nInfo commands:');
|
|
101
|
-
printHelp(' -h, --help Display this help screen.');
|
|
102
|
-
printHelp(' -v, --version Show version number.');
|
|
108
|
+
if (process.argv.some(arg => argRegex.help.test(arg))) printHelpScreen();
|
|
103
109
|
|
|
104
110
|
// Show VERSION number if -v or --version passed
|
|
105
|
-
|
|
111
|
+
else if (process.argv.some(arg => argRegex.version.test(arg)))
|
|
106
112
|
console.info('v' + require('./package.json').version);
|
|
107
113
|
|
|
108
|
-
|
|
114
|
+
else { // run MAIN routine
|
|
109
115
|
|
|
110
116
|
// Init I/O args
|
|
111
117
|
const [inputArg = '', outputArg = ''] = ( // default to empty strings for error-less handling
|
|
@@ -125,19 +131,20 @@ else { // run as CLI tool
|
|
|
125
131
|
}
|
|
126
132
|
|
|
127
133
|
// Find all eligible JavaScript files or arg-passed file
|
|
128
|
-
printIfNotQuiet('Searching for SCSS files...');
|
|
129
134
|
const scssFiles = inputArg.endsWith('.scss') ? [inputPath]
|
|
130
|
-
: findSCSS(inputPath, { recursive: !config.noRecursion });
|
|
135
|
+
: findSCSS(inputPath, { recursive: !config.noRecursion, verbose: !config.quietMode });
|
|
131
136
|
|
|
132
|
-
if (config.dryRun
|
|
133
|
-
|
|
134
|
-
|
|
137
|
+
if (config.dryRun) { // -n or --dry-run passed
|
|
138
|
+
if (scssFiles.length > 0) { // print files to be processed
|
|
139
|
+
console.info(`\n${by}SCSS files to be compiled:${nc}`);
|
|
140
|
+
scssFiles.forEach(file => console.info(file));
|
|
141
|
+
} else console.info(`${by}\nNo SCSS files will be compiled.${nc}`);
|
|
135
142
|
|
|
136
143
|
} else { // actually compile SCSS files
|
|
137
144
|
|
|
138
145
|
// Build array of compilation data
|
|
139
146
|
const failedPaths = [];
|
|
140
|
-
const compileData = scssFiles
|
|
147
|
+
const compileData = scssFiles.map(scssPath => {
|
|
141
148
|
const compileResult = compile(scssPath, {
|
|
142
149
|
minify: !config.noMinify, sourceMaps: !config.noSourceMaps, verbose: !config.quietMode });
|
|
143
150
|
if (compileResult.error) failedPaths.push(scssPath);
|
|
@@ -170,7 +177,7 @@ else { // run as CLI tool
|
|
|
170
177
|
printIfNotQuiet(`${ compileData.length } CSS file${ cssCntSuffix }`
|
|
171
178
|
+ ( !config.noSourceMaps ? ` + ${ compileData.length } source map${ cssCntSuffix }` : '' )
|
|
172
179
|
+ ' generated.');
|
|
173
|
-
} else printIfNotQuiet(`${by}No SCSS files processed
|
|
180
|
+
} else printIfNotQuiet(`${by}No SCSS files processed.${nc}`);
|
|
174
181
|
if (failedPaths.length > 0) {
|
|
175
182
|
printIfNotQuiet(`\n${br}`
|
|
176
183
|
+ `${ failedPaths.length } file${ failedPaths.length > 1 ? 's' : '' }`
|
|
@@ -182,7 +189,7 @@ else { // run as CLI tool
|
|
|
182
189
|
|
|
183
190
|
// Define LOGGING functions
|
|
184
191
|
|
|
185
|
-
function
|
|
192
|
+
function printHelpMsg(msg) { // wrap msg + indent 2nd+ lines (for --help screen)
|
|
186
193
|
const terminalWidth = process.stdout.columns || 80,
|
|
187
194
|
indentation = 30, lines = [], words = msg.match(/\S+|\s+/g);
|
|
188
195
|
|
|
@@ -205,5 +212,39 @@ else { // run as CLI tool
|
|
|
205
212
|
));
|
|
206
213
|
}
|
|
207
214
|
|
|
215
|
+
function printHelpScreen(includeSections = ['cmdFormat', 'pathArgs', 'configOptions', 'infoCmds']) {
|
|
216
|
+
const sections = {
|
|
217
|
+
'cmdFormat': [
|
|
218
|
+
`\n${by}scss-to-css [inputPath] [outputPath] [options]${nc}`
|
|
219
|
+
],
|
|
220
|
+
'pathArgs': [
|
|
221
|
+
'\nPath arguments:',
|
|
222
|
+
' [inputPath] '
|
|
223
|
+
+ 'Path to SCSS file or directory containing SCSS files to be compiled,'
|
|
224
|
+
+ ' relative to the current working directory.',
|
|
225
|
+
' [outputPath] '
|
|
226
|
+
+ 'Path to file or directory where CSS + sourcemap files will be stored,'
|
|
227
|
+
+ ' relative to original file location (if not provided, css/ is used).'
|
|
228
|
+
],
|
|
229
|
+
'configOptions': [
|
|
230
|
+
'\nConfig options:',
|
|
231
|
+
' -n, --dry-run Don\'t actually compile the file(s),'
|
|
232
|
+
+ ' just show if they will be processed.',
|
|
233
|
+
' -d, --include-dotfolders Include dotfolders in file search.',
|
|
234
|
+
' -S, --no-source-maps Prevent source maps from being generated.',
|
|
235
|
+
' -M, --no-minify Disable minification of output CSS.',
|
|
236
|
+
' -R, --no-recursion Disable recursive file searching.',
|
|
237
|
+
' -q, --quiet Suppress all logging except errors.'
|
|
238
|
+
],
|
|
239
|
+
'infoCmds': [
|
|
240
|
+
'\nInfo commands:',
|
|
241
|
+
' -h, --help Display help screen.',
|
|
242
|
+
' -v, --version Show version number.'
|
|
243
|
+
]
|
|
244
|
+
};
|
|
245
|
+
includeSections.forEach(section => { // print valid arg elems
|
|
246
|
+
if (sections[section]) sections[section].forEach(line => printHelpMsg(line)); });
|
|
247
|
+
}
|
|
248
|
+
|
|
208
249
|
function printIfNotQuiet(msg) { if (!config.quietMode) console.info(msg); }
|
|
209
250
|
}
|