@adamlui/scss-to-css 1.5.0 → 1.5.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 +46 -40
- package/docs/LICENSE.md +4 -16
- package/package.json +1 -1
- package/scss-to-css.js +43 -37
package/README.md
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
### Recursively compile all SCSS files into minified CSS.
|
|
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
|
-
<a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-
|
|
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.5.
|
|
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>
|
|
6
|
+
<a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-red.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.5.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&color=blue&labelColor=464646"></a>
|
|
9
|
+
<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>
|
|
9
10
|
|
|
10
11
|
<img height=8px width="100%" src="https://github.com/adamlui/js-utils/blob/main/docs/images/aqua-separator.png">
|
|
11
12
|
|
|
@@ -37,7 +38,7 @@ Sample output:
|
|
|
37
38
|
|
|
38
39
|
<img src="https://github.com/adamlui/js-utils/blob/main/scss-to-css/media/images/sample-output.png">
|
|
39
40
|
|
|
40
|
-
**💡 Note:** Source maps are also generated by default unless `-S` or `--
|
|
41
|
+
**💡 Note:** Source maps are also generated by default unless `-S` or `--no-source-maps` is passed.
|
|
41
42
|
|
|
42
43
|
#
|
|
43
44
|
|
|
@@ -50,7 +51,7 @@ scss-to-css [input_path] [output_path]
|
|
|
50
51
|
- `[input_path]`: Path to SCSS file or directory containing SCSS files to be compiled, relative to the current working directory.
|
|
51
52
|
- `[output_path]`: Path to file or directory where CSS + sourcemap files will be stored, relative to original file location (if not provided, `css/` is used).
|
|
52
53
|
|
|
53
|
-
**💡 Note:** If folders are passed, files will be processed recursively. To include dotfolders, pass `-
|
|
54
|
+
**💡 Note:** If folders are passed, files will be processed recursively unless `-R` or `--no-recursion` is passed. To include dotfolders, pass `-d` or `--include-dotfolders`.
|
|
54
55
|
|
|
55
56
|
#
|
|
56
57
|
|
|
@@ -65,61 +66,66 @@ To use as a **package script**, in your project's `package.json`:
|
|
|
65
66
|
Replace `<scss-to-css-cmd>` with `scss-to-css` + optional args. Then, `npm run build:css` can be used to run the command.
|
|
66
67
|
<br><br>
|
|
67
68
|
|
|
68
|
-
|
|
69
|
+
### Command line options
|
|
69
70
|
|
|
70
|
-
|
|
71
|
+
```
|
|
72
|
+
Config options:
|
|
73
|
+
-n, --dry-run Don't actually compile the file(s), just
|
|
74
|
+
show if they will be processed.
|
|
75
|
+
-d, --include-dotfolders Include dotfolders in file search.
|
|
76
|
+
-S, --no-source-maps Prevent source maps from being generated.
|
|
77
|
+
-M, --no-minify Disable minification of output CSS.
|
|
78
|
+
-R, --no-recursion Disable recursive file searching.
|
|
79
|
+
-q, --quiet Suppress all logging except errors.
|
|
80
|
+
|
|
81
|
+
Info commands:
|
|
82
|
+
-h, --help Display this help screen.
|
|
83
|
+
-v, --version Show version number.
|
|
84
|
+
```
|
|
71
85
|
|
|
72
|
-
|
|
73
|
-
scss-to-css
|
|
74
|
-
```
|
|
86
|
+
### Example commands
|
|
75
87
|
|
|
76
|
-
|
|
88
|
+
Compile all SCSS files in the **current directory** (outputs to `css/`):
|
|
77
89
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
90
|
+
```
|
|
91
|
+
scss-to-css
|
|
92
|
+
```
|
|
81
93
|
|
|
82
|
-
|
|
94
|
+
Compile all SCSS files in a **specific directory** (outputs to `path/to/your/directory/css/`):
|
|
83
95
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
96
|
+
```
|
|
97
|
+
scss-to-css path/to/your/directory
|
|
98
|
+
```
|
|
87
99
|
|
|
88
|
-
|
|
100
|
+
Compile a **specific file** (outputs to `path/to/your/css/file.min.css`):
|
|
89
101
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
102
|
+
```
|
|
103
|
+
scss-to-css path/to/your/file.scss
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Specify both **input and output** directories (outputs to `output_folder/`):
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
scss-to-css input_folder output_folder
|
|
110
|
+
```
|
|
93
111
|
|
|
94
112
|
**💡 Note:** Output CSS is minified unless `-M` or `--no-minify` is passed.
|
|
95
113
|
<br><br>
|
|
96
114
|
|
|
97
115
|
## 💖 Support
|
|
98
116
|
|
|
99
|
-
Please consider giving a ⭐
|
|
117
|
+
Please consider [giving a GitHub ⭐](https://github.com/adamlui/js-utils) if this helped you!
|
|
100
118
|
<br><br>
|
|
101
119
|
|
|
102
120
|
## 🏛️ MIT License
|
|
103
121
|
|
|
104
122
|
**Copyright (c) 2024 [Adam Lui](https://github.com/adamlui)**
|
|
105
123
|
|
|
106
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
107
|
-
|
|
108
|
-
in
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
furnished to do so, subject to the following conditions:
|
|
112
|
-
|
|
113
|
-
The above copyright notice and this permission notice shall be included in all
|
|
114
|
-
copies or substantial portions of the Software.
|
|
115
|
-
|
|
116
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
117
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
118
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
119
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
120
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
121
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
122
|
-
SOFTWARE.
|
|
124
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
125
|
+
|
|
126
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
127
|
+
|
|
128
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
123
129
|
|
|
124
130
|
<br>
|
|
125
131
|
|
package/docs/LICENSE.md
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
# MIT License
|
|
1
|
+
# 🏛️ MIT License
|
|
2
2
|
|
|
3
3
|
**Copyright (c) 2024 [Adam Lui](https://github.com/adamlui)**
|
|
4
4
|
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
11
6
|
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
14
8
|
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
CHANGED
package/scss-to-css.js
CHANGED
|
@@ -11,27 +11,42 @@ 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
|
+
// Load FLAG settings
|
|
15
|
+
const config = {
|
|
16
|
+
dryRun: process.argv.some(arg => /^--?(?:n|dry-?run)$/.test(arg)),
|
|
17
|
+
includeDotFolders: process.argv.some(arg =>
|
|
18
|
+
/^--?(?:dd?|(?:include-?)?dot-?(?:folder|dir(?:ector(?:y|ie))?)s?)$/.test(arg)),
|
|
19
|
+
disableSourceMaps: process.argv.some(arg =>
|
|
20
|
+
/^--?(?:S|(?:exclude|disable|no)-?so?u?rce?-?maps?)$/.test(arg)),
|
|
21
|
+
noRecursion: process.argv.some(arg =>
|
|
22
|
+
/^--?(?:R|(?:disable|no)-?recursion)$/.test(arg)),
|
|
23
|
+
noMinify: process.argv.some(arg =>
|
|
24
|
+
/^--?(?:M|(?:disable|no)-?minif(?:y|ication))$/.test(arg)),
|
|
25
|
+
quietMode: process.argv.some(arg => /^--?q(?:uiet)?$/.test(arg))
|
|
26
|
+
};
|
|
27
|
+
|
|
14
28
|
// Show HELP screen if -h or --help passed
|
|
15
29
|
if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
16
30
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
printWrappedMsg(' [inputPath] '
|
|
31
|
+
printHelp(`\n${by}scss-to-css [inputPath] [outputPath] [options]${nc}`);
|
|
32
|
+
printHelp('\nPath arguments:');
|
|
33
|
+
printHelp(' [inputPath] '
|
|
21
34
|
+ 'Path to SCSS file or directory containing SCSS files to be compiled,'
|
|
22
35
|
+ ' relative to the current working directory.');
|
|
23
|
-
|
|
36
|
+
printHelp(' [outputPath] '
|
|
24
37
|
+ 'Path to file or directory where CSS + sourcemap files will be stored,'
|
|
25
38
|
+ ' relative to original file location (if not provided, css/ is used).');
|
|
26
|
-
|
|
27
|
-
|
|
39
|
+
printHelp('\nConfig options:');
|
|
40
|
+
printHelp(' -n, --dry-run Don\'t actually compile the file(s),'
|
|
28
41
|
+ ' just show if they will be processed.');
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
printHelp(' -d, --include-dotfolders Include dotfolders in file search.');
|
|
43
|
+
printHelp(' -S, --no-source-maps Prevent source maps from being generated.');
|
|
44
|
+
printHelp(' -M, --no-minify Disable minification of output CSS.');
|
|
45
|
+
printHelp(' -R, --no-recursion Disable recursive file searching.');
|
|
46
|
+
printHelp(' -q, --quiet Suppress all logging except errors.');
|
|
47
|
+
printHelp('\nInfo commands:');
|
|
48
|
+
printHelp(' -h, --help Display this help screen.');
|
|
49
|
+
printHelp(' -v, --version Show version number.');
|
|
35
50
|
|
|
36
51
|
// Show VERSION number if -v or --version passed
|
|
37
52
|
} else if (process.argv.some(arg => /^--?ve?r?s?i?o?n?$/.test(arg))) {
|
|
@@ -56,18 +71,7 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
|
56
71
|
process.exit(1);
|
|
57
72
|
}
|
|
58
73
|
|
|
59
|
-
//
|
|
60
|
-
const config = {
|
|
61
|
-
dryRun: process.argv.some(arg => /^--?(?:n|dry-?run)$/.test(arg)),
|
|
62
|
-
includeDotFolders: process.argv.some(arg =>
|
|
63
|
-
/^--?(?:dd|(?:include-)?dot-?(?:folder|dir(?:ector(?:y|ie))?)s?)$/.test(arg)),
|
|
64
|
-
disableSourceMaps: process.argv.some(arg =>
|
|
65
|
-
/^--?(?:S|(?:exclude|disable)-so?u?rce?-?maps?)$/.test(arg)),
|
|
66
|
-
noMinify: process.argv.some(arg =>
|
|
67
|
-
/^--?(?:M|(?:disable|no)-minif(?:y|ication))$/.test(arg))
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// Recursively find all eligible SCSS files or arg-passed file
|
|
74
|
+
// Find all eligible SCSS files or arg-passed file
|
|
71
75
|
const scssFiles = [];
|
|
72
76
|
if (inputArg.endsWith('.scss')) scssFiles.push(inputPath);
|
|
73
77
|
else (function findSCSSfiles(dir) {
|
|
@@ -75,7 +79,7 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
|
75
79
|
files.forEach(file => {
|
|
76
80
|
const filePath = path.resolve(dir, file);
|
|
77
81
|
if (fs.statSync(filePath).isDirectory() &&
|
|
78
|
-
(config.includeDotFolders || !file.startsWith('.')))
|
|
82
|
+
(config.includeDotFolders || !file.startsWith('.')) && !config.noRecursion)
|
|
79
83
|
findSCSSfiles(filePath); // recursively find SCSS in eligible dir
|
|
80
84
|
else if (file.endsWith('.scss')) // SCSS file found
|
|
81
85
|
scssFiles.push(filePath); // store it for compilation
|
|
@@ -83,7 +87,7 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
|
83
87
|
})(inputPath);
|
|
84
88
|
|
|
85
89
|
if (scssFiles.length === 0) { // print nothing found
|
|
86
|
-
|
|
90
|
+
printIfNotQuiet(`\n${by}No SCSS files found.${nc}`);
|
|
87
91
|
|
|
88
92
|
} else if (config.dryRun) { // print files to be processed
|
|
89
93
|
console.info(`\n${by}SCSS files to be compiled:${nc}`);
|
|
@@ -92,10 +96,10 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
|
92
96
|
} else { // actually compile SCSS files
|
|
93
97
|
|
|
94
98
|
let cssGenCnt = 0, srcMapGenCnt = 0;
|
|
95
|
-
|
|
99
|
+
printIfNotQuiet(''); // line break before first log
|
|
96
100
|
scssFiles.forEach(scssPath => {
|
|
97
|
-
|
|
98
|
-
try { // to compile
|
|
101
|
+
printIfNotQuiet(`Compiling ${ scssPath }...`);
|
|
102
|
+
try { // to compile SCSS file
|
|
99
103
|
const outputDir = path.join(
|
|
100
104
|
path.dirname(scssPath), // path of file to be minified
|
|
101
105
|
/(?:src|s[ac]ss)$/.test(path.dirname(scssPath)) ? '../css' // + ../css/ if in *(src|sass|scss)/
|
|
@@ -117,22 +121,22 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
|
117
121
|
fs.writeFileSync(outputPath + '.map', JSON.stringify(compileResult.sourceMap), 'utf8');
|
|
118
122
|
srcMapGenCnt++;
|
|
119
123
|
}
|
|
120
|
-
} catch (err) {
|
|
121
|
-
console.error(`${br}Error compiling ${ scssPath }: ${ err.message }${nc}`);
|
|
122
|
-
}
|
|
124
|
+
} catch (err) { console.error(`${br}Error compiling ${ scssPath }: ${ err.message }${nc}`); }
|
|
123
125
|
});
|
|
124
126
|
|
|
125
127
|
// Print final summary
|
|
126
128
|
if (cssGenCnt) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
+
printIfNotQuiet(`\n${bg}Compilation complete!${nc}`);
|
|
130
|
+
printIfNotQuiet(`${ cssGenCnt } CSS file${ cssGenCnt > 1 ? 's' : '' }`
|
|
129
131
|
+ ( srcMapGenCnt ? ` + ${ srcMapGenCnt } source map${ srcMapGenCnt > 1 ? 's' : '' }` : '' )
|
|
130
132
|
+ ' generated.');
|
|
131
|
-
} else
|
|
133
|
+
} else printIfNotQuiet(`${by}No SCSS files processed successfully.${nc}`);
|
|
132
134
|
}
|
|
133
135
|
}
|
|
134
136
|
|
|
135
|
-
|
|
137
|
+
// Define LOGGING functions
|
|
138
|
+
|
|
139
|
+
function printHelp(msg) { // wrap msg + indent 2nd+ lines (for --help screen)
|
|
136
140
|
const terminalWidth = process.stdout.columns || 80,
|
|
137
141
|
indentation = 30, lines = [], words = msg.match(/\S+|\s+/g);
|
|
138
142
|
|
|
@@ -154,3 +158,5 @@ function printWrappedMsg(msg) { // wraps msg, indents 2nd+ lines
|
|
|
154
158
|
: ' '.repeat(indentation) + line // print subsequent lines indented
|
|
155
159
|
));
|
|
156
160
|
}
|
|
161
|
+
|
|
162
|
+
function printIfNotQuiet(msg) { if (!config.quietMode) console.info(msg); }
|