Skip to content

Commit 54ca532

Browse files
author
Christoph Hermann
committed
initial
0 parents  commit 54ca532

13 files changed

+260
-0
lines changed

Diff for: .coveralls.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
service_name: travis-pro
2+
repo_token: 1R8MpkkyI05rOZnyUZvlDYGtUqcOZVz5R

Diff for: .editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
indent_style = tab
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[{package.json,*.yml}]
11+
indent_style = space
12+
indent_size = 2
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

Diff for: .gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

Diff for: .gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules
2+
npm-debug.log
3+
*.js
4+
!cli.js
5+
!module/*.js
6+
!tests/*.js
7+
!utils/*.js
8+
coverage

Diff for: .jshintrc

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"node": true,
3+
"esnext": true,
4+
"bitwise": true,
5+
"curly": true,
6+
"immed": true,
7+
"newcap": true,
8+
"noarg": true,
9+
"undef": true,
10+
"unused": "vars",
11+
"eqnull": true
12+
}

Diff for: .travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- 'iojs'
5+
- '0.12'
6+
- '0.10'
7+
after_script: "npm run coveralls"

Diff for: CONTRIBUTING.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Contributing
2+
3+
:heart: We love pull requests from everyone!
4+
5+
Make sure to...
6+
7+
* add tests
8+
* keep 100% coverage
9+
* only write ***ONE LINE OF CODE***
10+
* and still keep it readable
11+
* update the README
12+
13+
## Getting started
14+
15+
1. `git clone https://github.com/1-liners/module-indexer`
16+
2. `npm install`
17+
3. add your new awesome feature
18+
4. `npm test`
19+
5. `npm run toc`
20+
6. push your commits (except compiled files in the root folder)
21+
22+
During development you can run `npm run develop` to start [nodangel](https://github.com/tomekwi/nodangel).
23+
24+

Diff for: README.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[![Coverage Status](https://coveralls.io/repos/1-liners/module-indexer/badge.svg?branch=master)](https://coveralls.io/r/1-liners/module-indexer?branch=master)
2+
[![Build Status](https://travis-ci.org/1-liners/module-indexer.svg?branch=master)](https://travis-ci.org/1-liners/module-indexer)
3+
[![Dependency Status](https://david-dm.org/1-liners/module-indexer.svg)](https://david-dm.org/1-liners/module-indexer)
4+
[![npm version](https://badge.fury.io/js/module-indexer.svg)](http://badge.fury.io/js/module-indexer)
5+
6+
module-indexer
7+
====
8+
9+
> creates a `index.js` for es6 modules
10+
11+
## Usage
12+
13+
### Install
14+
15+
```
16+
$ npm install --save module-indexer
17+
```
18+
19+
### Usage
20+
21+
```js
22+
import moduleIndexer from 'module-indexer';
23+
24+
moduleIndexer(__dirname, (err) => err? console.error('Doh!') : console.log('Created'));
25+
```
26+
27+
### CLI
28+
29+
```bash
30+
module-indexer ./
31+
```
32+
33+
## Maintainers
34+
35+
| [![stoeffel](https://avatars.githubusercontent.com/u/1217681?v=3&s=80)](https://github.com/stoeffel) | [![hemanth](https://avatars.githubusercontent.com/u/18315?v=3&s=80)](https://github.com/hemanth) | [![tomekwi](https://avatars.githubusercontent.com/u/4624660?v=3&s=80)](https://github.com/tomekwi) |
36+
| :--:|:--:|:--: |
37+
| [stoeffel](https://github.com/stoeffel) | [hemanth](https://github.com/hemanth) | [tomekwi](https://github.com/tomekwi) |
38+
39+
created with [gh-contributors-table](https://github.com/stoeffel/gh-contributors-table)
40+
41+
42+
## License
43+
44+
MIT © [stoeffel](http://schtoeffel.ch) [tomekwi](http://github.com/tomekwi) [hemanth](http://www.h3manth.com/)

Diff for: license

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) stoeffel <[email protected]> (schtoeffel.ch)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

Diff for: module/cli.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env node
2+
3+
var meow = require('meow');
4+
var moduleIndexer = require('./');
5+
6+
var cli = meow({
7+
help: [
8+
'Usage',
9+
' module-indexer <dir>'
10+
].join('\n')
11+
});
12+
13+
moduleIndexer(cli.input[0], (err, modules) => {
14+
if (err) console.error(err);
15+
else console.log(`index.js created in ${cli.input[0]}/module`);
16+
});

Diff for: module/index.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import getModules from 'get-modules';
2+
import { writeFile } from 'fs';
3+
import path from 'path';
4+
import curry from 'chickencurry';
5+
import map from '1-liners/map';
6+
import join from '1-liners/join';
7+
import compose from '1-liners/compose';
8+
import reduce from '1-liners/reduce';
9+
import filter from '1-liners/filter';
10+
11+
const mapλ = curry(map);
12+
const joinλ = curry(join);
13+
const filterλ = curry(filter);
14+
15+
const removeExt = mapλ(module => module.replace('.js', ''));
16+
const filterIndex = filterλ(module => module !== 'index.js');
17+
18+
const createImports = reduce(compose, [
19+
joinλ('\n'),
20+
mapλ(module => `import ${module} from './${module}';`),
21+
removeExt,
22+
filterIndex
23+
]);
24+
25+
const createExport = reduce(compose, [
26+
joinλ(',\n '),
27+
removeExt,
28+
filterIndex
29+
]);
30+
31+
export default function( root, callback ) {
32+
return getModules(root, (err, modules) => {
33+
if (err) throw err;
34+
let imports = createImports(modules);
35+
let exportDefault = `export {\n ${createExport(modules)}\n};`;
36+
writeFile(path.join(root, 'module', 'index.js'), `${imports}\n\n${exportDefault}`, callback);
37+
});
38+
}

Diff for: package.json

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "module-indexer",
3+
"version": "1.0.0",
4+
"description": "creates a `index.js` for es6 modules",
5+
"license": "MIT",
6+
"repository": "1-liners/module-indexer",
7+
"author": {
8+
"name": "stoeffel",
9+
"email": "[email protected]",
10+
"url": "schtoeffel.ch"
11+
},
12+
"engines": {
13+
"node": ">=0.10.0"
14+
},
15+
"bin": {
16+
"module-indexer": "cli.js"
17+
},
18+
"scripts": {
19+
"prepush": "npm test",
20+
"develop": "nodangel --watch module --watch tests --exec 'npm --silent test'",
21+
"istanbul": "istanbul cover ./node_modules/mocha/bin/_mocha -- --report lcov --compilers js:babel/register --ui qunit ./tests",
22+
"mocha": "mocha --compilers js:babel/register --ui qunit ./tests",
23+
"compile": "cd ./module; babel --loose=all ./*.js --out-dir ../",
24+
"clean": "rm *.js",
25+
"coverage": "npm run compile; npm run istanbul; npm run clean",
26+
"coveralls": "npm run compile && npm run istanbul && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && npm run clean",
27+
"test": "npm run coverage",
28+
"prepublish": "npm test; npm run compile"
29+
},
30+
"files": [
31+
"/*.js",
32+
"/module/",
33+
"/license",
34+
"/readme.md"
35+
],
36+
"keywords": [
37+
"oneliners",
38+
"shorthands",
39+
"module-indexer"
40+
],
41+
"dependencies": {
42+
"1-liners": "^0.2.7",
43+
"chickencurry": "^1.4.0",
44+
"get-modules": "^1.0.2",
45+
"meow": "^3.1.0"
46+
},
47+
"devDependencies": {
48+
"babel": "^5.1.10",
49+
"coveralls": "^2.11.2",
50+
"husky": "^0.7.0",
51+
"istanbul": "^0.3.13",
52+
"mocha": "^2.2.4",
53+
"mocha-lcov-reporter": "0.0.2",
54+
"nodangel": "1.3.8"
55+
}
56+
}

Diff for: tests/index.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { throws, equal } from 'assert';
2+
import { readFileSync } from 'fs';
3+
import { join } from 'path';
4+
import moduleIndexer from '../index';
5+
6+
test('#moduleIndexer', (done) => {
7+
throws(() => moduleIndexer(null, 'nirvana', () => {}));
8+
9+
moduleIndexer(__dirname, ( err ) => {
10+
equal(err, null);
11+
equal(readFileSync(join(__dirname, 'module', 'index.js'), { encoding: 'utf8' }),
12+
readFileSync(join(__dirname, 'fixture', 'expected.js'), { encoding: 'utf8' }));
13+
done();
14+
})
15+
16+
});

0 commit comments

Comments
 (0)