@adamlui/scss-to-css 2.3.1 → 2.4.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 CHANGED
@@ -29,12 +29,12 @@
29
29
 
30
30
  ### Recursively compile all SCSS files into minified CSS
31
31
 
32
- <a href="https://www.npmjs.com/package/@adamlui/scss-to-css">
32
+ <a href="https://npmstar.com/compare/@adamlui%2Fscss-to-css">
33
33
  <img height=31 src="https://img.shields.io/npm/dm/%40adamlui%2Fscss-to-css?logo=npm&color=af68ff&logoColor=white&labelColor=464646&style=for-the-badge"></a>
34
34
  <a href="#%EF%B8%8F-mit-license">
35
35
  <img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
36
- <a href="https://github.com/adamlui/js-utils/releases/tag/scss-to-css-2.3.1">
37
- <img height=31 src="https://img.shields.io/badge/Latest_Build-2.3.1-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
36
+ <a href="https://github.com/adamlui/js-utils/releases/tag/scss-to-css-2.4.0">
37
+ <img height=31 src="https://img.shields.io/badge/Latest_Build-2.4.0-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
38
38
  <a href="https://www.npmjs.com/package/@adamlui/scss-to-css?activeTab=code">
39
39
  <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>
40
40
  <a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_scss-to-css:src/scss-to-css.js">
@@ -80,7 +80,7 @@ $ scss-to-css
80
80
 
81
81
  Sample output:
82
82
 
83
- <img src="https://cdn.jsdelivr.net/gh/adamlui/scss-to-css@b74edea/node.js/media/images/screenshots/cli/scss-to-css-docs-cmd-output.png">
83
+ <img src="https://cdn.jsdelivr.net/gh/adamlui/scss-to-css@fe2867e/assets/images/screenshots/cli/scss-to-css-docs-cmd-output.png">
84
84
 
85
85
  **📝 Note:** Source maps are also generated by default unless `-S` or `--no-source-maps` is passed.
86
86
 
package/dist/cli/index.js CHANGED
@@ -3,19 +3,15 @@
3
3
  (async () => {
4
4
  'use strict'
5
5
 
6
- globalThis.env = {
7
- args: process.argv.slice(2),
8
- modes: { dev: /[\\/]src(?:[\\/]|$)/i.test(__dirname) },
9
- paths: { lib: './lib' }
10
- }
11
- env.modes.debug = env.args.some(arg => /^--?(?:V|debug(?:[-_]?mode)?)$/.test(arg))
6
+ // Init ENV
7
+ const init = require('./lib/init')
8
+ init.env()
12
9
 
13
10
  // Import LIBS
14
- globalThis.log = require(`${env.paths.lib}/log`)
15
- const compile = require(`${env.paths.lib}/compile`),
11
+ globalThis.log = require('./lib/log')
12
+ const compile = require('./lib/compile'),
16
13
  { findSCSS } = require('../scss-to-css'),
17
14
  fs = require('fs'),
18
- init = require(`${env.paths.lib}/init`),
19
15
  path = require('path')
20
16
 
21
17
  await init.cli()
@@ -1,12 +1,10 @@
1
1
  const language = require('./language'),
2
2
  settings = require('./settings')
3
3
 
4
- const dataPath = `../../${ env.modes.dev ? '../' : 'data/' }`
5
-
6
4
  module.exports = {
7
5
 
8
6
  async cli() {
9
- Object.assign(globalThis.cli ??= {}, require(`${dataPath}package-data.json`))
7
+ Object.assign(globalThis.cli ??= {}, require(`${env.paths.libData}/package-data.json`))
10
8
  cli.msgs = await language.getMsgs('en')
11
9
  cli.msgs = await language.getMsgs(cli.lang = settings.load('uiLang') || (
12
10
  env.modes.debug ? language.generateRandomLang({ excludes: ['en'] }) : language.getSysLang() ))
@@ -27,11 +25,11 @@ module.exports = {
27
25
 
28
26
  if (fs.existsSync(paths.target)) // use existing config file
29
27
  return log.warn(`${cli.msgs.warn_configFileExists}:`, paths.target)
30
- if (fs.existsSync(paths.src = path.resolve(__dirname, `${dataPath}${filename}`)))
28
+ if (fs.existsSync(paths.src = path.resolve(__dirname, `${env.paths.libData}/${filename}`)))
31
29
  fs.copyFileSync(paths.src, paths.target) // use found template
32
30
 
33
31
  else { // use jsDelivr copy
34
- const jsdURL = `${require('./jsdelivr').pkgVerURL()}/${filename}`
32
+ const jsdURL = `${require('./jsdelivr').getPkgVerURL()}/${filename}`
35
33
  log.data(`${cli.msgs.info_fetchingRemoteConfigFrom} ${jsdURL}...`)
36
34
  try {
37
35
  const data = require('./data'),
@@ -45,5 +43,15 @@ module.exports = {
45
43
  log.success(`${cli.msgs.info_configFileCreated}: ${paths.target}\n`)
46
44
  log.tip(`${cli.msgs.tip_editToSetDefaults}.`)
47
45
  log.tip(`${cli.msgs.tip_cliArgsPrioritized}.`)
46
+ },
47
+
48
+ env() {
49
+ Object.assign(globalThis.env ??= {}, {
50
+ args: process.argv.slice(2),
51
+ modes: { dev: /[\\/]src(?:[\\/]|$)/i.test(__dirname) },
52
+ supports: { unicode: require('is-unicode-supported').default() }
53
+ })
54
+ env.modes.debug = env.args.some(arg => /^--?(?:V|debug(?:[-_]?mode)?)$/.test(arg))
55
+ env.paths = { libData: `../../${ env.modes.dev ? '..' : 'data' }` }
48
56
  }
49
57
  }
@@ -1,10 +1,10 @@
1
1
  module.exports = {
2
2
 
3
- pkgVerURL(version) {
3
+ getPkgVerURL(version) {
4
4
  version ||= cli.version ||= require('./pkg').getVer('local') || 'none'
5
5
  const verTag = !/^\d+\.\d+\.\d+$/.test(version) ? 'latest' : `v${version}`
6
- return `${cli.urls.jsdelivr}@${verTag}`
6
+ return `${cli.urls.jsdelivr.pkg}@${verTag}`
7
7
  },
8
8
 
9
- commitURL(hash = 'latest') { return `${cli.urls.jsdelivr}@${hash}` }
9
+ getCommitURL(hash = 'latest') { return `${cli.urls.jsdelivr.pkg}@${hash}` }
10
10
  }
@@ -13,13 +13,13 @@ module.exports = {
13
13
  let locales = includes.length ? includes : (() => {
14
14
 
15
15
  // Read cache if found
16
- const cacheDir = path.join(__dirname, '..', '.cache'),
16
+ const cacheDir = path.join(__dirname, '../../.cache'),
17
17
  localeCache = path.join(cacheDir, 'locales.json')
18
18
  if (fs.existsSync(localeCache))
19
19
  try { return JSON.parse(fs.readFileSync(localeCache, 'utf8')) } catch (err) {}
20
20
 
21
21
  // Discover pkg _locales
22
- const localesDir = path.resolve(process.cwd(), '_locales')
22
+ const localesDir = path.resolve(__dirname, '../../../_locales')
23
23
  if (!fs.existsSync(localesDir)) return ['en']
24
24
  const locales = fs.readdirSync(localesDir, { withFileTypes: true })
25
25
  .filter(entry => entry.isDirectory()).map(entry => entry.name)
@@ -37,9 +37,7 @@ module.exports = {
37
37
  locales = locales.filter(locale => !excludeSet.has(locale))
38
38
 
39
39
  // Get random language
40
- let randomLang = 'en'
41
- if (locales.length)
42
- randomLang = locales[Math.floor(Math.random() * locales.length)]
40
+ const randomLang = locales.length ? locales[Math.floor(Math.random() * locales.length)] : 'en'
43
41
  log.debug(`Random language: ${randomLang}`)
44
42
 
45
43
  return randomLang
@@ -47,7 +45,7 @@ module.exports = {
47
45
 
48
46
  async getDocLocales() {
49
47
  cli.version ||= require('./pkg').getVer('local') || 'none'
50
- const jsdURL = `${require('./jsdelivr').pkgVerURL()}/docs/`,
48
+ const jsdURL = `${require('./jsdelivr').getPkgVerURL()}/docs/`,
51
49
  locales = []
52
50
  try {
53
51
  const respText = await (await data.fetch(jsdURL)).text(),
@@ -64,20 +62,29 @@ module.exports = {
64
62
  if (env.msgs && langCode == cli.lang) return env.msgs // don't re-fetch same msgs
65
63
 
66
64
  let msgs = data.flatten( // local ones
67
- require(`../../${ env.modes.dev ? '../_locales/en/' : 'data/' }messages.json`))
65
+ require(`../../${ env.modes.dev ? '../_locales/en' : 'data' }/messages.json`))
68
66
 
69
67
  if (!langCode.startsWith('en')) { // fetch non-English msgs from jsDelivr
70
- const msgHostURL = `${require('./jsdelivr').commitURL(cli.commitHashes.locales)}/_locales/`
71
- let msgHref = `${msgHostURL}${langCode}/messages.json`, msgFetchesTried = 0
68
+ try { // check if terminal supports non-Latin scripts
69
+ const nonLatinLocales = await (await data.fetch(
70
+ `${cli.urls.jsdelivr}@${cli.commitHashes.data}/assets/data/non-latin-locales.json`
71
+ )).json()
72
+ if (nonLatinLocales.includes(langCode.split('-')[0]) && !env.supports.unicode)
73
+ return msgs // en ones
74
+ } catch (err) {
75
+ log.debug(`Failed to fetch non-Latin locales: ${err}`)
76
+ }
77
+ const msgBaseURL = `${require('./jsdelivr').getCommitURL(cli.commitHashes.locales)}/_locales`
78
+ let msgURL = `${msgBaseURL}/${langCode}/messages.json`, msgFetchesTried = 0
72
79
  while (msgFetchesTried < 3)
73
80
  try { // fetch remote msgs
74
- msgs = data.flatten(await (await data.fetch(msgHref)).json())
81
+ msgs = data.flatten(await (await data.fetch(msgURL)).json())
75
82
  break
76
83
  } catch (err) { // retry up to 2X (region-stripped + EN)
77
84
  msgFetchesTried++ ; if (msgFetchesTried >= 3) break
78
- log.debug(msgHref = langCode.includes('-') && msgFetchesTried == 1 ?
79
- msgHref.replace(/([^_]*)_[^/]*(\/.*)/, '$1$2') // strip region before retrying
80
- : `${msgHostURL}en/messages.json` // else use EN msgs
85
+ log.debug(msgURL = langCode.includes('-') && msgFetchesTried == 1 ?
86
+ msgURL.replace(/([^_]*)_[^/]*(\/.*)/, '$1$2') // strip region before retrying
87
+ : `${msgBaseURL}/en/messages.json` // else use EN msgs
81
88
  )
82
89
  }
83
90
  }
@@ -1,5 +1,6 @@
1
1
  const colors = require('./color'),
2
2
  { getDownloads, getVer } = require('./pkg'),
3
+ settings = require('./settings'),
3
4
  string = require('./string')
4
5
 
5
6
  const nextMajVer = require('../../../package.json').version.replace(/^(\d+)\..*/, (_, major) => `${ +major +1 }.0.0`)
@@ -7,6 +8,7 @@ const nextMajVer = require('../../../package.json').version.replace(/^(\d+)\..*/
7
8
  module.exports = {
8
9
  colors,
9
10
 
11
+ break() { console.log() },
10
12
  configURL() { this.info(`${cli.msgs.info_exampleValidConfigFile}: ${cli.urls.config}`) },
11
13
  configURLandExit(...args) { this.error(...args); this.configURL(); process.exit(1) },
12
14
  data(msg) { console.log(`\n${colors.bw}${msg}${colors.nc}`) },
@@ -15,9 +17,8 @@ module.exports = {
15
17
  errorAndExit(...args) { this.error(...args); this.helpDocsCmdsDocsURL(); process.exit(1) },
16
18
  ifNotQuiet(msg) { if (!cli.config.quietMode) this.info(msg) },
17
19
  info(msg) { console.info(`\n${colors.schemes.default[0]}${msg}${colors.nc}`) },
18
- break() { console.log() },
19
- tip(msg) { console.info(`${colors.by}TIP: ${msg}${colors.nc}`) },
20
20
  success(msg) { console.log(`\n${colors.bg}${msg}${colors.nc}`) },
21
+ tip(msg) { console.info(`${colors.by}TIP: ${msg}${colors.nc}`) },
21
22
  warn(...args) { console.warn(`\n${colors.bo}WARNING:`, ...args, colors.nc) },
22
23
 
23
24
  argDoesNothing(arg) {
@@ -30,11 +31,10 @@ module.exports = {
30
31
  this.warn(
31
32
  `${cli.msgs.info_configFile} ${cli.msgs.warn_option.toLowerCase()} '${oldKey}: ${oldVal}' ${
32
33
  cli.msgs.warn_hasBeenReplacedBy} '${
33
- newKey}: ${ isNegKey(oldKey) != isNegKey(newKey) ? !oldVal : oldVal }' ${
34
+ newKey}: ${ settings.isNegKey(oldKey) != settings.isNegKey(newKey) ? !oldVal : oldVal }' ${
34
35
  cli.msgs.warn_andWillBeRemoved} @ v${nextMajVer}`
35
36
  )
36
37
  this[`${oldKey}Warned`] = true
37
- function isNegKey(key) { return /^(?:no|disable|exclude)[A-Z]/.test(key) }
38
38
  }
39
39
  },
40
40
 
@@ -43,12 +43,14 @@ module.exports = {
43
43
  type: 'cmd', regex: /^--?stats?$/ }
44
44
  },
45
45
 
46
+ isNegKey(key) { return /^(?:no|disable|exclude)[A-Z]/.test(key) },
47
+
46
48
  load(ctrlKeys = Object.keys(this.controls)) {
47
49
  const inputCtrlKeys = [].concat(ctrlKeys) // force array
48
50
 
49
51
  if (!cli.defaultsSet && !arguments.length) { // init all defaults on arg-less load()
50
52
  inputCtrlKeys.forEach(key => {
51
- const ctrl = this.controls[key] ; if (ctrl.mode || ctrl.type == 'legacy') return
53
+ const ctrl = this.controls[key] ; if (ctrl.mode || key.startsWith('legacy_')) return
52
54
  cli.config[key] ??= ctrl.defaultVal ?? ( ctrl.type == 'param' ? '' : false )
53
55
  })
54
56
  cli.defaultsSet = true
@@ -87,8 +89,8 @@ module.exports = {
87
89
  if (this.configFileKeyWhitelist && !this.configFileKeyWhitelist.includes(key))
88
90
  log.invalidConfigKey(key)
89
91
  return
90
- } else if (ctrl.type == 'legacy' && ctrl.replacedBy) {
91
- if (key.toLowerCase().includes('no') != ctrl.replacedBy.toLowerCase().includes('no'))
92
+ } else if (key.startsWith('legacy_') && ctrl.replacedBy) {
93
+ if (this.isNegKey(key) != this.isNegKey(ctrl.replacedBy))
92
94
  cli.config[ctrl.replacedBy] = !val // assign opposite val to current key
93
95
  else // assign direct val to current key
94
96
  cli.config[ctrl.replacedBy] = val
@@ -106,8 +108,8 @@ module.exports = {
106
108
  const ctrlKey = Object.keys(this.controls).find(key => this.controls[key]?.regex?.test(arg))
107
109
  if (!ctrlKey && cli.msgs) log.errorAndExit(`[${arg}] ${cli.msgs.error_notRecognized}.`)
108
110
  if (!inputCtrlKeys.includes(ctrlKey)) return // don't process env.args when load() specific keys
111
+ if (ctrlKey.startsWith('legacy_')) { log.argDoesNothing(arg) ; continue }
109
112
  const ctrl = this.controls[ctrlKey]
110
- if (ctrl.type == 'legacy') { log.argDoesNothing(arg) ; continue }
111
113
  if (ctrl.mode) // set cli.config.mode to mode name
112
114
  cli.config.mode = ctrlKey.replace(/mode$/i, '').toLowerCase()
113
115
  else { // init flag/param/cmd cli.config[ctrlKey] val
@@ -8,11 +8,15 @@
8
8
  "config": "https://github.com/adamlui/scss-to-css/blob/main/scss-to-css.config.mjs",
9
9
  "docs": "https://github.com/adamlui/scss-to-css/tree/main/docs",
10
10
  "github": "https://github.com/adamlui/scss-to-css",
11
- "jsdelivr": "https://cdn.jsdelivr.net/gh/adamlui/scss-to-css",
11
+ "jsdelivr": {
12
+ "jsutils": "https://cdn.jsdelivr.net/gh/adamlui/js-utils",
13
+ "pkg": "https://cdn.jsdelivr.net/gh/adamlui/scss-to-css"
14
+ },
12
15
  "npm": "https://www.npmjs.com/package/@adamlui/scss-to-css",
13
16
  "src": "https://github.com/adamlui/scss-to-css/tree/main/src"
14
17
  },
15
18
  "commitHashes": {
16
- "locales": "0da06d6"
19
+ "data": "92f4d1b",
20
+ "locales": "fd35208"
17
21
  }
18
22
  }
@@ -7,7 +7,7 @@ const fs = require('fs'),
7
7
  sass = require('sass')
8
8
 
9
9
  Object.assign(globalThis.api ??= {},
10
- require(`${ /[\\/]src(?:[\\/]|$)/i.test(__dirname) ? '../' : './data/' }package-data.json`))
10
+ require(`${ /[\\/]src(?:[\\/]|$)/i.test(__dirname) ? '..' : './data' }/package-data.json`))
11
11
  api.regex = {
12
12
  compile: /^(?:build|comp(?:ile|ress)|minify)$/i,
13
13
  findSCSS: /^(?:find|search)(?:scss)?$/i
package/docs/README.md CHANGED
@@ -29,12 +29,12 @@
29
29
 
30
30
  ### Recursively compile all SCSS files into minified CSS
31
31
 
32
- <a href="https://www.npmjs.com/package/@adamlui/scss-to-css">
32
+ <a href="https://npmstar.com/compare/@adamlui%2Fscss-to-css">
33
33
  <img height=31 src="https://img.shields.io/npm/dm/%40adamlui%2Fscss-to-css?logo=npm&color=af68ff&logoColor=white&labelColor=464646&style=for-the-badge"></a>
34
34
  <a href="#%EF%B8%8F-mit-license">
35
35
  <img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
36
- <a href="https://github.com/adamlui/js-utils/releases/tag/scss-to-css-2.3.1">
37
- <img height=31 src="https://img.shields.io/badge/Latest_Build-2.3.1-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
36
+ <a href="https://github.com/adamlui/js-utils/releases/tag/scss-to-css-2.4.0">
37
+ <img height=31 src="https://img.shields.io/badge/Latest_Build-2.4.0-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
38
38
  <a href="https://www.npmjs.com/package/@adamlui/scss-to-css?activeTab=code">
39
39
  <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>
40
40
  <a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_scss-to-css:src/scss-to-css.js">
@@ -80,7 +80,7 @@ $ scss-to-css
80
80
 
81
81
  Sample output:
82
82
 
83
- <img src="https://cdn.jsdelivr.net/gh/adamlui/scss-to-css@b74edea/node.js/media/images/screenshots/cli/scss-to-css-docs-cmd-output.png">
83
+ <img src="https://cdn.jsdelivr.net/gh/adamlui/scss-to-css@fe2867e/assets/images/screenshots/cli/scss-to-css-docs-cmd-output.png">
84
84
 
85
85
  **📝 Note:** Source maps are also generated by default unless `-S` or `--no-source-maps` is passed.
86
86
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamlui/scss-to-css",
3
- "version": "2.3.1",
3
+ "version": "2.4.0",
4
4
  "description": "Recursively compile all SCSS files into minified CSS",
5
5
  "author": {
6
6
  "name": "Adam Lui",
@@ -34,8 +34,8 @@
34
34
  "!docs/*/"
35
35
  ],
36
36
  "bin": {
37
- "scsstocss": "dist/cli/index.js",
38
- "scss-to-css": "dist/cli/index.js"
37
+ "scss-to-css": "dist/cli/index.js",
38
+ "scsstocss": "dist/cli/index.js"
39
39
  },
40
40
  "directories": {
41
41
  "lib": "./dist",
@@ -79,6 +79,7 @@
79
79
  "url": "https://github.com/adamlui/scss-to-css/issues"
80
80
  },
81
81
  "dependencies": {
82
+ "is-unicode-supported": "^2.1.0",
82
83
  "node-clipboardy": "^1.0.3",
83
84
  "sass": "^1.97.3"
84
85
  },