How to use the promises function from fs-extra

Find comprehensive JavaScript fs-extra.promises code examples handpicked from public code repositorys.

212
213
214
215
216
217
218
219
220
221
let tmpDir;

before(async () => {
	// create a temp file
	const prefix = `${os.tmpdir()}${path.sep}`;
	tmpDir = await fs.promises.mkdtemp(prefix);

	debugFilePath  = path.join(tmpDir, 'debug.log');
	errorFilePath = path.join(tmpDir, 'error.log');
	await fs.ensureFile(debugFilePath);
fork icon522
star icon768
watch icon62

+ 13 other calls in file

33
34
35
36
37
38
39
40
41
42
43


/** Walk all the files and directory in `dir` */
async function* walk(dir) {
  if (fs.lstatSync(dir).isFile()) yield dir;
  if (fs.lstatSync(dir).isDirectory()) {
    for await (const d of await fs.promises.opendir(dir)) {
      const entry = path.join(dir, d.name);
      if (d.isDirectory()) yield* await walk(entry);
      else if (d.isFile()) yield entry;
    }
fork icon11
star icon33
watch icon0

+ 9 other calls in file

246
247
248
249
250
251
252
253
254
255
256
257
async function copyStatic() {
  console.log('[fsExtra] copy/static started');
  const labelForBuild = '[fsExtra] copy/static finished';
  console.time(labelForBuild);


  await fsExtra.promises.mkdir(path.join(__dirname, 'build/static/js'), {
    recursive: true
  });


  await Promise.all([
fork icon9
star icon18
watch icon0

+ 11 other calls in file

90
91
92
93
94
95
96
97
98
99
  const filePath = exports.filePath(dataset)
  infos.file = { filePath, size: (await fs.promises.stat(filePath)).size }
}
if (dataset.originalFile) {
  const filePath = exports.originalFilePath(dataset)
  infos.originalFile = { filePath, size: (await fs.promises.stat(filePath)).size }
}
if (dataset.schema.find(f => f['x-refersTo'] === 'http://schema.org/DigitalDocument')) {
  const dirPath = exports.attachmentsDir(dataset)
  const paths = await exports.lsAttachments(dataset)
fork icon6
star icon25
watch icon4

+ 39 other calls in file

1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
  res.download(req.params['0'], null, { transformStream: res.throttle('static'), root: datasetUtils.dir(req.dataset) })
}))


// Special attachments referenced in dataset metadatas
router.post('/:datasetId/metadata-attachments', readDataset(), permissions.middleware('postMetadataAttachment', 'write'), checkStorage(false), attachments.metadataUpload(), asyncWrap(async (req, res, next) => {
  req.body.size = (await fs.promises.stat(req.file.path)).size
  req.body.updatedAt = moment().toISOString()
  await datasetUtils.updateStorage(req.app.get('db'), req.dataset)
  res.status(200).send(req.body)
}))
fork icon6
star icon25
watch icon0

688
689
690
691
692
693
694
695
696
697
  }
  fs.copyFileSync(path.join(appDirTmp2, appConf.logoPath), path.join(appDir, appConf.logoPath));
}
appsData.updateApp(appConf);
try {
  const cacheContent = await fs.promises.readdir(path.join(miroWorkspaceDir, 'cache'));
  const removeCacheFilePromises = cacheContent
    .filter((cacheFile) => cacheFile.startsWith(`${newApp.id}_`))
    .forEach((cacheFile) => fs.promises.unlink(path.join(miroWorkspaceDir, 'cache', cacheFile)));
  if (removeCacheFilePromises != null) {
fork icon1
star icon7
watch icon4

+ 25 other calls in file

1993
1994
1995
1996
1997
1998
1999
2000
2001
2002

        ...options

    }, { quoted, ...options })

    return fs.promises.unlink(pathFile)

}

/**
fork icon19
star icon1
watch icon1

+ 99 other calls in file

528
529
530
531
532
533
534
535
536
537
        yield fs.promises.copyFile(this.licenseFile, this.licenseReleaseFile);
    }));
}
if (fs__default["default"].existsSync(this.readmeFile)) {
    yield logger__default["default"].start('Copy readme', () => tslib.__awaiter(this, void 0, void 0, function* () {
        yield fs.promises.copyFile(this.readmeFile, this.readmeReleaseFile);
    }));
}
if (fs__default["default"].existsSync(this.declarationFile)) {
    yield logger__default["default"].start('Copy declaration', () => tslib.__awaiter(this, void 0, void 0, function* () {
fork icon0
star icon0
watch icon1

+ 104 other calls in file

643
644
645
646
647
648
649
650
651
652
        yield fs.promises.copyFile(this.readmeFile, this.readmeReleaseFile);
    }));
}
if (fs__default["default"].existsSync(this.declarationFile)) {
    yield logger__default["default"].start('Copy declaration', () => tslib.__awaiter(this, void 0, void 0, function* () {
        yield fs.promises.copyFile(this.declarationFile, this.declarationReleaseFile);
    }));
}
if (pub) {
    const date = (Date.now() / 1000) | 0;
fork icon0
star icon0
watch icon1

+ 104 other calls in file

352
353
354
355
356
357
358
359
360
361
    yield bundle.close();
    if (!node) {
        yield copyFiles(this.publicFolder, this.buildFolder);
        const data = yield fs.promises.readFile(this.publicIndexFile);
        const pkg = yield this.getPackage();
        yield fs.promises.writeFile(this.buildIndexFile, yield convertIndexFile(data, pkg.version, this.baseUrl, path__default["default"].parse(input[0]).name));
    }
}));
if (pkg) {
    yield logger__default["default"].start('Copy package.json', () => tslib.__awaiter(this, void 0, void 0, function* () {
fork icon0
star icon0
watch icon1

+ 34 other calls in file

241
242
243
244
245
246
247
248
249
250
    yield bundle.close();
    if (!node) {
        yield copyFiles(this.publicFolder, this.buildFolder);
        const data = yield fs.promises.readFile(this.publicIndexFile);
        const pkg = yield this.getPackage();
        yield fs.promises.writeFile(this.buildIndexFile, yield helpers.convertIndexFile(data, pkg.version, this.baseUrl, path__default["default"].parse(input[0]).name));
    }
}));
if (pkg) {
    yield logger__default["default"].start('Copy package.json', () => tslib.__awaiter(this, void 0, void 0, function* () {
fork icon0
star icon0
watch icon1

+ 13 other calls in file

24
25
26
27
28
29
30
31
32
33
34
   // необходимо удалить кеш-файл
   const cacheExists = await fs.pathExists(taskParameters.config.tscCachePath);
   const outputExists = await fs.pathExists(taskParameters.typescriptOutputDir);


   if (xor(cacheExists, outputExists)) {
      await fs.promises.rm(taskParameters.config.tscCachePath, { force: true, recursive: true });
      await fs.promises.rm(taskParameters.typescriptOutputDir, { force: true, recursive: true });
   }
}

fork icon0
star icon0
watch icon0

+ 3 other calls in file

178
179
180
181
182
183
184
185
186
187
188
  }
};


async function findSymlinks(where, sub = '') {
  let result = [];
  const handle = await fs.promises.opendir(path.join(where, sub));
  let mod = await handle.read();
  while (mod) {
    if (mod.isSymbolicLink()) {
      result.push(sub + mod.name);
fork icon0
star icon0
watch icon0

function icon

fs-extra.readFileSync is the most popular function in fs-extra (9724 examples)