|
| 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