1
1
mirror of https://github.com/primer/css.git synced 2024-12-20 04:32:21 +03:00
css/script/get-packages

36 lines
929 B
Plaintext
Raw Normal View History

2017-10-10 21:41:41 +03:00
#!/usr/bin/env node
const fs = require('fs')
const globby = require('globby')
const {join} = require('path')
2017-10-10 21:41:41 +03:00
const getPackages = (debug = false) => {
2017-10-10 21:41:41 +03:00
const lernaConfig = require('../lerna.json')
2019-01-03 08:51:23 +03:00
const packageGlobs = lernaConfig.packages.concat('!**/*.md')
2017-10-10 21:41:41 +03:00
return globby(packageGlobs)
.then(packagePaths => {
2019-01-03 08:51:23 +03:00
if (debug) {
console.warn(`Filtering ${packagePaths.length} paths...`)
}
2017-10-10 21:41:41 +03:00
return packagePaths.filter(pkg => {
try {
2018-12-22 02:17:00 +03:00
require.resolve(join('..', pkg, 'package.json'))
2019-01-03 08:51:23 +03:00
return true
2017-10-10 21:41:41 +03:00
} catch (error) {
if (debug) {
console.warn(`No package.json in ${pkg}: ${error}`)
2017-10-10 21:41:41 +03:00
}
2019-01-03 08:51:23 +03:00
return false
2017-10-10 21:41:41 +03:00
}
})
})
}
if (module.parent) {
module.exports = getPackages
} else {
getPackages(true).then(packages => {
console.warn('%d packages:', packages.length)
packages.forEach(pkg => console.log(pkg))
})
}