-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.coffee
128 lines (112 loc) · 4.36 KB
/
gulpfile.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
gulp = require 'gulp'
rename = require 'gulp-rename'
templateCache = require 'gulp-angular-templatecache'
uglify = require 'gulp-uglify'
_ = require 'underscore'
webpack = require 'webpack'
fs = require 'fs'
Path = require 'path'
moduleName = 'ari.ui.core'
paths =
src: 'src'
dist: 'dist'
inFile: 'index.js'
outFile: 'built.js'
uiTpls: 'ui-templates.js'
strapTpls: 'strap-templates.js'
uiBootstrap: './node_modules/angular-ui-bootstrap/src'
uiTemplates: './node_modules/angular-ui-bootstrap/template'
ngStrap: './node_modules/angular-strap'
components =
'ui.bootstrap.accordion' : "#{paths.uiBootstrap}/accordion/accordion.js"
'ui.bootstrap.alert' : "#{paths.uiBootstrap}/alert/alert.js"
'ui.bootstrap.buttons' : "#{paths.uiBootstrap}/buttons/buttons.js"
'ui.bootstrap.collapse' : "#{paths.uiBootstrap}/collapse/collapse.js"
'ui.bootstrap.dateparser' : "#{paths.uiBootstrap}/dateparser/dateparser.js"
'ui.bootstrap.datepicker' : "#{paths.uiBootstrap}/datepicker/datepicker.js"
'ui.bootstrap.timepicker' : "#{paths.uiBootstrap}/timepicker/timepicker.js"
'ui.bootstrap.dropdown' : "#{paths.uiBootstrap}/dropdown/dropdown.js"
'ui.bootstrap.modal' : "#{paths.uiBootstrap}/modal/modal.js"
'ui.bootstrap.progressbar' : "#{paths.uiBootstrap}/progressbar/progressbar.js"
'ui.bootstrap.rating' : "#{paths.uiBootstrap}/rating/rating.js"
'ui.bootstrap.tabs' : "#{paths.uiBootstrap}/tabs/tabs.js"
'ui.bootstrap.transition' : "#{paths.uiBootstrap}/transition/transition.js"
'ui.bootstrap.position' : "#{paths.uiBootstrap}/position/position.js"
'mgcrea.ngStrap.helpers.dimensions' : "#{paths.ngStrap}/dist/modules/dimensions.js"
'mgcrea.ngStrap.popover' : "#{paths.ngStrap}/dist/modules/popover.js"
'mgcrea.ngStrap.tooltip' : "#{paths.ngStrap}/dist/modules/tooltip.js"
'ari.ui.core.ui-bootstrap-templates' : "./#{paths.src}/#{paths.uiTpls}"
'ari.ui.core.ng-strap-templates' : "./#{paths.src}/#{paths.strapTpls}"
uiTpls = [
"#{paths.uiTemplates}/accordion/*.html"
"#{paths.uiTemplates}/alert/*.html"
"#{paths.uiTemplates}/buttons/*.html"
"#{paths.uiTemplates}/datepicker/*.html"
"#{paths.uiTemplates}/timepicker/*.html"
"#{paths.uiTemplates}/dropdown/*.html"
"#{paths.uiTemplates}/modal/*.html"
"#{paths.uiTemplates}/progressbar/*.html"
"#{paths.uiTemplates}/rating/*.html"
"#{paths.uiTemplates}/tabs/*.html"
]
strapTpls = [
"#{paths.ngStrap}/src/popover/*.html"
"#{paths.ngStrap}/src/tooltip/*.html"
]
createModule = (name, comps)->
modules = _(comps).map((p, n)-> "'#{n}'")
"""
angular.module('#{name}', [
#{modules.join(',\n')}
]);
"""
gulp.task 'uiTpls', ->
gulp.src uiTpls
.pipe(templateCache(paths.uiTpls, {
module: 'ari.ui.core.ui-bootstrap-templates',
standalone: true,
base: ((p)->
base = Path.dirname(Path.dirname(p.base))
p.path.slice base.length+1
) }))
.pipe(gulp.dest(paths.src))
gulp.task 'strapTpls', ->
gulp.src strapTpls
.pipe(templateCache(paths.strapTpls, {
module: 'ari.ui.core.ng-strap-templates',
standalone: true,
base: ((p)->
base = Path.dirname(p.base)
p.path.slice base.length+1
) }))
.pipe(gulp.dest(paths.src))
gulp.task 'generate', ['templates'], ->
srcPath = Path.resolve paths.src, paths.inFile
fs.writeFileSync srcPath, createModule moduleName, components
gulp.task 'pack', ['generate', 'templates'], (done)->
entries = [ Path.resolve(paths.src, paths.inFile) ]
entries = entries.concat(_(components).values())
compiler = webpack
devtool: '#inline-source-map'
entry: entries
output:
path: Path.resolve(paths.dist)
filename: paths.outFile
externals:
angular: 'angular'
plugins: [
new webpack.ProvidePlugin({
angular: 'angular'
})
],
compiler.run (err, stats)->
if err
console.log err
done()
# gulp.task 'minify', ['pack'], ->
# gulp.src Path.join paths.dist, paths.outFile
# .pipe uglify()
# .pipe rename({ suffix: '.min' })
# .pipe gulp.dest paths.dist
gulp.task 'templates', ['uiTpls', 'strapTpls']
gulp.task 'build', ['pack']