How to use the fs-jetpack.listAsync function in fs-jetpack

To help you get started, we’ve selected a few fs-jetpack 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 szwacz / scattered-store / lib / lister.js View on Github external
const listNextSubdir = () => {
    if (this._subdirsToGo.length === 0) {
      // No more directories to list!
      deferred.reject('endOfPaths');
    } else {
      const subdir = this._subdirsToGo.pop();
      const path = jetpack.path(this._basePath, subdir);
      jetpack.listAsync(path)
      .then((filenames) => {
        // Generate absolute paths from filenames.
        this._pathsToGive = filenames.map((filename) => {
          return jetpack.path(path, filename);
        });
        if (this._pathsToGive.length > 0) {
          // Yep. We have paths. Done!
          deferred.resolve();
        } else {
          // This directory was apparently empty. Go for next one.
          listNextSubdir();
        }
      });
    }
  };
github beakerbrowser / beaker / app / lib / bg / fs.js View on Github external
export async function checkFolderIsEmpty (dst, {noPrompt} = {}) {
  // check if there are files in the destination path
  try {
    var files = await jetpack.listAsync(dst)
    if (files && files.length > 0) {
      if (noPrompt) return false
      // ask the user if they're sure
      var res = await new Promise(resolve => {
        dialog.showMessageBox({
          type: 'question',
          message: 'This folder is not empty. Some files may be overwritten. Continue?',
          buttons: ['Yes', 'No, cancel']
        }, resolve)
      })
      if (res != 0) {
        return false
      }
    }
  } catch (e) {
    // no files
github experimentalDataAesthetics / play-splom / app / actions / datasets.js View on Github external
return dispatch => {
    jetpack.listAsync(datasetsDir).then(paths => {
      if (paths) {
        const dp = paths
          // only show those that have a parser
          .filter(p => Boolean(parsers[extname(p)]))
          .map(p => {
            return {
              name: p,
              path: join(datasetsDir, p)
            };
          });
        dispatch(addDatasetPaths(dp));

        if (thenLoadPath) {
          setTimeout(() => {
            dispatch(loadDataset(thenLoadPath));
          }, 500);
github szwacz / scattered-store / lib / lister.js View on Github external
this._pathsToGive = filenames.map((filename) => {
          return jetpack.path(path, filename);
        });
        if (this._pathsToGive.length > 0) {
          // Yep. We have paths. Done!
          deferred.resolve();
        } else {
          // This directory was apparently empty. Go for next one.
          listNextSubdir();
        }
      });
    }
  };

  if (this._subdirsToGo === null) {
    jetpack.listAsync(this._basePath)
    .then((dirs) => {
      this._subdirsToGo = dirs;
      listNextSubdir();
    });
  } else {
    listNextSubdir();
  }

  return deferred.promise;
};
github RocketChat / Rocket.Chat.Electron / src / i18n / index.js View on Github external
export const setupI18next = async () => {
	globalLocale = normalizeLocale(app.getLocale());

	const lngFiles = await jetpack.listAsync(languagesDirPath);
	const lngs = lngFiles
		.filter((filename) => /^([a-z]{2}(\-[A-Z]{2})?)\.i18n\.json$/.test(filename))
		.map((filename) => filename.split('.')[0]);

	await i18next
		.use(i18nextNodeFileSystemBackend)
		.init({
			lng: globalLocale,
			fallbackLng: defaultLocale,
			lngs,
			backend: {
				loadPath: `${ languagesDirPath }/{{lng}}.i18n.json`,
			},
			initImmediate: true,
		});
};