Skip to content

Commit c4b13c4

Browse files
committed
lots of refactoring
1 parent 998b69d commit c4b13c4

20 files changed

+171
-82
lines changed

.jshintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"node": true,
3+
"browser": true,
34
"esnext": true,
45
"bitwise": true,
56
"camelcase": true,
@@ -18,6 +19,7 @@
1819
"trailing": true,
1920
"smarttabs": true,
2021
"white": true,
22+
"validthis": true,
2123
"globals": {
2224
"chai": false,
2325
"sinon": false,
@@ -35,6 +37,7 @@
3537
"expect": false,
3638
"spyOn": false,
3739
"xdescribe": false,
38-
"xit": false
40+
"xit": false,
41+
"define": false
3942
}
4043
}

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Quickly scaffold out a micro library or framework.
2323
* [Mocha](http://visionmedia.github.io/mocha)
2424
* [QUnit](http://qunitjs.com) (TODO)
2525
* Test coverage pre-configured to publish to code climate.
26+
* Micro library template is pre-configured for AMD, Node.js and browser support.
2627
* README file
2728
* Dynamic based on the project configurations.
2829
* Pre-configured badges for:
@@ -61,7 +62,7 @@ To install generator-microjs from npm, run:
6162
$ npm install -g generator-microjs
6263
```
6364

64-
## Use
65+
## Scaffolding
6566

6667
Go to your new project folder, run the generator and follow the prompts. The use `--coffee` flag is optional.
6768

@@ -71,10 +72,6 @@ $ yo microjs --coffee
7172

7273
Check the generated `.travis.yml` file you'll need to fill in some data if you want to publish build status and test coverage reports.
7374

74-
```bash
75-
$ yo microjs --coffee
76-
```
77-
7875
Write unit tests and add code to create you micro-framework or library. Run your tests using:
7976

8077
```bash

app/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ var extractProj = function (_, appname) {
3434
return slugged;
3535
};
3636

37+
var toCamelCase = function (input) {
38+
return input.toLowerCase().replace(/-(.)/g, function (match, group1) {
39+
return group1.toUpperCase();
40+
});
41+
};
42+
3743
var githubUserInfo = function (name, cb) {
3844

3945
// handle bad data
@@ -132,6 +138,7 @@ var MicroJSGenerator = yeoman.generators.Base.extend({
132138

133139
this.projName = props.projName;
134140
this.baseFileName = path.basename(this.projName, path.extname(this.projName));
141+
this.exportName = toCamelCase(this.baseFileName);
135142

136143
done();
137144
}.bind(this));
@@ -236,14 +243,14 @@ var MicroJSGenerator = yeoman.generators.Base.extend({
236243
projectFiles: function () {
237244
this.copy('editorconfig', '.editorconfig');
238245
this.copy('npmignore', '.npmignore');
246+
this.template('umd', '.umd');
239247

240248
// only copy over coffee if the option was set
241249
if (this.options.coffee) {
242250
this.template('micro-tmpl.coffee', this.baseFileName + '.coffee');
243251
}
244252
this.template('micro-tmpl.js', this.baseFileName + '.js');
245253
this.template('micro-tmpl.min.js', this.baseFileName + '.min.js');
246-
this.template('micro-tmpl.min.js', this.baseFileName + '.min.js.map');
247254
this.template('README.md', 'README.md');
248255
},
249256

app/templates/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
## About
1313

14-
All about how amazing your <%= projName %> micro-library is.
14+
All about how amazing the <%= projName %> micro-library is.
1515

1616
## Examples
1717

@@ -27,9 +27,15 @@ All about how amazing your <%= projName %> micro-library is.
2727
- `bower install <%= projName %>`
2828
- [download the zip](https://github.com/<%= githubUser %>/<%= projName %>/archive/master.zip)
2929

30-
## Testing
30+
## Tasks
3131

32-
Tests can be run with the `npm test` command.
32+
All tasks can be run by simply running `<%= taskFramework %>` or with the `npm test` command, or individually:
33+
34+
* `<%= taskFramework %> lint` will lint source code for syntax errors and anti-patterns.
35+
* `<%= taskFramework %> gpa` will analyze source code against complexity thresholds.
36+
* `<%= taskFramework %> test` will run the <%= testFramework %> unit tests against the source code.<% if (options.coffee) { %>
37+
* `<%= taskFramework %> test-coffee` will run the <%= testFramework %> unit tests against the CoffeeScript source code.<% } %>
38+
* `<%= taskFramework %> test-min` will run the <%= testFramework %> unit tests against the minified code.
3339

3440
## License
3541

app/templates/_gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* ### Responsibilities
55
* - automate common tasks using grunt
66
*
7-
* Generated on <%= (new Date).toISOString().split('T')[0] %> using <%= pkg.name %> v<%= pkg.version %>
7+
* Scaffolded with <%= pkg.name %> v<%= pkg.version %>
88
*
99
* @author <%= realname %> <<%= email %>>
1010
*/

app/templates/_gulpfile.js

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* ### Responsibilities
55
* - automate common tasks using gulp
66
*
7-
* Generated on <%= (new Date).toISOString().split('T')[0] %> using <%= pkg.name %> v<%= pkg.version %>
7+
* Scaffolded with <%= pkg.name %> v<%= pkg.version %>
88
*
99
* @author <%= realname %> <<%= email %>>
1010
*/
@@ -15,20 +15,24 @@ var gulp = require('gulp'),
1515
complexity = require('gulp-complexity'),
1616
uglify = require('gulp-uglify'),
1717
rename = require('gulp-rename'),
18+
replace = require('gulp-replace'),
1819
karma = require('gulp-karma'),
20+
fs = require('fs'),
1921
source = '<%= baseFileName %>.js',
2022
sourceMin = '<%= baseFileName %>.min.js',
21-
sourceAndSpecs = [source, 'test/spec/*.spec.js'];
23+
specs = 'test/spec/*.spec.js',
24+
karmaConf = 'test/karma.conf',
25+
umdWrapper = fs.readFileSync('./.umd');
2226

2327
gulp.task('lint', function () {
24-
return gulp.src(sourceAndSpecs)
28+
return gulp.src([source, specs])
2529
.pipe(jshint())
2630
.pipe(jshint.reporter('default'))
2731
.pipe(jshint.reporter('fail'));
2832
});
2933

3034
gulp.task('gpa', function () {
31-
return gulp.src(sourceAndSpecs)
35+
return gulp.src([source, specs])
3236
.pipe(complexity({
3337
cyclomatic: [8],
3438
halstead: [9],
@@ -37,27 +41,35 @@ gulp.task('gpa', function () {
3741
});
3842

3943
gulp.task('test', function () {
40-
return gulp.src(sourceAndSpecs)
44+
return gulp.src([source, specs])
4145
.pipe(karma({
42-
configFile: 'test/karma.conf.js'
46+
configFile: karmaConf + '.js'
4347
}));
4448
});
45-
<% if (options.coffee) { %>
46-
gulp.task('test-coffee', function () {
47-
return gulp.src(['<%= baseFileName %>.coffee', 'test/spec/*.spec.coffee'])
48-
.pipe(karma({
49-
configFile: 'test/karma.conf.coffee'
50-
}));
51-
});<% } %>
5249

5350
gulp.task('min', function () {
5451
return gulp.src(source)
5552
.pipe(rename(sourceMin))
5653
.pipe(uglify({
57-
preserveComments: 'some',
5854
outSourceMap: true
5955
}))
56+
.pipe(replace(/(.*)/, umdWrapper))
6057
.pipe(gulp.dest('.'));
6158
});
59+
<% if (options.coffee) { %>
60+
gulp.task('test-coffee', function () {
61+
return gulp.src(['<%= baseFileName %>.coffee', 'test/spec/*.spec.coffee'])
62+
.pipe(karma({
63+
configFile: karmaConf + '.coffee'
64+
}));
65+
});<% } %>
66+
67+
gulp.task('test-min', ['min'], function () {
68+
return gulp.src([sourceMin, specs])
69+
.pipe(karma({
70+
configFile: karmaConf + '.js',
71+
reporters: ['dots']
72+
}));
73+
});
6274

63-
gulp.task('default', ['lint', 'gpa', 'test',<% if (options.coffee) { %> 'test-coffee',<% } %> 'min']);
75+
gulp.task('default', ['lint', 'gpa', 'test',<% if (options.coffee) { %> 'test-coffee',<% } %> 'test-min']);

app/templates/_package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"gulp-jshint": "*",
4444
"gulp-complexity": "*",
4545
"gulp-rename": "*",
46+
"gulp-replace": "*",
4647
"gulp-uglify": "*",<% if (options.coffee) { %>
4748
"gulp-coffee": "*",<% } %>
4849
"gulp-karma": "*",<% } %><% if (taskFramework === 'grunt') { %>

app/templates/jshintrc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@
1414
"quotmark": "single",
1515
"regexp": true,
1616
"undef": true,
17-
"unused": false,
18-
"strict": true,
17+
"strict": false,
1918
"trailing": true,
2019
"smarttabs": true,
20+
"validthis": true,
2121
"white": true,
22-
"globals": {<% if (testFramework === 'mocha') { %>
22+
"globals":{<% if (testFramework === 'mocha') { %>
2323
"chai": false,
2424
"sinon": false,
2525
"assert": false,
2626
"describe": false,
27+
"xdescribe": false,
2728
"it": false,
29+
"xit": false,
2830
"before": false,
2931
"after": false,
3032
"beforeEach": false,
@@ -33,14 +35,15 @@
3335
"test": false,
3436
"setup": false,
3537
"teardown": false,
36-
"expect": false<% } %><% if (testFramework === 'jasmine') { %>
38+
"expect": false,<% } %><% if (testFramework === 'jasmine') { %>
3739
"describe": false,
40+
"xdescribe": false,
3841
"it": false,
42+
"xit": false,
3943
"beforeEach": false,
4044
"afterEach": false,
4145
"expect": false,
42-
"spyOn": false,
43-
"xdescribe": false,
44-
"xit": false<% } %>
46+
"spyOn": false,<% } %>
47+
"define": false
4548
}
4649
}

app/templates/micro-tmpl.coffee

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
###*
2-
@file <%= projName %> was created using generator-microjs.
3-
Generated on <%= (new Date).toISOString().split('T')[0] %> using <%= pkg.name %> v<%= pkg.version %>
4-
@author <%= realname %> <<%= email %>>
2+
@file <%= projName %> was created using generator-microjs.
3+
Scaffolded with <%= pkg.name %> v<%= pkg.version %>
4+
@author <%= realname %> <<%= email %>>
55
###
6+
7+
<%= exportName %> = ->
8+
# TODO: implement your micro framework or library.

app/templates/micro-tmpl.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/**
22
* @file <%= projName %> was created using generator-microjs.
3-
* Generated on <%= (new Date).toISOString().split('T')[0] %> using <%= pkg.name %> v<%= pkg.version %>
3+
* Scaffolded with <%= pkg.name %> v<%= pkg.version %>
44
* @author <%= realname %> <<%= email %>>
55
*/
6-
'use strict';
6+
7+
function <%= exportName %>() {
8+
// TODO: implement your micro framework or library.
9+
}

0 commit comments

Comments
 (0)