-
Notifications
You must be signed in to change notification settings - Fork 0
/
grunt.hooks.coffee
39 lines (32 loc) · 1.18 KB
/
grunt.hooks.coffee
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
fs = require 'fs-extra'
path = require 'path'
_ = require 'lodash'
localConfigFile = '.leavesrc.local'
localConfig = null
module.exports = (grunt) ->
if fs.existsSync localConfigFile
localConfig = JSON.parse fs.readFileSync(localConfigFile)
prepareDir = ->
if fs.existsSync 'parse'
fs.removeSync 'parse'
fs.mkdirSync 'parse'
fs.copySync 'dist', path.join('parse', 'public')
if fs.existsSync 'cloud'
fs.copySync 'cloud', path.join('parse', 'cloud')
else
fs.mkdirSync path.join('parse', 'cloud')
fs.mkdirSync path.join('parse', 'config')
configFile = path.join('parse', 'config', 'global.json')
fs.writeFileSync configFile, JSON.stringify(localConfig.parse, null, 4)
grunt.registerTask 'afterCompile', (env) ->
return if env == 'tmp'
unless localConfig.parse
grunt.fail.warn 'Parse config not found. Aborting.'
return
prepareDir()
cloudFiles = fs.readdirSync path.join('parse', 'cloud')
_.each cloudFiles, (file) ->
filepath = path.join('parse', 'cloud', file)
content = fs.readFileSync filepath, 'utf8'
output = _.template(content)(localConfig)
fs.writeFileSync filepath, output