update and fixes
This commit is contained in:
committed by
Gajus Kuizinas
parent
bc314be2a1
commit
5b496536c6
@@ -13,7 +13,8 @@ export default (directoryPath, options = {}) => {
|
||||
|
||||
targetDirectories = _.filter(targetDirectories, (targetDirectoryPath) => {
|
||||
return validateTargetDirectory(path.dirname(targetDirectoryPath), {
|
||||
silent: options.silent
|
||||
silent: options.silent,
|
||||
outputFile: options.fileName
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export default (directoryPath) => {
|
||||
const indexPath = path.resolve(directoryPath, 'index.js');
|
||||
export default (directoryPath, options = {}) => {
|
||||
const indexPath = path.resolve(directoryPath, options.outputFile || 'index.js');
|
||||
|
||||
try {
|
||||
fs.statSync(indexPath);
|
||||
|
||||
@@ -72,7 +72,7 @@ const removeIgnoredFiles = (files, ignorePatterns = []) => {
|
||||
};
|
||||
|
||||
export default (directoryPath, options = {}) => {
|
||||
if (!validateTargetDirectory(directoryPath, {silent: options.silent})) {
|
||||
if (!validateTargetDirectory(directoryPath, options)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ export default (directoryPath, options = {}) => {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_.startsWith(fileName, 'index.js')) {
|
||||
if (_.startsWith(fileName, options.outputFile || 'index.js')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ export default (directoryPath, options = {}) => {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isDirectory && (!hasIndex(absolutePath) || ignoreDirectories)) {
|
||||
if (isDirectory && (!hasIndex(absolutePath, options) || ignoreDirectories)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,12 @@ import path from 'path';
|
||||
import hasIndex from './hasIndex';
|
||||
import {CREATE_INDEX_PATTERN} from './constants';
|
||||
|
||||
export default (directoryPath) => {
|
||||
if (!hasIndex(directoryPath)) {
|
||||
export default (directoryPath, options = {}) => {
|
||||
if (!hasIndex(directoryPath, options)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const indexPath = path.resolve(directoryPath, 'index.js');
|
||||
const indexPath = path.resolve(directoryPath, options.outputFile || 'index.js');
|
||||
const indexContents = fs.readFileSync(indexPath, 'utf-8');
|
||||
const found = indexContents.match(CREATE_INDEX_PATTERN);
|
||||
const configLine = typeof found[1] === 'string' ? found[1].trim() : '';
|
||||
|
||||
@@ -24,7 +24,7 @@ export default (targetDirectory, options = {}) => {
|
||||
}
|
||||
}
|
||||
|
||||
const indexFilePath = path.resolve(targetDirectory, './index.js');
|
||||
const indexFilePath = path.resolve(targetDirectory, './' + (options.outputFile || 'index.js'));
|
||||
|
||||
try {
|
||||
fs.statSync(indexFilePath);
|
||||
|
||||
@@ -10,15 +10,15 @@ import sortByDepth from './sortByDepth';
|
||||
export default (directoryPaths, options = {}) => {
|
||||
const sortedDirectoryPaths = sortByDepth(directoryPaths)
|
||||
.filter((directoryPath) => {
|
||||
return validateTargetDirectory(directoryPath, {silent: options.ignoreUnsafe});
|
||||
return validateTargetDirectory(directoryPath, {silent: options.ignoreUnsafe, outputFile: options.outputFile});
|
||||
});
|
||||
|
||||
_.forEach(sortedDirectoryPaths, (directoryPath) => {
|
||||
const config = readIndexConfig(directoryPath);
|
||||
const config = readIndexConfig(directoryPath, options);
|
||||
const optionsWithConfig = Object.assign({}, options, {config});
|
||||
const siblings = readDirectory(directoryPath, optionsWithConfig);
|
||||
const indexCode = createIndexCode(siblings, optionsWithConfig);
|
||||
const indexFilePath = path.resolve(directoryPath, optionsWithConfig.outputFile || 'index.js');
|
||||
const indexFilePath = path.resolve(directoryPath, options.outputFile || 'index.js');
|
||||
|
||||
fs.writeFileSync(indexFilePath, indexCode);
|
||||
});
|
||||
|
||||
@@ -40,13 +40,13 @@ export default (directoryPaths, options = {}) => {
|
||||
}
|
||||
|
||||
sortedDirectoryPaths = sortedDirectoryPaths.filter((directoryPath) => {
|
||||
return validateTargetDirectory(directoryPath, {silent: options.ignoreUnsafe});
|
||||
return validateTargetDirectory(directoryPath, {silent: options.ignoreUnsafe, outputFile: options.outputFile});
|
||||
});
|
||||
|
||||
_.forEach(sortedDirectoryPaths, (directoryPath) => {
|
||||
let existingIndexCode;
|
||||
|
||||
const config = readIndexConfig(directoryPath);
|
||||
const config = readIndexConfig(directoryPath, options);
|
||||
|
||||
const siblings = readDirectory(directoryPath, {
|
||||
config,
|
||||
@@ -60,7 +60,7 @@ export default (directoryPaths, options = {}) => {
|
||||
config
|
||||
});
|
||||
|
||||
const indexFilePath = path.resolve(directoryPath, 'index.js');
|
||||
const indexFilePath = path.resolve(directoryPath, options.outputFile || 'index.js');
|
||||
|
||||
try {
|
||||
existingIndexCode = fs.readFileSync(indexFilePath, 'utf8');
|
||||
|
||||
Reference in New Issue
Block a user