aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/build/lint-vars.js
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2018-10-19 11:18:28 +0200
committerMario Vavti <mario@mariovavti.com>2018-10-19 11:18:28 +0200
commitfa9e9510e5d993d183feb942fe74be5fdd07f5cf (patch)
tree41fec09f527a9346e043b8099b458a97d81b03ed /vendor/twbs/bootstrap/build/lint-vars.js
parent32de123db0ac526795a237ff46885fe8a332cbc0 (diff)
parent06b3ad1071c755757555baf941e2c0f446f97b21 (diff)
downloadvolse-hubzilla-fa9e9510e5d993d183feb942fe74be5fdd07f5cf.tar.gz
volse-hubzilla-fa9e9510e5d993d183feb942fe74be5fdd07f5cf.tar.bz2
volse-hubzilla-fa9e9510e5d993d183feb942fe74be5fdd07f5cf.zip
Merge branch '3.8RC'3.8
Diffstat (limited to 'vendor/twbs/bootstrap/build/lint-vars.js')
-rw-r--r--vendor/twbs/bootstrap/build/lint-vars.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/vendor/twbs/bootstrap/build/lint-vars.js b/vendor/twbs/bootstrap/build/lint-vars.js
new file mode 100644
index 000000000..1b8d71cc6
--- /dev/null
+++ b/vendor/twbs/bootstrap/build/lint-vars.js
@@ -0,0 +1,82 @@
+#!/usr/bin/env node
+
+/*!
+ * Script to find unused Sass variables.
+ * Copyright 2017-2018 The Bootstrap Authors
+ * Copyright 2017-2018 Twitter, Inc.
+ * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
+ */
+
+'use strict'
+
+const fs = require('fs')
+const path = require('path')
+const glob = require('glob')
+
+// Blame TC39... https://github.com/benjamingr/RegExp.escape/issues/37
+function regExpQuote(str) {
+ return str.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&')
+}
+
+let globalSuccess = true
+
+function findUnusedVars(dir) {
+ if (!(fs.existsSync(dir) && fs.statSync(dir).isDirectory())) {
+ console.log(`"${dir}": Not a valid directory!`)
+ process.exit(1)
+ }
+
+ console.log(`Finding unused variables in "${dir}"...`)
+
+ // A variable to handle success/failure message in this function
+ let unusedVarsFound = false
+
+ // Array of all Sass files' content
+ const sassFiles = glob.sync(path.join(dir, '**/*.scss'))
+ // String of all Sass files' content
+ let sassFilesString = ''
+
+ sassFiles.forEach((file) => {
+ sassFilesString += fs.readFileSync(file, 'utf8')
+ })
+
+ // Array of all Sass variables
+ const variables = sassFilesString.match(/(^\$[a-zA-Z0-9_-]+[^:])/gm)
+
+ console.log(`Found ${variables.length} total variables.`)
+
+ // Loop through each variable
+ variables.forEach((variable) => {
+ const re = new RegExp(regExpQuote(variable), 'g')
+ const count = (sassFilesString.match(re) || []).length
+
+ if (count === 1) {
+ console.log(`Variable "${variable}" is not being used.`)
+ unusedVarsFound = true
+ globalSuccess = false
+ }
+ })
+
+ if (unusedVarsFound === false) {
+ console.log(`No unused variables found in "${dir}".`)
+ }
+}
+
+function main(args) {
+ if (args.length < 1) {
+ console.log('Wrong arguments!')
+ console.log('Usage: lint-vars.js folder [, folder2...]')
+ process.exit(1)
+ }
+
+ args.forEach((arg) => {
+ findUnusedVars(arg)
+ })
+
+ if (globalSuccess === false) {
+ process.exit(1)
+ }
+}
+
+// The first and second args are: path/to/node script.js
+main(process.argv.slice(2))