diff options
Diffstat (limited to 'scripts/frontend/frontend_script_utils.js')
-rw-r--r-- | scripts/frontend/frontend_script_utils.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/scripts/frontend/frontend_script_utils.js b/scripts/frontend/frontend_script_utils.js new file mode 100644 index 00000000000..2c06747255c --- /dev/null +++ b/scripts/frontend/frontend_script_utils.js @@ -0,0 +1,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); + }, +}; |