How to use klaw - 10 common examples

To help you get started, we’ve selected a few klaw 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 collective-soundworks / soundworks / src / server / services / FileSystem.js View on Github external
const promise = new Promise((resolve, reject) => {
      klaw(dir)
        .on('data', (item) => {
          const basename = _path.basename(item.path);
          const dirname = _path.dirname(item.path);

          if (
            // ignore current directory
            item.path === dir || 
            // ignore common hidden system file patterns
            basename === 'thumbs.db' ||
            /^\./.test(basename) === true
          ) {
            return;
          }

          if (
            (directories && item.stats.isDirectory()) ||
github pandonetwork / pando / packages / pando.js / src / plant / fiber / factory.ts View on Github external
private _ls(path: string, { all = false }: { all?: boolean } = {}): any {
    return klaw(path).pipe(
      through2.obj(function(item, enc, next) {
        if (!all && item.path.indexOf('.pando') >= 0) {
          // ignore .pando directory
          next()
        } else if (item.stats.isDirectory()) {
          // ignore empty directories
          next()
        } else {
          this.push(item)
          next()
        }
      })
    )
  }
github nuxt / press / test / utils / index.js View on Github external
return new Promise((resolve) => {
    klaw(dir, options)
      .on('data', (item) => {
        const foundItem = pathsBefore.find(itemBefore => item.path === itemBefore.path)

        if (typeof foundItem === 'undefined' || item.stats.mtimeMs !== foundItem.stats.mtimeMs) {
          items.push(item)
        }
      })
      .on('end', () => resolve(items))
  })
}
github reptar / reptar / test / fixtures / index.js View on Github external
return new Promise((resolve) => {
    klaw(directory)
      .on('data', function(item) {
        if (item.stats.isFile()) {
          filePaths.push(item.path);
        }
      })
      .on('end', function() {
        resolve(filePaths);
      });
  });
}
github platformio / platformio-atom-ide / lib / library / containers / detail-headers-block.js View on Github external
return new Promise(resolve => {
      const items = [];
      klaw(libDir, {
        filter: item => {
          return !['test', 'tests', 'example', 'examples'].includes(path.basename(item));
        }
      })
        .on('data', function(item) {
          if (!['.h', '.hpp'].includes(path.extname(item.path))) {
            return;
          }
          if (items.includes(path.basename(item.path))) {
            return;
          }
          items.push(path.basename(item.path));
        })
        .on('end', function() {
          resolve(items);
        });
github roblox-ts / roblox-ts / src / Project.ts View on Github external
return new Promise>(resolve => {
			const result = new Array();
			klaw(this.outPath)
				.on("data", item => {
					if (item.stats.isFile() && item.path.endsWith(".d.ts")) {
						result.push(item.path);
					}
				})
				.on("end", () => resolve(result));
		});
	}
github apache / dubbo-js / packages / interpret-cli / src / cli.ts View on Github external
return new Promise((resolve, reject) => {
    klaw(srcDir)
      .on('data', async (item: klaw.Item) => {
        if (item.path.endsWith('.ts')) {
          try {
            let fileContent = await readFile(item.path);
            await writeFile(
              item.path,
              prettier.format(fileContent.toString(), {
                parser: 'typescript',
                singleQuote: true,
                bracketSpacing: false,
                trailingComma: 'all',
                semi: true,
              }),
            );
            log(`Format the source code successfully:${item.path}`);
          } catch (err) {
github jariz / gatsby-plugin-s3 / src / bin.ts View on Github external
if (routingRules.length) {
                websiteConfig.WebsiteConfiguration.RoutingRules = routingRules;
            }

            await s3.putBucketWebsite(websiteConfig).promise();
        }

        spinner.text = 'Listing objects...';
        spinner.color = 'green';
        const objects = await listAllObjects(s3, config.bucketName);

        spinner.color = 'cyan';
        spinner.text = 'Syncing...';
        const publicDir = resolve('./public');
        const stream = klaw(publicDir);
        const isKeyInUse: { [objectKey: string]: boolean } = {};

        stream.on('data', async ({ path, stats }) => {
            if (!stats.isFile()) {
                return;
            }
            uploadQueue.push(asyncify(async () => {
                const key = createSafeS3Key(relative(publicDir, path));
                const readStream = fs.createReadStream(path);
                const hashStream = readStream.pipe(createHash('md5').setEncoding('hex'));
                const data = await streamToPromise(hashStream);

                const tag = `"${data}"`;
                const object = objects.find(currObj => currObj.Key === key && currObj.ETag === tag);

                isKeyInUse[key] = true;
github jakehamilton / leverage / src / lib / manager.js View on Github external
middleware (middleware) {
    /*
     * If the argument given is a path
     */
    if (typeof middleware === 'string') {
      /*
       * Store all files found in an array
       */
      const files = []

      /*
       * Read the file/directory's information
       */
      klaw(middleware)
        .on('data', file => {
          /*
           * Add each file to our array
           */
          files.push(file)
        })
        .on('end', () => {
          files
            /*
             * Filter for JavaScript files
             */
            .filter(file => {
              /*
               * Get the base name
               *
               * ex. /a/b/c.js -> c.js
github quinton-ashley / nostlan / views / js / gameLibViewer.js View on Github external
return new Promise((resolve, reject) => {
			let items = [];
			let i = 0;
			require('klaw')(dir, options)
				.on('data', item => {
					if (i > 0) {
						items.push(item.path);
					}
					i++;
				})
				.on('end', () => resolve(items))
				.on('error', (err, item) => reject(err, item));
		});
	};

klaw

File system walker with Readable stream interface.

MIT
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis

Popular klaw functions