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