<commit_before>'use strict';

import configuration from './configuration';
import inquirer from 'inquirer';
import { noop } from 'lodash';
import { showErrorMessageAndQuit, showMessage, showStartScreen } from './messages';
import path from 'path';
import { cd, exec, rm } from 'shelljs';

const question = {
  type: 'input',
  name: 'name',
  message: `What's the name of your widget?`,
  default: 'star-rating'
};

const widgetPath = 'widget';

let widgetName;

showStartScreen();

inquirer.prompt([question]).then((answers) => {
  initialize(answers.name);
  showMessage(`Creating widget...`);
  return asPromise({code: 0}, noop);
}).then(() => {
  showMessage(`Cloning template repository...`);
  return cloneRepo(configuration.TEMPLATE_REPO_URL, widgetPath);
}).then(() => {
  showMessage(`Create dist files...`);
  return createDist();
}).then(() => {
  showMessage([
    ``,
    `New project with name '${widgetName}' has been created with a widget boilerplate.`,
    `Please have a look at the README file for instructions.`,
    ``
  ]);
})
.catch((error) => {
  showErrorMessageAndQuit(error);
});

function asPromise(result, resolve, reject) {
  return result.code === 0 ? resolve() : reject(result.stderr);
}

function cloneRepo(repoUrl, repoPath) {
  return new Promise((resolve, reject) => {
    let result = exec(`git clone ${repoUrl} ${repoPath}`,
      {silent: configuration.IS_EXECUTION_SILENT});

    // remove meta data in .git folder
    result = rm('-rf', path.join(__dirname, '..', repoPath, '.git'));

    return asPromise(result, resolve, reject);
  });
}

function createDist() {
  return new Promise((resolve, reject) => {
    cd(path.join(__dirname, '..', '..', '..', widgetPath));
    exec(`npm install`,
      {silent: configuration.IS_EXECUTION_SILENT});
    const result = exec(`npm run build`,
      {silent: configuration.IS_EXECUTION_SILENT});<commit_msg>Cleanup .git in clone step<commit_after>'use strict';

import configuration from './configuration';
import inquirer from 'inquirer';
import { noop } from 'lodash';
import { showErrorMessageAndQuit, showMessage, showStartScreen } from './messages';
import path from 'path';
import { cd, exec, rm } from 'shelljs';

const question = {
  type: 'input',
  name: 'name',
  message: `What's the name of your widget?`,
  default: 'star-rating'
};

const widgetPath = 'widget';

let widgetName;

showStartScreen();

inquirer.prompt([question]).then((answers) => {
  initialize(answers.name);
  showMessage(`Creating widget...`);
  return asPromise({code: 0}, noop);
}).then(() => {
  showMessage(`Cloning template repository...`);
  return cloneRepo(configuration.TEMPLATE_REPO_URL, widgetPath);
}).then(() => {
  showMessage(`Create dist files...`);
  return createDist();
}).then(() => {
  showMessage([
    ``,
    `New project with name '${widgetName}' has been created with a widget boilerplate.`,
    `Please have a look at the README file for instructions.`,
    ``
  ]);
})
.catch((error) => {
  showErrorMessageAndQuit(error);
});

function asPromise(result, resolve, reject) {
  return result.code === 0 ? resolve() : reject(result.stderr);
}

function cloneRepo(repoUrl, repoPath) {
  return new Promise((resolve, reject) => {
    let result = exec(`git clone ${repoUrl} ${repoPath}`,
      {silent: configuration.IS_EXECUTION_SILENT});

    // remove meta data in .git folder
    result = rm('-rf', path.join(__dirname, '..', '..', '..', repoPath, '.git'));

    return asPromise(result, resolve, reject);
  });
}

function createDist() {
  return new Promise((resolve, reject) => {
    cd(path.join(__dirname, '..', '..', '..', widgetPath));
    exec(`npm install`,
      {silent: configuration.IS_EXECUTION_SILENT});
    const result = exec(`npm run build`,
      {silent: configuration.IS_EXECUTION_SILENT});
{'fraction_non_alphanumeric': 0.17109067017082785, 'fraction_numerical': 0.0010512483574244415, 'mean_word_length': 4.286111111111111, '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': '1719361', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1170, 'n_words': 315}