| 1 | #!/usr/bin/env node |
| 2 | |
| 3 | 'use strict'; |
| 4 | |
| 5 | const {exec} = require('child-process-promise'); |
| 6 | const {join} = require('path'); |
| 7 | const {tmpdir} = require('os'); |
| 8 | const {logPromise} = require('../utils'); |
| 9 | const theme = require('../theme'); |
| 10 | |
| 11 | const run = async ({commit, cwd, tempDirectory}) => { |
| 12 | const directory = `react-${commit}`; |
| 13 | const temp = tmpdir(); |
| 14 | |
| 15 | if (tempDirectory !== join(tmpdir(), directory)) { |
| 16 | throw Error(`Unexpected temporary directory "${tempDirectory}"`); |
| 17 | } |
| 18 | |
| 19 | await exec(`rm -rf ${directory}`, {cwd: temp}); |
| 20 | await exec(`git archive --format=tar --output=${temp}/react.tgz ${commit}`, { |
| 21 | cwd, |
| 22 | }); |
| 23 | await exec(`mkdir ${directory}`, {cwd: temp}); |
| 24 | await exec(`tar -xf ./react.tgz -C ./${directory}`, {cwd: temp}); |
| 25 | }; |
| 26 | |
| 27 | module.exports = async params => { |
| 28 | return logPromise( |
| 29 | run(params), |
| 30 | theme`Copying React repo to temporary directory ({path ${params.tempDirectory}})` |
| 31 | ); |
| 32 | }; |