summaryrefslogtreecommitdiff
path: root/scripts/frontend/frontend_script_utils.js
blob: 2c06747255c311e88799933d66fb22b2f026f4be (plain)
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
/* eslint import/no-commonjs: "off" */
const execFileSync = require('child_process').execFileSync;

const exec = (command, args) => {
  const options = {
    cwd: process.cwd(),
    env: process.env,
    encoding: 'utf-8',
  };
  return execFileSync(command, args, options);
};

const execGitCmd = args =>
  exec('git', args)
    .trim()
    .toString()
    .split('\n');

module.exports = {
  getStagedFiles: fileExtensionFilter => {
    const gitOptions = [
      'diff',
      '--name-only',
      '--cached',
      '--diff-filter=ACMRTUB',
    ];
    if (fileExtensionFilter) gitOptions.push(...fileExtensionFilter);
    return execGitCmd(gitOptions);
  },
};