MCPcopy
hub / github.com/lingodotdev/lingo.dev / ensurePatterns

Function ensurePatterns

packages/cli/src/cli/utils/ensure-patterns.ts:6–19  ·  view source on GitHub ↗
(patterns: string[], source: string)

Source from the content-addressed store, hash-verified

4import { LocaleCode, resolveLocaleCode } from "@lingo.dev/_spec";
5
6export function ensurePatterns(patterns: string[], source: string) {
7 if (patterns.length === 0) {
8 throw new Error("No patterns found");
9 }
10
11 patterns.forEach((pattern) => {
12 const filePath = pattern.replace("[locale]", source);
13 if (!fs.existsSync(filePath)) {
14 const defaultContent = getDefaultContent(path.extname(filePath), source);
15 fs.mkdirSync(path.dirname(filePath), { recursive: true });
16 fs.writeFileSync(filePath, defaultContent);
17 }
18 });
19}
20
21function getDefaultContent(ext: string, source: string) {
22 const defaultGreeting = "Hello from Lingo.dev";

Callers 1

init.tsFile · 0.90

Calls 1

getDefaultContentFunction · 0.85

Tested by

no test coverage detected