Skip to content

Commit

Permalink
feat(test): add test_downstream_projects script
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen committed Dec 26, 2017
1 parent 2cd3226 commit c8790a8
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"modify_sourcemap_paths": "./modify_sourcemap_paths.js",
"release": "./release.js",
"show_changelog": "./show_changelog.js",
"test_downstream_projects": "./test_downstream_projects.js",
"util": "./util.js"
},
"dependencies": {
Expand Down
68 changes: 68 additions & 0 deletions test_downstream_projects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');

const util = require('./util');

util.packageDir();
const PKG_DIR = process.cwd();

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

const DOWNSTREAMS_PATH = path.resolve(PKG_DIR, 'downstream_projects');

function makeWorkingCopy() {
process.chdir(PKG_DIR);
if (!fs.existsSync(DOWNSTREAMS_PATH)) {
console.log('making downstream_projects working directory');
fs.mkdirSync(DOWNSTREAMS_PATH);
}
}

function localPublish() {
process.chdir(PKG_DIR);
console.log('Publishing using yalc...');
util._exec('yalc publish');
}

function cloneDownstreamProjects() {
Object.keys(config).forEach(key => {
process.chdir(DOWNSTREAMS_PATH);
const giturl = config[key];
const projectPath = path.resolve(DOWNSTREAMS_PATH, key);
if (!fs.existsSync(projectPath)) {
console.log('cloning from ' + giturl);
util._exec('git clone '+ giturl + ' ' + key);
}
process.chdir(projectPath);
console.log('cleaning ' + projectPath);
util._exec('git fetch origin');
util._exec('git reset --hard origin/master');
util._exec('git clean --force -d');
})
}

function installDownstreamDeps() {
Object.keys(config).forEach(key => {
const projectPath = path.resolve(DOWNSTREAMS_PATH, key);
process.chdir(projectPath);
util._exec('yarn install --check-files');
util._exec('yalc add ' + pkgjson.name);
})
}

function testDownstreamDeps() {
Object.keys(config).forEach(key => {
const projectPath = path.resolve(DOWNSTREAMS_PATH, key);
process.chdir(projectPath);
util._exec('yarn test');
})
}


makeWorkingCopy();
localPublish();
cloneDownstreamProjects();
installDownstreamDeps();
testDownstreamDeps();

0 comments on commit c8790a8

Please sign in to comment.