<commit_before>'use strict';

const chalk = require('chalk');
const ora = require('ora');
const inquirer = require('inquirer');
const archy = require('archy');
const scaffoldLib = require('@pingy/scaffold');
const confirmWithHelpText = require('./promptConfirmWithHelpText');

inquirer.registerPrompt('confirmWithHelpText', confirmWithHelpText);

const toNodeTree = (paths) => {
  const rootPath = [];
  const scriptsPath = [];
  const stylesPath = [];

  paths.forEach((path) => {
    const [folder, file] = path.split('/');
    if (!file) rootPath.push(folder);
    else if (folder === 'scripts') scriptsPath.push(file);
    else if (folder === 'styles') stylesPath.push(file);
  });
  return {
    nodes: [
      ...rootPath,
      {
        label: 'scripts',
        nodes: scriptsPath,
      },
      {
        label: 'styles',
        nodes: stylesPath,
      }
    ],
  };
};

function scaffold(pkgJsonPath, depsObj) {
  const lastWhitespace = global.repeatLastInit && global.conf.get('lastInit.whitespace');
  const options = {
    html: { type: depsObj.html.extension || 'html' },
    styles: { type: depsObj.css.extension || 'css' },
    scripts: { type: depsObj.js.extension || 'js' },
  };

  return scaffoldLib
    .preflight(process.cwd(), options)
    .then(info =>
      archy(toNodeTree(info.preparedFiles))
        .split('\n')
        .join('\n  ')
    )
    .then(filesToWriteTxt =>
      inquirer.prompt([
        {
          type: 'confirmWithHelpText',
          name: 'doScaffold',
          // TODO: If any existing files exist then put up a red warning.
          message: 'Do you want Pingy to scaffold the following files for you?',
          default: true,
          helpText: `${filesToWriteTxt}`,
        }
      ])
    )
    .then(
      ({ doScaffold }) =>
        doScaffold &&
        !lastWhitespace &&
        inquirer
          .prompt([
            {
              type: 'list',
              name: 'whitespace',
              message: 'The most important question: Tabs or spaces',
              choices: [
                {
                  name: '2 spaces',
                  value: '2',
                },
                {
                  name: '4 spaces',
                  value: '4',
                },
                {
                  name: 'Tabs',
                  value: 'tabs',
                }
              ],
            }
          ])
          .then(({ whitespace }) => {
            if (lastWhitespace) {
              whitespace = global.conf.get('lastInit.whitespace');
            }
            global.conf.set('lastInit.whitespace', whitespace);
            // TODO: Support babel.js and buble.js
            return scaffoldLib(
              process.cwd(),
              Object.assign(options, {
                whitespaceFormatting: whitespace,
              })
            );
          })
          .then(() => ora().succeed('Site files scaffolded'))
    );
}

module.exports = scaffold;
<commit_msg>[cli] fix: files didn't get scaffolded if you used the same options as last time<commit_after>'use strict';

const chalk = require('chalk');
const ora = require('ora');
const inquirer = require('inquirer');
const archy = require('archy');
const scaffoldLib = require('@pingy/scaffold');
const confirmWithHelpText = require('./promptConfirmWithHelpText');

inquirer.registerPrompt('confirmWithHelpText', confirmWithHelpText);

const toNodeTree = (paths) => {
  const rootPath = [];
  const scriptsPath = [];
  const stylesPath = [];

  paths.forEach((path) => {
    const [folder, file] = path.split('/');
    if (!file) rootPath.push(folder);
    else if (folder === 'scripts') scriptsPath.push(file);
    else if (folder === 'styles') stylesPath.push(file);
  });
  return {
    nodes: [
      ...rootPath,
      {
        label: 'scripts',
        nodes: scriptsPath,
      },
      {
        label: 'styles',
        nodes: stylesPath,
      }
    ],
  };
};

function scaffold(pkgJsonPath, depsObj) {
  const lastWhitespace = global.repeatLastInit && global.conf.get('lastInit.whitespace');
  const options = {
    html: { type: depsObj.html.extension || 'html' },
    styles: { type: depsObj.css.extension || 'css' },
    scripts: { type: depsObj.js.extension || 'js' },
  };

  return scaffoldLib
    .preflight(process.cwd(), options)
    .then(info =>
      archy(toNodeTree(info.preparedFiles))
        .split('\n')
        .join('\n  ')
    )
    .then(filesToWriteTxt =>
      inquirer.prompt([
        {
          type: 'confirmWithHelpText',
          name: 'doScaffold',
          // TODO: If any existing files exist then put up a red warning.
          message: 'Do you want Pingy to scaffold the following files for you?',
          default: true,
          helpText: `${filesToWriteTxt}`,
        }
      ])
    )
    .then(
      ({ doScaffold }) =>
        doScaffold &&
        !lastWhitespace &&
        inquirer.prompt([
          {
            type: 'list',
            name: 'whitespace',
            message: 'The most important question: Tabs or spaces',
            choices: [
              {
                name: '2 spaces',
                value: '2',
              },
              {
                name: '4 spaces',
                value: '4',
              },
              {
                name: 'Tabs',
                value: 'tabs',
              }
            ],
          }
        ])
    )
    .then(({ whitespace }) => {
      if (lastWhitespace) {
        whitespace = global.conf.get('lastInit.whitespace');
      }
      global.conf.set('lastInit.whitespace', whitespace);
      // TODO: Support babel.js and buble.js
      return scaffoldLib(
        process.cwd(),
        Object.assign(options, {
          whitespaceFormatting: whitespace,
        })
      );
    })
    .then(() => ora().succeed('Site files scaffolded'));
}

module.exports = scaffold;

{'fraction_non_alphanumeric': 0.14125255275697754, 'fraction_numerical': 0.0013614703880190605, 'mean_word_length': 1.803912213740458, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, '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': '1528817', 'n_tokens_mistral': 1762, 'n_tokens_neox': 1702, 'n_words': 375}