@adamlui/scss-to-css 1.0.1 → 1.1.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 +118 -81
- package/package.json +43 -37
- package/scss-to-css.js +56 -48
- package/adamlui-scss-to-css-1.0.1.tgz +0 -0
package/README.md
CHANGED
|
@@ -1,81 +1,118 @@
|
|
|
1
|
-
# { } scss-to-css.js
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
1
|
+
# { } scss-to-css.js
|
|
2
|
+
|
|
3
|
+
### Recursively compile all SCSS files into minified CSS.
|
|
4
|
+
|
|
5
|
+
<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>
|
|
6
|
+
<a href="https://www.npmjs.com/package/@adamlui/scss-to-css"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.1.1-fc7811.svg?logo=npm&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
7
|
+
|
|
8
|
+
<img height=8px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/media/images/separators/aqua.png">
|
|
9
|
+
|
|
10
|
+
## ⚡ Installation
|
|
11
|
+
|
|
12
|
+
As a **global utility**:
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
npm install -g @adamlui/scss-to-css
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
As a **dev dependency**, from your project root:
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
npm install -D @adamlui/scss-to-css
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 💻 Usage
|
|
25
|
+
|
|
26
|
+
The basic **global command** is:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
scss-to-css
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Sample output:
|
|
33
|
+
|
|
34
|
+
<img src="https://github.com/adamlui/js-utils/blob/main/scss-to-css/media/images/sample-output.png">
|
|
35
|
+
|
|
36
|
+
**💡 Note:** Source maps are also generated.
|
|
37
|
+
|
|
38
|
+
#
|
|
39
|
+
|
|
40
|
+
To specify **input/output** directories:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
scss-to-css <input_path> <output_path>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- `<input_path>`: Path to directory containing SCSS files to be compiled, relative to the current working directory.
|
|
47
|
+
- `<output_path>`: Path to directory where CSS/sourcemap files will be stored, relative to original file location. (If not provided, same location is used.)
|
|
48
|
+
|
|
49
|
+
**💡 Note:** The paths can be either folders or specific files. If folders are passed, files will be processed recursively.
|
|
50
|
+
|
|
51
|
+
#
|
|
52
|
+
|
|
53
|
+
To use as a **package script**, edit your project's `package.json` like this:
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build:css": "<scss-to-css-cmd>"
|
|
58
|
+
},
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Replace `<scss-to-css-cmd>` with `scss-to-css` + optional args. Then, `npm run build:css` can be used to run the command.
|
|
62
|
+
<br><br>
|
|
63
|
+
|
|
64
|
+
## 📃 Example commands:
|
|
65
|
+
|
|
66
|
+
- Compile all SCSS files in the **current directory** (outputs to same directory`):
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
scss-to-css
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
- Compile all SCSS files in a **specific directory** (outputs to `path/to/your/directory/`):
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
scss-to-css path/to/your/directory
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
- Compile a **specific file** (outputs to `path/to/your/minified/file.min.css`):
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
scss-to-css path/to/your/file.scss
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
- Specify both **input and output** directories (outputs to `output_folder/`):
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
scss-to-css input_folder output_folder
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## 🏛️ MIT License
|
|
91
|
+
|
|
92
|
+
**Copyright (c) 2024 [Adam Lui](https://github.com/adamlui)**
|
|
93
|
+
|
|
94
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
95
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
96
|
+
in the Software without restriction, including without limitation the rights
|
|
97
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
98
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
99
|
+
furnished to do so, subject to the following conditions:
|
|
100
|
+
|
|
101
|
+
The above copyright notice and this permission notice shall be included in all
|
|
102
|
+
copies or substantial portions of the Software.
|
|
103
|
+
|
|
104
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
105
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
106
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
107
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
108
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
109
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
110
|
+
SOFTWARE.
|
|
111
|
+
|
|
112
|
+
<br>
|
|
113
|
+
|
|
114
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/media/images/separators/aqua.png">
|
|
115
|
+
|
|
116
|
+
<a href="https://github.com/adamlui/js-utils">**Home**</a> /
|
|
117
|
+
<a href="https://github.com/adamlui/js-utils/discussions">Discuss</a> /
|
|
118
|
+
<a href="#--scss-to-cssjs">Back to top ↑</a>
|
package/package.json
CHANGED
|
@@ -1,37 +1,43 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@adamlui/scss-to-css",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Recursively compile all SCSS files into minified CSS",
|
|
5
|
-
"author": {
|
|
6
|
-
"name": "Adam Lui",
|
|
7
|
-
"email": "adam@kudoai.com",
|
|
8
|
-
"url": "https://github.com/adamlui"
|
|
9
|
-
},
|
|
10
|
-
"homepage": "https://github.com/adamlui/js-utils",
|
|
11
|
-
"license": "MIT",
|
|
12
|
-
"main": "scss-to-css.js",
|
|
13
|
-
"bin": {
|
|
14
|
-
"scss-to-css": "scss-to-css.js"
|
|
15
|
-
},
|
|
16
|
-
"scripts": {
|
|
17
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@adamlui/scss-to-css",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "Recursively compile all SCSS files into minified CSS",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Adam Lui",
|
|
7
|
+
"email": "adam@kudoai.com",
|
|
8
|
+
"url": "https://github.com/adamlui"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/adamlui/js-utils",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"main": "scss-to-css.js",
|
|
13
|
+
"bin": {
|
|
14
|
+
"scss-to-css": "scss-to-css.js"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
18
|
+
"bump:patch": "bash utils/bump.sh patch",
|
|
19
|
+
"bump:minor": "bash utils/bump.sh minor",
|
|
20
|
+
"bump:major": "bash utils/bump.sh major",
|
|
21
|
+
"publish:patch": "bash utils/bump.sh patch --publish",
|
|
22
|
+
"publish:minor": "bash utils/bump.sh minor --publish",
|
|
23
|
+
"publish:major": "bash utils/bump.sh major --publish"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/adamlui/js-utils.git"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"scss",
|
|
31
|
+
"sass",
|
|
32
|
+
"css",
|
|
33
|
+
"stylesheets",
|
|
34
|
+
"compiler",
|
|
35
|
+
"minifier"
|
|
36
|
+
],
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/adamlui/js-utils/issues"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"sass": "^1.70.0"
|
|
42
|
+
}
|
|
43
|
+
}
|
package/scss-to-css.js
CHANGED
|
@@ -1,63 +1,71 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// Import libs
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const fs = require('fs'),
|
|
5
|
+
path = require('path'),
|
|
6
|
+
sass = require('sass');
|
|
7
7
|
|
|
8
8
|
// Init UI colors
|
|
9
9
|
const nc = '\x1b[0m', // no color
|
|
10
10
|
br = '\x1b[1;91m', // bright red
|
|
11
|
+
by = '\x1b[1;33m', // bright yellow
|
|
11
12
|
bg = '\x1b[1;92m'; // bright green
|
|
12
13
|
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
// Clean leading slashes from args to avoid parsing system root
|
|
15
|
+
const inputArg = process.argv[2] ? process.argv[2].replace(/^\/*/, '') : '',
|
|
16
|
+
outputArg = process.argv[3] ? process.argv[3].replace(/^\/*/, '') : '';
|
|
17
|
+
|
|
18
|
+
// Validate input arg (output arg can be anything)
|
|
19
|
+
if (process.argv[2] && !fs.existsSync(inputArg)) {
|
|
20
|
+
console.error(`\n${br}Error: First arg must be an existing file or path.${nc}`
|
|
21
|
+
+ '\nExample valid command: \n>> scss-to-css . output.min.css');
|
|
18
22
|
process.exit(1);
|
|
19
23
|
}
|
|
20
24
|
|
|
21
|
-
//
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const scssFiles = (() => {
|
|
38
|
-
const fileList = [];
|
|
39
|
-
const findSCSSfiles = dir => {
|
|
40
|
-
const files = fs.readdirSync(dir);
|
|
41
|
-
files.forEach(file => {
|
|
42
|
-
const filePath = path.join(dir, file);
|
|
43
|
-
if (fs.statSync(filePath).isDirectory()) findSCSSfiles(filePath);
|
|
44
|
-
else if (file.endsWith('.scss')) fileList.push(filePath);
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
findSCSSfiles(userProjectDir); return fileList;
|
|
48
|
-
})();
|
|
25
|
+
// Recursively find all SCSS files or arg-passed file
|
|
26
|
+
const inputPath = path.resolve(process.cwd(), inputArg);
|
|
27
|
+
const scssFiles = inputArg.endsWith('.scss') ? [inputPath]
|
|
28
|
+
: (() => {
|
|
29
|
+
const fileList = [];
|
|
30
|
+
(function findSCSSfiles(dir) {
|
|
31
|
+
const files = fs.readdirSync(dir);
|
|
32
|
+
files.forEach(file => {
|
|
33
|
+
const filePath = path.resolve(dir, file);
|
|
34
|
+
if (fs.statSync(filePath).isDirectory())
|
|
35
|
+
findSCSSfiles(filePath); // recursively find SCSS
|
|
36
|
+
else if (/\.scss$/.test(file)) // SCSS file found
|
|
37
|
+
fileList.push(filePath); // store it for minification
|
|
38
|
+
});
|
|
39
|
+
})(inputPath); return fileList;
|
|
40
|
+
})();
|
|
49
41
|
|
|
50
42
|
// Compile SCSS files to CSS
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
43
|
+
let generatedCnt = 0;
|
|
44
|
+
console.log(''); // line break before first log
|
|
45
|
+
scssFiles.forEach(scssPath => {
|
|
46
|
+
try { // to compile it
|
|
47
|
+
const outputDir = path.join(
|
|
48
|
+
path.dirname(scssPath), // path of file to be minified
|
|
49
|
+
outputArg.endsWith('.css') ? path.dirname(outputArg) : outputArg, // path from output arg
|
|
50
|
+
path.dirname(scssPath).endsWith('scss') ? '../css' : '' // ../css/ if in scss/
|
|
58
51
|
);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
52
|
+
const outputFilename = (
|
|
53
|
+
outputArg.endsWith('.css') && inputArg.endsWith('.scss')
|
|
54
|
+
? path.basename(outputArg).replace(/(\.min)?\.css$/, '')
|
|
55
|
+
: path.basename(scssPath, '.scss')
|
|
56
|
+
) + '.min.css';
|
|
57
|
+
const outputPath = path.join(outputDir, outputFilename);
|
|
58
|
+
console.info(`Compiling ${ scssPath }...`);
|
|
59
|
+
const compileResult = sass.compile(scssPath, { style: 'compressed', sourceMap: true });
|
|
60
|
+
if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
|
|
61
|
+
fs.writeFileSync(outputPath, compileResult.css, 'utf8');
|
|
62
|
+
fs.writeFileSync(outputPath + '.map', JSON.stringify(compileResult.sourceMap), 'utf8');
|
|
63
|
+
generatedCnt+= 2;
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.error(`${br}Error compiling ${ scssPath }: ${ err.message }${nc}`);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Print final summary
|
|
70
|
+
if (generatedCnt) console.info(`\n${bg}Compilation complete!${nc}\n${ generatedCnt } files generated.`);
|
|
71
|
+
else console.info(`\n${by}No SCSS files found.${nc}`);
|
|
Binary file
|