fix: update dependencies
This commit is contained in:
+22
-20
@@ -1,8 +1,10 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/* eslint-disable filenames/match-regex */
|
||||
|
||||
import yargs from 'yargs';
|
||||
import {
|
||||
writeIndexCli
|
||||
writeIndexCli,
|
||||
} from '../utilities';
|
||||
|
||||
const argv = yargs
|
||||
@@ -12,66 +14,66 @@ const argv = yargs
|
||||
alias: 'r',
|
||||
default: false,
|
||||
description: 'Create/update index files recursively. Halts on any unsafe "index.js" files.',
|
||||
type: 'boolean'
|
||||
}
|
||||
type: 'boolean',
|
||||
},
|
||||
})
|
||||
.options({
|
||||
ignoreUnsafe: {
|
||||
alias: 'i',
|
||||
default: false,
|
||||
description: 'Ignores unsafe "index.js" files instead of halting.',
|
||||
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'
|
||||
}
|
||||
type: 'boolean',
|
||||
},
|
||||
})
|
||||
.options({
|
||||
update: {
|
||||
alias: 'u',
|
||||
default: false,
|
||||
description: 'Updates only previously created index files (recursively).',
|
||||
type: 'boolean'
|
||||
}
|
||||
type: 'boolean',
|
||||
},
|
||||
})
|
||||
.options({
|
||||
banner: {
|
||||
description: 'Add a custom banner at the top of the index file',
|
||||
type: 'string'
|
||||
}
|
||||
type: 'string',
|
||||
},
|
||||
})
|
||||
.options({
|
||||
extensions: {
|
||||
alias: 'x',
|
||||
default: ['js'],
|
||||
description: 'Allows some extensions to be parsed as valid source. First extension will always be preferred to homonyms with another allowed extension.',
|
||||
type: 'array'
|
||||
}
|
||||
type: 'array',
|
||||
},
|
||||
})
|
||||
.options({
|
||||
outputFile: {
|
||||
alias: 'o',
|
||||
default: 'index.js',
|
||||
description: 'Output file',
|
||||
type: 'string'
|
||||
}
|
||||
type: 'string',
|
||||
},
|
||||
})
|
||||
.example(
|
||||
'create-index ./src ./src/utilities',
|
||||
'Creates or updates an existing create-index index file in the target (./src, ./src/utilities) directories.'
|
||||
'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.'
|
||||
'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.'
|
||||
'Creates or updates an existing create-index index file in the target (./src) directory for both .js and .jsx extensions.',
|
||||
)
|
||||
.argv;
|
||||
|
||||
@@ -80,7 +82,7 @@ writeIndexCli(argv._, {
|
||||
extensions: argv.extensions,
|
||||
ignoreDirectories: argv.ignoreDirectories,
|
||||
ignoreUnsafe: argv.ignoreUnsafe,
|
||||
recursive: argv.recursive,
|
||||
outputFile: argv.outputFile,
|
||||
updateIndex: argv.update
|
||||
recursive: argv.recursive,
|
||||
updateIndex: argv.update,
|
||||
});
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
export {
|
||||
findIndexFiles,
|
||||
writeIndex
|
||||
writeIndex,
|
||||
} from './utilities';
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
// eslint-disable-next-line
|
||||
export const CREATE_INDEX_PATTERN = /(?:^|[\n\r]+)\/\/ @create-index\s?({.*})?[\n\r]+/;
|
||||
|
||||
@@ -4,7 +4,8 @@ import glob from 'glob';
|
||||
import validateTargetDirectory from './validateTargetDirectory';
|
||||
|
||||
export default (directoryPath, options = {}) => {
|
||||
let fileName, targetDirectories;
|
||||
let fileName;
|
||||
let targetDirectories;
|
||||
|
||||
fileName = options.fileName || 'index.js';
|
||||
fileName = './**/' + fileName;
|
||||
@@ -13,8 +14,8 @@ export default (directoryPath, options = {}) => {
|
||||
|
||||
targetDirectories = _.filter(targetDirectories, (targetDirectoryPath) => {
|
||||
return validateTargetDirectory(path.dirname(targetDirectoryPath), {
|
||||
outputFile: options.fileName,
|
||||
silent: options.silent,
|
||||
outputFile: options.fileName
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ export default (directoryPath, options = {}) => {
|
||||
fs.statSync(indexPath);
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,6 +2,6 @@ import chalk from 'chalk';
|
||||
import moment from 'moment';
|
||||
|
||||
export default (...append) => {
|
||||
// eslint-disable-next-line
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(chalk.dim('[' + moment().format('HH:mm:ss') + ']'), ...append);
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@ const hasMultipleExtensions = (fileName) => {
|
||||
};
|
||||
|
||||
const isSafeName = (fileName) => {
|
||||
return /^[a-z_][a-z0-9._]*$/i.test(fileName);
|
||||
return /^[_a-z][\w.]*$/i.test(fileName);
|
||||
};
|
||||
|
||||
const stripExtension = (fileName) => {
|
||||
@@ -27,7 +27,7 @@ const stripExtension = (fileName) => {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
return fileName.substr(0, pos);
|
||||
return fileName.slice(0, Math.max(0, pos));
|
||||
};
|
||||
|
||||
const removeDuplicates = (files, preferredExtension) => {
|
||||
@@ -79,7 +79,7 @@ export default (directoryPath, options = {}) => {
|
||||
const {
|
||||
extensions = ['js'],
|
||||
config = {},
|
||||
ignoreDirectories = false
|
||||
ignoreDirectories = false,
|
||||
} = options;
|
||||
|
||||
let children;
|
||||
@@ -106,8 +106,8 @@ export default (directoryPath, options = {}) => {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isDirectory && !extensions.some((ext) => {
|
||||
return _.endsWith(fileName, '.' + ext);
|
||||
if (!isDirectory && !extensions.some((extension) => {
|
||||
return _.endsWith(fileName, '.' + extension);
|
||||
})) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ export default (directoryPath, options = {}) => {
|
||||
|
||||
try {
|
||||
config = JSON.parse(configLine);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
throw new Error(
|
||||
'"' + indexPath + '" contains invalid configuration object.\n' +
|
||||
'Configuration object must be a valid JSON.'
|
||||
'Configuration object must be a valid JSON.',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ export default (targetDirectory, options = {}) => {
|
||||
|
||||
try {
|
||||
stats = fs.statSync(targetDirectory);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
if (silent) {
|
||||
return false;
|
||||
} else {
|
||||
@@ -28,7 +28,7 @@ export default (targetDirectory, options = {}) => {
|
||||
|
||||
try {
|
||||
fs.statSync(indexFilePath);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@ import sortByDepth from './sortByDepth';
|
||||
export default (directoryPaths, options = {}) => {
|
||||
const sortedDirectoryPaths = sortByDepth(directoryPaths)
|
||||
.filter((directoryPath) => {
|
||||
return validateTargetDirectory(directoryPath, {silent: options.ignoreUnsafe, outputFile: options.outputFile});
|
||||
return validateTargetDirectory(directoryPath, {outputFile: options.outputFile,
|
||||
silent: options.ignoreUnsafe});
|
||||
});
|
||||
|
||||
_.forEach(sortedDirectoryPaths, (directoryPath) => {
|
||||
|
||||
@@ -26,10 +26,10 @@ export default (directoryPaths, options = {}) => {
|
||||
}
|
||||
|
||||
if (options.updateIndex || options.recursive) {
|
||||
sortedDirectoryPaths = _.map(sortedDirectoryPaths, (dir) => {
|
||||
return findIndexFiles(dir, {
|
||||
sortedDirectoryPaths = _.map(sortedDirectoryPaths, (directory) => {
|
||||
return findIndexFiles(directory, {
|
||||
fileName: options.updateIndex ? options.outputFile || 'index.js' : '*',
|
||||
silent: options.updateIndex || options.ignoreUnsafe
|
||||
silent: options.updateIndex || options.ignoreUnsafe,
|
||||
});
|
||||
});
|
||||
sortedDirectoryPaths = _.flatten(sortedDirectoryPaths);
|
||||
@@ -40,7 +40,8 @@ export default (directoryPaths, options = {}) => {
|
||||
}
|
||||
|
||||
sortedDirectoryPaths = sortedDirectoryPaths.filter((directoryPath) => {
|
||||
return validateTargetDirectory(directoryPath, {silent: options.ignoreUnsafe, outputFile: options.outputFile});
|
||||
return validateTargetDirectory(directoryPath, {outputFile: options.outputFile,
|
||||
silent: options.ignoreUnsafe});
|
||||
});
|
||||
|
||||
_.forEach(sortedDirectoryPaths, (directoryPath) => {
|
||||
@@ -52,12 +53,12 @@ export default (directoryPaths, options = {}) => {
|
||||
config,
|
||||
extensions: options.extensions,
|
||||
ignoreDirectories: options.ignoreDirectories,
|
||||
silent: options.ignoreUnsafe
|
||||
silent: options.ignoreUnsafe,
|
||||
});
|
||||
|
||||
const indexCode = createIndexCode(siblings, {
|
||||
banner: options.banner,
|
||||
config
|
||||
config,
|
||||
});
|
||||
|
||||
const indexFilePath = path.resolve(directoryPath, options.outputFile || 'index.js');
|
||||
@@ -65,12 +66,12 @@ export default (directoryPaths, options = {}) => {
|
||||
try {
|
||||
existingIndexCode = fs.readFileSync(indexFilePath, 'utf8');
|
||||
|
||||
/* eslint-disable no-empty */
|
||||
} catch (error) {
|
||||
/* eslint-disable no-empty */
|
||||
} catch {
|
||||
|
||||
}
|
||||
|
||||
/* eslint-enable no-empty */
|
||||
/* eslint-enable no-empty */
|
||||
|
||||
fs.writeFileSync(indexFilePath, indexCode);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user