Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Commit

Permalink
Merge f24a01d into 2c8f652
Browse files Browse the repository at this point in the history
  • Loading branch information
iamstarkov committed Aug 5, 2015
2 parents 2c8f652 + f24a01d commit 17dbe3c
Show file tree
Hide file tree
Showing 9 changed files with 404 additions and 83 deletions.
57 changes: 31 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,41 @@

> Scaffold out an ES6 node module
Features:

* ES6 workflow with prepublish script
* Trustworthy README with Install, Usage, Api and License sections
* [Easy testability, `tdd` mode][tdd] and test coverage
* `npm init` compliant
* ES6 workflow
* Structured and trustworthy README
* Tests, tdd and test coverage
* [Ready to use with travis and coveralls](#next-steps)
* And obviously ![Badges][badges] for npm, tests, coverage and dependencies
* Eslint, jscs and editorconfig support
* Windows friendly
* ![Badges][badges]

## For whom?

For us and you. Specifically suitable for:

* nordnet’s open-source and internal projects (yep, we kinda lazy)
* for other companies’s open-source projects
* for personal open-source node modules

## Extra questions:

Generator will ask several questions. Main question is do you want to create _corporate_ or your own project? Not less important question is do you want to open-source your new project or not?

> corporate? Yn
Positive answer will lead to few questions about your company (name, github, site) and answers will be reflected almost only in License section.

> open-source? Yn
Positive answer will lead to github optimised workflow, otherwize you
will be asked about [publishConfig][sinopia] url and end up with custom stash'n'jenkins flow.

![transparent-banking example](https://i.imgur.com/tqbTOVH.png)

[tdd]: https://iamstarkov.com/start-with-testing/
[badges]: https://img.shields.io/badge/with-badges-brightgreen.svg?style=flat-square

![transparent-banking example](https://i.imgur.com/CUXqF1W.png)
[sinopia]: https://docs.npmjs.com/misc/registry#i-don-t-want-my-package-published-in-the-official-registry-it-s-private "I don't want my package published in the official registry. It's private."

## Install

Expand All @@ -37,24 +60,6 @@ Features:
git init
git commit -am 'init commit'

### Next steps:

1. Push it to your github repo
2. Enable your project on travis: https://travis-ci.org/profile/
![travis](http://i.imgur.com/mN4EvhC.png)
3. Enable your project on coveralls: https://coveralls.io/repos/new
![coveralls](http://i.imgur.com/ApfXMLl.png)
4. Write some tests in tests.js
5. Run tdd mode: `npm run tdd`
6. Write your module to pass the tests
7. When all tests are green bump major version and publish it:
```js
npm version major
npm publish
```
Your package will be tagged, commited, transpiled, published, cleaned up and pushed all the changes to github automagically ✨, take a look at scripts section.
8. You are awesome! ✨💫

## License

MIT © [Nordnet Bank AB](https://www.nordnet.se/)
Expand Down
123 changes: 100 additions & 23 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,121 @@
var yeoman = require('yeoman-generator');
var _s = require('underscore.string');
var mkdirp = require('mkdirp');
var normalizeUrl = require('normalize-url');
var humanizeUrl = require('humanize-url');

module.exports = yeoman.generators.Base.extend({
init: function () {
var cb = this.async();

this.prompt([{
name: 'isCorporate',
message: 'corporate?',
type: 'confirm',
store: true,
default: true,
}, {
name: 'isOpensource',
message: 'open-source?',
type: 'confirm',
default: true,
}, {
name: 'moduleName',
message: 'name:',
default: this.appname.replace(/\s/g, '-'),
filter: function (val) {
return _s.slugify(val);
}
filter: function (val) { return _s.slugify(val); },
}, {
name: 'moduleDesc',
message: 'description:'
message: 'description:',
}, {
name: 'moduleKeywords',
message: 'keywords:'
message: 'keywords:',
}, {
name: 'moduleVersion',
message: 'version:',
store: true,
default: '0.0.0',
}, {
name: 'moduleLicense',
message: 'license:',
store: true,
default: 'MIT',
}, {
name: 'github',
message: 'your github:',
store: true,
validate: function (val) {
return val.length > 0 ? true : 'You have to provide a username';
},
}, {
name: 'site',
message: 'your site:',
store: true,
filter: function (val) { return normalizeUrl(val); },
}, {
when: function(props) { return props.isCorporate; },
name: 'companyName',
message: 'company name:',
store: true,
}, {
when: function(props) { return props.isCorporate; },
name: 'companyGithub',
message: 'company github:',
store: true,
validate: function (val) {
return val.length > 0 ? true : 'You have to provide a username';
},
}, {
when: function(props) { return props.isCorporate; },
name: 'companySite',
message: 'company site:',
store: true,
}, {
when: function(props) { return !props.isOpensource; },
name: 'repositoryUrl',
message: 'repository:'
message: 'repository url:',
validate: function (val) {
return val.length > 0 ? true : 'You have to repositoryUrl URL';
},
}, {
when: function(props) { return !props.isOpensource; },
name: 'publishConfig',
message: 'publishConfig:',
store: true,
validate: function (val) {
return val.length > 0 ? true : 'You have to provide a publishConfig URL';
},
}], function (props) {
var name = this.user.git.name();
var email = this.user.git.email();
var moduleKeywords = (props.moduleKeywords || '').trim().split(',').map(function(i) { return (i || '').trim(); });
var licenseName = props.isCorporate ? props.companyName : name;
var licenseSite = props.isCorporate ? props.companySite : props.site;
var humanizedSite = props.site && humanizeUrl(props.site);
var humanizedCompanySite = (props.isCorporate && props.companySite) && humanizeUrl(props.companySite);
var humanizedLicenseSite = licenseSite && humanizeUrl(licenseSite);

var tpl = {
moduleName: props.moduleName,
camelModuleName: _s.camelize(props.moduleName),
moduleDesc: props.moduleDesc,
moduleKeywords: (props.moduleKeywords || '').trim().split(',').map(function(i) { return (i || '').trim(); }),
moduleKeywords: moduleKeywords,
moduleVersion: props.moduleVersion,
camelModuleName: _s.camelize(props.moduleName),
name: this.user.git.name(),
email: this.user.git.email(),
moduleLicense: props.moduleLicense,
github: props.isCorporate ? props.companyGithub : props.github,
licenseName: licenseName,
licenseSite: licenseSite,
humanizedLicenseSite: humanizedLicenseSite,
name: name,
email: email,
site: props.site,
repositoryUrl: props.repositoryUrl,
isCorporate: props.isCorporate,
isOpensource: props.isOpensource,
companyName: props.companyName,
companySite: props.companySite,
humanizedSite: humanizedSite,
humanizedCompanySite: humanizedCompanySite,
publishConfig: props.publishConfig,
};

Expand All @@ -53,24 +128,26 @@ module.exports = yeoman.generators.Base.extend({
mkdirp('src');
mkdirp('test');

cpTpl('_index.js', 'src/index.js');
cpTpl('_README.md', 'README.md');
cpTpl('_index.js', 'src/index.js');
cpTpl('_index.test.js', 'test/index.test.js');
cpTpl('mocha.opts', 'test/mocha.opts');
cpTpl('_package.json', 'package.json');
cpTpl('_README.md', 'README.md');
cpTpl('travis.yml', '.travis.yml');
cpTpl('istanbul.yml', '.istanbul.yml');
cpTpl('editorconfig', '.editorconfig');
cpTpl('gitignore', '.gitignore');
cpTpl('npmignore', '.npmignore');
cpTpl('eslintrc', '.eslintrc');
cpTpl('eslintignore', '.eslintignore');
cpTpl('jscsrc', '.jscsrc');
cpTpl('_package.json', 'package.json');
cpTpl('editorconfig', '.editorconfig');

cpTpl('travis.yml', '.travis.yml');
cpTpl('jscsrc', '.jscsrc');
cpTpl('eslintrc', '.eslintrc');
cpTpl('eslintignore', '.eslintignore');

cpTpl('gitignore', '.gitignore');
cpTpl('npmignore', '.npmignore');
cpTpl('istanbul.yml', '.istanbul.yml');
cpTpl('mocha.opts', 'test/mocha.opts');

cb();
}.bind(this));
},
install: function () {
this.installDependencies({bower: false});
this.installDependencies({ bower: false });
}
});
20 changes: 10 additions & 10 deletions app/templates/_README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# <%= moduleName %>

[![NPM version][npm-image]][npm-url]
<% if (isOpensource) { %>[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Coveralls Status][coveralls-image]][coveralls-url]
[![Dependency Status][depstat-image]][depstat-url]
[![Dependency Status][depstat-image]][depstat-url]<% } %>

> <%= moduleDesc %>
Expand Down Expand Up @@ -41,16 +41,16 @@ Lorem ipsum.

## License

MIT © [Nordnet Bank AB](https://www.nordnet.se/)
<%= moduleLicense %> © <% if (licenseSite) { %>[<%= licenseName %>](<%= humanizedLicenseSite %>)<% } else { %><%= licenseName %><% } %>

[npm-url]: https://npmjs.org/package/<%= moduleName %>
<% if (isOpensource) { %>[npm-url]: https://npmjs.org/package/<%= moduleName %>
[npm-image]: https://img.shields.io/npm/v/<%= moduleName %>.svg?style=flat-square

[travis-url]: https://travis-ci.org/nordnet/<%= moduleName %>
[travis-image]: https://img.shields.io/travis/nordnet/<%= moduleName %>.svg?style=flat-square
[travis-url]: https://travis-ci.org/<%= github %>/<%= moduleName %>
[travis-image]: https://img.shields.io/travis/<%= github %>/<%= moduleName %>.svg?style=flat-square

[coveralls-url]: https://coveralls.io/r/nordnet/<%= moduleName %>
[coveralls-image]: https://img.shields.io/coveralls/nordnet/<%= moduleName %>.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/<%= github %>/<%= moduleName %>
[coveralls-image]: https://img.shields.io/coveralls/<%= github %>/<%= moduleName %>.svg?style=flat-square

[depstat-url]: https://david-dm.org/nordnet/<%= moduleName %>
[depstat-image]: https://david-dm.org/nordnet/<%= moduleName %>.svg?style=flat-square
[depstat-url]: https://david-dm.org/<%= github %>/<%= moduleName %>
[depstat-image]: https://david-dm.org/<%= github %>/<%= moduleName %>.svg?style=flat-square<% } %>
26 changes: 18 additions & 8 deletions app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,48 @@
},<% } %>
"scripts": {
"clean": "trash dist",
"build": "babel src --out-dir dist",
"transpile": "babel src --out-dir dist",
"eslint": "eslint src",
"eslint:jenkins": "eslint src -f checkstyle -o reports/lintresult.xml",
"jscs": "jscs -c .jscsrc src",
"jscs": "jscs src",
"lint": "npm-run-all jscs eslint",
<% if (isOpensource) { %>
"test": "mocha",
"tdd": "npm test -- --watch",
<% } else { %>
"eslint:jenkins": "eslint src -f checkstyle -o reports/lintresult.xml",
"reports:rm": "trash reports/",
"reports:mkdir": "mkdirp reports",
"prelint:jenkins": "npm-run-all reports:rm reports:mkdir",
"lint:jenkins": "npm-run-all jscs eslint:jenkins",
"pretest": "npm-run-all reports:rm reports:mkdir",
"test": "BABEL_DISABLE_CACHE=1 mocha",
"posttest": "npm run reports",
"tdd": "npm test -- --watch",
"prereports": "echo '<?xml version=\"1.0\"?>' > reports/test-results.xml",
"reports": "npm-run-all reports:tests reports:coverage",
"reports:tests": "BABEL_DISABLE_CACHE=1 mocha --reporter xunit | grep \"<\" >> reports/test-results.xml",
"reports:coverage": "BABEL_DISABLE_CACHE=1 istanbul cover node_modules/mocha/bin/_mocha",
"tdd": "npm test -- --watch",
"reports:coverage": "BABEL_DISABLE_CACHE=1 istanbul cover _mocha",
<% } %>
"validate": "npm-run-all lint test",
"prepush": "npm run validate",
"prepublish": "npm run build",
"prepublish": "npm run transpile",
"push": "git push --follow-tags",
"postpublish": "npm-run-all clean push"
},
"repository": {
"type": "git",
"url": "<%= repositoryUrl %>"
"url": <% if (isOpensource) { %>"git+https://github.com/<%= github %>/<%= moduleName %>.git"<% } else { %>"<%= repositoryUrl %>"<% } %>
},
"keywords": [
<% moduleKeywords.forEach(function(keyword, i, arr) { %>"<%= keyword %>"<% if (i !== arr.length - 1) { %>,
<% } %><% }); %>
],
"author": "<%= name %> <<%= email %>>",
"author": "<%= name %> <<%= email %>> <% if (site) { %>(<%= humanizedSite %>)<% } %>",
"license": "<%= moduleLicense %>",
<% if (isOpensource) { %>"bugs": {
"url": "https://github.com/<%= github %>/<%= moduleName %>/issues"
},
"homepage": "https://github.com/<%= github %>/<%= moduleName %>#readme",<% } %>
"devDependencies": {
"babel": "^5.5.8",
"babel-core": "^5.6.18",
Expand Down
5 changes: 2 additions & 3 deletions app/templates/eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
lib
**/node_modules
**/webpack.config.js
dist
**/webpack.config.js
3 changes: 0 additions & 3 deletions app/templates/eslintrc
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
{
"extends": "eslint-config-airbnb",
"env": {
"browser": true,
"mocha": true,
"node": true,
"es6": true
},
"globals": {
"sinon": true
},
"rules": {
"no-use-before-define": [2, "nofunc"],
"comma-dangle": [2, "always-multiline"]
}
}
4 changes: 2 additions & 2 deletions app/templates/jscsrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"fileExtensions": [".js"],

"excludeFiles": [
"*.es5.js",
"dist/**",
"node_modules/**"
],

"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties"
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
},
"homepage": "https://github.com/nordnet/generator-nordnet-es-module#readme",
"devDependencies": {
"assert": "^1.3.0",
"babel": "*",
"coveralls": "*",
"fs-extra": "^0.22.1",
"istanbul": "*",
"mocha": "*",
"rimraf": "^2.4.2",
Expand Down

0 comments on commit 17dbe3c

Please sign in to comment.