How to use mkdirp - 10 common examples

To help you get started, we’ve selected a few mkdirp 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 FreeFeed / freefeed-server / test / integration / models / attachment.js View on Github external
before(async () => {
      // Create user
      user = new User({
        username: 'Luna',
        password: 'password'
      })
      await user.create()

      // Create directories for attachments
      mkdirp.sync(config.attachments.storage.rootDir + config.attachments.path)

      await Promise.all(_.map(
        config.attachments.imageSizes,
        (size) => mkdirpAsync(config.attachments.storage.rootDir + size.path)
      ));

      // "Upload" files
      const filesToUpload = {
        'test-image.150x150.png':              '1',
        'test-image.900x300.png':              '2',
        'test-image.1500x1000.png':            '3',
        'test-image.3000x2000.png':            '4',
        'test-image-exif-rotated.900x300.jpg': '5',
        'test-image-sgrb.png':                 '6',
        'test-image-animated.gif':             '7',
        'sample.mp3':                          '8',
github bencevans / quickgit / app.js View on Github external
var config = {};
config.repoPath = path.resolve(process.env.REPO_PATH || "/tmp/repos");
config.port = process.env.PORT || 3000;
config.externalPort = process.env.EXTERNAL_PORT || config.port;
config.externalHost = process.env.EXTERNAL_HOST || 'localhost';

// Web Server Requirements
var http = require('http');
var Handlebars = require('handlebars');

// Git Server Requirements
var pushover = require('pushover');
var repos = pushover(config.repoPath);

// mkdir -p ReposPath
mkdirp.sync(config.repoPath, 0777);

repos.on('push', function (push) {
  // TODO: Reject if more than config.maxRepoSize
  // TODO: Reject if URL hasn't actually been generated
  console.log('push ' + push.repo + '/' + push.commit
    + ' (' + push.branch + ')'
    );
  push.accept();
});

repos.on('fetch', function (fetch) {
  console.log('fetch ' + fetch.repo + '/' + fetch.commit);
  fetch.accept();
});

var server = http.createServer(function (req, res) {
github Ledoux / teleport / src / methods / replace.js View on Github external
templateCouples.forEach(templateCouple => {
        // unpack
        const [templatePrefix, templateFileDir] = templateCouple
        const dirChunks = templateFileDir.split('/')
        let installedFileName = dirChunks.slice(-1)[0]
                                         .replace(templatePrefix, '')
        if (templatePrefix === '_') {
          installedFileName = `${type.name}_${installedFileName}`
        }
        const installedFolderDir = path.join(project.dir, 'bundler')
        const installedFileDir = path.join(installedFolderDir, installedFileName)
        const templateFile = fs.readFileSync(templateFileDir, 'utf-8')
        mkdirp.sync(installedFolderDir)
        fs.writeFileSync(installedFileDir, formatString(templateFile, this))
      })
    }
github inkdropapp / docs / semantic / tasks / install.js View on Github external
for(var destination in installPaths) {
      if( installPaths.hasOwnProperty(destination) ) {
        // config goes in project root, rest in install folder
        installPaths[destination] = (destination == 'config' || destination == 'configFolder')
          ? path.normalize( path.join(manager.root, installPaths[destination]) )
          : path.normalize( path.join(installFolder, installPaths[destination]) )
        ;
      }
    }

    // create project folders
    try {
      mkdirp.sync(installFolder);
      mkdirp.sync(installPaths.definition);
      mkdirp.sync(installPaths.theme);
      mkdirp.sync(installPaths.tasks);
    }
    catch(error) {
      console.error('NPM does not have permissions to create folders at your specified path. Adjust your folders permissions and run "npm install" again');
    }

    console.log('Installing to \x1b[92m' + answers.semanticRoot + '\x1b[0m');

    console.info('Copying UI definitions');
    wrench.copyDirSyncRecursive(source.definitions, installPaths.definition, settings.wrench.overwrite);

    console.info('Copying UI themes');
    wrench.copyDirSyncRecursive(source.themes, installPaths.theme, settings.wrench.merge);
    wrench.copyDirSyncRecursive(source.defaultTheme, installPaths.defaultTheme, settings.wrench.overwrite);

    console.info('Copying gulp tasks');
    wrench.copyDirSyncRecursive(source.tasks, installPaths.tasks, settings.wrench.overwrite);
github mosen / buildy / lib / buildy / tasks / write.js View on Github external
this.state.forEach(function(name, value) {
            var basename; // filename without path.

            if (value.file) {
                basename = task_parameters.fnRename(path.basename(value.file), task_parameters.prefix, task_parameters.suffix);
            } else {
                basename = task_parameters.fnRename(name, task_parameters.prefix, task_parameters.suffix);
            }

            if (!fs.existsSync(path.dirname(task_parameters.dest))) {
                var self = this;

                mkdirp(path.dirname(task_parameters.dest), function(err) {
                    self.state.write(path.join(task_parameters.dest, basename), value, function(err) {
                        if (err) {
                            return status.emit('failure', 'write', 'Could not write: ' + err);
                        }

                        if (!--todo) {
                            return status.emit('complete', 'write', 'Items written.');
                        }
                    }, self);
                });
            } else {
                var self = this;

                self.state.write(path.join(task_parameters.dest, basename), value, function(err) {
                    if (err) {
                        return status.emit('failure', 'write', 'Could not write: ' + err);
github sebpiq / fields / backend / main.js View on Github external
HTTPServer.prototype.validateConfig = function(done) { done() }

// Rhizome servers and connection manager
manager = new rhizome.connections.ConnectionManager({ store: config.server.tmpDir })
httpServer = new HTTPServer()
wsServer = new rhizome.websockets.Server({ serverInstance: httpServer._httpServer })
oscServer = new rhizome.osc.Server({ port: config.osc.port })

// Set error handlers
;([wsServer, oscServer, manager]).forEach((server) => {
  server.on('error', (err) => console.error(err.stack ? err.stack : err))
})

// Create tmp and build folders
asyncOps.push(mkdirp.bind(mkdirp, buildDir))

// If `config.instruments` are provided, write it to a config file
if (config.instruments) {
  asyncOps.push(
    fs.writeFile.bind(fs, instrumentConfigFile, 'fields.config = ' + config.instruments.toString())
  )
}

// Start servers
asyncOps.push(rhizome.starter.bind(rhizome.starter, manager, [oscServer, httpServer, wsServer]))

// Async operations
async.series(asyncOps, function(err) {
  if (err) throw err
  console.log(clc.bold('Fields ' + version +' running') )
  console.log(clc.black('GPL license. Copyright (C) 2016 Sébastien Piquemal, Tim Shaw'))
github expo / exp / build / commands / init.js View on Github external
runAsync: _asyncToGenerator(function* (env) {
    var argv = env.argv;
    var args = argv._;

    // Here is what this will do

    // 0. If there is a command line argument, make a new directory in the current directory and chdir to it
    var dirName = args[1];
    var originalCwd = process.cwd();
    if (dirName) {
      dirName = dirName.toString();
      yield mkdirp.promise(dirName);
      log('Setting up an Exponent project at', path.resolve(dirName));
      process.chdir(dirName);
    }

    // 1. If there is no package.json in the current directory, run npm init
    var pkgJsonFile = jsonFile('package.json');
    var pkg;
    try {
      pkg = yield pkgJsonFile.readAsync();
    } catch (e) {
      //console.error(e);

      // No package.json, so let's create it
      log(crayon.cyan('No package.json file found. Using `npm init` to help you create one.'));
      log(crayon.cyan('Answer the questions and a package.json will be created for you.'));
      var _zero = yield spawnAsync('npm', ['init'], { stdio: 'inherit' });
github microsoft / BotBuilder-Samples / generators / generator-botbuilder / components / echoTemplateWriter.js View on Github external
const TS_SRC_FOLDER = 'src'
  const folders = [
    'deploymentScripts',
  ];
  const extension = _.toLower(generator.templateConfig.language) === 'javascript' ? 'js' : 'ts';
  const srcFolder = _.toLower(generator.templateConfig.language) === 'javascript' ? '' : TS_SRC_FOLDER;

  // create the echo bot folder structure common to both languages
  if (_.toLower(generator.templateConfig.language) === LANG_TS) {
    for (let cnt = 0; cnt < folders.length; ++cnt) {
      mkdirp.sync(folders[cnt]);
    }
  }
  // create a src directory if we are generating TypeScript
  if (_.toLower(generator.templateConfig.language) === LANG_TS) {
    mkdirp.sync(TS_SRC_FOLDER);
  }

  let sourcePath = path.join(templatePath, folders[DEPLOYMENT_SCRIPTS]);
  let destinationPath = path.join(generator.destinationPath(), folders[DEPLOYMENT_SCRIPTS]);
   // if we're writing out TypeScript, then we need to add a webConfigPrep.js
   if(_.toLower(generator.templateConfig.language) === LANG_TS) {
     generator.fs.copy(
       path.join(sourcePath, 'webConfigPrep.js'),
       path.join(destinationPath, 'webConfigPrep.js')
     );
   }

  // write out the index.js and bot.js
  destinationPath = path.join(generator.destinationPath(), srcFolder);

  // gen the main index file
github derek / yui-benchmark / bin / yb-compile.js View on Github external
perfSuiteSource = fs.readFileSync(path.join(__dirname, '../lib/assets/perf-suite.js'), 'utf-8'),
        configSource = fs.readFileSync(srcConfigPath, 'utf-8'),
        suite,
        compiled;

    // Turn the config string into an object
    vm.runInNewContext(perfSuiteSource + configSource, context);
    suite = context.suite.exportConfig();

    if (options.node) {
        suite.runner = 'node';
    }

    // Create the target directory if it doesn't exist
    if (!fs.existsSync(targetDir)) {
        mkdirp.sync(targetDir);
    }

    // Compile the suite
    compiled = compile(suite, srcDir);

    // Log the configuration object
    log.debug('Suite Configuration');
    log.debug(JSON.stringify(suite, null, 4));

    // Write the HTML & assets to the filesystem
    writeSuite(compiled, targetDir);
}
github remoteinterview / zero / packages / core / lib / builder / clone.js View on Github external
async function prepareBuildFolder(basePath, buildPath) {
  //basePath = basePath || process.cwd()
  //var buildPath = path.join(basePath, "./.zero")
  // await rimraf(buildPath)
  await del([path.join(buildPath, "/**"), '!' + buildPath, '!'+path.join(buildPath, '/node_modules/**') ]);
  mkdirp.sync(buildPath)
  await copy(basePath, buildPath, { filter: ['**/*', "!.zero"] })
}

mkdirp

Recursively mkdir, like `mkdir -p`

MIT
Latest version published 2 years ago

Package Health Score

67 / 100
Full package analysis