mirror of
https://github.com/primer/css.git
synced 2025-01-01 18:53:34 +03:00
Some docs
This commit is contained in:
parent
08afa167df
commit
bfe72b931f
@ -6,29 +6,41 @@ const glob = require("glob")
|
||||
var selectors, classnames = null
|
||||
const classRegex = /class="([^"]+)"/ig
|
||||
|
||||
// Find unique selectors from the cssstats selector list
|
||||
function uniqueSelectors(s) {
|
||||
return s.filter(s => {
|
||||
// remove any selectors with hover states
|
||||
return s.match(/^\.[a-z\-_\s\.]+$/ig)
|
||||
}).map(s => {
|
||||
s = s.map(s => {
|
||||
// split multi-selectors into last class used .foo .bar .baz
|
||||
return s.split(" ").pop()
|
||||
}).filter(s => {
|
||||
// remove any selector that aren't just regular classnames eg. ::hover [type]
|
||||
return s.match(/^\.[a-z\-_]+$/ig)
|
||||
})
|
||||
|
||||
// return only the unique selectors
|
||||
return [...new Set(s)]
|
||||
}
|
||||
|
||||
// From the given glob sources array, read the files and return found classnames
|
||||
function documentedClassnames(sources) {
|
||||
var cn = []
|
||||
sources.forEach( f => {
|
||||
glob.sync(f).forEach( g => {
|
||||
var match = null
|
||||
|
||||
// While we match a classRegex in the source
|
||||
while ((match = classRegex.exec(fs.readFileSync(g).toString())) != null) {
|
||||
|
||||
// Get the matched classnames "..." and split by space into classes
|
||||
cn = cn.concat(match[1].split(" "))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// return only the unique classnames
|
||||
return [...new Set(cn)]
|
||||
}
|
||||
|
||||
// Before all the tests get the selectors and classnames
|
||||
test.before(async t => {
|
||||
selectors = await uniqueSelectors(css.cssstats.selectors.values)
|
||||
classnames = await documentedClassnames([
|
||||
|
Loading…
Reference in New Issue
Block a user