@adamlui/scss-to-css 1.4.2 → 1.5.0
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 +17 -9
- package/package.json +1 -1
- package/scss-to-css.js +21 -13
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.
|
|
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.0-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">
|
|
@@ -28,7 +28,7 @@ npm install -D @adamlui/scss-to-css
|
|
|
28
28
|
The basic **global command** is:
|
|
29
29
|
|
|
30
30
|
```
|
|
31
|
-
|
|
31
|
+
scss-to-css
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
**💡 Note:** Pass `-n` or `--dry-run` to only see what files will be processed.
|
|
@@ -37,14 +37,14 @@ Sample output:
|
|
|
37
37
|
|
|
38
38
|
<img src="https://github.com/adamlui/js-utils/blob/main/scss-to-css/media/images/sample-output.png">
|
|
39
39
|
|
|
40
|
-
**💡 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.
|
|
41
41
|
|
|
42
42
|
#
|
|
43
43
|
|
|
44
44
|
To specify **input/output** paths:
|
|
45
45
|
|
|
46
46
|
```
|
|
47
|
-
|
|
47
|
+
scss-to-css [input_path] [output_path]
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
- `[input_path]`: Path to SCSS file or directory containing SCSS files to be compiled, relative to the current working directory.
|
|
@@ -62,7 +62,7 @@ To use as a **package script**, in your project's `package.json`:
|
|
|
62
62
|
},
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
Replace `<scss-to-css-cmd>` with `
|
|
65
|
+
Replace `<scss-to-css-cmd>` with `scss-to-css` + optional args. Then, `npm run build:css` can be used to run the command.
|
|
66
66
|
<br><br>
|
|
67
67
|
|
|
68
68
|
## 📃 Example commands:
|
|
@@ -70,27 +70,35 @@ Replace `<scss-to-css-cmd>` with `scsstocss` + optional args. Then, `npm run bui
|
|
|
70
70
|
- Compile all SCSS files in the **current directory** (outputs to `css/`):
|
|
71
71
|
|
|
72
72
|
```
|
|
73
|
-
|
|
73
|
+
scss-to-css
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
- Compile all SCSS files in a **specific directory** (outputs to `path/to/your/directory/css/`):
|
|
77
77
|
|
|
78
78
|
```
|
|
79
|
-
|
|
79
|
+
scss-to-css path/to/your/directory
|
|
80
80
|
```
|
|
81
81
|
|
|
82
82
|
- Compile a **specific file** (outputs to `path/to/your/css/file.min.css`):
|
|
83
83
|
|
|
84
84
|
```
|
|
85
|
-
|
|
85
|
+
scss-to-css path/to/your/file.scss
|
|
86
86
|
```
|
|
87
87
|
|
|
88
88
|
- Specify both **input and output** directories (outputs to `output_folder/`):
|
|
89
89
|
|
|
90
90
|
```
|
|
91
|
-
|
|
91
|
+
scss-to-css input_folder output_folder
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
+
**💡 Note:** Output CSS is minified unless `-M` or `--no-minify` is passed.
|
|
95
|
+
<br><br>
|
|
96
|
+
|
|
97
|
+
## 💖 Support
|
|
98
|
+
|
|
99
|
+
Please consider giving a ⭐ on [GitHub](https://github.com/adamlui/js-utils) if this helped you!
|
|
100
|
+
<br><br>
|
|
101
|
+
|
|
94
102
|
## 🏛️ MIT License
|
|
95
103
|
|
|
96
104
|
**Copyright (c) 2024 [Adam Lui](https://github.com/adamlui)**
|
package/package.json
CHANGED
package/scss-to-css.js
CHANGED
|
@@ -15,7 +15,7 @@ const nc = '\x1b[0m', // no color
|
|
|
15
15
|
if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
16
16
|
|
|
17
17
|
// Print help
|
|
18
|
-
console.info(`\n${by}
|
|
18
|
+
console.info(`\n${by}scss-to-css [inputPath] [outputPath] [options]${nc}`);
|
|
19
19
|
console.info('\nPath arguments:');
|
|
20
20
|
printWrappedMsg(' [inputPath] '
|
|
21
21
|
+ 'Path to SCSS file or directory containing SCSS files to be compiled,'
|
|
@@ -24,13 +24,14 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
|
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('
|
|
27
|
+
printWrappedMsg(' -n, --dry-run Don\'t actually compile the file(s),'
|
|
28
28
|
+ ' just show if they will be processed.');
|
|
29
29
|
printWrappedMsg(' -dd, --include-dotfolders Include dotfolders in file search.');
|
|
30
|
-
printWrappedMsg('
|
|
30
|
+
printWrappedMsg(' -S, --disable-source-maps Prevent source maps from being generated.');
|
|
31
|
+
printWrappedMsg(' -M, --no-minify Disable minification of output CSS.');
|
|
31
32
|
console.info('\nInfo commands:');
|
|
32
|
-
printWrappedMsg('
|
|
33
|
-
printWrappedMsg('
|
|
33
|
+
printWrappedMsg(' -h, --help Display this help screen.');
|
|
34
|
+
printWrappedMsg(' -v, --version Show version number.');
|
|
34
35
|
|
|
35
36
|
// Show VERSION number if -v or --version passed
|
|
36
37
|
} else if (process.argv.some(arg => /^--?ve?r?s?i?o?n?$/.test(arg))) {
|
|
@@ -50,7 +51,8 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
|
50
51
|
if (inputArg && !fs.existsSync(inputPath)) {
|
|
51
52
|
console.error(`\n${br}Error: First arg must be an existing file or directory.`
|
|
52
53
|
+ `\n${ inputPath } does not exist.${nc}`
|
|
53
|
-
+
|
|
54
|
+
+ `\n\n${bg}Example valid command: \n>> scss-to-css . output.min.css${nc}`
|
|
55
|
+
+ `\n\n${by}For all command options: \n>> scss-to-css --help${nc}`);
|
|
54
56
|
process.exit(1);
|
|
55
57
|
}
|
|
56
58
|
|
|
@@ -60,7 +62,9 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
|
60
62
|
includeDotFolders: process.argv.some(arg =>
|
|
61
63
|
/^--?(?:dd|(?:include-)?dot-?(?:folder|dir(?:ector(?:y|ie))?)s?)$/.test(arg)),
|
|
62
64
|
disableSourceMaps: process.argv.some(arg =>
|
|
63
|
-
/^--?(?:S|(?:exclude|disable)-so?u?rce?-?maps?)$/.test(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))
|
|
64
68
|
};
|
|
65
69
|
|
|
66
70
|
// Recursively find all eligible SCSS files or arg-passed file
|
|
@@ -78,13 +82,15 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
|
78
82
|
});
|
|
79
83
|
})(inputPath);
|
|
80
84
|
|
|
81
|
-
if (
|
|
82
|
-
console.info(
|
|
85
|
+
if (scssFiles.length === 0) { // print nothing found
|
|
86
|
+
console.info(`\n${by}No SCSS files found.${nc}`);
|
|
87
|
+
|
|
88
|
+
} else if (config.dryRun) { // print files to be processed
|
|
89
|
+
console.info(`\n${by}SCSS files to be compiled:${nc}`);
|
|
83
90
|
scssFiles.forEach(file => console.info(file));
|
|
84
91
|
|
|
85
92
|
} else { // actually compile SCSS files
|
|
86
93
|
|
|
87
|
-
// Compile SCSS files to CSS
|
|
88
94
|
let cssGenCnt = 0, srcMapGenCnt = 0;
|
|
89
95
|
console.log(''); // line break before first log
|
|
90
96
|
scssFiles.forEach(scssPath => {
|
|
@@ -102,7 +108,9 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
|
102
108
|
: path.basename(scssPath, '.scss')
|
|
103
109
|
) + '.min.css';
|
|
104
110
|
const outputPath = path.join(outputDir, outputFilename),
|
|
105
|
-
compileResult = sass.compile(scssPath, {
|
|
111
|
+
compileResult = sass.compile(scssPath, {
|
|
112
|
+
style: config.noMinify ? 'expanded' : 'compressed',
|
|
113
|
+
sourceMap: !config.disableSourceMaps });
|
|
106
114
|
if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
|
|
107
115
|
fs.writeFileSync(outputPath, compileResult.css, 'utf8'); cssGenCnt++;
|
|
108
116
|
if (!config.disableSourceMaps) {
|
|
@@ -120,11 +128,11 @@ if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
|
120
128
|
console.info(`${ cssGenCnt } CSS file${ cssGenCnt > 1 ? 's' : '' }`
|
|
121
129
|
+ ( srcMapGenCnt ? ` + ${ srcMapGenCnt } source map${ srcMapGenCnt > 1 ? 's' : '' }` : '' )
|
|
122
130
|
+ ' generated.');
|
|
123
|
-
} else console.info(`${by}No SCSS files
|
|
131
|
+
} else console.info(`${by}No SCSS files processed successfully.${nc}`);
|
|
124
132
|
}
|
|
125
133
|
}
|
|
126
134
|
|
|
127
|
-
function printWrappedMsg(msg) { //
|
|
135
|
+
function printWrappedMsg(msg) { // wraps msg, indents 2nd+ lines
|
|
128
136
|
const terminalWidth = process.stdout.columns || 80,
|
|
129
137
|
indentation = 30, lines = [], words = msg.match(/\S+|\s+/g);
|
|
130
138
|
|