How to use staged-git-files - 5 common examples

To help you get started, we’ve selected a few staged-git-files examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github umijs / father / packages / father / src / preCommit.ts View on Github external
export async function check() {
  const list: string[] = (await sgf())
    .map((file: { filename: string }) => file.filename)
    .filter((filename: string) => /^(src|tests|examples)/.test(filename))
    .filter((filename: string) => /\.(ts|js|tsx|jsx)$/.test(filename))

    // Only keep exist files
    .map((filename: string) => {
      const filePath = join(cwd, filename);
      return existsSync(filePath) ? filePath : null;
    })
    .filter((filePath: string | null) => filePath);

  if (!list.length) {
    return;
  }

  // Prettier
github umijs / father / src / preCommit.ts View on Github external
export async function check() {
  const list: string[] = (await sgf())
    .map((file: { filename: string }) => file.filename)
    .filter((filename: string) => /^(src|tests)/.test(filename))
    .filter((filename: string) => /\.(ts|js|tsx|jsx)$/.test(filename))

    // Only keep exist files
    .map((filename: string) => {
      const filePath = join(cwd, filename);
      return existsSync(filePath) ? filePath : null;
    })
    .filter((filePath: string | null) => filePath);

  if (!list.length) {
    return;
  }

  // Prettier
github x-orpheus / elint / src / walker / stage.js View on Github external
function getStagedFileList (patterns, ignorePatterns) {
  const baseDir = getBaseDir()

  // 如果 baseDir 根本不存在 sgf 会抛出异常
  if (!fs.existsSync(baseDir)) {
    return Promise.resolve([])
  }

  sgf.cwd = baseDir

  return new Promise(resolve => {
    sgf((err, result) => {
      if (err) {
        debug('staged-git-files error: %o', err)
        return resolve([])
      }

      const fileList = result
        .filter(item => item.status !== 'Deleted') // 过滤已删除的文件
        .filter(item => match(item.filename, patterns, ignorePatterns))
        .map(item => item.filename)

      resolve(fileList)
    })
  })
github floatdrop / vinyl-git / sources / staged.js View on Github external
module.exports = function (options) {
    var stream = through.obj();

    sgf.cwd = process.cwd();

    sgf(function(err, results) {
        if (err) { return stream.emit('error', err); }

        var files = results.map(function (file) {
            return file.filename;
        });

        if (files.length === 0) {
            return stream.end();
        }

        fs.src(files, options).pipe(stream);
    });

    return stream;
github Tencent / feflow / lib / internal / lint / linter.js View on Github external
function getStageFiles(cb) {
  const gitDir = findParentDir.sync(process.cwd(), '.git');
  sgf.cwd = gitDir
  let stageFiles = [];
  sgf('ACM', (err, files) => {
    if (files) {
      stageFiles = files.map(item => {
        return item.filename
      })
    }
    cb(err, stageFiles);
  });
}

staged-git-files

get a list of staged git files and their status

BSD-2-Clause
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis

Popular staged-git-files functions