@vocoder/cli 0.1.15 → 0.1.17

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.
@@ -0,0 +1,261 @@
1
+ // src/utils/detect-local.ts
2
+ import { existsSync, readFileSync } from "fs";
3
+ import { join } from "path";
4
+ function detectLocalEcosystem(cwd = process.cwd()) {
5
+ const packageManager = detectPackageManager(cwd);
6
+ const pkg = readPackageJson(cwd);
7
+ if (!pkg) {
8
+ return {
9
+ ecosystem: null,
10
+ framework: null,
11
+ packageManager,
12
+ uiPackage: null,
13
+ hasUnplugin: false,
14
+ hasUiPackage: false,
15
+ sourceLocale: null
16
+ };
17
+ }
18
+ const allDeps = {
19
+ ...pkg.dependencies ?? {},
20
+ ...pkg.devDependencies ?? {}
21
+ };
22
+ const hasUnplugin = "@vocoder/unplugin" in allDeps;
23
+ const { ecosystem, framework, uiPackage } = detectFromDeps(allDeps, cwd);
24
+ const hasUiPackage = uiPackage !== null && uiPackage in allDeps;
25
+ return {
26
+ ecosystem,
27
+ framework,
28
+ packageManager,
29
+ uiPackage,
30
+ hasUnplugin,
31
+ hasUiPackage,
32
+ sourceLocale: null
33
+ };
34
+ }
35
+ function detectPackageManager(cwd) {
36
+ if (existsSync(join(cwd, "pnpm-lock.yaml"))) return "pnpm";
37
+ if (existsSync(join(cwd, "bun.lockb")) || existsSync(join(cwd, "bun.lock"))) return "bun";
38
+ if (existsSync(join(cwd, "yarn.lock"))) return "yarn";
39
+ return "npm";
40
+ }
41
+ function readPackageJson(cwd) {
42
+ const pkgPath = join(cwd, "package.json");
43
+ if (!existsSync(pkgPath)) return null;
44
+ try {
45
+ return JSON.parse(readFileSync(pkgPath, "utf-8"));
46
+ } catch {
47
+ return null;
48
+ }
49
+ }
50
+ function detectFromDeps(allDeps, cwd) {
51
+ if ("vue" in allDeps) {
52
+ const framework = "nuxt" in allDeps ? "nuxt" : null;
53
+ return { ecosystem: "vue", framework, uiPackage: "@vocoder/vue" };
54
+ }
55
+ if ("svelte" in allDeps) {
56
+ const framework = "@sveltejs/kit" in allDeps ? "sveltekit" : null;
57
+ return { ecosystem: "svelte", framework, uiPackage: "@vocoder/svelte" };
58
+ }
59
+ if ("@angular/core" in allDeps || existsSync(join(cwd, "angular.json"))) {
60
+ return { ecosystem: "angular", framework: "angular", uiPackage: "@vocoder/angular" };
61
+ }
62
+ if ("react" in allDeps) {
63
+ let framework = null;
64
+ if ("next" in allDeps) framework = "nextjs";
65
+ else if ("@remix-run/react" in allDeps) framework = "remix";
66
+ else if ("gatsby" in allDeps) framework = "gatsby";
67
+ else if ("vite" in allDeps) framework = "vite";
68
+ return { ecosystem: "react", framework, uiPackage: "@vocoder/react" };
69
+ }
70
+ return { ecosystem: null, framework: null, uiPackage: null };
71
+ }
72
+ function buildInstallCommand(packageManager, packages) {
73
+ if (packages.length === 0) return "";
74
+ const pkgList = packages.join(" ");
75
+ switch (packageManager) {
76
+ case "pnpm":
77
+ return `pnpm add ${pkgList}`;
78
+ case "yarn":
79
+ return `yarn add ${pkgList}`;
80
+ case "bun":
81
+ return `bun add ${pkgList}`;
82
+ default:
83
+ return `npm install ${pkgList}`;
84
+ }
85
+ }
86
+ function getPackagesToInstall(detection) {
87
+ const packages = [];
88
+ if (!detection.hasUnplugin) packages.push("@vocoder/unplugin");
89
+ if (detection.uiPackage && !detection.hasUiPackage) packages.push(detection.uiPackage);
90
+ return packages;
91
+ }
92
+
93
+ // src/utils/setup-snippets.ts
94
+ function getSetupSnippets(params) {
95
+ const { framework, ecosystem, sourceLocale } = params;
96
+ return {
97
+ pluginStep: getPluginSnippet(framework, ecosystem),
98
+ providerStep: getProviderSnippet(ecosystem, sourceLocale),
99
+ wrapStep: getWrapSnippet(ecosystem),
100
+ whatsNext: "Push to a target branch to trigger translations."
101
+ };
102
+ }
103
+ function getPluginSnippet(framework, ecosystem) {
104
+ switch (framework) {
105
+ case "nextjs":
106
+ return {
107
+ file: "next.config.ts",
108
+ code: `import { withVocoder } from '@vocoder/unplugin/next';
109
+
110
+ export default withVocoder({
111
+ // your existing Next.js config
112
+ });`
113
+ };
114
+ case "vite":
115
+ case "remix":
116
+ return {
117
+ file: "vite.config.ts",
118
+ code: `import vocoder from '@vocoder/unplugin/vite';
119
+
120
+ export default defineConfig({
121
+ plugins: [
122
+ vocoder(),
123
+ // your other plugins
124
+ ],
125
+ });`
126
+ };
127
+ case "nuxt":
128
+ return {
129
+ file: "nuxt.config.ts",
130
+ code: `import vocoder from '@vocoder/unplugin/vite';
131
+
132
+ export default defineNuxtConfig({
133
+ vite: {
134
+ plugins: [vocoder()],
135
+ },
136
+ });`
137
+ };
138
+ case "sveltekit":
139
+ return {
140
+ file: "vite.config.ts",
141
+ code: `import vocoder from '@vocoder/unplugin/vite';
142
+ import { sveltekit } from '@sveltejs/kit/vite';
143
+
144
+ export default defineConfig({
145
+ plugins: [
146
+ sveltekit(),
147
+ vocoder(),
148
+ ],
149
+ });`
150
+ };
151
+ case "gatsby":
152
+ return {
153
+ file: "gatsby-node.js",
154
+ code: `const vocoder = require('@vocoder/unplugin/webpack');
155
+
156
+ exports.onCreateWebpackConfig = ({ actions }) => {
157
+ actions.setWebpackConfig({
158
+ plugins: [vocoder()],
159
+ });
160
+ };`
161
+ };
162
+ case "angular":
163
+ return null;
164
+ // Angular CLI doesn't expose plugin config easily
165
+ default:
166
+ if (ecosystem) {
167
+ return {
168
+ file: "your bundler config",
169
+ code: `// Vite
170
+ import vocoder from '@vocoder/unplugin/vite';
171
+ // Webpack
172
+ const vocoder = require('@vocoder/unplugin/webpack');
173
+
174
+ // Add vocoder() to your plugins array`
175
+ };
176
+ }
177
+ return null;
178
+ }
179
+ }
180
+ function getProviderSnippet(ecosystem, sourceLocale) {
181
+ switch (ecosystem) {
182
+ case "react":
183
+ return {
184
+ file: "your root layout or App component",
185
+ code: `import { VocoderProvider } from '@vocoder/react';
186
+
187
+ <VocoderProvider defaultLocale="${sourceLocale}">
188
+ {children}
189
+ </VocoderProvider>`
190
+ };
191
+ case "vue":
192
+ return {
193
+ file: "your app entry",
194
+ code: `import { createVocoder } from '@vocoder/vue';
195
+
196
+ const vocoder = createVocoder({
197
+ defaultLocale: '${sourceLocale}',
198
+ });
199
+
200
+ app.use(vocoder);`
201
+ };
202
+ case "svelte":
203
+ return {
204
+ file: "your root layout",
205
+ code: `<script>
206
+ import { VocoderProvider } from '@vocoder/svelte';
207
+ </script>
208
+
209
+ <VocoderProvider defaultLocale="${sourceLocale}">
210
+ <slot />
211
+ </VocoderProvider>`
212
+ };
213
+ default:
214
+ return null;
215
+ }
216
+ }
217
+ function getWrapSnippet(ecosystem) {
218
+ switch (ecosystem) {
219
+ case "react":
220
+ return {
221
+ code: `import { T } from '@vocoder/react';
222
+
223
+ <T>Hello, world!</T>`
224
+ };
225
+ case "vue":
226
+ return {
227
+ code: `<template>
228
+ <T>Hello, world!</T>
229
+ </template>
230
+
231
+ <script setup>
232
+ import { T } from '@vocoder/vue';
233
+ </script>`
234
+ };
235
+ case "svelte":
236
+ return {
237
+ code: `<script>
238
+ import { T } from '@vocoder/svelte';
239
+ </script>
240
+
241
+ <T>Hello, world!</T>`
242
+ };
243
+ default:
244
+ return {
245
+ code: `// Wrap translatable strings with <T>
246
+ <T>Hello, world!</T>`
247
+ };
248
+ }
249
+ }
250
+
251
+ // src/utils/extract.ts
252
+ import { StringExtractor } from "@vocoder/extractor";
253
+
254
+ export {
255
+ detectLocalEcosystem,
256
+ buildInstallCommand,
257
+ getPackagesToInstall,
258
+ getSetupSnippets,
259
+ StringExtractor
260
+ };
261
+ //# sourceMappingURL=chunk-3QBORM6T.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/detect-local.ts","../src/utils/setup-snippets.ts","../src/utils/extract.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'fs';\nimport { join } from 'path';\n\nexport type PackageManager = 'pnpm' | 'npm' | 'yarn' | 'bun';\n\nexport type DetectedFramework =\n | 'nextjs'\n | 'vite'\n | 'remix'\n | 'nuxt'\n | 'sveltekit'\n | 'gatsby'\n | 'angular'\n | null;\n\nexport type DetectedEcosystem =\n | 'react'\n | 'vue'\n | 'svelte'\n | 'angular'\n | null;\n\nexport interface LocalDetectionResult {\n ecosystem: DetectedEcosystem;\n framework: DetectedFramework;\n packageManager: PackageManager;\n uiPackage: string | null;\n hasUnplugin: boolean;\n hasUiPackage: boolean;\n sourceLocale: string | null;\n}\n\n/**\n * Detect the local project's ecosystem, framework, and package manager\n * by inspecting filesystem artifacts. No network calls.\n */\nexport function detectLocalEcosystem(cwd: string = process.cwd()): LocalDetectionResult {\n const packageManager = detectPackageManager(cwd);\n const pkg = readPackageJson(cwd);\n\n if (!pkg) {\n return {\n ecosystem: null,\n framework: null,\n packageManager,\n uiPackage: null,\n hasUnplugin: false,\n hasUiPackage: false,\n sourceLocale: null,\n };\n }\n\n const allDeps = {\n ...((pkg.dependencies as Record<string, string>) ?? {}),\n ...((pkg.devDependencies as Record<string, string>) ?? {}),\n };\n\n const hasUnplugin = '@vocoder/unplugin' in allDeps;\n\n // Detect ecosystem + framework\n const { ecosystem, framework, uiPackage } = detectFromDeps(allDeps, cwd);\n const hasUiPackage = uiPackage !== null && uiPackage in allDeps;\n\n return {\n ecosystem,\n framework,\n packageManager,\n uiPackage,\n hasUnplugin,\n hasUiPackage,\n sourceLocale: null,\n };\n}\n\nfunction detectPackageManager(cwd: string): PackageManager {\n if (existsSync(join(cwd, 'pnpm-lock.yaml'))) return 'pnpm';\n if (existsSync(join(cwd, 'bun.lockb')) || existsSync(join(cwd, 'bun.lock'))) return 'bun';\n if (existsSync(join(cwd, 'yarn.lock'))) return 'yarn';\n return 'npm';\n}\n\nfunction readPackageJson(cwd: string): Record<string, unknown> | null {\n const pkgPath = join(cwd, 'package.json');\n if (!existsSync(pkgPath)) return null;\n try {\n return JSON.parse(readFileSync(pkgPath, 'utf-8')) as Record<string, unknown>;\n } catch {\n return null;\n }\n}\n\nfunction detectFromDeps(\n allDeps: Record<string, string>,\n cwd: string,\n): { ecosystem: DetectedEcosystem; framework: DetectedFramework; uiPackage: string | null } {\n // Vue ecosystem\n if ('vue' in allDeps) {\n const framework = 'nuxt' in allDeps ? 'nuxt' as const : null;\n return { ecosystem: 'vue', framework, uiPackage: '@vocoder/vue' };\n }\n\n // Svelte ecosystem\n if ('svelte' in allDeps) {\n const framework = '@sveltejs/kit' in allDeps ? 'sveltekit' as const : null;\n return { ecosystem: 'svelte', framework, uiPackage: '@vocoder/svelte' };\n }\n\n // Angular ecosystem\n if ('@angular/core' in allDeps || existsSync(join(cwd, 'angular.json'))) {\n return { ecosystem: 'angular', framework: 'angular', uiPackage: '@vocoder/angular' };\n }\n\n // React ecosystem (most common — check last)\n if ('react' in allDeps) {\n let framework: DetectedFramework = null;\n if ('next' in allDeps) framework = 'nextjs';\n else if ('@remix-run/react' in allDeps) framework = 'remix';\n else if ('gatsby' in allDeps) framework = 'gatsby';\n else if ('vite' in allDeps) framework = 'vite';\n return { ecosystem: 'react', framework, uiPackage: '@vocoder/react' };\n }\n\n return { ecosystem: null, framework: null, uiPackage: null };\n}\n\n/**\n * Build the install command for packages that aren't already installed.\n */\nexport function buildInstallCommand(\n packageManager: PackageManager,\n packages: string[],\n): string {\n if (packages.length === 0) return '';\n const pkgList = packages.join(' ');\n switch (packageManager) {\n case 'pnpm':\n return `pnpm add ${pkgList}`;\n case 'yarn':\n return `yarn add ${pkgList}`;\n case 'bun':\n return `bun add ${pkgList}`;\n default:\n return `npm install ${pkgList}`;\n }\n}\n\n/**\n * Get the list of packages that need to be installed.\n */\nexport function getPackagesToInstall(detection: LocalDetectionResult): string[] {\n const packages: string[] = [];\n if (!detection.hasUnplugin) packages.push('@vocoder/unplugin');\n if (detection.uiPackage && !detection.hasUiPackage) packages.push(detection.uiPackage);\n return packages;\n}\n","import type { DetectedEcosystem, DetectedFramework } from './detect-local.js';\n\nexport interface SetupSnippets {\n pluginStep: { file: string; code: string } | null;\n providerStep: { file: string; code: string } | null;\n wrapStep: { code: string };\n whatsNext: string;\n}\n\n/**\n * Generate framework-specific setup snippets.\n */\nexport function getSetupSnippets(params: {\n framework: DetectedFramework;\n ecosystem: DetectedEcosystem;\n sourceLocale: string;\n targetBranches: string[];\n}): SetupSnippets {\n const { framework, ecosystem, sourceLocale } = params;\n\n return {\n pluginStep: getPluginSnippet(framework, ecosystem),\n providerStep: getProviderSnippet(ecosystem, sourceLocale),\n wrapStep: getWrapSnippet(ecosystem),\n whatsNext: 'Push to a target branch to trigger translations.',\n };\n}\n\nfunction getPluginSnippet(\n framework: DetectedFramework,\n ecosystem: DetectedEcosystem,\n): { file: string; code: string } | null {\n switch (framework) {\n case 'nextjs':\n return {\n file: 'next.config.ts',\n code: `import { withVocoder } from '@vocoder/unplugin/next';\n\nexport default withVocoder({\n // your existing Next.js config\n});`,\n };\n\n case 'vite':\n case 'remix':\n return {\n file: 'vite.config.ts',\n code: `import vocoder from '@vocoder/unplugin/vite';\n\nexport default defineConfig({\n plugins: [\n vocoder(),\n // your other plugins\n ],\n});`,\n };\n\n case 'nuxt':\n return {\n file: 'nuxt.config.ts',\n code: `import vocoder from '@vocoder/unplugin/vite';\n\nexport default defineNuxtConfig({\n vite: {\n plugins: [vocoder()],\n },\n});`,\n };\n\n case 'sveltekit':\n return {\n file: 'vite.config.ts',\n code: `import vocoder from '@vocoder/unplugin/vite';\nimport { sveltekit } from '@sveltejs/kit/vite';\n\nexport default defineConfig({\n plugins: [\n sveltekit(),\n vocoder(),\n ],\n});`,\n };\n\n case 'gatsby':\n return {\n file: 'gatsby-node.js',\n code: `const vocoder = require('@vocoder/unplugin/webpack');\n\nexports.onCreateWebpackConfig = ({ actions }) => {\n actions.setWebpackConfig({\n plugins: [vocoder()],\n });\n};`,\n };\n\n case 'angular':\n return null; // Angular CLI doesn't expose plugin config easily\n\n default:\n // No known framework — if they have React/Vue/Svelte, they likely have a bundler\n // but we can't guess which config file. Give generic advice.\n if (ecosystem) {\n return {\n file: 'your bundler config',\n code: `// Vite\nimport vocoder from '@vocoder/unplugin/vite';\n// Webpack\nconst vocoder = require('@vocoder/unplugin/webpack');\n\n// Add vocoder() to your plugins array`,\n };\n }\n return null;\n }\n}\n\nfunction getProviderSnippet(\n ecosystem: DetectedEcosystem,\n sourceLocale: string,\n): { file: string; code: string } | null {\n switch (ecosystem) {\n case 'react':\n return {\n file: 'your root layout or App component',\n code: `import { VocoderProvider } from '@vocoder/react';\n\n<VocoderProvider defaultLocale=\"${sourceLocale}\">\n {children}\n</VocoderProvider>`,\n };\n\n case 'vue':\n return {\n file: 'your app entry',\n code: `import { createVocoder } from '@vocoder/vue';\n\nconst vocoder = createVocoder({\n defaultLocale: '${sourceLocale}',\n});\n\napp.use(vocoder);`,\n };\n\n case 'svelte':\n return {\n file: 'your root layout',\n code: `<script>\n import { VocoderProvider } from '@vocoder/svelte';\n</script>\n\n<VocoderProvider defaultLocale=\"${sourceLocale}\">\n <slot />\n</VocoderProvider>`,\n };\n\n default:\n return null;\n }\n}\n\nfunction getWrapSnippet(ecosystem: DetectedEcosystem): { code: string } {\n switch (ecosystem) {\n case 'react':\n return {\n code: `import { T } from '@vocoder/react';\n\n<T>Hello, world!</T>`,\n };\n\n case 'vue':\n return {\n code: `<template>\n <T>Hello, world!</T>\n</template>\n\n<script setup>\nimport { T } from '@vocoder/vue';\n</script>`,\n };\n\n case 'svelte':\n return {\n code: `<script>\n import { T } from '@vocoder/svelte';\n</script>\n\n<T>Hello, world!</T>`,\n };\n\n default:\n return {\n code: `// Wrap translatable strings with <T>\n<T>Hello, world!</T>`,\n };\n }\n}\n\n","export { StringExtractor, type ExtractedString } from '@vocoder/extractor';\n"],"mappings":";AAAA,SAAS,YAAY,oBAAoB;AACzC,SAAS,YAAY;AAmCd,SAAS,qBAAqB,MAAc,QAAQ,IAAI,GAAyB;AACtF,QAAM,iBAAiB,qBAAqB,GAAG;AAC/C,QAAM,MAAM,gBAAgB,GAAG;AAE/B,MAAI,CAAC,KAAK;AACR,WAAO;AAAA,MACL,WAAW;AAAA,M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AA,MAGR;AAAA,IAEF,KAAK;AACH,aAAO;AAAA,QACL,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAOR;AAAA,IAEF,KAAK;AACH,aAAO;AAAA,QACL,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,MAKR;AAAA,IAEF;AACE,aAAO;AAAA,QACL,MAAM;AAAA;AAAA,MAER;AAAA,EACJ;AACF;;;ACnMA,SAAS,uBAA6C;","names":[]}
package/dist/lib.d.mts CHANGED
@@ -1,3 +1,55 @@
1
+ export { ExtractedString, StringExtractor } from '@vocoder/extractor';
2
+
3
+ type PackageManager = 'pnpm' | 'npm' | 'yarn' | 'bun';
4
+ type DetectedFramework = 'nextjs' | 'vite' | 'remix' | 'nuxt' | 'sveltekit' | 'gatsby' | 'angular' | null;
5
+ type DetectedEcosystem = 'react' | 'vue' | 'svelte' | 'angular' | null;
6
+ interface LocalDetectionResult {
7
+ ecosystem: DetectedEcosystem;
8
+ framework: DetectedFramework;
9
+ packageManager: PackageManager;
10
+ uiPackage: string | null;
11
+ hasUnplugin: boolean;
12
+ hasUiPackage: boolean;
13
+ sourceLocale: string | null;
14
+ }
15
+ /**
16
+ * Detect the local project's ecosystem, framework, and package manager
17
+ * by inspecting filesystem artifacts. No network calls.
18
+ */
19
+ declare function detectLocalEcosystem(cwd?: string): LocalDetectionResult;
20
+ /**
21
+ * Build the install command for packages that aren't already installed.
22
+ */
23
+ declare function buildInstallCommand(packageManager: PackageManager, packages: string[]): string;
24
+ /**
25
+ * Get the list of packages that need to be installed.
26
+ */
27
+ declare function getPackagesToInstall(detection: LocalDetectionResult): string[];
28
+
29
+ interface SetupSnippets {
30
+ pluginStep: {
31
+ file: string;
32
+ code: string;
33
+ } | null;
34
+ providerStep: {
35
+ file: string;
36
+ code: string;
37
+ } | null;
38
+ wrapStep: {
39
+ code: string;
40
+ };
41
+ whatsNext: string;
42
+ }
43
+ /**
44
+ * Generate framework-specific setup snippets.
45
+ */
46
+ declare function getSetupSnippets(params: {
47
+ framework: DetectedFramework;
48
+ ecosystem: DetectedEcosystem;
49
+ sourceLocale: string;
50
+ targetBranches: string[];
51
+ }): SetupSnippets;
52
+
1
53
  type EffectiveSyncMode = 'required' | 'best-effort';
2
54
  interface SyncPolicyConfig {
3
55
  blockingBranches: string[];
@@ -5,28 +57,15 @@ interface SyncPolicyConfig {
5
57
  nonBlockingMode: EffectiveSyncMode;
6
58
  defaultMaxWaitMs: number;
7
59
  }
8
- interface BranchTriggerConfig {
9
- pattern: string;
10
- triggers: string[];
11
- }
12
60
  interface APIProjectConfig {
13
61
  projectName: string;
14
62
  organizationName: string;
15
63
  sourceLocale: string;
16
64
  targetLocales: string[];
17
- branchTriggers: BranchTriggerConfig[];
18
- /** Primary branch derived from branchTriggers (first non-wildcard pattern) */
65
+ targetBranches: string[];
19
66
  primaryBranch?: string;
20
67
  syncPolicy: SyncPolicyConfig;
21
68
  }
22
- interface ExtractedString {
23
- key: string;
24
- text: string;
25
- file: string;
26
- line: number;
27
- context?: string;
28
- formality?: 'formal' | 'informal' | 'neutral' | 'auto';
29
- }
30
69
  interface TranslationBatchResponse {
31
70
  batchId: string;
32
71
  newStrings: number;
@@ -86,98 +125,4 @@ interface SyncPolicyErrorResponse {
86
125
  boundScopePath?: string | null;
87
126
  }
88
127
 
89
- /**
90
- * Extract translatable strings from source files
91
- *
92
- * NOTE: This is a simplified version for the CLI MVP.
93
- * Eventually this logic should be moved to a shared @vocoder/extraction package
94
- * that can be used by both the CLI and the backend.
95
- */
96
- declare class StringExtractor {
97
- /**
98
- * Extract strings from all files matching the pattern(s)
99
- *
100
- * @param pattern - Glob pattern(s) to include
101
- * @param projectRoot - Project root directory
102
- * @param excludePattern - Glob pattern(s) to exclude (optional)
103
- */
104
- extractFromProject(pattern: string | string[], projectRoot?: string, excludePattern?: string | string[]): Promise<ExtractedString[]>;
105
- /**
106
- * Extract strings from a single file
107
- */
108
- private extractFromFile;
109
- /**
110
- * Extract text from template literal
111
- * Converts template literals like `Hello ${name}` to `Hello {name}`
112
- */
113
- private extractTemplateText;
114
- /**
115
- * Extract text content from JSX children
116
- */
117
- private extractTextContent;
118
- /**
119
- * Get string value from JSX attribute
120
- * Handles both string literals and template literals
121
- */
122
- private getStringAttribute;
123
- /**
124
- * Deduplicate strings (keep first occurrence)
125
- */
126
- private deduplicateStrings;
127
- private generateStableKey;
128
- }
129
-
130
- type PackageManager = 'pnpm' | 'npm' | 'yarn' | 'bun';
131
- type DetectedFramework = 'nextjs' | 'vite' | 'remix' | 'nuxt' | 'sveltekit' | 'gatsby' | 'angular' | null;
132
- type DetectedEcosystem = 'react' | 'vue' | 'svelte' | 'angular' | null;
133
- interface LocalDetectionResult {
134
- ecosystem: DetectedEcosystem;
135
- framework: DetectedFramework;
136
- packageManager: PackageManager;
137
- uiPackage: string | null;
138
- hasUnplugin: boolean;
139
- hasUiPackage: boolean;
140
- sourceLocale: string | null;
141
- }
142
- /**
143
- * Detect the local project's ecosystem, framework, and package manager
144
- * by inspecting filesystem artifacts. No network calls.
145
- */
146
- declare function detectLocalEcosystem(cwd?: string): LocalDetectionResult;
147
- /**
148
- * Build the install command for packages that aren't already installed.
149
- */
150
- declare function buildInstallCommand(packageManager: PackageManager, packages: string[]): string;
151
- /**
152
- * Get the list of packages that need to be installed.
153
- */
154
- declare function getPackagesToInstall(detection: LocalDetectionResult): string[];
155
-
156
- interface SetupSnippets {
157
- pluginStep: {
158
- file: string;
159
- code: string;
160
- } | null;
161
- providerStep: {
162
- file: string;
163
- code: string;
164
- } | null;
165
- wrapStep: {
166
- code: string;
167
- };
168
- whatsNext: string;
169
- }
170
- /**
171
- * Generate framework-specific setup snippets.
172
- */
173
- declare function getSetupSnippets(params: {
174
- framework: DetectedFramework;
175
- ecosystem: DetectedEcosystem;
176
- sourceLocale: string;
177
- branchTriggers: Array<{
178
- pattern: string;
179
- triggers: string[];
180
- }>;
181
- }): SetupSnippets;
182
-
183
- export { type APIProjectConfig, type DetectedEcosystem, type DetectedFramework, type ExtractedString, type LimitErrorResponse, type LocalDetectionResult, type PackageManager, type SetupSnippets, StringExtractor, type SyncPolicyConfig, type SyncPolicyErrorResponse, type TranslationBatchResponse, type TranslationSnapshotResponse, type TranslationStatusResponse, buildInstallCommand, detectLocalEcosystem, getPackagesToInstall, getSetupSnippets };
128
+ export { type APIProjectConfig, type DetectedEcosystem, type DetectedFramework, type LimitErrorResponse, type LocalDetectionResult, type PackageManager, type SetupSnippets, type SyncPolicyConfig, type SyncPolicyErrorResponse, type TranslationBatchResponse, type TranslationSnapshotResponse, type TranslationStatusResponse, buildInstallCommand, detectLocalEcosystem, getPackagesToInstall, getSetupSnippets };
package/dist/lib.mjs CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  detectLocalEcosystem,
5
5
  getPackagesToInstall,
6
6
  getSetupSnippets
7
- } from "./chunk-KPIT5ETY.mjs";
7
+ } from "./chunk-3QBORM6T.mjs";
8
8
  export {
9
9
  StringExtractor,
10
10
  buildInstallCommand,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vocoder/cli",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "description": "CLI tool for Vocoder translation workflow",
5
5
  "files": [
6
6
  "dist"
@@ -38,35 +38,29 @@
38
38
  "bugs": {
39
39
  "url": "https://github.com/vocoder/vocoder-sdk/issues"
40
40
  },
41
- "scripts": {
42
- "build": "tsup",
43
- "dev": "tsup --watch",
44
- "watch": "tsup --watch",
45
- "test": "vitest run --exclude 'src/__tests__/integration/**'",
46
- "test:watch": "vitest",
47
- "test:unit": "vitest run --exclude 'src/__tests__/integration/**'",
48
- "test:integration": "RUN_INTEGRATION=true vitest run src/__tests__/integration",
49
- "typecheck": "tsc --noEmit"
50
- },
51
41
  "dependencies": {
52
- "@babel/core": "^7.26.0",
53
- "@babel/parser": "^7.26.0",
54
- "@babel/traverse": "^7.26.0",
55
- "@babel/types": "^7.26.0",
56
42
  "@clack/core": "0.4.1",
57
43
  "@clack/prompts": "^0.9.1",
58
44
  "chalk": "^5.3.0",
59
45
  "commander": "^11.1.0",
60
46
  "dotenv": "^16.3.1",
61
- "glob": "^10.3.10",
62
- "tsx": "^4.7.0"
47
+ "tsx": "^4.7.0",
48
+ "@vocoder/extractor": "0.1.0"
63
49
  },
64
50
  "devDependencies": {
65
- "@types/babel__core": "^7.20.5",
66
- "@types/babel__traverse": "^7.20.6",
67
51
  "@types/node": "^20.19.9",
68
52
  "tsup": "^8.0.0",
69
53
  "typescript": "^5.4.0",
70
54
  "vitest": "^1.0.0"
55
+ },
56
+ "scripts": {
57
+ "build": "tsup",
58
+ "dev": "tsup --watch",
59
+ "watch": "tsup --watch",
60
+ "test": "vitest run --exclude 'src/__tests__/integration/**'",
61
+ "test:watch": "vitest",
62
+ "test:unit": "vitest run --exclude 'src/__tests__/integration/**'",
63
+ "test:integration": "RUN_INTEGRATION=true vitest run src/__tests__/integration",
64
+ "typecheck": "tsc --noEmit"
71
65
  }
72
- }
66
+ }