Skip to content

Commit 6c12618

Browse files
feat(downstream): enable yalc add of grandparent upstream (core -> angular -> sample-app-angular)
1 parent 96d813d commit 6c12618

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

test_downstream_projects.js

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,28 @@ const fs = require('fs');
33
const path = require('path');
44

55
const util = require('./util');
6-
76
util.packageDir();
87
const PKG_DIR = process.cwd();
98

109
const config = JSON.parse(fs.readFileSync('downstream_projects.json'));
1110
const pkgjson = JSON.parse(fs.readFileSync('package.json'));
1211

1312
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+
}
1428

1529
function makeWorkingCopy() {
1630
process.chdir(PKG_DIR);
@@ -26,43 +40,32 @@ function localPublish() {
2640
util._exec('yalc publish');
2741
}
2842

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');
4448
}
4549

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');
5353
}
5454

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));
6158
}
6259

60+
function runTests() {
61+
util._exec(`UPSTREAM_PKGS="${UPSTREAM_PKGS.join(',')}" npm test`);
62+
}
6363

6464
makeWorkingCopy();
6565
localPublish();
66-
cloneDownstreamProjects();
67-
installDownstreamDeps();
68-
testDownstreamDeps();
66+
67+
forEachDownstream(getCleanMaster);
68+
forEachDownstream(installDeps);
69+
forEachDownstream(runTests);
70+
forEachDownstream(revertLocalChanges);
71+

0 commit comments

Comments
 (0)