mirror of
https://github.com/primer/css.git
synced 2024-12-25 07:03:35 +03:00
68 lines
1.9 KiB
JavaScript
Executable File
68 lines
1.9 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
const fse = require('fs-extra')
|
|
const globby = require('globby')
|
|
|
|
const DEP_FIELDS = [
|
|
'dependencies',
|
|
]
|
|
|
|
const parseImports = filename => {
|
|
return fse.readFile(filename, 'utf8')
|
|
.then(scss => {
|
|
const matches = scss.match(/\@import\s+"[-a-z]+\/index\.scss"/g)
|
|
return matches
|
|
? Array.from(matches).map(stmt => stmt.match(/"([-a-z]+)\//)[1])
|
|
: []
|
|
})
|
|
}
|
|
|
|
globby('modules/primer-*')
|
|
.then(paths => {
|
|
return paths.reduce((modules, path) => {
|
|
const pkg = require(`../${path}/package.json`)
|
|
if (pkg.dependencies) {
|
|
pkg.path = path
|
|
modules.push(pkg)
|
|
} else {
|
|
console.warn('%s: no dependencies', pkg.name)
|
|
}
|
|
return modules
|
|
}, [])
|
|
})
|
|
.then(modules => {
|
|
console.log('⏱ checking %d modules...', modules.length)
|
|
const maxNameLength = modules.reduce((len, {name}) => {
|
|
return Math.max(len, name.length)
|
|
}, 0)
|
|
const map = new Map()
|
|
const tasks = []
|
|
modules.forEach(mod => map.set(mod.name, mod))
|
|
modules.forEach(mod => {
|
|
const deps = Object.keys(mod.dependencies)
|
|
.filter(key => key.indexOf('primer-') === 0)
|
|
tasks.push(
|
|
parseImports(`${mod.path}/index.scss`)
|
|
.then(imports => {
|
|
console.warn('📦 %s: %s%d dependencies, %d import(s)',
|
|
mod.name, ' '.repeat(maxNameLength - mod.name.length),
|
|
deps.length, imports.length)
|
|
imports.forEach(imported => {
|
|
if (!deps.includes(imported)) {
|
|
throw new Error(
|
|
`❌ ${mod.name} imports ${imported}, but is missing a dependency`
|
|
)
|
|
}
|
|
})
|
|
})
|
|
)
|
|
})
|
|
return Promise.all(tasks)
|
|
})
|
|
.catch(error => {
|
|
console.error(error)
|
|
process.exit(1)
|
|
})
|
|
.then(matches => {
|
|
console.warn('✅ checked %d matching version dependencies', matches.length)
|
|
})
|