<commit_before>#!/usr/bin/env node

'use strict';

var fs             = require('fs'),
    program        = require('commander'),
    chalk          = require('chalk'),
    logSymbols     = require('log-symbols'),
    inquirer       = require('inquirer');

var projectVersion = require('../package.json').version,
    defaultDir     = process.env.HOME + '/.knick-knack';

program
  .version(projectVersion)
  .option('-d, --directory [directory]', 'Specify the directory where knick-knack should look for templates [' + defaultDir + ']', defaultDir);

program.on('--help', function () {
  console.log('  ' + chalk.cyan.underline('Commands:'));
  console.log();
  console.log('    $ knick-knack [list]             List all available knick-knack templates');
  console.log('    $ knick-knack [template-name]    Generate a new project based on a template');
  console.log('    $ knick-knack add general-readme Add a readme partial to the project in the current directory');
  console.log('    $ knick-knack init               Initialize a knick-knack templates directory');
  console.log();
});

program.parse(process.argv);

var additionalArgs = program.args,
    directory      = program.directory;

var list     = require('../lib/list'),
    init     = require('../lib/init'),
    generate = require('../lib/generate');

if (! fs.existsSync(directory) || ! fs.statSync(directory).isDirectory()) {
  if (directory !== defaultDir) {
    console.error(chalk.yellow('"' + directory + '" is not a valid directory.'));
    return;
  } else {
    console.log('This seems to be the first time you are using knick-knack.\n');
    
    var continueQuestion = {
      name: 'continue',
      type: 'confirm',
      message: 'May I suggest that you start the setup assistant for you?',
      default: true
    };
    inquirer.prompt(continueQuestion, function(answer) {
      if (answer.continue) {
        init.createTemplateFolder(directory);
      }
    });
    return;
  }
}

switch (additionalArgs[0]) {
case 'list':
case undefined:
  var templates = list.listTemplates(directory);

  if (templates.length > 0) {
    console.log(chalk.yellow('A valid template name must be specified.'));
    console.log();
    console.log(chalk.cyan.underline('Available templates:'));
    console.log(templates.join('\n'));
    console.log();
    console.log('You can generate a new project with ' + chalk.blue.bold('knick-knack TEMPLATE'));
    console.log();
    console.log('For more information see https://github.com/haimich/knick-knack');
    console.log();
  } else {
    console.log(logSymbols.warning + chalk.magenta(' No templates found in "' + directory + '".'));
    console.log();
  }

  break;
case 'init':
  init.createTemplateFolder(directory);
  break;
case 'check':
  console.log('check');
  break;
case 'add':
  console.log('add ' + additionalArgs[1]);
  break;
case 'create':
  console.log('create ' + additionalArgs[1]);
  break;
default: // not a command, maybe a template name?
  generate.createProject(additionalArgs[0]);<commit_msg>finetuned cli for only showing the first time message when it is appropriate<commit_after>#!/usr/bin/env node

'use strict';

var fs             = require('fs'),
    program        = require('commander'),
    chalk          = require('chalk'),
    logSymbols     = require('log-symbols'),
    inquirer       = require('inquirer'),
    filesystem     = require('../lib/util/filesystem');

var projectVersion = require('../package.json').version,
    defaultDir     = process.env.HOME + '/.knick-knack';

program
  .version(projectVersion)
  .option('-d, --directory [directory]', 'Specify the directory where knick-knack should look for templates [' + defaultDir + ']', defaultDir);

program.on('--help', function () {
  console.log('  ' + chalk.cyan.underline('Commands:'));
  console.log();
  console.log('    $ knick-knack [list]             List all available knick-knack templates');
  console.log('    $ knick-knack [template-name]    Generate a new project based on a template');
  console.log('    $ knick-knack add general-readme Add a readme partial to the project in the current directory');
  console.log('    $ knick-knack init               Initialize a knick-knack templates directory');
  console.log();
});

program.parse(process.argv);

var additionalArgs = program.args,
    directory      = program.directory;

var list     = require('../lib/list'),
    init     = require('../lib/init'),
    generate = require('../lib/generate');

function folderInvalid(name) {
  if (! filesystem.folderExists(name) && name !== defaultDir && additionalArgs[0] !== 'init') {
    //the user passed in an invalid folder with -d but did not want to create one with "init"
    return true;
  }
  return false;
}

if (folderInvalid(directory)) {
  console.error(chalk.yellow('"' + directory + '" is not a valid directory.'));
  return;
}

switch (additionalArgs[0]) {
  case 'init':
    init.createTemplateFolder(directory);
    break;
  
  case undefined:
    if (! filesystem.folderExists(directory)) {
      console.log('This seems to be the first time you\'re using knick-knack.\n');
      
      var continueQuestion = {
        name: 'continue',
        type: 'confirm',
        message: 'May I suggest that you start the setup assistant for you?',
        default: true
      };
      inquirer.prompt(continueQuestion, function(answer) {
        if (answer.continue) {
          init.createTemplateFolder(directory);
        }
      });
      return;
    }
    
    var templates = list.listTemplates(directory);
  
    if (templates.length > 0) {
      console.log(chalk.yellow('A valid template name must be specified.'));
      console.log();
      console.log(chalk.cyan.underline('Available templates:'));
      console.log(templates.join('\n'));
      console.log();
      console.log('You can generate a new project with ' + chalk.blue.bold('knick-knack TEMPLATE'));
      console.log();
      console.log('For more information see https://github.com/haimich/knick-knack');
      console.log();
    } else {
      console.log(logSymbols.warning + chalk.magenta(' No templates found in "' + directory + '".'));
      console.log();
    }
  
    break;
    
  case 'check':
    console.log('check');
    break;
  case 'add':
    console.log('add ' + additionalArgs[1]);
    break;
  case 'create':
    console.log('create ' + additionalArgs[1]);
    break;
    
  default: // not a command, maybe a template name?
    generate.createProject(additionalArgs[0]);
{'fraction_non_alphanumeric': 0.14863203197048877, 'fraction_numerical': 0.001690747002766677, 'mean_word_length': 3.0241187384044528, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6673681', 'n_tokens_mistral': 1937, 'n_tokens_neox': 1915, 'n_words': 491}