@uiwwsw/react-query-helper 1.0.10 → 1.0.11
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/dist/cli.js +31 -16
- package/dist/config.d.ts +8 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/index.js +18 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1576,7 +1576,7 @@ import {
|
|
|
1576
1576
|
extname as extname3,
|
|
1577
1577
|
join as join4,
|
|
1578
1578
|
relative as relative3,
|
|
1579
|
-
resolve as
|
|
1579
|
+
resolve as resolve4,
|
|
1580
1580
|
sep
|
|
1581
1581
|
} from "path";
|
|
1582
1582
|
import { writeFileSync, existsSync as existsSync2, mkdirSync, unlinkSync } from "fs";
|
|
@@ -1648,7 +1648,7 @@ function generateOptionsCode(functionInfos, importPath, { keySegments, templateI
|
|
|
1648
1648
|
import { existsSync } from "fs";
|
|
1649
1649
|
import { readFile, unlink, writeFile } from "fs/promises";
|
|
1650
1650
|
import { randomUUID } from "crypto";
|
|
1651
|
-
import { dirname as dirname3, extname as extname2, join as join3 } from "path";
|
|
1651
|
+
import { dirname as dirname3, extname as extname2, join as join3, resolve as resolve3 } from "path";
|
|
1652
1652
|
import { pathToFileURL } from "url";
|
|
1653
1653
|
import ts2 from "typescript";
|
|
1654
1654
|
|
|
@@ -1721,9 +1721,24 @@ async function loadConfig() {
|
|
|
1721
1721
|
...defaultConfig,
|
|
1722
1722
|
...userConfig
|
|
1723
1723
|
};
|
|
1724
|
-
|
|
1724
|
+
const configDir2 = dirname3(configPath);
|
|
1725
|
+
return {
|
|
1726
|
+
...mergedConfig,
|
|
1727
|
+
configPath,
|
|
1728
|
+
configDir: configDir2,
|
|
1729
|
+
resolvedSourceDir: resolve3(configDir2, mergedConfig.sourceDir),
|
|
1730
|
+
resolvedOutputDir: resolve3(configDir2, mergedConfig.outputDir),
|
|
1731
|
+
resolvedTemplateDir: mergedConfig.templateDir && mergedConfig.templateDir.startsWith(".") ? resolve3(configDir2, mergedConfig.templateDir) : mergedConfig.templateDir
|
|
1732
|
+
};
|
|
1725
1733
|
}
|
|
1726
|
-
|
|
1734
|
+
const configDir = process.cwd();
|
|
1735
|
+
return {
|
|
1736
|
+
...defaultConfig,
|
|
1737
|
+
configDir,
|
|
1738
|
+
resolvedSourceDir: resolve3(configDir, defaultConfig.sourceDir),
|
|
1739
|
+
resolvedOutputDir: resolve3(configDir, defaultConfig.outputDir),
|
|
1740
|
+
resolvedTemplateDir: defaultConfig.templateDir
|
|
1741
|
+
};
|
|
1727
1742
|
}
|
|
1728
1743
|
|
|
1729
1744
|
// src/cli.ts
|
|
@@ -1773,7 +1788,7 @@ function runInit() {
|
|
|
1773
1788
|
console.log(`Config already exists at ${existingConfigPath}`);
|
|
1774
1789
|
return;
|
|
1775
1790
|
}
|
|
1776
|
-
const configPath =
|
|
1791
|
+
const configPath = resolve4(process.cwd(), DEFAULT_CONFIG_FILE_NAME);
|
|
1777
1792
|
writeFileSync(configPath, DEFAULT_CONFIG_TEMPLATE, "utf8");
|
|
1778
1793
|
console.log(`✅ Created ${configPath}`);
|
|
1779
1794
|
console.log("Next steps:");
|
|
@@ -1800,8 +1815,8 @@ async function processFile(filePath) {
|
|
|
1800
1815
|
if (!shouldProcess(filePath)) {
|
|
1801
1816
|
return;
|
|
1802
1817
|
}
|
|
1803
|
-
const sourceRoot =
|
|
1804
|
-
const outputRoot =
|
|
1818
|
+
const sourceRoot = config.resolvedSourceDir;
|
|
1819
|
+
const outputRoot = config.resolvedOutputDir;
|
|
1805
1820
|
const relativePath = relative3(sourceRoot, filePath);
|
|
1806
1821
|
if (relativePath.startsWith("..")) {
|
|
1807
1822
|
console.warn(`Skipping file outside of sourceDir: ${filePath}`);
|
|
@@ -1823,7 +1838,7 @@ async function processFile(filePath) {
|
|
|
1823
1838
|
const outputFile = join4(outputFolder, `${fileName}Options.ts`);
|
|
1824
1839
|
const generatedCode = generateOptionsCode(functionInfos, normalizeModulePath(relative3(dirname4(outputFile), filePath.replace(new RegExp(`${extname3(filePath)}$`), "")) || ".", true), {
|
|
1825
1840
|
keySegments: relativeDir === "." ? [fileName] : relativeDir.split(sep).filter(Boolean),
|
|
1826
|
-
templateImportPath: config.
|
|
1841
|
+
templateImportPath: config.resolvedTemplateDir && config.templateDir?.startsWith(".") ? normalizeModulePath(relative3(dirname4(outputFile), config.resolvedTemplateDir) || ".", true) : config.resolvedTemplateDir ?? "@uiwwsw/react-query-helper"
|
|
1827
1842
|
});
|
|
1828
1843
|
if (!existsSync2(outputFolder)) {
|
|
1829
1844
|
mkdirSync(outputFolder, { recursive: true });
|
|
@@ -1844,11 +1859,11 @@ async function runGenerate() {
|
|
|
1844
1859
|
return;
|
|
1845
1860
|
}
|
|
1846
1861
|
config = loadedConfig;
|
|
1847
|
-
const sourcePath =
|
|
1848
|
-
const outputRootPath =
|
|
1862
|
+
const sourcePath = config.resolvedSourceDir;
|
|
1863
|
+
const outputRootPath = config.resolvedOutputDir;
|
|
1849
1864
|
ensureDirectory(outputRootPath);
|
|
1850
1865
|
console.log(`\uD83D\uDCC1 Ensured output directory exists at ${outputRootPath}`);
|
|
1851
|
-
const files = await new Promise((
|
|
1866
|
+
const files = await new Promise((resolve5, reject) => {
|
|
1852
1867
|
const results = [];
|
|
1853
1868
|
const watcher = watch(sourcePath, {
|
|
1854
1869
|
ignored: config.ignoredFiles?.map((file) => join4(sourcePath, "**", file)) || [],
|
|
@@ -1856,7 +1871,7 @@ async function runGenerate() {
|
|
|
1856
1871
|
depth: 99
|
|
1857
1872
|
}).on("add", (path) => results.push(path)).on("ready", () => {
|
|
1858
1873
|
watcher.close();
|
|
1859
|
-
|
|
1874
|
+
resolve5(results);
|
|
1860
1875
|
}).on("error", (error) => {
|
|
1861
1876
|
watcher.close();
|
|
1862
1877
|
reject(error);
|
|
@@ -1874,8 +1889,8 @@ async function runWatch() {
|
|
|
1874
1889
|
return;
|
|
1875
1890
|
}
|
|
1876
1891
|
config = loadedConfig;
|
|
1877
|
-
const sourcePath =
|
|
1878
|
-
const outputRootPath =
|
|
1892
|
+
const sourcePath = config.resolvedSourceDir;
|
|
1893
|
+
const outputRootPath = config.resolvedOutputDir;
|
|
1879
1894
|
ensureDirectory(outputRootPath);
|
|
1880
1895
|
console.log(`\uD83D\uDCC1 Ensured output directory exists at ${outputRootPath}`);
|
|
1881
1896
|
watch(sourcePath, {
|
|
@@ -1899,8 +1914,8 @@ async function runWatch() {
|
|
|
1899
1914
|
return;
|
|
1900
1915
|
}
|
|
1901
1916
|
console.log(`\uD83D\uDDD1️ File unlinked: ${filePath}`);
|
|
1902
|
-
const sourceRoot =
|
|
1903
|
-
const outputRoot =
|
|
1917
|
+
const sourceRoot = config.resolvedSourceDir;
|
|
1918
|
+
const outputRoot = config.resolvedOutputDir;
|
|
1904
1919
|
const relativePath = relative3(sourceRoot, filePath);
|
|
1905
1920
|
if (relativePath.startsWith("..")) {
|
|
1906
1921
|
return;
|
package/dist/config.d.ts
CHANGED
|
@@ -9,6 +9,13 @@ export interface AutoQueryConfig {
|
|
|
9
9
|
templateDir?: string;
|
|
10
10
|
ignoredFiles?: string[];
|
|
11
11
|
}
|
|
12
|
+
export interface ResolvedAutoQueryConfig extends AutoQueryConfig {
|
|
13
|
+
configPath?: string;
|
|
14
|
+
configDir: string;
|
|
15
|
+
resolvedSourceDir: string;
|
|
16
|
+
resolvedOutputDir: string;
|
|
17
|
+
resolvedTemplateDir?: string;
|
|
18
|
+
}
|
|
12
19
|
export declare function resolveConfigPath(cwd?: string): string | undefined;
|
|
13
|
-
export declare function loadConfig(): Promise<
|
|
20
|
+
export declare function loadConfig(): Promise<ResolvedAutoQueryConfig>;
|
|
14
21
|
//# sourceMappingURL=config.d.ts.map
|
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;aAGt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@@ function generateOptionsCode(functionInfos, importPath, { keySegments, templateI
|
|
|
63
63
|
import { existsSync } from "fs";
|
|
64
64
|
import { readFile, unlink, writeFile } from "fs/promises";
|
|
65
65
|
import { randomUUID } from "crypto";
|
|
66
|
-
import { dirname, extname, join } from "path";
|
|
66
|
+
import { dirname, extname, join, resolve } from "path";
|
|
67
67
|
import { pathToFileURL } from "url";
|
|
68
68
|
import ts2 from "typescript";
|
|
69
69
|
|
|
@@ -136,9 +136,24 @@ async function loadConfig() {
|
|
|
136
136
|
...defaultConfig,
|
|
137
137
|
...userConfig
|
|
138
138
|
};
|
|
139
|
-
|
|
139
|
+
const configDir2 = dirname(configPath);
|
|
140
|
+
return {
|
|
141
|
+
...mergedConfig,
|
|
142
|
+
configPath,
|
|
143
|
+
configDir: configDir2,
|
|
144
|
+
resolvedSourceDir: resolve(configDir2, mergedConfig.sourceDir),
|
|
145
|
+
resolvedOutputDir: resolve(configDir2, mergedConfig.outputDir),
|
|
146
|
+
resolvedTemplateDir: mergedConfig.templateDir && mergedConfig.templateDir.startsWith(".") ? resolve(configDir2, mergedConfig.templateDir) : mergedConfig.templateDir
|
|
147
|
+
};
|
|
140
148
|
}
|
|
141
|
-
|
|
149
|
+
const configDir = process.cwd();
|
|
150
|
+
return {
|
|
151
|
+
...defaultConfig,
|
|
152
|
+
configDir,
|
|
153
|
+
resolvedSourceDir: resolve(configDir, defaultConfig.sourceDir),
|
|
154
|
+
resolvedOutputDir: resolve(configDir, defaultConfig.outputDir),
|
|
155
|
+
resolvedTemplateDir: defaultConfig.templateDir
|
|
156
|
+
};
|
|
142
157
|
}
|
|
143
158
|
// src/utils/query.ts
|
|
144
159
|
var queryOption = (key, fn) => {
|