@adamlui/scss-to-css 1.4.2 → 1.5.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 +21 -12
- package/docs/LICENSE.md +4 -16
- package/package.json +1 -1
- package/scss-to-css.js +47 -36
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.
|
|
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.1-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
|
|
|
@@ -28,7 +29,7 @@ npm install -D @adamlui/scss-to-css
|
|
|
28
29
|
The basic **global command** is:
|
|
29
30
|
|
|
30
31
|
```
|
|
31
|
-
|
|
32
|
+
scss-to-css
|
|
32
33
|
```
|
|
33
34
|
|
|
34
35
|
**💡 Note:** Pass `-n` or `--dry-run` to only see what files will be processed.
|
|
@@ -37,20 +38,20 @@ 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 `--disable-source-maps` is passed.
|
|
41
|
+
**💡 Note:** Source maps are also generated by default unless `-S` or `--disable-source-maps` is passed.
|
|
41
42
|
|
|
42
43
|
#
|
|
43
44
|
|
|
44
45
|
To specify **input/output** paths:
|
|
45
46
|
|
|
46
47
|
```
|
|
47
|
-
|
|
48
|
+
scss-to-css [input_path] [output_path]
|
|
48
49
|
```
|
|
49
50
|
|
|
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. To include dotfolders, pass `-d` or `--include-dotfolders`.
|
|
54
55
|
|
|
55
56
|
#
|
|
56
57
|
|
|
@@ -62,7 +63,7 @@ To use as a **package script**, in your project's `package.json`:
|
|
|
62
63
|
},
|
|
63
64
|
```
|
|
64
65
|
|
|
65
|
-
Replace `<scss-to-css-cmd>` with `
|
|
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
|
## 📃 Example commands:
|
|
@@ -70,27 +71,35 @@ Replace `<scss-to-css-cmd>` with `scsstocss` + optional args. Then, `npm run bui
|
|
|
70
71
|
- Compile all SCSS files in the **current directory** (outputs to `css/`):
|
|
71
72
|
|
|
72
73
|
```
|
|
73
|
-
|
|
74
|
+
scss-to-css
|
|
74
75
|
```
|
|
75
76
|
|
|
76
77
|
- Compile all SCSS files in a **specific directory** (outputs to `path/to/your/directory/css/`):
|
|
77
78
|
|
|
78
79
|
```
|
|
79
|
-
|
|
80
|
+
scss-to-css path/to/your/directory
|
|
80
81
|
```
|
|
81
82
|
|
|
82
83
|
- Compile a **specific file** (outputs to `path/to/your/css/file.min.css`):
|
|
83
84
|
|
|
84
85
|
```
|
|
85
|
-
|
|
86
|
+
scss-to-css path/to/your/file.scss
|
|
86
87
|
```
|
|
87
88
|
|
|
88
89
|
- Specify both **input and output** directories (outputs to `output_folder/`):
|
|
89
90
|
|
|
90
91
|
```
|
|
91
|
-
|
|
92
|
+
scss-to-css input_folder output_folder
|
|
92
93
|
```
|
|
93
94
|
|
|
95
|
+
**💡 Note:** Output CSS is minified unless `-M` or `--no-minify` is passed.
|
|
96
|
+
<br><br>
|
|
97
|
+
|
|
98
|
+
## 💖 Support
|
|
99
|
+
|
|
100
|
+
Please consider [giving a GitHub ⭐](https://github.com/adamlui/js-utils) if this helped you!
|
|
101
|
+
<br><br>
|
|
102
|
+
|
|
94
103
|
## 🏛️ MIT License
|
|
95
104
|
|
|
96
105
|
**Copyright (c) 2024 [Adam Lui](https://github.com/adamlui)**
|
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,26 +11,39 @@ 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
|
+
noMinify: process.argv.some(arg =>
|
|
22
|
+
/^--?(?:M|(?:disable|no)-?minif(?:y|ication))$/.test(arg)),
|
|
23
|
+
quietMode: process.argv.some(arg => /^--?q(?:uiet)?$/.test(arg))
|
|
24
|
+
};
|
|
25
|
+
|
|
14
26
|
// Show HELP screen if -h or --help passed
|
|
15
27
|
if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
16
28
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
printWrappedMsg(' [inputPath] '
|
|
29
|
+
printHelp(`\n${by}scss-to-css [inputPath] [outputPath] [options]${nc}`);
|
|
30
|
+
printHelp('\nPath arguments:');
|
|
31
|
+
printHelp(' [inputPath] '
|
|
21
32
|
+ 'Path to SCSS file or directory containing SCSS files to be compiled,'
|
|
22
33
|
+ ' relative to the current working directory.');
|
|
23
|
-
|
|
34
|
+
printHelp(' [outputPath] '
|
|
24
35
|
+ 'Path to file or directory where CSS + sourcemap files will be stored,'
|
|
25
36
|
+ ' relative to original file location (if not provided, css/ is used).');
|
|
26
|
-
|
|
27
|
-
|
|
37
|
+
printHelp('\nConfig options:');
|
|
38
|
+
printHelp(' -n, --dry-run Don\'t actually compile the file(s),'
|
|
28
39
|
+ ' just show if they will be processed.');
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
printHelp(' -d, --include-dotfolders Include dotfolders in file search.');
|
|
41
|
+
printHelp(' -S, --disable-source-maps Prevent source maps from being generated.');
|
|
42
|
+
printHelp(' -M, --no-minify Disable minification of output CSS.');
|
|
43
|
+
printHelp(' -q, --quiet Suppress all logging except errors.');
|
|
44
|
+
printHelp('\nInfo commands:');
|
|
45
|
+
printHelp(' -h, --help Display this help screen.');
|
|
46
|
+
printHelp(' -v, --version Show version number.');
|
|
34
47
|
|
|
35
48
|
// Show VERSION number if -v or --version passed
|
|
36
49
|
} else if (process.argv.some(arg => /^--?ve?r?s?i?o?n?$/.test(arg))) {
|
|
@@ -50,19 +63,11 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
|
50
63
|
if (inputArg && !fs.existsSync(inputPath)) {
|
|
51
64
|
console.error(`\n${br}Error: First arg must be an existing file or directory.`
|
|
52
65
|
+ `\n${ inputPath } does not exist.${nc}`
|
|
53
|
-
+
|
|
66
|
+
+ `\n\n${bg}Example valid command: \n>> scss-to-css . output.min.css${nc}`
|
|
67
|
+
+ `\n\n${by}For all command options: \n>> scss-to-css --help${nc}`);
|
|
54
68
|
process.exit(1);
|
|
55
69
|
}
|
|
56
70
|
|
|
57
|
-
// Load flag settings
|
|
58
|
-
const config = {
|
|
59
|
-
dryRun: process.argv.some(arg => /^--?(?:n|dry-?run)$/.test(arg)),
|
|
60
|
-
includeDotFolders: process.argv.some(arg =>
|
|
61
|
-
/^--?(?:dd|(?:include-)?dot-?(?:folder|dir(?:ector(?:y|ie))?)s?)$/.test(arg)),
|
|
62
|
-
disableSourceMaps: process.argv.some(arg =>
|
|
63
|
-
/^--?(?:S|(?:exclude|disable)-so?u?rce?-?maps?)$/.test(arg))
|
|
64
|
-
};
|
|
65
|
-
|
|
66
71
|
// Recursively find all eligible SCSS files or arg-passed file
|
|
67
72
|
const scssFiles = [];
|
|
68
73
|
if (inputArg.endsWith('.scss')) scssFiles.push(inputPath);
|
|
@@ -78,18 +83,20 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
|
78
83
|
});
|
|
79
84
|
})(inputPath);
|
|
80
85
|
|
|
81
|
-
if (
|
|
82
|
-
|
|
86
|
+
if (scssFiles.length === 0) { // print nothing found
|
|
87
|
+
printIfNotQuiet(`\n${by}No SCSS files found.${nc}`);
|
|
88
|
+
|
|
89
|
+
} else if (config.dryRun) { // print files to be processed
|
|
90
|
+
console.info(`\n${by}SCSS files to be compiled:${nc}`);
|
|
83
91
|
scssFiles.forEach(file => console.info(file));
|
|
84
92
|
|
|
85
93
|
} else { // actually compile SCSS files
|
|
86
94
|
|
|
87
|
-
// Compile SCSS files to CSS
|
|
88
95
|
let cssGenCnt = 0, srcMapGenCnt = 0;
|
|
89
|
-
|
|
96
|
+
printIfNotQuiet(''); // line break before first log
|
|
90
97
|
scssFiles.forEach(scssPath => {
|
|
91
|
-
|
|
92
|
-
try { // to compile
|
|
98
|
+
printIfNotQuiet(`Compiling ${ scssPath }...`);
|
|
99
|
+
try { // to compile SCSS file
|
|
93
100
|
const outputDir = path.join(
|
|
94
101
|
path.dirname(scssPath), // path of file to be minified
|
|
95
102
|
/(?:src|s[ac]ss)$/.test(path.dirname(scssPath)) ? '../css' // + ../css/ if in *(src|sass|scss)/
|
|
@@ -102,29 +109,31 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
|
102
109
|
: path.basename(scssPath, '.scss')
|
|
103
110
|
) + '.min.css';
|
|
104
111
|
const outputPath = path.join(outputDir, outputFilename),
|
|
105
|
-
compileResult = sass.compile(scssPath, {
|
|
112
|
+
compileResult = sass.compile(scssPath, {
|
|
113
|
+
style: config.noMinify ? 'expanded' : 'compressed',
|
|
114
|
+
sourceMap: !config.disableSourceMaps });
|
|
106
115
|
if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
|
|
107
116
|
fs.writeFileSync(outputPath, compileResult.css, 'utf8'); cssGenCnt++;
|
|
108
117
|
if (!config.disableSourceMaps) {
|
|
109
118
|
fs.writeFileSync(outputPath + '.map', JSON.stringify(compileResult.sourceMap), 'utf8');
|
|
110
119
|
srcMapGenCnt++;
|
|
111
120
|
}
|
|
112
|
-
} catch (err) {
|
|
113
|
-
console.error(`${br}Error compiling ${ scssPath }: ${ err.message }${nc}`);
|
|
114
|
-
}
|
|
121
|
+
} catch (err) { console.error(`${br}Error compiling ${ scssPath }: ${ err.message }${nc}`); }
|
|
115
122
|
});
|
|
116
123
|
|
|
117
124
|
// Print final summary
|
|
118
125
|
if (cssGenCnt) {
|
|
119
|
-
|
|
120
|
-
|
|
126
|
+
printIfNotQuiet(`\n${bg}Compilation complete!${nc}`);
|
|
127
|
+
printIfNotQuiet(`${ cssGenCnt } CSS file${ cssGenCnt > 1 ? 's' : '' }`
|
|
121
128
|
+ ( srcMapGenCnt ? ` + ${ srcMapGenCnt } source map${ srcMapGenCnt > 1 ? 's' : '' }` : '' )
|
|
122
129
|
+ ' generated.');
|
|
123
|
-
} else
|
|
130
|
+
} else printIfNotQuiet(`${by}No SCSS files processed successfully.${nc}`);
|
|
124
131
|
}
|
|
125
132
|
}
|
|
126
133
|
|
|
127
|
-
|
|
134
|
+
// Define LOGGING functions
|
|
135
|
+
|
|
136
|
+
function printHelp(msg) { // wrap msg + indent 2nd+ lines (for --help screen)
|
|
128
137
|
const terminalWidth = process.stdout.columns || 80,
|
|
129
138
|
indentation = 30, lines = [], words = msg.match(/\S+|\s+/g);
|
|
130
139
|
|
|
@@ -146,3 +155,5 @@ function printWrappedMsg(msg) { // truncates msg, indents 2nd+ lines
|
|
|
146
155
|
: ' '.repeat(indentation) + line // print subsequent lines indented
|
|
147
156
|
));
|
|
148
157
|
}
|
|
158
|
+
|
|
159
|
+
function printIfNotQuiet(msg) { if (!config.quietMode) console.info(msg); }
|