Example #1
0
File: node.ts Project: Volune/jest
      names.forEach(file => {
        file = path.join(directory, file);
        if (ignore(file)) {
          return;
        }
        activeCalls++;

        fs.lstat(file, (err, stat) => {
          activeCalls--;

          if (!err && stat && !stat.isSymbolicLink()) {
            if (stat.isDirectory()) {
              search(file);
            } else {
              const ext = path.extname(file).substr(1);
              if (extensions.indexOf(ext) !== -1) {
                result.push([file, stat.mtime.getTime(), stat.size]);
              }
            }
          }
          if (activeCalls === 0) {
            callback(result);
          }
        });
      });
Example #2
0
export function link(sourcePath: string,
                     targetPath: string,
                     ignoreFunction: (file: string) => boolean,
                     callback: (error?: Error) => void) {
  lstat(sourcePath, (error, sourceStats) => {
    if (error) return callback(error);
    if (sourceStats.isDirectory()) {
      // if source is a directory, mkdir a new directory at targetPath and recurse
      mkdir_p(targetPath, error => {
        if (error) return callback(error);
        readdir(sourcePath, (error, files) => {
          if (error) return callback(error);
          const sourcePairs = files.map(file => [file, join(sourcePath, file)]);
          const includedSourcePairs = sourcePairs.filter(([_, source]) => !ignoreFunction(source));
          async.each(includedSourcePairs, ([file, source], callback) => {
            const target = join(targetPath, file);
            link(source, target, ignoreFunction, callback);
          }, callback);
        });
      });
    }
    else if (sourceStats.isSymbolicLink() || sourceStats.isFile()) {
      log(`${sourcePath} <- ${targetPath}`);
      // type declarations are incorrect; symlink should be overloaded with three arguments
      symlink(sourcePath, targetPath, null, callback);
    }
    else {
      callback(new Error(`Cannot link unusual source file: "${sourcePath}"`));
    }
  });
}
  return new Promise((resolve, _) => {
    Fs.lstat(path, (err, stat) => {
      if (err) {
        resolve([])
      } else {
        if (stat.isDirectory()) {
          Fs.readdir(path, (readDirErr, paths) => {
            if (readDirErr) {
              resolve([])
            } else {
              const files = paths.map(p =>
                FsUtil.getStats(Path.join(path, p))
                  .then(s => (s.isFile() ? [Path.basename(p)] : []))
                  .catch(() => []),
              )

              resolve(Promise.all(files).then(ArrayUtil.flatten))
            }
          })
        } else if (stat.isFile()) {
          resolve([Path.basename(path)])
        } else {
          // Something else.
          resolve([])
        }
      }
    })
  })
Example #4
0
  var printLink = function(err, res){
    if(err) {
	  console.error(err);
      cb(err);
      return;
    }

    var linkList = [to];
    var lstatCb =  function(file, err, stats){
      if(err){
        console.error("Link target %s not found", file);
        return;
      }
      if(stats.isSymbolicLink()){
        fs.readlink(file, function(err, linkString){
          linkList.push(linkString);
          fs.lstat(linkString, lstatCb.bind(null,linkString));
        });
      } else {
        console.log(linkList.join(" -> "));
        cb(null);
      }
    }
    fs.lstat(to,lstatCb.bind(null,to));

  }
Example #5
0
  private handleEvent(filepath: string) {
    const relativePath = path.relative(this.root, filepath);
    if (!this.isFileIncluded(relativePath)) {
      return;
    }

    fs.lstat(filepath, (error, stat) => {
      if (error && error.code !== 'ENOENT') {
        this.emit('error', error);
        return;
      }

      if (error) {
        // Ignore files that aren't tracked and don't exist.
        if (!this._tracked.has(filepath)) {
          return;
        }

        this._emit(DELETE_EVENT, relativePath);
        this._tracked.delete(filepath);
        return;
      }

      if (this._tracked.has(filepath)) {
        this._emit(CHANGE_EVENT, relativePath, stat);
      } else {
        this._tracked.add(filepath);
        this._emit(ADD_EVENT, relativePath, stat);
      }
    });
  }
Example #6
0
 return new Promise<fs.Stats>((resolve, reject) => {
   fs.lstat(path, (err, stats) => {
     if (err) {
       return reject(err);
     }
     resolve(stats);
   });
 });
 return new Promise((resolve, reject) => {
     fs.lstat(path, (err, stats) => {
         if (err) {
             return reject(err)
         }
         resolve(stats.isDirectory())
     })
 })
Example #8
0
 return new Promise((resolve, reject) => {
   Fs.lstat(path, (err, stat) => {
     if (err) {
       reject(err)
     } else {
       resolve(stat)
     }
   })
 })
	fs.readdir(home, (err, dirs) => {
		if (err) throw err;

		for (const dir of dirs.map(d => path.join(home, d))) {
			fs.lstat(dir, (err, stats) => {
				if(dir.indexOf('.git') > 0) return;

				if (err) throw err;
				if (stats.isDirectory()) {
					checkDir(dir, count + 1);
					fs.readdir(dir, (err, files) => {
						if (err) throw err;
						const target = path.join(dir, 'tsconfig.json');
						fs.exists(target, exists => {
							if (exists) {
								const old = JSON.parse(fs.readFileSync(target, 'utf-8'));

								let entryPoint: string = undefined;
								let definitionFiles = files.filter(f => (f.indexOf('.d.ts') > 0));
								if (definitionFiles.length === 1) {
									entryPoint = definitionFiles[0];
								} else if(fs.existsSync(path.join(dir, 'index.d.ts'))) {
									entryPoint = 'index.d.ts';
								} else {
									entryPoint = path.basename(dir) + '.d.ts';
								}

								if (!fs.existsSync(path.join(dir, entryPoint))) {
									console.log('No file ' + entryPoint + ' exists in ' + dir + ' so deleting it');
									fs.unlink(target);
									return;
								}

								let testFile = path.join(dir, path.basename(dir) + '-tests.ts');
								if (!fs.existsSync(testFile)) {
									let onlyTest = files.filter(f => f.toLowerCase().indexOf('-tests.ts') > 0)[0];
									if (onlyTest) {
										testFile = path.join(dir, onlyTest);
									} else {
										testFile = undefined;
									}
								}
								if (testFile) {
									old['files'] = ['index.d.ts', path.basename(testFile)];
								} else {
									old['files'] = ['index.d.ts'];
								}

								fs.writeFileSync(target, JSON.stringify(old, undefined, 4));
								console.log('Write to ' + target);
							}
						});
					});
				}
			});
		}
	});
	fs.readdir(home, (err, dirs) => {
		if (err) throw err;
		for (const dir of dirs) {
			const fullPath = path.join(home, dir);
			fs.lstat(fullPath, (err, stats) => {
				if (err) throw err;			
				if (stats.isDirectory()) {
					callback(fullPath, dir);
				}
			});
		}
	});