Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6aac149a8b | ||
|
|
1efd1c6c7b | ||
|
|
ed8e1d0699 |
+4
-2
@@ -1,7 +1,9 @@
|
|||||||
root = true
|
root = true
|
||||||
|
|
||||||
[*]
|
[*]
|
||||||
|
charset = utf-8
|
||||||
end_of_line = lf
|
end_of_line = lf
|
||||||
insert_final_newline = true
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
indent_style = space
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
* text eol=lf
|
||||||
@@ -82,21 +82,34 @@ npm install create-index
|
|||||||
create-index --help
|
create-index --help
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--recursive, -r Create/update index files recursively. Halts on any unsafe
|
--recursive, -r Create/update index files recursively. Halts on any
|
||||||
"index.js" files. [boolean] [default: false]
|
unsafe "index.js" files. [boolean] [default: false]
|
||||||
--ignoreUnsafe, -i Ignores unsafe "index.js" files instead of halting.
|
--ignoreUnsafe, -i Ignores unsafe "index.js" files instead of halting.
|
||||||
[boolean] [default: false]
|
[boolean] [default: false]
|
||||||
--update, -u Updates only previously created index files (recursively).
|
--ignoreDirectories, -d Ignores importing directories into the index file,
|
||||||
|
even if they have a safe "index.js".
|
||||||
[boolean] [default: false]
|
[boolean] [default: false]
|
||||||
--banner Add a custom banner at the top of the index file [string]
|
--update, -u Updates only previously created index files
|
||||||
|
(recursively). [boolean] [default: false]
|
||||||
|
--banner Add a custom banner at the top of the index file
|
||||||
|
[string]
|
||||||
|
--extensions, -x Allows some extensions to be parsed as valid source.
|
||||||
|
First extension will always be preferred to homonyms
|
||||||
|
with another allowed extension.
|
||||||
|
[array] [default: ["js"]]
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
create-index ./src ./src/utilities Creates or updates an existing
|
create-index ./src ./src/utilities Creates or updates an existing
|
||||||
create-index index file in the target
|
create-index index file in the target
|
||||||
(./src, ./src/utilities) directories.
|
(./src, ./src/utilities) directories.
|
||||||
create-index --update ./src ./tests Finds all create-index index files in the
|
create-index --update ./src ./tests Finds all create-index index files in
|
||||||
target directories and descending
|
the target directories and descending
|
||||||
directories. Updates found index files.
|
directories. Updates found index
|
||||||
|
files.
|
||||||
|
create-index ./src --extensions js jsx Creates or updates an existing
|
||||||
|
create-index index file in the target
|
||||||
|
(./src) directory for both .js and
|
||||||
|
.jsx extensions.
|
||||||
```
|
```
|
||||||
|
|
||||||
### Using `create-index` Programmatically
|
### Using `create-index` Programmatically
|
||||||
|
|||||||
+21
-3
@@ -23,6 +23,14 @@ const argv = yargs
|
|||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.options({
|
||||||
|
ignoreDirectories: {
|
||||||
|
alias: 'd',
|
||||||
|
default: false,
|
||||||
|
description: 'Ignores importing directories into the index file, even if they have a safe "index.js".',
|
||||||
|
type: 'boolean'
|
||||||
|
}
|
||||||
|
})
|
||||||
.options({
|
.options({
|
||||||
update: {
|
update: {
|
||||||
alias: 'u',
|
alias: 'u',
|
||||||
@@ -45,14 +53,24 @@ const argv = yargs
|
|||||||
type: 'array'
|
type: 'array'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.example('create-index ./src ./src/utilities', 'Creates or updates an existing create-index index file in the target (./src, ./src/utilities) directories.')
|
.example(
|
||||||
.example('create-index --update ./src ./tests', 'Finds all create-index index files in the target directories and descending directories. Updates found index files.')
|
'create-index ./src ./src/utilities',
|
||||||
.example('create-index ./src --extensions js jsx', 'Creates or updates an existing create-index index file in the target (./src) directory for both .js and .jsx extensions.')
|
'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 ./src --extensions js jsx',
|
||||||
|
'Creates or updates an existing create-index index file in the target (./src) directory for both .js and .jsx extensions.'
|
||||||
|
)
|
||||||
.argv;
|
.argv;
|
||||||
|
|
||||||
writeIndexCli(argv._, {
|
writeIndexCli(argv._, {
|
||||||
banner: argv.banner,
|
banner: argv.banner,
|
||||||
extensions: argv.extensions,
|
extensions: argv.extensions,
|
||||||
|
ignoreDirectories: argv.ignoreDirectories,
|
||||||
ignoreUnsafe: argv.ignoreUnsafe,
|
ignoreUnsafe: argv.ignoreUnsafe,
|
||||||
recursive: argv.recursive,
|
recursive: argv.recursive,
|
||||||
updateIndex: argv.update
|
updateIndex: argv.update
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
// @create-index
|
// @create-index
|
||||||
|
|
||||||
export createIndexCode from './createIndexCode.js';
|
export createIndexCode from './createIndexCode';
|
||||||
export findIndexFiles from './findIndexFiles.js';
|
export findIndexFiles from './findIndexFiles';
|
||||||
export log from './log.js';
|
export log from './log';
|
||||||
export readDirectory from './readDirectory.js';
|
export readDirectory from './readDirectory';
|
||||||
export sortByDepth from './sortByDepth.js';
|
export sortByDepth from './sortByDepth';
|
||||||
export validateTargetDirectory from './validateTargetDirectory.js';
|
export validateTargetDirectory from './validateTargetDirectory';
|
||||||
export writeIndex from './writeIndex.js';
|
export writeIndex from './writeIndex';
|
||||||
export writeIndexCli from './writeIndexCli.js';
|
export writeIndexCli from './writeIndexCli';
|
||||||
|
|||||||
@@ -78,7 +78,8 @@ export default (directoryPath, options = {}) => {
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
extensions = ['js'],
|
extensions = ['js'],
|
||||||
config = {}
|
config = {},
|
||||||
|
ignoreDirectories = false
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
let children;
|
let children;
|
||||||
@@ -111,7 +112,7 @@ export default (directoryPath, options = {}) => {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDirectory && !hasIndex(absolutePath)) {
|
if (isDirectory && (!hasIndex(absolutePath) || ignoreDirectories)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export default (directoryPaths, options = {}) => {
|
|||||||
const config = readIndexConfig(directoryPath);
|
const config = readIndexConfig(directoryPath);
|
||||||
const optionsWithConfig = Object.assign({}, options, {config});
|
const optionsWithConfig = Object.assign({}, options, {config});
|
||||||
const siblings = readDirectory(directoryPath, optionsWithConfig);
|
const siblings = readDirectory(directoryPath, optionsWithConfig);
|
||||||
const indexCode = createIndexCode(siblings, {config});
|
const indexCode = createIndexCode(siblings, optionsWithConfig);
|
||||||
const indexFilePath = path.resolve(directoryPath, 'index.js');
|
const indexFilePath = path.resolve(directoryPath, 'index.js');
|
||||||
|
|
||||||
fs.writeFileSync(indexFilePath, indexCode);
|
fs.writeFileSync(indexFilePath, indexCode);
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ export default (directoryPaths, options = {}) => {
|
|||||||
const siblings = readDirectory(directoryPath, {
|
const siblings = readDirectory(directoryPath, {
|
||||||
config,
|
config,
|
||||||
extensions: options.extensions,
|
extensions: options.extensions,
|
||||||
|
ignoreDirectories: options.ignoreDirectories,
|
||||||
silent: options.ignoreUnsafe
|
silent: options.ignoreUnsafe
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ describe('readDirectory()', () => {
|
|||||||
|
|
||||||
expect(names).to.deep.equal(['bar', 'foo']);
|
expect(names).to.deep.equal(['bar', 'foo']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('excludes directories if ignoreDirectories = true', () => {
|
||||||
|
const names = readDirectory(path.resolve(fixturesPath, 'children-index'), {ignoreDirectories: true});
|
||||||
|
|
||||||
|
expect(names).to.deep.equal([]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
context('target directory contains files', () => {
|
context('target directory contains files', () => {
|
||||||
it('refers to the files (with extension)', () => {
|
it('refers to the files (with extension)', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user