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
fork icon253
star icon252
watch icon0

+ 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');
fork icon252
star icon248
watch icon14

+ 11 other calls in file

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
fork icon234
star icon281
watch icon77

+ 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] !== '/') {
fork icon234
star icon281
watch icon77

+ 2 other calls in file

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
fork icon108
star icon959
watch icon48

+ 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;
};
fork icon7
star icon86
watch icon2

+ 25 other calls in file

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;
    
fork icon8
star icon11
watch icon6

+ 29 other calls in file

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);
fork icon7
star icon46
watch icon3

+ 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')
fork icon6
star icon26
watch icon4

+ 7 other calls in file

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' }
fork icon6
star icon26
watch icon4

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))
fork icon6
star icon26
watch icon4

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) {
fork icon4
star icon14
watch icon4

+ 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(),
fork icon3
star icon7
watch icon3

+ 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(
                `
fork icon3
star icon3
watch icon2

+ 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)
fork icon1
star icon3
watch icon3

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)
fork icon0
star icon7
watch icon6

+ 9 other calls in file

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);
  }
fork icon4
star icon5
watch icon4

+ 11 other calls in file

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) {
fork icon3
star icon27
watch icon2

+ 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'
fork icon0
star icon2
watch icon1

+ 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,
fork icon0
star icon2
watch icon0

+ 3 other calls in file

function icon

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