@adamlui/scss-to-css 1.3.2 → 1.4.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 +14 -13
- package/docs/SECURITY.md +1 -1
- package/package.json +2 -1
- package/scss-to-css.js +119 -68
package/README.md
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
### Recursively compile all SCSS files into minified CSS.
|
|
4
4
|
|
|
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=
|
|
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.4.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&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,27 +28,27 @@ npm install -D @adamlui/scss-to-css
|
|
|
27
28
|
The basic **global command** is:
|
|
28
29
|
|
|
29
30
|
```
|
|
30
|
-
|
|
31
|
+
scsstocss
|
|
31
32
|
```
|
|
32
33
|
|
|
33
34
|
Sample output:
|
|
34
35
|
|
|
35
36
|
<img src="https://github.com/adamlui/js-utils/blob/main/scss-to-css/media/images/sample-output.png">
|
|
36
37
|
|
|
37
|
-
**💡 Note:** Source maps are also generated by default unless `--disable-source-maps` is passed.
|
|
38
|
+
**💡 Note:** Source maps are also generated by default unless `-S` or `--disable-source-maps` is passed.
|
|
38
39
|
|
|
39
40
|
#
|
|
40
41
|
|
|
41
42
|
To specify **input/output** paths:
|
|
42
43
|
|
|
43
44
|
```
|
|
44
|
-
|
|
45
|
+
scsstocss [input_path] [output_path]
|
|
45
46
|
```
|
|
46
47
|
|
|
47
|
-
-
|
|
48
|
-
-
|
|
48
|
+
- `[input_path]`: Path to SCSS file or directory containing SCSS files to be compiled, relative to the current working directory.
|
|
49
|
+
- `[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).
|
|
49
50
|
|
|
50
|
-
**💡 Note:** If folders are passed, files will be processed recursively. To include dotfolders, pass `--include-dotfolders`.
|
|
51
|
+
**💡 Note:** If folders are passed, files will be processed recursively. To include dotfolders, pass `-dd` or `--include-dotfolders`.
|
|
51
52
|
|
|
52
53
|
#
|
|
53
54
|
|
|
@@ -59,7 +60,7 @@ To use as a **package script**, edit your project's `package.json` like this:
|
|
|
59
60
|
},
|
|
60
61
|
```
|
|
61
62
|
|
|
62
|
-
Replace `<scss-to-css-cmd>` with `
|
|
63
|
+
Replace `<scss-to-css-cmd>` with `scsstocss` + optional args. Then, `npm run build:css` can be used to run the command.
|
|
63
64
|
<br><br>
|
|
64
65
|
|
|
65
66
|
## 📃 Example commands:
|
|
@@ -67,25 +68,25 @@ Replace `<scss-to-css-cmd>` with `scss-to-css` + optional args. Then, `npm run b
|
|
|
67
68
|
- Compile all SCSS files in the **current directory** (outputs to `css/`):
|
|
68
69
|
|
|
69
70
|
```
|
|
70
|
-
|
|
71
|
+
scsstocss
|
|
71
72
|
```
|
|
72
73
|
|
|
73
74
|
- Compile all SCSS files in a **specific directory** (outputs to `path/to/your/directory/css/`):
|
|
74
75
|
|
|
75
76
|
```
|
|
76
|
-
|
|
77
|
+
scsstocss path/to/your/directory
|
|
77
78
|
```
|
|
78
79
|
|
|
79
80
|
- Compile a **specific file** (outputs to `path/to/your/css/file.min.css`):
|
|
80
81
|
|
|
81
82
|
```
|
|
82
|
-
|
|
83
|
+
scsstocss path/to/your/file.scss
|
|
83
84
|
```
|
|
84
85
|
|
|
85
86
|
- Specify both **input and output** directories (outputs to `output_folder/`):
|
|
86
87
|
|
|
87
88
|
```
|
|
88
|
-
|
|
89
|
+
scsstocss input_folder output_folder
|
|
89
90
|
```
|
|
90
91
|
|
|
91
92
|
## 🏛️ 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.
|
|
3
|
+
"version": "1.4.1",
|
|
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
|
|
3
|
+
// Import LIBS
|
|
4
4
|
const fs = require('fs'),
|
|
5
5
|
path = require('path'),
|
|
6
6
|
sass = require('sass');
|
|
@@ -11,77 +11,128 @@ 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
|
-
//
|
|
15
|
-
|
|
16
|
-
process.argv.slice(2) // exclude executable and script paths
|
|
17
|
-
.filter(arg => !arg.startsWith('-')) // exclude flags
|
|
18
|
-
.map(arg => arg.replace(/^\/*/, '')) // clean leading slashes to avoid parsing system root
|
|
19
|
-
);
|
|
14
|
+
// Show HELP screen if -h or --help passed
|
|
15
|
+
if (process.argv.some(arg => /^--?h(?:elp)?$/.test(arg))) {
|
|
20
16
|
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
+
|
|
26
|
-
+ '
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
// Print help
|
|
18
|
+
console.info(`\n${by}scsstocss [inputPath] [outputPath] [options]${nc}`);
|
|
19
|
+
console.info('\nPath arguments:');
|
|
20
|
+
printWrappedMsg(' [inputPath] '
|
|
21
|
+
+ 'Path to SCSS file or directory containing SCSS files to be compiled,'
|
|
22
|
+
+ ' relative to the current working directory.');
|
|
23
|
+
printWrappedMsg(' [outputPath] '
|
|
24
|
+
+ 'Path to file or directory where CSS + sourcemap files will be stored,'
|
|
25
|
+
+ ' relative to original file location (if not provided, css/ is used).');
|
|
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.');
|
|
29
|
+
console.info('\nInfo commands:');
|
|
30
|
+
printWrappedMsg(' -h, --help Display this help screen.');
|
|
31
|
+
printWrappedMsg(' -v, --version Show version number.');
|
|
32
|
+
|
|
33
|
+
// Show VERSION number if -v or --version passed
|
|
34
|
+
} else if (process.argv.some(arg => /^--?ve?r?s?i?o?n?$/.test(arg))) {
|
|
35
|
+
console.info('v' + require('./package.json').version);
|
|
36
|
+
|
|
37
|
+
} else { // run MAIN routine
|
|
38
|
+
|
|
39
|
+
// Init I/O args
|
|
40
|
+
const [inputArg = '', outputArg = ''] = ( // default to empty strings for error-less handling
|
|
41
|
+
process.argv.slice(2) // exclude executable and script paths
|
|
42
|
+
.filter(arg => !arg.startsWith('-')) // exclude flags
|
|
43
|
+
.map(arg => arg.replace(/^\/*/, '')) // clean leading slashes to avoid parsing system root
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
// Validate input arg (output arg can be anything)
|
|
47
|
+
const inputPath = path.resolve(process.cwd(), inputArg);
|
|
48
|
+
if (inputArg && !fs.existsSync(inputPath)) {
|
|
49
|
+
console.error(`\n${br}Error: First arg must be an existing file or directory.`
|
|
50
|
+
+ `\n${ inputPath } does not exist.${nc}`
|
|
51
|
+
+ '\n\nExample valid command: \n>> scsstocss . output.min.css');
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Load flag settings
|
|
56
|
+
const config = {
|
|
57
|
+
includeDotFolders: process.argv.some(arg =>
|
|
58
|
+
/^--?(?:dd|(?:include-)?dot-?(?:folder|dir(?:ector(?:y|ie))?)s?)$/.test(arg)),
|
|
59
|
+
disableSourceMaps: process.argv.some(arg =>
|
|
60
|
+
/^--?(?:S|(?:exclude|disable)-so?u?rce?-?maps?)$/.test(arg))
|
|
61
|
+
};
|
|
29
62
|
|
|
30
|
-
//
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
63
|
+
// Recursively find all eligible SCSS files or arg-passed file
|
|
64
|
+
const scssFiles = [];
|
|
65
|
+
if (inputArg.endsWith('.scss')) scssFiles.push(inputPath);
|
|
66
|
+
else (function findSCSSfiles(dir) {
|
|
67
|
+
const files = fs.readdirSync(dir);
|
|
68
|
+
files.forEach(file => {
|
|
69
|
+
const filePath = path.resolve(dir, file);
|
|
70
|
+
if (fs.statSync(filePath).isDirectory() &&
|
|
71
|
+
(config.includeDotFolders || !file.startsWith('.')))
|
|
72
|
+
findSCSSfiles(filePath); // recursively find SCSS in eligible dir
|
|
73
|
+
else if (file.endsWith('.scss')) // SCSS file found
|
|
74
|
+
scssFiles.push(filePath); // store it for compilation
|
|
75
|
+
});
|
|
76
|
+
})(inputPath);
|
|
35
77
|
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
78
|
+
// Compile SCSS files to CSS
|
|
79
|
+
let cssGenCnt = 0, srcMapGenCnt = 0;
|
|
80
|
+
console.log(''); // line break before first log
|
|
81
|
+
scssFiles.forEach(scssPath => {
|
|
82
|
+
console.info(`Compiling ${ scssPath }...`);
|
|
83
|
+
try { // to compile it
|
|
84
|
+
const outputDir = path.join(
|
|
85
|
+
path.dirname(scssPath), // path of file to be minified
|
|
86
|
+
/(?:src|s[ac]ss)$/.test(path.dirname(scssPath)) ? '../css' // + ../css/ if in *(src|sass|scss)/
|
|
87
|
+
: outputArg.endsWith('.css') ? path.dirname(outputArg) // or path from file output arg
|
|
88
|
+
: outputArg || 'css' // or path from folder output arg or css/ if no output arg passed
|
|
89
|
+
);
|
|
90
|
+
const outputFilename = (
|
|
91
|
+
outputArg.endsWith('.css') && inputArg.endsWith('.scss')
|
|
92
|
+
? path.basename(outputArg).replace(/(\.min)?\.css$/, '')
|
|
93
|
+
: path.basename(scssPath, '.scss')
|
|
94
|
+
) + '.min.css';
|
|
95
|
+
const outputPath = path.join(outputDir, outputFilename),
|
|
96
|
+
compileResult = sass.compile(scssPath, { style: 'compressed', sourceMap: !config.disableSourceMaps });
|
|
97
|
+
if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
|
|
98
|
+
fs.writeFileSync(outputPath, compileResult.css, 'utf8'); cssGenCnt++;
|
|
99
|
+
if (!config.disableSourceMaps) {
|
|
100
|
+
fs.writeFileSync(outputPath + '.map', JSON.stringify(compileResult.sourceMap), 'utf8');
|
|
101
|
+
srcMapGenCnt++;
|
|
102
|
+
}
|
|
103
|
+
} catch (err) {
|
|
104
|
+
console.error(`${br}Error compiling ${ scssPath }: ${ err.message }${nc}`);
|
|
105
|
+
}
|
|
48
106
|
});
|
|
49
|
-
})(inputPath);
|
|
50
107
|
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
console.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
fs.writeFileSync(outputPath, compileResult.css, 'utf8'); cssGenCnt++;
|
|
72
|
-
if (!config.disableSourceMaps) {
|
|
73
|
-
fs.writeFileSync(outputPath + '.map', JSON.stringify(compileResult.sourceMap), 'utf8');
|
|
74
|
-
srcMapGenCnt++;
|
|
108
|
+
// Print final summary
|
|
109
|
+
if (cssGenCnt) {
|
|
110
|
+
console.info(`\n${bg}Compilation complete!${nc}`);
|
|
111
|
+
console.info(`${ cssGenCnt } CSS file${ cssGenCnt > 1 ? 's' : '' }`
|
|
112
|
+
+ ( srcMapGenCnt ? ` + ${ srcMapGenCnt } source map${ srcMapGenCnt > 1 ? 's' : '' }` : '' )
|
|
113
|
+
+ ' generated.');
|
|
114
|
+
} else console.info(`${by}No SCSS files found.${nc}`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function printWrappedMsg(msg) { // truncates msg, indents 2nd+ lines
|
|
118
|
+
const terminalWidth = process.stdout.columns || 80,
|
|
119
|
+
indentation = 29, lines = [], words = msg.match(/\S+|\s+/g);
|
|
120
|
+
|
|
121
|
+
// Split msg into lines of appropriate lengths
|
|
122
|
+
let currentLine = '';
|
|
123
|
+
words.forEach(word => {
|
|
124
|
+
const lineLength = terminalWidth - ( lines.length === 0 ? 0 : indentation );
|
|
125
|
+
if (currentLine.length + word.length > lineLength) { // cap/store it
|
|
126
|
+
lines.push(lines.length === 0 ? currentLine : currentLine.trimStart());
|
|
127
|
+
currentLine = '';
|
|
75
128
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
});
|
|
129
|
+
currentLine += word;
|
|
130
|
+
});
|
|
131
|
+
lines.push(lines.length === 0 ? currentLine : currentLine.trimStart());
|
|
80
132
|
|
|
81
|
-
// Print
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
} else console.info(`${by}No SCSS files found.${nc}`);
|
|
133
|
+
// Print formatted msg
|
|
134
|
+
lines.forEach((line, index) => console.info(
|
|
135
|
+
index === 0 ? line // print 1st line unindented
|
|
136
|
+
: ' '.repeat(indentation) + line // print subsequent lines indented
|
|
137
|
+
));
|
|
138
|
+
}
|