Skip to content

Commit bc8da5a

Browse files
committed
add grunt command-line tools for building, watching and linting.
1 parent f1d91cb commit bc8da5a

File tree

2 files changed

+167
-46
lines changed

2 files changed

+167
-46
lines changed

gruntfile.js

+149-40
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,151 @@
1-
module.exports = function(grunt){
2-
3-
grunt.initConfig({
4-
5-
pkg: grunt.file.readJSON('package.json'),
6-
7-
watch: {
8-
options: {
9-
livereload: true
10-
}
11-
},
12-
13-
connect: {
14-
dev: {
15-
options: {
16-
//port: '?',
17-
port: '62332',
18-
base: '',
19-
hostname: '*'
20-
//open: ''
21-
//open: '//localhost:50390/node_modules/intern/client.html',
22-
//open: true
23-
}
24-
}
25-
},
26-
open: {
27-
dev: {
28-
path: 'http://localhost:62332/tests/Export/index.html'
29-
}
30-
}
31-
});
32-
33-
34-
// load the tasks
35-
grunt.loadNpmTasks('grunt-contrib-watch');
36-
grunt.loadNpmTasks('grunt-contrib-connect');
37-
grunt.loadNpmTasks('grunt-open');
38-
39-
// define the tasks
40-
grunt.registerTask('dev', ['connect:dev', 'open:dev', 'watch']);
1+
/* global module */
2+
module.exports = function (grunt) {
3+
'use strict';
414

5+
// grunt task config
6+
grunt.initConfig({
7+
pkg: grunt.file.readJSON('package.json'),
8+
tag: {
9+
banner: '/* <%= pkg.name %>\n' +
10+
' * version <%= pkg.version %>\n' +
11+
' * Project: <%= pkg.homepage %>\n' +
12+
' */\n'
13+
},
14+
copy: {
15+
build: {
16+
src: ['**', '!cmv/**', '!node_modules/**', '!tests/**', '!package.json', '!gruntfile.js'],
17+
dest: 'dist',
18+
expand: true
19+
}
20+
},
21+
clean: {
22+
build: {
23+
src: ['dist']
24+
}
25+
},
26+
autoprefixer: {
27+
build: {
28+
expand: true,
29+
cwd: 'dist/widgets',
30+
src: ['widgets/**/*.css'],
31+
dest: 'dist/widgets'
32+
}
33+
},
34+
cssmin: {
35+
build: {
36+
expand: true,
37+
cwd: 'dist',
38+
src: ['**/*.css'],
39+
dest: 'dist'
40+
}
41+
},
42+
43+
csslint: {
44+
build: {
45+
src: ['widgets/**/*.css'],
46+
options: {
47+
csslintrc: '.csslintrc'
48+
}
49+
}
50+
},
51+
52+
eslint: {
53+
build: {
54+
src: ['widgets/**/*.js', 'config/**/*.js'],
55+
options: {
56+
eslintrc: '.eslintrc'
57+
}
58+
}
59+
},
60+
61+
uglify: {
62+
build: {
63+
files: [{
64+
expand: true,
65+
cwd: 'dist',
66+
src: ['**/*.js', '!**/config/**', '!**/cmv/**'],
67+
dest: 'dist',
68+
ext: '.js'
69+
}],
70+
options: {
71+
banner: '<%= tag.banner %>',
72+
sourceMap: true,
73+
sourceMapIncludeSources: true,
74+
compress: {
75+
'drop_console': false
76+
}
77+
}
78+
}
79+
},
80+
81+
watch: {
82+
dev: {
83+
files: ['widgets/**'],
84+
tasks: ['eslint', 'csslint']
85+
},
86+
build: {
87+
files: ['widgets/**'],
88+
tasks: ['eslint', 'csslint']
89+
}
90+
},
91+
92+
connect: {
93+
dev: {
94+
options: {
95+
port: 3000,
96+
base: '.',
97+
hostname: '*'
98+
}
99+
},
100+
build: {
101+
options: {
102+
port: 3001,
103+
base: 'dist/viewer',
104+
hostname: '*'
105+
}
106+
}
107+
},
108+
open: {
109+
'dev_browser': {
110+
path: 'http://localhost:3000/index.html'
111+
},
112+
'build_browser': {
113+
path: 'http://localhost:3001/index.html'
114+
}
115+
},
116+
compress: {
117+
build: {
118+
options: {
119+
archive: 'dist/cmv-widgets.zip'
120+
},
121+
files: [{
122+
expand: true,
123+
cwd: 'dist',
124+
src: ['**', '!**/dijit.css']
125+
}]
126+
}
127+
}
128+
});
129+
130+
// load the tasks
131+
grunt.loadNpmTasks('grunt-contrib-copy');
132+
grunt.loadNpmTasks('grunt-contrib-clean');
133+
grunt.loadNpmTasks('grunt-autoprefixer');
134+
grunt.loadNpmTasks('grunt-contrib-cssmin');
135+
grunt.loadNpmTasks('grunt-contrib-csslint');
136+
grunt.loadNpmTasks('grunt-contrib-uglify');
137+
grunt.loadNpmTasks('grunt-eslint');
138+
grunt.loadNpmTasks('grunt-contrib-watch');
139+
grunt.loadNpmTasks('grunt-contrib-connect');
140+
grunt.loadNpmTasks('grunt-newer');
141+
grunt.loadNpmTasks('grunt-open');
142+
grunt.loadNpmTasks('grunt-contrib-compress');
143+
144+
// define the tasks
145+
grunt.registerTask('default', 'Watches the project for changes, automatically builds them and runs a web server and opens default browser to preview.', ['eslint', 'csslint', 'connect:dev', 'open:dev_browser', 'watch:dev']);
146+
grunt.registerTask('build', 'Compiles all of the assets and copies the files to the build directory.', ['clean', 'copy', 'scripts', 'stylesheets', 'compress:build']);
147+
grunt.registerTask('build-view', 'Compiles all of the assets and copies the files to the build directory starts a web server and opens browser to preview app.', ['clean', 'copy', 'scripts', 'stylesheets', 'compress:build', 'connect:build', 'open:build_browser', 'watch:build']);
148+
grunt.registerTask('scripts', 'Compiles the JavaScript files.', ['eslint', 'uglify']);
149+
grunt.registerTask('stylesheets', 'Auto prefixes css and compiles the stylesheets.', ['csslint', 'autoprefixer', 'cssmin']);
150+
grunt.registerTask('lint', 'Run simple eslint and csslint.', ['eslint', 'csslint']);
42151
};

package.json

+18-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@
44
"author": "Tim McGee",
55
"license": "",
66
"year": "2015",
7-
"devDependencies": {
8-
"grunt": "^0.4.5",
9-
"grunt-contrib-connect": "0.4.x",
10-
"grunt-contrib-watch": "0.5.x",
11-
"grunt-open": "^0.2.3"
12-
},
7+
"homepage": "https://tmcgee.github.io/cmv-widgets/",
8+
"repository": "https://github.com/tmcgee/cmv-widgets",
139
"dependencies": {
10+
"csslint": "0.10.x",
11+
"babel-eslint": "4.1.x",
12+
"eslint": "1.7.x",
13+
"grunt": "0.4.x",
14+
"grunt-autoprefixer": "0.7.x",
15+
"grunt-contrib-clean": "0.5.x",
16+
"grunt-contrib-connect": "0.7.x",
17+
"grunt-contrib-copy": "0.5.x",
18+
"grunt-contrib-csslint": "0.5.x",
19+
"grunt-contrib-cssmin": "0.9.x",
20+
"grunt-eslint": "17.3.x",
21+
"grunt-contrib-uglify": "0.4.x",
22+
"grunt-contrib-watch": "0.6.x",
23+
"grunt-newer": "0.7.x",
24+
"grunt-open": "0.2.x",
25+
"grunt-contrib-compress": "0.10.x"
1426
},
1527
"engine": "node >= 0.10"
1628
}

0 commit comments

Comments
 (0)