@adamlui/scss-to-css 1.7.1 → 1.7.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 CHANGED
@@ -1,4 +1,4 @@
1
- <div align="right">
1
+ <div align="center">
2
2
  <h6>
3
3
  <picture>
4
4
  <source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
@@ -11,7 +11,9 @@
11
11
  <a href="https://github.com/adamlui/js-utils/tree/main/scss-to-css/docs/bn#readme">বাংলা</a> |
12
12
  <a href="https://github.com/adamlui/js-utils/tree/main/scss-to-css/docs/mr#readme">मराठी</a> |
13
13
  <a href="https://github.com/adamlui/js-utils/tree/main/scss-to-css/docs/pa#readme">ਪੰਜਾਬੀ</a> |
14
+ <a href="https://github.com/adamlui/js-utils/tree/main/scss-to-css/docs/de#readme">Deutsch</a> |
14
15
  <a href="https://github.com/adamlui/js-utils/tree/main/scss-to-css/docs/es#readme">Español</a> |
16
+ <a href="https://github.com/adamlui/js-utils/tree/main/scss-to-css/docs/fr#readme">Français</a> |
15
17
  <a href="https://github.com/adamlui/js-utils/tree/main/scss-to-css/docs/pt#readme">Português</a>
16
18
  </h6>
17
19
  </div>
@@ -22,7 +24,7 @@
22
24
 
23
25
  <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&color=af68ff&logoColor=white&labelColor=464646&style=for-the-badge"></a>
24
26
  <a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
25
- <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.1-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
27
+ <a href="https://github.com/adamlui/js-utils/releases/tag/scss-to-css-1.7.2"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.7.2-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
26
28
  <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>
27
29
  <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>
28
30
 
@@ -212,8 +214,18 @@ Searches for all SCSS files within the `searchDir` string passed (useful for dis
212
214
  Options are boolean, passed as object properties. For example:
213
215
 
214
216
  ```js
215
- // Returns array containing filepaths to SCSS files in exactly `searchDir`
216
- scssToCSS.findSCSS(searchDir, { recursive: false });
217
+ // Search for SCSS files in exactly assets/scss:
218
+ const searchResults = scssToCSS.findSCSS('assets/scss', { recursive: false });
219
+ console.log(searchResults);
220
+
221
+ /* sample output:
222
+ Searching for SCSS files...
223
+ Search complete. 2 files found.
224
+ [
225
+ 'E:\\js\\utils\\minify.js\\assets\\scss\\foo.scss',
226
+ 'E:\\js\\utils\\minify.js\\assets\\scss\\bar.scss'
227
+ ]
228
+ */
217
229
  ```
218
230
 
219
231
  Available parameters (and their default settings) are:
package/docs/LICENSE.md CHANGED
@@ -11,7 +11,9 @@
11
11
  <a href="bn/LICENSE.md">বাংলা</a> |
12
12
  <a href="mr/LICENSE.md">मराठी</a> |
13
13
  <a href="pa/LICENSE.md">ਪੰਜਾਬੀ</a> |
14
+ <a href="de/LICENSE.md">Deutsch</a> |
14
15
  <a href="es/LICENSE.md">Español</a> |
16
+ <a href="fr/LICENSE.md">Français</a> |
15
17
  <a href="pt/LICENSE.md">Português</a>
16
18
  </h6>
17
19
  </div>
package/docs/SECURITY.md CHANGED
@@ -11,7 +11,9 @@
11
11
  <a href="bn/SECURITY.md">বাংলা</a> |
12
12
  <a href="mr/SECURITY.md">मराठी</a> |
13
13
  <a href="pa/SECURITY.md">ਪੰਜਾਬੀ</a> |
14
+ <a href="de/SECURITY.md">Deutsch</a> |
14
15
  <a href="es/SECURITY.md">Español</a> |
16
+ <a href="fr/SECURITY.md">Français</a> |
15
17
  <a href="pt/SECURITY.md">Português</a>
16
18
  </h6>
17
19
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamlui/scss-to-css",
3
- "version": "1.7.1",
3
+ "version": "1.7.2",
4
4
  "description": "Recursively compile all SCSS files into minified CSS",
5
5
  "author": {
6
6
  "name": "Adam Lui",
package/scss-to-css.js CHANGED
@@ -13,6 +13,28 @@ function findSCSS(searchDir, options = {}) {
13
13
  const defaultOptions = { recursive: true, verbose: true, dotFolders: false };
14
14
  options = { ...defaultOptions, ...options };
15
15
 
16
+ // Validate searchDir
17
+ if (!searchDir) return console.error(
18
+ 'findSCSS() error: Please supply a `searchDir` arg.');
19
+ else if (typeof searchDir !== 'string') return console.error(
20
+ 'findSCSS() error: Arg `searchDir` must be a string.');
21
+ else { // verify searchDir path existence
22
+ const searchPath = path.resolve(process.cwd(), searchDir);
23
+ if (!fs.existsSync(searchPath)) return console.error(
24
+ 'findSCSS() error: Arg `searchDir` must be an existing directory.'
25
+ + `\n'${ searchPath }' does not exist.`);
26
+ }
27
+
28
+ // Validate options
29
+ for (const key of Object.keys(options)) {
30
+ if (!Object.prototype.hasOwnProperty.call(defaultOptions, key))
31
+ if (key !== 'isRecursing') return console.error(
32
+ `findSCSS() error: \`${ key }\` is an invalid option.`
33
+ + `\nValid options: [ ${Object.keys(defaultOptions).join(', ')} ]`);
34
+ else if (typeof options[key] !== 'boolean') return console.error(
35
+ `findSCSS() error: \`${ key }\` option must be set to \`true\` or \`false\`.`);
36
+ }
37
+
16
38
  // Search for SCSS
17
39
  const dirFiles = fs.readdirSync(searchDir), scssFiles = [];
18
40
  if (options.verbose && !options.isRecursing) console.info('\nSearching for SCSS files...');
@@ -42,9 +64,23 @@ function compile(inputPath, options = {}) {
42
64
  options = { ...defaultOptions, ...options };
43
65
 
44
66
  // Validate inputPath
45
- if (typeof inputPath !== 'string')
46
- return console.error('ERROR:'
47
- + ' First argument must be a string representing a file/folder path.');
67
+ if (typeof inputPath !== 'string') return console.error(
68
+ 'compile() error: Arg `inputPath` must be a string.');
69
+ else { // verify inputPath path existence
70
+ inputPath = path.resolve(process.cwd(), inputPath);
71
+ if (!fs.existsSync(inputPath)) return console.error(
72
+ 'compile() error: Arg `inputPath` must be an existing directory or file.'
73
+ + `\n'${ inputPath }' does not exist.`);
74
+ }
75
+
76
+ // Validate options
77
+ for (const key of Object.keys(options)) {
78
+ if (!Object.prototype.hasOwnProperty.call(defaultOptions, key)) return console.error(
79
+ `findSCSS() error: \`${ key }\` is an invalid option.`
80
+ + `\nValid options: [ ${Object.keys(defaultOptions).join(', ')} ]`);
81
+ else if (typeof options[key] !== 'boolean') return console.error(
82
+ `findSCSS() error: \`${ key }\` option must be set to \`true\` or \`false\`.`);
83
+ }
48
84
 
49
85
  // Compile SCSS based on inputPath
50
86
  const compileOptions = { style: options.minify ? 'compressed' : 'expanded', sourceMap: options.sourceMaps };
@@ -53,10 +89,11 @@ function compile(inputPath, options = {}) {
53
89
  if (options.verbose) console.info(`Compiling ${ inputPath }...`);
54
90
  try { // to compile file passed
55
91
  const compileResult = sass.compile(inputPath, compileOptions);
56
- return { code: compileResult.css, srcMap: compileResult.sourceMap, srcPath: inputPath };
92
+ return { code: compileResult.css, srcMap: compileResult.sourceMap,
93
+ srcPath: path.resolve(process.cwd(), inputPath) };
57
94
  } catch (err) { console.error(`\nERROR: ${ err.message }\n`); return { error: err }; }
58
95
  } else { // dir path passed
59
- return findSCSS(inputPath, { recursive: options.recursive, verbosity: options.verbose,
96
+ return findSCSS(inputPath, { recursive: options.recursive, verbose: options.verbose,
60
97
  dotFolders: options.dotFolders
61
98
  })?.map(scssPath => { // compile found SCSS files
62
99
  if (options.verbose) console.info(`Compiling ${ scssPath }...`);
@@ -66,14 +103,13 @@ function compile(inputPath, options = {}) {
66
103
  } catch (err) { console.error(`\nERROR: ${ err.message }\n`); return { error: err }; }
67
104
  }).filter(data => !data.error ); // filter out failed compilations
68
105
  }
69
- } else return console.error('First argument must be an existing file or directory.'
70
- + `\n'${ inputPath }' does not exist.`);
106
+ }
71
107
  }
72
108
 
73
- // EXPORT functions if script was required
109
+ // EXPORT main functions if script was required
74
110
  if (require.main !== module) module.exports = { compile, findSCSS };
75
111
 
76
- else { // run as CLI tool
112
+ else { // run as CLI utility
77
113
 
78
114
  // Init UI colors
79
115
  const nc = '\x1b[0m', // no color
@@ -100,12 +136,12 @@ else { // run as CLI tool
100
136
  else {
101
137
  console.error(`\n${br}ERROR: Arg [${ arg }] not recognized.${nc}`);
102
138
  console.info(`\n${by}Valid arguments are below.${nc}`);
103
- printHelpScreen(['configOptions', 'infoCmds']);
139
+ printHelpSections(['configOptions', 'infoCmds']);
104
140
  process.exit(1);
105
141
  }});
106
142
 
107
143
  // Show HELP screen if -h or --help passed
108
- if (process.argv.some(arg => argRegex.help.test(arg))) printHelpScreen();
144
+ if (process.argv.some(arg => argRegex.help.test(arg))) printHelpSections();
109
145
 
110
146
  // Show VERSION number if -v or --version passed
111
147
  else if (process.argv.some(arg => argRegex.version.test(arg)))
@@ -189,31 +225,8 @@ else { // run as CLI tool
189
225
 
190
226
  // Define LOGGING functions
191
227
 
192
- function printHelpMsg(msg) { // wrap msg + indent 2nd+ lines (for --help screen)
193
- const terminalWidth = process.stdout.columns || 80,
194
- indentation = 30, lines = [], words = msg.match(/\S+|\s+/g);
195
-
196
- // Split msg into lines of appropriate lengths
197
- let currentLine = '';
198
- words.forEach(word => {
199
- const lineLength = terminalWidth - ( lines.length === 0 ? 0 : indentation );
200
- if (currentLine.length + word.length > lineLength) { // cap/store it
201
- lines.push(lines.length === 0 ? currentLine : currentLine.trimStart());
202
- currentLine = '';
203
- }
204
- currentLine += word;
205
- });
206
- lines.push(lines.length === 0 ? currentLine : currentLine.trimStart());
207
-
208
- // Print formatted msg
209
- lines.forEach((line, index) => console.info(
210
- index === 0 ? line // print 1st line unindented
211
- : ' '.repeat(indentation) + line // print subsequent lines indented
212
- ));
213
- }
214
-
215
- function printHelpScreen(includeSections = ['cmdFormat', 'pathArgs', 'configOptions', 'infoCmds']) {
216
- const sections = {
228
+ function printHelpSections(includeSections = ['cmdFormat', 'pathArgs', 'configOptions', 'infoCmds']) {
229
+ const helpSections = {
217
230
  'cmdFormat': [
218
231
  `\n${by}scss-to-css [inputPath] [outputPath] [options]${nc}`
219
232
  ],
@@ -243,7 +256,30 @@ else { // run as CLI tool
243
256
  ]
244
257
  };
245
258
  includeSections.forEach(section => { // print valid arg elems
246
- if (sections[section]) sections[section].forEach(line => printHelpMsg(line)); });
259
+ helpSections[section]?.forEach(line => printHelpMsg(line)); });
260
+
261
+ function printHelpMsg(msg) { // wrap msg + indent 2nd+ lines (for --help screen)
262
+ const terminalWidth = process.stdout.columns || 80,
263
+ indentation = 30, lines = [], words = msg.match(/\S+|\s+/g);
264
+
265
+ // Split msg into lines of appropriate lengths
266
+ let currentLine = '';
267
+ words.forEach(word => {
268
+ const lineLength = terminalWidth - ( lines.length === 0 ? 0 : indentation );
269
+ if (currentLine.length + word.length > lineLength) { // cap/store it
270
+ lines.push(lines.length === 0 ? currentLine : currentLine.trimStart());
271
+ currentLine = '';
272
+ }
273
+ currentLine += word;
274
+ });
275
+ lines.push(lines.length === 0 ? currentLine : currentLine.trimStart());
276
+
277
+ // Print formatted msg
278
+ lines.forEach((line, index) => console.info(
279
+ index === 0 ? line // print 1st line unindented
280
+ : ' '.repeat(indentation) + line // print subsequent lines indented
281
+ ));
282
+ }
247
283
  }
248
284
 
249
285
  function printIfNotQuiet(msg) { if (!config.quietMode) console.info(msg); }