Blame view

node_modules/yamljs/Cakefile 4.19 KB
f7563de62   Palak Handa   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
  
  {exec, spawn}   = require 'child_process'
  fs              = require 'fs'
  path            = require 'path'
  esc             = (arg) -> (''+arg).replace(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF
  ])/gm, '\\').replace(/
  /g, "'
  '").replace(/^$/, "''")
  
  srcDir = path.normalize __dirname+'/src'
  libDir = path.normalize __dirname+'/lib'
  libDebugDir = path.normalize __dirname+'/lib/debug'
  distDir = path.normalize __dirname+'/dist'
  cliDir = path.normalize __dirname+'/cli'
  binDir = path.normalize __dirname+'/bin'
  specDir = path.normalize __dirname+'/test/spec'
  modulesDir = path.normalize __dirname+'/node_modules'
  
  task 'build', 'build project', ->
  
      # Compile
      do compile = ->
          unless fs.existsSync libDir
              fs.mkdirSync libDir
          unless fs.existsSync libDir+'/Exception'
              fs.mkdirSync libDir+'/Exception'
          toCompile = 'Yaml Utils Unescaper Pattern Parser Inline Escaper Dumper Exception/ParseException Exception/ParseMore Exception/DumpException'.split ' '
          do compileOne = ->
              name = toCompile.shift()
              outputDir = (if '/' in name then libDir+'/Exception' else libDir)
              exec 'coffee -b -o '+esc(outputDir)+' -c '+esc(srcDir+'/'+name+'.coffee'), (err, res) ->
                  if err then throw err
  
                  console.log "Compiled #{name}.js"
                  if toCompile.length
                      compileOne()
                  else
                      debugCompile()
  
      # Debug compile
      debugCompile = ->
          unless fs.existsSync libDebugDir
              fs.mkdirSync libDebugDir
          unless fs.existsSync libDebugDir+'/Exception'
              fs.mkdirSync libDebugDir+'/Exception'
          toCompile = 'Yaml Utils Unescaper Pattern Parser Inline Escaper Dumper Exception/ParseException Exception/ParseMore Exception/DumpException'.split ' '
          do compileOne = ->
              name = toCompile.shift()
              outputDir = (if '/' in name then libDebugDir+'/Exception' else libDebugDir)
              exec 'coffee -m -b -o '+esc(outputDir)+' -c '+esc(srcDir+'/'+name+'.coffee'), (err, res) ->
                  if err then throw err
  
                  console.log "Compiled #{name}.js (debug)"
                  if toCompile.length
                      compileOne()
                  else
                      browserify()
  
      # Browserify
      unless fs.existsSync distDir
          fs.mkdirSync distDir
      browserify = ->
          exec 'browserify -t coffeeify --extension=".coffee" '+esc(srcDir+'/Yaml.coffee')+' > '+esc(distDir+'/yaml.js'), (err, res) ->
              if err then throw err
  
              console.log "Browserified yaml.js"
              exec 'browserify --debug -t coffeeify --extension=".coffee" '+esc(srcDir+'/Yaml.coffee')+' > '+esc(distDir+'/yaml.debug.js'), (err, res) ->
                  if err then throw err
  
                  console.log "Browserified yaml.js (debug)"
                  minify()
  
      # Minify
      minify = ->
          exec 'uglifyjs --mangle sort '+esc(distDir+'/yaml.js')+' > '+esc(distDir+'/yaml.min.js'), (err, res) ->
              if err then throw err
  
              console.log "Minified yaml.min.js"
              compileSpec()
  
      # Compile spec
      compileSpec = ->
          exec 'coffee -b -c '+esc(specDir+'/YamlSpec.coffee'), (err, res) ->
              if err then throw err
  
              console.log "Compiled YamlSpec.js"
              compileCLI()
  
      # Compile CLI
      compileCLI = ->
          unless fs.existsSync binDir
              fs.mkdirSync binDir
  
          # yaml2json
          str = fs.readFileSync cliDir+'/yaml2json.js'
          str = "#!/usr/bin/env node
  " + str
          fs.writeFileSync binDir+'/yaml2json', str
          fs.chmodSync binDir+'/yaml2json', '755'
          console.log "Bundled yaml2json"
  
          # json2yaml
          str = fs.readFileSync cliDir+'/json2yaml.js'
          str = "#!/usr/bin/env node
  " + str
          fs.writeFileSync binDir+'/json2yaml', str
          fs.chmodSync binDir+'/json2yaml', '755'
          console.log "Bundled json2yaml"
  
  
  task 'test', 'test project', ->
  
      # Test
      spawn 'node', [modulesDir+'/jasmine-node/lib/jasmine-node/cli.js', '--verbose', '--coffee', specDir+'/YamlSpec.coffee'], stdio: "inherit"
  
  
  task 'doc', 'generate documentation', ->
  
      # Generate
      spawn 'codo', [srcDir], stdio: "inherit"