@@ -3,14 +3,28 @@ const fs = require('fs');
3
3
const path = require ( 'path' ) ;
4
4
5
5
const util = require ( './util' ) ;
6
-
7
6
util . packageDir ( ) ;
8
7
const PKG_DIR = process . cwd ( ) ;
9
8
10
9
const config = JSON . parse ( fs . readFileSync ( 'downstream_projects.json' ) ) ;
11
10
const pkgjson = JSON . parse ( fs . readFileSync ( 'package.json' ) ) ;
12
11
13
12
const DOWNSTREAMS_PATH = path . resolve ( PKG_DIR , 'downstream_projects' ) ;
13
+ const UPSTREAM_PKGS = ( process . env . UPSTREAM_PKGS || '' ) . split ( ',' ) . filter ( x => x ) . concat ( pkgjson . name ) ;
14
+
15
+ function forEachDownstream ( callback ) {
16
+ Object . keys ( config ) . forEach ( key => {
17
+ const projectPath = path . resolve ( DOWNSTREAMS_PATH , key ) ;
18
+ if ( ! fs . existsSync ( projectPath ) ) {
19
+ process . chdir ( DOWNSTREAMS_PATH ) ;
20
+ console . log ( 'cloning ' + giturl ) ;
21
+ util . _exec ( 'git clone ' + giturl + ' ' + key ) ;
22
+ }
23
+ process . chdir ( projectPath ) ;
24
+
25
+ callback ( ) ;
26
+ } ) ;
27
+ }
14
28
15
29
function makeWorkingCopy ( ) {
16
30
process . chdir ( PKG_DIR ) ;
@@ -26,43 +40,32 @@ function localPublish() {
26
40
util . _exec ( 'yalc publish' ) ;
27
41
}
28
42
29
- function cloneDownstreamProjects ( ) {
30
- Object . keys ( config ) . forEach ( key => {
31
- process . chdir ( DOWNSTREAMS_PATH ) ;
32
- const giturl = config [ key ] ;
33
- const projectPath = path . resolve ( DOWNSTREAMS_PATH , key ) ;
34
- if ( ! fs . existsSync ( projectPath ) ) {
35
- console . log ( 'cloning from ' + giturl ) ;
36
- util . _exec ( 'git clone ' + giturl + ' ' + key ) ;
37
- }
38
- process . chdir ( projectPath ) ;
39
- console . log ( 'cleaning ' + projectPath ) ;
40
- util . _exec ( 'git fetch origin' ) ;
41
- util . _exec ( 'git reset --hard origin/master' ) ;
42
- util . _exec ( 'git clean --force -d' ) ;
43
- } )
43
+ function getCleanMaster ( ) {
44
+ console . log ( 'cleaning ' + process . cwd ( ) ) ;
45
+ util . _exec ( 'git fetch origin' ) ;
46
+ util . _exec ( 'git reset --hard origin/master' ) ;
47
+ util . _exec ( 'git clean --force -d' ) ;
44
48
}
45
49
46
- function installDownstreamDeps ( ) {
47
- Object . keys ( config ) . forEach ( key => {
48
- const projectPath = path . resolve ( DOWNSTREAMS_PATH , key ) ;
49
- process . chdir ( projectPath ) ;
50
- util . _exec ( 'yarn install --check-files' ) ;
51
- util . _exec ( 'yalc add ' + pkgjson . name ) ;
52
- } )
50
+ function revertLocalChanges ( ) {
51
+ util . _exec ( 'git reset --hard origin/master' ) ;
52
+ util . _exec ( 'git clean --force -d' ) ;
53
53
}
54
54
55
- function testDownstreamDeps ( ) {
56
- Object . keys ( config ) . forEach ( key => {
57
- const projectPath = path . resolve ( DOWNSTREAMS_PATH , key ) ;
58
- process . chdir ( projectPath ) ;
59
- util . _exec ( 'yarn test' ) ;
60
- } )
55
+ function installDeps ( ) {
56
+ util . _exec ( 'yarn install --check-files' ) ;
57
+ UPSTREAM_PKGS . forEach ( upstream => util . _exec ( 'yalc add ' + upstream ) ) ;
61
58
}
62
59
60
+ function runTests ( ) {
61
+ util . _exec ( `UPSTREAM_PKGS="${ UPSTREAM_PKGS . join ( ',' ) } " npm test` ) ;
62
+ }
63
63
64
64
makeWorkingCopy ( ) ;
65
65
localPublish ( ) ;
66
- cloneDownstreamProjects ( ) ;
67
- installDownstreamDeps ( ) ;
68
- testDownstreamDeps ( ) ;
66
+
67
+ forEachDownstream ( getCleanMaster ) ;
68
+ forEachDownstream ( installDeps ) ;
69
+ forEachDownstream ( runTests ) ;
70
+ forEachDownstream ( revertLocalChanges ) ;
71
+
0 commit comments