This repository has been archived by the owner on Oct 29, 2024. It is now read-only.
forked from jooohn/textAngular
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
239 lines (231 loc) · 7.14 KB
/
Gruntfile.js
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
module.exports = function (grunt) {
// load all grunt tasks
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-istanbul-coverage');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-karma-coveralls');
grunt.loadNpmTasks('grunt-conventional-changelog');
grunt.loadNpmTasks('grunt-bump');
grunt.loadNpmTasks('grunt-git');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-umd');
grunt.registerTask('compile', ['concat', 'umd', 'copy:setupFiles', 'jshint', 'uglify']);
grunt.registerTask('default', ['compile', 'test']);
grunt.registerTask('test', ['clean:coverage', 'jshint', 'karma', 'coverage']);
grunt.registerTask('travis-test', ['concat', 'umd', 'copy:setupFiles', 'jshint', 'karma', 'coverage', 'coveralls']);
grunt.registerTask('release', ['bump-only', 'setVersion', 'compile', 'demo_pages', 'conventionalChangelog', 'shell:changelog', 'gitcommit','bump-commit', 'shell:publish']);
grunt.registerTask('release:patch', ['bump-only:patch','setVersion','compile','demo_pages','conventionalChangelog','shell:changelog','gitcommit','bump-commit', 'shell:publish']);
grunt.registerTask('release:minor', ['bump-only:minor','setVersion','compile','demo_pages','conventionalChangelog','shell:changelog','gitcommit','bump-commit', 'shell:publish']);
grunt.registerTask('release:major', ['bump-only:major','setVersion','compile','demo_pages','conventionalChangelog','shell:changelog','gitcommit','bump-commit', 'shell:publish']);
grunt.registerTask('release:prerelease', ['bump-only:prerelease','setVersion','demo_pages','compile','conventionalChangelog','shell:changelog','gitcommit','bump-commit', 'shell:publish']);
grunt.registerTask('setVersion', function () {
var pkgJson = require('./package.json');
var version = pkgJson.version;
//grunt.log.writeln('textAngular version:'+version);
var contents = grunt.file.read('./src/globals.js');
contents = contents.replace(/textAngularVersion = 'v\d+.\d+.\d+(-\d)?'/i, "textAngularVersion = 'v"+version+"'");
grunt.file.write('./src/globals.js', contents);
console.log('Updated src/globals.js to textAngular version: v'+version);
});
var testConfig = function (configFile, customOptions) {
var options = { configFile: configFile, keepalive: true };
var travisOptions = process.env.TRAVIS && { browsers: ['PhantomJS'], reporters: ['dots','coverage'] };
return grunt.util._.extend(options, customOptions, travisOptions);
};
grunt.registerMultiTask('demo_pages', 'Compile demo pages', function(){
var d = this.data;
var srcPath = function(fname){ return d.cwd + fname; };
var destPath = function(fname){ return d.dest + fname; };
grunt.file.expand({cwd: d.cwd}, d.src).forEach(function(each){
grunt.file.copy(srcPath(each), destPath(each), {
process: function (contents, path){
return grunt.template.process(contents, {
data: {
js: Object.keys(grunt.config('uglify.my_target.files')),
version: grunt.config('pkg.version')
}
});
}
});
});
});
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// grunt-spawn
spawn_changelog: {
command: 'pico',
pattern: 'changelog.md',
commandArgs: ['{0}'],
opts: {
stdio: 'inherit'
}
},
conventionalChangelog: {
options: {
changelogOpts: {
// conventional-changelog options go here
preset: 'angular'
},
context: {
// context goes here
},
gitRawCommitsOpts: {
// git-raw-commits options go here
},
parserOpts: {
// conventional-commits-parser options go here
},
writerOpts: {
// conventional-changelog-writer options go here
}
},
release: {
src: 'changelog.md'
},
},
bump: {
options: {
files: ['package.json','bower.json'],
commitFiles: ['package.json', 'changelog.md','bower.json'],
pushTo: 'origin',
updateConfigs: ['pkg']
}
},
gitcommit: {
release: {
options: {
message: "chore(release): Build Dist files"
},
files: {
src: ['src/*', 'demo/*', 'src/demo/*','dist/*']
}
}
},
shell: {
publish: {
command: "npm publish"
},
changelog: {
options: {
stdinRawMode: true
},
command: 'pico changelog.md',
}
},
clean: {
coverage: ["coverage"],
dist: ["dist"],
},
coverage: {
options: {
thresholds: {
'statements': 100,
'branches': 100,
'lines': 100,
'functions': 100
},
dir: 'coverage'
}
},
coveralls: {
options: {
debug: true,
coverageDir: 'coverage',
force: true,
}
},
karma: {
jquery: {
options: testConfig('karma-jquery.conf.js')
},
jqlite: {
options: testConfig('karma-jqlite.conf.js')
}
},
jshint: {
files: ['src/*.js', 'test/*.spec.js', 'test/taBind/*.spec.js', '!src/textAngular-sanitize.js'],// don't hint the textAngularSanitize as they will fail
options: {
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
boss: true,
eqnull: true,
globals: {}
}
},
copy: {
setupFiles: {
expand: true,
cwd: 'src/',
src: ['textAngularSetup.js', 'textAngular.css', 'textAngular-sanitize.js'],
dest: 'dist/'
}
},
concat: {
dist: {
options: {
banner: "/*\n@license textAngular\nAuthor : Austin Anderson\nLicense : 2013 MIT\nVersion <%- pkg.version %>\n\nSee README.md or https://github.com/fraywing/textAngular/wiki for requirements and use.\n*/\n\n/*\nCommonjs package manager support (eg componentjs).\n*/\n\n\n\"use strict\";"
},
files:{
'dist/textAngular.js': ['src/globals.js','src/factories.js','src/DOM.js','src/validators.js','src/taBind.js','src/main.js'],
}
},
umd: {
files: {
'dist/textAngular.umd.js': ['dist/textAngularSetup.js', 'dist/textAngular.js']
}
}
},
umd: {
all: {
options: {
src: 'dist/textAngular.umd.js',
dest: 'dist/textAngular.umd.js',
objectToExport: 'textAngular.name',
globalAlias: 'textAngular',
amdModuleId: 'textAngular',
deps: {
'default': ['rangy'],
cjs: ['rangy', {'rangy/lib/rangy-selectionsaverestore': ''}],
amd: ['rangy', {'rangy/lib/rangy-selectionsaverestore': ''}]
}
}
}
},
uglify: {
options: {
mangle: true,
compress: {},
wrap: false,
preserveComments: 'some'
},
my_target: {
files: {
'dist/textAngular-rangy.min.js': ['bower_components/rangy/rangy-core.js', 'bower_components/rangy/rangy-selectionsaverestore.js'],
'dist/textAngular-sanitize.min.js': ['src/textAngular-sanitize.js'],
'dist/textAngular.min.js': ['dist/textAngular.umd.js']
}
}
},
demo_pages: {
main: {
cwd: 'src/demo/',
src: '*.html',
dest: 'demo/'
}
},
watch: {
files: "src/*.js",
tasks: "compile"
}
});
};