Skip to content

Commit 537d254

Browse files
committed
Add basic npm support and Gruntfile, move tests to grunt
1 parent e4b39c6 commit 537d254

File tree

10 files changed

+130
-225
lines changed

10 files changed

+130
-225
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
instrumented/
2-
tests/coverage.html
31
docs/_build
2+
node_modules/
3+
_build

.hgignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
instrumented/
2-
tests/coverage.html
31
docs/_build
2+
node_modules/
3+
_build/

.travis.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1+
language: node_js
2+
node_js:
3+
- "0.10"
14
install:
2-
- npm install -g jshint jscs
3-
before_script:
4-
- cd ./tests
5-
- echo "new Date().toString();" | phantomjs
6-
script:
7-
- jshint ../js/bootstrap-datepicker.js ../js/locales/*.js
8-
- jscs -c ../.jscs.json ../js/bootstrap-datepicker.js ../js/locales/*.js
9-
- phantomjs run-qunit.js tests.html
5+
- npm install -g grunt-cli

Gruntfile.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/* global module, require */
2+
module.exports = function(grunt){
3+
require('load-grunt-tasks')(grunt);
4+
5+
grunt.initConfig({
6+
pkg: grunt.file.readJSON('package.json'),
7+
qunit: {
8+
all: ['tests/tests.html']
9+
},
10+
jshint: {
11+
options: {
12+
jshintrc: true
13+
},
14+
gruntfile: ['Gruntfile.js'],
15+
main: ['js/bootstrap-datepicker.js'],
16+
locales: ['js/locales/*js']
17+
},
18+
jscs: {
19+
/* grunt-contrib-jscs notes:
20+
0.1.2 works
21+
0.1.3 inifite loops on postinstall
22+
0.1.4 doesn't seem to hit all targets when run "grunt jscs"
23+
*/
24+
gruntfile: ['Gruntfile.js'],
25+
main: ['js/bootstrap-datepicker.js'],
26+
locales: ['js/locales/*js']
27+
},
28+
less: {
29+
standalone: {
30+
files: {
31+
'_build/datepicker.standalone.css': 'build/build_standalone.less',
32+
'_build/datepicker3.standalone.css': 'build/build_standalone3.less'
33+
}
34+
},
35+
css: {
36+
files: {
37+
'_build/datepicker.css': 'build/build.less',
38+
'_build/datepicker3.css': 'build/build3.less'
39+
}
40+
},
41+
repo: {
42+
files: {
43+
'css/datepicker.css': 'build/build_standalone.less',
44+
'css/datepicker3.css': 'build/build_standalone3.less'
45+
}
46+
}
47+
},
48+
uglify: {
49+
options: {
50+
compress: true,
51+
mangle: true
52+
},
53+
main: {
54+
options: {
55+
sourceMap: function(dest){
56+
return dest.replace('.min.js', '.js.map');
57+
}
58+
},
59+
files: {
60+
'_build/bootstrap-datepicker.min.js': 'js/bootstrap-datepicker.js',
61+
'_build/bootstrap-datepicker.locales.min.js': 'js/locales/*.js'
62+
}
63+
},
64+
locales: {
65+
files: [{
66+
expand: true,
67+
cwd: 'js/locales/',
68+
src: ['*.js', '!*.min.js'],
69+
dest: '_build/locales/',
70+
rename: function(dest, name){
71+
return dest + name.replace(/\.js$/, '.min.js');
72+
}
73+
}]
74+
}
75+
},
76+
cssmin: {
77+
all: {
78+
files: {
79+
'_build/datepicker.standalone.min.css': '_build/datepicker.standalone.css',
80+
'_build/datepicker.min.css': '_build/datepicker.css',
81+
'_build/datepicker3.standalone.min.css': '_build/datepicker3.standalone.css',
82+
'_build/datepicker3.min.css': '_build/datepicker3.css'
83+
}
84+
}
85+
},
86+
clean: ['_build']
87+
});
88+
89+
grunt.registerTask('lint', 'Lint all js files with jshint and jscs', ['jshint', 'jscs']);
90+
grunt.registerTask('test', 'Lint files and run unit tests', ['lint', 'qunit']);
91+
grunt.registerTask('finish', 'Prepares repo for commit [test, less:repo]', ['test', 'less:repo']);
92+
grunt.registerTask('dist', 'Builds minified files', ['less:css', 'less:standalone', 'cssmin', 'uglify']);
93+
};

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ Please note that this fork is not used on Stefan's page, nor is it maintained or
77

88
Versions are incremented according to [semver](http://semver.org/).
99

10+
## Links
11+
1012
* [Online Demo](http://eternicode.github.io/bootstrap-datepicker/)
1113
* [Online Docs](http://bootstrap-datepicker.readthedocs.org/) (ReadTheDocs.com)
1214
* [Google Group](https://groups.google.com/group/bootstrap-datepicker/)
1315
* [Travis CI ![Build Status](https://travis-ci.org/eternicode/bootstrap-datepicker.png?branch=master)](https://travis-ci.org/eternicode/bootstrap-datepicker)
16+
17+
## Development
18+
19+
Once you cloned the repo, you'll need to install [grunt](http://gruntjs.com/) and the development dependencies using [npm](https://npmjs.org/).
20+
21+
npm install -g grunt-cli
22+
npm install

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"scripts": {
3+
"test": "grunt test"
4+
},
5+
"devDependencies": {
6+
"grunt": "~0.4.2",
7+
"load-grunt-tasks": "~0.2.1",
8+
"grunt-contrib-jshint": "~0.8.0",
9+
"grunt-contrib-jscs": "0.1.2",
10+
"grunt-contrib-qunit": "~0.3.0",
11+
"grunt-contrib-less": "~0.9.0",
12+
"grunt-contrib-uglify": "~0.2.7",
13+
"grunt-contrib-cssmin": "~0.7.0",
14+
"grunt-contrib-clean": "~0.5.0"
15+
}
16+
}

tests/README.md

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,11 @@ bugs when adding new features and making changes.
77
The simplest way to run the tests is to open `tests/tests.html` in your browser.
88
The test suites will automatically run themselves and present their results.
99

10-
To run the tests from the command line, download and install
11-
[PhantomJS](http://phantomjs.org/), and run `run-qunit.js` with it:
10+
To run the tests from the command line (after running jshint and jscs, which is
11+
recommended), install Grunt and run the `test` task from anywhere within the
12+
repo:
1213

13-
$ cd tests/
14-
$ phantomjs run-qunit.js tests.html
15-
16-
Failed tests and their failed assertions will be printed to the console. A
17-
results summary will be printed at the end.
18-
19-
To generate coverage statistics, use [JSCoverage](http://siliconforks.com/jscoverage/)
20-
to instrument the js files:
21-
22-
$ cd tests/
23-
$ jscoverage ../js/ ../instrumented/
24-
$ phantomjs run-qunit.js tests.html
25-
26-
Coverage percentage will be included in the output summary, and a highlighted
27-
line-by-line html file will be generated.
28-
29-
# Shout-out
30-
31-
Thanks to Rod @ While One Fork for the
32-
[CIS guide](http://whileonefork.blogspot.com/2011/10/integrating-javascript-tests-into-cli.html)
33-
on putting the above together.
14+
$ grunt test
3415

3516
# Adding tests
3617

@@ -47,9 +28,3 @@ name and `<year>` is the four-digit year the tests pertain to.
4728
In order for new tests to be run, they must be imported into `tests/tests.html`.
4829
Find the script includes headed by the html comment `<!-- Test suites -->`, and
4930
add a new one to the list which includes the new js files.
50-
51-
# Can I use this?
52-
53-
By all means, please do! Just note that I stopped working on this structure
54-
once it fit my needs, there's no real support for it, and it may change in the
55-
future. Otherwise, have at it.

tests/_coverage.html

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/run-qunit.js

Lines changed: 0 additions & 157 deletions
This file was deleted.

tests/tests.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<link rel="stylesheet" href="assets/qunit.css" />
55
<script src="assets/qunit.js"></script>
66
<script src="assets/qunit-logging.js"></script> <!-- console.log for test failures -->
7-
<script src="assets/coverage.js"></script>
87
<script src="assets/jquery-1.7.1.min.js"></script>
98
<script src="../js/bootstrap-datepicker.js"></script>
109

0 commit comments

Comments
 (0)