<commit_before>require 'colors'
path = require 'path'
fs   = require 'fs'
eco  = require 'eco'
info = console.info

{Tintan, $, _, E, appXML} = {}

T = (pth) ->
  T.deps.push _ pth

  file _(pth), ->
    info 'create'.green + ' ' + pth
    jake.mkdirP path.dirname @name
    temp = E pth + '.eco'
    if path.existsSync temp
      temp = fs.readFileSync temp, 'utf-8'
      value = eco.render temp, Tintan: Tintan
      fs.writeFileSync @name, value, 'utf-8'
    else
      jake.cpR E(pth), @name

T.deps = []

npm_install = ->
   info 'updating'.green + ' node modules'
   npm = require('child_process').spawn 'npm', ['install', '-l']
   npm.stdout.on 'data', (data)-> process.stdout.write(data)
   npm.stderr.on 'data', (data)-> process.stderr.write(data)
   npm.on 'exit', (code)=>
    fail('npm install -l: failed with code '+code) if code != 0
    complete()

class Boot

  ready: ->
    files = ['package.json', 'Jakefile.coffee', 'plugins/tintan/plugin.py']
    return false for v in files when jake.Task['boot:'+_(v)].shouldRunAction()
    true

  constructor: (Ti)->

    Tintan = Ti
    {$, appXML} = Tintan
    {E, _} = $

    namespace 'boot', ->

      T 'plugins/tintan/plugin.py'

      desc 'Install the Tintan plugin for Titanium Studio'
      task 'plugin.py': _ 'plugins/tintan/plugin.py'


      desc 'Register plugin on tiapp.xml'
      task 'plugin.xml', ->
        unless appXML.plugin()
          info 'register'.green + ' tintan plugin on tiapp.xml'
          xml = appXML.doc
          plugins = xml.get './plugins'
          unless plugins
            plugins = xml.root().node 'plugins', ''
          plugin = plugins.node 'plugin', 'tintan'
          plugin.attr version: Tintan.version
          xml.encoding 'utf-8'
          fs.writeFileSync appXML.file, xml.toString(), 'utf-8'
      T.deps.push 'plugin.xml'

      T 'package.json'
      desc 'Create a generic package.json'
      task 'package.json': _ 'package.json'

      T 'Jakefile.coffee'
      desc 'Create a basic Jakefile'
      task 'Jakefile.coffee': _ 'Jakefile.coffee'

      desc 'Install node modules with npm'
      task 'npm', [_('package.json')], npm_install, async: true
      T.deps.push 'npm'

      desc 'Initialize this project to use Tintan'
      task 'init', T.deps, ->
        info 'Tintan initialized'.bold.italic

module.exports = (Tintan)-> new Boot Tintan<commit_msg>Tell the user to take a look at his new jakefile<commit_after>require 'colors'
path = require 'path'
fs   = require 'fs'
eco  = require 'eco'
info = console.info

{Tintan, $, _, E, appXML} = {}

T = (pth) ->
  T.deps.push _ pth

  file _(pth), ->
    info 'create'.green + ' ' + pth
    jake.mkdirP path.dirname @name
    temp = E pth + '.eco'
    if path.existsSync temp
      temp = fs.readFileSync temp, 'utf-8'
      value = eco.render temp, Tintan: Tintan
      fs.writeFileSync @name, value, 'utf-8'
    else
      jake.cpR E(pth), @name

T.deps = []

npm_install = ->
   info 'updating'.green + ' node modules'
   npm = require('child_process').spawn 'npm', ['install', '-l']
   npm.stdout.on 'data', (data)-> process.stdout.write(data)
   npm.stderr.on 'data', (data)-> process.stderr.write(data)
   npm.on 'exit', (code)=>
    fail('npm install -l: failed with code '+code) if code != 0
    complete()

class Boot

  ready: ->
    files = ['package.json', 'Jakefile.coffee', 'plugins/tintan/plugin.py']
    return false for v in files when jake.Task['boot:'+_(v)].shouldRunAction()
    true

  constructor: (Ti)->

    Tintan = Ti
    {$, appXML} = Tintan
    {E, _} = $

    namespace 'boot', ->

      T 'plugins/tintan/plugin.py'

      desc 'Install the Tintan plugin for Titanium Studio'
      task 'plugin.py': _ 'plugins/tintan/plugin.py'


      desc 'Register plugin on tiapp.xml'
      task 'plugin.xml', ->
        unless appXML.plugin()
          info 'register'.green + ' tintan plugin on tiapp.xml'
          xml = appXML.doc
          plugins = xml.get './plugins'
          unless plugins
            plugins = xml.root().node 'plugins', ''
          plugin = plugins.node 'plugin', 'tintan'
          plugin.attr version: Tintan.version
          xml.encoding 'utf-8'
          fs.writeFileSync appXML.file, xml.toString(), 'utf-8'
      T.deps.push 'plugin.xml'

      T 'package.json'
      desc 'Create a generic package.json'
      task 'package.json': _ 'package.json'

      T 'Jakefile.coffee'
      desc 'Create a basic Jakefile'
      task 'Jakefile.coffee': _ 'Jakefile.coffee'

      desc 'Install node modules with npm'
      task 'npm', [_('package.json')], npm_install, async: true
      T.deps.push 'npm'

      desc 'Initialize this project to use Tintan'
      task 'init', T.deps, ->
        info 'Tintan initialized'.bold.italic
        info 'Take a look at your Jakefile.coffee'

module.exports = (Tintan)-> new Boot Tintan
{'fraction_non_alphanumeric': 0.14406430338004947, 'fraction_numerical': 0.002061005770816158, 'mean_word_length': 2.4540925266903915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 18}, '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': '2188821', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1635, 'n_words': 446}