@@ -3,9 +3,15 @@ const fs = require('fs');
3
3
const path = require ( 'path' ) ;
4
4
const tmp = require ( 'tmp' ) ;
5
5
const shelljs = require ( 'shelljs' ) ;
6
+ const _ = require ( 'lodash' ) ;
6
7
const IS_TRAVIS = ! ! process . env . TRAVIS ;
7
8
8
9
const yargs = require ( 'yargs' )
10
+ . option ( 'group' , {
11
+ alias : 'g' ,
12
+ default : 'all' ,
13
+ description : 'the group of projects to test (from downstream_projects.json "group" key)' ,
14
+ } )
9
15
. option ( 'workspace' , {
10
16
alias : 'ws' ,
11
17
description : 'use yarn workspace to save space' ,
@@ -24,19 +30,39 @@ const util = require('./util');
24
30
util . packageDir ( ) ;
25
31
const PKG_DIR = process . cwd ( ) ;
26
32
27
- const config = JSON . parse ( fs . readFileSync ( 'downstream_projects.json' ) ) ;
28
33
const pkgjson = JSON . parse ( fs . readFileSync ( 'package.json' ) ) ;
29
- const projects = config . projects || config ;
30
- const nohoist = ( config . projects && config . nohoist ) || [ ] ;
31
-
32
34
const DOWNSTREAM_PKGS = ( process . env . DOWNSTREAM_PKGS || '' ) . split ( ',' ) . filter ( x => x ) ;
33
- const UPSTREAM_PKGS = ( process . env . UPSTREAM_PKGS || '' ) . split ( ',' ) . filter ( x => x ) ;
34
35
35
36
const TEMP = tmp . dirSync ( ) ;
36
37
const TEMP_DIR = TEMP . name ;
37
38
const TEMP_DOWNSTREAM_CACHE = path . resolve ( TEMP_DIR , '.downstream_cache' ) ;
38
39
const DOWNSTREAM_CACHE = path . resolve ( PKG_DIR , '.downstream_cache' ) ;
39
40
41
+ function parseConfig ( ) {
42
+ const config = JSON . parse ( fs . readFileSync ( 'downstream_projects.json' ) ) ;
43
+ const configBlock = _ . toPairs ( config . projects || config ) ;
44
+
45
+ // Object values are groups (nested config). string values are github url or local file path
46
+ const isGroup = ( [ key , value ] ) => typeof value === 'object' ;
47
+ const groupsAsPairs = configBlock . filter ( pair => isGroup ( pair ) ) ;
48
+ const ungroupedProjectsAsPairs = configBlock . filter ( pair => ! isGroup ( pair ) ) ;
49
+
50
+ const allGroupedProjectPairs = _ . flatten ( groupsAsPairs . map ( ( [ name , groupedProjects ] ) => _ . toPairs ( groupedProjects ) ) ) ;
51
+
52
+ const groups = _ . fromPairs ( groupsAsPairs ) ;
53
+ groups . all = _ . fromPairs ( allGroupedProjectPairs . concat ( ungroupedProjectsAsPairs ) ) ;
54
+
55
+ const projects = groups [ yargs . argv . group ] ;
56
+ if ( ! projects ) {
57
+ throw new Error ( `Attempting to run tests for a group named ${ yargs . argv . group } , but no matching group was found in downstream_projects.json` ) ;
58
+ }
59
+
60
+ const nohoist = ( config . projects && config . nohoist ) || [ ] ;
61
+ return { projects, nohoist } ;
62
+ }
63
+
64
+ const { projects, nohoist } = parseConfig ( ) ;
65
+
40
66
function makeDownstreamCache ( ) {
41
67
if ( ! fs . existsSync ( DOWNSTREAM_CACHE ) ) {
42
68
console . log ( ' ===> making .downstream_cache working directory <===' ) ;
0 commit comments