<commit_before>var gulp = require('gulp'),
	uglify = require('gulp-uglify'),
    jshint = require('gulp-jshint'),
    stylish = require('jshint-stylish'),
    rename = require('gulp-rename'),
    replace = require('gulp-replace'),
    ignore = require('gulp-ignore'),
    sourcemaps = require('gulp-sourcemaps'),
	request = require('request'),
	merge = require('merge-stream'),
    fs = require('fs'),
	del = require('del'),
    bump = require('gulp-bump'),
    tap = require('gulp-tap'),
    runSequence = require('run-sequence'),
    git = require('gulp-git'),
    glob = require('glob'),
    path = require('path'),
    shell = require('shelljs');
var args = require('yargs').argv;

var settings = {
    baseProject: 'jquery.dirtyforms',
    src: ['./jquery.dirtyforms.js', './helpers/*.js', './dialogs/*.js'],
    src_assets: ['./README.md', './pkg/*.json'],
    src_module_assets: ['./helpers/**/*.json', './helpers/**/README.md', './helpers/**/LICENSE*', './dialogs/**/*.json', './dialogs/**/README.md', './dialogs/**/LICENSE*'],
    src_json_files: ['./**/*.json', '!./node_modules/**', '!./dist/**'],
    src_readme_files: ['./**/README*', '!./dist/**'],
    dest: './dist/',
    dest_plugins: '/plugins',
    nugetPath: './nuget.exe',
    subModules: [], // All of the git submodule names (individual releases) for the build
    version: '',
    debug: true
};

settings.subModules = getSubmoduleNames();
settings.version = getBuildVersion();
settings.debug = getDebug();

console.log('subModules: ' + settings.subModules);
console.log('Debug mode: ' + settings.debug);


// Builds the distribution files and packs them with NuGet
gulp.task('default', function (cb) {
    runSequence(
        'git-checkout',
        'pack',
        cb);
});

// Cleans the distribution folders
gulp.task('clean', function (cb) {
    del([settings.dest + '**/*.js',
        settings.dest + '**/*.map',
        settings.dest + '**/*.nupkg',
        settings.dest + '**/*.tgz',
        settings.dest + '**/*.css',
        settings.dest + '**/*.png',
        settings.dest + '**/*.gif',
        settings.dest + '**/README.*',
        settings.dest + '**/LICENSE.*',
        settings.dest + '**/*.json'], cb);
});

// Moves the .js files to the distribution folders and creates a minified version and sourcemap
gulp.task('build', ['copy-minified'], function (cb) {
    del([settings.dest + '*.js', settings.dest + '*.map'], cb);
});

// Tests the source files (smoke test)
gulp.task('test', function () {
    return gulp.src(settings.src, { base: './' })
        .pipe(jshint())
        .pipe(jshint.reporter(stylish));
});

gulp.task('copy-minified', ['uglify', 'distribute-module-assets'], function () {
    return gulp.src([settings.dest + '*.js', settings.dest + '*.map'], { base: './' })
        .pipe(rename(function (path) {
            console.log('moving: ' + path.basename)
            path.dirname = path.basename.replace(/\.min(?:\.js)?/g, '');
        }))
        .pipe(gulp.dest(settings.dest))
        .pipe(ignore.exclude(eval('/' + settings.baseProject + '\.min/')))
        // Make a copy of the minified files in the /dist/plugins directory for 
        // CDN distribution.
        .pipe(rename(function (path) {
            console.log('moving: ' + path.basename)
            path.dirname = settings.baseProject + settings.dest_plugins;
        }))
        .pipe(gulp.dest(settings.dest));
});

gulp.task('uglify', ['clean', 'test'], function () {
    return gulp.src(settings.src, { base: './' })
        .pipe(rename(function (path) {
            var baseName = path.basename;
            var dirName = path.dirname;
            if (dirName == 'helpers' || dirName == 'dialogs') {
                path.basename = settings.baseProject + '.' + dirName + '.' + baseName;
            }
            path.dirname = path.basename;
        }))
        .pipe(gulp.dest(settings.dest))
        .pipe(sourcemaps.init())
        .pipe(rename(function (path) {
            path.dirname = '';
            path.extname = '.min.js';
        }))
        .pipe(uglify({
            outSourceMap: true,
            sourceRoot: '/'
        }))
        .pipe(gulp.dest(settings.dest))
        .pipe(sourcemaps.write('.', {
            includeContent: true,
            sourceRoot: '/'
        }))
        .pipe(gulp.dest(settings.dest));
});

gulp.task('distribute-default-license', ['clean'], function () {
    var defaultLicense = './LICENSE*';
    var baseModule = gulp.src(defaultLicense, { base: './' })
        .pipe(rename(function (path) {
            path.dirname = settings.baseProject;
        }))
        .pipe(gulp.dest(settings.dest));

    var merged = merge(baseModule);
    var modulesLength = settings.subModules.length;
    for (var i = 0; i < modulesLength; i++) {
        var subModule = settings.subModules[i];
        var module = gulp.src(defaultLicense, { base: './' })
            .pipe(ignore(settings.baseProject))
            .pipe(gulp.dest(settings.dest + subModule));

        merged.add(module);
    }

    return merged;
});

gulp.task('distribute-assets', ['distribute-default-license'], function () {
    return gulp.src(settings.src_assets, { base: './' })
        .pipe(rename(function (path) {
            path.dirname = settings.baseProject;
        }))
        .pipe(gulp.dest(settings.dest));
});

gulp.task('distribute-module-assets', ['distribute-assets'], function () {
    return gulp.src(settings.src_module_assets, { base: './' })
        .pipe(rename(function (path) {
            var segments = path.dirname.split(/[/\\]/);
            var rootDir = segments[0];
            if (rootDir == 'helpers' || rootDir == 'dialogs') {
                var pkgDir = segments[1].replace('.pkg', '');
                path.dirname = settings.baseProject + '.' + rootDir + '.' + pkgDir;
                console.log(path.dirname);
            }
        }))
        .pipe(gulp.dest(settings.dest));
});

// Runs the build, downloads the NuGet.exe file, and packs the distribution files with NuGet
gulp.task('nuget-pack', ['nuget-download', 'build'], function (cb) {
    console.log('build version: ' + settings.version);

    // Get the nuspec files
    var nuspecFiles = glob.sync("./**/*.nuspec");

    console.log('Nuspec files: ' + nuspecFiles);

    var nuspecLength = nuspecFiles.length;
    for (var i = 0; i < nuspecLength; i++) {
        var nuspecFile = nuspecFiles[i];
        var absoluteNuspecFile = path.resolve(nuspecFile);
        var absoluteNugetPath = path.resolve(settings.nugetPath);
        var absoluteDistributionFolder = path.resolve(settings.dest);
<commit_msg>Updated source module assets and logging of files that are moved.<commit_after>var gulp = require('gulp'),
	uglify = require('gulp-uglify'),
    jshint = require('gulp-jshint'),
    stylish = require('jshint-stylish'),
    rename = require('gulp-rename'),
    replace = require('gulp-replace'),
    ignore = require('gulp-ignore'),
    sourcemaps = require('gulp-sourcemaps'),
	request = require('request'),
	merge = require('merge-stream'),
    fs = require('fs'),
	del = require('del'),
    bump = require('gulp-bump'),
    tap = require('gulp-tap'),
    runSequence = require('run-sequence'),
    git = require('gulp-git'),
    glob = require('glob'),
    path = require('path'),
    shell = require('shelljs');
var args = require('yargs').argv;

var settings = {
    baseProject: 'jquery.dirtyforms',
    src: ['./jquery.dirtyforms.js', './helpers/*.js', './dialogs/*.js'],
    src_assets: ['./README.md', './pkg/*.json'],
    src_module_assets: ['./@(helpers|dialogs)/**/*.json', './@(helpers|dialogs)/**/README.md', './@(helpers|dialogs)/**/LICENSE*'],
    src_json_files: ['./**/*.json', '!./node_modules/**', '!./dist/**'],
    src_readme_files: ['./**/README*', '!./dist/**'],
    dest: './dist/',
    dest_plugins: '/plugins',
    nugetPath: './nuget.exe',
    subModules: [], // All of the git submodule names (individual releases) for the build
    version: '',
    debug: true
};

settings.subModules = getSubmoduleNames();
settings.version = getBuildVersion();
settings.debug = getDebug();

console.log('subModules: ' + settings.subModules);
console.log('Debug mode: ' + settings.debug);


// Builds the distribution files and packs them with NuGet
gulp.task('default', function (cb) {
    runSequence(
        'git-checkout',
        'pack',
        cb);
});

// Cleans the distribution folders
gulp.task('clean', function (cb) {
    del([settings.dest + '**/*.js',
        settings.dest + '**/*.map',
        settings.dest + '**/*.nupkg',
        settings.dest + '**/*.tgz',
        settings.dest + '**/*.css',
        settings.dest + '**/*.png',
        settings.dest + '**/*.gif',
        settings.dest + '**/README.*',
        settings.dest + '**/LICENSE.*',
        settings.dest + '**/*.json'], cb);
});

// Moves the .js files to the distribution folders and creates a minified version and sourcemap
gulp.task('build', ['copy-minified'], function (cb) {
    del([settings.dest + '*.js', settings.dest + '*.map'], cb);
});

// Tests the source files (smoke test)
gulp.task('test', function () {
    return gulp.src(settings.src, { base: './' })
        .pipe(jshint())
        .pipe(jshint.reporter(stylish));
});

gulp.task('copy-minified', ['uglify', 'distribute-module-assets'], function () {
    return gulp.src([settings.dest + '*.js', settings.dest + '*.map'], { base: './' })
        .pipe(rename(function (path) {
            console.log('moving: ' + path.basename)
            path.dirname = path.basename.replace(/\.min(?:\.js)?/g, '');
        }))
        .pipe(gulp.dest(settings.dest))
        .pipe(ignore.exclude(eval('/' + settings.baseProject + '\.min/')))
        // Make a copy of the minified files in the /dist/plugins directory for 
        // CDN distribution.
        .pipe(rename(function (path) {
            console.log('moving: ' + path.basename)
            path.dirname = settings.baseProject + settings.dest_plugins;
        }))
        .pipe(gulp.dest(settings.dest));
});

gulp.task('uglify', ['clean', 'test'], function () {
    return gulp.src(settings.src, { base: './' })
        .pipe(rename(function (path) {
            var baseName = path.basename;
            var dirName = path.dirname;
            if (dirName == 'helpers' || dirName == 'dialogs') {
                path.basename = settings.baseProject + '.' + dirName + '.' + baseName;
            }
            path.dirname = path.basename;
        }))
        .pipe(gulp.dest(settings.dest))
        .pipe(sourcemaps.init())
        .pipe(rename(function (path) {
            path.dirname = '';
            path.extname = '.min.js';
        }))
        .pipe(uglify({
            outSourceMap: true,
            sourceRoot: '/'
        }))
        .pipe(gulp.dest(settings.dest))
        .pipe(sourcemaps.write('.', {
            includeContent: true,
            sourceRoot: '/'
        }))
        .pipe(gulp.dest(settings.dest));
});

gulp.task('distribute-default-license', ['clean'], function () {
    var defaultLicense = './LICENSE*';
    var baseModule = gulp.src(defaultLicense, { base: './' })
        .pipe(rename(function (path) {
            path.dirname = settings.baseProject;
        }))
        .pipe(gulp.dest(settings.dest));

    var merged = merge(baseModule);
    var modulesLength = settings.subModules.length;
    for (var i = 0; i < modulesLength; i++) {
        var subModule = settings.subModules[i];
        var module = gulp.src(defaultLicense, { base: './' })
            .pipe(ignore(settings.baseProject))
            .pipe(gulp.dest(settings.dest + subModule));

        merged.add(module);
    }

    return merged;
});

gulp.task('distribute-assets', ['distribute-default-license'], function () {
    return gulp.src(settings.src_assets, { base: './' })
        .pipe(rename(function (path) {
            path.dirname = settings.baseProject;
        }))
        .pipe(gulp.dest(settings.dest));
});

gulp.task('distribute-module-assets', ['distribute-assets'], function () {
    return gulp.src(settings.src_module_assets, { base: './' })
        .pipe(rename(function (path) {
            var segments = path.dirname.split(/[/\\]/);
            var rootDir = segments[0];
            if (rootDir == 'helpers' || rootDir == 'dialogs') {
                console.log('moving: ' + path.dirname + '/' + path.basename + '.' + path.extname);
                var pkgDir = segments[1].replace('.pkg', '');
                path.dirname = settings.baseProject + '.' + rootDir + '.' + pkgDir;
            }
        }))
        .pipe(gulp.dest(settings.dest));
});

// Runs the build, downloads the NuGet.exe file, and packs the distribution files with NuGet
gulp.task('nuget-pack', ['nuget-download', 'build'], function (cb) {
    console.log('build version: ' + settings.version);

    // Get the nuspec files
    var nuspecFiles = glob.sync("./**/*.nuspec");

    console.log('Nuspec files: ' + nuspecFiles);

    var nuspecLength = nuspecFiles.length;
    for (var i = 0; i < nuspecLength; i++) {
        var nuspecFile = nuspecFiles[i];
        var absoluteNuspecFile = path.resolve(nuspecFile);
        var absoluteNugetPath = path.resolve(settings.nugetPath);
        var absoluteDistributionFolder = path.resolve(settings.dest);

{'fraction_non_alphanumeric': 0.1897810218978102, 'fraction_numerical': 0.0006020016555045527, 'mean_word_length': 2.538338658146965, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4754877', 'n_tokens_mistral': 4186, 'n_tokens_neox': 4159, 'n_words': 808}