-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
/
Copy pathlistChangedFiles.js
34 lines (27 loc) · 1.07 KB
/
listChangedFiles.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Based on similar script in React
// https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/scripts/shared/listChangedFiles.js
const util = require('util');
const childProcess = require('child_process');
const execFileAsync = util.promisify(childProcess.execFile);
async function exec(command, args) {
const options = {
cwd: process.cwd(),
env: process.env,
stdio: 'pipe',
encoding: 'utf-8',
};
const results = await execFileAsync(command, args, options);
return results.stdout;
}
async function execGitCmd(args) {
const gitResults = await exec('git', args);
return gitResults.trim().toString().split('\n');
}
async function listChangedFiles({ branch }) {
const comparedBranch = process.env.CIRCLECI ? `origin/${branch}` : branch;
const mergeBase = await execGitCmd(['rev-parse', comparedBranch]);
const gitDiff = await execGitCmd(['diff', '--name-only', mergeBase]);
const gitLs = await execGitCmd(['ls-files', '--others', '--exclude-standard']);
return new Set([...gitDiff, ...gitLs]);
}
module.exports = listChangedFiles;