<commit_before>import * as path from 'path';
import * as fs from 'fs';
import * as mkdirp from 'mkdirp';
import * as webpack from 'webpack';
import { Gulp } from 'gulp';
import * as Listr from 'listr';
import * as minimist from 'minimist';

import { getConfigs } from './config';
import Build from '../utils/build';
import { walkFolders } from '../utils/misc';
import { detectProdMode, compileEnvHashedString } from '../utils/env';
import { processStepMessage } from '../utils/log';

import { ISPBuildSettings, IGulpConfigs, IAssetMap, IFile } from '../interfaces';

declare var global: any;

export const buildTasks = (gulp: Gulp, $: any, settings: ISPBuildSettings) => {

  const buildTasks = new BuildTasks(settings);

  gulp.task('build', cb => {
    const mode = detectProdMode();
    const args = process.argv.slice(3);
    (async () => {
      processStepMessage(`Build (mode: ${mode})`);
      if (!fs.existsSync(path.resolve(settings.privateConf || './config/private.json'))) {
        await getConfigs(settings);
      }
      const tasksInfo = [
        { key: '--copy-assets', title: 'Copy Assets', task: buildTasks.buildCopyAssetsTask },
        { key: '--webparts', title: 'Build CEWPs', task: buildTasks.buildWebpartsTask },
        { key: '--masterpage', title: 'Build Masterpages', task: buildTasks.buildMasterpagesTask },
        { key: '--layouts', title: 'Build Layouts', task: buildTasks.buildLayoutsTask },
        { key: '--css-custom', title: 'Build Custom CSS', task: buildTasks.buildCustomCssTask },
        { key: '--css-libs', title: 'Build CSS Libraries', task: buildTasks.buildCssLibsTask },
        { key: '--js-libs', title: 'Build JavaScript DLLs', task: buildTasks.buildJsLibsTask },
        { key: '--webpack', title: 'Starting Webpack build', task: () => Promise.resolve() }
      ];
      let tasks = tasksInfo.filter(task => args.indexOf(task.key) !== -1);
      tasks = tasks.length > 0 ? tasks : tasksInfo;
      await new Listr(tasks).run();
      if (args.indexOf('--webpack') !== -1 || tasksInfo.length === tasks.length) {
        await buildTasks.buildWebpackTask();
      }
    })()
      .then(_ => cb())
      .catch(cb);
  });

};

export const mapProjectData = (configs: IGulpConfigs) => {
  const serverPath: string = configs.privateConf.siteUrl.split('/').splice(0, 3).join('/');
  const publishPath: string = `${configs.privateConf.siteUrl}/${configs.appConfig.spFolder}`.replace(serverPath, '');

  const packageData = require(path.join(process.cwd(), 'package.json'));
  const data = {
    serverPath,
    publishPath,<commit_msg>--no-webpack build option<commit_after>import * as path from 'path';
import * as fs from 'fs';
import * as mkdirp from 'mkdirp';
import * as webpack from 'webpack';
import { Gulp } from 'gulp';
import * as Listr from 'listr';
import * as minimist from 'minimist';

import { getConfigs } from './config';
import Build from '../utils/build';
import { walkFolders } from '../utils/misc';
import { detectProdMode, compileEnvHashedString } from '../utils/env';
import { processStepMessage } from '../utils/log';

import { ISPBuildSettings, IGulpConfigs, IAssetMap, IFile } from '../interfaces';

declare var global: any;

export const buildTasks = (gulp: Gulp, $: any, settings: ISPBuildSettings) => {

  const buildTasks = new BuildTasks(settings);

  gulp.task('build', cb => {
    const mode = detectProdMode();
    const args = process.argv.slice(3);
    (async () => {
      processStepMessage(`Build (mode: ${mode})`);
      if (!fs.existsSync(path.resolve(settings.privateConf || './config/private.json'))) {
        await getConfigs(settings);
      }
      const tasksInfo = [
        { key: '--copy-assets', title: 'Copy Assets', task: buildTasks.buildCopyAssetsTask },
        { key: '--webparts', title: 'Build CEWPs', task: buildTasks.buildWebpartsTask },
        { key: '--masterpage', title: 'Build Masterpages', task: buildTasks.buildMasterpagesTask },
        { key: '--layouts', title: 'Build Layouts', task: buildTasks.buildLayoutsTask },
        { key: '--css-custom', title: 'Build Custom CSS', task: buildTasks.buildCustomCssTask },
        { key: '--css-libs', title: 'Build CSS Libraries', task: buildTasks.buildCssLibsTask },
        { key: '--js-libs', title: 'Build JavaScript DLLs', task: buildTasks.buildJsLibsTask },
        { key: '--webpack', title: 'Starting Webpack build', task: () => Promise.resolve() }
      ];
      let tasks = tasksInfo.filter(task => args.indexOf(task.key) !== -1);
      tasks = tasks.length > 0 ? tasks : tasksInfo;
      await new Listr(tasks).run();
      if (args.indexOf('--webpack') !== -1 || tasksInfo.length === tasks.length) {
        if (args.indexOf('--no-webpack') === -1) {
          await buildTasks.buildWebpackTask();
        }
      }
    })()
      .then(_ => cb())
      .catch(cb);
  });

};

export const mapProjectData = (configs: IGulpConfigs) => {
  const serverPath: string = configs.privateConf.siteUrl.split('/').splice(0, 3).join('/');
  const publishPath: string = `${configs.privateConf.siteUrl}/${configs.appConfig.spFolder}`.replace(serverPath, '');

  const packageData = require(path.join(process.cwd(), 'package.json'));
  const data = {
    serverPath,
    publishPath,
{'fraction_non_alphanumeric': 0.16955941255006676, 'fraction_numerical': 0.0024794964714857904, 'mean_word_length': 3.4705882352941178, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '5787950', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1614, 'n_words': 408}