This repository has been archived by the owner on Sep 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathGruntfile.coffee
116 lines (103 loc) · 3.14 KB
/
Gruntfile.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
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
path = require "path"
renameCoffe2js = (dest, matchedSrcPath, opts) ->
path.join dest, path.basename(matchedSrcPath,'.coffee') + '.js'
renameJs2min = (dest, matchedSrcPath, opts) ->
path.join dest, path.basename(matchedSrcPath,'.js') + '.min.js'
banner =
"""
/*!
<%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today(\"yyyy-mm-dd\") %>
This program is distributed under the terms of the <%= pkg.license %> license.
Copyright (c) 2011-<%= grunt.template.today(\"yyyy\") %> <%= pkg.author %>
*/\n
"""
module.exports = (grunt) ->
grunt.initConfig
pkg: grunt.file.readJSON "package.json"
concat:
options:
banner: banner
core:
files:
"dist/scaleApp.js": ["dist/scaleApp.js"]
full:
files:
"dist/scaleApp.full.js": ["dist/scaleApp.full.js"]
coffee:
core:
options:
join: true
files:
"dist/scaleApp.js": [
"src/Util.coffee"
"src/Mediator.coffee"
"src/Core.coffee"
"src/scaleApp.coffee" ]
full:
options:
join: true
files:
"dist/scaleApp.full.js": [
"src/Util.coffee",
"src/Mediator.coffee"
"src/Core.coffee"
"src/scaleApp.coffee"
"plugins/src/*.coffee" ]
plugins:
expand: true
flatten: true
cwd: 'plugins/src'
src: ['*.coffee']
dest: 'dist/plugins/'
rename: renameCoffe2js
uglify:
options:
banner: banner
mangle:
toplevel: false
squeeze:
dead_code: true
codegen:
quote_keys: false
core:
files:
'dist/scaleApp.min.js': ["dist/scaleApp.js"]
full:
files:
'dist/scaleApp.full.min.js': ["dist/scaleApp.full.js"]
plugins:
expand: true
flatten: true
cwd: 'dist/plugins/'
src: ["*.js","!*.min.js"]
dest: 'dist/plugins/'
rename: renameJs2min
watch:
src:
files: ["src/*.coffee", "src/**/*.coffee"]
tasks: ["coffee"]
grunt.loadNpmTasks "grunt-contrib-coffee"
grunt.loadNpmTasks "grunt-contrib-watch"
grunt.loadNpmTasks "grunt-contrib-uglify"
grunt.loadNpmTasks "grunt-contrib-concat"
grunt.registerTask "default", ["coffee", "concat", "uglify" ]
# Quick and dirty task to build a custom bundle
# Does s.o. know how to do that properly?
grunt.registerTask "custom", "create a custom bundle", ->
if @args.length is 0
grunt.warn @name + ", no plugins specified"
else
base = grunt.file.read("./dist/scaleApp.js")
plugins = ""
i = 0
while i < @args.length
try
plugins += "\n" + grunt.file.read("./dist/plugins/scaleApp." + @args[i] + ".js")
catch e
console.log e
grunt.warn "could not find \"" + @args[i] + "\" plugin"
i++
customBuild = base + "\n" + plugins
grunt.file.write "./dist/scaleApp.custom.js", customBuild
min = require("uglify-js").minify customBuild, fromString:true
grunt.file.write "./dist/scaleApp.custom.min.js", min.code