Skip to content

Commit

Permalink
Added support for npm scoped modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wil Moore III committed Apr 26, 2015
1 parent d96ac4c commit 174ba38
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 12 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change Log
All notable changes to this project will be documented in this file (keepachangelog.com).

## 0.6.0 - 2015-04-26
### Added
- Added support for npm scoped modules.

## 0.5.1 - 2015-04-23
### Changed
- [root/index.js] imports and exports block updated to use ! instead of *.
Expand Down
39 changes: 39 additions & 0 deletions init.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ exports.configure = [

exports.beforeRender = function (utils, config) {
config.date = (new Date().toISOString()).split('T')[0]
config.repo_name = repoName(config.repo_name)
config.github_clone_url = format('https://github.com/%s/%s.git', config.github_user_name, config.repo_name)
config.simple_name = simpleName(config.repo_name)
config.export_name = exportName(config.repo_name)
config.author_full_name = gitConfigGet('user.name')
}

Expand All @@ -55,6 +58,42 @@ exports.after = function (utils, config) {
console.log('\nYour CommonJS package has been generated. To get started, type: \n\n cd %s && npm install && npm run dev\n', config.repo_name)
}

function exportName (name) {
return camel(simpleName(name))
}

function simpleName (name) {
return name.split(/^node-/).pop().split('.').shift()
}

function camel (name) {
return name
.split(/[-_]/)
.map(ucfirst)
.join('')
}

function ucfirst (str, idx) {
return idx
? str.replace(/^./, str[0].toUpperCase())
: str
}

/**
* Normalize repo name
*
* @param {String} name
* repository name.
*
* @return {String}
* normalized repository name.
*/

function repoName (name) {
// in case user inputs user/repo, we just take `repo` part.
return name.split('/').pop()
}

function gitConfigGet (key) {
return exec('git config --get ' + key).toString().trim()
}
4 changes: 2 additions & 2 deletions locals.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"github_user_name": "wilmoore",
"github_user_email": "wil.moore@wilmoore.com",
"package_name": "tiny",
"repo_name": "tiny.js",
"package_name": "@wilmoore/tiny",
"repo_name": "node-tiny.js",
"package_description": "Tiny Library.",
"travis": true
}
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* Contributer [Guidelines](https://github.com/blog/1184-contributing-guidelines).
* [EditorConfig](http://editorconfig.org) support.
* [MIT](LICENSE) license.
* Supports npm scoped modules.

## Input-based template variables

Expand Down
4 changes: 2 additions & 2 deletions root/contributing.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing to <%= package_name %>
# Contributing to <%= simple_name %>

Below are a few ways to make contributing to `<%= package_name %>` smoother.
Below are a few ways to make contributing to `<%= simple_name %>` smoother.

## Issues

Expand Down
4 changes: 2 additions & 2 deletions root/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var format = require('util').format
* exports.
*/

module.exports = <%= S.camelize(package_name) %>
module.exports = <%= export_name %>

/**
* <%= package_description %>
Expand All @@ -22,6 +22,6 @@ module.exports = <%= S.camelize(package_name) %>
* string literal.
*/

function <%= S.camelize(package_name) %> (string) {
function <%= export_name %> (string) {
return format('%s', string)
}
10 changes: 5 additions & 5 deletions root/readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# <%= package_name %> [![Build Status](http://img.shields.io/travis/wilmoore/<%= repo_name %>.svg)](https://travis-ci.org/wilmoore/<%= repo_name %>) [![Code Climate](https://codeclimate.com/github/wilmoore/<%= repo_name %>/badges/gpa.svg)](https://codeclimate.com/github/wilmoore/<%= repo_name %>) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)
# <%= package_name %> [![Build Status](http://img.shields.io/travis/<%= github_user_name %>/<%= repo_name %>.svg)](https://travis-ci.org/<%= github_user_name %>/<%= repo_name %>) [![Code Climate](https://codeclimate.com/github/<%= github_user_name %>/<%= repo_name %>/badges/gpa.svg)](https://codeclimate.com/github/<%= github_user_name %>/<%= repo_name %>) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)

> <%= package_description %>
Expand All @@ -8,13 +8,13 @@

###### npm stats

[![npm](https://img.shields.io/npm/v/<%= package_name %>.svg)](https://www.npmjs.org/package/<%= package_name %>) [![NPM downloads](http://img.shields.io/npm/dm/<%= package_name %>.svg)](https://www.npmjs.org/package/<%= package_name %>) [![Dependency Status](https://gemnasium.com/wilmoore/<%= repo_name %>.svg)](https://gemnasium.com/wilmoore/<%= repo_name %>)
[![npm](https://img.shields.io/npm/v/<%= package_name %>.svg)](https://www.npmjs.org/package/<%= package_name %>) [![NPM downloads](http://img.shields.io/npm/dm/<%= package_name %>.svg)](https://www.npmjs.org/package/<%= package_name %>) [![Dependency Status](https://gemnasium.com/<%= github_user_name %>/<%= repo_name %>.svg)](https://gemnasium.com/<%= github_user_name %>/<%= repo_name %>)

## Example

```js
var <%= S.camelize(package_name) %> = require('<%= package_name %>');
<%= S.camelize(package_name) %>('training')
var <%= export_name %> = require('<%= package_name %>');
<%= export_name %>('training')
//=> training
```

Expand All @@ -28,7 +28,7 @@ var <%= S.camelize(package_name) %> = require('<%= package_name %>');

## API

> `<%= S.camelize(package_name) %>(string)`
> `<%= export_name %>(string)`
###### Arguments

Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var parameters = [
{ file: 'package.json', pattern: format('"name": "%s"', locals.package_name) },
{ file: 'readme.md', pattern: /tiny\('training'\)/ },
{ file: 'license', pattern: locals.github_user_email },
{ file: 'contributing.md', pattern: format('Contributing to %s', locals.package_name) },
{ file: 'contributing.md', pattern: 'Contributing to tiny' },
{ file: 'test.js', pattern: format('%s()', locals.package_name) },
{ file: '.travis.yml', pattern: 'language: node_js' }
]
Expand Down

0 comments on commit 174ba38

Please sign in to comment.