forked from psychobolt/react-pie-menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
project-list.js
34 lines (28 loc) · 992 Bytes
/
project-list.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const fs = require('fs');
const path = require('path');
const { isMatch } = require('micromatch');
const { getPackagesSync } = require('@lerna/project');
const ROOT_RESOLVE = path.resolve();
const PACKAGES = (process.env.PACKAGES || `${fs.readFileSync('.projectlist', 'utf8')}`).trim();
const EXCLUDES = [];
const INCLUDES = [];
if (PACKAGES) {
Array.prototype.push.apply(INCLUDES, PACKAGES.split(/\s*(?:,|\n|\s)+\s*/).filter(pattern => {
if (pattern.startsWith('!')) {
EXCLUDES.push(pattern.substring(1));
return false;
}
return true;
}));
}
const match = (strings, pattern) => strings.some(string => isMatch(string, pattern));
module.exports = {
EXCLUDES,
INCLUDES,
projectList: getPackagesSync().filter(pkg => {
const { name, location } = pkg;
const strings = [name, location.replace(`${ROOT_RESOLVE}/`, '')];
return INCLUDES.some(pattern => match(strings, pattern))
&& !EXCLUDES.some(pattern => match(strings, pattern));
}),
};