<commit_before>const fs = require('fs')
const path = require('path')
const gulp = require('gulp')
const del = require('del')
const gzip = require('gulp-gzip')
const s3 = require('gulp-s3')
const through2 = require('through2')
const Vinyl = require('vinyl')
const UglifyJS = require('uglify-js')
const build = require('./build')
const packageInfo = require('../package.json')
const preamble = require('./preamble.js')
const execSync = require('child_process').execSync
const git = require('gulp-git')

// internals

const version = packageInfo.version
const latestNpmVersion = execSync(`npm view ${packageInfo.name} version`).toString('utf8').replace('\n', '')

// configs

const srcDir = 'build'
const destDir = 'release'
const gitCommitMessage = 'Release '+version
const awsConfig = {
  bucket: '3d.io',
  region: 'eu-west-1',
  key: process.env.AWS_ACCESS_KEY_ID,
  secret: process.env.AWS_SECRET_ACCESS_KEY
}
const awsDir = {
  version: `releases/3dio-js/${version}/`,
  latestMinor: `releases/3dio-js/${getLatestMinor(version)}/`,
  latestPatch: `releases/3dio-js/${getLatestPatch(version)}/`
}

// tasks

const release = gulp.series(
  npmCheckVersion,
  build,
  cleanDestDir,
  uglify,
  gitTag,
  gitCommit,
  gitPush,
  npmPublish,
  s3Upload
)

function cleanDestDir () {
  return del([destDir]).then(function () {
    fs.mkdirSync(process.cwd() + `/${destDir}`, 0744)
    fs.mkdirSync(process.cwd() + `/${destDir}/${version}`, 0744)
  })
}

function uglify () {
  return gulp.src(srcDir + '/*.js').pipe(through2.obj((inputFile, enc, cb) => {
    // process files only
    if (!inputFile.isBuffer()) return
    // get filename without extension
    var cwd = process.cwd()
    var sourceBasename = inputFile.basename.substr(0, inputFile.basename.length - 3)
    var targetBasename = sourceBasename //+'-'+version
    // decode text from vinyl object
    const ugly = UglifyJS.minify(inputFile.contents.toString(enc), {
      warnings: true, mangle: true, ie8: false,
      compress: {dead_code: true, toplevel: true, passes: 3},
      output: {preamble: preamble.text, beautify: false},
      sourceMap: {
        content: read(`${srcDir}/${sourceBasename}.js.map`),
        url: `${targetBasename}.min.js.map`
      }
    })
    if (ugly.warnings) console.log('UGLIFY WARNINGS: ', ugly.warnings)
    if (ugly.error) return Promise.reject(ugly.error)
    // write files
    fs.writeFileSync(`${cwd}/${destDir}/${version}/${targetBasename}.min.js.map`, ugly.map)
    fs.writeFileSync(`${cwd}/${destDir}/${version}/${targetBasename}.min.js`, ugly.code)
    // gulp callback
    cb()
  }))
}

function gitTag () {
  return new Promise(function (resolve, reject) {
    git.tag('v'+version, '', function (err) {
      if (err) throw err
      resolve()<commit_msg>Continue release if git tag fails<commit_after>const fs = require('fs')
const path = require('path')
const gulp = require('gulp')
const del = require('del')
const gzip = require('gulp-gzip')
const s3 = require('gulp-s3')
const through2 = require('through2')
const Vinyl = require('vinyl')
const UglifyJS = require('uglify-js')
const build = require('./build')
const packageInfo = require('../package.json')
const preamble = require('./preamble.js')
const execSync = require('child_process').execSync
const git = require('gulp-git')

// internals

const version = packageInfo.version
const latestNpmVersion = execSync(`npm view ${packageInfo.name} version`).toString('utf8').replace('\n', '')

// configs

const srcDir = 'build'
const destDir = 'release'
const gitCommitMessage = 'Release '+version
const awsConfig = {
  bucket: '3d.io',
  region: 'eu-west-1',
  key: process.env.AWS_ACCESS_KEY_ID,
  secret: process.env.AWS_SECRET_ACCESS_KEY
}
const awsDir = {
  version: `releases/3dio-js/${version}/`,
  latestMinor: `releases/3dio-js/${getLatestMinor(version)}/`,
  latestPatch: `releases/3dio-js/${getLatestPatch(version)}/`
}

// tasks

const release = gulp.series(
  npmCheckVersion,
  build,
  cleanDestDir,
  uglify,
  gitTag,
  gitCommit,
  gitPush,
  npmPublish,
  s3Upload
)

function cleanDestDir () {
  return del([destDir]).then(function () {
    fs.mkdirSync(process.cwd() + `/${destDir}`, 0744)
    fs.mkdirSync(process.cwd() + `/${destDir}/${version}`, 0744)
  })
}

function uglify () {
  return gulp.src(srcDir + '/*.js').pipe(through2.obj((inputFile, enc, cb) => {
    // process files only
    if (!inputFile.isBuffer()) return
    // get filename without extension
    var cwd = process.cwd()
    var sourceBasename = inputFile.basename.substr(0, inputFile.basename.length - 3)
    var targetBasename = sourceBasename //+'-'+version
    // decode text from vinyl object
    const ugly = UglifyJS.minify(inputFile.contents.toString(enc), {
      warnings: true, mangle: true, ie8: false,
      compress: {dead_code: true, toplevel: true, passes: 3},
      output: {preamble: preamble.text, beautify: false},
      sourceMap: {
        content: read(`${srcDir}/${sourceBasename}.js.map`),
        url: `${targetBasename}.min.js.map`
      }
    })
    if (ugly.warnings) console.log('UGLIFY WARNINGS: ', ugly.warnings)
    if (ugly.error) return Promise.reject(ugly.error)
    // write files
    fs.writeFileSync(`${cwd}/${destDir}/${version}/${targetBasename}.min.js.map`, ugly.map)
    fs.writeFileSync(`${cwd}/${destDir}/${version}/${targetBasename}.min.js`, ugly.code)
    // gulp callback
    cb()
  }))
}

function gitTag () {
  return new Promise(function (resolve, reject) {
    git.tag('v'+version, '', function (err) {
      if (err) {
        // graceful error handling because not critical. i.e. tag may already exist when
        // a previous release failed at a later step and the release has to be repeated.
        console.warn('Git tag error: ', err)
      }
      resolve()
{'fraction_non_alphanumeric': 0.16381248918872168, 'fraction_numerical': 0.008303061754021795, 'mean_word_length': 3.8466051969823973, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '573418', 'n_tokens_mistral': 1990, 'n_tokens_neox': 1958, 'n_words': 427}