Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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)
})
})
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;
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);
});
}