How to use the ensureDir function from fs-extra
Find comprehensive JavaScript fs-extra.ensureDir code examples handpicked from public code repositorys.
384 385 386 387 388 389 390 391 392 393
const root = config.workspaceHomeDirRoot; const destinationPath = path.join(root, remotePath); const sourcePath = `${destinationPath}-${uuidv4()}`; await fse.ensureDir(sourcePath); await fsPromises.chown( sourcePath, config.workspaceJobsDirectoryOwnerUid, config.workspaceJobsDirectoryOwnerGid
253
252
0
+ 3 other calls in file
251 252 253 254 255 256 257 258 259 260
}); it('records an error if a question directory is missing an info.json file', async () => { const courseData = util.getCourseData(); const courseDir = await util.writeCourseToTempDirectory(courseData); await fs.ensureDir(path.join(courseDir, 'questions', 'badQuestion')); await util.syncCourseData(courseDir); const syncedQuestions = await util.dumpTable('questions'); const syncedQuestion = syncedQuestions.find((q) => q.qid === 'badQuestion');
252
248
14
+ 11 other calls in file
GitHub: alphagov/govuk-prototype-kit
219 220 221 222 223 224 225 226 227 228
console.log('') const installDirectory = getInstallLocation() const kitDependency = getChosenKitDependency() await fs.ensureDir(installDirectory) if ((await fs.readdir(installDirectory)).length > 0) { console.error(`Directory ${installDirectory} is not empty, please specify an empty location.`) process.exitCode = 3 return
234
281
77
+ 14 other calls in file
346 347 348 349 350 351 352 353 354 355
if (await fse.exists(installLocation)) { renderError('exists') return } await fse.ensureDir(path.dirname(installLocation)) await fse.copy(templatePath, installLocation) // Inject a forward slash if the user hasn't included one if (chosenUrl[0] !== '/') {
234
281
77
+ 2 other calls in file
GitHub: balena-os/meta-balena
76 77 78 79 80 81 82 83 84 85
join(homedir(), 'id') ); const cloud = new Balena(this.suite.options?.balena?.apiUrl, this.getLogger()); await fse.ensureDir(this.suite.options.tmpdir); let systemd = { /** * Wait for a service to be active/inactive
108
959
48
+ 4 other calls in file
79 80 81 82 83 84 85 86 87 88
const createCopy = async () => { const root = path.resolve(__dirname, '../fixtures'); const copyDir = path.resolve(__dirname, '..', `test-dir-${Math.random().toString(36).slice(2)}`); await fs.ensureDir(copyDir); await fs.copy(root, copyDir); return copyDir; };
7
86
2
+ 25 other calls in file
GitHub: LibreTexts/Libretext
680 681 682 683 684 685 686 687 688 689
} } async function getCover(current, numPages, options = {}) { current = await getAPI(current); await fs.ensureDir(`./PDF/Letter/Cover`); if (!options.thin && (numPages < 32 && options.hasExtraPadding && !options.isHardcover) || (numPages < 24 && options.hasExtraPadding && options.isHardcover)) return false;
8
11
6
+ 29 other calls in file
GitHub: mrvautin/squido
274 275 276 277 278 279 280 281 282 283
for(const file of setupFiles){ const dest = file.replace(winPath(path.join(__dirname, '..', 'source')), winPath(path.join(process.cwd(), 'source'))); const dirName = path.dirname(dest); // Create dir if doesn't exist await fsExtra.ensureDir(dirName); try{ // Copy the file await fsExtra.copy(file, dest);
7
46
3
+ 23 other calls in file
384 385 386 387 388 389 390 391 392 393
const lineId = req.params.lineId || req.body._id const dir = path.join(datasetUtils.attachmentsDir(req.dataset), lineId) if (req.file) { // An attachment was uploaded await fs.ensureDir(dir) await fs.emptyDir(dir) await fs.rename(req.file.path, path.join(dir, req.file.originalname)) const relativePath = path.join(lineId, req.file.originalname) const pathField = req.dataset.schema.find(f => f['x-refersTo'] === 'http://schema.org/DigitalDocument')
6
26
4
+ 7 other calls in file
GitHub: data-fair/data-fair
690 691 692 693 694 695 696 697 698 699
if (draft) { dataset.status = 'draft' patch.draftReason = { key: 'file-new', message: 'Nouveau jeu de données chargé en mode brouillon' } } await fs.ensureDir(datasetUtils.dir({ ...dataset, ...patch })) await fs.move(file.path, datasetUtils.originalFilePath({ ...dataset, ...patch })) } else { if (draft) { patch.draftReason = { key: 'file-updated', message: 'Nouveau fichier chargé sur un jeu de données existant' }
6
26
4
GitHub: data-fair/data-fair
935 936 937 938 939 940 941 942 943 944
continue } } } } await fs.ensureDir(exports.dir(patchedDataset)) await fs.remove(exports.originalFilePath(patchedDataset)) await fs.move(exports.originalFilePath(dataset), exports.originalFilePath(patchedDataset)) if (await fs.pathExists(exports.attachmentsDir(dataset))) { await fs.remove(exports.attachmentsDir(patchedDataset))
6
26
4
GitHub: ortexx/spreadable
117 118 119 120 121 122 123 124 125 126
if(!this.ip) { throw new Error(`Hostname ${this.hostname} is not found`); } await fse.ensureDir(this.storagePath); await this.prepareServices(); await super.init.apply(this, arguments); if(!this.options.server) {
4
14
4
+ 28 other calls in file
117 118 119 120 121 122 123 124 125 126 127 128
}) } } async function createWriter(outputPath, departement) { await ensureDir(outputPath) const adressesFile = createWriteStream(join(outputPath, `adresses-addok-${departement}.ndjson.gz`)) const adressesStream = pumpify.obj( stringify(),
3
7
3
+ 3 other calls in file
13 14 15 16 17 18 19 20 21 22 23
async function ensureDirectoriesExist(directories) { const validDirectories = []; for (const dir of directories) { try { await fs.ensureDir(dir.path); validDirectories.push(dir); } catch (err) { logger.err( `
3
3
2
+ 9 other calls in file
38 39 40 41 42 43 44 45 46
readdirAsync = dirname => fse.readdir(getAbsPath(dirname)) statAsync = path => fse.stat(getAbsPath(path)) readJson = fname => fse.readJSON(getAbsPath(fname)) pathExistsAsync = fname => fse.pathExists(getAbsPath(fname)) copyAsync = (src, dest) => fse.copy(src,dest) ensureDirAsync = dirPath => fse.ensureDir(dirPath) moveAsync = (srcPath,destPath) => fse.move(srcPath,destPath) removeAsync = dirPath => fse.remove(dirPath) emptyDirAsync = dirPath => fse.emptyDir(dirPath)
1
3
3
350 351 352 353 354 355 356 357 358 359
}, buildPath: { env: "KS_BUILD_PATH", defaultFunction: async (config) => { const { buildRootPath } = config await fs.ensureDir(buildRootPath) return mkdtemp(path.join(buildRootPath, "build-")) }, transform: async (buildPath) => { await fs.ensureDir(buildPath)
0
7
6
+ 9 other calls in file
GitHub: athombv/node-homey
615 616 617 618 619 620 621 622 623 624
} let userdataDirWarned = false; const userdataDir = path.join(Settings.getSettingsDirectory(), 'apps-userdata', manifest.id); if (homey.platform === 'local') { await fse.ensureDir(userdataDir); if (clean === true) { await fse.emptyDir(userdataDir); }
4
5
4
+ 11 other calls in file
GitHub: bcomnes/cpx2
95 96 97 98 99 100 101 102 103 104
} } } if (stat.isDirectory()) { await fs.ensureDir(output) } else { await fs.ensureDir(path.dirname(output)) if (!(stat.mode & 0o200) && options.force) {
3
27
2
+ 17 other calls in file
261 262 263 264 265 266 267 268 269 270
} ) } // make the new cache directory return fse.ensureDir(cacheDir, function (err) { if (err != null) { logger.error( { err, directory: cacheDir }, 'error creating cache directory'
0
2
1
+ 27 other calls in file
148 149 150 151 152 153 154 155 156
init: async function (_settings) { settings = _settings; libDir = fspath.join(settings.userDir, "lib"); libFlowsDir = fspath.join(libDir, "flows"); if (!settings.readOnly) { return fs.ensureDir(libFlowsDir); } }, getLibraryEntry: getLibraryEntry,
0
2
0
+ 3 other calls in file
fs-extra.readFileSync is the most popular function in fs-extra (9724 examples)