@intlayer/engine 9.8.0 → 9.8.2
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/assets/initConfig/templates/cjs.txt +16 -15
- package/dist/assets/initConfig/templates/json.txt +8 -7
- package/dist/assets/initConfig/templates/mjs.txt +16 -15
- package/dist/assets/initConfig/templates/ts.txt +16 -15
- package/dist/cjs/_virtual/_utils_asset.cjs +1 -1
- package/dist/cjs/build.cjs +9 -9
- package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs +3 -3
- package/dist/cjs/buildIntlayerDictionary/writeFetchDictionary.cjs +2 -2
- package/dist/cjs/buildIntlayerDictionary/writeMergedDictionary.cjs +2 -2
- package/dist/cjs/buildIntlayerDictionary/writeNestedDictionary.cjs +2 -2
- package/dist/cjs/buildIntlayerDictionary/writeRemoteDictionary.cjs +2 -2
- package/dist/cjs/buildIntlayerDictionary/writeUnmergedDictionary.cjs +2 -2
- package/dist/cjs/cleanOutputDir.cjs +1 -1
- package/dist/cjs/cleanRemovedContentDeclaration.cjs +1 -1
- package/dist/cjs/cli.cjs +22 -7
- package/dist/cjs/createDictionaryEntryPoint/createDictionaryEntryPoint.cjs +1 -1
- package/dist/cjs/createDictionaryEntryPoint/getBuiltDictionariesPath.cjs +2 -2
- package/dist/cjs/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.cjs +2 -2
- package/dist/cjs/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.cjs +2 -2
- package/dist/cjs/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.cjs +2 -2
- package/dist/cjs/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.cjs +2 -2
- package/dist/cjs/createType/createModuleAugmentation.cjs +1 -1
- package/dist/cjs/createType/createType.cjs +1 -1
- package/dist/cjs/detectFormatCommand.cjs +45 -0
- package/dist/cjs/detectFormatCommand.cjs.map +1 -1
- package/dist/cjs/handleContentDeclarationFileChange.cjs +2 -2
- package/dist/cjs/init/aiSetup.cjs +280 -0
- package/dist/cjs/init/aiSetup.cjs.map +1 -0
- package/dist/cjs/init/cms.cjs +50 -6
- package/dist/cjs/init/cms.cjs.map +1 -1
- package/dist/cjs/init/frameworkSetup/nextAppRouter/index.cjs +2 -2
- package/dist/cjs/init/frameworkSetup/nextAppRouter/restructure.cjs +1 -1
- package/dist/cjs/init/frameworkSetup/tanstackStart/index.cjs +1 -1
- package/dist/cjs/init/frameworkSetup/tanstackStart/restructure.cjs +1 -1
- package/dist/cjs/init/index.cjs +29 -3
- package/dist/cjs/init/index.cjs.map +1 -1
- package/dist/cjs/init/utils/configManipulation.cjs +47 -10
- package/dist/cjs/init/utils/configManipulation.cjs.map +1 -1
- package/dist/cjs/init/utils/fileSystem.cjs +2 -2
- package/dist/cjs/init/utils/githubActions.cjs +1 -1
- package/dist/cjs/init/utils/index.cjs +11 -0
- package/dist/cjs/init/utils/intlayerDependencies.cjs +2 -2
- package/dist/cjs/init/utils/packageManager.cjs +1 -1
- package/dist/cjs/init/utils/toolConfigManipulation.cjs +247 -0
- package/dist/cjs/init/utils/toolConfigManipulation.cjs.map +1 -0
- package/dist/cjs/initConfig/index.cjs +1 -1
- package/dist/cjs/installLSP.cjs +1 -1
- package/dist/cjs/installMCP/installMCP.cjs +44 -2
- package/dist/cjs/installMCP/installMCP.cjs.map +1 -1
- package/dist/cjs/installSkills/index.cjs +1 -1
- package/dist/cjs/listGitFiles.cjs +1 -1
- package/dist/cjs/loadDictionaries/getIntlayerBundle.cjs +1 -1
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +1 -1
- package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs +1 -1
- package/dist/cjs/loadDictionaries/log.cjs +1 -1
- package/dist/cjs/prepareIntlayer.cjs +2 -2
- package/dist/cjs/scan/index.cjs +7 -7
- package/dist/cjs/syncPluginKit/createFileAdapter.cjs +1 -1
- package/dist/cjs/utils/buildComponentFilesList.cjs +1 -1
- package/dist/cjs/utils/contentWatcherLock.cjs +2 -2
- package/dist/cjs/utils/readDictionariesFromDisk.cjs +1 -1
- package/dist/cjs/utils/runOnce.cjs +2 -2
- package/dist/cjs/utils/withFileLock.cjs +2 -2
- package/dist/cjs/watcher.cjs +4 -4
- package/dist/cjs/writeConfiguration/index.cjs +2 -2
- package/dist/cjs/writeContentDeclaration/processContentDeclarationContent.cjs +1 -1
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +3 -12
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +3 -12
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeMarkdownFile.cjs +2 -11
- package/dist/cjs/writeContentDeclaration/writeMarkdownFile.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeYamlFile.cjs +2 -11
- package/dist/cjs/writeContentDeclaration/writeYamlFile.cjs.map +1 -1
- package/dist/cjs/writeFileIfChanged.cjs +2 -2
- package/dist/esm/_virtual/_utils_asset.mjs +1 -1
- package/dist/esm/build.mjs +9 -9
- package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs +3 -3
- package/dist/esm/buildIntlayerDictionary/writeFetchDictionary.mjs +2 -2
- package/dist/esm/buildIntlayerDictionary/writeMergedDictionary.mjs +2 -2
- package/dist/esm/buildIntlayerDictionary/writeNestedDictionary.mjs +2 -2
- package/dist/esm/buildIntlayerDictionary/writeRemoteDictionary.mjs +2 -2
- package/dist/esm/buildIntlayerDictionary/writeUnmergedDictionary.mjs +2 -2
- package/dist/esm/cleanOutputDir.mjs +1 -1
- package/dist/esm/cleanRemovedContentDeclaration.mjs +1 -1
- package/dist/esm/cli.mjs +12 -11
- package/dist/esm/createDictionaryEntryPoint/createDictionaryEntryPoint.mjs +1 -1
- package/dist/esm/createDictionaryEntryPoint/getBuiltDictionariesPath.mjs +2 -2
- package/dist/esm/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.mjs +2 -2
- package/dist/esm/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.mjs +2 -2
- package/dist/esm/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.mjs +2 -2
- package/dist/esm/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.mjs +2 -2
- package/dist/esm/createType/createModuleAugmentation.mjs +1 -1
- package/dist/esm/createType/createType.mjs +1 -1
- package/dist/esm/detectFormatCommand.mjs +43 -1
- package/dist/esm/detectFormatCommand.mjs.map +1 -1
- package/dist/esm/handleContentDeclarationFileChange.mjs +2 -2
- package/dist/esm/init/aiSetup.mjs +270 -0
- package/dist/esm/init/aiSetup.mjs.map +1 -0
- package/dist/esm/init/cms.mjs +50 -8
- package/dist/esm/init/cms.mjs.map +1 -1
- package/dist/esm/init/frameworkSetup/nextAppRouter/index.mjs +2 -2
- package/dist/esm/init/frameworkSetup/nextAppRouter/restructure.mjs +1 -1
- package/dist/esm/init/frameworkSetup/tanstackStart/index.mjs +1 -1
- package/dist/esm/init/frameworkSetup/tanstackStart/restructure.mjs +1 -1
- package/dist/esm/init/index.mjs +29 -3
- package/dist/esm/init/index.mjs.map +1 -1
- package/dist/esm/init/utils/configManipulation.mjs +47 -11
- package/dist/esm/init/utils/configManipulation.mjs.map +1 -1
- package/dist/esm/init/utils/fileSystem.mjs +2 -2
- package/dist/esm/init/utils/githubActions.mjs +1 -1
- package/dist/esm/init/utils/index.mjs +3 -2
- package/dist/esm/init/utils/intlayerDependencies.mjs +2 -2
- package/dist/esm/init/utils/packageManager.mjs +1 -1
- package/dist/esm/init/utils/toolConfigManipulation.mjs +236 -0
- package/dist/esm/init/utils/toolConfigManipulation.mjs.map +1 -0
- package/dist/esm/initConfig/index.mjs +1 -1
- package/dist/esm/installLSP.mjs +1 -1
- package/dist/esm/installMCP/installMCP.mjs +44 -3
- package/dist/esm/installMCP/installMCP.mjs.map +1 -1
- package/dist/esm/installSkills/index.mjs +1 -1
- package/dist/esm/listGitFiles.mjs +1 -1
- package/dist/esm/loadDictionaries/getIntlayerBundle.mjs +1 -1
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +1 -1
- package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs +1 -1
- package/dist/esm/loadDictionaries/log.mjs +1 -1
- package/dist/esm/prepareIntlayer.mjs +2 -2
- package/dist/esm/scan/index.mjs +7 -7
- package/dist/esm/syncPluginKit/createFileAdapter.mjs +1 -1
- package/dist/esm/utils/buildComponentFilesList.mjs +1 -1
- package/dist/esm/utils/contentWatcherLock.mjs +2 -2
- package/dist/esm/utils/readDictionariesFromDisk.mjs +1 -1
- package/dist/esm/utils/runOnce.mjs +2 -2
- package/dist/esm/utils/withFileLock.mjs +2 -2
- package/dist/esm/watcher.mjs +4 -4
- package/dist/esm/writeConfiguration/index.mjs +2 -2
- package/dist/esm/writeContentDeclaration/processContentDeclarationContent.mjs +1 -1
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +4 -13
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs +4 -13
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeMarkdownFile.mjs +3 -12
- package/dist/esm/writeContentDeclaration/writeMarkdownFile.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeYamlFile.mjs +3 -12
- package/dist/esm/writeContentDeclaration/writeYamlFile.mjs.map +1 -1
- package/dist/esm/writeFileIfChanged.mjs +2 -2
- package/dist/types/build.d.ts +15 -15
- package/dist/types/cli.d.ts +14 -13
- package/dist/types/detectFormatCommand.d.ts +24 -0
- package/dist/types/detectFormatCommand.d.ts.map +1 -1
- package/dist/types/init/aiSetup.d.ts +69 -0
- package/dist/types/init/aiSetup.d.ts.map +1 -0
- package/dist/types/init/cms.d.ts +13 -1
- package/dist/types/init/cms.d.ts.map +1 -1
- package/dist/types/init/index.d.ts.map +1 -1
- package/dist/types/init/utils/configManipulation.d.ts +14 -0
- package/dist/types/init/utils/configManipulation.d.ts.map +1 -1
- package/dist/types/init/utils/index.d.ts +3 -2
- package/dist/types/init/utils/toolConfigManipulation.d.ts +46 -0
- package/dist/types/init/utils/toolConfigManipulation.d.ts.map +1 -0
- package/dist/types/installMCP/installMCP.d.ts +6 -0
- package/dist/types/installMCP/installMCP.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +1 -1
- package/dist/types/scan/index.d.ts +2 -2
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts +1 -1
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/writeJSFile.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/writeMarkdownFile.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/writeYamlFile.d.ts.map +1 -1
- package/package.json +10 -10
|
@@ -8,9 +8,9 @@ const require_createType_createModuleAugmentation = require("./createType/create
|
|
|
8
8
|
const require_loadDictionaries_loadLocalDictionaries = require("./loadDictionaries/loadLocalDictionaries.cjs");
|
|
9
9
|
const require_utils_formatter = require("./utils/formatter.cjs");
|
|
10
10
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
11
|
-
let node_fs = require("node:fs");
|
|
12
|
-
let node_path = require("node:path");
|
|
13
11
|
let node_fs_promises = require("node:fs/promises");
|
|
12
|
+
let node_path = require("node:path");
|
|
13
|
+
let node_fs = require("node:fs");
|
|
14
14
|
|
|
15
15
|
// src/handleContentDeclarationFileChange.ts
|
|
16
16
|
/**
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_init_cms = require("./cms.cjs");
|
|
4
|
+
const require_init_utils_fileSystem = require("./utils/fileSystem.cjs");
|
|
5
|
+
const require_init_utils_packageManager = require("./utils/packageManager.cjs");
|
|
6
|
+
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
7
|
+
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
8
|
+
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
9
|
+
let _intlayer_types_config = require("@intlayer/types/config");
|
|
10
|
+
|
|
11
|
+
// src/init/aiSetup.ts
|
|
12
|
+
/** Package running the AI commands locally with the user's own key. */
|
|
13
|
+
const AI_PACKAGE_NAME = "@intlayer/ai";
|
|
14
|
+
/** `Authorization: Bearer` header, only when a key is given. */
|
|
15
|
+
const bearer = (apiKey) => apiKey ? { Authorization: `Bearer ${apiKey}` } : {};
|
|
16
|
+
/** Lists models from the Google Generative AI API. */
|
|
17
|
+
const getGoogleModelsRequest = (apiKey) => ({ url: `https://generativelanguage.googleapis.com/v1beta/models?key=${encodeURIComponent(apiKey ?? "")}` });
|
|
18
|
+
/** Providers offered by `intlayer init ai`, in display order. */
|
|
19
|
+
const AI_PROVIDER_SETUPS = [
|
|
20
|
+
{
|
|
21
|
+
provider: _intlayer_types_config.AiProviders.ANTHROPIC,
|
|
22
|
+
label: "Anthropic",
|
|
23
|
+
apiKeyEnvironmentVariable: "ANTHROPIC_API_KEY",
|
|
24
|
+
apiKeyPlaceholder: "sk-ant-",
|
|
25
|
+
apiKeyUrl: "https://console.anthropic.com/settings/keys",
|
|
26
|
+
getModelsRequest: (apiKey) => ({
|
|
27
|
+
url: "https://api.anthropic.com/v1/models?limit=100",
|
|
28
|
+
headers: {
|
|
29
|
+
"x-api-key": apiKey ?? "",
|
|
30
|
+
"anthropic-version": "2023-06-01"
|
|
31
|
+
}
|
|
32
|
+
}),
|
|
33
|
+
suggestedModels: [
|
|
34
|
+
"claude-haiku-5-5",
|
|
35
|
+
"claude-sonnet-5-5",
|
|
36
|
+
"claude-opus-5-5"
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
provider: _intlayer_types_config.AiProviders.OPENAI,
|
|
41
|
+
label: "OpenAI",
|
|
42
|
+
apiKeyEnvironmentVariable: "OPENAI_API_KEY",
|
|
43
|
+
apiKeyPlaceholder: "sk-",
|
|
44
|
+
apiKeyUrl: "https://platform.openai.com/api-keys",
|
|
45
|
+
getModelsRequest: (apiKey) => ({
|
|
46
|
+
url: "https://api.openai.com/v1/models",
|
|
47
|
+
headers: bearer(apiKey)
|
|
48
|
+
}),
|
|
49
|
+
suggestedModels: ["gpt-5.6-terra"]
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
provider: _intlayer_types_config.AiProviders.GEMINI,
|
|
53
|
+
label: "Google Gemini",
|
|
54
|
+
sdkPackage: "@ai-sdk/google",
|
|
55
|
+
apiKeyEnvironmentVariable: "GOOGLE_GENERATIVE_AI_API_KEY",
|
|
56
|
+
apiKeyUrl: "https://aistudio.google.com/apikey",
|
|
57
|
+
getModelsRequest: getGoogleModelsRequest,
|
|
58
|
+
suggestedModels: []
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
provider: _intlayer_types_config.AiProviders.MISTRAL,
|
|
62
|
+
label: "Mistral",
|
|
63
|
+
sdkPackage: "@ai-sdk/mistral",
|
|
64
|
+
apiKeyEnvironmentVariable: "MISTRAL_API_KEY",
|
|
65
|
+
apiKeyUrl: "https://console.mistral.ai/api-keys",
|
|
66
|
+
getModelsRequest: (apiKey) => ({
|
|
67
|
+
url: "https://api.mistral.ai/v1/models",
|
|
68
|
+
headers: bearer(apiKey)
|
|
69
|
+
}),
|
|
70
|
+
suggestedModels: []
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
provider: _intlayer_types_config.AiProviders.DEEPSEEK,
|
|
74
|
+
label: "DeepSeek",
|
|
75
|
+
sdkPackage: "@ai-sdk/deepseek",
|
|
76
|
+
apiKeyEnvironmentVariable: "DEEPSEEK_API_KEY",
|
|
77
|
+
apiKeyPlaceholder: "sk-",
|
|
78
|
+
apiKeyUrl: "https://platform.deepseek.com/api_keys",
|
|
79
|
+
getModelsRequest: (apiKey) => ({
|
|
80
|
+
url: "https://api.deepseek.com/models",
|
|
81
|
+
headers: bearer(apiKey)
|
|
82
|
+
}),
|
|
83
|
+
suggestedModels: []
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
provider: _intlayer_types_config.AiProviders.OPENROUTER,
|
|
87
|
+
label: "OpenRouter",
|
|
88
|
+
sdkPackage: "@openrouter/ai-sdk-provider",
|
|
89
|
+
apiKeyEnvironmentVariable: "OPENROUTER_API_KEY",
|
|
90
|
+
apiKeyPlaceholder: "sk-or-",
|
|
91
|
+
apiKeyUrl: "https://openrouter.ai/settings/keys",
|
|
92
|
+
getModelsRequest: () => ({ url: "https://openrouter.ai/api/v1/models" }),
|
|
93
|
+
suggestedModels: []
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
provider: _intlayer_types_config.AiProviders.GROQ,
|
|
97
|
+
label: "Groq",
|
|
98
|
+
sdkPackage: "@ai-sdk/groq",
|
|
99
|
+
apiKeyEnvironmentVariable: "GROQ_API_KEY",
|
|
100
|
+
apiKeyPlaceholder: "gsk_",
|
|
101
|
+
apiKeyUrl: "https://console.groq.com/keys",
|
|
102
|
+
getModelsRequest: (apiKey) => ({
|
|
103
|
+
url: "https://api.groq.com/openai/v1/models",
|
|
104
|
+
headers: bearer(apiKey)
|
|
105
|
+
}),
|
|
106
|
+
suggestedModels: []
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
provider: _intlayer_types_config.AiProviders.FIREWORKS,
|
|
110
|
+
label: "Fireworks",
|
|
111
|
+
sdkPackage: "@ai-sdk/fireworks",
|
|
112
|
+
apiKeyEnvironmentVariable: "FIREWORKS_API_KEY",
|
|
113
|
+
apiKeyUrl: "https://app.fireworks.ai/settings/users/api-keys",
|
|
114
|
+
getModelsRequest: (apiKey) => ({
|
|
115
|
+
url: "https://api.fireworks.ai/inference/v1/models",
|
|
116
|
+
headers: bearer(apiKey)
|
|
117
|
+
}),
|
|
118
|
+
suggestedModels: []
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
provider: _intlayer_types_config.AiProviders.TOGETHERAI,
|
|
122
|
+
label: "Together AI",
|
|
123
|
+
sdkPackage: "@ai-sdk/togetherai",
|
|
124
|
+
apiKeyEnvironmentVariable: "TOGETHER_AI_API_KEY",
|
|
125
|
+
apiKeyUrl: "https://api.together.ai/settings/api-keys",
|
|
126
|
+
getModelsRequest: (apiKey) => ({
|
|
127
|
+
url: "https://api.together.xyz/v1/models",
|
|
128
|
+
headers: bearer(apiKey)
|
|
129
|
+
}),
|
|
130
|
+
suggestedModels: []
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
provider: _intlayer_types_config.AiProviders.MOONSHOTAI,
|
|
134
|
+
label: "Moonshot AI",
|
|
135
|
+
sdkPackage: "@ai-sdk/moonshotai",
|
|
136
|
+
apiKeyEnvironmentVariable: "MOONSHOT_API_KEY",
|
|
137
|
+
apiKeyPlaceholder: "sk-",
|
|
138
|
+
apiKeyUrl: "https://platform.moonshot.ai/console/api-keys",
|
|
139
|
+
getModelsRequest: (apiKey) => ({
|
|
140
|
+
url: "https://api.moonshot.ai/v1/models",
|
|
141
|
+
headers: bearer(apiKey)
|
|
142
|
+
}),
|
|
143
|
+
suggestedModels: []
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
provider: _intlayer_types_config.AiProviders.ALIBABA,
|
|
147
|
+
label: "Alibaba (Qwen)",
|
|
148
|
+
sdkPackage: "@ai-sdk/alibaba",
|
|
149
|
+
apiKeyEnvironmentVariable: "ALIBABA_API_KEY",
|
|
150
|
+
apiKeyPlaceholder: "sk-",
|
|
151
|
+
getModelsRequest: (apiKey) => ({
|
|
152
|
+
url: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models",
|
|
153
|
+
headers: bearer(apiKey)
|
|
154
|
+
}),
|
|
155
|
+
suggestedModels: []
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
provider: _intlayer_types_config.AiProviders.HUGGINGFACE,
|
|
159
|
+
label: "Hugging Face",
|
|
160
|
+
sdkPackage: "@ai-sdk/huggingface",
|
|
161
|
+
apiKeyEnvironmentVariable: "HUGGINGFACE_API_KEY",
|
|
162
|
+
apiKeyPlaceholder: "hf_",
|
|
163
|
+
apiKeyUrl: "https://huggingface.co/settings/tokens",
|
|
164
|
+
suggestedModels: []
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
provider: _intlayer_types_config.AiProviders.BEDROCK,
|
|
168
|
+
label: "Amazon Bedrock",
|
|
169
|
+
sdkPackage: "@ai-sdk/amazon-bedrock",
|
|
170
|
+
suggestedModels: []
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
provider: _intlayer_types_config.AiProviders.GOOGLEVERTEX,
|
|
174
|
+
label: "Google Vertex AI",
|
|
175
|
+
sdkPackage: "@ai-sdk/google-vertex",
|
|
176
|
+
suggestedModels: []
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
provider: _intlayer_types_config.AiProviders.OLLAMA,
|
|
180
|
+
label: "Ollama (local)",
|
|
181
|
+
getModelsRequest: () => ({ url: "http://localhost:11434/v1/models" }),
|
|
182
|
+
suggestedModels: []
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
provider: _intlayer_types_config.AiProviders.LMSTUDIO,
|
|
186
|
+
label: "LM Studio (local)",
|
|
187
|
+
sdkPackage: "@ai-sdk/openai-compatible",
|
|
188
|
+
getModelsRequest: () => ({ url: "http://localhost:1234/v1/models" }),
|
|
189
|
+
suggestedModels: []
|
|
190
|
+
}
|
|
191
|
+
];
|
|
192
|
+
/** Providers accepted by `--provider`. */
|
|
193
|
+
const AI_PROVIDER_CHOICES = AI_PROVIDER_SETUPS.map(({ provider }) => provider);
|
|
194
|
+
/** Looks up the setup of a provider. */
|
|
195
|
+
const getAiProviderSetup = (provider) => AI_PROVIDER_SETUPS.find((setup) => setup.provider === provider);
|
|
196
|
+
/**
|
|
197
|
+
* Reads model ids out of a `/models` response: OpenAI-style `{ data: [{ id }] }`,
|
|
198
|
+
* Google-style `{ models: [{ name: 'models/…' }] }`, or a bare array.
|
|
199
|
+
*/
|
|
200
|
+
const parseModelIds = (body) => {
|
|
201
|
+
const modelIds = (Array.isArray(body) ? body : typeof body === "object" && body !== null ? body.data ?? body.models ?? [] : []).map((entry) => {
|
|
202
|
+
if (typeof entry !== "object" || entry === null) return void 0;
|
|
203
|
+
const { id, name } = entry;
|
|
204
|
+
const modelId = typeof id === "string" ? id : name;
|
|
205
|
+
return typeof modelId === "string" ? modelId.replace(/^models\//, "") : void 0;
|
|
206
|
+
}).filter((modelId) => Boolean(modelId));
|
|
207
|
+
return [...new Set(modelIds)].sort((first, second) => first.localeCompare(second));
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Lists the models available to the given key from the provider API. Resolves
|
|
211
|
+
* to an empty list when the provider has no listing endpoint, the key is
|
|
212
|
+
* rejected or the API cannot be reached.
|
|
213
|
+
*/
|
|
214
|
+
const fetchAiProviderModels = async (provider, apiKey) => {
|
|
215
|
+
const request = getAiProviderSetup(provider)?.getModelsRequest?.(apiKey);
|
|
216
|
+
if (!request) return [];
|
|
217
|
+
try {
|
|
218
|
+
const response = await fetch(request.url, {
|
|
219
|
+
headers: request.headers,
|
|
220
|
+
signal: AbortSignal.timeout(1e4)
|
|
221
|
+
});
|
|
222
|
+
if (!response.ok) return [];
|
|
223
|
+
return parseModelIds(await response.json());
|
|
224
|
+
} catch {
|
|
225
|
+
return [];
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* Installs `@intlayer/ai` (runs the AI commands locally with the user's key)
|
|
230
|
+
* and the provider AI SDK when `@intlayer/ai` does not ship it, as dev
|
|
231
|
+
* dependencies. Already declared packages are skipped.
|
|
232
|
+
*/
|
|
233
|
+
const installAiProviderPackages = async (rootDir, provider, version) => {
|
|
234
|
+
const setup = getAiProviderSetup(provider);
|
|
235
|
+
const packageJson = JSON.parse(await require_init_utils_fileSystem.readFileFromRoot(rootDir, "package.json"));
|
|
236
|
+
const declaredDependencies = {
|
|
237
|
+
...packageJson.dependencies,
|
|
238
|
+
...packageJson.devDependencies
|
|
239
|
+
};
|
|
240
|
+
const packagesToInstall = [AI_PACKAGE_NAME, setup?.sdkPackage].filter((packageName) => Boolean(packageName)).filter((packageName) => !declaredDependencies[packageName]);
|
|
241
|
+
if (packagesToInstall.length === 0) {
|
|
242
|
+
(0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.v} AI packages already installed`);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const packageSpecifiers = packagesToInstall.map((packageName) => version && require_init_utils_packageManager.isIntlayerPackageName(packageName) ? `${packageName}@${version}` : packageName);
|
|
246
|
+
try {
|
|
247
|
+
require_init_utils_packageManager.installPackages(rootDir, packageSpecifiers, require_init_utils_packageManager.detectPackageManager(rootDir), true);
|
|
248
|
+
(0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.v} Installed: ${packagesToInstall.map((packageName) => (0, _intlayer_config_logger.colorize)(packageName, _intlayer_config_colors.MAGENTA)).join(", ")}`);
|
|
249
|
+
} catch {
|
|
250
|
+
(0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.x} Failed to install the AI packages. Please install them manually: ${packageSpecifiers.join(" ")}`, { level: "warn" });
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* Persists an AI provider setup: the API key to the environment file (e.g.
|
|
255
|
+
* `ANTHROPIC_API_KEY=sk-ant-…` in `.env`) and the provider, model and
|
|
256
|
+
* `process.env` key reference to the `ai` block of the Intlayer config.
|
|
257
|
+
*/
|
|
258
|
+
const setupAiProvider = async (rootDir, { provider, model, apiKey }) => {
|
|
259
|
+
const apiKeyEnvironmentVariable = getAiProviderSetup(provider)?.apiKeyEnvironmentVariable;
|
|
260
|
+
if (apiKey && apiKeyEnvironmentVariable) {
|
|
261
|
+
const envFile = await require_init_cms.writeEnvVariables(rootDir, { [apiKeyEnvironmentVariable]: apiKey });
|
|
262
|
+
(0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.v} Saved ${(0, _intlayer_config_logger.colorize)(apiKeyEnvironmentVariable, _intlayer_config_colors.GREY_LIGHT)} to ${(0, _intlayer_config_logger.colorizePath)(envFile)}`);
|
|
263
|
+
}
|
|
264
|
+
await require_init_cms.setAiInConfig(rootDir, {
|
|
265
|
+
provider,
|
|
266
|
+
model,
|
|
267
|
+
apiKeyEnvironmentVariable
|
|
268
|
+
});
|
|
269
|
+
if (!apiKey && apiKeyEnvironmentVariable) (0, _intlayer_config_logger.logger)(`Set ${(0, _intlayer_config_logger.colorize)(`${apiKeyEnvironmentVariable}=…`, _intlayer_config_colors.GREY_LIGHT)} in your ${(0, _intlayer_config_logger.colorizePath)(".env")} to enable the AI features.`);
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
exports.AI_PACKAGE_NAME = AI_PACKAGE_NAME;
|
|
273
|
+
exports.AI_PROVIDER_CHOICES = AI_PROVIDER_CHOICES;
|
|
274
|
+
exports.AI_PROVIDER_SETUPS = AI_PROVIDER_SETUPS;
|
|
275
|
+
exports.fetchAiProviderModels = fetchAiProviderModels;
|
|
276
|
+
exports.getAiProviderSetup = getAiProviderSetup;
|
|
277
|
+
exports.installAiProviderPackages = installAiProviderPackages;
|
|
278
|
+
exports.parseModelIds = parseModelIds;
|
|
279
|
+
exports.setupAiProvider = setupAiProvider;
|
|
280
|
+
//# sourceMappingURL=aiSetup.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aiSetup.cjs","names":["AiProviders","readFileFromRoot","v","isIntlayerPackageName","detectPackageManager","colorize","ANSIColors","x","writeEnvVariables","colorizePath","setAiInConfig"],"sources":["../../../src/init/aiSetup.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, colorizePath, logger, v, x } from '@intlayer/config/logger';\nimport { AiProviders } from '@intlayer/types/config';\nimport { setAiInConfig, writeEnvVariables } from './cms';\nimport { readFileFromRoot } from './utils/fileSystem';\nimport {\n detectPackageManager,\n installPackages,\n isIntlayerPackageName,\n} from './utils/packageManager';\n\n/** Package running the AI commands locally with the user's own key. */\nexport const AI_PACKAGE_NAME = '@intlayer/ai';\n\n/** Request listing the models of a provider. */\ntype ModelsRequest = {\n url: string;\n headers?: Record<string, string>;\n};\n\n/** Everything `intlayer init ai` needs to know about a provider. */\nexport type AiProviderSetup = {\n provider: `${AiProviders}`;\n label: string;\n /**\n * AI SDK package to install. `undefined` when `@intlayer/ai` already ships\n * it (Anthropic, OpenAI and the OpenAI-compatible Ollama).\n */\n sdkPackage?: string;\n /**\n * Environment variable the API key is stored in. `undefined` for local\n * runtimes and cloud providers authenticated by their own credentials.\n */\n apiKeyEnvironmentVariable?: string;\n /** Start of a valid key, shown as the input placeholder. */\n apiKeyPlaceholder?: string;\n /** Where the user creates an API key. */\n apiKeyUrl?: string;\n /** Builds the request listing the available models, when the API has one. */\n getModelsRequest?: (apiKey?: string) => ModelsRequest;\n /** Models suggested when the list cannot be fetched (first is default). */\n suggestedModels: string[];\n};\n\n/** `Authorization: Bearer` header, only when a key is given. */\nconst bearer = (apiKey?: string): Record<string, string> =>\n apiKey ? { Authorization: `Bearer ${apiKey}` } : {};\n\n/** Lists models from the Google Generative AI API. */\nconst getGoogleModelsRequest = (apiKey?: string): ModelsRequest => ({\n url: `https://generativelanguage.googleapis.com/v1beta/models?key=${encodeURIComponent(apiKey ?? '')}`,\n});\n\n/** Providers offered by `intlayer init ai`, in display order. */\nexport const AI_PROVIDER_SETUPS: AiProviderSetup[] = [\n {\n provider: AiProviders.ANTHROPIC,\n label: 'Anthropic',\n apiKeyEnvironmentVariable: 'ANTHROPIC_API_KEY',\n apiKeyPlaceholder: 'sk-ant-',\n apiKeyUrl: 'https://console.anthropic.com/settings/keys',\n getModelsRequest: (apiKey) => ({\n url: 'https://api.anthropic.com/v1/models?limit=100',\n headers: {\n 'x-api-key': apiKey ?? '',\n 'anthropic-version': '2023-06-01',\n },\n }),\n suggestedModels: [\n 'claude-haiku-5-5',\n 'claude-sonnet-5-5',\n 'claude-opus-5-5',\n ],\n },\n {\n provider: AiProviders.OPENAI,\n label: 'OpenAI',\n apiKeyEnvironmentVariable: 'OPENAI_API_KEY',\n apiKeyPlaceholder: 'sk-',\n apiKeyUrl: 'https://platform.openai.com/api-keys',\n getModelsRequest: (apiKey) => ({\n url: 'https://api.openai.com/v1/models',\n headers: bearer(apiKey),\n }),\n suggestedModels: ['gpt-5.6-terra'],\n },\n {\n provider: AiProviders.GEMINI,\n label: 'Google Gemini',\n sdkPackage: '@ai-sdk/google',\n apiKeyEnvironmentVariable: 'GOOGLE_GENERATIVE_AI_API_KEY',\n apiKeyUrl: 'https://aistudio.google.com/apikey',\n getModelsRequest: getGoogleModelsRequest,\n suggestedModels: [],\n },\n {\n provider: AiProviders.MISTRAL,\n label: 'Mistral',\n sdkPackage: '@ai-sdk/mistral',\n apiKeyEnvironmentVariable: 'MISTRAL_API_KEY',\n apiKeyUrl: 'https://console.mistral.ai/api-keys',\n getModelsRequest: (apiKey) => ({\n url: 'https://api.mistral.ai/v1/models',\n headers: bearer(apiKey),\n }),\n suggestedModels: [],\n },\n {\n provider: AiProviders.DEEPSEEK,\n label: 'DeepSeek',\n sdkPackage: '@ai-sdk/deepseek',\n apiKeyEnvironmentVariable: 'DEEPSEEK_API_KEY',\n apiKeyPlaceholder: 'sk-',\n apiKeyUrl: 'https://platform.deepseek.com/api_keys',\n getModelsRequest: (apiKey) => ({\n url: 'https://api.deepseek.com/models',\n headers: bearer(apiKey),\n }),\n suggestedModels: [],\n },\n {\n provider: AiProviders.OPENROUTER,\n label: 'OpenRouter',\n sdkPackage: '@openrouter/ai-sdk-provider',\n apiKeyEnvironmentVariable: 'OPENROUTER_API_KEY',\n apiKeyPlaceholder: 'sk-or-',\n apiKeyUrl: 'https://openrouter.ai/settings/keys',\n getModelsRequest: () => ({ url: 'https://openrouter.ai/api/v1/models' }),\n suggestedModels: [],\n },\n {\n provider: AiProviders.GROQ,\n label: 'Groq',\n sdkPackage: '@ai-sdk/groq',\n apiKeyEnvironmentVariable: 'GROQ_API_KEY',\n apiKeyPlaceholder: 'gsk_',\n apiKeyUrl: 'https://console.groq.com/keys',\n getModelsRequest: (apiKey) => ({\n url: 'https://api.groq.com/openai/v1/models',\n headers: bearer(apiKey),\n }),\n suggestedModels: [],\n },\n {\n provider: AiProviders.FIREWORKS,\n label: 'Fireworks',\n sdkPackage: '@ai-sdk/fireworks',\n apiKeyEnvironmentVariable: 'FIREWORKS_API_KEY',\n apiKeyUrl: 'https://app.fireworks.ai/settings/users/api-keys',\n getModelsRequest: (apiKey) => ({\n url: 'https://api.fireworks.ai/inference/v1/models',\n headers: bearer(apiKey),\n }),\n suggestedModels: [],\n },\n {\n provider: AiProviders.TOGETHERAI,\n label: 'Together AI',\n sdkPackage: '@ai-sdk/togetherai',\n apiKeyEnvironmentVariable: 'TOGETHER_AI_API_KEY',\n apiKeyUrl: 'https://api.together.ai/settings/api-keys',\n getModelsRequest: (apiKey) => ({\n url: 'https://api.together.xyz/v1/models',\n headers: bearer(apiKey),\n }),\n suggestedModels: [],\n },\n {\n provider: AiProviders.MOONSHOTAI,\n label: 'Moonshot AI',\n sdkPackage: '@ai-sdk/moonshotai',\n apiKeyEnvironmentVariable: 'MOONSHOT_API_KEY',\n apiKeyPlaceholder: 'sk-',\n apiKeyUrl: 'https://platform.moonshot.ai/console/api-keys',\n getModelsRequest: (apiKey) => ({\n url: 'https://api.moonshot.ai/v1/models',\n headers: bearer(apiKey),\n }),\n suggestedModels: [],\n },\n {\n provider: AiProviders.ALIBABA,\n label: 'Alibaba (Qwen)',\n sdkPackage: '@ai-sdk/alibaba',\n apiKeyEnvironmentVariable: 'ALIBABA_API_KEY',\n apiKeyPlaceholder: 'sk-',\n getModelsRequest: (apiKey) => ({\n url: 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models',\n headers: bearer(apiKey),\n }),\n suggestedModels: [],\n },\n {\n provider: AiProviders.HUGGINGFACE,\n label: 'Hugging Face',\n sdkPackage: '@ai-sdk/huggingface',\n apiKeyEnvironmentVariable: 'HUGGINGFACE_API_KEY',\n apiKeyPlaceholder: 'hf_',\n apiKeyUrl: 'https://huggingface.co/settings/tokens',\n suggestedModels: [],\n },\n {\n provider: AiProviders.BEDROCK,\n label: 'Amazon Bedrock',\n sdkPackage: '@ai-sdk/amazon-bedrock',\n suggestedModels: [],\n },\n {\n provider: AiProviders.GOOGLEVERTEX,\n label: 'Google Vertex AI',\n sdkPackage: '@ai-sdk/google-vertex',\n suggestedModels: [],\n },\n {\n provider: AiProviders.OLLAMA,\n label: 'Ollama (local)',\n getModelsRequest: () => ({ url: 'http://localhost:11434/v1/models' }),\n suggestedModels: [],\n },\n {\n provider: AiProviders.LMSTUDIO,\n label: 'LM Studio (local)',\n sdkPackage: '@ai-sdk/openai-compatible',\n getModelsRequest: () => ({ url: 'http://localhost:1234/v1/models' }),\n suggestedModels: [],\n },\n];\n\n/** Providers accepted by `--provider`. */\nexport const AI_PROVIDER_CHOICES = AI_PROVIDER_SETUPS.map(\n ({ provider }) => provider\n);\n\n/** Looks up the setup of a provider. */\nexport const getAiProviderSetup = (\n provider: string\n): AiProviderSetup | undefined =>\n AI_PROVIDER_SETUPS.find((setup) => setup.provider === provider);\n\n/**\n * Reads model ids out of a `/models` response: OpenAI-style `{ data: [{ id }] }`,\n * Google-style `{ models: [{ name: 'models/…' }] }`, or a bare array.\n */\nexport const parseModelIds = (body: unknown): string[] => {\n const entries: unknown[] = Array.isArray(body)\n ? body\n : typeof body === 'object' && body !== null\n ? ((body as { data?: unknown[]; models?: unknown[] }).data ??\n (body as { models?: unknown[] }).models ??\n [])\n : [];\n\n const modelIds = entries\n .map((entry) => {\n if (typeof entry !== 'object' || entry === null) return undefined;\n const { id, name } = entry as { id?: unknown; name?: unknown };\n const modelId = typeof id === 'string' ? id : name;\n return typeof modelId === 'string'\n ? modelId.replace(/^models\\//, '')\n : undefined;\n })\n .filter((modelId): modelId is string => Boolean(modelId));\n\n return [...new Set(modelIds)].sort((first, second) =>\n first.localeCompare(second)\n );\n};\n\n/**\n * Lists the models available to the given key from the provider API. Resolves\n * to an empty list when the provider has no listing endpoint, the key is\n * rejected or the API cannot be reached.\n */\nexport const fetchAiProviderModels = async (\n provider: string,\n apiKey?: string\n): Promise<string[]> => {\n const request = getAiProviderSetup(provider)?.getModelsRequest?.(apiKey);\n\n if (!request) return [];\n\n try {\n const response = await fetch(request.url, {\n headers: request.headers,\n signal: AbortSignal.timeout(10_000),\n });\n\n if (!response.ok) return [];\n\n return parseModelIds(await response.json());\n } catch {\n return [];\n }\n};\n\n/**\n * Installs `@intlayer/ai` (runs the AI commands locally with the user's key)\n * and the provider AI SDK when `@intlayer/ai` does not ship it, as dev\n * dependencies. Already declared packages are skipped.\n */\nexport const installAiProviderPackages = async (\n rootDir: string,\n provider: string,\n version?: string\n): Promise<void> => {\n const setup = getAiProviderSetup(provider);\n const packageJson = JSON.parse(\n await readFileFromRoot(rootDir, 'package.json')\n ) as {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n };\n const declaredDependencies = {\n ...packageJson.dependencies,\n ...packageJson.devDependencies,\n };\n\n const packagesToInstall = [AI_PACKAGE_NAME, setup?.sdkPackage]\n .filter((packageName): packageName is string => Boolean(packageName))\n .filter((packageName) => !declaredDependencies[packageName]);\n\n if (packagesToInstall.length === 0) {\n logger(`${v} AI packages already installed`);\n return;\n }\n\n const packageSpecifiers = packagesToInstall.map((packageName) =>\n version && isIntlayerPackageName(packageName)\n ? `${packageName}@${version}`\n : packageName\n );\n\n try {\n installPackages(\n rootDir,\n packageSpecifiers,\n detectPackageManager(rootDir),\n true\n );\n logger(\n `${v} Installed: ${packagesToInstall.map((packageName) => colorize(packageName, ANSIColors.MAGENTA)).join(', ')}`\n );\n } catch {\n logger(\n `${x} Failed to install the AI packages. Please install them manually: ${packageSpecifiers.join(' ')}`,\n { level: 'warn' }\n );\n }\n};\n\n/** Choices of `intlayer init ai`. */\nexport type SetupAiProviderOptions = {\n provider: string;\n model?: string;\n /** Stored in the environment file when given. */\n apiKey?: string;\n};\n\n/**\n * Persists an AI provider setup: the API key to the environment file (e.g.\n * `ANTHROPIC_API_KEY=sk-ant-…` in `.env`) and the provider, model and\n * `process.env` key reference to the `ai` block of the Intlayer config.\n */\nexport const setupAiProvider = async (\n rootDir: string,\n { provider, model, apiKey }: SetupAiProviderOptions\n): Promise<void> => {\n const apiKeyEnvironmentVariable =\n getAiProviderSetup(provider)?.apiKeyEnvironmentVariable;\n\n if (apiKey && apiKeyEnvironmentVariable) {\n const envFile = await writeEnvVariables(rootDir, {\n [apiKeyEnvironmentVariable]: apiKey,\n });\n logger(\n `${v} Saved ${colorize(apiKeyEnvironmentVariable, ANSIColors.GREY_LIGHT)} to ${colorizePath(envFile)}`\n );\n }\n\n await setAiInConfig(rootDir, {\n provider,\n model,\n apiKeyEnvironmentVariable,\n });\n\n if (!apiKey && apiKeyEnvironmentVariable) {\n logger(\n `Set ${colorize(`${apiKeyEnvironmentVariable}=…`, ANSIColors.GREY_LIGHT)} in your ${colorizePath('.env')} to enable the AI features.`\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,kBAAkB;;AAiC/B,MAAM,UAAU,WACd,SAAS,EAAE,eAAe,UAAU,SAAS,IAAI,CAAC;;AAGpD,MAAM,0BAA0B,YAAoC,EAClE,KAAK,+DAA+D,mBAAmB,UAAU,EAAE,IACrG;;AAGA,MAAa,qBAAwC;CACnD;EACE,UAAUA,mCAAY;EACtB,OAAO;EACP,2BAA2B;EAC3B,mBAAmB;EACnB,WAAW;EACX,mBAAmB,YAAY;GAC7B,KAAK;GACL,SAAS;IACP,aAAa,UAAU;IACvB,qBAAqB;GACvB;EACF;EACA,iBAAiB;GACf;GACA;GACA;EACF;CACF;CACA;EACE,UAAUA,mCAAY;EACtB,OAAO;EACP,2BAA2B;E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B,KAAK,oBAAgBG,kCAAS,aAAaC,wBAAW,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,GAChH;CACF,QAAQ;EACN,oCACE,GAAGC,0BAAE,oEAAoE,kBAAkB,KAAK,GAAG,KACnG,EAAE,OAAO,OAAO,CAClB;CACF;AACF;;;;;;AAeA,MAAa,kBAAkB,OAC7B,SACA,EAAE,UAAU,OAAO,aACD;CAClB,MAAM,4BACJ,mBAAmB,QAAQ,CAAC,EAAE;CAEhC,IAAI,UAAU,2BAA2B;EACvC,MAAM,UAAU,MAAMC,mCAAkB,SAAS,GAC9C,4BAA4B,OAC/B,CAAC;EACD,oCACE,GAAGN,0BAAE,aAASG,kCAAS,2BAA2BC,wBAAW,UAAU,EAAE,UAAMG,sCAAa,OAAO,GACrG;CACF;CAEA,MAAMC,+BAAc,SAAS;EAC3B;EACA;EACA;CACF,CAAC;CAED,IAAI,CAAC,UAAU,2BACb,oCACE,WAAOL,kCAAS,GAAG,0BAA0B,KAAKC,wBAAW,UAAU,EAAE,eAAWG,sCAAa,MAAM,EAAE,4BAC3G;AAEJ"}
|
package/dist/cjs/init/cms.cjs
CHANGED
|
@@ -69,17 +69,59 @@ const upsertEnvVariable = (content, key, value) => {
|
|
|
69
69
|
* of the file that was written.
|
|
70
70
|
*/
|
|
71
71
|
const writeCmsCredentialsToEnv = async (rootDir, { clientId, clientSecret }) => {
|
|
72
|
+
const envFile = await writeEnvVariables(rootDir, {
|
|
73
|
+
INTLAYER_CLIENT_ID: clientId,
|
|
74
|
+
INTLAYER_CLIENT_SECRET: clientSecret
|
|
75
|
+
});
|
|
76
|
+
(0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.v} Saved Intlayer CMS credentials to ${(0, _intlayer_config_logger.colorizePath)(envFile)} (${(0, _intlayer_config_logger.colorize)("INTLAYER_CLIENT_ID", _intlayer_config_colors.GREY_LIGHT)}, ${(0, _intlayer_config_logger.colorize)("INTLAYER_CLIENT_SECRET", _intlayer_config_colors.GREY_LIGHT)})`);
|
|
77
|
+
return envFile;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Upserts `KEY=value` lines in the project's environment file (detected with
|
|
81
|
+
* {@link findEnvFile}, created when missing), and makes sure git ignores it.
|
|
82
|
+
* Returns the relative path of the file that was written.
|
|
83
|
+
*/
|
|
84
|
+
const writeEnvVariables = async (rootDir, variables) => {
|
|
72
85
|
const envFile = await findEnvFile(rootDir);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
let updatedContent = content;
|
|
76
|
-
updatedContent = upsertEnvVariable(updatedContent, "INTLAYER_CLIENT_ID", clientId);
|
|
77
|
-
updatedContent = upsertEnvVariable(updatedContent, "INTLAYER_CLIENT_SECRET", clientSecret);
|
|
86
|
+
const content = await require_init_utils_fileSystem.exists(rootDir, envFile) ? await require_init_utils_fileSystem.readFileFromRoot(rootDir, envFile) : "";
|
|
87
|
+
const updatedContent = Object.entries(variables).reduce((currentContent, [key, value]) => upsertEnvVariable(currentContent, key, value), content);
|
|
78
88
|
await require_init_utils_fileSystem.writeFileToRoot(rootDir, envFile, updatedContent);
|
|
79
|
-
|
|
89
|
+
await ensureGitIgnored(rootDir, envFile);
|
|
80
90
|
return envFile;
|
|
81
91
|
};
|
|
82
92
|
/**
|
|
93
|
+
* Appends `fileName` to an existing `.gitignore` unless a line already covers
|
|
94
|
+
* it (exact name or a `.env*` style glob), so secrets are never committed.
|
|
95
|
+
*/
|
|
96
|
+
const ensureGitIgnored = async (rootDir, fileName) => {
|
|
97
|
+
const gitignorePath = ".gitignore";
|
|
98
|
+
if (!await require_init_utils_fileSystem.exists(rootDir, gitignorePath)) return;
|
|
99
|
+
const gitignoreContent = await require_init_utils_fileSystem.readFileFromRoot(rootDir, gitignorePath);
|
|
100
|
+
if (gitignoreContent.split("\n").map((line) => line.trim().replace(/^\//, "")).some((pattern) => pattern === fileName || pattern.endsWith("*") && fileName.startsWith(pattern.slice(0, -1)))) return;
|
|
101
|
+
const separator = gitignoreContent.endsWith("\n") ? "" : "\n";
|
|
102
|
+
await require_init_utils_fileSystem.writeFileToRoot(rootDir, gitignorePath, `${gitignoreContent}${separator}${fileName}\n`);
|
|
103
|
+
(0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.v} Added ${(0, _intlayer_config_logger.colorizePath)(fileName)} to ${(0, _intlayer_config_logger.colorizePath)(gitignorePath)}`);
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Writes the AI provider, model and API key reference to the `ai` block of the
|
|
107
|
+
* project's Intlayer configuration file. Returns the config file that was
|
|
108
|
+
* updated, or `undefined` when none was found.
|
|
109
|
+
*/
|
|
110
|
+
const setAiInConfig = async (rootDir, settings) => {
|
|
111
|
+
const configFile = await findIntlayerConfigFile(rootDir);
|
|
112
|
+
if (!configFile) {
|
|
113
|
+
(0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.x} Could not find an Intlayer configuration file to set the AI provider. Run ${(0, _intlayer_config_logger.colorize)("intlayer init", _intlayer_config_colors.MAGENTA)} first.`, { level: "warn" });
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const extension = configFile.split(".").pop();
|
|
117
|
+
const content = await require_init_utils_fileSystem.readFileFromRoot(rootDir, configFile);
|
|
118
|
+
const updatedContent = require_init_utils_configManipulation.setIntlayerConfigAi(content, extension, settings);
|
|
119
|
+
if (updatedContent !== content) await require_init_utils_fileSystem.writeFileToRoot(rootDir, configFile, updatedContent);
|
|
120
|
+
(0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.v} Set ${(0, _intlayer_config_logger.colorize)(`ai.provider = '${settings.provider}'`, _intlayer_config_colors.GREY_LIGHT)}${settings.model ? `, ${(0, _intlayer_config_logger.colorize)(`ai.model = '${settings.model}'`, _intlayer_config_colors.GREY_LIGHT)}` : ""} in ${(0, _intlayer_config_logger.colorizePath)(configFile)}`);
|
|
121
|
+
if (extension === "json" && settings.apiKeyEnvironmentVariable) (0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.x} ${(0, _intlayer_config_logger.colorizePath)(configFile)} is a JSON config and cannot reference ${(0, _intlayer_config_logger.colorize)(settings.apiKeyEnvironmentVariable, _intlayer_config_colors.GREY_LIGHT)}: pass the key with ${(0, _intlayer_config_logger.colorize)("--api-key", _intlayer_config_colors.MAGENTA)} when running the AI commands.`, { level: "warn" });
|
|
122
|
+
return configFile;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
83
125
|
* Enables the Intlayer visual editor in the project's configuration file:
|
|
84
126
|
* flips `editor.enabled` to `true` and wires `clientId` / `clientSecret` to the
|
|
85
127
|
* matching environment variables. JSON configs cannot reference `process.env`,
|
|
@@ -200,6 +242,7 @@ const setupCmsCredentials = async (rootDir, credentials) => {
|
|
|
200
242
|
exports.INTLAYER_CONFIG_FILE_CANDIDATES = INTLAYER_CONFIG_FILE_CANDIDATES;
|
|
201
243
|
exports.enableEditorInConfig = enableEditorInConfig;
|
|
202
244
|
exports.findEnvFile = findEnvFile;
|
|
245
|
+
exports.setAiInConfig = setAiInConfig;
|
|
203
246
|
exports.setCompilerOutputInConfig = setCompilerOutputInConfig;
|
|
204
247
|
exports.setDictionaryLocaleInConfig = setDictionaryLocaleInConfig;
|
|
205
248
|
exports.setEnableProxyInConfig = setEnableProxyInConfig;
|
|
@@ -207,4 +250,5 @@ exports.setRoutingModeInConfig = setRoutingModeInConfig;
|
|
|
207
250
|
exports.setRoutingStorageOnlyInConfig = setRoutingStorageOnlyInConfig;
|
|
208
251
|
exports.setupCmsCredentials = setupCmsCredentials;
|
|
209
252
|
exports.writeCmsCredentialsToEnv = writeCmsCredentialsToEnv;
|
|
253
|
+
exports.writeEnvVariables = writeEnvVariables;
|
|
210
254
|
//# sourceMappingURL=cms.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cms.cjs","names":["exists","fg","readFileFromRoot","writeFileToRoot","v","colorizePath","colorize","ANSIColors","x","enableIntlayerEditorConfig","setIntlayerConfigRoutingMode","setIntlayerConfigEnableProxy","setIntlayerConfigRoutingStorageOnly","setIntlayerConfigCompilerOutput","setIntlayerConfigDictionaryLocale"],"sources":["../../../src/init/cms.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, colorizePath, logger, v, x } from '@intlayer/config/logger';\nimport fg from 'fast-glob';\nimport {\n enableIntlayerEditorConfig,\n type RoutingMode,\n setIntlayerConfigCompilerOutput,\n setIntlayerConfigDictionaryLocale,\n setIntlayerConfigEnableProxy,\n setIntlayerConfigRoutingMode,\n setIntlayerConfigRoutingStorageOnly,\n} from './utils/configManipulation';\nimport { exists, readFileFromRoot, writeFileToRoot } from './utils/fileSystem';\n\n/**\n * Intlayer configuration file candidates, ordered by the precedence used when\n * resolving which file to mutate.\n */\nexport const INTLAYER_CONFIG_FILE_CANDIDATES = [\n 'intlayer.config.ts',\n 'intlayer.config.mjs',\n 'intlayer.config.js',\n 'intlayer.config.cjs',\n 'intlayer.config.json',\n] as const;\n\n/**\n * Environment files searched (most-preferred first) when persisting the CMS\n * credentials. The first existing match is reused; otherwise a `.env` file is\n * created at the project root.\n */\nconst ENV_FILE_CANDIDATES = ['.env', '.env.local', '.env.development'] as const;\n\n/** Credentials returned by the CMS login flow (access key pair). */\nexport type CmsCredentials = {\n clientId: string;\n clientSecret: string;\n};\n\n/**\n * Resolves the first existing Intlayer configuration file at the project root,\n * or `undefined` when none is present.\n */\nconst findIntlayerConfigFile = async (\n rootDir: string\n): Promise<(typeof INTLAYER_CONFIG_FILE_CANDIDATES)[number] | undefined> => {\n for (const candidate of INTLAYER_CONFIG_FILE_CANDIDATES) {\n if (await exists(rootDir, candidate)) {\n return candidate;\n }\n }\n\n return undefined;\n};\n\n/**\n * Locates the environment file the CMS credentials should be written to. Uses\n * `fast-glob` to detect an existing dotenv file at the project root, preferring\n * a plain `.env`; falls back to `.env` (to be created) when none exist.\n */\nexport const findEnvFile = async (rootDir: string): Promise<string> => {\n const matches = await fg([...ENV_FILE_CANDIDATES], {\n cwd: rootDir,\n dot: true,\n deep: 1,\n onlyFiles: true,\n });\n\n return (\n ENV_FILE_CANDIDATES.find((candidate) => matches.includes(candidate)) ??\n '.env'\n );\n};\n\n/**\n * Inserts or updates a `KEY=value` line in dotenv file content. An existing\n * assignment of the same key is replaced in place; otherwise the line is\n * appended with a trailing newline.\n */\nconst upsertEnvVariable = (\n content: string,\n key: string,\n value: string\n): string => {\n const line = `${key}=${value}`;\n const keyMatcher = new RegExp(`^${key}=.*$`, 'm');\n\n if (keyMatcher.test(content)) {\n return content.replace(keyMatcher, line);\n }\n\n const needsLeadingNewline = content.length > 0 && !content.endsWith('\\n');\n\n return `${content}${needsLeadingNewline ? '\\n' : ''}${line}\\n`;\n};\n\n/**\n * Persists the CMS access-key credentials to the project's environment file as\n * `INTLAYER_CLIENT_ID` / `INTLAYER_CLIENT_SECRET`. The target file is detected\n * with {@link findEnvFile} and created when missing. Returns the relative path\n * of the file that was written.\n */\nexport const writeCmsCredentialsToEnv = async (\n rootDir: string,\n { clientId, clientSecret }: CmsCredentials\n): Promise<string> => {\n const envFile = await findEnvFile(rootDir);\n\n let content = '';\n if (await exists(rootDir, envFile)) {\n content = await readFileFromRoot(rootDir, envFile);\n }\n\n let updatedContent = content;\n updatedContent = upsertEnvVariable(\n updatedContent,\n 'INTLAYER_CLIENT_ID',\n clientId\n );\n updatedContent = upsertEnvVariable(\n updatedContent,\n 'INTLAYER_CLIENT_SECRET',\n clientSecret\n );\n\n await writeFileToRoot(rootDir, envFile, updatedContent);\n logger(\n `${v} Saved Intlayer CMS credentials to ${colorizePath(envFile)} (${colorize('INTLAYER_CLIENT_ID', ANSIColors.GREY_LIGHT)}, ${colorize('INTLAYER_CLIENT_SECRET', ANSIColors.GREY_LIGHT)})`\n );\n\n return envFile;\n};\n\n/**\n * Enables the Intlayer visual editor in the project's configuration file:\n * flips `editor.enabled` to `true` and wires `clientId` / `clientSecret` to the\n * matching environment variables. JSON configs cannot reference `process.env`,\n * so they are skipped with a warning. Returns the config file that was updated,\n * or `undefined` when no editable config was found.\n */\nexport const enableEditorInConfig = async (\n rootDir: string\n): Promise<string | undefined> => {\n const configFile = await findIntlayerConfigFile(rootDir);\n\n if (!configFile) {\n logger(\n `${x} Could not find an Intlayer configuration file to enable the editor.`,\n { level: 'warn' }\n );\n return undefined;\n }\n\n const extension = configFile.split('.').pop()!;\n\n if (extension === 'json') {\n logger(\n `${x} ${colorizePath(configFile)} is a JSON config and cannot reference environment variables. Enable the editor and set clientId/clientSecret manually.`,\n { level: 'warn' }\n );\n return undefined;\n }\n\n const content = await readFileFromRoot(rootDir, configFile);\n const updatedContent = enableIntlayerEditorConfig(content);\n\n if (updatedContent !== content) {\n await writeFileToRoot(rootDir, configFile, updatedContent);\n logger(`${v} Enabled the Intlayer editor in ${colorizePath(configFile)}`);\n } else {\n logger(\n `${v} ${colorizePath(configFile)} already has the Intlayer editor enabled`\n );\n }\n\n return configFile;\n};\n\n/**\n * Sets `routing.mode` in the project's Intlayer configuration file. Returns the\n * config file that was updated, or `undefined` when none was found.\n */\nexport const setRoutingModeInConfig = async (\n rootDir: string,\n mode: RoutingMode\n): Promise<string | undefined> => {\n const configFile = await findIntlayerConfigFile(rootDir);\n\n if (!configFile) return undefined;\n\n const extension = configFile.split('.').pop()!;\n const content = await readFileFromRoot(rootDir, configFile);\n const updatedContent = setIntlayerConfigRoutingMode(content, extension, mode);\n\n if (updatedContent !== content) {\n await writeFileToRoot(rootDir, configFile, updatedContent);\n logger(\n `${v} Set ${colorize(`routing.mode = '${mode}'`, ANSIColors.GREY_LIGHT)} in ${colorizePath(configFile)}`\n );\n }\n\n return configFile;\n};\n\n/**\n * Sets `routing.enableProxy` in the project's Intlayer configuration file.\n * Returns the config file that was updated, or `undefined` when none was found.\n */\nexport const setEnableProxyInConfig = async (\n rootDir: string,\n enableProxy: boolean\n): Promise<string | undefined> => {\n const configFile = await findIntlayerConfigFile(rootDir);\n\n if (!configFile) return undefined;\n\n const extension = configFile.split('.').pop()!;\n const content = await readFileFromRoot(rootDir, configFile);\n const updatedContent = setIntlayerConfigEnableProxy(\n content,\n extension,\n enableProxy\n );\n\n if (updatedContent !== content) {\n await writeFileToRoot(rootDir, configFile, updatedContent);\n logger(\n `${v} Set ${colorize(`routing.enableProxy = ${enableProxy}`, ANSIColors.GREY_LIGHT)} in ${colorizePath(configFile)}`\n );\n }\n\n return configFile;\n};\n\n/**\n * Reduces `routing` in the project's Intlayer configuration file to its\n * `storage` entry. Returns the config file that was updated, or `undefined`\n * when none was found.\n */\nexport const setRoutingStorageOnlyInConfig = async (\n rootDir: string\n): Promise<string | undefined> => {\n const configFile = await findIntlayerConfigFile(rootDir);\n\n if (!configFile) return undefined;\n\n const extension = configFile.split('.').pop()!;\n const content = await readFileFromRoot(rootDir, configFile);\n const updatedContent = setIntlayerConfigRoutingStorageOnly(\n content,\n extension\n );\n\n if (updatedContent !== content) {\n await writeFileToRoot(rootDir, configFile, updatedContent);\n logger(\n `${v} Kept only ${colorize('routing.storage', ANSIColors.GREY_LIGHT)} in ${colorizePath(configFile)} (no URL routing in this project)`\n );\n }\n\n return configFile;\n};\n\n/**\n * Sets `compiler.output` in the project's Intlayer configuration file to the\n * given `{{variable}}` path template. Returns the config file that was updated,\n * or `undefined` when none was found.\n */\nexport const setCompilerOutputInConfig = async (\n rootDir: string,\n outputTemplate: string\n): Promise<string | undefined> => {\n const configFile = await findIntlayerConfigFile(rootDir);\n\n if (!configFile) return undefined;\n\n const extension = configFile.split('.').pop()!;\n const content = await readFileFromRoot(rootDir, configFile);\n const updatedContent = setIntlayerConfigCompilerOutput(\n content,\n extension,\n outputTemplate\n );\n\n if (updatedContent !== content) {\n await writeFileToRoot(rootDir, configFile, updatedContent);\n logger(\n `${v} Set ${colorize(`compiler.output = '${outputTemplate}'`, ANSIColors.GREY_LIGHT)} in ${colorizePath(configFile)}`\n );\n }\n\n return configFile;\n};\n\n/**\n * Sets `dictionary.locale` to the default locale in the project's Intlayer\n * configuration file. Returns the config file that was updated, or `undefined`\n * when none was found.\n */\nexport const setDictionaryLocaleInConfig = async (\n rootDir: string\n): Promise<string | undefined> => {\n const configFile = await findIntlayerConfigFile(rootDir);\n\n if (!configFile) return undefined;\n\n const extension = configFile.split('.').pop()!;\n const content = await readFileFromRoot(rootDir, configFile);\n const updatedContent = setIntlayerConfigDictionaryLocale(content, extension);\n\n if (updatedContent !== content) {\n await writeFileToRoot(rootDir, configFile, updatedContent);\n logger(\n `${v} Set ${colorize('dictionary.locale', ANSIColors.GREY_LIGHT)} to the default locale in ${colorizePath(configFile)}`\n );\n }\n\n return configFile;\n};\n\n/**\n * Completes the CMS setup once credentials are received from the login flow:\n * writes them to the environment file and enables the editor in the Intlayer\n * configuration file.\n */\nexport const setupCmsCredentials = async (\n rootDir: string,\n credentials: CmsCredentials\n): Promise<void> => {\n await writeCmsCredentialsToEnv(rootDir, credentials);\n await enableEditorInConfig(rootDir);\n};\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,MAAa,kCAAkC;CAC7C;CACA;CACA;CACA;CACA;AACF;;;;;;AAOA,MAAM,sBAAsB;CAAC;CAAQ;CAAc;AAAkB;;;;;AAYrE,MAAM,yBAAyB,OAC7B,YAC0E;CAC1E,KAAK,MAAM,aAAa,iCACtB,IAAI,MAAMA,qCAAO,SAAS,SAAS,GACjC,OAAO;AAKb;;;;;;AAOA,MAAa,cAAc,OAAO,YAAqC;CACrE,MAAM,UAAU,UAAMC,mBAAG,CAAC,GAAG,mBAAmB,GAAG;EACjD,KAAK;EACL,KAAK;EACL,MAAM;EACN,WAAW;CACb,CAAC;CAED,OACE,oBAAoB,MAAM,cAAc,QAAQ,SAAS,SAAS,CAAC,KACnE;AAEJ;;;;;;AAOA,MAAM,qBACJ,SACA,KACA,UACW;CACX,MAAM,OAAO,GAAG,IAAI,GAAG;CACvB,MAAM,aAAa,IAAI,OAAO,IAAI,IAAI,OAAO,GAAG;CAEhD,IAAI,WAAW,KAAK,OAAO,GACzB,OAAO,QAAQ,QAAQ,YAAY,IAAI;CAKzC,O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E,kCAAS,mBAAmBC,wBAAW,UAAU,EAAE,UAAMF,sCAAa,UAAU,EAAE,kCACtG;CACF;CAEA,OAAO;AACT;;;;;;AAOA,MAAa,4BAA4B,OACvC,SACA,mBACgC;CAChC,MAAM,aAAa,MAAM,uBAAuB,OAAO;CAEvD,IAAI,CAAC,YAAY,OAAO;CAExB,MAAM,YAAY,WAAW,MAAM,GAAG,CAAC,CAAC,IAAI;CAC5C,MAAM,UAAU,MAAMH,+CAAiB,SAAS,UAAU;CAC1D,MAAM,iBAAiBW,sEACrB,SACA,WACA,cACF;CAEA,IAAI,mBAAmB,SAAS;EAC9B,MAAMV,8CAAgB,SAAS,YAAY,cAAc;EACzD,oCACE,GAAGC,0BAAE,WAAOE,kCAAS,sBAAsB,eAAe,IAAIC,wBAAW,UAAU,EAAE,UAAMF,sCAAa,UAAU,GACpH;CACF;CAEA,OAAO;AACT;;;;;;AAOA,MAAa,8BAA8B,OACzC,YACgC;CAChC,MAAM,aAAa,MAAM,uBAAuB,OAAO;CAEvD,IAAI,CAAC,YAAY,OAAO;CAExB,MAAM,YAAY,WAAW,MAAM,GAAG,CAAC,CAAC,IAAI;CAC5C,MAAM,UAAU,MAAMH,+CAAiB,SAAS,UAAU;CAC1D,MAAM,iBAAiBY,wEAAkC,SAAS,SAAS;CAE3E,IAAI,mBAAmB,SAAS;EAC9B,MAAMX,8CAAgB,SAAS,YAAY,cAAc;EACzD,oCACE,GAAGC,0BAAE,WAAOE,kCAAS,qBAAqBC,wBAAW,UAAU,EAAE,gCAA4BF,sCAAa,UAAU,GACtH;CACF;CAEA,OAAO;AACT;;;;;;AAOA,MAAa,sBAAsB,OACjC,SACA,gBACkB;CAClB,MAAM,yBAAyB,SAAS,WAAW;CACnD,MAAM,qBAAqB,OAAO;AACpC"}
|
|
1
|
+
{"version":3,"file":"cms.cjs","names":["exists","fg","v","colorizePath","colorize","ANSIColors","readFileFromRoot","writeFileToRoot","x","setIntlayerConfigAi","enableIntlayerEditorConfig","setIntlayerConfigRoutingMode","setIntlayerConfigEnableProxy","setIntlayerConfigRoutingStorageOnly","setIntlayerConfigCompilerOutput","setIntlayerConfigDictionaryLocale"],"sources":["../../../src/init/cms.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, colorizePath, logger, v, x } from '@intlayer/config/logger';\nimport fg from 'fast-glob';\nimport {\n enableIntlayerEditorConfig,\n type IntlayerConfigAiSettings,\n type RoutingMode,\n setIntlayerConfigAi,\n setIntlayerConfigCompilerOutput,\n setIntlayerConfigDictionaryLocale,\n setIntlayerConfigEnableProxy,\n setIntlayerConfigRoutingMode,\n setIntlayerConfigRoutingStorageOnly,\n} from './utils/configManipulation';\nimport { exists, readFileFromRoot, writeFileToRoot } from './utils/fileSystem';\n\n/**\n * Intlayer configuration file candidates, ordered by the precedence used when\n * resolving which file to mutate.\n */\nexport const INTLAYER_CONFIG_FILE_CANDIDATES = [\n 'intlayer.config.ts',\n 'intlayer.config.mjs',\n 'intlayer.config.js',\n 'intlayer.config.cjs',\n 'intlayer.config.json',\n] as const;\n\n/**\n * Environment files searched (most-preferred first) when persisting the CMS\n * credentials. The first existing match is reused; otherwise a `.env` file is\n * created at the project root.\n */\nconst ENV_FILE_CANDIDATES = ['.env', '.env.local', '.env.development'] as const;\n\n/** Credentials returned by the CMS login flow (access key pair). */\nexport type CmsCredentials = {\n clientId: string;\n clientSecret: string;\n};\n\n/**\n * Resolves the first existing Intlayer configuration file at the project root,\n * or `undefined` when none is present.\n */\nconst findIntlayerConfigFile = async (\n rootDir: string\n): Promise<(typeof INTLAYER_CONFIG_FILE_CANDIDATES)[number] | undefined> => {\n for (const candidate of INTLAYER_CONFIG_FILE_CANDIDATES) {\n if (await exists(rootDir, candidate)) {\n return candidate;\n }\n }\n\n return undefined;\n};\n\n/**\n * Locates the environment file the CMS credentials should be written to. Uses\n * `fast-glob` to detect an existing dotenv file at the project root, preferring\n * a plain `.env`; falls back to `.env` (to be created) when none exist.\n */\nexport const findEnvFile = async (rootDir: string): Promise<string> => {\n const matches = await fg([...ENV_FILE_CANDIDATES], {\n cwd: rootDir,\n dot: true,\n deep: 1,\n onlyFiles: true,\n });\n\n return (\n ENV_FILE_CANDIDATES.find((candidate) => matches.includes(candidate)) ??\n '.env'\n );\n};\n\n/**\n * Inserts or updates a `KEY=value` line in dotenv file content. An existing\n * assignment of the same key is replaced in place; otherwise the line is\n * appended with a trailing newline.\n */\nconst upsertEnvVariable = (\n content: string,\n key: string,\n value: string\n): string => {\n const line = `${key}=${value}`;\n const keyMatcher = new RegExp(`^${key}=.*$`, 'm');\n\n if (keyMatcher.test(content)) {\n return content.replace(keyMatcher, line);\n }\n\n const needsLeadingNewline = content.length > 0 && !content.endsWith('\\n');\n\n return `${content}${needsLeadingNewline ? '\\n' : ''}${line}\\n`;\n};\n\n/**\n * Persists the CMS access-key credentials to the project's environment file as\n * `INTLAYER_CLIENT_ID` / `INTLAYER_CLIENT_SECRET`. The target file is detected\n * with {@link findEnvFile} and created when missing. Returns the relative path\n * of the file that was written.\n */\nexport const writeCmsCredentialsToEnv = async (\n rootDir: string,\n { clientId, clientSecret }: CmsCredentials\n): Promise<string> => {\n const envFile = await writeEnvVariables(rootDir, {\n INTLAYER_CLIENT_ID: clientId,\n INTLAYER_CLIENT_SECRET: clientSecret,\n });\n\n logger(\n `${v} Saved Intlayer CMS credentials to ${colorizePath(envFile)} (${colorize('INTLAYER_CLIENT_ID', ANSIColors.GREY_LIGHT)}, ${colorize('INTLAYER_CLIENT_SECRET', ANSIColors.GREY_LIGHT)})`\n );\n\n return envFile;\n};\n\n/**\n * Upserts `KEY=value` lines in the project's environment file (detected with\n * {@link findEnvFile}, created when missing), and makes sure git ignores it.\n * Returns the relative path of the file that was written.\n */\nexport const writeEnvVariables = async (\n rootDir: string,\n variables: Record<string, string>\n): Promise<string> => {\n const envFile = await findEnvFile(rootDir);\n const content = (await exists(rootDir, envFile))\n ? await readFileFromRoot(rootDir, envFile)\n : '';\n\n const updatedContent = Object.entries(variables).reduce(\n (currentContent, [key, value]) =>\n upsertEnvVariable(currentContent, key, value),\n content\n );\n\n await writeFileToRoot(rootDir, envFile, updatedContent);\n await ensureGitIgnored(rootDir, envFile);\n\n return envFile;\n};\n\n/**\n * Appends `fileName` to an existing `.gitignore` unless a line already covers\n * it (exact name or a `.env*` style glob), so secrets are never committed.\n */\nconst ensureGitIgnored = async (\n rootDir: string,\n fileName: string\n): Promise<void> => {\n const gitignorePath = '.gitignore';\n\n if (!(await exists(rootDir, gitignorePath))) return;\n\n const gitignoreContent = await readFileFromRoot(rootDir, gitignorePath);\n const isIgnored = gitignoreContent\n .split('\\n')\n .map((line) => line.trim().replace(/^\\//, ''))\n .some(\n (pattern) =>\n pattern === fileName ||\n (pattern.endsWith('*') && fileName.startsWith(pattern.slice(0, -1)))\n );\n\n if (isIgnored) return;\n\n const separator = gitignoreContent.endsWith('\\n') ? '' : '\\n';\n await writeFileToRoot(\n rootDir,\n gitignorePath,\n `${gitignoreContent}${separator}${fileName}\\n`\n );\n logger(\n `${v} Added ${colorizePath(fileName)} to ${colorizePath(gitignorePath)}`\n );\n};\n\n/**\n * Writes the AI provider, model and API key reference to the `ai` block of the\n * project's Intlayer configuration file. Returns the config file that was\n * updated, or `undefined` when none was found.\n */\nexport const setAiInConfig = async (\n rootDir: string,\n settings: IntlayerConfigAiSettings\n): Promise<string | undefined> => {\n const configFile = await findIntlayerConfigFile(rootDir);\n\n if (!configFile) {\n logger(\n `${x} Could not find an Intlayer configuration file to set the AI provider. Run ${colorize('intlayer init', ANSIColors.MAGENTA)} first.`,\n { level: 'warn' }\n );\n return undefined;\n }\n\n const extension = configFile.split('.').pop()!;\n const content = await readFileFromRoot(rootDir, configFile);\n const updatedContent = setIntlayerConfigAi(content, extension, settings);\n\n if (updatedContent !== content) {\n await writeFileToRoot(rootDir, configFile, updatedContent);\n }\n\n logger(\n `${v} Set ${colorize(`ai.provider = '${settings.provider}'`, ANSIColors.GREY_LIGHT)}${settings.model ? `, ${colorize(`ai.model = '${settings.model}'`, ANSIColors.GREY_LIGHT)}` : ''} in ${colorizePath(configFile)}`\n );\n\n if (extension === 'json' && settings.apiKeyEnvironmentVariable) {\n logger(\n `${x} ${colorizePath(configFile)} is a JSON config and cannot reference ${colorize(settings.apiKeyEnvironmentVariable, ANSIColors.GREY_LIGHT)}: pass the key with ${colorize('--api-key', ANSIColors.MAGENTA)} when running the AI commands.`,\n { level: 'warn' }\n );\n }\n\n return configFile;\n};\n\n/**\n * Enables the Intlayer visual editor in the project's configuration file:\n * flips `editor.enabled` to `true` and wires `clientId` / `clientSecret` to the\n * matching environment variables. JSON configs cannot reference `process.env`,\n * so they are skipped with a warning. Returns the config file that was updated,\n * or `undefined` when no editable config was found.\n */\nexport const enableEditorInConfig = async (\n rootDir: string\n): Promise<string | undefined> => {\n const configFile = await findIntlayerConfigFile(rootDir);\n\n if (!configFile) {\n logger(\n `${x} Could not find an Intlayer configuration file to enable the editor.`,\n { level: 'warn' }\n );\n return undefined;\n }\n\n const extension = configFile.split('.').pop()!;\n\n if (extension === 'json') {\n logger(\n `${x} ${colorizePath(configFile)} is a JSON config and cannot reference environment variables. Enable the editor and set clientId/clientSecret manually.`,\n { level: 'warn' }\n );\n return undefined;\n }\n\n const content = await readFileFromRoot(rootDir, configFile);\n const updatedContent = enableIntlayerEditorConfig(content);\n\n if (updatedContent !== content) {\n await writeFileToRoot(rootDir, configFile, updatedContent);\n logger(`${v} Enabled the Intlayer editor in ${colorizePath(configFile)}`);\n } else {\n logger(\n `${v} ${colorizePath(configFile)} already has the Intlayer editor enabled`\n );\n }\n\n return configFile;\n};\n\n/**\n * Sets `routing.mode` in the project's Intlayer configuration file. Returns the\n * config file that was updated, or `undefined` when none was found.\n */\nexport const setRoutingModeInConfig = async (\n rootDir: string,\n mode: RoutingMode\n): Promise<string | undefined> => {\n const configFile = await findIntlayerConfigFile(rootDir);\n\n if (!configFile) return undefined;\n\n const extension = configFile.split('.').pop()!;\n const content = await readFileFromRoot(rootDir, configFile);\n const updatedContent = setIntlayerConfigRoutingMode(content, extension, mode);\n\n if (updatedContent !== content) {\n await writeFileToRoot(rootDir, configFile, updatedContent);\n logger(\n `${v} Set ${colorize(`routing.mode = '${mode}'`, ANSIColors.GREY_LIGHT)} in ${colorizePath(configFile)}`\n );\n }\n\n return configFile;\n};\n\n/**\n * Sets `routing.enableProxy` in the project's Intlayer configuration file.\n * Returns the config file that was updated, or `undefined` when none was found.\n */\nexport const setEnableProxyInConfig = async (\n rootDir: string,\n enableProxy: boolean\n): Promise<string | undefined> => {\n const configFile = await findIntlayerConfigFile(rootDir);\n\n if (!configFile) return undefined;\n\n const extension = configFile.split('.').pop()!;\n const content = await readFileFromRoot(rootDir, configFile);\n const updatedContent = setIntlayerConfigEnableProxy(\n content,\n extension,\n enableProxy\n );\n\n if (updatedContent !== content) {\n await writeFileToRoot(rootDir, configFile, updatedContent);\n logger(\n `${v} Set ${colorize(`routing.enableProxy = ${enableProxy}`, ANSIColors.GREY_LIGHT)} in ${colorizePath(configFile)}`\n );\n }\n\n return configFile;\n};\n\n/**\n * Reduces `routing` in the project's Intlayer configuration file to its\n * `storage` entry. Returns the config file that was updated, or `undefined`\n * when none was found.\n */\nexport const setRoutingStorageOnlyInConfig = async (\n rootDir: string\n): Promise<string | undefined> => {\n const configFile = await findIntlayerConfigFile(rootDir);\n\n if (!configFile) return undefined;\n\n const extension = configFile.split('.').pop()!;\n const content = await readFileFromRoot(rootDir, configFile);\n const updatedContent = setIntlayerConfigRoutingStorageOnly(\n content,\n extension\n );\n\n if (updatedContent !== content) {\n await writeFileToRoot(rootDir, configFile, updatedContent);\n logger(\n `${v} Kept only ${colorize('routing.storage', ANSIColors.GREY_LIGHT)} in ${colorizePath(configFile)} (no URL routing in this project)`\n );\n }\n\n return configFile;\n};\n\n/**\n * Sets `compiler.output` in the project's Intlayer configuration file to the\n * given `{{variable}}` path template. Returns the config file that was updated,\n * or `undefined` when none was found.\n */\nexport const setCompilerOutputInConfig = async (\n rootDir: string,\n outputTemplate: string\n): Promise<string | undefined> => {\n const configFile = await findIntlayerConfigFile(rootDir);\n\n if (!configFile) return undefined;\n\n const extension = configFile.split('.').pop()!;\n const content = await readFileFromRoot(rootDir, configFile);\n const updatedContent = setIntlayerConfigCompilerOutput(\n content,\n extension,\n outputTemplate\n );\n\n if (updatedContent !== content) {\n await writeFileToRoot(rootDir, configFile, updatedContent);\n logger(\n `${v} Set ${colorize(`compiler.output = '${outputTemplate}'`, ANSIColors.GREY_LIGHT)} in ${colorizePath(configFile)}`\n );\n }\n\n return configFile;\n};\n\n/**\n * Sets `dictionary.locale` to the default locale in the project's Intlayer\n * configuration file. Returns the config file that was updated, or `undefined`\n * when none was found.\n */\nexport const setDictionaryLocaleInConfig = async (\n rootDir: string\n): Promise<string | undefined> => {\n const configFile = await findIntlayerConfigFile(rootDir);\n\n if (!configFile) return undefined;\n\n const extension = configFile.split('.').pop()!;\n const content = await readFileFromRoot(rootDir, configFile);\n const updatedContent = setIntlayerConfigDictionaryLocale(content, extension);\n\n if (updatedContent !== content) {\n await writeFileToRoot(rootDir, configFile, updatedContent);\n logger(\n `${v} Set ${colorize('dictionary.locale', ANSIColors.GREY_LIGHT)} to the default locale in ${colorizePath(configFile)}`\n );\n }\n\n return configFile;\n};\n\n/**\n * Completes the CMS setup once credentials are received from the login flow:\n * writes them to the environment file and enables the editor in the Intlayer\n * configuration file.\n */\nexport const setupCmsCredentials = async (\n rootDir: string,\n credentials: CmsCredentials\n): Promise<void> => {\n await writeCmsCredentialsToEnv(rootDir, credentials);\n await enableEditorInConfig(rootDir);\n};\n"],"mappings":";;;;;;;;;;;;;;;AAoBA,MAAa,kCAAkC;CAC7C;CACA;CACA;CACA;CACA;AACF;;;;;;AAOA,MAAM,sBAAsB;CAAC;CAAQ;CAAc;AAAkB;;;;;AAYrE,MAAM,yBAAyB,OAC7B,YAC0E;CAC1E,KAAK,MAAM,aAAa,iCACtB,IAAI,MAAMA,qCAAO,SAAS,SAAS,GACjC,OAAO;AA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,SAAS,YAAY,cAAc;EACzD,oCACE,GAAGL,0BAAE,WAAOE,kCAAS,sBAAsB,eAAe,IAAIC,wBAAW,UAAU,EAAE,UAAMF,sCAAa,UAAU,GACpH;CACF;CAEA,OAAO;AACT;;;;;;AAOA,MAAa,8BAA8B,OACzC,YACgC;CAChC,MAAM,aAAa,MAAM,uBAAuB,OAAO;CAEvD,IAAI,CAAC,YAAY,OAAO;CAExB,MAAM,YAAY,WAAW,MAAM,GAAG,CAAC,CAAC,IAAI;CAC5C,MAAM,UAAU,MAAMG,+CAAiB,SAAS,UAAU;CAC1D,MAAM,iBAAiBS,wEAAkC,SAAS,SAAS;CAE3E,IAAI,mBAAmB,SAAS;EAC9B,MAAMR,8CAAgB,SAAS,YAAY,cAAc;EACzD,oCACE,GAAGL,0BAAE,WAAOE,kCAAS,qBAAqBC,wBAAW,UAAU,EAAE,gCAA4BF,sCAAa,UAAU,GACtH;CACF;CAEA,OAAO;AACT;;;;;;AAOA,MAAa,sBAAsB,OACjC,SACA,gBACkB;CAClB,MAAM,yBAAyB,SAAS,WAAW;CACnD,MAAM,qBAAqB,OAAO;AACpC"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
|
|
3
3
|
const require_init_utils_fileSystem = require("../../utils/fileSystem.cjs");
|
|
4
|
-
const require_init_frameworkSetup_localeRouting = require("../localeRouting.cjs");
|
|
5
4
|
const require_init_utils_version = require("../../utils/version.cjs");
|
|
5
|
+
const require_init_frameworkSetup_localeRouting = require("../localeRouting.cjs");
|
|
6
6
|
const require_init_frameworkSetup_nextAppRouter_detect = require("./detect.cjs");
|
|
7
7
|
const require_init_frameworkSetup_nextAppRouter_restructure = require("./restructure.cjs");
|
|
8
8
|
const require_init_frameworkSetup_nextAppRouter_templates = require("./templates.cjs");
|
|
9
9
|
const require_init_frameworkSetup_nextAppRouter_transforms = require("./transforms.cjs");
|
|
10
10
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
11
|
-
let node_path = require("node:path");
|
|
12
11
|
let node_fs_promises = require("node:fs/promises");
|
|
12
|
+
let node_path = require("node:path");
|
|
13
13
|
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
14
14
|
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
15
15
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
|
|
3
3
|
const require_utils_babelParser = require("../../../utils/babelParser.cjs");
|
|
4
|
-
let node_path = require("node:path");
|
|
5
4
|
let node_fs_promises = require("node:fs/promises");
|
|
5
|
+
let node_path = require("node:path");
|
|
6
6
|
let fast_glob = require("fast-glob");
|
|
7
7
|
fast_glob = require_runtime.__toESM(fast_glob);
|
|
8
8
|
let recast = require("recast");
|
|
@@ -8,8 +8,8 @@ const require_init_frameworkSetup_tanstackStart_restructure = require("./restruc
|
|
|
8
8
|
const require_init_frameworkSetup_tanstackStart_templates = require("./templates.cjs");
|
|
9
9
|
const require_init_frameworkSetup_tanstackStart_transforms = require("./transforms.cjs");
|
|
10
10
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
11
|
-
let node_path = require("node:path");
|
|
12
11
|
let node_fs_promises = require("node:fs/promises");
|
|
12
|
+
let node_path = require("node:path");
|
|
13
13
|
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
14
14
|
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
15
15
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
|
|
3
3
|
const require_init_frameworkSetup_nextAppRouter_restructure = require("../nextAppRouter/restructure.cjs");
|
|
4
|
-
let node_path = require("node:path");
|
|
5
4
|
let node_fs_promises = require("node:fs/promises");
|
|
5
|
+
let node_path = require("node:path");
|
|
6
6
|
let fast_glob = require("fast-glob");
|
|
7
7
|
fast_glob = require_runtime.__toESM(fast_glob);
|
|
8
8
|
|
package/dist/cjs/init/index.cjs
CHANGED
|
@@ -6,6 +6,7 @@ const require_init_documentationRouter = require("./documentationRouter.cjs");
|
|
|
6
6
|
const require_init_frameworkSetup_index = require("./frameworkSetup/index.cjs");
|
|
7
7
|
const require_init_upgradeIntlayerPackages = require("./upgradeIntlayerPackages.cjs");
|
|
8
8
|
const require_init_utils_prettierConfig = require("./utils/prettierConfig.cjs");
|
|
9
|
+
const require_init_utils_toolConfigManipulation = require("./utils/toolConfigManipulation.cjs");
|
|
9
10
|
const require_init_utils_lintConfig = require("./utils/lintConfig.cjs");
|
|
10
11
|
const require_init_utils_backendPackages = require("./utils/backendPackages.cjs");
|
|
11
12
|
const require_init_utils_packageManager = require("./utils/packageManager.cjs");
|
|
@@ -18,11 +19,11 @@ const require_init_utils_jsonParser = require("./utils/jsonParser.cjs");
|
|
|
18
19
|
const require_init_utils_nextCompilerBabel = require("./utils/nextCompilerBabel.cjs");
|
|
19
20
|
const require_init_utils_contentLayout = require("./utils/contentLayout.cjs");
|
|
20
21
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
21
|
-
let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
|
|
22
22
|
let node_path = require("node:path");
|
|
23
|
-
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
24
23
|
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
25
24
|
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
25
|
+
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
26
|
+
let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
|
|
26
27
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
27
28
|
|
|
28
29
|
// src/init/index.ts
|
|
@@ -43,6 +44,26 @@ const getDefaultApplicationURL = (dependencies) => {
|
|
|
43
44
|
return "http://localhost:3000";
|
|
44
45
|
};
|
|
45
46
|
/**
|
|
47
|
+
* Patches the first existing file of `configFiles` with `patch`, logging the
|
|
48
|
+
* outcome. Resolves to `undefined` when no candidate exists or its shape is not
|
|
49
|
+
* supported, so the caller can print the manual snippet.
|
|
50
|
+
*/
|
|
51
|
+
const patchFirstConfigFile = async (rootDir, configFiles, patch, description) => {
|
|
52
|
+
for (const configFile of configFiles) {
|
|
53
|
+
if (!await require_init_utils_fileSystem.exists(rootDir, configFile)) continue;
|
|
54
|
+
try {
|
|
55
|
+
const result = patch(await require_init_utils_fileSystem.readFileFromRoot(rootDir, configFile), configFile.split(".").pop() ?? "js");
|
|
56
|
+
if (result.status === "updated") {
|
|
57
|
+
await require_init_utils_fileSystem.writeFileToRoot(rootDir, configFile, result.content);
|
|
58
|
+
(0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.v} Added ${description} to ${(0, _intlayer_config_logger.colorizePath)(configFile)}`);
|
|
59
|
+
} else if (result.status === "already") (0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.v} ${(0, _intlayer_config_logger.colorizePath)(configFile)} already includes ${description}`);
|
|
60
|
+
return result.status === "unsupported" ? void 0 : result.status;
|
|
61
|
+
} catch {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
46
67
|
* Installs `prettier-plugin-intlayer` (when the package step is skipped) and
|
|
47
68
|
* registers it in the first JSON Prettier config found: `.prettierrc.json`, a
|
|
48
69
|
* JSON `.prettierrc`, or the `prettier` field of `package.json`. Any other
|
|
@@ -76,6 +97,7 @@ const setupPrettierPlugin = async (rootDir, allDependencies, packageManager, opt
|
|
|
76
97
|
};
|
|
77
98
|
for (const configPath of require_init_utils_prettierConfig.JSON_PRETTIER_CONFIG_FILES) if (await patchJsonConfig(configPath, (config) => config) !== void 0) return;
|
|
78
99
|
if (await patchJsonConfig("package.json", (packageJson) => packageJson.prettier) !== void 0) return;
|
|
100
|
+
if (await patchFirstConfigFile(rootDir, [...require_init_utils_toolConfigManipulation.SCRIPT_PRETTIER_CONFIG_FILES, ...require_init_utils_toolConfigManipulation.YAML_PRETTIER_CONFIG_FILES], (content, extension) => extension === "yaml" || extension === "yml" ? require_init_utils_toolConfigManipulation.addIntlayerPluginToPrettierYamlConfig(content) : require_init_utils_toolConfigManipulation.addIntlayerPluginToPrettierScriptConfig(content), pluginName) !== void 0) return;
|
|
79
101
|
(0, _intlayer_config_logger.logger)([
|
|
80
102
|
(0, _intlayer_config_logger.colorize)("Intlayer Prettier plugin →", _intlayer_config_colors.MAGENTA),
|
|
81
103
|
(0, _intlayer_config_logger.colorize)(`Add ${require_init_utils_prettierConfig.PRETTIER_PLUGIN_PACKAGE_NAME} to the plugins of your Prettier config, to sort the keys of t(), plural(), enu() and select():`, _intlayer_config_colors.GREY_LIGHT),
|
|
@@ -245,7 +267,8 @@ const initIntlayer = async (rootDir, options) => {
|
|
|
245
267
|
} catch {
|
|
246
268
|
(0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.x} Could not update ${(0, _intlayer_config_logger.colorizePath)(oxlintConfigPath)}. You may need to add ${(0, _intlayer_config_logger.colorize)(require_init_utils_lintConfig.LINT_PLUGIN_PACKAGE_NAME, _intlayer_config_colors.MAGENTA)} manually.`, { level: "warn" });
|
|
247
269
|
}
|
|
248
|
-
|
|
270
|
+
const eslintResult = allDeps.eslint ? await patchFirstConfigFile(rootDir, require_init_utils_toolConfigManipulation.ESLINT_FLAT_CONFIG_FILES, require_init_utils_toolConfigManipulation.addIntlayerPresetToEslintFlatConfig, `the ${(0, _intlayer_config_logger.colorize)(require_init_utils_lintConfig.LINT_PLUGIN_PACKAGE_NAME, _intlayer_config_colors.MAGENTA)} preset`) : void 0;
|
|
271
|
+
if (allDeps.eslint && eslintResult === void 0) (0, _intlayer_config_logger.logger)([
|
|
249
272
|
(0, _intlayer_config_logger.colorize)("Intlayer lint rules →", _intlayer_config_colors.MAGENTA),
|
|
250
273
|
(0, _intlayer_config_logger.colorize)(`Add the ${require_init_utils_lintConfig.LINT_PLUGIN_PACKAGE_NAME} preset to the array your ESLint flat config exports, to catch hardcoded text and dynamic calls the compiler cannot optimize:`, _intlayer_config_colors.GREY_LIGHT),
|
|
251
274
|
(0, _intlayer_config_logger.colorize)(` import intlayer from '${require_init_utils_lintConfig.LINT_PLUGIN_PACKAGE_NAME}';\n\n export default [\n // ...your existing config\n ...intlayer.configs.recommended,\n ];`, _intlayer_config_colors.GREY_LIGHT),
|
|
@@ -345,6 +368,9 @@ const initIntlayer = async (rootDir, options) => {
|
|
|
345
368
|
await require_init_utils_fileSystem.writeFileToRoot(rootDir, file, updatedContent);
|
|
346
369
|
(0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.v} Updated ${(0, _intlayer_config_logger.colorizePath)(file)} to include Intlayer plugin`);
|
|
347
370
|
}
|
|
371
|
+
if (require_init_utils_toolConfigManipulation.hasTanStackRouterVitePlugin(await require_init_utils_fileSystem.readFileFromRoot(rootDir, file))) {
|
|
372
|
+
if (await patchFirstConfigFile(rootDir, [file], require_init_utils_toolConfigManipulation.setTanStackRouteFileIgnorePattern, (0, _intlayer_config_logger.colorize)("routeFileIgnorePattern", _intlayer_config_colors.GREY_LIGHT)) === void 0) (0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.x} Could not set ${(0, _intlayer_config_logger.colorize)("routeFileIgnorePattern", _intlayer_config_colors.GREY_LIGHT)} in ${(0, _intlayer_config_logger.colorizePath)(file)}. Add ${(0, _intlayer_config_logger.colorize)(`routeFileIgnorePattern: '${require_init_utils_toolConfigManipulation.CONTENT_DECLARATION_ROUTE_IGNORE_PATTERN}'`, _intlayer_config_colors.GREY_LIGHT)} to the TanStack Router options so .content files are not treated as routes.`, { level: "warn" });
|
|
373
|
+
}
|
|
348
374
|
break;
|
|
349
375
|
}
|
|
350
376
|
const nextConfigs = [
|