diff --git a/README.md b/README.md index e587530..f11a771 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ create-index --help Options: --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 files. [boolean] [default: false] @@ -172,7 +172,7 @@ drwxr-xr-x 2 gajus staff 68B 6 Jan 15:29 foo Given the above directory contents, `./index.js` will be: ```js -'create index'; +// @create-index import bar from './bar'; import foo from './foo.js'; @@ -187,6 +187,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. -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. diff --git a/src/bin/create-index.js b/src/bin/create-index.js index 2ae6ebc..1d6434e 100644 --- a/src/bin/create-index.js +++ b/src/bin/create-index.js @@ -8,10 +8,10 @@ import { const argv = yargs .demand(1) .options({ - 'update': { + update: { alias: 'u', 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' } }) diff --git a/src/utilities/index.js b/src/utilities/index.js index ffbc3fa..b38d324 100644 --- a/src/utilities/index.js +++ b/src/utilities/index.js @@ -1,4 +1,4 @@ -'create index'; +// @create-index export createIndexCode from './createIndexCode.js'; export findIndexFiles from './findIndexFiles.js'; @@ -8,4 +8,3 @@ export sortByDepth from './sortByDepth.js'; export validateTargetDirectory from './validateTargetDirectory.js'; export writeIndex from './writeIndex.js'; export writeIndexCli from './writeIndexCli.js'; - diff --git a/test/createIndexCode.js b/test/createIndexCode.js index f5f650d..2d50057 100644 --- a/test/createIndexCode.js +++ b/test/createIndexCode.js @@ -11,14 +11,14 @@ describe('createIndexCode()', () => { const indexCode = createIndexCode([]); expect(indexCode).to.equal(codeExample(` -'create index'; +// @create-index `)); }); it('describes a single child', () => { const indexCode = createIndexCode(['foo']); expect(indexCode).to.equal(codeExample(` -'create index'; +// @create-index export foo from './foo'; `)); @@ -27,7 +27,7 @@ export foo from './foo'; const indexCode = createIndexCode(['bar', 'foo']); expect(indexCode).to.equal(codeExample(` -'create index'; +// @create-index export bar from './bar'; export foo from './foo'; @@ -38,7 +38,7 @@ export foo from './foo'; const indexCode = createIndexCode(['foo.js']); expect(indexCode).to.equal(codeExample(` -'create index'; +// @create-index export foo from './foo.js'; `)); @@ -49,7 +49,7 @@ export foo from './foo.js'; const indexCode = createIndexCode(['foo', 'bar']); expect(indexCode).to.equal(codeExample(` -'create index'; +// @create-index export bar from './bar'; export foo from './foo'; diff --git a/test/fixtures/write-index/mixed/index.js b/test/fixtures/write-index/mixed/index.js index 1c830cb..6b4bf06 100644 --- a/test/fixtures/write-index/mixed/index.js +++ b/test/fixtures/write-index/mixed/index.js @@ -1,4 +1,4 @@ -'create index'; +// @create-index export bar from './bar'; export foo from './foo.js'; diff --git a/test/writeIndex.js b/test/writeIndex.js index c843507..403a7fe 100644 --- a/test/writeIndex.js +++ b/test/writeIndex.js @@ -27,7 +27,7 @@ describe('writeIndex()', () => { const indexCode = fs.readFileSync(indexFilePath, 'utf8'); expect(indexCode).to.equal(codeExample(` -'create index'; +// @create-index export bar from './bar'; export foo from './foo.js';