<commit_before>// import
var gulp = require('gulp')
var fs = require('fs')
var standard = require('gulp-standard')

// primary tasks
gulp.task('dev', ['setupDev', 'lint'])
gulp.task('prod', ['setupNpm', 'lint'])
gulp.task('lint', ['standard'])

// secondary tasks

// --------------------------------------------------
// Linting
// --------------------------------------------------
gulp.task('standard', function () {
  // standard format for javascript
  var javascript = [
    './hooks/**/*.js',
    './testbed/www/js/**/*.js',
    './gulpfile.js'
  ]

  return gulp.src(javascript)
  .pipe(standard())
  .pipe(standard.reporter('default', {
    breakOnError: true,
    quiet: true
  }))
})

// --------------------------------------------------
// Setup
// --------------------------------------------------
gulp.task('setupDev', function () {
  // setup for development use
  getDevPluginXML()
  setIosNpmOrDev('dev')
})

gulp.task('setupNpm', function () {
  // setup for npm deployment
  genNpmPluginXML()
  setIosNpmOrDev('npm')
})

// TODO: does not work.. need to revise and update package.json -> semantic-release
gulp.task('update-plugin-xml-version', function () {
  // first match only!
  var PLUGIN_XML_VERSION_REGEX = /^\s*version=\"[\d\.]*\"\>$/m // eslint-disable-line
  var versionNumber = require('./package.json').version

  // this will break if plugin.xml is not formatted exactly as we expect
  // so you might end up needing to fix the regex
  for (var target of [ '.xml', '.template.xml' ]) {
    var pluginXML = fs.readFileSync('plugin' + target, 'utf8')
    var newVersionXML = `    version="${versionNumber}">`
    pluginXML = pluginXML.replace(PLUGIN_XML_VERSION_REGEX, newVersionXML)
    fs.writeFileSync('plugin' + target, pluginXML)
  }
})

function getDevPluginXML () {
  // generate plugin.xml for local development
  // here we reference the frameworks instead of all the files directly
  var xml = fs.readFileSync('plugin.template.xml', 'utf-8')

  xml = xml.replace('<!--[Branch Framework Reference]-->', '<framework custom="true" src="src/ios/dependencies/Branch.framework" />')

  fs.writeFileSync('plugin.xml', xml)
}

function genNpmPluginXML () {
  // generate plugin.xml for use as a Cordova plugin
  // here we explode the contents of the frameworks
  var xml = fs.readFileSync('plugin.template.xml', 'utf-8')
  var files = []
  var head = 'src/ios/dependencies/'<commit_msg>chore: updated comments<commit_after>// import
var gulp = require('gulp')
var fs = require('fs')
var standard = require('gulp-standard')

// primary tasks
gulp.task('dev', ['setupDev', 'lint'])
gulp.task('prod', ['setupNpm', 'lint'])
gulp.task('lint', ['standard'])

// --------------------------------------------------
// Linting
// --------------------------------------------------
gulp.task('standard', function () {
  // standard format for javascript
  var javascript = [
    './hooks/**/*.js',
    './testbed/www/js/**/*.js',
    './gulpfile.js'
  ]

  return gulp.src(javascript)
  .pipe(standard())
  .pipe(standard.reporter('default', {
    breakOnError: true,
    quiet: true
  }))
})

// --------------------------------------------------
// Setup
// --------------------------------------------------
gulp.task('setupDev', function () {
  // setup for development use
  getDevPluginXML()
  setIosNpmOrDev('dev')
})

gulp.task('setupNpm', function () {
  // setup for npm deployment
  genNpmPluginXML()
  setIosNpmOrDev('npm')
})

// TODO: does not work. need to revise and update package.json -> semantic-release
gulp.task('update-plugin-xml-version', function () {
  // first match only!
  var PLUGIN_XML_VERSION_REGEX = /^\s*version=\"[\d\.]*\"\>$/m // eslint-disable-line
  var versionNumber = require('./package.json').version

  // this will break if plugin.xml is not formatted exactly as we expect
  // so you might end up needing to fix the regex
  for (var target of [ '.xml', '.template.xml' ]) {
    var pluginXML = fs.readFileSync('plugin' + target, 'utf8')
    var newVersionXML = `    version="${versionNumber}">`
    pluginXML = pluginXML.replace(PLUGIN_XML_VERSION_REGEX, newVersionXML)
    fs.writeFileSync('plugin' + target, pluginXML)
  }
})

function getDevPluginXML () {
  // generate plugin.xml for local development
  // here we reference the frameworks instead of all the files directly
  var xml = fs.readFileSync('plugin.template.xml', 'utf-8')

  xml = xml.replace('<!--[Branch Framework Reference]-->', '<framework custom="true" src="src/ios/dependencies/Branch.framework" />')

  fs.writeFileSync('plugin.xml', xml)
}

function genNpmPluginXML () {
  // generate plugin.xml for use as a Cordova plugin
  // here we explode the contents of the frameworks
  var xml = fs.readFileSync('plugin.template.xml', 'utf-8')
  var files = []
  var head = 'src/ios/dependencies/'
{'fraction_non_alphanumeric': 0.2363899813703167, 'fraction_numerical': 0.001241978886358932, 'mean_word_length': 2.5321637426900585, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 28}, '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': '4278517', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1433, 'n_words': 365}