@uiwwsw/react-query-helper 1.2.1 → 1.2.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/README.md +3 -1
- package/dist/cli.js +37 -7
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -94,6 +94,7 @@ const config: AutoQueryConfig = {
|
|
|
94
94
|
outputDir: "./src/options", // 생성된 코드가 저장될 경로
|
|
95
95
|
ignoredFiles: ["domain.ts", "adaptor.ts"],
|
|
96
96
|
templateDir: "@uiwwsw/react-query-helper",
|
|
97
|
+
sourceImportAlias: "@/libs",
|
|
97
98
|
analyzer: {
|
|
98
99
|
exportFilter: "exported-only",
|
|
99
100
|
functionMatchMode: "all",
|
|
@@ -146,8 +147,9 @@ npm exec react-query-helper -- --generate
|
|
|
146
147
|
| --- | --- | --- |
|
|
147
148
|
| `sourceDir` | ✅ | API 함수가 포함된 TypeScript 디렉토리 (루트 기준 경로) |
|
|
148
149
|
| `outputDir` | ✅ | 생성된 훅과 옵션 파일이 저장될 디렉토리 |
|
|
149
|
-
| `ignoredFiles` | ❌ | 코드 생성에서 제외할
|
|
150
|
+
| `ignoredFiles` | ❌ | 코드 생성에서 제외할 파일/경로 패턴 배열 (`domain.ts`, `**/*.spec.ts`, `admin/internal/**`) |
|
|
150
151
|
| `templateDir` | ❌ | 생성된 코드에서 `queryOption` 계열을 import 할 모듈 경로 또는 상대 디렉토리 |
|
|
152
|
+
| `sourceImportAlias` | ❌ | API 함수 import를 상대경로 대신 alias로 생성할 때 사용할 prefix (`@/apis` 등) |
|
|
151
153
|
| `analyzer` | ❌ | 어떤 함수를 읽을지 필터링하는 설정 (`exported-only`, `async-only`, include/exclude 등) |
|
|
152
154
|
| `template` | ❌ | 어떤 아티팩트를 생성할지와 이름 규칙을 제어하는 설정 |
|
|
153
155
|
|
package/dist/cli.js
CHANGED
|
@@ -1821,6 +1821,7 @@ const config: AutoQueryConfig = {
|
|
|
1821
1821
|
outputDir: "./src/options",
|
|
1822
1822
|
ignoredFiles: ["domain.ts", "adaptor.ts"],
|
|
1823
1823
|
templateDir: "@uiwwsw/react-query-helper",
|
|
1824
|
+
sourceImportAlias: "@/libs",
|
|
1824
1825
|
analyzer: {
|
|
1825
1826
|
exportFilter: "exported-only",
|
|
1826
1827
|
functionMatchMode: "all",
|
|
@@ -1869,6 +1870,26 @@ function shouldProcess(filePath) {
|
|
|
1869
1870
|
const extension = extname3(filePath).toLowerCase();
|
|
1870
1871
|
return extension === ".ts" || extension === ".tsx";
|
|
1871
1872
|
}
|
|
1873
|
+
function escapeRegExp(value) {
|
|
1874
|
+
return value.replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
|
|
1875
|
+
}
|
|
1876
|
+
function globToRegExp(pattern) {
|
|
1877
|
+
const normalized = normalizeModulePath(pattern);
|
|
1878
|
+
const placeholder = "__DOUBLE_STAR__";
|
|
1879
|
+
const escaped = escapeRegExp(normalized).replace(/\*\*/g, placeholder).replace(/\*/g, "[^/]*").replace(new RegExp(placeholder, "g"), ".*");
|
|
1880
|
+
return new RegExp(`^${escaped}$`);
|
|
1881
|
+
}
|
|
1882
|
+
function isIgnoredFile(filePath) {
|
|
1883
|
+
const relativePath = normalizeModulePath(relative3(config.resolvedSourceDir, filePath));
|
|
1884
|
+
const fileName = basename3(filePath);
|
|
1885
|
+
return config.ignoredFiles?.some((pattern) => {
|
|
1886
|
+
const normalizedPattern = normalizeModulePath(pattern);
|
|
1887
|
+
if (!normalizedPattern.includes("/") && !normalizedPattern.includes("*")) {
|
|
1888
|
+
return fileName === normalizedPattern;
|
|
1889
|
+
}
|
|
1890
|
+
return globToRegExp(normalizedPattern).test(relativePath);
|
|
1891
|
+
}) ?? false;
|
|
1892
|
+
}
|
|
1872
1893
|
function printUsage() {
|
|
1873
1894
|
console.log("Usage: react-query-helper [init | generate | watch | help]");
|
|
1874
1895
|
console.log(" react-query-helper [--init | --generate | --watch | --help]");
|
|
@@ -1936,6 +1957,15 @@ async function renderOptionsCode(params) {
|
|
|
1936
1957
|
template: config.template
|
|
1937
1958
|
});
|
|
1938
1959
|
}
|
|
1960
|
+
function resolveSourceImportPath(filePath, outputFile) {
|
|
1961
|
+
const sourceModulePath = filePath.replace(new RegExp(`${extname3(filePath)}$`), "");
|
|
1962
|
+
const relativeSourcePath = normalizeModulePath(relative3(config.resolvedSourceDir, sourceModulePath));
|
|
1963
|
+
if (config.sourceImportAlias) {
|
|
1964
|
+
const aliasBase = config.sourceImportAlias.replace(/\/$/, "");
|
|
1965
|
+
return relativeSourcePath ? `${aliasBase}/${relativeSourcePath}` : aliasBase;
|
|
1966
|
+
}
|
|
1967
|
+
return normalizeModulePath(relative3(dirname4(outputFile), sourceModulePath) || ".", true);
|
|
1968
|
+
}
|
|
1939
1969
|
async function processFile(filePath) {
|
|
1940
1970
|
if (!shouldProcess(filePath)) {
|
|
1941
1971
|
return;
|
|
@@ -1949,7 +1979,7 @@ async function processFile(filePath) {
|
|
|
1949
1979
|
}
|
|
1950
1980
|
const relativeDir = dirname4(relativePath);
|
|
1951
1981
|
const fileName = basename3(filePath, extname3(filePath));
|
|
1952
|
-
if (
|
|
1982
|
+
if (isIgnoredFile(filePath)) {
|
|
1953
1983
|
console.log(`Skipping ignored file: ${filePath}`);
|
|
1954
1984
|
return;
|
|
1955
1985
|
}
|
|
@@ -1963,7 +1993,7 @@ async function processFile(filePath) {
|
|
|
1963
1993
|
const outputFile = join4(outputFolder, `${fileName}Options.ts`);
|
|
1964
1994
|
const generatedCode = await renderOptionsCode({
|
|
1965
1995
|
functionInfos,
|
|
1966
|
-
importPath:
|
|
1996
|
+
importPath: resolveSourceImportPath(filePath, outputFile),
|
|
1967
1997
|
keySegments: relativeDir === "." ? [fileName] : relativeDir.split(sep).filter(Boolean),
|
|
1968
1998
|
fileName,
|
|
1969
1999
|
templateImportPath: config.resolvedTemplateDir && config.templateDir?.startsWith(".") ? normalizeModulePath(relative3(dirname4(outputFile), config.resolvedTemplateDir) || ".", true) : config.resolvedTemplateDir ?? "@uiwwsw/react-query-helper"
|
|
@@ -1995,7 +2025,7 @@ async function runGenerate() {
|
|
|
1995
2025
|
const files = await new Promise((resolve5, reject) => {
|
|
1996
2026
|
const results = [];
|
|
1997
2027
|
const watcher = watch(sourcePath, {
|
|
1998
|
-
ignored:
|
|
2028
|
+
ignored: (watchedPath) => isIgnoredFile(String(watchedPath)),
|
|
1999
2029
|
ignoreInitial: false,
|
|
2000
2030
|
depth: 99
|
|
2001
2031
|
}).on("add", (path) => results.push(path)).on("ready", () => {
|
|
@@ -2024,23 +2054,23 @@ async function runWatch() {
|
|
|
2024
2054
|
ensureDirectory(outputRootPath);
|
|
2025
2055
|
console.log(`\uD83D\uDCC1 Ensured output directory exists at ${outputRootPath}`);
|
|
2026
2056
|
watch(sourcePath, {
|
|
2027
|
-
ignored:
|
|
2057
|
+
ignored: (watchedPath) => isIgnoredFile(String(watchedPath)),
|
|
2028
2058
|
ignoreInitial: false,
|
|
2029
2059
|
depth: 99
|
|
2030
2060
|
}).on("add", async (filePath) => {
|
|
2031
|
-
if (!shouldProcess(filePath)) {
|
|
2061
|
+
if (!shouldProcess(filePath) || isIgnoredFile(filePath)) {
|
|
2032
2062
|
return;
|
|
2033
2063
|
}
|
|
2034
2064
|
console.log(`\uD83D\uDCC4 File added: ${filePath}`);
|
|
2035
2065
|
await processFile(filePath);
|
|
2036
2066
|
}).on("change", async (filePath) => {
|
|
2037
|
-
if (!shouldProcess(filePath)) {
|
|
2067
|
+
if (!shouldProcess(filePath) || isIgnoredFile(filePath)) {
|
|
2038
2068
|
return;
|
|
2039
2069
|
}
|
|
2040
2070
|
console.log(`\uD83D\uDD04 File changed: ${filePath}`);
|
|
2041
2071
|
await processFile(filePath);
|
|
2042
2072
|
}).on("unlink", async (filePath) => {
|
|
2043
|
-
if (!shouldProcess(filePath)) {
|
|
2073
|
+
if (!shouldProcess(filePath) || isIgnoredFile(filePath)) {
|
|
2044
2074
|
return;
|
|
2045
2075
|
}
|
|
2046
2076
|
console.log(`\uD83D\uDDD1️ File unlinked: ${filePath}`);
|
package/dist/config.d.ts
CHANGED
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAOA,qBAAa,eAAgB,SAAQ,KAAK;aAGtB,UAAU,CAAC,EAAE,MAAM;aACnB,KAAK,CAAC,EAAE,OAAO;gBAF/B,OAAO,EAAE,MAAM,EACC,UAAU,CAAC,EAAE,MAAM,YAAA,EACnB,KAAK,CAAC,EAAE,OAAO,YAAA;CAKlC;AAED,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,uBAAuB,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CAChG;AAED,MAAM,WAAW,oBAAoB;IACnC,mBAAmB,EAAE,CAAC,MAAM,EAAE;QAC5B,aAAa,EAAE,OAAO,EAAE,CAAC;QACzB,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,QAAQ,EAAE,MAAM,CAAC;QACjB,kBAAkB,EA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