How to use the sync function from mkdirp
Find comprehensive JavaScript mkdirp.sync code examples handpicked from public code repositorys.
mkdirp.sync is a Node.js module that creates a new directory and any necessary subdirectories synchronously.
15 16 17 18 19 20 21 22 23 24
// FIXME process.setMaxListeners(0); const maybeMkdirp = (dir) => { try { mkdirp.sync(dir); } catch (e) { if (e.code !== 'EEXIST') throw e; } }
+ 3 other calls in file
16 17 18 19 20 21 22 23 24 25
// (https://ninja-build.org/manual.html#_depfile) return `${outputName}: ${depPaths.join(' ')}` } function writeDepfileContentSync(filePath, content) { mkdirp.sync(path.dirname(filePath)) fs.writeFileSync(filePath, content, { encoding: 'utf8' }) } class GenerateDepfilePlugin {
How does mkdirp.sync work?
The mkdirp.sync
function is a synchronous implementation of creating a new directory and any necessary subdirectories in a given path by recursively creating directories if they don't exist. If the directory already exists, it won't do anything.
GitHub: codeceptjs/CodeceptJS
98 99 100 101 102 103 104 105
if (path.isAbsolute(config.output)) outputDir = config.output; else outputDir = path.join(testRoot, config.output); if (!fileExists(outputDir)) { output.print(`creating output directory: ${outputDir}`); mkdirp.sync(outputDir); } };
+ 3 other calls in file
GitHub: rock-app/fabu.love
37 38 39 40 41 42 43 44 45 46 47 48
var uploadPrefix = "upload"; function createFolderIfNeeded(path) { if (!fs.existsSync(path)) { mkdirp.sync(path, function(err) { if (err) console.error(err) }) } }
+ 4 other calls in file
Ai Example
1 2 3 4
const mkdirp = require("mkdirp"); // Create a new directory if it doesn't already exist mkdirp.sync("/path/to/new/directory");
In this example, we're using mkdirp.sync to create a new directory at the specified path, /path/to/new/directory. If the directory already exists, nothing happens. If it doesn't exist, it will be created, including any parent directories that need to be created as well. The sync method is used to perform the operation synchronously, which means that the function will block until it has completed, and will not return until the directory has been created.
GitHub: Nozbe/zacs
21 22 23 24 25 26 27 28 29 30 31
// Ignore error } if (currentCssText !== cssText) { // TODO: Remove unnecessary dependency on mkdirp mkdirp.sync(path.dirname(outputFilename)) fs.writeFileSync(outputFilename, cssText) } }
+ 8 other calls in file
167 168 169 170 171 172 173 174 175 176
function copyEventImage(inFilepath, eventId) { const extname = path.extname(inFilepath) const outUrl = `event-images/${eventId}${extname}` const outFilepath = `public/${outUrl}` console.log(`* Copying image "${outFilepath}"`) mkdirp.sync(path.dirname(outFilepath)) fs.copyFileSync(inFilepath, outFilepath) return outUrl }
930 931 932 933 934 935 936 937 938 939 940 941
return err; } }; exports.asFiles = function asFiles(json, outDir) { mkdirp.sync(outDir); Object.keys(json).forEach((moduleName) => { const licenseFile = json[moduleName].licenseFile;
7 8 9 10 11 12 13 14 15 16 17 18
const zlib = require('zlib'); const childProcess = require('child_process'); exports.mkdirp = function (dir, mode) { mode = mode || '0755'; mkdirp.sync(dir, mode); }; exports.md5 = function (str) { if (typeof str !== 'string') {
126 127 128 129 130 131 132 133 134 135 136 137
return d + "d " + h + "h " + m + "m " + s + "s"; } } async function writeAt(filePath, jsonPath, value) { mkdirp.sync(getDirName(filePath)); return fs .readJson(filePath) .then(function (json) {
30 31 32 33 34 35 36 37 38 39
'--rc-path', 'remark-build.config.js', ]; var build = function() { rimraf.sync(program.dist); mkdirp.sync(program.dist); var files = GetFiles(path.join(program.src, '**', '*.md')); if (!files.length) { log.error('Source directory ' + process.src + ' doesnt exist or contains no md files!');
+ 7 other calls in file
201 202 203 204 205 206 207 208 209 210
time: 100000 }); filesArray.reverse().forEach(function (fileInfo) { var folder = path.dirname(fileInfo.target); mkdirp.sync(folder); var file = fs.createWriteStream(fileInfo.target); baseRequest(fileInfo.source) .on('error', function(err) { console.log(err);
+ 3 other calls in file
GitHub: rweigel/urlwatcher
63 64 65 66 67 68 69 70 71
// Prepare configuration file with masked email address let settingsDir = config.app.logDirectory + "/" + testName; let settingsFile = settingsDir + "/settings.json"; if (!fs.existsSync(settingsDir)) { mkdirp.sync(settingsDir); } let fullEmail = urlTests[testName]["emailAlertsTo"];
+ 4 other calls in file
61 62 63 64 65 66 67 68 69 70
ExtractPosts.prototype = { putPosts: function (postsdetails, key) { var self = this; var folderpath = entriesFolderPath + "/" + key; if (!fs.existsSync(folderpath)) { mkdirp.sync(folderpath); helper.writeFile(path.join(folderpath, "en-us.json")); } var contenttype = helper.readFile(path.join(folderpath, "en-us.json"));
+ 4 other calls in file
623 624 625 626 627 628 629 630 631
//console.log(response); //Create Path let dirpath = path.dirname(savepath); if (!fs.existsSync(dirpath)) { console.log("Creating path: " + dirpath); mkdirp.sync(dirpath); } var out = fs.createWriteStream(savepath); res.body.pipe(out);
+ 3 other calls in file
215 216 217 218 219 220 221 222 223 224 225 226
rimraf.sync("Build/createThirdPartyNpm"); }); } gulp.task("build", async function () { mkdirp.sync("Build"); fs.writeFileSync( "Build/package.json", JSON.stringify({
+ 9 other calls in file
3839 3840 3841 3842 3843 3844 3845 3846 3847 3848
if (options.reporterOptions && options.reporterOptions.output) { if (!fs.createWriteStream) { throw new Error('file output not supported in browser'); } mkdirp.sync(path.dirname(options.reporterOptions.output)); self.fileStream = fs.createWriteStream(options.reporterOptions.output); } runner.on('pending', function(test) {
134 135 136 137 138 139 140 141 142 143
*/ exports.getSync = function(key, options = {}) { const fileName = _.partial(utils.getFileName, key, { dataPath: options.dataPath })(); mkdirp.sync(path.dirname(fileName)); let objectJSON = {}; try { const object = fs.readFileSync(fileName, 'utf-8'); objectJSON = JSON.parse(object);
+ 11 other calls in file
20 21 22 23 24 25 26 27 28 29 30 31 32
const outputLogFilePath = path.join(__dirname, nconf.get('logFile') || 'logs/output.log'); const logDir = path.dirname(outputLogFilePath); if (!fs.existsSync(logDir)) { mkdirp.sync(path.dirname(outputLogFilePath)); } const output = logrotate({ file: outputLogFilePath, size: '1m', keep: 3, compress: true }); const silent = nconf.get('silent') === 'false' ? false : nconf.get('silent') !== false;
GitHub: kevin20888802/dcmtkEdits
118 119 120 121 122 123 124 125 126 127
// Write the binary data to disk let filename = path.join( process.env.DICOM_STORE_ROOTPATH, relativeFilename ); mkdirp.sync( path.join( process.env.DICOM_STORE_ROOTPATH, `files/bulkData/${shortInstanceUID}` )
+ 11 other calls in file
482 483 484 485 486 487 488 489 490 491
for (let input of inputs) { let inputContent = input.filename let pssh = input.pssh inputContent = path.resolve(inputContent) let outputContent = `${rootDir}/${this.util.randomFileName('.mp4')}` mkdirp.sync(rootDir) let promise = null let cacheId = `${pssh}` let key = await this.redisClient.getAsync(cacheId) if (!key) {
+ 64 other calls in file
mkdirp.sync is the most popular function in mkdirp (471 examples)