11 Commits
Author SHA1 Message Date
Gajus Kuizinas 2450b7202e chore: use semantic-release 2016-11-29 17:51:38 +00:00
Gajus Kuizinas 707ae70240 style: sort properties alphabetically 2016-11-29 17:50:16 +00:00
Gajus Kuizinas c6952fa1e1 chore: add a precommit hook 2016-11-29 17:49:57 +00:00
Gajus Kuizinas e6ebaec387 chore: setup env when running scripts 2016-11-29 17:49:44 +00:00
Gajus Kuizinas 1f0a517797 style: fix style issues 2016-11-29 17:49:05 +00:00
Gajus Kuizinas 7867b8f8c7 chore: use default travis test script 2016-11-29 17:48:50 +00:00
Gajus Kuizinas 9cfc2ad367 Merge branch 'master' of github.com:gajus/create-index 2016-11-29 17:45:58 +00:00
Gajus Kuizinas ab6c399241 fix: correct all the references to @create-index 2016-11-29 17:45:54 +00:00
laggingreflexandGajus Kuizinas fdb17d0179 feat: ability to add banner (#20)
Lets you add a custom banner.

```sh
create-index src -u --banner "/* eslint-disable */"
```
```js
/* eslint-disable */

// @create-index

import xxx ...
```
2016-11-29 17:45:23 +00:00
laggingreflexandGajus Kuizinas d7e2528999 fix: rename --update-index to --update (fixes #10) (#15) 2016-11-28 15:36:37 +00:00
laggingreflexandGajus Kuizinas 974142c38c fix: use comment to target files (fixes #5) (#17) 2016-11-28 15:35:43 +00:00
10 changed files with 78 additions and 55 deletions
+3 -4
View File
@@ -1,12 +1,11 @@
language: node_js language: node_js
node_js: node_js:
- node
- 7 - 7
- 6 - 6
- 5 - 5
scripts: after_success:
- npm run test - semantic-release pre && npm publish && semantic-release post
- npm run lint
- npm run build
notifications: notifications:
email: false email: false
sudo: false sudo: false
+5 -4
View File
@@ -83,9 +83,10 @@ create-index --help
Options: Options:
--update, -u Recursively iterates target directories looking for "index.js" --update, -u Recursively iterates target directories looking for "index.js"
files that start with "'create index';\n" (create-index index files that start with "// @create-index\n" (create-index index
file). Updates found index files. Does not create new index file). Updates found index files. Does not create new index
files. [boolean] [default: false] files. [boolean] [default: false]
--banner Add a custom banner at the top of the index file [string]
Examples: Examples:
create-index ./src ./src/utilities Creates or updates an existing create-index ./src ./src/utilities Creates or updates an existing
@@ -172,7 +173,7 @@ drwxr-xr-x 2 gajus staff 68B 6 Jan 15:29 foo
Given the above directory contents, `./index.js` will be: Given the above directory contents, `./index.js` will be:
```js ```js
'create index'; // @create-index
import bar from './bar'; import bar from './bar';
import foo from './foo.js'; import foo from './foo.js';
@@ -187,6 +188,6 @@ When file has the same name as a sibling directory, file `import` takes preceden
Directories that do not have `./index.js` in themselves will be excluded. Directories that do not have `./index.js` in themselves will be excluded.
When run again, `create-index` will update existing `./index.js` if it starts with `'create index';\n\n`. When run again, `create-index` will update existing `./index.js` if it starts with `// @create-index\n\n`.
If `create-index` is executed against a directory that contains `./index.js`, which does not start with `'create index';\n\n`, an error will be thrown. If `create-index` is executed against a directory that contains `./index.js`, which does not start with `// @create-index\n\n`, an error will be thrown.
+35 -32
View File
@@ -1,33 +1,18 @@
{ {
"name": "create-index",
"description": "Creates ES6 ./index.js file in target directories that imports and exports all sibling files and directories.",
"version": "1.0.0",
"main": "./dist/index.js",
"bin": "./dist/bin/create-index.js",
"repository": {
"type": "git",
"url": "https://github.com/gajus/create-index"
},
"keywords": [
"index",
"import",
"export"
],
"engines": {
"node": ">=5"
},
"author": { "author": {
"name": "Gajus Kuizinas",
"email": "gajus@gajus.com", "email": "gajus@gajus.com",
"name": "Gajus Kuizinas",
"url": "http://gajus.com" "url": "http://gajus.com"
}, },
"license": "BSD-3-Clause", "bin": "./dist/bin/create-index.js",
"scripts": { "dependencies": {
"lint": "eslint ./src ./tests", "chalk": "^1.1.3",
"test": "mocha --compilers js:babel-register", "glob": "^7.1.1",
"build": "babel --source-maps --copy-files ./src --out-dir ./dist", "lodash": "^4.16.6",
"create-index": "node ./dist/bin/create-index ./src/utilities" "moment": "^2.15.2",
"yargs": "^6.3.0"
}, },
"description": "Creates ES6 ./index.js file in target directories that imports and exports all sibling files and directories.",
"devDependencies": { "devDependencies": {
"babel-cli": "^6.18.0", "babel-cli": "^6.18.0",
"babel-plugin-transform-es2015-destructuring": "^6.18.0", "babel-plugin-transform-es2015-destructuring": "^6.18.0",
@@ -38,13 +23,31 @@
"chai": "^3.5.0", "chai": "^3.5.0",
"eslint": "^3.9.1", "eslint": "^3.9.1",
"eslint-config-canonical": "^4.0.0", "eslint-config-canonical": "^4.0.0",
"mocha": "^3.1.2" "husky": "^0.11.9",
"mocha": "^3.1.2",
"semantic-release": "^6.3.2"
}, },
"dependencies": { "engines": {
"glob": "^7.1.1", "node": ">=5"
"lodash": "^4.16.6", },
"yargs": "^6.3.0", "keywords": [
"chalk": "^1.1.3", "index",
"moment": "^2.15.2" "import",
} "export"
],
"license": "BSD-3-Clause",
"main": "./dist/index.js",
"name": "create-index",
"repository": {
"type": "git",
"url": "https://github.com/gajus/create-index"
},
"scripts": {
"build": "NODE_ENV=production babel --source-maps --copy-files ./src --out-dir ./dist",
"create-index": "node ./dist/bin/create-index ./src/utilities",
"lint": "NODE_ENV=development eslint ./src ./tests",
"precommit": "npm run test",
"test": "npm run build && npm run lint && NODE_ENV=development mocha --compilers js:babel-register"
},
"version": "1.0.0"
} }
+10 -3
View File
@@ -8,17 +8,24 @@ import {
const argv = yargs const argv = yargs
.demand(1) .demand(1)
.options({ .options({
'update': { update: {
alias: 'u', alias: 'u',
default: false, default: false,
description: 'Recursively iterates target directories looking for "index.js" files that start with "\'create index\';\\n" (create-index index file). Updates found index files. Does not create new index files.', description: 'Recursively iterates target directories looking for "index.js" files that start with "// @create-index\\n" (create-index index file). Updates found index files. Does not create new index files.',
type: 'boolean' type: 'boolean'
} }
}) })
.options({
banner: {
description: 'Add a custom banner at the top of the index file',
type: 'string'
}
})
.example('create-index ./src ./src/utilities', 'Creates or updates an existing create-index index file in the target (./src, ./src/utilities) directories.') .example('create-index ./src ./src/utilities', 'Creates or updates an existing create-index index file in the target (./src, ./src/utilities) directories.')
.example('create-index --update ./src ./tests', 'Finds all create-index index files in the target directories and descending directories. Updates found index files.') .example('create-index --update ./src ./tests', 'Finds all create-index index files in the target directories and descending directories. Updates found index files.')
.argv; .argv;
writeIndexCli(argv._, { writeIndexCli(argv._, {
updateIndex: argv.updateIndex banner: argv.banner,
updateIndex: argv.update
}); });
+14 -2
View File
@@ -22,10 +22,22 @@ const buildExportBlock = (files) => {
return importBlock; return importBlock;
}; };
export default (filePaths) => { export default (filePaths, options = {}) => {
let code; let code;
code = '\'create index\';\n\n'; code = '';
if (options.banner) {
const banners = _.isArray(options.banner) ? options.banner : [options.banner];
banners.forEach((banner) => {
code += banner + '\n';
});
code += '\n';
}
code += '// @create-index\n\n';
if (filePaths.length) { if (filePaths.length) {
const sortedFilePaths = filePaths.sort(); const sortedFilePaths = filePaths.sort();
+1 -2
View File
@@ -1,4 +1,4 @@
'create index'; // @create-index
export createIndexCode from './createIndexCode.js'; export createIndexCode from './createIndexCode.js';
export findIndexFiles from './findIndexFiles.js'; export findIndexFiles from './findIndexFiles.js';
@@ -8,4 +8,3 @@ export sortByDepth from './sortByDepth.js';
export validateTargetDirectory from './validateTargetDirectory.js'; export validateTargetDirectory from './validateTargetDirectory.js';
export writeIndex from './writeIndex.js'; export writeIndex from './writeIndex.js';
export writeIndexCli from './writeIndexCli.js'; export writeIndexCli from './writeIndexCli.js';
+3 -1
View File
@@ -35,7 +35,9 @@ export default (directoryPaths, options = {}) => {
const siblings = readDirectory(directoryPath); const siblings = readDirectory(directoryPath);
const indexCode = createIndexCode(siblings); const indexCode = createIndexCode(siblings, {
banner: options.banner
});
const indexFilePath = path.resolve(directoryPath, 'index.js'); const indexFilePath = path.resolve(directoryPath, 'index.js');
+5 -5
View File
@@ -11,14 +11,14 @@ describe('createIndexCode()', () => {
const indexCode = createIndexCode([]); const indexCode = createIndexCode([]);
expect(indexCode).to.equal(codeExample(` expect(indexCode).to.equal(codeExample(`
'create index'; // @create-index
`)); `));
}); });
it('describes a single child', () => { it('describes a single child', () => {
const indexCode = createIndexCode(['foo']); const indexCode = createIndexCode(['foo']);
expect(indexCode).to.equal(codeExample(` expect(indexCode).to.equal(codeExample(`
'create index'; // @create-index
export foo from './foo'; export foo from './foo';
`)); `));
@@ -27,7 +27,7 @@ export foo from './foo';
const indexCode = createIndexCode(['bar', 'foo']); const indexCode = createIndexCode(['bar', 'foo']);
expect(indexCode).to.equal(codeExample(` expect(indexCode).to.equal(codeExample(`
'create index'; // @create-index
export bar from './bar'; export bar from './bar';
export foo from './foo'; export foo from './foo';
@@ -38,7 +38,7 @@ export foo from './foo';
const indexCode = createIndexCode(['foo.js']); const indexCode = createIndexCode(['foo.js']);
expect(indexCode).to.equal(codeExample(` expect(indexCode).to.equal(codeExample(`
'create index'; // @create-index
export foo from './foo.js'; export foo from './foo.js';
`)); `));
@@ -49,7 +49,7 @@ export foo from './foo.js';
const indexCode = createIndexCode(['foo', 'bar']); const indexCode = createIndexCode(['foo', 'bar']);
expect(indexCode).to.equal(codeExample(` expect(indexCode).to.equal(codeExample(`
'create index'; // @create-index
export bar from './bar'; export bar from './bar';
export foo from './foo'; export foo from './foo';
+1 -1
View File
@@ -1,4 +1,4 @@
'create index'; // @create-index
export bar from './bar'; export bar from './bar';
export foo from './foo.js'; export foo from './foo.js';
+1 -1
View File
@@ -27,7 +27,7 @@ describe('writeIndex()', () => {
const indexCode = fs.readFileSync(indexFilePath, 'utf8'); const indexCode = fs.readFileSync(indexFilePath, 'utf8');
expect(indexCode).to.equal(codeExample(` expect(indexCode).to.equal(codeExample(`
'create index'; // @create-index
export bar from './bar'; export bar from './bar';
export foo from './foo.js'; export foo from './foo.js';