<commit_before>'use strict';

var gulp = require('gulp-param')(require('gulp'), process.argv),
    plugins = require('gulp-load-plugins')(),
    spawn = require('child_process').spawn,
    swaggerCodeGenerator = require('./api/swagger/scripts/swagger-code-generator'),
    spawned;

/**
 * $ gulp serve
 * description: launch the server. If there's a server already running, kill it.
 */
gulp.task('serve', function () {
    if (spawned) {
        spawned.kill();
    }
    spawned = spawn('node', ['app.js'], {stdio: 'inherit'});
    spawned.on('close', function (code) {
        if (code === 8) {
            plugins.util.log('Error detected, waiting for changes...');
        }
    });
});

/**
 * $ gulp swagger
 * description: Install swagger in your api and generates code based on the SCHEMA declared automatically
 * usage:  gulp swagger --framework nodejs --destinationFile slapi --fileFormat .js --destinationFolder ./swagger/
 * OR   gulp swagger --framework angularjs --destinationFile slapi --fileFormat .js --destinationFolder ./swagger/
 * additional info: fileFormat and destinationFile must be different look swaggerCodeGenerator()
 */
gulp.task('swagger', function (framework, destinationFile, fileFormat, destinationFolder) {
    gulp.start('schema');
    gulp.start('swagger-ui');
    plugins.util.log(swaggerCodeGenerator(framework || 'angularjs', destinationFile || 'slapi', fileFormat || '.js', destinationFolder || './api/swagger/'));
});

/**
 * $ gulp schema
 * description: generates the schema using the spec.js
 */
gulp.task('schema', function () {
    gulp.src('api/swagger/swagger.yaml')
        .pipe(plugins.swagger('spec-schema.json'))
        .pipe(gulp.dest('api/swagger/schemas'))
        .on('finish', function () {
            gulp.start('swagger-code-gen')
                .once('end', function () {
                    process.exit();
                });
        });
});

/**
 * $ gulp init
 * description: modifies swagger index.html to point to our project api spec schema
 */
gulp.task('init', function () {
    gulp.src(['node_modules/swagger-ui/dist/index.html'])
        .pipe(plugins.replace('http://petstore.swagger.io/v2/swagger.json', 'http://localhost:3002/spec'))//TODO this is hacky, i dont like it but i cant see any cleaner way to be able to have swagger updated automatically and not having to manually install it
        .pipe(gulp.dest('api/swagger/swagger-ui'));
});


/**
 * $ gulp swagger-ui
 * description: Copies the swagger-ui from swagger to out local project automatically
 */
gulp.task('swagger-ui', ['init'], function () {
    gulp.src(['node_modules/swagger-ui/dist/{,*/}*', '!node_modules/swagger-ui/dist/index.html'])
        .pipe(gulp.dest('api/swagger/swagger-ui'));
});

/**
 * $ gulp swagger-code-gen
 * description: Calls swagger-code-gen to autogenerates code from the spec.js
 * usage:  gulp swagger-code-gen --framework nodejs --destinationFile slapi --fileFormat .js --destinationFolder ./swagger/
 * OR   gulp swagger-code-gen --framework angularjs --destinationFile slapi --fileFormat .js --destinationFolder ./swagger/
 * additional info: fileFormat and destinationFile must be different look swaggerCodeGenerator();
 */
gulp.task('swagger-code-gen', function (framework, destinationFile, fileFormat, destinationFolder) {
    swaggerCodeGenerator(framework || 'angularjs', destinationFile || 'slapi', fileFormat || '.js', destinationFolder || './api/swagger/');
});


/**
 * $ gulp test
 * description: run tests using mocha and istambul lcov reporter
 */
gulp.task('test', function () {
    gulp.src(['api/**/*.js', 'app.js', '!api/swagger/*'])
        .pipe(plugins.istanbul()) // Covering files
        .pipe(plugins.istanbul.hookRequire()) // Force `require` to return covered files
        .on('finish', function () {
            gulp.src(['test/**/*.js'])
                .pipe(plugins.mocha({reporter: process.env.TRAVIS ? 'spec' : 'spec'}))
                .pipe(plugins.istanbul.writeReports()) // Creating the reports after tests ran
                .pipe(plugins.istanbul.enforceThresholds({thresholds: {global: 1}})) // Enforce a coverage of at least 1%
                .once('end', function () {
                    process.exit();
                });
        });
});

/**
 * $ gulp lint
 * description: linting with plugins.jshint
 */
gulp.task('lint', function () {
    return gulp.src(['api/{,*/}*.js', 'gulpfile.js', '!api/swagger/*'])
        .pipe(plugins.jshint())
        .pipe(plugins.jshint.reporter('default'));
});

/**<commit_msg>:tada: pipeline working ci-cd<commit_after>'use strict';

var gulp = require('gulp-param')(require('gulp'), process.argv),
    plugins = require('gulp-load-plugins')(),
    spawn = require('child_process').spawn,
    swaggerCodeGenerator = require('./api/swagger/scripts/swagger-code-generator'),
    spawned;

/**
 * $ gulp serve
 * description: launch the server. If there's a server already running, kill it.
 */
gulp.task('serve', function () {
    if (spawned) {
        spawned.kill();
    }
    spawned = spawn('node', ['app.js'], {stdio: 'inherit'});
    spawned.on('close', function (code) {
        if (code === 8) {
            plugins.util.log('Error detected, waiting for changes...');
        }
    });
});

/**
 * $ gulp swagger
 * description: Install swagger in your api and generates code based on the SCHEMA declared automatically
 * usage:  gulp swagger --framework nodejs --destinationFile slapi --fileFormat .js --destinationFolder ./swagger/
 * OR   gulp swagger --framework angularjs --destinationFile slapi --fileFormat .js --destinationFolder ./swagger/
 * additional info: fileFormat and destinationFile must be different look swaggerCodeGenerator()
 */
gulp.task('swagger', function (framework, destinationFile, fileFormat, destinationFolder) {
    gulp.start('schema');
    gulp.start('swagger-ui');
    plugins.util.log(swaggerCodeGenerator(framework || 'angularjs', destinationFile || 'slapi', fileFormat || '.js', destinationFolder || './api/swagger/'));
});

/**
 * $ gulp schema
 * description: generates the schema using the spec.js
 */
gulp.task('schema', function () {
    gulp.src('api/swagger/swagger.yaml')
        .pipe(plugins.swagger('spec-schema.json'))
        .pipe(gulp.dest('api/swagger/schemas'))
        .on('finish', function () {
            gulp.start('swagger-code-gen')
                .once('end', function () {
                    process.exit();
                });
        });
});

/**
 * $ gulp init
 * description: modifies swagger index.html to point to our project api spec schema
 */
gulp.task('init', function () {
    gulp.src(['node_modules/swagger-ui/dist/index.html'])
        .pipe(plugins.replace('http://petstore.swagger.io/v2/swagger.json', 'http://localhost:3002/spec'))//TODO this is hacky, i dont like it but i cant see any cleaner way to be able to have swagger updated automatically and not having to manually install it
        .pipe(gulp.dest('api/swagger/swagger-ui'));
});


/**
 * $ gulp swagger-ui
 * description: Copies the swagger-ui from swagger to out local project automatically
 */
gulp.task('swagger-ui', ['init'], function () {
    gulp.src(['node_modules/swagger-ui/dist/{,*/}*', '!node_modules/swagger-ui/dist/index.html'])
        .pipe(gulp.dest('api/swagger/swagger-ui'));
});

/**
 * $ gulp swagger-code-gen
 * description: Calls swagger-code-gen to autogenerates code from the spec.js
 * usage:  gulp swagger-code-gen --framework nodejs --destinationFile slapi --fileFormat .js --destinationFolder ./swagger/
 * OR   gulp swagger-code-gen --framework angularjs --destinationFile slapi --fileFormat .js --destinationFolder ./swagger/
 * additional info: fileFormat and destinationFile must be different look swaggerCodeGenerator();
 */
gulp.task('swagger-code-gen', function (framework, destinationFile, fileFormat, destinationFolder) {
    swaggerCodeGenerator(framework || 'angularjs', destinationFile || 'slapi', fileFormat || '.js', destinationFolder || './api/swagger/');
});


/**
 * $ gulp test
 * description: run tests using mocha and istambul lcov reporter
 */
gulp.task('test', function () {
    gulp.src(['api/**/*.js', 'app.js', '!api/swagger/*'])
        .pipe(plugins.istanbul()) // Covering files
        .pipe(plugins.istanbul.hookRequire()) // Force `require` to return covered files
        .on('finish', function () {
            gulp.src(['test/**/*.js'])
                .pipe(plugins.mocha({reporter: process.env.TRAVIS ? 'spec' : 'nyan'}))
                .pipe(plugins.istanbul.writeReports()) // Creating the reports after tests ran
                .pipe(plugins.istanbul.enforceThresholds({thresholds: {global: 1}})) // Enforce a coverage of at least 1%
                .once('end', function () {
                    process.exit();
                });
        });
});

/**
 * $ gulp lint
 * description: linting with plugins.jshint
 */
gulp.task('lint', function () {
    return gulp.src(['api/{,*/}*.js', 'gulpfile.js', '!api/swagger/*'])
        .pipe(plugins.jshint())
        .pipe(plugins.jshint.reporter('default'));
});

/**
{'fraction_non_alphanumeric': 0.16564080017586283, 'fraction_numerical': 0.0017586282699494395, 'mean_word_length': 3.1190583974649164, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1112243', 'n_tokens_mistral': 2731, 'n_tokens_neox': 2694, 'n_words': 653}