forked from butterproject/butter-desktop-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.coffee
213 lines (182 loc) · 4.98 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
os = require 'os'
livereload = require 'electron-livereload'
electron = livereload.server()
platform = os.platform()
{ normalize, sep } = require 'path'
if platform is 'darwin'
platform = 'osx'
if platform in [ 'linux', 'osx' ]
platform = platform + os.arch().replace 'x', ''
module.exports = (grunt) ->
grunt.initConfig
config:
platform: platform
env: 'dev'
pkg: grunt.file.readJSON 'package.json'
clean:
build: src: [ 'build' ]
dist: src: [ 'dist' ]
coffee:
app:
options:
bare: true
join: true
files: 'build/js/app.js': ['src/client/*.coffee', 'src/client/**/**.coffee']
server:
expand: true
flatten: true
cwd: 'src/server'
src: [ '*.coffee' ]
dest: 'build/server/'
ext: '.js'
main:
expand: true
cwd: 'src/scripts'
src: [ '**/*.coffee' ]
dest: 'build/scripts/'
ext: '.js'
watch:
options:
nospawn : true
client:
files: [
'src/client/*.client'
'src/client/**/*.coffee'
'src/scripts/**/*.coffee'
'src/client/*.html'
'src/client/**/*.html'
],
tasks: ['coffee', 'ngtemplates', 'ngAnnotate', 'restart-electron']
stylus:
files: ['src/**/*.styl'],
tasks: ['stylus', 'restart-electron']
server:
files: ['src/server/*.coffee', 'src/server/**/*.coffee'],
tasks: ['coffee', 'restart-electron']
# https://www.npmjs.com/package/grunt-angular-templates
ngtemplates:
ng:
cwd: 'src/client'
src: ['**/*.html']
dest: 'build/js/templates.js'
# https://www.npmjs.com/package/grunt-ng-annotate
ngAnnotate:
build:
files: 'build/js/app.js': ['build/js/app.js']
concat:
js:
src: [
'src/vendor/js/**/*.js'
'src/vendor/js/**'
]
dest: 'build/js/vendor.js'
css:
src: [
'src/vendor/css/**/*.css'
'src/vendor/css/**'
]
dest: 'build/css/vendor.css'
stylus:
build:
options:
'resolve url': true
use: [ 'nib' ]
compress: false
paths: [ '/styl' ]
expand: true
join: true
files: 'build/css/app.css': ['src/**/*.styl', 'src/**/**.styl']
'string-replace':
main_script:
files:
'build/package.json': 'package.json'
options:
replacements:
[ {
pattern: 'build/scripts/main.js'
replacement: 'scripts/main.js'
} ]
copy:
main:
files: [
{ expand: true, cwd: 'src/assets/', src: ['**'], dest: 'build' }
]
server:
src: ['src/server/package.json']
dest: 'build/server/package.json'
node_modules:
files: [
{ expand: true, cwd: 'node_modules/', src: ['**'], dest: 'build/node_modules' }
]
electron:
options:
name: '<%= config.pkg.name %>'
dir: 'build'
out: 'dist'
version: '<%= config.pkg.electronVersion %>'
'app-version': '<%=config.pkg.version %>'
overwrite: true
prune: true
ignore: []
linux64:
options:
platform: 'linux'
arch: 'x64'
linux32:
options:
platform: 'linux'
arch: 'ia32'
darwin:
options:
platform: 'darwin'
arch: 'x64'
# icon: ""
win32:
options:
platform: 'win32'
arch: 'x64'
# icon: ""
# load the tasks
require('load-grunt-tasks') grunt
grunt.loadNpmTasks 'grunt-string-replace'
grunt.registerTask 'default', ->
grunt.task.run 'build'
grunt.task.run 'start'
grunt.registerTask 'restart-electron', ->
electron.restart()
return
grunt.registerTask 'reload-electron', ->
electron.reload()
return
grunt.registerTask 'copyDeps', ->
grunt.task.run 'copy:main'
grunt.task.run 'copy:server'
grunt.task.run 'copy:node_modules'
# define the main tasks
grunt.registerTask 'build', (env) ->
env = env or 'dev'
grunt.config.set 'config.env', env
grunt.task.run 'clean:build'
grunt.task.run 'string-replace:main_script'
grunt.task.run 'coffee'
grunt.task.run 'ngtemplates:ng'
grunt.task.run 'ngAnnotate:build'
grunt.task.run 'stylus:build'
grunt.task.run 'concat'
grunt.task.run 'copyDeps'
grunt.registerTask 'start', (env) ->
electron.start()
grunt.task.run 'watch'
grunt.registerTask 'dev', (env) ->
process.env.NODE_ENV = 'dev'
grunt.task.run 'build'
grunt.task.run 'start'
return
grunt.event.on 'watch', (action, filepath, target) ->
grunt.log.writeln target + ': ' + filepath + ' has ' + action
return
grunt.registerTask 'package', ->
grunt.task.run 'electron:linux64'
grunt.task.run 'electron:linux32'
grunt.task.run 'electron:darwin'
grunt.task.run 'electron:win32'