barrelize 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +26 -18
- package/lib/src/config/config.d.ts +3 -3
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -591,7 +591,7 @@ class CAC extends EventEmitter {
|
|
|
591
591
|
}
|
|
592
592
|
const cac = (name2 = "") => new CAC(name2);
|
|
593
593
|
const name = "barrelize";
|
|
594
|
-
const version = "1.1.
|
|
594
|
+
const version = "1.1.2";
|
|
595
595
|
function cliInit() {
|
|
596
596
|
const cli = cac(name);
|
|
597
597
|
cli.command("[config path]", `Generate 'index.ts' files for all directories`).action(async (config) => {
|
|
@@ -905,11 +905,14 @@ async function runInitCommand(baseConfigFilePath) {
|
|
|
905
905
|
}
|
|
906
906
|
const configTemplateJson = JSON.stringify(configTemplate, null, 2);
|
|
907
907
|
await writeFile(configFilePath, configTemplateJson);
|
|
908
|
-
console.log(
|
|
908
|
+
console.log(
|
|
909
|
+
colorize(baseConfigFilePath, TerminalColor.CYAN),
|
|
910
|
+
colorize(`config file created`, TerminalColor.GRAY)
|
|
911
|
+
);
|
|
909
912
|
console.log(colorize(configTemplateJson, TerminalColor.GREEN));
|
|
910
913
|
}
|
|
911
914
|
const validateConfig = (() => {
|
|
912
|
-
const _io0 = (input, _exceptionable = true) => Array.isArray(input.directories) && input.directories.every((elem, _index1) => "object" === typeof elem && null !== elem && _io1(elem, _exceptionable)) && (1 === Object.keys(input).length || Object.keys(input).every((key2) => {
|
|
915
|
+
const _io0 = (input, _exceptionable = true) => Array.isArray(input.directories) && input.directories.every((elem, _index1) => "object" === typeof elem && null !== elem && false === Array.isArray(elem) && _io1(elem, _exceptionable)) && (1 === Object.keys(input).length || Object.keys(input).every((key2) => {
|
|
913
916
|
if (["directories"].some((prop) => key2 === prop))
|
|
914
917
|
return true;
|
|
915
918
|
const value = input[key2];
|
|
@@ -917,7 +920,7 @@ const validateConfig = (() => {
|
|
|
917
920
|
return true;
|
|
918
921
|
return false;
|
|
919
922
|
}));
|
|
920
|
-
const _io1 = (input, _exceptionable = true) => "string" === typeof input.path && (Array.isArray(input.include) && input.include.every((elem, _index2) => "string" === typeof elem)) && (Array.isArray(input.exclude) && input.exclude.every((elem, _index3) => "string" === typeof elem)) && (void 0 === input.order || Array.isArray(input.order) && input.order.every((elem, _index4) => "string" === typeof elem)) && (void 0 === input.indexFilePath || "string" === typeof input.indexFilePath) && (void 0 === input.keepFileExtension || "boolean" === typeof input.keepFileExtension) && (void 0 === input.replace || Array.isArray(input.replace) && input.replace.every((elem, _index5) => "object" === typeof elem && null !== elem && _io2(elem, _exceptionable))) && (
|
|
923
|
+
const _io1 = (input, _exceptionable = true) => (void 0 === input.path || "string" === typeof input.path) && (void 0 === input.include || Array.isArray(input.include) && input.include.every((elem, _index2) => "string" === typeof elem)) && (void 0 === input.exclude || Array.isArray(input.exclude) && input.exclude.every((elem, _index3) => "string" === typeof elem)) && (void 0 === input.order || Array.isArray(input.order) && input.order.every((elem, _index4) => "string" === typeof elem)) && (void 0 === input.indexFilePath || "string" === typeof input.indexFilePath) && (void 0 === input.keepFileExtension || "boolean" === typeof input.keepFileExtension) && (void 0 === input.replace || Array.isArray(input.replace) && input.replace.every((elem, _index5) => "object" === typeof elem && null !== elem && _io2(elem, _exceptionable))) && (0 === Object.keys(input).length || Object.keys(input).every((key2) => {
|
|
921
924
|
if (["path", "include", "exclude", "order", "indexFilePath", "keepFileExtension", "replace"].some((prop) => key2 === prop))
|
|
922
925
|
return true;
|
|
923
926
|
const value = input[key2];
|
|
@@ -937,7 +940,7 @@ const validateConfig = (() => {
|
|
|
937
940
|
path: _path + ".directories",
|
|
938
941
|
expected: "Array<__type>",
|
|
939
942
|
value: input.directories
|
|
940
|
-
})) && input.directories.map((elem, _index6) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
|
|
943
|
+
})) && input.directories.map((elem, _index6) => ("object" === typeof elem && null !== elem && false === Array.isArray(elem) || _report(_exceptionable, {
|
|
941
944
|
path: _path + ".directories[" + _index6 + "]",
|
|
942
945
|
expected: "__type",
|
|
943
946
|
value: elem
|
|
@@ -961,13 +964,13 @@ const validateConfig = (() => {
|
|
|
961
964
|
value
|
|
962
965
|
});
|
|
963
966
|
}).every((flag) => flag))].every((flag) => flag);
|
|
964
|
-
const _vo1 = (input, _path, _exceptionable = true) => ["string" === typeof input.path || _report(_exceptionable, {
|
|
967
|
+
const _vo1 = (input, _path, _exceptionable = true) => [void 0 === input.path || "string" === typeof input.path || _report(_exceptionable, {
|
|
965
968
|
path: _path + ".path",
|
|
966
|
-
expected: "string",
|
|
969
|
+
expected: "(string | undefined)",
|
|
967
970
|
value: input.path
|
|
968
|
-
}), (Array.isArray(input.include) || _report(_exceptionable, {
|
|
971
|
+
}), void 0 === input.include || (Array.isArray(input.include) || _report(_exceptionable, {
|
|
969
972
|
path: _path + ".include",
|
|
970
|
-
expected: "Array<string>",
|
|
973
|
+
expected: "(Array<string> | undefined)",
|
|
971
974
|
value: input.include
|
|
972
975
|
})) && input.include.map((elem, _index7) => "string" === typeof elem || _report(_exceptionable, {
|
|
973
976
|
path: _path + ".include[" + _index7 + "]",
|
|
@@ -975,11 +978,11 @@ const validateConfig = (() => {
|
|
|
975
978
|
value: elem
|
|
976
979
|
})).every((flag) => flag) || _report(_exceptionable, {
|
|
977
980
|
path: _path + ".include",
|
|
978
|
-
expected: "Array<string>",
|
|
981
|
+
expected: "(Array<string> | undefined)",
|
|
979
982
|
value: input.include
|
|
980
|
-
}), (Array.isArray(input.exclude) || _report(_exceptionable, {
|
|
983
|
+
}), void 0 === input.exclude || (Array.isArray(input.exclude) || _report(_exceptionable, {
|
|
981
984
|
path: _path + ".exclude",
|
|
982
|
-
expected: "Array<string>",
|
|
985
|
+
expected: "(Array<string> | undefined)",
|
|
983
986
|
value: input.exclude
|
|
984
987
|
})) && input.exclude.map((elem, _index8) => "string" === typeof elem || _report(_exceptionable, {
|
|
985
988
|
path: _path + ".exclude[" + _index8 + "]",
|
|
@@ -987,7 +990,7 @@ const validateConfig = (() => {
|
|
|
987
990
|
value: elem
|
|
988
991
|
})).every((flag) => flag) || _report(_exceptionable, {
|
|
989
992
|
path: _path + ".exclude",
|
|
990
|
-
expected: "Array<string>",
|
|
993
|
+
expected: "(Array<string> | undefined)",
|
|
991
994
|
value: input.exclude
|
|
992
995
|
}), void 0 === input.order || (Array.isArray(input.order) || _report(_exceptionable, {
|
|
993
996
|
path: _path + ".order",
|
|
@@ -1025,7 +1028,7 @@ const validateConfig = (() => {
|
|
|
1025
1028
|
path: _path + ".replace",
|
|
1026
1029
|
expected: "(Array<__type>.o1 | undefined)",
|
|
1027
1030
|
value: input.replace
|
|
1028
|
-
}),
|
|
1031
|
+
}), 0 === Object.keys(input).length || (false === _exceptionable || Object.keys(input).map((key2) => {
|
|
1029
1032
|
if (["path", "include", "exclude", "order", "indexFilePath", "keepFileExtension", "replace"].some((prop) => key2 === prop))
|
|
1030
1033
|
return true;
|
|
1031
1034
|
const value = input[key2];
|
|
@@ -8864,7 +8867,7 @@ const DEFAULT_INDEX_FILE_PATH = "index.ts";
|
|
|
8864
8867
|
async function generateBarrels(rootPath, config) {
|
|
8865
8868
|
for (const directoryConfig of config.directories) {
|
|
8866
8869
|
const indexFileBasePath = directoryConfig.indexFilePath ?? DEFAULT_INDEX_FILE_PATH;
|
|
8867
|
-
const indexFileRelativePath = join(directoryConfig.path, indexFileBasePath);
|
|
8870
|
+
const indexFileRelativePath = join(directoryConfig.path ?? "", indexFileBasePath);
|
|
8868
8871
|
const indexFileAbsolutePath = resolve(rootPath, indexFileRelativePath);
|
|
8869
8872
|
const indexDirectory = dirname(indexFileAbsolutePath);
|
|
8870
8873
|
if (!existsSync(indexDirectory)) {
|
|
@@ -8882,9 +8885,14 @@ async function generateBarrels(rootPath, config) {
|
|
|
8882
8885
|
}
|
|
8883
8886
|
}
|
|
8884
8887
|
async function generateBarrel(rootPath, directoryConfig) {
|
|
8885
|
-
const ignore = [...directoryConfig.exclude, "**/index.ts", "**/index.js"];
|
|
8886
|
-
const cwd = resolve(rootPath, directoryConfig.path);
|
|
8887
|
-
let files = await glob(directoryConfig.include
|
|
8888
|
+
const ignore = [...directoryConfig.exclude ?? [], "**/index.ts", "**/index.js"];
|
|
8889
|
+
const cwd = resolve(rootPath, directoryConfig.path ?? "");
|
|
8890
|
+
let files = await glob(directoryConfig.include ?? "**/*", {
|
|
8891
|
+
cwd,
|
|
8892
|
+
ignore,
|
|
8893
|
+
nodir: true,
|
|
8894
|
+
includeChildMatches: true
|
|
8895
|
+
});
|
|
8888
8896
|
files = files.map((file) => file.replace(/\\/g, "/"));
|
|
8889
8897
|
files = handleFileExtension(directoryConfig, files);
|
|
8890
8898
|
files = handleOrder(directoryConfig, files);
|