Ejemplo n.º 1
0
 return (globs || []).some(glob => {
   try {
     const globStat = lstatSync(join(configDir, glob))
     const newGlob = glob.length === 0 ? '.' : glob
     const globToMatch = globStat.isDirectory() ? `${glob}/**` : glob
     return minimatch(filePath, globToMatch, { matchBase: true })
   } catch (error) {
     // Out of errors that lstat provides, EACCES and ENOENT are the
     // most likely. For both cases, run the match with the raw glob
     // and return the result.
     return minimatch(filePath, glob, { matchBase: true })
   }
 })
function checkDictonariesInstalled(): Promise<any> {
    let dictionariesRootPath = readDictionaryConfig();
    try {
        let isDirectory = fs.lstatSync(dictionariesRootPath);
        if (isDirectory) {
            return Promise.resolve(true);
        }
    }
    catch (err) {
       // Directory does not exist 
    }
    return downloadManager.downloadAndInstallServer(path.resolve(dictionariesRootPath, ".."), readUrlConfig());
}
Ejemplo n.º 3
0
 private add(changes: IPendingChange[], newChange: IPendingChange, ignoreFolders: boolean) {
     // Deleted files won't exist, but we still include them in the results
     if (ignoreFolders && fs.existsSync(newChange.localItem)) {
         // check to see if the local item is a file or folder
         const f: string = newChange.localItem;
         const stats: any = fs.lstatSync(f);
         if (stats.isDirectory()) {
             // It's a directory/folder and we don't want those
             return;
         }
     }
     changes.push(newChange);
 }
Ejemplo n.º 4
0
function copyTree(sourcePath: string, destPath: string): void {
    if (!fs.existsSync(sourcePath))
        throw "Copy tree source doesn't exist: " + sourcePath;
    if (!fs.lstatSync(sourcePath).isDirectory()) // File
        return copyFile(sourcePath, destPath);

    // Directory
    if (!fs.existsSync(destPath))
        mkdirParentsSync(destPath);
    else if (!fs.lstatSync(destPath).isDirectory())
        throw "Can't copy a directory onto a file: " + sourcePath + " " + destPath;

    var filesInDir = fs.readdirSync(sourcePath);
    for (var i = 0; i < filesInDir.length; i++) {
        var filename = filesInDir[i];
        var file = sourcePath + "/" + filename;
        if (fs.lstatSync(file).isDirectory())
            copyTree(file, destPath + "/" + filename);
        else
            copyFile(file, destPath);
    }
}
Ejemplo n.º 5
0
    static tryCreateProgram(project?: string): Program {
        if (typeof project === 'string') {
            try {
                if (lstatSync(project).isDirectory()) {
                    project = join(project, 'tsconfig.json');
                }

                return TslintPreprocessor.createProgram(project);
            } catch (e) {

            }
        }
    }
Ejemplo n.º 6
0
Archivo: Utils.ts Proyecto: Volune/jest
export const copyDir = (src: string, dest: string) => {
  const srcStat = fs.lstatSync(src);
  if (srcStat.isDirectory()) {
    if (!fs.existsSync(dest)) {
      fs.mkdirSync(dest);
    }
    fs.readdirSync(src).map(filePath =>
      copyDir(path.join(src, filePath), path.join(dest, filePath)),
    );
  } else {
    fs.writeFileSync(dest, fs.readFileSync(src));
  }
};
Ejemplo n.º 7
0
 const deleteFolderRecursive = async (path: string) => {
   if (await exists(path)) {
     for (const file of await readdir(path)) {
       var curPath = path + "/" + file;
       if (lstatSync(curPath).isDirectory()) {
         await deleteFolderRecursive(curPath);
       } else {
         unlinkSync(curPath);
       }
     }
     rmdirSync(path);
   }
 };
Ejemplo n.º 8
0
	public getFilesInDirectory(directoryPath, ignoreList?: string[]) : any {
		var dirContents = fs.readdirSync(directoryPath);
		var files = []; 

		for (var index in dirContents) {
			var fullPath = path.join(directoryPath, dirContents[index]);
			if (fs.lstatSync(fullPath).isFile()) {
				files.push(fullPath);
			}
		}

		return files;
	}
Ejemplo n.º 9
0
    dirs.forEach(dir => {
        let state = fs.lstatSync(root + '/' + dir);

        if (state.isFile()) {
            var route: Route = parseFileToRoute(dir);
            if (!allRoutes[route.routePath]) {
                console.log(`添加${route.routePath}到路由组合,已经可以接收${route.routePath}的请求`);
                allRoutes[route.routePath] = route;
            } else {
                console.error(`出现扫描错误,${route.routePath}已经存在`);
            }
        }
    });
Ejemplo n.º 10
0
	public fileOrDirectoryExists(source: string, isFile?: boolean): boolean {
		var sourceExists = false;
		
		if (fs.existsSync(source)) {
			var stat = fs.lstatSync(source);

			if (stat.isFile() || stat.isDirectory()) {
				sourceExists = true;
			}
		}
		
		return sourceExists;
	}