(patterns: string[], source: string)
| 4 | import { LocaleCode, resolveLocaleCode } from "@lingo.dev/_spec"; |
| 5 | |
| 6 | export 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 | |
| 21 | function getDefaultContent(ext: string, source: string) { |
| 22 | const defaultGreeting = "Hello from Lingo.dev"; |
no test coverage detected