subaya 1.0.0
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 +156 -0
- package/dist/commands/api/OrpcGeneratorCommand.d.ts +16 -0
- package/dist/commands/api/OrpcGeneratorCommand.d.ts.map +1 -0
- package/dist/commands/api/OrpcGeneratorCommand.js +100 -0
- package/dist/commands/api/OrpcGeneratorCommand.js.map +1 -0
- package/dist/commands/api/generators/ApiMethodGenerator.d.ts +22 -0
- package/dist/commands/api/generators/ApiMethodGenerator.d.ts.map +1 -0
- package/dist/commands/api/generators/ApiMethodGenerator.js +73 -0
- package/dist/commands/api/generators/ApiMethodGenerator.js.map +1 -0
- package/dist/commands/api/generators/QueryStringGenerator.d.ts +7 -0
- package/dist/commands/api/generators/QueryStringGenerator.d.ts.map +1 -0
- package/dist/commands/api/generators/QueryStringGenerator.js +34 -0
- package/dist/commands/api/generators/QueryStringGenerator.js.map +1 -0
- package/dist/commands/api/generators/SchemaGenerator.d.ts +5 -0
- package/dist/commands/api/generators/SchemaGenerator.d.ts.map +1 -0
- package/dist/commands/api/generators/SchemaGenerator.js +61 -0
- package/dist/commands/api/generators/SchemaGenerator.js.map +1 -0
- package/dist/commands/api/services/ApiFileWriter.d.ts +9 -0
- package/dist/commands/api/services/ApiFileWriter.d.ts.map +1 -0
- package/dist/commands/api/services/ApiFileWriter.js +112 -0
- package/dist/commands/api/services/ApiFileWriter.js.map +1 -0
- package/dist/commands/api/services/DependencyChecker.d.ts +6 -0
- package/dist/commands/api/services/DependencyChecker.d.ts.map +1 -0
- package/dist/commands/api/services/DependencyChecker.js +63 -0
- package/dist/commands/api/services/DependencyChecker.js.map +1 -0
- package/dist/commands/api/utils/CommentGenerator.d.ts +6 -0
- package/dist/commands/api/utils/CommentGenerator.d.ts.map +1 -0
- package/dist/commands/api/utils/CommentGenerator.js +52 -0
- package/dist/commands/api/utils/CommentGenerator.js.map +1 -0
- package/dist/commands/api/utils/ParameterExtractor.d.ts +10 -0
- package/dist/commands/api/utils/ParameterExtractor.d.ts.map +1 -0
- package/dist/commands/api/utils/ParameterExtractor.js +29 -0
- package/dist/commands/api/utils/ParameterExtractor.js.map +1 -0
- package/dist/commands/api/utils/ResponseTypeExtractor.d.ts +9 -0
- package/dist/commands/api/utils/ResponseTypeExtractor.d.ts.map +1 -0
- package/dist/commands/api/utils/ResponseTypeExtractor.js +36 -0
- package/dist/commands/api/utils/ResponseTypeExtractor.js.map +1 -0
- package/dist/commands/api/utils/TypeResolver.d.ts +6 -0
- package/dist/commands/api/utils/TypeResolver.d.ts.map +1 -0
- package/dist/commands/api/utils/TypeResolver.js +38 -0
- package/dist/commands/api/utils/TypeResolver.js.map +1 -0
- package/dist/commands/axios/AxiosGeneratorCommand.d.ts +5 -0
- package/dist/commands/axios/AxiosGeneratorCommand.d.ts.map +1 -0
- package/dist/commands/axios/AxiosGeneratorCommand.js +56 -0
- package/dist/commands/axios/AxiosGeneratorCommand.js.map +1 -0
- package/dist/commands/env/EnvGeneratorCommand.d.ts +8 -0
- package/dist/commands/env/EnvGeneratorCommand.d.ts.map +1 -0
- package/dist/commands/env/EnvGeneratorCommand.js +62 -0
- package/dist/commands/env/EnvGeneratorCommand.js.map +1 -0
- package/dist/commands/icon/IconGenerateCommand.d.ts +6 -0
- package/dist/commands/icon/IconGenerateCommand.d.ts.map +1 -0
- package/dist/commands/icon/IconGenerateCommand.js +103 -0
- package/dist/commands/icon/IconGenerateCommand.js.map +1 -0
- package/dist/commands/image/BackgroundRemoveCommand.d.ts +7 -0
- package/dist/commands/image/BackgroundRemoveCommand.d.ts.map +1 -0
- package/dist/commands/image/BackgroundRemoveCommand.js +89 -0
- package/dist/commands/image/BackgroundRemoveCommand.js.map +1 -0
- package/dist/commands/image/ImageOptimizeCommand.d.ts +8 -0
- package/dist/commands/image/ImageOptimizeCommand.d.ts.map +1 -0
- package/dist/commands/image/ImageOptimizeCommand.js +161 -0
- package/dist/commands/image/ImageOptimizeCommand.js.map +1 -0
- package/dist/commands/image/ImageResizeCommand.d.ts +5 -0
- package/dist/commands/image/ImageResizeCommand.d.ts.map +1 -0
- package/dist/commands/image/ImageResizeCommand.js +64 -0
- package/dist/commands/image/ImageResizeCommand.js.map +1 -0
- package/dist/commands/index.d.ts +4 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +4 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/localstorage/LocalstorageGeneratorCommand.d.ts +5 -0
- package/dist/commands/localstorage/LocalstorageGeneratorCommand.d.ts.map +1 -0
- package/dist/commands/localstorage/LocalstorageGeneratorCommand.js +45 -0
- package/dist/commands/localstorage/LocalstorageGeneratorCommand.js.map +1 -0
- package/dist/commands/provider/ProviderGeneratorCommand.d.ts +5 -0
- package/dist/commands/provider/ProviderGeneratorCommand.d.ts.map +1 -0
- package/dist/commands/provider/ProviderGeneratorCommand.js +54 -0
- package/dist/commands/provider/ProviderGeneratorCommand.js.map +1 -0
- package/dist/commands/route/NextRouteGeneratorCommand.d.ts +12 -0
- package/dist/commands/route/NextRouteGeneratorCommand.d.ts.map +1 -0
- package/dist/commands/route/NextRouteGeneratorCommand.js +126 -0
- package/dist/commands/route/NextRouteGeneratorCommand.js.map +1 -0
- package/dist/commands/share/ShareGeneratorCommand.d.ts +5 -0
- package/dist/commands/share/ShareGeneratorCommand.d.ts.map +1 -0
- package/dist/commands/share/ShareGeneratorCommand.js +44 -0
- package/dist/commands/share/ShareGeneratorCommand.js.map +1 -0
- package/dist/commands/state/StateGeneratorCommand.d.ts +10 -0
- package/dist/commands/state/StateGeneratorCommand.d.ts.map +1 -0
- package/dist/commands/state/StateGeneratorCommand.js +99 -0
- package/dist/commands/state/StateGeneratorCommand.js.map +1 -0
- package/dist/commands/supabase/SupabaseCommand.d.ts +7 -0
- package/dist/commands/supabase/SupabaseCommand.d.ts.map +1 -0
- package/dist/commands/supabase/SupabaseCommand.js +140 -0
- package/dist/commands/supabase/SupabaseCommand.js.map +1 -0
- package/dist/config/defaultConfig.d.ts +4 -0
- package/dist/config/defaultConfig.d.ts.map +1 -0
- package/dist/config/defaultConfig.js +15 -0
- package/dist/config/defaultConfig.js.map +1 -0
- package/dist/config/initial.d.ts +5 -0
- package/dist/config/initial.d.ts.map +1 -0
- package/dist/config/initial.js +32 -0
- package/dist/config/initial.js.map +1 -0
- package/dist/core/BaseCommand.d.ts +10 -0
- package/dist/core/BaseCommand.d.ts.map +1 -0
- package/dist/core/BaseCommand.js +36 -0
- package/dist/core/BaseCommand.js.map +1 -0
- package/dist/core/CommandRegistry.d.ts +15 -0
- package/dist/core/CommandRegistry.d.ts.map +1 -0
- package/dist/core/CommandRegistry.js +58 -0
- package/dist/core/CommandRegistry.js.map +1 -0
- package/dist/core/ConfigManager.d.ts +11 -0
- package/dist/core/ConfigManager.d.ts.map +1 -0
- package/dist/core/ConfigManager.js +42 -0
- package/dist/core/ConfigManager.js.map +1 -0
- package/dist/core/EnsureSystem.d.ts +10 -0
- package/dist/core/EnsureSystem.d.ts.map +1 -0
- package/dist/core/EnsureSystem.js +118 -0
- package/dist/core/EnsureSystem.js.map +1 -0
- package/dist/core/FileSystemService.d.ts +20 -0
- package/dist/core/FileSystemService.d.ts.map +1 -0
- package/dist/core/FileSystemService.js +97 -0
- package/dist/core/FileSystemService.js.map +1 -0
- package/dist/core/FrameworkDetector.d.ts +7 -0
- package/dist/core/FrameworkDetector.d.ts.map +1 -0
- package/dist/core/FrameworkDetector.js +33 -0
- package/dist/core/FrameworkDetector.js.map +1 -0
- package/dist/core/ProviderBuilder.d.ts +25 -0
- package/dist/core/ProviderBuilder.d.ts.map +1 -0
- package/dist/core/ProviderBuilder.js +227 -0
- package/dist/core/ProviderBuilder.js.map +1 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +7 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +105 -0
- package/dist/index.js.map +1 -0
- package/dist/template/api/gen/httpClient.d.ts +2 -0
- package/dist/template/api/gen/httpClient.d.ts.map +1 -0
- package/dist/template/api/gen/httpClient.js +177 -0
- package/dist/template/api/gen/httpClient.js.map +1 -0
- package/dist/template/api/gen/queryApiClient.d.ts +2 -0
- package/dist/template/api/gen/queryApiClient.d.ts.map +1 -0
- package/dist/template/api/gen/queryApiClient.js +27 -0
- package/dist/template/api/gen/queryApiClient.js.map +1 -0
- package/dist/template/api/gen/queryReactQueryClient.d.ts +13 -0
- package/dist/template/api/gen/queryReactQueryClient.d.ts.map +1 -0
- package/dist/template/api/gen/queryReactQueryClient.js +159 -0
- package/dist/template/api/gen/queryReactQueryClient.js.map +1 -0
- package/dist/template/api/type/httpClientType.d.ts +2 -0
- package/dist/template/api/type/httpClientType.d.ts.map +1 -0
- package/dist/template/api/type/httpClientType.js +2 -0
- package/dist/template/api/type/httpClientType.js.map +1 -0
- package/dist/template/axios/instance.d.ts +2 -0
- package/dist/template/axios/instance.d.ts.map +1 -0
- package/dist/template/axios/instance.js +91 -0
- package/dist/template/axios/instance.js.map +1 -0
- package/dist/template/axios/refresh.d.ts +2 -0
- package/dist/template/axios/refresh.d.ts.map +1 -0
- package/dist/template/axios/refresh.js +81 -0
- package/dist/template/axios/refresh.js.map +1 -0
- package/dist/template/imageAsNext.d.ts +2 -0
- package/dist/template/imageAsNext.d.ts.map +1 -0
- package/dist/template/imageAsNext.js +104 -0
- package/dist/template/imageAsNext.js.map +1 -0
- package/dist/template/localstorage/LocalStorageManager.d.ts +2 -0
- package/dist/template/localstorage/LocalStorageManager.d.ts.map +1 -0
- package/dist/template/localstorage/LocalStorageManager.js +64 -0
- package/dist/template/localstorage/LocalStorageManager.js.map +1 -0
- package/dist/template/localstorage/localStorage.d.ts +2 -0
- package/dist/template/localstorage/localStorage.d.ts.map +1 -0
- package/dist/template/localstorage/localStorage.js +9 -0
- package/dist/template/localstorage/localStorage.js.map +1 -0
- package/dist/template/localstorage/localStorageType.d.ts +2 -0
- package/dist/template/localstorage/localStorageType.d.ts.map +1 -0
- package/dist/template/localstorage/localStorageType.js +6 -0
- package/dist/template/localstorage/localStorageType.js.map +1 -0
- package/dist/template/localstorage/useSharedStorage.d.ts +2 -0
- package/dist/template/localstorage/useSharedStorage.d.ts.map +1 -0
- package/dist/template/localstorage/useSharedStorage.js +24 -0
- package/dist/template/localstorage/useSharedStorage.js.map +1 -0
- package/dist/template/logger/api-logger.d.ts +2 -0
- package/dist/template/logger/api-logger.d.ts.map +1 -0
- package/dist/template/logger/api-logger.js +44 -0
- package/dist/template/logger/api-logger.js.map +1 -0
- package/dist/template/logger/styled-console.d.ts +2 -0
- package/dist/template/logger/styled-console.d.ts.map +1 -0
- package/dist/template/logger/styled-console.js +27 -0
- package/dist/template/logger/styled-console.js.map +1 -0
- package/dist/template/provider/defaultProvider.tsx +6 -0
- package/dist/template/provider/providerTemplates.d.ts +9 -0
- package/dist/template/provider/providerTemplates.d.ts.map +1 -0
- package/dist/template/provider/providerTemplates.js +40 -0
- package/dist/template/provider/providerTemplates.js.map +1 -0
- package/dist/template/provider/providerTemplates.ts +47 -0
- package/dist/template/share/copyText.d.ts +2 -0
- package/dist/template/share/copyText.d.ts.map +1 -0
- package/dist/template/share/copyText.js +12 -0
- package/dist/template/share/copyText.js.map +1 -0
- package/dist/template/share/sharer.d.ts +2 -0
- package/dist/template/share/sharer.d.ts.map +1 -0
- package/dist/template/share/sharer.js +211 -0
- package/dist/template/share/sharer.js.map +1 -0
- package/dist/template/share/useSharer.d.ts +2 -0
- package/dist/template/share/useSharer.d.ts.map +1 -0
- package/dist/template/share/useSharer.js +78 -0
- package/dist/template/share/useSharer.js.map +1 -0
- package/dist/template/state/zustand-persist.d.ts +2 -0
- package/dist/template/state/zustand-persist.d.ts.map +1 -0
- package/dist/template/state/zustand-persist.js +53 -0
- package/dist/template/state/zustand-persist.js.map +1 -0
- package/dist/template/state/zustand-provider-store.d.ts +2 -0
- package/dist/template/state/zustand-provider-store.d.ts.map +1 -0
- package/dist/template/state/zustand-provider-store.js +19 -0
- package/dist/template/state/zustand-provider-store.js.map +1 -0
- package/dist/template/state/zustand-provider.d.ts +2 -0
- package/dist/template/state/zustand-provider.d.ts.map +1 -0
- package/dist/template/state/zustand-provider.js +46 -0
- package/dist/template/state/zustand-provider.js.map +1 -0
- package/dist/template/state/zustand.d.ts +2 -0
- package/dist/template/state/zustand.d.ts.map +1 -0
- package/dist/template/state/zustand.js +38 -0
- package/dist/template/state/zustand.js.map +1 -0
- package/dist/template/supabase/actions/supabaseAdmin.d.ts +2 -0
- package/dist/template/supabase/actions/supabaseAdmin.d.ts.map +1 -0
- package/dist/template/supabase/actions/supabaseAdmin.js +21 -0
- package/dist/template/supabase/actions/supabaseAdmin.js.map +1 -0
- package/dist/template/supabase/actions/supabaseCrud.d.ts +3 -0
- package/dist/template/supabase/actions/supabaseCrud.d.ts.map +1 -0
- package/dist/template/supabase/actions/supabaseCrud.js +72 -0
- package/dist/template/supabase/actions/supabaseCrud.js.map +1 -0
- package/dist/template/supabase/actions/supabaseCrudWithAdmin.d.ts +2 -0
- package/dist/template/supabase/actions/supabaseCrudWithAdmin.d.ts.map +1 -0
- package/dist/template/supabase/actions/supabaseCrudWithAdmin.js +57 -0
- package/dist/template/supabase/actions/supabaseCrudWithAdmin.js.map +1 -0
- package/dist/template/supabase/supabaseAdminLayout.d.ts +2 -0
- package/dist/template/supabase/supabaseAdminLayout.d.ts.map +1 -0
- package/dist/template/supabase/supabaseAdminLayout.js +7 -0
- package/dist/template/supabase/supabaseAdminLayout.js.map +1 -0
- package/dist/template/supabase/supabaseAdminLoginLayout.d.ts +2 -0
- package/dist/template/supabase/supabaseAdminLoginLayout.d.ts.map +1 -0
- package/dist/template/supabase/supabaseAdminLoginLayout.js +121 -0
- package/dist/template/supabase/supabaseAdminLoginLayout.js.map +1 -0
- package/dist/template/supabase/supabaseProxy.d.ts +2 -0
- package/dist/template/supabase/supabaseProxy.d.ts.map +1 -0
- package/dist/template/supabase/supabaseProxy.js +42 -0
- package/dist/template/supabase/supabaseProxy.js.map +1 -0
- package/dist/template/supabase/utilBase.d.ts +3 -0
- package/dist/template/supabase/utilBase.d.ts.map +1 -0
- package/dist/template/supabase/utilBase.js +29 -0
- package/dist/template/supabase/utilBase.js.map +1 -0
- package/dist/types/BaseExtensionCommands.d.ts +38 -0
- package/dist/types/BaseExtensionCommands.d.ts.map +1 -0
- package/dist/types/BaseExtensionCommands.js +20 -0
- package/dist/types/BaseExtensionCommands.js.map +1 -0
- package/dist/types/config.d.ts +19 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +2 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/env.d.ts +7 -0
- package/dist/types/env.d.ts.map +1 -0
- package/dist/types/env.js +5 -0
- package/dist/types/env.js.map +1 -0
- package/dist/types/index.d.ts +31 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/PathSearcher.d.ts +8 -0
- package/dist/utils/PathSearcher.d.ts.map +1 -0
- package/dist/utils/PathSearcher.js +40 -0
- package/dist/utils/PathSearcher.js.map +1 -0
- package/dist/utils/askInput.d.ts +10 -0
- package/dist/utils/askInput.d.ts.map +1 -0
- package/dist/utils/askInput.js +12 -0
- package/dist/utils/askInput.js.map +1 -0
- package/dist/utils/askSections.d.ts +13 -0
- package/dist/utils/askSections.d.ts.map +1 -0
- package/dist/utils/askSections.js +14 -0
- package/dist/utils/askSections.js.map +1 -0
- package/dist/utils/coverHyphenToQuotes.d.ts +2 -0
- package/dist/utils/coverHyphenToQuotes.d.ts.map +1 -0
- package/dist/utils/coverHyphenToQuotes.js +4 -0
- package/dist/utils/coverHyphenToQuotes.js.map +1 -0
- package/dist/utils/pathToAlias.d.ts +2 -0
- package/dist/utils/pathToAlias.d.ts.map +1 -0
- package/dist/utils/pathToAlias.js +4 -0
- package/dist/utils/pathToAlias.js.map +1 -0
- package/dist/utils/showSubaya.d.ts +2 -0
- package/dist/utils/showSubaya.d.ts.map +1 -0
- package/dist/utils/showSubaya.js +14 -0
- package/dist/utils/showSubaya.js.map +1 -0
- package/dist/utils/validateConfig.d.ts +3 -0
- package/dist/utils/validateConfig.d.ts.map +1 -0
- package/dist/utils/validateConfig.js +45 -0
- package/dist/utils/validateConfig.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import { Project, SourceFile, SyntaxKind } from "ts-morph";
|
|
3
|
+
import { providerTemplates } from "../template/provider/providerTemplates.js";
|
|
4
|
+
export class ProviderBuilder {
|
|
5
|
+
project;
|
|
6
|
+
sourceFile;
|
|
7
|
+
filePath;
|
|
8
|
+
additionalProviders;
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.project = new Project();
|
|
11
|
+
this.filePath = options.filePath;
|
|
12
|
+
this.additionalProviders = options.additionalProviders;
|
|
13
|
+
}
|
|
14
|
+
async build() {
|
|
15
|
+
const fileExists = await fs.pathExists(this.filePath);
|
|
16
|
+
if (fileExists) {
|
|
17
|
+
return this.updateExistingProvider();
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return this.createNewProvider();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async createNewProvider() {
|
|
24
|
+
const baseContent = `"use client"
|
|
25
|
+
|
|
26
|
+
export default function Providers({ children }: { children: React.ReactNode }) {
|
|
27
|
+
return <>{children}</>
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
this.sourceFile = this.project.createSourceFile(this.filePath, baseContent, { overwrite: true });
|
|
31
|
+
// additional providers가 있으면 추가
|
|
32
|
+
if (this.additionalProviders.length > 0) {
|
|
33
|
+
const result = this.addProvidersToFile();
|
|
34
|
+
return this.formatOutput(result);
|
|
35
|
+
}
|
|
36
|
+
return baseContent;
|
|
37
|
+
}
|
|
38
|
+
async updateExistingProvider() {
|
|
39
|
+
const existingContent = await fs.readFile(this.filePath, "utf8");
|
|
40
|
+
this.sourceFile = this.project.createSourceFile(this.filePath, existingContent, { overwrite: true });
|
|
41
|
+
const result = this.addProvidersToFile();
|
|
42
|
+
return this.formatOutput(result);
|
|
43
|
+
}
|
|
44
|
+
formatOutput(code) {
|
|
45
|
+
const lines = code.split("\n");
|
|
46
|
+
const useClientIndex = lines.findIndex((line) => line.includes('"use client"'));
|
|
47
|
+
const importLines = [];
|
|
48
|
+
const otherLines = [];
|
|
49
|
+
lines.forEach((line, index) => {
|
|
50
|
+
if (index === useClientIndex)
|
|
51
|
+
return;
|
|
52
|
+
if (line.trim().startsWith("import ")) {
|
|
53
|
+
importLines.push(line);
|
|
54
|
+
}
|
|
55
|
+
else if (line.trim()) {
|
|
56
|
+
otherLines.push(line);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
const formatted = ['"use client"', "", ...importLines, "", ...otherLines].join("\n");
|
|
60
|
+
return formatted;
|
|
61
|
+
}
|
|
62
|
+
addProvidersToFile() {
|
|
63
|
+
if (!this.sourceFile) {
|
|
64
|
+
throw new Error("Source file not initialized");
|
|
65
|
+
}
|
|
66
|
+
const templates = [];
|
|
67
|
+
// additional providers에 해당하는 템플릿 수집
|
|
68
|
+
for (const providerName of this.additionalProviders) {
|
|
69
|
+
const template = providerTemplates[providerName.toLowerCase()];
|
|
70
|
+
if (!template) {
|
|
71
|
+
console.warn(`⚠️ Provider template not found: ${providerName}`);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
// 이미 존재하는지 확인
|
|
75
|
+
if (this.isProviderAlreadyExists(template)) {
|
|
76
|
+
console.log(`Provider '${providerName}' already exists, skipping...`);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
templates.push(template);
|
|
80
|
+
}
|
|
81
|
+
if (templates.length === 0) {
|
|
82
|
+
return this.sourceFile.getFullText();
|
|
83
|
+
}
|
|
84
|
+
// imports 추가
|
|
85
|
+
this.addImports(templates);
|
|
86
|
+
// 함수 내부에 코드 추가
|
|
87
|
+
this.addFunctionsToBody(templates);
|
|
88
|
+
// JSX 래퍼 추가
|
|
89
|
+
this.wrapJSXWithProviders(templates);
|
|
90
|
+
return this.sourceFile.getFullText();
|
|
91
|
+
}
|
|
92
|
+
isProviderAlreadyExists(template) {
|
|
93
|
+
if (!this.sourceFile)
|
|
94
|
+
return false;
|
|
95
|
+
const fullText = this.sourceFile.getFullText();
|
|
96
|
+
// import 문이나 wrapper가 존재하는지 확인
|
|
97
|
+
for (const importStatement of template.imports) {
|
|
98
|
+
const packageName = this.extractPackageName(importStatement);
|
|
99
|
+
if (packageName && fullText.includes(packageName)) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
extractPackageName(importStatement) {
|
|
106
|
+
const match = importStatement.match(/from ['"]([^'"]+)['"]/);
|
|
107
|
+
return match && match[1] ? match[1] : "";
|
|
108
|
+
}
|
|
109
|
+
addImports(templates) {
|
|
110
|
+
if (!this.sourceFile)
|
|
111
|
+
return;
|
|
112
|
+
const existingImports = this.sourceFile.getImportDeclarations().map((imp) => imp.getFullText().trim());
|
|
113
|
+
for (const template of templates) {
|
|
114
|
+
for (const importStatement of template.imports) {
|
|
115
|
+
const trimmedImport = importStatement.trim();
|
|
116
|
+
const packageName = this.extractPackageName(trimmedImport);
|
|
117
|
+
// 중복 체크
|
|
118
|
+
if (!existingImports.some((existing) => existing.includes(packageName))) {
|
|
119
|
+
this.sourceFile.addImportDeclaration({
|
|
120
|
+
moduleSpecifier: packageName,
|
|
121
|
+
namedImports: this.extractNamedImports(trimmedImport),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
extractNamedImports(importStatement) {
|
|
128
|
+
const match = importStatement.match(/import\s+{([^}]+)}/);
|
|
129
|
+
if (match && match[1]) {
|
|
130
|
+
return match[1].split(",").map((s) => s.trim());
|
|
131
|
+
}
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
addFunctionsToBody(templates) {
|
|
135
|
+
if (!this.sourceFile)
|
|
136
|
+
return;
|
|
137
|
+
const functionDeclaration = this.sourceFile.getFunction("Providers");
|
|
138
|
+
if (!functionDeclaration)
|
|
139
|
+
return;
|
|
140
|
+
const functionBody = functionDeclaration.getBody();
|
|
141
|
+
if (!functionBody || !functionBody.isKind(SyntaxKind.Block))
|
|
142
|
+
return;
|
|
143
|
+
// 함수 시작 부분에 코드 추가
|
|
144
|
+
for (const template of templates) {
|
|
145
|
+
for (const functionCode of template.functions) {
|
|
146
|
+
// 이미 존재하는지 확인
|
|
147
|
+
const bodyText = functionBody.getFullText();
|
|
148
|
+
const firstLine = functionCode.trim().split("\n")[0];
|
|
149
|
+
if (firstLine && !bodyText.includes(firstLine)) {
|
|
150
|
+
// 코드 블록을 적절히 인덴트 (2칸)
|
|
151
|
+
const indentedCode = functionCode
|
|
152
|
+
.split("\n")
|
|
153
|
+
.map((line) => (line.trim() ? " " + line : line))
|
|
154
|
+
.join("\n");
|
|
155
|
+
functionBody.insertStatements(0, indentedCode);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
wrapJSXWithProviders(templates) {
|
|
161
|
+
if (!this.sourceFile)
|
|
162
|
+
return;
|
|
163
|
+
const functionDeclaration = this.sourceFile.getFunction("Providers");
|
|
164
|
+
if (!functionDeclaration)
|
|
165
|
+
return;
|
|
166
|
+
const returnStatement = functionDeclaration.getDescendantsOfKind(SyntaxKind.ReturnStatement)[0];
|
|
167
|
+
if (!returnStatement)
|
|
168
|
+
return;
|
|
169
|
+
// 각 템플릿으로 래핑
|
|
170
|
+
for (const template of templates) {
|
|
171
|
+
this.wrapReturnStatementWithProvider(returnStatement, template);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
wrapReturnStatementWithProvider(returnStatement, template) {
|
|
175
|
+
// 현재 return 문의 JSX 가져오기
|
|
176
|
+
let jsxElement = returnStatement.getDescendantsOfKind(SyntaxKind.JsxElement)[0];
|
|
177
|
+
let jsxFragment = returnStatement.getDescendantsOfKind(SyntaxKind.JsxFragment)[0];
|
|
178
|
+
let jsxSelfClosing = returnStatement.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement)[0];
|
|
179
|
+
if (!jsxElement && !jsxFragment && !jsxSelfClosing)
|
|
180
|
+
return;
|
|
181
|
+
// 현재 JSX 텍스트 가져오기
|
|
182
|
+
let currentJSXText = "";
|
|
183
|
+
if (jsxElement) {
|
|
184
|
+
currentJSXText = jsxElement.getFullText().trim();
|
|
185
|
+
}
|
|
186
|
+
else if (jsxFragment) {
|
|
187
|
+
currentJSXText = jsxFragment.getFullText().trim();
|
|
188
|
+
}
|
|
189
|
+
else if (jsxSelfClosing) {
|
|
190
|
+
currentJSXText = jsxSelfClosing.getFullText().trim();
|
|
191
|
+
}
|
|
192
|
+
// children을 적절히 인덴트 (2칸 추가)
|
|
193
|
+
const indentedChildren = currentJSXText
|
|
194
|
+
.split("\n")
|
|
195
|
+
.map((line) => " " + line)
|
|
196
|
+
.join("\n");
|
|
197
|
+
// wrapperClose에서 줄바꿈과 닫는 태그 분리
|
|
198
|
+
const wrapperCloseLines = template.wrapperClose.split("\n");
|
|
199
|
+
const hasMultipleLines = wrapperCloseLines.length > 1;
|
|
200
|
+
let wrappedJSX;
|
|
201
|
+
if (hasMultipleLines) {
|
|
202
|
+
// ReactQueryDevtools 같은 경우
|
|
203
|
+
const closingTag = wrapperCloseLines[wrapperCloseLines.length - 1];
|
|
204
|
+
const middleContent = wrapperCloseLines
|
|
205
|
+
.slice(0, -1)
|
|
206
|
+
.map((line) => " " + line)
|
|
207
|
+
.join("\n");
|
|
208
|
+
wrappedJSX = `(\n ${template.wrapperOpen}\n${indentedChildren}\n${middleContent}\n ${closingTag}\n)`;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
wrappedJSX = `(\n ${template.wrapperOpen}\n${indentedChildren}\n ${template.wrapperClose}\n)`;
|
|
212
|
+
}
|
|
213
|
+
// return 문 전체 교체
|
|
214
|
+
returnStatement.replaceWithText(`return ${wrappedJSX}`);
|
|
215
|
+
}
|
|
216
|
+
static getRequiredDependencies(providerNames) {
|
|
217
|
+
const dependencies = [];
|
|
218
|
+
for (const name of providerNames) {
|
|
219
|
+
const template = providerTemplates[name.toLowerCase()];
|
|
220
|
+
if (template?.dependencies) {
|
|
221
|
+
dependencies.push(...template.dependencies);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return [...new Set(dependencies)];
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=ProviderBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProviderBuilder.js","sourceRoot":"","sources":["../../src/core/ProviderBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,UAAU,CAAA;AACzB,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAA;AAO7E,MAAM,OAAO,eAAe;IAClB,OAAO,CAAS;IAChB,UAAU,CAAwB;IAClC,QAAQ,CAAQ;IAChB,mBAAmB,CAAU;IAErC,YAAY,OAA+B;QACzC,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,EAAE,CAAA;QAC5B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;QAChC,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAA;IACxD,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,UAAU,GAAG,MAAM,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAErD,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,IAAI,CAAC,sBAAsB,EAAE,CAAA;QACtC,CAAC;aAAM,CAAC;YACN,O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BaseCommand } from "./BaseCommand.js";
|
|
3
|
+
export { CommandRegistry } from "./CommandRegistry.js";
|
|
4
|
+
export { ConfigManager } from "./ConfigManager.js";
|
|
5
|
+
export { FileSystemService } from "./FileSystemService.js";
|
|
6
|
+
export { FrameworkDetector } from "./FrameworkDetector.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AACtH,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { BaseApiCommand, BaseEnvCommand, BaseRouteCommand, BaseStateCommand } from "../types/BaseExtensionCommands.js";
|
|
2
|
+
export { BaseCommand } from "./BaseCommand.js";
|
|
3
|
+
export { CommandRegistry } from "./CommandRegistry.js";
|
|
4
|
+
export { ConfigManager } from "./ConfigManager.js";
|
|
5
|
+
export { FileSystemService } from "./FileSystemService.js";
|
|
6
|
+
export { FrameworkDetector } from "./FrameworkDetector.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AACtH,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { generateInitialCommands, MULTI_COMMAND_CATEGORIES, SINGLE_COMMAND_CATEGORIES } from "./config/initial.js";
|
|
3
|
+
import { CommandRegistry } from "./core/CommandRegistry.js";
|
|
4
|
+
import { showSubaya } from "./utils/showSubaya.js";
|
|
5
|
+
generateInitialCommands();
|
|
6
|
+
async function main() {
|
|
7
|
+
const [, , category, commandName] = process.argv;
|
|
8
|
+
showSubaya();
|
|
9
|
+
if (!category) {
|
|
10
|
+
printUsage();
|
|
11
|
+
process.exitCode = 0;
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (!CommandRegistry.hasCategory(category)) {
|
|
15
|
+
printUsage(category);
|
|
16
|
+
process.exitCode = 1;
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (MULTI_COMMAND_CATEGORIES.includes(category) && !commandName) {
|
|
20
|
+
printCategoryUsage(category);
|
|
21
|
+
process.exitCode = 1;
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const command = await CommandRegistry.getCommand(category, commandName);
|
|
25
|
+
if (!command) {
|
|
26
|
+
printCategoryUsage(category);
|
|
27
|
+
process.exitCode = 1;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
await command.execute();
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
console.error("❌ 오류 발생:", err);
|
|
35
|
+
process.exitCode = 1;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function logUsageSingle() {
|
|
39
|
+
console.log(`
|
|
40
|
+
Usage: subaya <category>
|
|
41
|
+
|
|
42
|
+
A CLI toolkit for rapid development.
|
|
43
|
+
|
|
44
|
+
Available Categories:
|
|
45
|
+
`);
|
|
46
|
+
for (const category of CommandRegistry.getAllCategories()) {
|
|
47
|
+
console.log(` subaya ${MULTI_COMMAND_CATEGORIES.includes(category) ? category + " <command>" : category}`);
|
|
48
|
+
}
|
|
49
|
+
console.log(`
|
|
50
|
+
Example:
|
|
51
|
+
subaya route
|
|
52
|
+
`);
|
|
53
|
+
}
|
|
54
|
+
function logUsageMulti() {
|
|
55
|
+
console.log(`
|
|
56
|
+
Usage: subaya <category> <command>
|
|
57
|
+
|
|
58
|
+
A CLI toolkit for rapid development.
|
|
59
|
+
|
|
60
|
+
Available Commands in '${process.argv[2] ?? "<category>"}':
|
|
61
|
+
`);
|
|
62
|
+
for (const _category of CommandRegistry.getCategories(false)) {
|
|
63
|
+
console.log(` ${_category}`);
|
|
64
|
+
}
|
|
65
|
+
console.log(`
|
|
66
|
+
Run 'subaya <category> --help' for details on available commands.
|
|
67
|
+
|
|
68
|
+
Example:
|
|
69
|
+
subaya image optimize
|
|
70
|
+
`);
|
|
71
|
+
}
|
|
72
|
+
function printUsage(category) {
|
|
73
|
+
if (!category) {
|
|
74
|
+
logUsageSingle();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const isMulti = SINGLE_COMMAND_CATEGORIES.includes(category);
|
|
78
|
+
if (isMulti) {
|
|
79
|
+
logUsageMulti();
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
logUsageSingle();
|
|
83
|
+
}
|
|
84
|
+
console.log("------------------------------");
|
|
85
|
+
}
|
|
86
|
+
function printCategoryUsage(category) {
|
|
87
|
+
console.log(`
|
|
88
|
+
❌ Invalid command.
|
|
89
|
+
|
|
90
|
+
Usage:
|
|
91
|
+
subaya ${category} <command>
|
|
92
|
+
|
|
93
|
+
Available Commands in '${category}':
|
|
94
|
+
`);
|
|
95
|
+
const commands = CommandRegistry.getCommandNames(category);
|
|
96
|
+
for (const cmd of commands) {
|
|
97
|
+
console.log(` - ${cmd}`);
|
|
98
|
+
}
|
|
99
|
+
console.log(`
|
|
100
|
+
Example:
|
|
101
|
+
subaya ${category} ${commands[0] ?? "<command>"}
|
|
102
|
+
`);
|
|
103
|
+
}
|
|
104
|
+
main();
|
|
105
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAA;AAClH,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAElD,uBAAuB,EAAE,CAAA;AAEzB,KAAK,UAAU,IAAI;IACjB,MAAM,CAAC,EAAE,AAAD,EAAG,QAAQ,EAAE,WAAW,CAAC,GAAG,OAAO,CAAC,IAAI,CAAA;IAEhD,UAAU,EAAE,CAAA;IACZ,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,UAAU,EAAE,CAAA;QACZ,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;QACpB,OAAM;IACR,CAAC;IAED,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3C,UAAU,CAAC,QAAQ,CAAC,CAAA;QACpB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;QACpB,OAAM;IACR,CAAC;IAED,IAAI,wBAAwB,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QAChE,kBAAkB,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Kb,CAAC,CAAA;AACF,CAAC;AAED,SAAS,UAAU,CAAC,QAAiB;IACnC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,cAAc,EAAE,CAAA;QAChB,OAAM;IACR,CAAC;IACD,MAAM,OAAO,GAAG,yBAAyB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAE5D,IAAI,OAAO,EAAE,CAAC;QACZ,aAAa,EAAE,CAAA;IACjB,CAAC;SAAM,CAAC;QACN,cAAc,EAAE,CAAA;IAClB,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAA;AAC/C,CAAC;AAED,SAAS,kBAAkB,CAAC,QAAgB;IAC1C,OAAO,CAAC,GAAG,CAAC;;;;WAIH,QAAQ;;yBAEM,QAAQ;CAChC,CAAC,CAAA;IACA,MAAM,QAAQ,GAAG,eAAe,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAA;IAC1D,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,OAAO,CAAC,GAAG,CAAC,OAAO,GAAG,EAAE,CAAC,CAAA;IAC3B,CAAC;IACD,OAAO,CAAC,GAAG,CAAC;;WAEH,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,WAAW;CAChD,CAAC,CAAA;AACF,CAAC;AAED,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const genApiHttpClient = "import axios, {\n AxiosInstance,\n AxiosRequestConfig,\n HeadersDefaults,\n ResponseType,\n} from 'axios';\n\nexport type QueryParamsType = Record<string | number, any>;\n\nexport interface FullRequestParams\n extends Omit<AxiosRequestConfig, 'data' | 'params' | 'url' | 'responseType'> {\n /** set parameter to `true` for call `securityWorker` for this request */\n secure?: boolean;\n /** request path */\n path: string;\n /** content type of request body */\n type?: ContentType;\n /** query params */\n query?: QueryParamsType;\n /** format of response (i.e. response.json() -> format: \"json\") */\n format?: ResponseType;\n /** request body */\n body?: unknown;\n}\n\nexport type RequestParams = Omit<\n FullRequestParams,\n 'body' | 'method' | 'query' | 'path'\n>;\n\nexport interface ApiConfig<SecurityDataType = unknown> {\n securityWorker?: (\n securityData: SecurityDataType | null,\n ) => Promise<AxiosRequestConfig | void> | AxiosRequestConfig | void;\n secure?: boolean;\n format?: ResponseType;\n instance?: AxiosInstance;\n axiosConfig?: Omit<AxiosRequestConfig, 'data' | 'cancelToken'>;\n}\n\nexport enum ContentType {\n Json = 'application/json',\n FormData = 'multipart/form-data',\n UrlEncoded = 'application/x-www-form-urlencoded',\n Text = 'text/plain',\n}\n\nexport class HttpClient<SecurityDataType = unknown> {\n public instance: AxiosInstance;\n private securityData: SecurityDataType | null = null;\n private securityWorker?: ApiConfig<SecurityDataType>['securityWorker'];\n private secure?: boolean;\n private format?: ResponseType;\n\n constructor({\n securityWorker,\n secure,\n format,\n instance,\n axiosConfig,\n }: ApiConfig<SecurityDataType> = {}) {\n this.instance =\n instance ||\n axios.create({\n ...axiosConfig,\n baseURL: axiosConfig?.baseURL || '',\n });\n this.secure = secure;\n this.format = format;\n this.securityWorker = securityWorker;\n }\n\n public setSecurityData = (data: SecurityDataType | null) => {\n this.securityData = data;\n };\n\n protected mergeRequestParams(\n params1: AxiosRequestConfig,\n params2?: AxiosRequestConfig,\n ): AxiosRequestConfig {\n const method = params1.method || (params2 && params2.method);\n\n return {\n ...this.instance.defaults,\n ...params1,\n ...(params2 || {}),\n headers: {\n ...((method &&\n this.instance.defaults.headers[\n method.toLowerCase() as keyof HeadersDefaults\n ]) ||\n {}),\n ...(params1.headers || {}),\n ...((params2 && params2.headers) || {}),\n },\n };\n }\n\n protected stringifyFormItem(formItem: unknown) {\n if (typeof formItem === 'object' && formItem !== null) {\n return JSON.stringify(formItem);\n } else {\n return `${formItem}`;\n }\n }\n\n protected createFormData(input: Record<string, unknown>): FormData {\n return Object.keys(input || {}).reduce((formData, key) => {\n const property = input[key];\n const propertyContent: any[] =\n property instanceof Array ? property : [property];\n\n for (const formItem of propertyContent) {\n const isFileType = formItem instanceof Blob || formItem instanceof File;\n formData.append(\n key,\n isFileType ? formItem : this.stringifyFormItem(formItem),\n );\n }\n\n return formData;\n }, new FormData());\n }\n\n public request = async <T = any, _E = any>({\n secure,\n path,\n type,\n query,\n format,\n body,\n ...params\n }: FullRequestParams): Promise<T> => {\n const secureParams =\n ((typeof secure === 'boolean' ? secure : this.secure) &&\n this.securityWorker &&\n (await this.securityWorker(this.securityData))) ||\n {};\n const requestParams = this.mergeRequestParams(params, secureParams);\n const responseFormat = format || this.format || undefined;\n\n if (\n type === ContentType.FormData &&\n body &&\n body !== null &&\n typeof body === 'object'\n ) {\n body = this.createFormData(body as Record<string, unknown>);\n }\n\n if (\n type === ContentType.Text &&\n body &&\n body !== null &&\n typeof body !== 'string'\n ) {\n body = JSON.stringify(body);\n }\n\n return this.instance\n .request({\n ...requestParams,\n headers: {\n ...(requestParams.headers || {}),\n ...(type && type !== ContentType.FormData\n ? { 'Content-Type': type }\n : {}),\n },\n params: query,\n responseType: responseFormat,\n data: body,\n url: path,\n })\n .then((response) => response.data);\n };\n}";
|
|
2
|
+
//# sourceMappingURL=httpClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpClient.d.ts","sourceRoot":"","sources":["../../../../src/template/api/gen/httpClient.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,2rJA+K3B,CAAA"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
export const genApiHttpClient = `import axios, {
|
|
2
|
+
AxiosInstance,
|
|
3
|
+
AxiosRequestConfig,
|
|
4
|
+
HeadersDefaults,
|
|
5
|
+
ResponseType,
|
|
6
|
+
} from 'axios';
|
|
7
|
+
|
|
8
|
+
export type QueryParamsType = Record<string | number, any>;
|
|
9
|
+
|
|
10
|
+
export interface FullRequestParams
|
|
11
|
+
extends Omit<AxiosRequestConfig, 'data' | 'params' | 'url' | 'responseType'> {
|
|
12
|
+
/** set parameter to \`true\` for call \`securityWorker\` for this request */
|
|
13
|
+
secure?: boolean;
|
|
14
|
+
/** request path */
|
|
15
|
+
path: string;
|
|
16
|
+
/** content type of request body */
|
|
17
|
+
type?: ContentType;
|
|
18
|
+
/** query params */
|
|
19
|
+
query?: QueryParamsType;
|
|
20
|
+
/** format of response (i.e. response.json() -> format: "json") */
|
|
21
|
+
format?: ResponseType;
|
|
22
|
+
/** request body */
|
|
23
|
+
body?: unknown;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type RequestParams = Omit<
|
|
27
|
+
FullRequestParams,
|
|
28
|
+
'body' | 'method' | 'query' | 'path'
|
|
29
|
+
>;
|
|
30
|
+
|
|
31
|
+
export interface ApiConfig<SecurityDataType = unknown> {
|
|
32
|
+
securityWorker?: (
|
|
33
|
+
securityData: SecurityDataType | null,
|
|
34
|
+
) => Promise<AxiosRequestConfig | void> | AxiosRequestConfig | void;
|
|
35
|
+
secure?: boolean;
|
|
36
|
+
format?: ResponseType;
|
|
37
|
+
instance?: AxiosInstance;
|
|
38
|
+
axiosConfig?: Omit<AxiosRequestConfig, 'data' | 'cancelToken'>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export enum ContentType {
|
|
42
|
+
Json = 'application/json',
|
|
43
|
+
FormData = 'multipart/form-data',
|
|
44
|
+
UrlEncoded = 'application/x-www-form-urlencoded',
|
|
45
|
+
Text = 'text/plain',
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class HttpClient<SecurityDataType = unknown> {
|
|
49
|
+
public instance: AxiosInstance;
|
|
50
|
+
private securityData: SecurityDataType | null = null;
|
|
51
|
+
private securityWorker?: ApiConfig<SecurityDataType>['securityWorker'];
|
|
52
|
+
private secure?: boolean;
|
|
53
|
+
private format?: ResponseType;
|
|
54
|
+
|
|
55
|
+
constructor({
|
|
56
|
+
securityWorker,
|
|
57
|
+
secure,
|
|
58
|
+
format,
|
|
59
|
+
instance,
|
|
60
|
+
axiosConfig,
|
|
61
|
+
}: ApiConfig<SecurityDataType> = {}) {
|
|
62
|
+
this.instance =
|
|
63
|
+
instance ||
|
|
64
|
+
axios.create({
|
|
65
|
+
...axiosConfig,
|
|
66
|
+
baseURL: axiosConfig?.baseURL || '',
|
|
67
|
+
});
|
|
68
|
+
this.secure = secure;
|
|
69
|
+
this.format = format;
|
|
70
|
+
this.securityWorker = securityWorker;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public setSecurityData = (data: SecurityDataType | null) => {
|
|
74
|
+
this.securityData = data;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
protected mergeRequestParams(
|
|
78
|
+
params1: AxiosRequestConfig,
|
|
79
|
+
params2?: AxiosRequestConfig,
|
|
80
|
+
): AxiosRequestConfig {
|
|
81
|
+
const method = params1.method || (params2 && params2.method);
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
...this.instance.defaults,
|
|
85
|
+
...params1,
|
|
86
|
+
...(params2 || {}),
|
|
87
|
+
headers: {
|
|
88
|
+
...((method &&
|
|
89
|
+
this.instance.defaults.headers[
|
|
90
|
+
method.toLowerCase() as keyof HeadersDefaults
|
|
91
|
+
]) ||
|
|
92
|
+
{}),
|
|
93
|
+
...(params1.headers || {}),
|
|
94
|
+
...((params2 && params2.headers) || {}),
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
protected stringifyFormItem(formItem: unknown) {
|
|
100
|
+
if (typeof formItem === 'object' && formItem !== null) {
|
|
101
|
+
return JSON.stringify(formItem);
|
|
102
|
+
} else {
|
|
103
|
+
return \`\${formItem}\`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
protected createFormData(input: Record<string, unknown>): FormData {
|
|
108
|
+
return Object.keys(input || {}).reduce((formData, key) => {
|
|
109
|
+
const property = input[key];
|
|
110
|
+
const propertyContent: any[] =
|
|
111
|
+
property instanceof Array ? property : [property];
|
|
112
|
+
|
|
113
|
+
for (const formItem of propertyContent) {
|
|
114
|
+
const isFileType = formItem instanceof Blob || formItem instanceof File;
|
|
115
|
+
formData.append(
|
|
116
|
+
key,
|
|
117
|
+
isFileType ? formItem : this.stringifyFormItem(formItem),
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return formData;
|
|
122
|
+
}, new FormData());
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public request = async <T = any, _E = any>({
|
|
126
|
+
secure,
|
|
127
|
+
path,
|
|
128
|
+
type,
|
|
129
|
+
query,
|
|
130
|
+
format,
|
|
131
|
+
body,
|
|
132
|
+
...params
|
|
133
|
+
}: FullRequestParams): Promise<T> => {
|
|
134
|
+
const secureParams =
|
|
135
|
+
((typeof secure === 'boolean' ? secure : this.secure) &&
|
|
136
|
+
this.securityWorker &&
|
|
137
|
+
(await this.securityWorker(this.securityData))) ||
|
|
138
|
+
{};
|
|
139
|
+
const requestParams = this.mergeRequestParams(params, secureParams);
|
|
140
|
+
const responseFormat = format || this.format || undefined;
|
|
141
|
+
|
|
142
|
+
if (
|
|
143
|
+
type === ContentType.FormData &&
|
|
144
|
+
body &&
|
|
145
|
+
body !== null &&
|
|
146
|
+
typeof body === 'object'
|
|
147
|
+
) {
|
|
148
|
+
body = this.createFormData(body as Record<string, unknown>);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (
|
|
152
|
+
type === ContentType.Text &&
|
|
153
|
+
body &&
|
|
154
|
+
body !== null &&
|
|
155
|
+
typeof body !== 'string'
|
|
156
|
+
) {
|
|
157
|
+
body = JSON.stringify(body);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return this.instance
|
|
161
|
+
.request({
|
|
162
|
+
...requestParams,
|
|
163
|
+
headers: {
|
|
164
|
+
...(requestParams.headers || {}),
|
|
165
|
+
...(type && type !== ContentType.FormData
|
|
166
|
+
? { 'Content-Type': type }
|
|
167
|
+
: {}),
|
|
168
|
+
},
|
|
169
|
+
params: query,
|
|
170
|
+
responseType: responseFormat,
|
|
171
|
+
data: body,
|
|
172
|
+
url: path,
|
|
173
|
+
})
|
|
174
|
+
.then((response) => response.data);
|
|
175
|
+
};
|
|
176
|
+
}`;
|
|
177
|
+
//# sourceMappingURL=httpClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpClient.js","sourceRoot":"","sources":["../../../../src/template/api/gen/httpClient.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+K9B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryApiClient.d.ts","sourceRoot":"","sources":["../../../../src/template/api/gen/queryApiClient.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,GAAI,SAAS,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,eAAe,MAAM,EAAE,WAyB5F,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { camelCase } from "change-case";
|
|
2
|
+
export const genQueryApiClient = (apiName, queries, importTypeArr) => {
|
|
3
|
+
const genImportArr = () => {
|
|
4
|
+
if (importTypeArr.length === 0) {
|
|
5
|
+
return "";
|
|
6
|
+
}
|
|
7
|
+
const sortedImportTypeArr = importTypeArr.sort((a, b) => a.localeCompare(b));
|
|
8
|
+
const importStrSet = [...new Set(sortedImportTypeArr)];
|
|
9
|
+
if (importStrSet.length < 5) {
|
|
10
|
+
return `import { ${importStrSet.join(", ")} } from '../@types/data-contracts';`;
|
|
11
|
+
}
|
|
12
|
+
return `import {
|
|
13
|
+
${importStrSet.join(",\n ")}
|
|
14
|
+
} from '../@types/data-contracts';`;
|
|
15
|
+
};
|
|
16
|
+
return `import { instance } from "@/configs/axios/instance"
|
|
17
|
+
import { ContentType, HttpClient, RequestParams } from '../@http-client';
|
|
18
|
+
${importTypeArr.length === 0 ? "" : `${genImportArr()}`}
|
|
19
|
+
export class ${apiName}Api<
|
|
20
|
+
SecurityDataType = unknown,
|
|
21
|
+
> extends HttpClient<SecurityDataType> {
|
|
22
|
+
${queries.join("\n")}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const ${camelCase(apiName.toLocaleLowerCase())}Api = new ${apiName}Api({ instance });`;
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=queryApiClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryApiClient.js","sourceRoot":"","sources":["../../../../src/template/api/gen/queryApiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAE,OAAiB,EAAE,aAAuB,EAAE,EAAE;IAC/F,MAAM,YAAY,GAAG,GAAG,EAAE;QACxB,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,OAAO,EAAE,CAAA;QACX,CAAC;QAED,MAAM,mBAAmB,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;QAC5E,MAAM,YAAY,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,mBAAmB,CAAC,CAAC,CAAA;QACtD,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,OAAO,YAAY,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,qCAAqC,CAAA;QACjF,CAAC;QACD,OAAO;IACP,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC;mCACK,CAAA;IACjC,CAAC,CAAA;IACD,OAAO;;EAEP,aAAa,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,YAAY,EAAE,EAAE;eACxC,OAAO;;;GAGnB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;;;eAGN,SAAS,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC,aAAa,OAAO,oBAAoB,CAAA;AAC7F,CAAC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type QueryMethodInfo = {
|
|
2
|
+
operationId: string;
|
|
3
|
+
method: string;
|
|
4
|
+
hasQuery: boolean;
|
|
5
|
+
hasPathParams: boolean;
|
|
6
|
+
responseType: string;
|
|
7
|
+
errorType: string;
|
|
8
|
+
comments: string[];
|
|
9
|
+
isInfinite: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare const genQueryReactQueryClient: (apiName: string, methods: QueryMethodInfo[], importErrorTypeArr: string[]) => string;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=queryReactQueryClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryReactQueryClient.d.ts","sourceRoot":"","sources":["../../../../src/template/api/gen/queryReactQueryClient.ts"],"names":[],"mappings":"AAEA,KAAK,eAAe,GAAG;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,OAAO,CAAA;IACjB,aAAa,EAAE,OAAO,CAAA;IACtB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,UAAU,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,wBAAwB,GAAI,SAAS,MAAM,EAAE,SAAS,eAAe,EAAE,EAAE,oBAAoB,MAAM,EAAE,WAoKjH,CAAA"}
|