15 Commits
Author SHA1 Message Date
Gorji 061c645544 dit 2021-06-03 08:36:23 +04:30
Gorji 80189f9972 fix import inde files 2021-06-03 08:31:40 +04:30
Gajus Kuizinas 76c6d4b5ee fix: update dependencies 2020-05-18 10:11:25 -07:00
Gajus Kuizinas 017b834393 Merge branch 'danielpza-master' 2020-05-18 10:02:12 -07:00
Gajus Kuizinas 669e36fe67 chore: remove unused script 2020-05-18 10:02:11 -07:00
Daniel Perez AlvarezandGajus Kuizinas 1a50178f71 docs: recover -x footer 2020-05-18 10:01:37 -07:00
Daniel Perez AlvarezandGajus Kuizinas c9d4fa2471 fix trailing comma 2020-05-18 10:01:37 -07:00
Daniel Perez AlvarezandGajus Kuizinas 5b496536c6 update and fixes 2020-05-18 10:01:37 -07:00
Daniel Perez AlvarezandGajus Kuizinas bc314be2a1 update 2020-05-18 10:01:37 -07:00
Daniel Perez AlvarezandGajus Kuizinas 0dbb06ecc6 chore: add prepare script 2020-05-18 10:01:37 -07:00
Daniel Perez AlvarezandGajus Kuizinas 64af79d428 docs: update yargs and readme 2020-05-18 10:01:37 -07:00
Andrei MiulescuandGajus Kuizinas 38c4094655 feat: add outputFile for typescript etc 2020-05-18 10:01:37 -07:00
beralivandGajus Kuizinas 1f87f9a8b3 feat: cannot use create-index for short folders (#51)
* feat: file cannot be started from _ and be one symbol
* test: add children-directories-short-name for readDirectory
2019-10-27 13:37:12 +00:00
Joe WhittlesandGajus Kuizinas 6aac149a8b feat: add option to exclude directories from index.js (#50)
* Add option to exclude directories from index.js
* Update readDirectory.js
* Update writeIndexCli.js
* Update readDirectory.js
* Update README
2019-01-25 17:49:18 +00:00
Gajus KuizinasandGitHub 1efd1c6c7b chore: update .editorconfig 2018-11-12 23:43:25 +00:00
62 changed files with 1703 additions and 127 deletions
+5 -4
View File
@@ -1,8 +1,9 @@
{ {
"plugins": [ "plugins": [
"transform-es2015-modules-commonjs", "@babel/plugin-transform-modules-commonjs",
"transform-export-extensions", "@babel/plugin-proposal-export-default-from",
"transform-es2015-destructuring", "@babel/plugin-proposal-export-namespace-from",
"transform-es2015-parameters" "@babel/plugin-transform-destructuring",
"@babel/plugin-transform-parameters"
] ]
} }
+4 -2
View File
@@ -1,7 +1,9 @@
root = true root = true
[*] [*]
charset = utf-8
end_of_line = lf end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2 indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
+1 -1
View File
@@ -1 +1 @@
./test/fixtures test/fixtures
-1
View File
@@ -1,5 +1,4 @@
coverage coverage
dist
node_modules node_modules
*.log *.log
.* .*
+5 -1
View File
@@ -4,8 +4,12 @@ node_js:
- 7 - 7
- 6 - 6
- 5 - 5
script:
- npm run lint
- npm run test
- npm run build
after_success: after_success:
- semantic-release pre && npm publish && semantic-release post - semantic-release
notifications: notifications:
email: false email: false
sudo: false sudo: false
+1 -1
View File
@@ -1,4 +1,4 @@
Copyright (c) 2016, Gajus Kuizinas (http://gajus.com/) Copyright (c) 2020, Gajus Kuizinas (http://gajus.com/)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
+21 -7
View File
@@ -82,21 +82,35 @@ npm install create-index
create-index --help create-index --help
Options: Options:
--recursive, -r Create/update index files recursively. Halts on any unsafe --recursive, -r Create/update index files recursively. Halts on any
"index.js" files. [boolean] [default: false] unsafe "index.js" files. [boolean] [default: false]
--ignoreUnsafe, -i Ignores unsafe "index.js" files instead of halting. --ignoreUnsafe, -i Ignores unsafe "index.js" files instead of halting.
[boolean] [default: false] [boolean] [default: false]
--update, -u Updates only previously created index files (recursively). --ignoreDirectories, -d Ignores importing directories into the index file,
even if they have a safe "index.js".
[boolean] [default: false] [boolean] [default: false]
--banner Add a custom banner at the top of the index file [string] --update, -u Updates only previously created index files
(recursively). [boolean] [default: false]
--banner Add a custom banner at the top of the index file
[string]
--extensions, -x Allows some extensions to be parsed as valid source.
First extension will always be preferred to homonyms
with another allowed extension.
[array] [default: ["js"]]
--outputFile, -o Output file [string] [default: "index.js"] [array] [default: ["js"]]
Examples: Examples:
create-index ./src ./src/utilities Creates or updates an existing create-index ./src ./src/utilities Creates or updates an existing
create-index index file in the target create-index index file in the target
(./src, ./src/utilities) directories. (./src, ./src/utilities) directories.
create-index --update ./src ./tests Finds all create-index index files in the create-index --update ./src ./tests Finds all create-index index files in
target directories and descending the target directories and descending
directories. Updates found index files. directories. Updates found index
files.
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.
``` ```
### Using `create-index` Programmatically ### Using `create-index` Programmatically
+70
View File
@@ -0,0 +1,70 @@
#!/usr/bin/env node
/* eslint-disable filenames/match-regex */
"use strict";
var _yargs = _interopRequireDefault(require("yargs"));
var _utilities = require("../utilities");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const argv = _yargs.default.demand(1).options({
recursive: {
alias: 'r',
default: false,
description: 'Create/update index files recursively. Halts on any unsafe "index.js" files.',
type: 'boolean'
}
}).options({
ignoreUnsafe: {
alias: 'i',
default: false,
description: 'Ignores unsafe "index.js" files instead of halting.',
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'
}
}).options({
update: {
alias: 'u',
default: false,
description: 'Updates only previously created index files (recursively).',
type: 'boolean'
}
}).options({
banner: {
description: 'Add a custom banner at the top of the index file',
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'
}
}).options({
outputFile: {
alias: 'o',
default: 'index.js',
description: 'Output 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 --update ./src ./tests', '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.').argv;
(0, _utilities.writeIndexCli)(argv._, {
banner: argv.banner,
extensions: argv.extensions,
ignoreDirectories: argv.ignoreDirectories,
ignoreUnsafe: argv.ignoreUnsafe,
outputFile: argv.outputFile,
recursive: argv.recursive,
updateIndex: argv.update
});
//# sourceMappingURL=create-index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../src/bin/create-index.js"],"names":["argv","yargs","demand","options","recursive","alias","default","description","type","ignoreUnsafe","ignoreDirectories","update","banner","extensions","outputFile","example","_","updateIndex"],"mappings":"AAAA;;AAEA;;;AAEA;;AACA;;;;AAIA,MAAMA,IAAI,GAAGC,eACVC,MADU,CACH,CADG,EAEVC,OAFU,CAEF;AACPC,EAAAA,SAAS,EAAE;AACTC,IAAAA,KAAK,EAAE,GADE;AAETC,IAAAA,OAAO,EAAE,KAFA;AAGTC,IAAAA,WAAW,EAAE,8EAHJ;AAITC,IAAAA,IAAI,EAAE;AAJG;AADJ,CAFE,EAUVL,OAVU,CAUF;AACPM,EAAAA,YAAY,EAAE;AACZJ,IAAAA,KAAK,EAAE,GADK;AAEZC,IAAAA,OAAO,EAAE,KAFG;AAGZC,IAAAA,WAAW,EAAE,qDAHD;AAIZC,IAAAA,IAAI,EAAE;AAJM;AADP,CAVE,EAkBVL,OAlBU,CAkBF;AACPO,EAAAA,iBAAiB,EAAE;AACjBL,IAAAA,KAAK,EAAE,GADU;AAEjBC,IAAAA,OAAO,EAAE,KAFQ;AAGjBC,IAAAA,WAAW,EAAE,yFAHI;AAIjBC,IAAAA,IAAI,EAAE;AAJW;AADZ,CAlBE,EA0BVL,OA1BU,CA0BF;AACPQ,EAAAA,MAAM,EAAE;AACNN,IAAAA,KAAK,EAAE,GADD;AAENC,IAAAA,OAAO,EAAE,KAFH;AAGNC,IAAAA,WAAW,EAAE,4DAHP;AAINC,IAAAA,IAAI,EAAE;AAJA;AADD,CA1BE,EAkCVL,OAlCU,CAkCF;AACPS,EAAAA,MAAM,EAAE;AACNL,IAAAA,WAAW,EAAE,kDADP;AAENC,IAAAA,IAAI,EAAE;AAFA;AADD,CAlCE,EAwCVL,OAxCU,CAwCF;AACPU,EAAAA,UAAU,EAAE;AACVR,IAAAA,KAAK,EAAE,GADG;AAEVC,IAAAA,OAAO,EAAE,CAAC,IAAD,CAFC;AAGVC,IAAAA,WAAW,EAAE,2IAHH;AAIVC,IAAAA,IAAI,EAAE;AAJI;AADL,CAxCE,EAgDVL,OAhDU,CAgDF;AACPW,EAAAA,UAAU,EAAE;AACVT,IAAAA,KAAK,EAAE,GADG;AAEVC,IAAAA,OAAO,EAAE,UAFC;AAGVC,IAAAA,WAAW,EAAE,aAHH;AAIVC,IAAAA,IAAI,EAAE;AAJI;AADL,CAhDE,EAwDVO,OAxDU,CAyDT,oCAzDS,EA0DT,4GA1DS,EA4DVA,OA5DU,CA6DT,qCA7DS,EA8DT,qHA9DS,EAgEVA,OAhEU,CAiET,wCAjES,EAkET,0HAlES,EAoEVf,IApEH;;AAsEA,8BAAcA,IAAI,CAACgB,CAAnB,EAAsB;AACpBJ,EAAAA,MAAM,EAAEZ,IAAI,CAACY,MADO;AAEpBC,EAAAA,UAAU,EAAEb,IAAI,CAACa,UAFG;AAGpBH,EAAAA,iBAAiB,EAAEV,IAAI,CAACU,iBAHJ;AAIpBD,EAAAA,YAAY,EAAET,IAAI,CAACS,YAJC;AAKpBK,EAAAA,UAAU,EAAEd,IAAI,CAACc,UALG;AAMpBV,EAAAA,SAAS,EAAEJ,IAAI,CAACI,SANI;AAOpBa,EAAAA,WAAW,EAAEjB,IAAI,CAACW;AAPE,CAAtB","sourcesContent":["#!/usr/bin/env node\n\n/* eslint-disable filenames/match-regex */\n\nimport yargs from 'yargs';\nimport {\n writeIndexCli,\n} from '../utilities';\n\nconst argv = yargs\n .demand(1)\n .options({\n recursive: {\n alias: 'r',\n default: false,\n description: 'Create/update index files recursively. Halts on any unsafe \"index.js\" files.',\n type: 'boolean',\n },\n })\n .options({\n ignoreUnsafe: {\n alias: 'i',\n default: false,\n description: 'Ignores unsafe \"index.js\" files instead of halting.',\n type: 'boolean',\n },\n })\n .options({\n ignoreDirectories: {\n alias: 'd',\n default: false,\n description: 'Ignores importing directories into the index file, even if they have a safe \"index.js\".',\n type: 'boolean',\n },\n })\n .options({\n update: {\n alias: 'u',\n default: false,\n description: 'Updates only previously created index files (recursively).',\n type: 'boolean',\n },\n })\n .options({\n banner: {\n description: 'Add a custom banner at the top of the index file',\n type: 'string',\n },\n })\n .options({\n extensions: {\n alias: 'x',\n default: ['js'],\n description: 'Allows some extensions to be parsed as valid source. First extension will always be preferred to homonyms with another allowed extension.',\n type: 'array',\n },\n })\n .options({\n outputFile: {\n alias: 'o',\n default: 'index.js',\n description: 'Output file',\n type: 'string',\n },\n })\n .example(\n 'create-index ./src ./src/utilities',\n 'Creates or updates an existing create-index index file in the target (./src, ./src/utilities) directories.',\n )\n .example(\n 'create-index --update ./src ./tests',\n 'Finds all create-index index files in the target directories and descending directories. Updates found index files.',\n )\n .example(\n 'create-index ./src --extensions js jsx',\n 'Creates or updates an existing create-index index file in the target (./src) directory for both .js and .jsx extensions.',\n )\n .argv;\n\nwriteIndexCli(argv._, {\n banner: argv.banner,\n extensions: argv.extensions,\n ignoreDirectories: argv.ignoreDirectories,\n ignoreUnsafe: argv.ignoreUnsafe,\n outputFile: argv.outputFile,\n recursive: argv.recursive,\n updateIndex: argv.update,\n});\n"],"file":"create-index.js"}
+20
View File
@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "findIndexFiles", {
enumerable: true,
get: function () {
return _utilities.findIndexFiles;
}
});
Object.defineProperty(exports, "writeIndex", {
enumerable: true,
get: function () {
return _utilities.writeIndex;
}
});
var _utilities = require("./utilities");
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA","sourcesContent":["export {\n findIndexFiles,\n writeIndex,\n} from './utilities';\n"],"file":"index.js"}
+9
View File
@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.CREATE_INDEX_PATTERN = void 0;
const CREATE_INDEX_PATTERN = /(?:^|[\n\r]+)\/\/ @create-index\s?({.*})?[\n\r]+/;
exports.CREATE_INDEX_PATTERN = CREATE_INDEX_PATTERN;
//# sourceMappingURL=constants.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../src/utilities/constants.js"],"names":["CREATE_INDEX_PATTERN"],"mappings":";;;;;;AAAO,MAAMA,oBAAoB,GAAG,kDAA7B","sourcesContent":["export const CREATE_INDEX_PATTERN = /(?:^|[\\n\\r]+)\\/\\/ @create-index\\s?({.*})?[\\n\\r]+/;\n"],"file":"constants.js"}
+62
View File
@@ -0,0 +1,62 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _lodash = _interopRequireDefault(require("lodash"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const safeVariableName = fileName => {
const indexOfDot = fileName.indexOf('.');
if (indexOfDot === -1) {
return fileName;
} else {
return fileName.slice(0, indexOfDot);
}
};
const buildExportBlock = files => {
let importBlock;
importBlock = _lodash.default.map(files, fileName => {
if (fileName.indexOf(".") == -1) return "export * as " + safeVariableName(fileName) + " from './" + fileName + "';";
return "export { default as " + safeVariableName(fileName) + " } from './" + fileName + "';";
});
importBlock = importBlock.join('\n');
return importBlock;
};
var _default = function _default(filePaths) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
let code;
let configCode;
code = '';
configCode = '';
if (options.banner) {
const banners = _lodash.default.isArray(options.banner) ? options.banner : [options.banner];
banners.forEach(banner => {
code += banner + '\n';
});
code += '\n';
}
if (options.config && _lodash.default.size(options.config) > 0) {
configCode += ' ' + JSON.stringify(options.config);
}
code += '// @create-index' + configCode + '\n\n';
if (filePaths.length) {
const sortedFilePaths = filePaths.sort();
code += buildExportBlock(sortedFilePaths) + '\n\n';
}
return code;
};
exports.default = _default;
//# sourceMappingURL=createIndexCode.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../src/utilities/createIndexCode.js"],"names":["safeVariableName","fileName","indexOfDot","indexOf","slice","buildExportBlock","files","importBlock","_","map","join","filePaths","options","code","configCode","banner","banners","isArray","forEach","config","size","JSON","stringify","length","sortedFilePaths","sort"],"mappings":";;;;;;;AAAA;;;;AAEA,MAAMA,gBAAgB,GAAIC,QAAD,IAAc;AACrC,QAAMC,UAAU,GAAGD,QAAQ,CAACE,OAAT,CAAiB,GAAjB,CAAnB;;AAEA,MAAID,UAAU,KAAK,CAAC,CAApB,EAAuB;AACrB,WAAOD,QAAP;AACD,GAFD,MAEO;AACL,WAAOA,QAAQ,CAACG,KAAT,CAAe,CAAf,EAAkBF,UAAlB,CAAP;AACD;AACF,CARD;;AAUA,MAAMG,gBAAgB,GAAIC,KAAD,IAAW;AAClC,MAAIC,WAAJ;AAEAA,EAAAA,WAAW,GAAGC,gBAAEC,GAAF,CAAMH,KAAN,EAAcL,QAAD,IAAc;AACvC,QAAIA,QAAQ,CAACE,OAAT,CAAiB,GAAjB,KAAyB,CAAC,CAA9B,EACE,OACE,iBACAH,gBAAgB,CAACC,QAAD,CADhB,GAEA,YAFA,GAGAA,QAHA,GAIA,IALF;AAOF,WACE,yBACAD,gBAAgB,CAACC,QAAD,CADhB,GAEA,aAFA,GAGAA,QAHA,GAIA,IALF;AAOD,GAhBa,CAAd;AAkBAM,EAAAA,WAAW,GAAGA,WAAW,CAACG,IAAZ,CAAiB,IAAjB,CAAd;AAEA,SAAOH,WAAP;AACD,CAxBD;;eA0Be,kBAACI,SAAD,EAA6B;AAAA,MAAjBC,OAAiB,uEAAP,EAAO;AAC1C,MAAIC,IAAJ;AACA,MAAIC,UAAJ;AAEAD,EAAAA,IAAI,GAAG,EAAP;AACAC,EAAAA,UAAU,GAAG,EAAb;;AAEA,MAAIF,OAAO,CAACG,MAAZ,EAAoB;AAClB,UAAMC,OAAO,GAAGR,gBAAES,OAAF,CAAUL,OAAO,CAACG,MAAlB,IAA4BH,OAAO,CAACG,MAApC,GAA6C,CAACH,OAAO,CAACG,MAAT,CAA7D;AAEAC,IAAAA,OAAO,CAACE,OAAR,CAAiBH,MAAD,IAAY;AAC1BF,MAAAA,IAAI,IAAIE,MAAM,GAAG,IAAjB;AACD,KAFD;AAIAF,IAAAA,IAAI,IAAI,IAAR;AACD;;AAED,MAAID,OAAO,CAACO,MAAR,IAAkBX,gBAAEY,IAAF,CAAOR,OAAO,CAACO,MAAf,IAAyB,CAA/C,EAAkD;AAChDL,IAAAA,UAAU,IAAI,MAAMO,IAAI,CAACC,SAAL,CAAeV,OAAO,CAACO,MAAvB,CAApB;AACD;;AAEDN,EAAAA,IAAI,IAAI,qBAAqBC,UAArB,GAAkC,MAA1C;;AAEA,MAAIH,SAAS,CAACY,MAAd,EAAsB;AACpB,UAAMC,eAAe,GAAGb,SAAS,CAACc,IAAV,EAAxB;AAEAZ,IAAAA,IAAI,IAAIR,gBAAgB,CAACmB,eAAD,CAAhB,GAAoC,MAA5C;AACD;;AAED,SAAOX,IAAP;AACD,C","sourcesContent":["import _ from 'lodash';\n\nconst safeVariableName = (fileName) => {\n const indexOfDot = fileName.indexOf('.');\n\n if (indexOfDot === -1) {\n return fileName;\n } else {\n return fileName.slice(0, indexOfDot);\n }\n};\n\nconst buildExportBlock = (files) => {\n let importBlock;\n\n importBlock = _.map(files, (fileName) => {\n if (fileName.indexOf(\".\") == -1)\n return (\n \"export * as \" +\n safeVariableName(fileName) +\n \" from './\" +\n fileName +\n \"';\"\n );\n return (\n \"export { default as \" +\n safeVariableName(fileName) +\n \" } from './\" +\n fileName +\n \"';\"\n );\n });\n\n importBlock = importBlock.join('\\n');\n\n return importBlock;\n};\n\nexport default (filePaths, options = {}) => {\n let code;\n let configCode;\n\n code = '';\n configCode = '';\n\n if (options.banner) {\n const banners = _.isArray(options.banner) ? options.banner : [options.banner];\n\n banners.forEach((banner) => {\n code += banner + '\\n';\n });\n\n code += '\\n';\n }\n\n if (options.config && _.size(options.config) > 0) {\n configCode += ' ' + JSON.stringify(options.config);\n }\n\n code += '// @create-index' + configCode + '\\n\\n';\n\n if (filePaths.length) {\n const sortedFilePaths = filePaths.sort();\n\n code += buildExportBlock(sortedFilePaths) + '\\n\\n';\n }\n\n return code;\n};\n"],"file":"createIndexCode.js"}
+36
View File
@@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _path = _interopRequireDefault(require("path"));
var _lodash = _interopRequireDefault(require("lodash"));
var _glob = _interopRequireDefault(require("glob"));
var _validateTargetDirectory = _interopRequireDefault(require("./validateTargetDirectory"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = function _default(directoryPath) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
let fileName;
let targetDirectories;
fileName = options.fileName || 'index.js';
fileName = './**/' + fileName;
targetDirectories = _glob.default.sync(_path.default.join(directoryPath, fileName));
targetDirectories = _lodash.default.filter(targetDirectories, targetDirectoryPath => {
return (0, _validateTargetDirectory.default)(_path.default.dirname(targetDirectoryPath), {
outputFile: options.fileName,
silent: options.silent
});
});
targetDirectories = _lodash.default.map(targetDirectories, _path.default.dirname);
return targetDirectories;
};
exports.default = _default;
//# sourceMappingURL=findIndexFiles.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../src/utilities/findIndexFiles.js"],"names":["directoryPath","options","fileName","targetDirectories","glob","sync","path","join","_","filter","targetDirectoryPath","dirname","outputFile","silent","map"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;;;eAEe,kBAACA,aAAD,EAAiC;AAAA,MAAjBC,OAAiB,uEAAP,EAAO;AAC9C,MAAIC,QAAJ;AACA,MAAIC,iBAAJ;AAEAD,EAAAA,QAAQ,GAAGD,OAAO,CAACC,QAAR,IAAoB,UAA/B;AACAA,EAAAA,QAAQ,GAAG,UAAUA,QAArB;AAEAC,EAAAA,iBAAiB,GAAGC,cAAKC,IAAL,CAAUC,cAAKC,IAAL,CAAUP,aAAV,EAAyBE,QAAzB,CAAV,CAApB;AAEAC,EAAAA,iBAAiB,GAAGK,gBAAEC,MAAF,CAASN,iBAAT,EAA6BO,mBAAD,IAAyB;AACvE,WAAO,sCAAwBJ,cAAKK,OAAL,CAAaD,mBAAb,CAAxB,EAA2D;AAChEE,MAAAA,UAAU,EAAEX,OAAO,CAACC,QAD4C;AAEhEW,MAAAA,MAAM,EAAEZ,OAAO,CAACY;AAFgD,KAA3D,CAAP;AAID,GALmB,CAApB;AAOAV,EAAAA,iBAAiB,GAAGK,gBAAEM,GAAF,CAAMX,iBAAN,EAAyBG,cAAKK,OAA9B,CAApB;AAEA,SAAOR,iBAAP;AACD,C","sourcesContent":["import path from 'path';\nimport _ from 'lodash';\nimport glob from 'glob';\nimport validateTargetDirectory from './validateTargetDirectory';\n\nexport default (directoryPath, options = {}) => {\n let fileName;\n let targetDirectories;\n\n fileName = options.fileName || 'index.js';\n fileName = './**/' + fileName;\n\n targetDirectories = glob.sync(path.join(directoryPath, fileName));\n\n targetDirectories = _.filter(targetDirectories, (targetDirectoryPath) => {\n return validateTargetDirectory(path.dirname(targetDirectoryPath), {\n outputFile: options.fileName,\n silent: options.silent,\n });\n });\n\n targetDirectories = _.map(targetDirectories, path.dirname);\n\n return targetDirectories;\n};\n"],"file":"findIndexFiles.js"}
+29
View File
@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _fs = _interopRequireDefault(require("fs"));
var _path = _interopRequireDefault(require("path"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = function _default(directoryPath) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
const indexPath = _path.default.resolve(directoryPath, options.outputFile || 'index.js');
try {
_fs.default.statSync(indexPath);
return true;
} catch {
return false;
}
};
exports.default = _default;
//# sourceMappingURL=hasIndex.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../src/utilities/hasIndex.js"],"names":["directoryPath","options","indexPath","path","resolve","outputFile","fs","statSync"],"mappings":";;;;;;;AAAA;;AACA;;;;eAEe,kBAACA,aAAD,EAAiC;AAAA,MAAjBC,OAAiB,uEAAP,EAAO;;AAC9C,QAAMC,SAAS,GAAGC,cAAKC,OAAL,CAAaJ,aAAb,EAA4BC,OAAO,CAACI,UAAR,IAAsB,UAAlD,CAAlB;;AAEA,MAAI;AACFC,gBAAGC,QAAH,CAAYL,SAAZ;;AAEA,WAAO,IAAP;AACD,GAJD,CAIE,MAAM;AACN,WAAO,KAAP;AACD;AACF,C","sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\nexport default (directoryPath, options = {}) => {\n const indexPath = path.resolve(directoryPath, options.outputFile || 'index.js');\n\n try {\n fs.statSync(indexPath);\n\n return true;\n } catch {\n return false;\n }\n};\n"],"file":"hasIndex.js"}
+72
View File
@@ -0,0 +1,72 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "createIndexCode", {
enumerable: true,
get: function () {
return _createIndexCode2.default;
}
});
Object.defineProperty(exports, "findIndexFiles", {
enumerable: true,
get: function () {
return _findIndexFiles2.default;
}
});
Object.defineProperty(exports, "log", {
enumerable: true,
get: function () {
return _log2.default;
}
});
Object.defineProperty(exports, "readDirectory", {
enumerable: true,
get: function () {
return _readDirectory2.default;
}
});
Object.defineProperty(exports, "sortByDepth", {
enumerable: true,
get: function () {
return _sortByDepth2.default;
}
});
Object.defineProperty(exports, "validateTargetDirectory", {
enumerable: true,
get: function () {
return _validateTargetDirectory2.default;
}
});
Object.defineProperty(exports, "writeIndex", {
enumerable: true,
get: function () {
return _writeIndex2.default;
}
});
Object.defineProperty(exports, "writeIndexCli", {
enumerable: true,
get: function () {
return _writeIndexCli2.default;
}
});
var _createIndexCode2 = _interopRequireDefault(require("./createIndexCode"));
var _findIndexFiles2 = _interopRequireDefault(require("./findIndexFiles"));
var _log2 = _interopRequireDefault(require("./log"));
var _readDirectory2 = _interopRequireDefault(require("./readDirectory"));
var _sortByDepth2 = _interopRequireDefault(require("./sortByDepth"));
var _validateTargetDirectory2 = _interopRequireDefault(require("./validateTargetDirectory"));
var _writeIndex2 = _interopRequireDefault(require("./writeIndex"));
var _writeIndexCli2 = _interopRequireDefault(require("./writeIndexCli"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"index.js"}
+24
View File
@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _chalk = _interopRequireDefault(require("chalk"));
var _moment = _interopRequireDefault(require("moment"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = function _default() {
for (var _len = arguments.length, append = new Array(_len), _key = 0; _key < _len; _key++) {
append[_key] = arguments[_key];
}
// eslint-disable-next-line no-console
console.log(_chalk.default.dim('[' + (0, _moment.default)().format('HH:mm:ss') + ']'), ...append);
};
exports.default = _default;
//# sourceMappingURL=log.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../src/utilities/log.js"],"names":["append","console","log","chalk","dim","format"],"mappings":";;;;;;;AAAA;;AACA;;;;eAEe,oBAAe;AAAA,oCAAXA,MAAW;AAAXA,IAAAA,MAAW;AAAA;;AAC5B;AACAC,EAAAA,OAAO,CAACC,GAAR,CAAYC,eAAMC,GAAN,CAAU,MAAM,uBAASC,MAAT,CAAgB,UAAhB,CAAN,GAAoC,GAA9C,CAAZ,EAAgE,GAAGL,MAAnE;AACD,C","sourcesContent":["import chalk from 'chalk';\nimport moment from 'moment';\n\nexport default (...append) => {\n // eslint-disable-next-line no-console\n console.log(chalk.dim('[' + moment().format('HH:mm:ss') + ']'), ...append);\n};\n"],"file":"log.js"}
+139
View File
@@ -0,0 +1,139 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _fs = _interopRequireDefault(require("fs"));
var _path = _interopRequireDefault(require("path"));
var _lodash = _interopRequireDefault(require("lodash"));
var _hasIndex = _interopRequireDefault(require("./hasIndex"));
var _validateTargetDirectory = _interopRequireDefault(require("./validateTargetDirectory"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const hasNoExtension = fileName => {
const matches = fileName.match(/\./g);
return !matches;
};
const hasMultipleExtensions = fileName => {
const matches = fileName.match(/\./g);
return matches && matches.length > 1;
};
const isSafeName = fileName => {
return /^[_a-z][\w.]*$/i.test(fileName);
};
const stripExtension = fileName => {
const pos = fileName.lastIndexOf('.');
if (pos === -1) {
return fileName;
}
return fileName.slice(0, Math.max(0, pos));
};
const removeDuplicates = (files, preferredExtension) => {
return _lodash.default.filter(files, fileName => {
const withoutExtension = stripExtension(fileName);
const mainAlternative = withoutExtension + '.' + preferredExtension;
if (mainAlternative === fileName) {
return true;
}
return !_lodash.default.includes(files, mainAlternative);
});
};
const removeIgnoredFiles = function (files) {
let ignorePatterns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
if (ignorePatterns.length === 0) {
return files;
}
const patterns = ignorePatterns.map(pattern => {
if (_lodash.default.startsWith(pattern, '/') && _lodash.default.endsWith(pattern, '/')) {
const patternWithoutSlashes = pattern.slice(1, -1);
return new RegExp(patternWithoutSlashes);
}
return new RegExp(pattern);
});
return _lodash.default.filter(files, fileName => {
let pattern;
for (pattern of patterns) {
if (fileName.match(pattern) !== null) {
return false;
}
}
return true;
});
};
var _default = function _default(directoryPath) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!(0, _validateTargetDirectory.default)(directoryPath, options)) {
return false;
}
const _options$extensions = options.extensions,
extensions = _options$extensions === void 0 ? ['js'] : _options$extensions,
_options$config = options.config,
config = _options$config === void 0 ? {} : _options$config,
_options$ignoreDirect = options.ignoreDirectories,
ignoreDirectories = _options$ignoreDirect === void 0 ? false : _options$ignoreDirect;
let children;
children = _fs.default.readdirSync(directoryPath);
children = _lodash.default.filter(children, fileName => {
const absolutePath = _path.default.resolve(directoryPath, fileName);
const isDirectory = _fs.default.statSync(absolutePath).isDirectory();
if (!isSafeName(fileName)) {
return false;
}
if (hasNoExtension(fileName) && !isDirectory) {
return false;
}
if (hasMultipleExtensions(fileName)) {
return false;
}
if (_lodash.default.startsWith(fileName, options.outputFile || 'index.js')) {
return false;
}
if (!isDirectory && !extensions.some(extension => {
return _lodash.default.endsWith(fileName, '.' + extension);
})) {
return false;
}
if (isDirectory && (!(0, _hasIndex.default)(absolutePath, options) || ignoreDirectories)) {
return false;
}
return true;
});
children = removeDuplicates(children, extensions[0]);
children = removeIgnoredFiles(children, config.ignore);
return children.sort();
};
exports.default = _default;
//# sourceMappingURL=readDirectory.js.map
File diff suppressed because one or more lines are too long
+48
View File
@@ -0,0 +1,48 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _fs = _interopRequireDefault(require("fs"));
var _path = _interopRequireDefault(require("path"));
var _hasIndex = _interopRequireDefault(require("./hasIndex"));
var _constants = require("./constants");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = function _default(directoryPath) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!(0, _hasIndex.default)(directoryPath, options)) {
return {};
}
const indexPath = _path.default.resolve(directoryPath, options.outputFile || 'index.js');
const indexContents = _fs.default.readFileSync(indexPath, 'utf-8');
const found = indexContents.match(_constants.CREATE_INDEX_PATTERN);
const configLine = typeof found[1] === 'string' ? found[1].trim() : '';
if (configLine.length === 0) {
return {};
}
let config;
try {
config = JSON.parse(configLine);
} catch {
throw new Error('"' + indexPath + '" contains invalid configuration object.\n' + 'Configuration object must be a valid JSON.');
}
return config;
};
exports.default = _default;
//# sourceMappingURL=readIndexConfig.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../src/utilities/readIndexConfig.js"],"names":["directoryPath","options","indexPath","path","resolve","outputFile","indexContents","fs","readFileSync","found","match","CREATE_INDEX_PATTERN","configLine","trim","length","config","JSON","parse","Error"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;;;eAEe,kBAACA,aAAD,EAAiC;AAAA,MAAjBC,OAAiB,uEAAP,EAAO;;AAC9C,MAAI,CAAC,uBAASD,aAAT,EAAwBC,OAAxB,CAAL,EAAuC;AACrC,WAAO,EAAP;AACD;;AAED,QAAMC,SAAS,GAAGC,cAAKC,OAAL,CAAaJ,aAAb,EAA4BC,OAAO,CAACI,UAAR,IAAsB,UAAlD,CAAlB;;AACA,QAAMC,aAAa,GAAGC,YAAGC,YAAH,CAAgBN,SAAhB,EAA2B,OAA3B,CAAtB;;AACA,QAAMO,KAAK,GAAGH,aAAa,CAACI,KAAd,CAAoBC,+BAApB,CAAd;AACA,QAAMC,UAAU,GAAG,OAAOH,KAAK,CAAC,CAAD,CAAZ,KAAoB,QAApB,GAA+BA,KAAK,CAAC,CAAD,CAAL,CAASI,IAAT,EAA/B,GAAiD,EAApE;;AAEA,MAAID,UAAU,CAACE,MAAX,KAAsB,CAA1B,EAA6B;AAC3B,WAAO,EAAP;AACD;;AAED,MAAIC,MAAJ;;AAEA,MAAI;AACFA,IAAAA,MAAM,GAAGC,IAAI,CAACC,KAAL,CAAWL,UAAX,CAAT;AACD,GAFD,CAEE,MAAM;AACN,UAAM,IAAIM,KAAJ,CACJ,MAAMhB,SAAN,GAAkB,4CAAlB,GACA,4CAFI,CAAN;AAID;;AAED,SAAOa,MAAP;AACD,C","sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport hasIndex from './hasIndex';\nimport {CREATE_INDEX_PATTERN} from './constants';\n\nexport default (directoryPath, options = {}) => {\n if (!hasIndex(directoryPath, options)) {\n return {};\n }\n\n const indexPath = path.resolve(directoryPath, options.outputFile || 'index.js');\n const indexContents = fs.readFileSync(indexPath, 'utf-8');\n const found = indexContents.match(CREATE_INDEX_PATTERN);\n const configLine = typeof found[1] === 'string' ? found[1].trim() : '';\n\n if (configLine.length === 0) {\n return {};\n }\n\n let config;\n\n try {\n config = JSON.parse(configLine);\n } catch {\n throw new Error(\n '\"' + indexPath + '\" contains invalid configuration object.\\n' +\n 'Configuration object must be a valid JSON.',\n );\n }\n\n return config;\n};\n"],"file":"readIndexConfig.js"}
+19
View File
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _lodash = _interopRequireDefault(require("lodash"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = paths => {
return _lodash.default.sortBy(paths, path => {
return -path.split('/').length;
});
};
exports.default = _default;
//# sourceMappingURL=sortByDepth.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../src/utilities/sortByDepth.js"],"names":["paths","_","sortBy","path","split","length"],"mappings":";;;;;;;AAAA;;;;eAEgBA,KAAD,IAAW;AACxB,SAAOC,gBAAEC,MAAF,CAASF,KAAT,EAAiBG,IAAD,IAAU;AAC/B,WAAO,CAACA,IAAI,CAACC,KAAL,CAAW,GAAX,EAAgBC,MAAxB;AACD,GAFM,CAAP;AAGD,C","sourcesContent":["import _ from 'lodash';\n\nexport default (paths) => {\n return _.sortBy(paths, (path) => {\n return -path.split('/').length;\n });\n};\n"],"file":"sortByDepth.js"}
+61
View File
@@ -0,0 +1,61 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _fs = _interopRequireDefault(require("fs"));
var _path = _interopRequireDefault(require("path"));
var _constants = require("./constants");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = function _default(targetDirectory) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
const silent = options.silent;
let stats;
try {
stats = _fs.default.statSync(targetDirectory);
} catch {
if (silent) {
return false;
} else {
throw new Error('Directory "' + targetDirectory + '" does not exist.');
}
}
if (!stats.isDirectory()) {
if (silent) {
return false;
} else {
throw new Error('"' + targetDirectory + '" is not a directory.');
}
}
const indexFilePath = _path.default.resolve(targetDirectory, './' + (options.outputFile || 'index.js'));
try {
_fs.default.statSync(indexFilePath);
} catch {
return true;
}
const indexFile = _fs.default.readFileSync(indexFilePath, 'utf8');
if (!indexFile.match(_constants.CREATE_INDEX_PATTERN)) {
if (silent) {
return false;
} else {
throw new Error('"' + indexFilePath + '" unsafe index.');
}
}
return true;
};
exports.default = _default;
//# sourceMappingURL=validateTargetDirectory.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../src/utilities/validateTargetDirectory.js"],"names":["targetDirectory","options","silent","stats","fs","statSync","Error","isDirectory","indexFilePath","path","resolve","outputFile","indexFile","readFileSync","match","CREATE_INDEX_PATTERN"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;eAEe,kBAACA,eAAD,EAAmC;AAAA,MAAjBC,OAAiB,uEAAP,EAAO;AAChD,QAAMC,MAAM,GAAGD,OAAO,CAACC,MAAvB;AACA,MAAIC,KAAJ;;AAEA,MAAI;AACFA,IAAAA,KAAK,GAAGC,YAAGC,QAAH,CAAYL,eAAZ,CAAR;AACD,GAFD,CAEE,MAAM;AACN,QAAIE,MAAJ,EAAY;AACV,aAAO,KAAP;AACD,KAFD,MAEO;AACL,YAAM,IAAII,KAAJ,CAAU,gBAAgBN,eAAhB,GAAkC,mBAA5C,CAAN;AACD;AACF;;AAED,MAAI,CAACG,KAAK,CAACI,WAAN,EAAL,EAA0B;AACxB,QAAIL,MAAJ,EAAY;AACV,aAAO,KAAP;AACD,KAFD,MAEO;AACL,YAAM,IAAII,KAAJ,CAAU,MAAMN,eAAN,GAAwB,uBAAlC,CAAN;AACD;AACF;;AAED,QAAMQ,aAAa,GAAGC,cAAKC,OAAL,CAAaV,eAAb,EAA8B,QAAQC,OAAO,CAACU,UAAR,IAAsB,UAA9B,CAA9B,CAAtB;;AAEA,MAAI;AACFP,gBAAGC,QAAH,CAAYG,aAAZ;AACD,GAFD,CAEE,MAAM;AACN,WAAO,IAAP;AACD;;AAED,QAAMI,SAAS,GAAGR,YAAGS,YAAH,CAAgBL,aAAhB,EAA+B,MAA/B,CAAlB;;AAEA,MAAI,CAACI,SAAS,CAACE,KAAV,CAAgBC,+BAAhB,CAAL,EAA4C;AAC1C,QAAIb,MAAJ,EAAY;AACV,aAAO,KAAP;AACD,KAFD,MAEO;AACL,YAAM,IAAII,KAAJ,CAAU,MAAME,aAAN,GAAsB,iBAAhC,CAAN;AACD;AACF;;AAED,SAAO,IAAP;AACD,C","sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport {CREATE_INDEX_PATTERN} from './constants';\n\nexport default (targetDirectory, options = {}) => {\n const silent = options.silent;\n let stats;\n\n try {\n stats = fs.statSync(targetDirectory);\n } catch {\n if (silent) {\n return false;\n } else {\n throw new Error('Directory \"' + targetDirectory + '\" does not exist.');\n }\n }\n\n if (!stats.isDirectory()) {\n if (silent) {\n return false;\n } else {\n throw new Error('\"' + targetDirectory + '\" is not a directory.');\n }\n }\n\n const indexFilePath = path.resolve(targetDirectory, './' + (options.outputFile || 'index.js'));\n\n try {\n fs.statSync(indexFilePath);\n } catch {\n return true;\n }\n\n const indexFile = fs.readFileSync(indexFilePath, 'utf8');\n\n if (!indexFile.match(CREATE_INDEX_PATTERN)) {\n if (silent) {\n return false;\n } else {\n throw new Error('\"' + indexFilePath + '\" unsafe index.');\n }\n }\n\n return true;\n};\n\n"],"file":"validateTargetDirectory.js"}
+50
View File
@@ -0,0 +1,50 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _fs = _interopRequireDefault(require("fs"));
var _path = _interopRequireDefault(require("path"));
var _lodash = _interopRequireDefault(require("lodash"));
var _createIndexCode = _interopRequireDefault(require("./createIndexCode"));
var _validateTargetDirectory = _interopRequireDefault(require("./validateTargetDirectory"));
var _readDirectory = _interopRequireDefault(require("./readDirectory"));
var _readIndexConfig = _interopRequireDefault(require("./readIndexConfig"));
var _sortByDepth = _interopRequireDefault(require("./sortByDepth"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = function _default(directoryPaths) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
const sortedDirectoryPaths = (0, _sortByDepth.default)(directoryPaths).filter(directoryPath => {
return (0, _validateTargetDirectory.default)(directoryPath, {
outputFile: options.outputFile,
silent: options.ignoreUnsafe
});
});
_lodash.default.forEach(sortedDirectoryPaths, directoryPath => {
const config = (0, _readIndexConfig.default)(directoryPath, options);
const optionsWithConfig = Object.assign({}, options, {
config
});
const siblings = (0, _readDirectory.default)(directoryPath, optionsWithConfig);
const indexCode = (0, _createIndexCode.default)(siblings, optionsWithConfig);
const indexFilePath = _path.default.resolve(directoryPath, options.outputFile || 'index.js');
_fs.default.writeFileSync(indexFilePath, indexCode);
});
};
exports.default = _default;
//# sourceMappingURL=writeIndex.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../src/utilities/writeIndex.js"],"names":["directoryPaths","options","sortedDirectoryPaths","filter","directoryPath","outputFile","silent","ignoreUnsafe","_","forEach","config","optionsWithConfig","Object","assign","siblings","indexCode","indexFilePath","path","resolve","fs","writeFileSync"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;eAEe,kBAACA,cAAD,EAAkC;AAAA,MAAjBC,OAAiB,uEAAP,EAAO;AAC/C,QAAMC,oBAAoB,GAAG,0BAAYF,cAAZ,EAC1BG,MAD0B,CAClBC,aAAD,IAAmB;AACzB,WAAO,sCAAwBA,aAAxB,EAAuC;AAACC,MAAAA,UAAU,EAAEJ,OAAO,CAACI,UAArB;AAC5CC,MAAAA,MAAM,EAAEL,OAAO,CAACM;AAD4B,KAAvC,CAAP;AAED,GAJ0B,CAA7B;;AAMAC,kBAAEC,OAAF,CAAUP,oBAAV,EAAiCE,aAAD,IAAmB;AACjD,UAAMM,MAAM,GAAG,8BAAgBN,aAAhB,EAA+BH,OAA/B,CAAf;AACA,UAAMU,iBAAiB,GAAGC,MAAM,CAACC,MAAP,CAAc,EAAd,EAAkBZ,OAAlB,EAA2B;AAACS,MAAAA;AAAD,KAA3B,CAA1B;AACA,UAAMI,QAAQ,GAAG,4BAAcV,aAAd,EAA6BO,iBAA7B,CAAjB;AACA,UAAMI,SAAS,GAAG,8BAAgBD,QAAhB,EAA0BH,iBAA1B,CAAlB;;AACA,UAAMK,aAAa,GAAGC,cAAKC,OAAL,CAAad,aAAb,EAA4BH,OAAO,CAACI,UAAR,IAAsB,UAAlD,CAAtB;;AAEAc,gBAAGC,aAAH,CAAiBJ,aAAjB,EAAgCD,SAAhC;AACD,GARD;AASD,C","sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport _ from 'lodash';\nimport createIndexCode from './createIndexCode';\nimport validateTargetDirectory from './validateTargetDirectory';\nimport readDirectory from './readDirectory';\nimport readIndexConfig from './readIndexConfig';\nimport sortByDepth from './sortByDepth';\n\nexport default (directoryPaths, options = {}) => {\n const sortedDirectoryPaths = sortByDepth(directoryPaths)\n .filter((directoryPath) => {\n return validateTargetDirectory(directoryPath, {outputFile: options.outputFile,\n silent: options.ignoreUnsafe});\n });\n\n _.forEach(sortedDirectoryPaths, (directoryPath) => {\n const config = readIndexConfig(directoryPath, options);\n const optionsWithConfig = Object.assign({}, options, {config});\n const siblings = readDirectory(directoryPath, optionsWithConfig);\n const indexCode = createIndexCode(siblings, optionsWithConfig);\n const indexFilePath = path.resolve(directoryPath, options.outputFile || 'index.js');\n\n fs.writeFileSync(indexFilePath, indexCode);\n });\n};\n"],"file":"writeIndex.js"}
+105
View File
@@ -0,0 +1,105 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _fs = _interopRequireDefault(require("fs"));
var _path = _interopRequireDefault(require("path"));
var _lodash = _interopRequireDefault(require("lodash"));
var _chalk = _interopRequireDefault(require("chalk"));
var _createIndexCode = _interopRequireDefault(require("./createIndexCode"));
var _validateTargetDirectory = _interopRequireDefault(require("./validateTargetDirectory"));
var _readDirectory = _interopRequireDefault(require("./readDirectory"));
var _readIndexConfig = _interopRequireDefault(require("./readIndexConfig"));
var _sortByDepth = _interopRequireDefault(require("./sortByDepth"));
var _log = _interopRequireDefault(require("./log"));
var _findIndexFiles = _interopRequireDefault(require("./findIndexFiles"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = function _default(directoryPaths) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
let sortedDirectoryPaths;
sortedDirectoryPaths = (0, _sortByDepth.default)(directoryPaths);
(0, _log.default)('Target directories', sortedDirectoryPaths);
(0, _log.default)('Output file', options.outputFile);
if (options.updateIndex) {
(0, _log.default)('Update index:', options.updateIndex ? _chalk.default.green('true') : _chalk.default.red('false'));
} else {
(0, _log.default)('Recursive:', options.recursive ? _chalk.default.green('true') : _chalk.default.red('false'));
(0, _log.default)('Ignore unsafe:', options.ignoreUnsafe ? _chalk.default.green('true') : _chalk.default.red('false'));
(0, _log.default)('Extensions:', _chalk.default.green(options.extensions));
}
if (options.updateIndex || options.recursive) {
sortedDirectoryPaths = _lodash.default.map(sortedDirectoryPaths, directory => {
return (0, _findIndexFiles.default)(directory, {
fileName: options.updateIndex ? options.outputFile || 'index.js' : '*',
silent: options.updateIndex || options.ignoreUnsafe
});
});
sortedDirectoryPaths = _lodash.default.flatten(sortedDirectoryPaths);
sortedDirectoryPaths = _lodash.default.uniq(sortedDirectoryPaths);
sortedDirectoryPaths = (0, _sortByDepth.default)(sortedDirectoryPaths);
(0, _log.default)('Updating index files in:', sortedDirectoryPaths.reverse().join(', '));
}
sortedDirectoryPaths = sortedDirectoryPaths.filter(directoryPath => {
return (0, _validateTargetDirectory.default)(directoryPath, {
outputFile: options.outputFile,
silent: options.ignoreUnsafe
});
});
_lodash.default.forEach(sortedDirectoryPaths, directoryPath => {
let existingIndexCode;
const config = (0, _readIndexConfig.default)(directoryPath, options);
const siblings = (0, _readDirectory.default)(directoryPath, {
config,
extensions: options.extensions,
ignoreDirectories: options.ignoreDirectories,
silent: options.ignoreUnsafe
});
const indexCode = (0, _createIndexCode.default)(siblings, {
banner: options.banner,
config
});
const indexFilePath = _path.default.resolve(directoryPath, options.outputFile || 'index.js');
try {
existingIndexCode = _fs.default.readFileSync(indexFilePath, 'utf8');
/* eslint-disable no-empty */
} catch {}
/* eslint-enable no-empty */
_fs.default.writeFileSync(indexFilePath, indexCode);
if (existingIndexCode && existingIndexCode === indexCode) {
(0, _log.default)(indexFilePath, _chalk.default.yellow('[index has not changed]'));
} else if (existingIndexCode && existingIndexCode !== indexCode) {
(0, _log.default)(indexFilePath, _chalk.default.green('[updated index]'));
} else {
(0, _log.default)(indexFilePath, _chalk.default.green('[created index]'));
}
});
(0, _log.default)('Done');
};
exports.default = _default;
//# sourceMappingURL=writeIndexCli.js.map
File diff suppressed because one or more lines are too long
+722
View File
@@ -0,0 +1,722 @@
{
"name": "create-index",
"version": "0.0.0-development",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@babel/code-frame": {
"version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.12.13.tgz",
"integrity": "sha512-HV1Cm0Q3ZrpCR93tkWOYiuYIgLxZXZFVG2VgK+MBWjUqZTundupbfx2aXarXuw5Ko5aMcjtJgbSs4vUGBS5v6g==",
"dev": true,
"requires": {
"@babel/highlight": "^7.12.13"
}
},
"@babel/compat-data": {
"version": "7.14.4",
"resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.14.4.tgz",
"integrity": "sha512-i2wXrWQNkH6JplJQGn3Rd2I4Pij8GdHkXwHMxm+zV5YG/Jci+bCNrWZEWC4o+umiDkRrRs4dVzH3X4GP7vyjQQ==",
"dev": true
},
"@babel/core": {
"version": "7.14.3",
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.14.3.tgz",
"integrity": "sha512-jB5AmTKOCSJIZ72sd78ECEhuPiDMKlQdDI/4QRI6lzYATx5SSogS1oQA2AoPecRCknm30gHi2l+QVvNUu3wZAg==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.12.13",
"@babel/generator": "^7.14.3",
"@babel/helper-compilation-targets": "^7.13.16",
"@babel/helper-module-transforms": "^7.14.2",
"@babel/helpers": "^7.14.0",
"@babel/parser": "^7.14.3",
"@babel/template": "^7.12.13",
"@babel/traverse": "^7.14.2",
"@babel/types": "^7.14.2",
"convert-source-map": "^1.7.0",
"debug": "^4.1.0",
"gensync": "^1.0.0-beta.2",
"json5": "^2.1.2",
"semver": "^6.3.0",
"source-map": "^0.5.0"
}
},
"@babel/generator": {
"version": "7.14.3",
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.14.3.tgz",
"integrity": "sha512-bn0S6flG/j0xtQdz3hsjJ624h3W0r3llttBMfyHX3YrZ/KtLYr15bjA0FXkgW7FpvrDuTuElXeVjiKlYRpnOFA==",
"dev": true,
"requires": {
"@babel/types": "^7.14.2",
"jsesc": "^2.5.1",
"source-map": "^0.5.0"
}
},
"@babel/helper-compilation-targets": {
"version": "7.14.4",
"resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.14.4.tgz",
"integrity": "sha512-JgdzOYZ/qGaKTVkn5qEDV/SXAh8KcyUVkCoSWGN8T3bwrgd6m+/dJa2kVGi6RJYJgEYPBdZ84BZp9dUjNWkBaA==",
"dev": true,
"requires": {
"@babel/compat-data": "^7.14.4",
"@babel/helper-validator-option": "^7.12.17",
"browserslist": "^4.16.6",
"semver": "^6.3.0"
}
},
"@babel/helper-function-name": {
"version": "7.14.2",
"resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.14.2.tgz",
"integrity": "sha512-NYZlkZRydxw+YT56IlhIcS8PAhb+FEUiOzuhFTfqDyPmzAhRge6ua0dQYT/Uh0t/EDHq05/i+e5M2d4XvjgarQ==",
"dev": true,
"requires": {
"@babel/helper-get-function-arity": "^7.12.13",
"@babel/template": "^7.12.13",
"@babel/types": "^7.14.2"
}
},
"@babel/helper-get-function-arity": {
"version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.12.13.tgz",
"integrity": "sha512-DjEVzQNz5LICkzN0REdpD5prGoidvbdYk1BVgRUOINaWJP2t6avB27X1guXK1kXNrX0WMfsrm1A/ZBthYuIMQg==",
"dev": true,
"requires": {
"@babel/types": "^7.12.13"
}
},
"@babel/helper-member-expression-to-functions": {
"version": "7.13.12",
"resolved": "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.13.12.tgz",
"integrity": "sha512-48ql1CLL59aKbU94Y88Xgb2VFy7a95ykGRbJJaaVv+LX5U8wFpLfiGXJJGUozsmA1oEh/o5Bp60Voq7ACyA/Sw==",
"dev": true,
"requires": {
"@babel/types": "^7.13.12"
}
},
"@babel/helper-module-imports": {
"version": "7.13.12",
"resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.13.12.tgz",
"integrity": "sha512-4cVvR2/1B693IuOvSI20xqqa/+bl7lqAMR59R4iu39R9aOX8/JoYY1sFaNvUMyMBGnHdwvJgUrzNLoUZxXypxA==",
"dev": true,
"requires": {
"@babel/types": "^7.13.12"
}
},
"@babel/helper-module-transforms": {
"version": "7.14.2",
"resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.14.2.tgz",
"integrity": "sha512-OznJUda/soKXv0XhpvzGWDnml4Qnwp16GN+D/kZIdLsWoHj05kyu8Rm5kXmMef+rVJZ0+4pSGLkeixdqNUATDA==",
"dev": true,
"requires": {
"@babel/helper-module-imports": "^7.13.12",
"@babel/helper-replace-supers": "^7.13.12",
"@babel/helper-simple-access": "^7.13.12",
"@babel/helper-split-export-declaration": "^7.12.13",
"@babel/helper-validator-identifier": "^7.14.0",
"@babel/template": "^7.12.13",
"@babel/traverse": "^7.14.2",
"@babel/types": "^7.14.2"
}
},
"@babel/helper-optimise-call-expression": {
"version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.12.13.tgz",
"integrity": "sha512-BdWQhoVJkp6nVjB7nkFWcn43dkprYauqtk++Py2eaf/GRDFm5BxRqEIZCiHlZUGAVmtwKcsVL1dC68WmzeFmiA==",
"dev": true,
"requires": {
"@babel/types": "^7.12.13"
}
},
"@babel/helper-plugin-utils": {
"version": "7.13.0",
"resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.13.0.tgz",
"integrity": "sha512-ZPafIPSwzUlAoWT8DKs1W2VyF2gOWthGd5NGFMsBcMMol+ZhK+EQY/e6V96poa6PA/Bh+C9plWN0hXO1uB8AfQ==",
"dev": true
},
"@babel/helper-replace-supers": {
"version": "7.14.4",
"resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.14.4.tgz",
"integrity": "sha512-zZ7uHCWlxfEAAOVDYQpEf/uyi1dmeC7fX4nCf2iz9drnCwi1zvwXL3HwWWNXUQEJ1k23yVn3VbddiI9iJEXaTQ==",
"dev": true,
"requires": {
"@babel/helper-member-expression-to-functions": "^7.13.12",
"@babel/helper-optimise-call-expression": "^7.12.13",
"@babel/traverse": "^7.14.2",
"@babel/types": "^7.14.4"
}
},
"@babel/helper-simple-access": {
"version": "7.13.12",
"resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.13.12.tgz",
"integrity": "sha512-7FEjbrx5SL9cWvXioDbnlYTppcZGuCY6ow3/D5vMggb2Ywgu4dMrpTJX0JdQAIcRRUElOIxF3yEooa9gUb9ZbA==",
"dev": true,
"requires": {
"@babel/types": "^7.13.12"
}
},
"@babel/helper-split-export-declaration": {
"version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.12.13.tgz",
"integrity": "sha512-tCJDltF83htUtXx5NLcaDqRmknv652ZWCHyoTETf1CXYJdPC7nohZohjUgieXhv0hTJdRf2FjDueFehdNucpzg==",
"dev": true,
"requires": {
"@babel/types": "^7.12.13"
}
},
"@babel/helper-validator-identifier": {
"version": "7.14.0",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.14.0.tgz",
"integrity": "sha512-V3ts7zMSu5lfiwWDVWzRDGIN+lnCEUdaXgtVHJgLb1rGaA6jMrtB9EmE7L18foXJIE8Un/A/h6NJfGQp/e1J4A==",
"dev": true
},
"@babel/helper-validator-option": {
"version": "7.12.17",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.12.17.tgz",
"integrity": "sha512-TopkMDmLzq8ngChwRlyjR6raKD6gMSae4JdYDB8bByKreQgG0RBTuKe9LRxW3wFtUnjxOPRKBDwEH6Mg5KeDfw==",
"dev": true
},
"@babel/helpers": {
"version": "7.14.0",
"resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.14.0.tgz",
"integrity": "sha512-+ufuXprtQ1D1iZTO/K9+EBRn+qPWMJjZSw/S0KlFrxCw4tkrzv9grgpDHkY9MeQTjTY8i2sp7Jep8DfU6tN9Mg==",
"dev": true,
"requires": {
"@babel/template": "^7.12.13",
"@babel/traverse": "^7.14.0",
"@babel/types": "^7.14.0"
}
},
"@babel/highlight": {
"version": "7.14.0",
"resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.14.0.tgz",
"integrity": "sha512-YSCOwxvTYEIMSGaBQb5kDDsCopDdiUGsqpatp3fOlI4+2HQSkTmEVWnVuySdAC5EWCqSWWTv0ib63RjR7dTBdg==",
"dev": true,
"requires": {
"@babel/helper-validator-identifier": "^7.14.0",
"chalk": "^2.0.0",
"js-tokens": "^4.0.0"
},
"dependencies": {
"chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
}
}
},
"@babel/parser": {
"version": "7.14.4",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.14.4.tgz",
"integrity": "sha512-ArliyUsWDUqEGfWcmzpGUzNfLxTdTp6WU4IuP6QFSp9gGfWS6boxFCkJSJ/L4+RG8z/FnIU3WxCk6hPL9SSWeA==",
"dev": true
},
"@babel/plugin-proposal-export-default-from": {
"version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/plugin-proposal-export-default-from/-/plugin-proposal-export-default-from-7.12.13.tgz",
"integrity": "sha512-idIsBT+DGXdOHL82U+8bwX4goHm/z10g8sGGrQroh+HCRcm7mDv/luaGdWJQMTuCX2FsdXS7X0Nyyzp4znAPJA==",
"dev": true,
"requires": {
"@babel/helper-plugin-utils": "^7.12.13",
"@babel/plugin-syntax-export-default-from": "^7.12.13"
}
},
"@babel/plugin-proposal-export-namespace-from": {
"version": "7.14.2",
"resolved": "https://registry.npmjs.org/@babel/plugin-proposal-export-namespace-from/-/plugin-proposal-export-namespace-from-7.14.2.tgz",
"integrity": "sha512-sRxW3z3Zp3pFfLAgVEvzTFutTXax837oOatUIvSG9o5gRj9mKwm3br1Se5f4QalTQs9x4AzlA/HrCWbQIHASUQ==",
"dev": true,
"requires": {
"@babel/helper-plugin-utils": "^7.13.0",
"@babel/plugin-syntax-export-namespace-from": "^7.8.3"
}
},
"@babel/plugin-syntax-export-default-from": {
"version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/plugin-syntax-export-default-from/-/plugin-syntax-export-default-from-7.12.13.tgz",
"integrity": "sha512-gVry0zqoums0hA+EniCYK3gABhjYSLX1dVuwYpPw9DrLNA4/GovXySHVg4FGRsZht09ON/5C2NVx3keq+qqVGQ==",
"dev": true,
"requires": {
"@babel/helper-plugin-utils": "^7.12.13"
}
},
"@babel/plugin-syntax-export-namespace-from": {
"version": "7.8.3",
"resolved": "https://registry.npmjs.org/@babel/plugin-syntax-export-namespace-from/-/plugin-syntax-export-namespace-from-7.8.3.tgz",
"integrity": "sha512-MXf5laXo6c1IbEbegDmzGPwGNTsHZmEy6QGznu5Sh2UCWvueywb2ee+CCE4zQiZstxU9BMoQO9i6zUFSY0Kj0Q==",
"dev": true,
"requires": {
"@babel/helper-plugin-utils": "^7.8.3"
}
},
"@babel/plugin-transform-destructuring": {
"version": "7.14.4",
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-destructuring/-/plugin-transform-destructuring-7.14.4.tgz",
"integrity": "sha512-JyywKreTCGTUsL1OKu1A3ms/R1sTP0WxbpXlALeGzF53eB3bxtNkYdMj9SDgK7g6ImPy76J5oYYKoTtQImlhQA==",
"dev": true,
"requires": {
"@babel/helper-plugin-utils": "^7.13.0"
}
},
"@babel/plugin-transform-modules-commonjs": {
"version": "7.14.0",
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.14.0.tgz",
"integrity": "sha512-EX4QePlsTaRZQmw9BsoPeyh5OCtRGIhwfLquhxGp5e32w+dyL8htOcDwamlitmNFK6xBZYlygjdye9dbd9rUlQ==",
"dev": true,
"requires": {
"@babel/helper-module-transforms": "^7.14.0",
"@babel/helper-plugin-utils": "^7.13.0",
"@babel/helper-simple-access": "^7.13.12",
"babel-plugin-dynamic-import-node": "^2.3.3"
}
},
"@babel/plugin-transform-parameters": {
"version": "7.14.2",
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-parameters/-/plugin-transform-parameters-7.14.2.tgz",
"integrity": "sha512-NxoVmA3APNCC1JdMXkdYXuQS+EMdqy0vIwyDHeKHiJKRxmp1qGSdb0JLEIoPRhkx6H/8Qi3RJ3uqOCYw8giy9A==",
"dev": true,
"requires": {
"@babel/helper-plugin-utils": "^7.13.0"
}
},
"@babel/template": {
"version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/template/-/template-7.12.13.tgz",
"integrity": "sha512-/7xxiGA57xMo/P2GVvdEumr8ONhFOhfgq2ihK3h1e6THqzTAkHbkXgB0xI9yeTfIUoH3+oAeHhqm/I43OTbbjA==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.12.13",
"@babel/parser": "^7.12.13",
"@babel/types": "^7.12.13"
}
},
"@babel/traverse": {
"version": "7.14.2",
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.14.2.tgz",
"integrity": "sha512-TsdRgvBFHMyHOOzcP9S6QU0QQtjxlRpEYOy3mcCO5RgmC305ki42aSAmfZEMSSYBla2oZ9BMqYlncBaKmD/7iA==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.12.13",
"@babel/generator": "^7.14.2",
"@babel/helper-function-name": "^7.14.2",
"@babel/helper-split-export-declaration": "^7.12.13",
"@babel/parser": "^7.14.2",
"@babel/types": "^7.14.2",
"debug": "^4.1.0",
"globals": "^11.1.0"
}
},
"@babel/types": {
"version": "7.14.4",
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.14.4.tgz",
"integrity": "sha512-lCj4aIs0xUefJFQnwwQv2Bxg7Omd6bgquZ6LGC+gGMh6/s5qDVfjuCMlDmYQ15SLsWHd9n+X3E75lKIhl5Lkiw==",
"dev": true,
"requires": {
"@babel/helper-validator-identifier": "^7.14.0",
"to-fast-properties": "^2.0.0"
}
},
"ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"requires": {
"color-convert": "^1.9.0"
}
},
"babel-plugin-dynamic-import-node": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.3.tgz",
"integrity": "sha512-jZVI+s9Zg3IqA/kdi0i6UDCybUI3aSBLnglhYbSSjKlV7yF1F/5LWv8MakQmvYpnbJDS6fcBL2KzHSxNCMtWSQ==",
"dev": true,
"requires": {
"object.assign": "^4.1.0"
}
},
"balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
},
"browserslist": {
"version": "4.16.6",
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.16.6.tgz",
"integrity": "sha512-Wspk/PqO+4W9qp5iUTJsa1B/QrYn1keNCcEP5OvP7WBwT4KaDly0uONYmC6Xa3Z5IqnUgS0KcgLYu1l74x0ZXQ==",
"dev": true,
"requires": {
"caniuse-lite": "^1.0.30001219",
"colorette": "^1.2.2",
"electron-to-chromium": "^1.3.723",
"escalade": "^3.1.1",
"node-releases": "^1.1.71"
}
},
"call-bind": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
"integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==",
"dev": true,
"requires": {
"function-bind": "^1.1.1",
"get-intrinsic": "^1.0.2"
}
},
"caniuse-lite": {
"version": "1.0.30001233",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001233.tgz",
"integrity": "sha512-BmkbxLfStqiPA7IEzQpIk0UFZFf3A4E6fzjPJ6OR+bFC2L8ES9J8zGA/asoi47p8XDVkev+WJo2I2Nc8c/34Yg==",
"dev": true
},
"color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"dev": true,
"requires": {
"color-name": "1.1.3"
}
},
"color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
"dev": true
},
"colorette": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/colorette/-/colorette-1.2.2.tgz",
"integrity": "sha512-MKGMzyfeuutC/ZJ1cba9NqcNpfeqMUcYmyF1ZFY6/Cn7CNSAKx6a+s48sqLqyAiZuaP2TcqMhoo+dlwFnVxT9w==",
"dev": true
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"convert-source-map": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.7.0.tgz",
"integrity": "sha512-4FJkXzKXEDB1snCFZlLP4gpC3JILicCpGbzG9f9G7tGqGCzETQ2hWPrcinA9oU4wtf2biUaEH5065UnMeR33oA==",
"dev": true,
"requires": {
"safe-buffer": "~5.1.1"
}
},
"cross-env": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz",
"integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==",
"dev": true,
"requires": {
"cross-spawn": "^7.0.1"
}
},
"cross-spawn": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
"integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==",
"dev": true,
"requires": {
"path-key": "^3.1.0",
"shebang-command": "^2.0.0",
"which": "^2.0.1"
}
},
"debug": {
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz",
"integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==",
"dev": true,
"requires": {
"ms": "2.1.2"
}
},
"define-properties": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz",
"integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==",
"dev": true,
"requires": {
"object-keys": "^1.0.12"
}
},
"electron-to-chromium": {
"version": "1.3.744",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.744.tgz",
"integrity": "sha512-o/vep/PvSXg+7buwCbVJXHY3zbjYVmFPwnMMnchESXgAzrfcasvbX/hQZHCFGG7YdZgdtwt1KTMyK9CyBxPbLA==",
"dev": true
},
"escalade": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz",
"integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==",
"dev": true
},
"escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
"dev": true
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
},
"function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
"dev": true
},
"gensync": {
"version": "1.0.0-beta.2",
"resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz",
"integrity": "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==",
"dev": true
},
"get-intrinsic": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz",
"integrity": "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==",
"dev": true,
"requires": {
"function-bind": "^1.1.1",
"has": "^1.0.3",
"has-symbols": "^1.0.1"
}
},
"globals": {
"version": "11.12.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz",
"integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==",
"dev": true
},
"has": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
"integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
"dev": true,
"requires": {
"function-bind": "^1.1.1"
}
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
"dev": true
},
"has-symbols": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.2.tgz",
"integrity": "sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw==",
"dev": true
},
"inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"requires": {
"once": "^1.3.0",
"wrappy": "1"
}
},
"inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"isexe": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
"integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=",
"dev": true
},
"js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
"dev": true
},
"jsesc": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz",
"integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==",
"dev": true
},
"json5": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.0.tgz",
"integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==",
"dev": true,
"requires": {
"minimist": "^1.2.5"
}
},
"minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"requires": {
"brace-expansion": "^1.1.7"
}
},
"minimist": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
"dev": true
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
"dev": true
},
"node-releases": {
"version": "1.1.72",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.72.tgz",
"integrity": "sha512-LLUo+PpH3dU6XizX3iVoubUNheF/owjXCZZ5yACDxNnPtgFuludV1ZL3ayK1kVep42Rmm0+R9/Y60NQbZ2bifw==",
"dev": true
},
"object-keys": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz",
"integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==",
"dev": true
},
"object.assign": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.2.tgz",
"integrity": "sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ==",
"dev": true,
"requires": {
"call-bind": "^1.0.0",
"define-properties": "^1.1.3",
"has-symbols": "^1.0.1",
"object-keys": "^1.1.1"
}
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"requires": {
"wrappy": "1"
}
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
},
"path-key": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
"integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
"dev": true
},
"rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"requires": {
"glob": "^7.1.3"
},
"dependencies": {
"glob": {
"version": "7.1.7",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz",
"integrity": "sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==",
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
}
}
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
"dev": true
},
"semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true
},
"shebang-command": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
"integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
"dev": true,
"requires": {
"shebang-regex": "^3.0.0"
}
},
"shebang-regex": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
"integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
"dev": true
},
"source-map": {
"version": "0.5.7",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz",
"integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=",
"dev": true
},
"supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dev": true,
"requires": {
"has-flag": "^3.0.0"
}
},
"to-fast-properties": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
"integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=",
"dev": true
},
"which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
"dev": true,
"requires": {
"isexe": "^2.0.0"
}
},
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
}
}
}
+32 -25
View File
@@ -6,27 +6,30 @@
}, },
"bin": "./dist/bin/create-index.js", "bin": "./dist/bin/create-index.js",
"dependencies": { "dependencies": {
"chalk": "^1.1.3", "chalk": "^4.0.0",
"glob": "^7.1.1", "glob": "^7.1.6",
"lodash": "^4.16.6", "lodash": "^4.17.15",
"moment": "^2.15.2", "moment": "^2.25.3",
"yargs": "^6.3.0" "rimraf": "^3.0.2",
"yargs": "^15.3.1"
}, },
"description": "Creates ES6 ./index.js file in target directories that imports and exports all sibling files and directories.", "description": "Creates ES6 ./index.js file in target directories that imports and exports all sibling files and directories.",
"devDependencies": { "devDependencies": {
"babel-cli": "^6.18.0", "@babel/cli": "^7.0.0",
"babel-plugin-transform-es2015-destructuring": "^6.18.0", "@babel/core": "^7.14.3",
"babel-plugin-transform-es2015-modules-commonjs": "^6.18.0", "@babel/plugin-proposal-export-default-from": "^7.12.13",
"babel-plugin-transform-es2015-parameters": "^6.18.0", "@babel/plugin-proposal-export-namespace-from": "^7.14.2",
"babel-plugin-transform-export-extensions": "^6.8.0", "@babel/plugin-transform-destructuring": "^7.14.4",
"babel-register": "^6.18.0", "@babel/plugin-transform-modules-commonjs": "^7.14.0",
"chai": "^3.5.0", "@babel/plugin-transform-parameters": "^7.14.2",
"cross-env": "^3.1.3", "@babel/register": "^7.0.0",
"eslint": "^3.9.1", "chai": "^4.2.0",
"eslint-config-canonical": "^4.0.0", "cross-env": "^7.0.3",
"husky": "^0.11.9", "eslint": "^7.0.0",
"mocha": "^3.1.2", "eslint-config-canonical": "^20.0.4",
"semantic-release": "^6.3.2" "husky": "^4.2.5",
"mocha": "^7.1.2",
"semantic-release": "^17.0.7"
}, },
"engines": { "engines": {
"node": ">=5" "node": ">=5"
@@ -43,12 +46,16 @@
"type": "git", "type": "git",
"url": "https://github.com/gajus/create-index" "url": "https://github.com/gajus/create-index"
}, },
"scripts": { "husky": {
"build": "cross-env NODE_ENV=production babel --source-maps --copy-files ./src --out-dir ./dist", "hooks": {
"create-index": "node ./dist/bin/create-index ./src/utilities", "pre-commit": "npm run test"
"lint": "cross-env NODE_ENV=development eslint ./src ./tests", }
"precommit": "npm run test",
"test": "npm run build && npm run lint && cross-env NODE_ENV=development mocha --compilers js:babel-register"
}, },
"version": "1.1.0" "scripts": {
"build": "rimraf -fr ./dist && cross-env NODE_ENV=production && babel --source-maps --copy-files ./src --out-dir ./dist",
"create-index": "node ./dist/bin/create-index ./src/utilities",
"lint": "cross-env NODE_ENV=development eslint ./src ./test",
"test": "cross-env NODE_ENV=development mocha --require @babel/register"
},
"version": "0.0.0-development"
} }
+44 -15
View File
@@ -1,8 +1,10 @@
#!/usr/bin/env node #!/usr/bin/env node
/* eslint-disable filenames/match-regex */
import yargs from 'yargs'; import yargs from 'yargs';
import { import {
writeIndexCli writeIndexCli,
} from '../utilities'; } from '../utilities';
const argv = yargs const argv = yargs
@@ -12,48 +14,75 @@ const argv = yargs
alias: 'r', alias: 'r',
default: false, default: false,
description: 'Create/update index files recursively. Halts on any unsafe "index.js" files.', description: 'Create/update index files recursively. Halts on any unsafe "index.js" files.',
type: 'boolean' type: 'boolean',
} },
}) })
.options({ .options({
ignoreUnsafe: { ignoreUnsafe: {
alias: 'i', alias: 'i',
default: false, default: false,
description: 'Ignores unsafe "index.js" files instead of halting.', 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',
},
}) })
.options({ .options({
update: { update: {
alias: 'u', alias: 'u',
default: false, default: false,
description: 'Updates only previously created index files (recursively).', description: 'Updates only previously created index files (recursively).',
type: 'boolean' type: 'boolean',
} },
}) })
.options({ .options({
banner: { banner: {
description: 'Add a custom banner at the top of the index file', description: 'Add a custom banner at the top of the index file',
type: 'string' type: 'string',
} },
}) })
.options({ .options({
extensions: { extensions: {
alias: 'x', alias: 'x',
default: ['js'], default: ['js'],
description: 'Allows some extensions to be parsed as valid source. First extension will always be preferred to homonyms with another allowed extension.', 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',
} },
}) })
.example('create-index ./src ./src/utilities', 'Creates or updates an existing create-index index file in the target (./src, ./src/utilities) directories.') .options({
.example('create-index --update ./src ./tests', 'Finds all create-index index files in the target directories and descending directories. Updates found index files.') outputFile: {
.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.') alias: 'o',
default: 'index.js',
description: 'Output 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 --update ./src ./tests',
'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.',
)
.argv; .argv;
writeIndexCli(argv._, { writeIndexCli(argv._, {
banner: argv.banner, banner: argv.banner,
extensions: argv.extensions, extensions: argv.extensions,
ignoreDirectories: argv.ignoreDirectories,
ignoreUnsafe: argv.ignoreUnsafe, ignoreUnsafe: argv.ignoreUnsafe,
outputFile: argv.outputFile,
recursive: argv.recursive, recursive: argv.recursive,
updateIndex: argv.update updateIndex: argv.update,
}); });
+1 -1
View File
@@ -1,4 +1,4 @@
export { export {
findIndexFiles, findIndexFiles,
writeIndex writeIndex,
} from './utilities'; } from './utilities';
-1
View File
@@ -1,2 +1 @@
// eslint-disable-next-line
export const CREATE_INDEX_PATTERN = /(?:^|[\n\r]+)\/\/ @create-index\s?({.*})?[\n\r]+/; export const CREATE_INDEX_PATTERN = /(?:^|[\n\r]+)\/\/ @create-index\s?({.*})?[\n\r]+/;
+15 -1
View File
@@ -14,7 +14,21 @@ const buildExportBlock = (files) => {
let importBlock; let importBlock;
importBlock = _.map(files, (fileName) => { importBlock = _.map(files, (fileName) => {
return 'export { default as ' + safeVariableName(fileName) + ' } from \'./' + fileName + '\';'; if (fileName.indexOf(".") == -1)
return (
"export * as " +
safeVariableName(fileName) +
" from './" +
fileName +
"';"
);
return (
"export { default as " +
safeVariableName(fileName) +
" } from './" +
fileName +
"';"
);
}); });
importBlock = importBlock.join('\n'); importBlock = importBlock.join('\n');
+4 -2
View File
@@ -4,7 +4,8 @@ import glob from 'glob';
import validateTargetDirectory from './validateTargetDirectory'; import validateTargetDirectory from './validateTargetDirectory';
export default (directoryPath, options = {}) => { export default (directoryPath, options = {}) => {
let fileName, targetDirectories; let fileName;
let targetDirectories;
fileName = options.fileName || 'index.js'; fileName = options.fileName || 'index.js';
fileName = './**/' + fileName; fileName = './**/' + fileName;
@@ -13,7 +14,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 outputFile: options.fileName,
silent: options.silent,
}); });
}); });
+3 -3
View File
@@ -1,14 +1,14 @@
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);
return true; return true;
} catch (error) { } catch {
return false; return false;
} }
}; };
+8 -8
View File
@@ -1,10 +1,10 @@
// @create-index // @create-index
export createIndexCode from './createIndexCode.js'; export createIndexCode from './createIndexCode';
export findIndexFiles from './findIndexFiles.js'; export findIndexFiles from './findIndexFiles';
export log from './log.js'; export log from './log';
export readDirectory from './readDirectory.js'; export readDirectory from './readDirectory';
export sortByDepth from './sortByDepth.js'; export sortByDepth from './sortByDepth';
export validateTargetDirectory from './validateTargetDirectory.js'; export validateTargetDirectory from './validateTargetDirectory';
export writeIndex from './writeIndex.js'; export writeIndex from './writeIndex';
export writeIndexCli from './writeIndexCli.js'; export writeIndexCli from './writeIndexCli';
+1 -1
View File
@@ -2,6 +2,6 @@ import chalk from 'chalk';
import moment from 'moment'; import moment from 'moment';
export default (...append) => { export default (...append) => {
// eslint-disable-next-line // eslint-disable-next-line no-console
console.log(chalk.dim('[' + moment().format('HH:mm:ss') + ']'), ...append); console.log(chalk.dim('[' + moment().format('HH:mm:ss') + ']'), ...append);
}; };
+9 -8
View File
@@ -17,7 +17,7 @@ const hasMultipleExtensions = (fileName) => {
}; };
const isSafeName = (fileName) => { const isSafeName = (fileName) => {
return /^[a-z][a-z0-9._]+$/i.test(fileName); return /^[_a-z][\w.]*$/i.test(fileName);
}; };
const stripExtension = (fileName) => { const stripExtension = (fileName) => {
@@ -27,7 +27,7 @@ const stripExtension = (fileName) => {
return fileName; return fileName;
} }
return fileName.substr(0, pos); return fileName.slice(0, Math.max(0, pos));
}; };
const removeDuplicates = (files, preferredExtension) => { const removeDuplicates = (files, preferredExtension) => {
@@ -72,13 +72,14 @@ 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;
} }
const { const {
extensions = ['js'], extensions = ['js'],
config = {} config = {},
ignoreDirectories = false,
} = options; } = options;
let children; let children;
@@ -101,17 +102,17 @@ export default (directoryPath, options = {}) => {
return false; return false;
} }
if (_.startsWith(fileName, 'index.js')) { if (_.startsWith(fileName, options.outputFile || 'index.js')) {
return false; return false;
} }
if (!isDirectory && !extensions.some((ext) => { if (!isDirectory && !extensions.some((extension) => {
return _.endsWith(fileName, '.' + ext); return _.endsWith(fileName, '.' + extension);
})) { })) {
return false; return false;
} }
if (isDirectory && !hasIndex(absolutePath)) { if (isDirectory && (!hasIndex(absolutePath, options) || ignoreDirectories)) {
return false; return false;
} }
+5 -5
View File
@@ -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() : '';
@@ -21,10 +21,10 @@ export default (directoryPath) => {
try { try {
config = JSON.parse(configLine); config = JSON.parse(configLine);
} catch (error) { } catch {
throw new Error( throw new Error(
'"' + indexPath + '" contains invalid configuration object.\n' + '"' + indexPath + '" contains invalid configuration object.\n' +
'Configuration object must be a valid JSON.' 'Configuration object must be a valid JSON.',
); );
} }
+3 -3
View File
@@ -8,7 +8,7 @@ export default (targetDirectory, options = {}) => {
try { try {
stats = fs.statSync(targetDirectory); stats = fs.statSync(targetDirectory);
} catch (error) { } catch {
if (silent) { if (silent) {
return false; return false;
} else { } else {
@@ -24,11 +24,11 @@ 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);
} catch (error) { } catch {
return true; return true;
} }
+4 -3
View File
@@ -10,15 +10,16 @@ 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, {outputFile: options.outputFile,
silent: options.ignoreUnsafe});
}); });
_.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, 'index.js'); const indexFilePath = path.resolve(directoryPath, options.outputFile || 'index.js');
fs.writeFileSync(indexFilePath, indexCode); fs.writeFileSync(indexFilePath, indexCode);
}); });
+13 -10
View File
@@ -16,6 +16,7 @@ export default (directoryPaths, options = {}) => {
sortedDirectoryPaths = sortByDepth(directoryPaths); sortedDirectoryPaths = sortByDepth(directoryPaths);
log('Target directories', sortedDirectoryPaths); log('Target directories', sortedDirectoryPaths);
log('Output file', options.outputFile);
if (options.updateIndex) { if (options.updateIndex) {
log('Update index:', options.updateIndex ? chalk.green('true') : chalk.red('false')); log('Update index:', options.updateIndex ? chalk.green('true') : chalk.red('false'));
} else { } else {
@@ -25,10 +26,10 @@ export default (directoryPaths, options = {}) => {
} }
if (options.updateIndex || options.recursive) { if (options.updateIndex || options.recursive) {
sortedDirectoryPaths = _.map(sortedDirectoryPaths, (dir) => { sortedDirectoryPaths = _.map(sortedDirectoryPaths, (directory) => {
return findIndexFiles(dir, { return findIndexFiles(directory, {
fileName: options.updateIndex ? 'index.js' : '*', fileName: options.updateIndex ? options.outputFile || 'index.js' : '*',
silent: options.updateIndex || options.ignoreUnsafe silent: options.updateIndex || options.ignoreUnsafe,
}); });
}); });
sortedDirectoryPaths = _.flatten(sortedDirectoryPaths); sortedDirectoryPaths = _.flatten(sortedDirectoryPaths);
@@ -39,32 +40,34 @@ export default (directoryPaths, options = {}) => {
} }
sortedDirectoryPaths = sortedDirectoryPaths.filter((directoryPath) => { sortedDirectoryPaths = sortedDirectoryPaths.filter((directoryPath) => {
return validateTargetDirectory(directoryPath, {silent: options.ignoreUnsafe}); return validateTargetDirectory(directoryPath, {outputFile: options.outputFile,
silent: options.ignoreUnsafe});
}); });
_.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,
extensions: options.extensions, extensions: options.extensions,
silent: options.ignoreUnsafe ignoreDirectories: options.ignoreDirectories,
silent: options.ignoreUnsafe,
}); });
const indexCode = createIndexCode(siblings, { const indexCode = createIndexCode(siblings, {
banner: options.banner, banner: options.banner,
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');
/* eslint-disable no-empty */ /* eslint-disable no-empty */
} catch (error) { } catch {
} }
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "canonical/mocha"
}
+2 -2
View File
@@ -1,7 +1,7 @@
/* eslint-disable no-restricted-syntax */ /* eslint-disable no-restricted-syntax */
import { import {
expect expect,
} from 'chai'; } from 'chai';
import createIndexCode from '../src/utilities/createIndexCode'; import createIndexCode from '../src/utilities/createIndexCode';
import codeExample from './codeExample'; import codeExample from './codeExample';
@@ -60,7 +60,7 @@ export { default as foo } from './foo';
context('with config', () => { context('with config', () => {
it('should append config', () => { it('should append config', () => {
const config = { const config = {
ignore: ['/^zoo/'] ignore: ['/^zoo/'],
}; };
const indexCode = createIndexCode(['foo', 'bar'], {config}); const indexCode = createIndexCode(['foo', 'bar'], {config});
+1 -1
View File
@@ -1,6 +1,6 @@
import path from 'path'; import path from 'path';
import { import {
expect expect,
} from 'chai'; } from 'chai';
import glob from 'glob'; import glob from 'glob';
import findIndexFiles from '../src/utilities/findIndexFiles'; import findIndexFiles from '../src/utilities/findIndexFiles';
@@ -0,0 +1 @@
// @create-index
@@ -0,0 +1 @@
// @create-index
@@ -0,0 +1 @@
// @create-index
@@ -0,0 +1 @@
// @create-index
+18 -5
View File
@@ -1,6 +1,6 @@
import path from 'path'; import path from 'path';
import { import {
expect expect,
} from 'chai'; } from 'chai';
import readDirectory from '../src/utilities/readDirectory'; import readDirectory from '../src/utilities/readDirectory';
@@ -21,6 +21,13 @@ describe('readDirectory()', () => {
expect(names).to.deep.equal(['present.js']); expect(names).to.deep.equal(['present.js']);
}); });
}); });
context('target directory contains child directories (short safe name)', () => {
it('gets names of the children directories', () => {
const names = readDirectory(path.resolve(fixturesPath, 'children-directories-short-name'));
expect(names).to.deep.equal(['F', 'T', '__', 'o']);
});
});
context('target directory contains child directories (unsafe name)', () => { context('target directory contains child directories (unsafe name)', () => {
it('gets names of the children directories', () => { it('gets names of the children directories', () => {
const names = readDirectory(path.resolve(fixturesPath, 'children-directories-unsafe-name')); const names = readDirectory(path.resolve(fixturesPath, 'children-directories-unsafe-name'));
@@ -34,6 +41,12 @@ describe('readDirectory()', () => {
expect(names).to.deep.equal(['bar', 'foo']); expect(names).to.deep.equal(['bar', 'foo']);
}); });
it('excludes directories if ignoreDirectories = true', () => {
const names = readDirectory(path.resolve(fixturesPath, 'children-index'), {ignoreDirectories: true});
expect(names).to.deep.equal([]);
});
}); });
context('target directory contains files', () => { context('target directory contains files', () => {
it('refers to the files (with extension)', () => { it('refers to the files (with extension)', () => {
@@ -58,7 +71,7 @@ describe('readDirectory()', () => {
}); });
context('target directory contains non js files, and allowing only jsx', () => { context('target directory contains non js files, and allowing only jsx', () => {
it('prefers file', () => { it('prefers file', () => {
const options = { extensions: ['jsx'] }; const options = {extensions: ['jsx']};
const names = readDirectory(path.resolve(fixturesPath, 'children-files-alt-extension'), options); const names = readDirectory(path.resolve(fixturesPath, 'children-files-alt-extension'), options);
expect(names).to.deep.equal(['bar.jsx']); expect(names).to.deep.equal(['bar.jsx']);
@@ -66,7 +79,7 @@ describe('readDirectory()', () => {
}); });
context('target directory contains non js files, and allowing both js and jsx', () => { context('target directory contains non js files, and allowing both js and jsx', () => {
it('prefers file', () => { it('prefers file', () => {
const options = { extensions: ['js', 'jsx'] }; const options = {extensions: ['js', 'jsx']};
const names = readDirectory(path.resolve(fixturesPath, 'children-files-alt-extension'), options); const names = readDirectory(path.resolve(fixturesPath, 'children-files-alt-extension'), options);
expect(names).to.deep.equal(['bar.jsx', 'present.js']); expect(names).to.deep.equal(['bar.jsx', 'present.js']);
@@ -74,7 +87,7 @@ describe('readDirectory()', () => {
}); });
context('target directory contains homonyms files, and allowing both js and jsx, will prefer JS as it is first extension listed', () => { context('target directory contains homonyms files, and allowing both js and jsx, will prefer JS as it is first extension listed', () => {
it('prefers file', () => { it('prefers file', () => {
const options = { extensions: ['js', 'jsx'] }; const options = {extensions: ['js', 'jsx']};
const names = readDirectory(path.resolve(fixturesPath, 'children-files-alt-extension-with-homonyms'), options); const names = readDirectory(path.resolve(fixturesPath, 'children-files-alt-extension-with-homonyms'), options);
expect(names).to.deep.equal(['bar.js', 'present.js']); expect(names).to.deep.equal(['bar.js', 'present.js']);
@@ -82,7 +95,7 @@ describe('readDirectory()', () => {
}); });
context('target directory contains homonyms files, and allowing both js and jsx, will prefer JSX as it is first extension listed', () => { context('target directory contains homonyms files, and allowing both js and jsx, will prefer JSX as it is first extension listed', () => {
it('prefers file', () => { it('prefers file', () => {
const options = { extensions: ['jsx', 'js'] }; const options = {extensions: ['jsx', 'js']};
const names = readDirectory(path.resolve(fixturesPath, 'children-files-alt-extension-with-homonyms'), options); const names = readDirectory(path.resolve(fixturesPath, 'children-files-alt-extension-with-homonyms'), options);
expect(names).to.deep.equal(['bar.jsx', 'present.js']); expect(names).to.deep.equal(['bar.jsx', 'present.js']);
+4 -4
View File
@@ -1,6 +1,6 @@
import path from 'path'; import path from 'path';
import { import {
expect expect,
} from 'chai'; } from 'chai';
import readIndexConfig from '../src/utilities/readIndexConfig'; import readIndexConfig from '../src/utilities/readIndexConfig';
@@ -8,15 +8,15 @@ const fixtures = {
noIndex: path.resolve(__dirname, 'fixtures/read-index-config/no-index'), noIndex: path.resolve(__dirname, 'fixtures/read-index-config/no-index'),
withConfig: path.resolve(__dirname, 'fixtures/read-index-config/with-config'), withConfig: path.resolve(__dirname, 'fixtures/read-index-config/with-config'),
withInvalidConfig: path.resolve(__dirname, 'fixtures/read-index-config/with-invalid-config'), withInvalidConfig: path.resolve(__dirname, 'fixtures/read-index-config/with-invalid-config'),
withoutConfig: path.resolve(__dirname, 'fixtures/read-index-config/without-config') withoutConfig: path.resolve(__dirname, 'fixtures/read-index-config/without-config'),
}; };
const expectedValues = { const expectedValues = {
noIndex: {}, noIndex: {},
withConfig: { withConfig: {
ignore: ['/foo.js$/'] ignore: ['/foo.js$/'],
}, },
withoutConfig: {} withoutConfig: {},
}; };
describe('readIndexConfig()', () => { describe('readIndexConfig()', () => {
+3 -3
View File
@@ -1,7 +1,7 @@
import { import {
expect expect,
} from 'chai'; } from 'chai';
import sortByDepth from './../src/utilities/sortByDepth'; import sortByDepth from '../src/utilities/sortByDepth';
describe('sortByDepth()', () => { describe('sortByDepth()', () => {
it('sorts from deepest to the most shallow', () => { it('sorts from deepest to the most shallow', () => {
@@ -9,7 +9,7 @@ describe('sortByDepth()', () => {
'/b', '/b',
'/a', '/a',
'/a/b/c', '/a/b/c',
'/a/b' '/a/b',
]; ];
const sortedPaths = sortByDepth(paths); const sortedPaths = sortByDepth(paths);
+1 -1
View File
@@ -2,7 +2,7 @@
import path from 'path'; import path from 'path';
import { import {
expect expect,
} from 'chai'; } from 'chai';
import validateTargetDirectory from '../src/utilities/validateTargetDirectory'; import validateTargetDirectory from '../src/utilities/validateTargetDirectory';
+2 -2
View File
@@ -3,7 +3,7 @@
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import { import {
expect expect,
} from 'chai'; } from 'chai';
import writeIndex from '../src/utilities/writeIndex'; import writeIndex from '../src/utilities/writeIndex';
import codeExample from './codeExample'; import codeExample from './codeExample';
@@ -40,7 +40,7 @@ export { default as foo } from './foo.js';
it('creates index with config in target directory', () => { it('creates index with config in target directory', () => {
const indexFilePath = path.resolve(fixturesPath, 'with-config/index.js'); const indexFilePath = path.resolve(fixturesPath, 'with-config/index.js');
// eslint-disable-next-line // eslint-disable-next-line quotes
const ignoredExportLine = `export { default as bar } from './bar.js';`; const ignoredExportLine = `export { default as bar } from './bar.js';`;
appendToFile(indexFilePath, ignoredExportLine); appendToFile(indexFilePath, ignoredExportLine);