Skip to content

Commit c8790a8

Browse files
feat(test): add test_downstream_projects script
1 parent 2cd3226 commit c8790a8

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"modify_sourcemap_paths": "./modify_sourcemap_paths.js",
2323
"release": "./release.js",
2424
"show_changelog": "./show_changelog.js",
25+
"test_downstream_projects": "./test_downstream_projects.js",
2526
"util": "./util.js"
2627
},
2728
"dependencies": {

test_downstream_projects.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env node
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
const util = require('./util');
6+
7+
util.packageDir();
8+
const PKG_DIR = process.cwd();
9+
10+
const config = JSON.parse(fs.readFileSync('downstream_projects.json'));
11+
const pkgjson = JSON.parse(fs.readFileSync('package.json'));
12+
13+
const DOWNSTREAMS_PATH = path.resolve(PKG_DIR, 'downstream_projects');
14+
15+
function makeWorkingCopy() {
16+
process.chdir(PKG_DIR);
17+
if (!fs.existsSync(DOWNSTREAMS_PATH)) {
18+
console.log('making downstream_projects working directory');
19+
fs.mkdirSync(DOWNSTREAMS_PATH);
20+
}
21+
}
22+
23+
function localPublish() {
24+
process.chdir(PKG_DIR);
25+
console.log('Publishing using yalc...');
26+
util._exec('yalc publish');
27+
}
28+
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+
})
44+
}
45+
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+
})
53+
}
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+
})
61+
}
62+
63+
64+
makeWorkingCopy();
65+
localPublish();
66+
cloneDownstreamProjects();
67+
installDownstreamDeps();
68+
testDownstreamDeps();

0 commit comments

Comments
 (0)