<commit_before>const fs = require('fs');
const path = require('path');
const copy = require('copy');
const install = require('gulp-install');
const zip = require('gulp-zip');
const del = require('del');
const gutil = require('gulp-util');
const tsPipeline = require('gulp-webpack-typescript-pipeline');
const AWS = require('aws-sdk');
const localServer = require('./localServer');
const awsLambda = require('node-aws-lambda');

const handleError = (msg) => {
  gutil.log(gutil.colors.red('ERROR!', msg));
  process.exit(1);
};

const getLambdaConfig = (lambdaDir) => {
  const configPath = path.join(lambdaDir, 'lambda-config.js');
  try {
    fs.existsSync(configPath);
    return require(configPath);
  } catch (e) {
    return {};
  }
};


const runLocalServer = (lambdaDir) => {
  localServer.runServer(path.join(lambdaDir, 'index.ts'), getLambdaConfig(lambdaDir));
};

const registerBuildGulpTasks = (gulp, lambdaDir) => {
  const lambdaName = lambdaDir.split(path.sep).pop();
  const pathToLambda = path.join(lambdaDir, 'index.ts');
  const distRootDir = path.join(lambdaDir, 'dist');
  const dist = path.join(distRootDir, lambdaName);
  const config = getLambdaConfig(lambdaDir);
  if (config.region) {
    AWS.region = config.region;
  }

  if (!config.functionName) {
    config.functionName = lambdaName;
  }

  // check that lambda exists
  try {
    fs.existsSync(pathToLambda);
  } catch (e) {
    console.log(e);
    handleError(`${pathToLambda} does not exist`);
  }

  const runSequence = require('run-sequence').use(gulp);
  const lambda = new AWS.Lambda({
    apiVersion: '2015-03-31',
    region: config.region || 'us-west-2',
    accessKeyId: 'accessKeyId' in config ? config.accessKeyId : '',
    secretAccessKey: 'secretAccessKey' in config ? config.secretAccessKey : '',
    sessionToken: '<PASSWORD>Token' in config ? config.sessionToken : ''
  });

  const tsOptions = {
    entryPoints: {
      index: pathToLambda
    },
    outputDir: dist
  };

  tsPipeline.registerBuildGulpTasks(gulp, tsOptions);

  gulp.task('lambda:clean', (done) => {
    del(distRootDir).then(() => {
      done();
    });
  });

  gulp.task('lambda:run', () => {
    runLocalServer(lambdaDir, lambdaName);
  });

  gulp.task('lambda:info', (done) => {
    lambda.getFunction({ FunctionName: lambdaName }, (err) => {
      if (err) {
        if (err.statusCode === 404) {
          gutil.log(`Unable to find lambda function ${lambdaName}. Verify the lambda function name and AWS region are correct.`);
        } else {
          gutil.log('AWS API request failed. Check your AWS credentials and permissions.');
        }
      }
      done();
    });
  });

  gulp.task('lambda:build', ['tsPipeline:build:release'], (done) => {
    done();
  });

  gulp.task('lambda:npm', () => {
    return gulp.src(path.join(pathToLambda, 'package.json'))
      .pipe(gulp.dest(dist))
      .pipe(install({ production: true })
    );
  });

  gulp.task('lambda:zip', ['lambda:build', 'lambda:npm'], () => {<commit_msg>make info actually do something<commit_after>const fs = require('fs');
const path = require('path');
const copy = require('copy');
const install = require('gulp-install');
const zip = require('gulp-zip');
const del = require('del');
const gutil = require('gulp-util');
const tsPipeline = require('gulp-webpack-typescript-pipeline');
const AWS = require('aws-sdk');
const localServer = require('./localServer');
const awsLambda = require('node-aws-lambda');

const handleError = (msg) => {
  gutil.log(gutil.colors.red('ERROR!', msg));
  process.exit(1);
};

const getLambdaConfig = (lambdaDir) => {
  const configPath = path.join(lambdaDir, 'lambda-config.js');
  try {
    fs.existsSync(configPath);
    return require(configPath);
  } catch (e) {
    return {};
  }
};


const runLocalServer = (lambdaDir) => {
  localServer.runServer(path.join(lambdaDir, 'index.ts'), getLambdaConfig(lambdaDir));
};

const registerBuildGulpTasks = (gulp, lambdaDir) => {
  const lambdaName = lambdaDir.split(path.sep).pop();
  const pathToLambda = path.join(lambdaDir, 'index.ts');
  const distRootDir = path.join(lambdaDir, 'dist');
  const dist = path.join(distRootDir, lambdaName);
  const config = getLambdaConfig(lambdaDir);
  if (config.region) {
    AWS.region = config.region;
  }

  if (!config.functionName) {
    config.functionName = lambdaName;
  }

  // check that lambda exists
  try {
    fs.existsSync(pathToLambda);
  } catch (e) {
    console.log(e);
    handleError(`${pathToLambda} does not exist`);
  }

  const runSequence = require('run-sequence').use(gulp);
  const lambda = new AWS.Lambda({
    apiVersion: '2015-03-31',
    region: config.region || 'us-west-2',
    accessKeyId: 'accessKeyId' in config ? config.accessKeyId : '',
    secretAccessKey: 'secretAccessKey' in config ? config.secretAccessKey : '',
    sessionToken: 'sessionToken' in config ? config.sessionToken : ''
  });

  const tsOptions = {
    entryPoints: {
      index: pathToLambda
    },
    outputDir: dist
  };

  tsPipeline.registerBuildGulpTasks(gulp, tsOptions);

  gulp.task('lambda:clean', (done) => {
    del(distRootDir).then(() => {
      done();
    });
  });

  gulp.task('lambda:run', () => {
    runLocalServer(lambdaDir, lambdaName);
  });

  gulp.task('lambda:info', (done) => {
    lambda.getFunction({ FunctionName: lambdaName }, (err, data) => {
      if (err) {
        if (err.statusCode === 404) {
          gutil.log(`Unable to find lambda function ${lambdaName}. Verify the lambda function name and AWS region are correct.`);
        } else {
          gutil.log('AWS API request failed. Check your AWS credentials and permissions.');
        }
      }
      console.log(data);
      done();
    });
  });

  gulp.task('lambda:build', ['tsPipeline:build:release'], (done) => {
    done();
  });

  gulp.task('lambda:npm', () => {
    return gulp.src(path.join(pathToLambda, 'package.json'))
      .pipe(gulp.dest(dist))
      .pipe(install({ production: true })
    );
  });

  gulp.task('lambda:zip', ['lambda:build', 'lambda:npm'], () => {
{'fraction_non_alphanumeric': 0.1705183228788379, 'fraction_numerical': 0.004291845493562232, 'mean_word_length': 3.6607692307692306, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 28, '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': '28251', 'n_tokens_mistral': 1961, 'n_tokens_neox': 1930, 'n_words': 404}