How to use klaw-sync - 8 common examples

To help you get started, we’ve selected a few klaw-sync 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 stoikerty / dev-toolkit / src / packages / dev-toolkit / src / postinstall-prepare / copy-templates.js View on Github external
const removeCommentsFromJSFiles = ({ directory }) => {
  const onlyJSFiles = item => item && item.path && path.extname(item.path) === '.js';
  const allFiles = klawSync(directory, { nodir: true, filter: onlyJSFiles });
  const allFilePaths = Object.keys(allFiles).map(item => allFiles[item].path);

  allFilePaths.forEach(filePath => {
    readFile(filePath, 'utf8')
      .then(data => {
        // Uncomment files as if they were plain text files (avoiding issues with jsx)
        outputFile(filePath, decomment.text(data));
      })
      .catch(err => {
        console.error(err);
      });
  });
};
github pandonetwork / pando / packages / pando.js / src / components / index.ts View on Github external
public async update(): Promise {
    const index = this.current
    const files = {}
    const filter = item => {
      return (
        item.path.indexOf('.pando') < 0 && item.path.indexOf('node_modules') < 0
      )
    }
    const listing = klaw(this.repository.paths.root, { nodir: true, filter })

    for (const item of listing) {
      const relativePath = path.relative(this.repository.paths.root, item.path)
      files[relativePath] = { mtime: new Date(item.stats.mtime) }
    }

    const newFiles: any = Object.assign(files)

    for (const relativePath in index) {
      if (index.hasOwnProperty(relativePath)) {
        if (files[relativePath]) {
          // files at _path still exists
          if (
            new Date(index[relativePath].mtime) <=
            new Date(files[relativePath].mtime)
          ) {
github pandonetwork / pando / src / components / repository.ts View on Github external
public async updateIndex (): Promise < any > {
  
    // si le fichier est rajouté je mets undefined à stage et repo
    // si le fichier existe déjà je remplace just le champ wdir
    // si le fichier est supprimé je mets null à wdir
    // et quand je fais un commit je clean la version du dépot
    
    
    let index: any = this.index
    let files: any = {}
    let filter = item => item.path.indexOf('.pando') < 0 
    let _files = klaw(this.paths.root, { nodir: true, filter: filter })
    
    for (let _file in _files) {
      let _path = path.relative(this.paths.root, _files[_file].path)
      let _mtime = _files[_file].stats.mtime
      files[_path] = { mtime: _mtime }
    }
    
    let copy: any = Object.assign(files)
        
    for (let _path in index) {
      if (files[_path]) {
        if (new Date(index[_path].mtime) < new Date(files[_path].mtime)) {
          // File has been modified
          let file = [ { path: _path, content: fs.readFileSync(_path) } ]
          let results = await this.ipfs.files.add(file, { 'only-hash': true })
          let cid = results[0].hash
github willyb321 / media_mate / app / renderjs / viewer.js View on Github external
storage.get('path', (err, data) => {
		if (err) {
			Raven.captureException(err);
			Raven.showReportDialog();
		} else {
			const files = klawSync(data.path, {nodir: true});
			_.each(files, (file, index) => {
				files[index] = file.path;
				const pathParsed = path.parse(file.path);
				if (pathParsed.base === filename) {
					console.log('VIEWER: Found file to delete.');
					console.log(`VIEWER: File path: ${file.path}`);
					console.log(`VIEWER: Directory: ${pathParsed.dir}`);
					require('sweetalert2')({
						title: 'Delete confirmation',
						text: `The following folder and its contents will be deleted: ${pathParsed.dir}`,
						type: 'warning',
						showCancelButton: true,
						confirmButtonColor: '#3085d6',
						cancelButtonColor: '#d33',
						confirmButtonText: 'Yes, delete it!'
					}).then(() => {
github Soluto / dynamico / server / fs-storage / lib / index.ts View on Github external
async getComponentTree(): Promise {
    const basePath = join(resolve(this.basePath), sep);

    return klaw(this.basePath, { nodir: true })
      .filter((dir: Item): boolean => dir.path.endsWith('package.json'))
      .reduce((tree: ComponentTree, file: Item): ComponentTree => {
        const [, componentPath] = file.path.split(basePath);

        const [name, componentVersion] = componentPath.split('/');

        return {
          ...tree,
          [name]: {
            ...tree[name],
            [componentVersion]: async () => require(file.path).peerDependencies
          }
        };
      }, {});
  }
github ecmadao / hacknical / scripts / deploy / cdn / index.js View on Github external
const getFiles = () => {
  const files = klawSync(PATH.PUBLIC_PATH, { nodir: true })
    .map(item => item.path)
    .filter(path => path.split('/').slice(-1)[0][0] !== '.')
    .filter(path => !/\/downloads\//.test(path));
  return files;
};
github serverless / components / registry / AwsS3Website / src / index.js View on Github external
const items = await new Promise((res, rej) => {
    try {
      res(klawSync(assets))
    } catch (error) {
      rej(error)
    }
  })
github wix / kissfs / src / local-fs-crud-only.ts View on Github external
loadDirectoryChildrenSync(fullPath: string): Array {
        const rootPath = fullPath ? path.join(this.baseUrl, fullPath) : this.baseUrl;
        const items = klawSync(rootPath, KLAW_SHALLOW_OPTIONS);
        const memFs = klawItemsToMemFs(items, this.baseUrl, false);
        return memFs.loadDirectoryChildrenSync(fullPath);
    }

klaw-sync

Recursive, synchronous, and fast file system walker

MIT
Latest version published 6 years ago

Package Health Score

67 / 100
Full package analysis

Popular klaw-sync functions