How to use the ncp.ncpAsync function in ncp

To help you get started, we’ve selected a few ncp 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 t4t5 / november-cli / actions / new-project.js View on Github external
if (nov.novemberDir()) {
    userArgs.shift();
    return nov.logErr("You're trying to create a new November project inside an existing one! Did you mean to use `november generate " + userArgs.join(' ') + "?");
  }

  // Check if the folder already exists
  try {
    stats = fs.lstatSync(projectName);
    return nov.logErr("There's already a project with the name " + projectName + " in this directory!");
  }
  catch (e) {
    var spinner = new Spinner('%s Building November project...');

    // Copy the contents of the blueprint folder to the user's app folder 
    ncp.ncpAsync(path.resolve(__dirname, '../template-files/blueprint-project'), projectName)
    .then(function() {
      return fs.readFileAsync(projectName + '/package.json', 'utf8');
    })
    // Set the name of the app in package.json
    .then(function(packageJsonContents) {
      packageJsonContents = nov.fillTemplatePlaceholders(packageJsonContents, projectName);
      return fs.writeFileAsync(projectName + '/package.json', packageJsonContents, 'utf8');
    })
    .then(function() {
      return fs.readFileAsync(projectName + '/public/index.html', 'utf8');
    })
    // Set the name of the app in index.html
    .then(function(htmlContents) {
      htmlContents = nov.fillTemplatePlaceholders(htmlContents, projectName);
      return fs.writeFileAsync(projectName + '/public/index.html', htmlContents, 'utf8');
    })

ncp

Asynchronous recursive file copy utility.

MIT
Latest version published 10 years ago

Package Health Score

72 / 100
Full package analysis