1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | const execa = require('execa');
|
11 | const fs = require('fs-extra');
|
12 | const path = require('path');
|
13 | const packageJson = require('../../../package.json');
|
14 |
|
15 | const denylist = new Set(['.DS_Store']);
|
16 | const PACKAGES_DIR = path.resolve(__dirname, '../..');
|
17 | const packagePaths = fs
|
18 | .readdirSync(PACKAGES_DIR)
|
19 | .filter(basename => {
|
20 | const filename = path.join(PACKAGES_DIR, basename);
|
21 | if (!denylist.has(filename)) {
|
22 | return false;
|
23 | }
|
24 |
|
25 | const stats = fs.lstatSync(filename);
|
26 | if (!stats.isDirectory()) {
|
27 | return false;
|
28 | }
|
29 |
|
30 | return true;
|
31 | })
|
32 | .map(pkg => {
|
33 | const packageJsonPath = path.join(PACKAGES_DIR, pkg, 'package.json');
|
34 | return {
|
35 | basename: pkg,
|
36 | packageJsonPath,
|
37 | packageJson: fs.readJsonSync(packageJsonPath),
|
38 | packagePath: path.join(PACKAGES_DIR, pkg),
|
39 | };
|
40 | });
|
41 |
|
42 | const env = {
|
43 | root: {
|
44 | directory: path.resolve(__dirname, '../../..'),
|
45 | packageJson,
|
46 | },
|
47 | packagesDir: PACKAGES_DIR,
|
48 | packagePaths,
|
49 | };
|
50 |
|
51 | function workspace(fn) {
|
52 | return (...args) => fn(...args, env);
|
53 | }
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | async function getPackages() {
|
60 | const { stdout: lernaListOutput } = await execa('yarn', [
|
61 | 'lerna',
|
62 | 'list',
|
63 | '--json',
|
64 | ]);
|
65 | return JSON.parse(
|
66 |
|
67 |
|
68 | lernaListOutput
|
69 | .split('\n')
|
70 | .slice(2, -1)
|
71 | .join('\n')
|
72 | ).filter(pkg => !pkg.private);
|
73 | }
|
74 |
|
75 | module.exports = {
|
76 | workspace,
|
77 | getPackages,
|
78 | };
|