forked from salsita/chrome-extension-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
141 lines (118 loc) · 3.76 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
module.exports = function(grunt) {
var pkg = grunt.file.readJSON('package.json');
var mnf = grunt.file.readJSON('code/manifest.json');
var fileMaps = { browserify: {}, uglify: {} };
var file, files = grunt.file.expand({cwd:'code/js'}, ['*.js']);
for (var i = 0; i < files.length; i++) {
file = files[i];
fileMaps.browserify['build/unpacked-dev/js/' + file] = 'code/js/' + file;
fileMaps.uglify['build/unpacked-prod/js/' + file] = 'build/unpacked-dev/js/' + file;
}
//
// config
//
grunt.initConfig({
clean: ['build/unpacked-dev', 'build/unpacked-prod', 'build/*.crx'],
mkdir: {
unpacked: { options: { create: ['build/unpacked-dev', 'build/unpacked-prod'] } },
js: { options: { create: ['build/unpacked-dev/js'] } }
},
jshint: {
options: grunt.file.readJSON('lint-options.json'), // see http://www.jshint.com/docs/options/
all: { src: ['package.json', 'lint-options.json', 'Gruntfile.js', 'code/**/*.js',
'code/**/*.json', '!code/js/libs/*'] }
},
mochaTest: {
options: { colors: true, reporter: 'spec' },
files: ['code/**/*.spec.js']
},
copy: {
main: { files: [ {
expand: true,
cwd: 'code/',
src: ['**', '!js/**', '!**/*.md'],
dest: 'build/unpacked-dev/'
} ] },
prod: { files: [ {
expand: true,
cwd: 'build/unpacked-dev/',
src: ['**', '!js/*.js'],
dest: 'build/unpacked-prod/'
} ] },
artifact: { files: [ {
expand: true,
cwd: 'build/',
src: [pkg.name + '-' + pkg.version + '.crx'],
dest: process.env.CIRCLE_ARTIFACTS
} ] }
},
browserify: {
build: {
files: fileMaps.browserify,
options: { browserifyOptions: {
debug: true, // for source maps
standalone: pkg['export-symbol']
} }
}
},
exec: {
crx: {
cmd: [
'./crxmake.sh build/unpacked-prod ./mykey.pem',
'mv -v ./unpacked-prod.crx build/' + pkg.name + '-' + pkg.version + '.crx'
].join(' && ')
}
},
uglify: {
min: { files: fileMaps.uglify }
},
watch: {
js: {
files: ['package.json', 'lint-options.json', 'Gruntfile.js', 'code/**/*.js',
'code/**/*.json', '!code/js/libs/*'],
tasks: ['test']
}
}
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-mkdir');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
//
// custom tasks
//
grunt.registerTask(
'manifest', 'Extend manifest.json with extra fields from package.json',
function() {
var fields = ['name', 'version', 'description'];
for (var i = 0; i < fields.length; i++) {
var field = fields[i];
mnf[field] = pkg[field];
}
grunt.file.write('build/unpacked-dev/manifest.json', JSON.stringify(mnf, null, 4) + '\n');
grunt.log.ok('manifest.json generated');
}
);
grunt.registerTask(
'circleci', 'Store built extension as CircleCI arfitact',
function() {
if (process.env.CIRCLE_ARTIFACTS) { grunt.task.run('copy:artifact'); }
else { grunt.log.ok('Not on CircleCI, skipped'); }
}
);
//
// testing-related tasks
//
grunt.registerTask('test', ['jshint', 'mochaTest']);
grunt.registerTask('test-cont', ['test', 'watch']);
//
// DEFAULT
//
grunt.registerTask('default', ['clean', 'test', 'mkdir:unpacked', 'copy:main', 'manifest',
'mkdir:js', 'browserify', 'copy:prod', 'uglify', 'exec', 'circleci']);
};