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 ... ```
This commit is contained in:
committed by
Gajus Kuizinas
parent
d7e2528999
commit
fdb17d0179
@@ -86,6 +86,7 @@ Options:
|
|||||||
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
|
||||||
|
|||||||
@@ -15,10 +15,17 @@ const argv = yargs
|
|||||||
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.update
|
updateIndex: argv.update,
|
||||||
|
banner: argv.banner
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user