Code style preferences.
This commit is contained in:
@@ -5,9 +5,7 @@ import {
|
||||
writeIndexCli
|
||||
} from './../utilities';
|
||||
|
||||
let argv;
|
||||
|
||||
argv = yargs
|
||||
const argv = yargs
|
||||
.demand(1)
|
||||
.options({
|
||||
'update-index': {
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
let buildExportBlock,
|
||||
safeVariableName;
|
||||
|
||||
safeVariableName = (fileName) => {
|
||||
let indexOfDot;
|
||||
|
||||
indexOfDot = fileName.indexOf('.');
|
||||
const safeVariableName = (fileName) => {
|
||||
const indexOfDot = fileName.indexOf('.');
|
||||
|
||||
if (indexOfDot === -1) {
|
||||
return fileName;
|
||||
@@ -15,7 +10,7 @@ safeVariableName = (fileName) => {
|
||||
}
|
||||
};
|
||||
|
||||
buildExportBlock = (files) => {
|
||||
const buildExportBlock = (files) => {
|
||||
let importBlock;
|
||||
|
||||
importBlock = _.map(files, (fileName) => {
|
||||
@@ -28,13 +23,12 @@ buildExportBlock = (files) => {
|
||||
};
|
||||
|
||||
export default (filePaths) => {
|
||||
let code,
|
||||
sortedFilePaths;
|
||||
let code;
|
||||
|
||||
code = '\'create index\';\n\n';
|
||||
|
||||
if (filePaths.length) {
|
||||
sortedFilePaths = filePaths.sort();
|
||||
const sortedFilePaths = filePaths.sort();
|
||||
|
||||
code += buildExportBlock(sortedFilePaths) + '\n\n';
|
||||
}
|
||||
|
||||
@@ -3,16 +3,8 @@ import _ from 'lodash';
|
||||
import path from 'path';
|
||||
import validateTargetDirectory from './validateTargetDirectory';
|
||||
|
||||
let hasIndex,
|
||||
hasMultipleExtensions,
|
||||
hasNoExtension,
|
||||
isSafeName,
|
||||
removeDuplicates;
|
||||
|
||||
hasIndex = (directoryPath) => {
|
||||
let indexPath;
|
||||
|
||||
indexPath = path.resolve(directoryPath, 'index.js');
|
||||
const hasIndex = (directoryPath) => {
|
||||
const indexPath = path.resolve(directoryPath, 'index.js');
|
||||
|
||||
try {
|
||||
fs.statSync(indexPath);
|
||||
@@ -23,27 +15,23 @@ hasIndex = (directoryPath) => {
|
||||
}
|
||||
};
|
||||
|
||||
hasNoExtension = (fileName) => {
|
||||
let matches;
|
||||
|
||||
matches = fileName.match(/\./g);
|
||||
const hasNoExtension = (fileName) => {
|
||||
const matches = fileName.match(/\./g);
|
||||
|
||||
return !matches;
|
||||
};
|
||||
|
||||
hasMultipleExtensions = (fileName) => {
|
||||
let matches;
|
||||
|
||||
matches = fileName.match(/\./g);
|
||||
const hasMultipleExtensions = (fileName) => {
|
||||
const matches = fileName.match(/\./g);
|
||||
|
||||
return matches && matches.length > 1;
|
||||
};
|
||||
|
||||
isSafeName = (fileName) => {
|
||||
const isSafeName = (fileName) => {
|
||||
return /^[a-z][a-z0-9\._]+$/i.test(fileName);
|
||||
};
|
||||
|
||||
removeDuplicates = (files) => {
|
||||
const removeDuplicates = (files) => {
|
||||
return _.filter(files, (fileName) => {
|
||||
return !_.includes(files, fileName + '.js');
|
||||
});
|
||||
@@ -57,12 +45,8 @@ export default (directoryPath) => {
|
||||
children = fs.readdirSync(directoryPath);
|
||||
|
||||
children = _.filter(children, (fileName) => {
|
||||
let absolutePath,
|
||||
isDirectory;
|
||||
|
||||
absolutePath = path.resolve(directoryPath, fileName);
|
||||
|
||||
isDirectory = fs.statSync(absolutePath).isDirectory();
|
||||
const absolutePath = path.resolve(directoryPath, fileName);
|
||||
const isDirectory = fs.statSync(absolutePath).isDirectory();
|
||||
|
||||
if (!isSafeName(fileName)) {
|
||||
return false;
|
||||
|
||||
@@ -3,9 +3,7 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export default (targetDirectory) => {
|
||||
let indexFile,
|
||||
indexFilePath,
|
||||
stats;
|
||||
let stats;
|
||||
|
||||
try {
|
||||
stats = fs.statSync(targetDirectory);
|
||||
@@ -17,7 +15,7 @@ export default (targetDirectory) => {
|
||||
throw new Error('"' + targetDirectory + '" is not a directory.');
|
||||
}
|
||||
|
||||
indexFilePath = path.resolve(targetDirectory, './index.js');
|
||||
const indexFilePath = path.resolve(targetDirectory, './index.js');
|
||||
|
||||
try {
|
||||
fs.statSync(indexFilePath);
|
||||
@@ -25,7 +23,7 @@ export default (targetDirectory) => {
|
||||
return true;
|
||||
}
|
||||
|
||||
indexFile = fs.readFileSync(indexFilePath, 'utf8');
|
||||
const indexFile = fs.readFileSync(indexFilePath, 'utf8');
|
||||
|
||||
if (!_.startsWith(indexFile, '\'create index\';\n')) {
|
||||
throw new Error('"' + indexFilePath + '" unsafe index.');
|
||||
|
||||
@@ -7,24 +7,16 @@ import readDirectory from './readDirectory';
|
||||
import sortByDepth from './sortByDepth';
|
||||
|
||||
export default (directoryPaths) => {
|
||||
let sortedDirectoryPaths;
|
||||
|
||||
sortedDirectoryPaths = sortByDepth(directoryPaths);
|
||||
const sortedDirectoryPaths = sortByDepth(directoryPaths);
|
||||
|
||||
_.forEach(sortedDirectoryPaths, (directoryPath) => {
|
||||
validateTargetDirectory(directoryPath);
|
||||
});
|
||||
|
||||
_.forEach(sortedDirectoryPaths, (directoryPath) => {
|
||||
let indexCode,
|
||||
indexFilePath,
|
||||
siblings;
|
||||
|
||||
siblings = readDirectory(directoryPath);
|
||||
|
||||
indexCode = createIndexCode(siblings);
|
||||
|
||||
indexFilePath = path.resolve(directoryPath, 'index.js');
|
||||
const siblings = readDirectory(directoryPath);
|
||||
const indexCode = createIndexCode(siblings);
|
||||
const indexFilePath = path.resolve(directoryPath, 'index.js');
|
||||
|
||||
fs.writeFileSync(indexFilePath, indexCode);
|
||||
});
|
||||
|
||||
@@ -31,16 +31,13 @@ export default (directoryPaths, options = {}) => {
|
||||
});
|
||||
|
||||
_.forEach(sortedDirectoryPaths, (directoryPath) => {
|
||||
let existingIndexCode,
|
||||
indexCode,
|
||||
indexFilePath,
|
||||
siblings;
|
||||
let existingIndexCode;
|
||||
|
||||
siblings = readDirectory(directoryPath);
|
||||
const siblings = readDirectory(directoryPath);
|
||||
|
||||
indexCode = createIndexCode(siblings);
|
||||
const indexCode = createIndexCode(siblings);
|
||||
|
||||
indexFilePath = path.resolve(directoryPath, 'index.js');
|
||||
const indexFilePath = path.resolve(directoryPath, 'index.js');
|
||||
|
||||
try {
|
||||
existingIndexCode = fs.readFileSync(indexFilePath, 'utf8');
|
||||
|
||||
Reference in New Issue
Block a user