dit
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
coverage
|
||||
dist
|
||||
node_modules
|
||||
*.log
|
||||
.*
|
||||
|
||||
Vendored
+70
@@ -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
|
||||
Vendored
+1
@@ -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"}
|
||||
Vendored
+20
@@ -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
|
||||
Vendored
+1
@@ -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"}
|
||||
Vendored
+9
@@ -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
|
||||
Vendored
+1
@@ -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"}
|
||||
Vendored
+62
@@ -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
@@ -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"}
|
||||
Vendored
+36
@@ -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
|
||||
Vendored
+1
@@ -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"}
|
||||
Vendored
+29
@@ -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
|
||||
Vendored
+1
@@ -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"}
|
||||
Vendored
+72
@@ -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
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"index.js"}
|
||||
Vendored
+24
@@ -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
|
||||
Vendored
+1
@@ -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"}
|
||||
Vendored
+139
@@ -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
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
+48
@@ -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
@@ -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"}
|
||||
Vendored
+19
@@ -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
|
||||
Vendored
+1
@@ -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
@@ -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
|
||||
@@ -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"}
|
||||
Vendored
+50
@@ -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
|
||||
Vendored
+1
@@ -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"}
|
||||
Vendored
+105
@@ -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
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user