Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// @flow
import ignore from 'ignore';
const ign = ignore();
ignore({});
ignore({ ignorecase: false });
// $ExpectError
ignore({ foo: true });
ign.add('.abc/*');
ign.add(['.abc/*', '!.abc/d/']);
ign.add('.abc/*').add('!.abc/d/');
ign.add(ignore());
ign.add([ignore(), ignore()]);
ign.add(ignore()).add(ignore());
// $ExpectError
ign.add(666);
// $ExpectError
*
*/
import * as fs from "fs";
import * as path from "path";
import ignore from 'ignore'
const colors = require('colors/safe');
import FrameworkHelper from "./helper/framework.helper";
import FileUtil from "./helper/file.util";
const parseIgnore = require('parse-gitignore');
let ignoreFiles = parseIgnore(fs.readFileSync(process.cwd() + '/' + '.gitignore'));
const ig = ignore().add(ignoreFiles);
function compile(filename: string, filePath: string, options: { projectType: string; program: any }) {
const isDir = fs.lstatSync(filePath).isDirectory();
const isFile = !isDir;
const lines: string[] = [];
// Do not show these regardless.
if (filename) {
let filteredPath = ig.filter([filename]);
if (filteredPath.length === 0) {
return lines;
}
}
if (isFile) {
async loadIgnoreList() {
const ignoreFilePath = path.join(this.path, SHOUTEM_IGNORE_FILE_NAME);
const shoutemIgnores = readLinesInFile(ignoreFilePath);
// no need to remove comments, 'ignores' does that for us
return ignore().add(shoutemIgnores);
}
}
function makeFilter(ignoreFile) {
const ignoreList = fs.readFileSync(ignoreFile, 'utf8').split(/\r?\n/)
const filter = ignore().add(ignoreList)
return vinyl => !filter.ignores(vinyl.path)
}
knit?: boolean
files?: boolean
}
) => {
const { workingDir } = options
const copyFromDir = options.workingDir
const storePackageStoreDir = join(
getStorePackagesDir(),
pkg.name,
pkg.version
)
const ignoreFileContent = readIgnoreFile(workingDir)
const ignoreRule = ignore().add(ignoreFileContent)
const npmList: string[] = await npmPacklist({ path: workingDir })
const filesToCopy = npmList.filter(f => !ignoreRule.ignores(f))
if (options.files) {
console.log('Files included in published content:')
filesToCopy.forEach(f => {
console.log(`- ${f}`)
})
console.log(`Total ${filesToCopy.length} files.`)
}
const copyFilesToStore = async () => {
await fs.remove(storePackageStoreDir)
return Promise.all(
filesToCopy
.sort()
.map(relPath =>
copyFile(
export function matchesRules(relativePath: string, rules: Array): boolean {
const fileName = Path.basename(relativePath)
const ignoreRules = []
for (const rule of rules) {
if (!(rule instanceof RegExp)) {
ignoreRules.push(rule)
continue
}
if (rule.test(relativePath) || rule.test(fileName)) {
return true
}
}
if (ignoreRules.length && createIgnore().add(ignoreRules).filter([relativePath, fileName]).length !== 2) {
return true
}
return false
}
function cloneTemplate(templatePath: string, appPath: string) {
const ig = ignore()
const defaultIgnore = ['node_modules', 'dist', 'yarn.*', '.git', '.template-ignore', '.cache-loader']
ig.add(defaultIgnore)
const templateIgnorePath = path.join(templatePath, '.template-ignore')
if (fs.existsSync(templateIgnorePath)) {
ig.add(fs.readFileSync(templateIgnorePath).toString())
}
fs.copySync(templatePath, appPath, {
overwrite: false,
errorOnExist: false,
dereference: true,
filter: src => {
const relativePath = path.relative(templatePath, src)
if (relativePath === '') {
return true
public static isBlacklisted(node: CodeMapNode, blacklist: Array, type: BlacklistType): boolean {
if (blacklist.length === 0) {
return false
}
const ig = ignore().add(blacklist.filter(b => b.type === type).map(ex => CodeMapHelper.transformPath(ex.path)))
return ig.ignores(CodeMapHelper.transformPath(node.path))
}
return host => {
if (!host.exists('.gitignore')) {
return;
}
const ig = ignore();
ig.add(host.read('.gitignore').toString());
if (!ig.ignores('bazel-out')) {
const content = `${host
.read('.gitignore')!
.toString('utf-8')
.trimRight()}\nbazel-*\n`;
host.overwrite('.gitignore', content);
}
};
}