@kopynator/cli 1.0.6 → 1.0.8

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/index.js CHANGED
@@ -52,49 +52,87 @@ async function initCommand() {
52
52
  name: "languages",
53
53
  message: "Select supported languages:",
54
54
  choices: [
55
- "en",
56
- "es",
57
- "fr",
58
- "de",
59
- "it",
60
- "pt",
61
- "zh",
62
- "ja",
63
- "en-US",
64
- "en-GB",
65
- "pt-BR",
66
- "pt-PT",
67
- "ar",
68
- "bn",
69
- "ca",
70
- "cs",
71
- "da",
72
- "el",
73
- "fi",
74
- "he",
75
- "hi",
76
- "hu",
77
- "id",
78
- "ko",
79
- "ms",
80
- "nl",
81
- "no",
82
- "pl",
83
- "ro",
84
- "ru",
85
- "sv",
86
- "ta",
87
- "te",
88
- "th",
89
- "tr",
90
- "uk",
91
- "vi"
55
+ { name: "\u{1F1FA}\u{1F1F8} English (en)", value: "en" },
56
+ { name: "\u{1F1EA}\u{1F1F8} Spanish (es)", value: "es" },
57
+ { name: "\u{1F1EB}\u{1F1F7} French (fr)", value: "fr" },
58
+ { name: "\u{1F1E9}\u{1F1EA} German (de)", value: "de" },
59
+ { name: "\u{1F1EE}\u{1F1F9} Italian (it)", value: "it" },
60
+ { name: "\u{1F1F5}\u{1F1F9} Portuguese (pt)", value: "pt" },
61
+ { name: "\u{1F1E8}\u{1F1F3} Chinese (zh)", value: "zh" },
62
+ { name: "\u{1F1EF}\u{1F1F5} Japanese (ja)", value: "ja" },
63
+ new import_inquirer.default.Separator("--- Variations ---"),
64
+ { name: "\u{1F1FA}\u{1F1F8} English (US) (en-US)", value: "en-US" },
65
+ { name: "\u{1F1EC}\u{1F1E7} English (UK) (en-GB)", value: "en-GB" },
66
+ { name: "\u{1F1E7}\u{1F1F7} Portuguese (Brazil) (pt-BR)", value: "pt-BR" },
67
+ { name: "\u{1F1F5}\u{1F1F9} Portuguese (Portugal) (pt-PT)", value: "pt-PT" },
68
+ new import_inquirer.default.Separator("--- Others ---"),
69
+ { name: "\u{1F1F8}\u{1F1E6} Arabic (ar)", value: "ar" },
70
+ { name: "\u{1F1E7}\u{1F1E9} Bengali (bn)", value: "bn" },
71
+ { name: "\u{1F1EA}\u{1F1F8} Catalan (ca)", value: "ca" },
72
+ { name: "\u{1F1E8}\u{1F1FF} Czech (cs)", value: "cs" },
73
+ { name: "\u{1F1E9}\u{1F1F0} Danish (da)", value: "da" },
74
+ { name: "\u{1F1F3}\u{1F1F1} Dutch (nl)", value: "nl" },
75
+ { name: "\u{1F1EB}\u{1F1EE} Finnish (fi)", value: "fi" },
76
+ { name: "\u{1F1EC}\u{1F1F7} Greek (el)", value: "el" },
77
+ { name: "\u{1F1EE}\u{1F1F1} Hebrew (he)", value: "he" },
78
+ { name: "\u{1F1EE}\u{1F1F3} Hindi (hi)", value: "hi" },
79
+ { name: "\u{1F1ED}\u{1F1FA} Hungarian (hu)", value: "hu" },
80
+ { name: "\u{1F1EE}\u{1F1E9} Indonesian (id)", value: "id" },
81
+ { name: "\u{1F1F0}\u{1F1F7} Korean (ko)", value: "ko" },
82
+ { name: "\u{1F1F2}\u{1F1FE} Malay (ms)", value: "ms" },
83
+ { name: "\u{1F1F3}\u{1F1F4} Norwegian (no)", value: "no" },
84
+ { name: "\u{1F1F5}\u{1F1F1} Polish (pl)", value: "pl" },
85
+ { name: "\u{1F1F7}\u{1F1F4} Romanian (ro)", value: "ro" },
86
+ { name: "\u{1F1F7}\u{1F1FA} Russian (ru)", value: "ru" },
87
+ { name: "\u{1F1F8}\u{1F1EA} Swedish (sv)", value: "sv" },
88
+ { name: "\u{1F1EE}\u{1F1F3} Tamil (ta)", value: "ta" },
89
+ { name: "\u{1F1EE}\u{1F1F3} Telugu (te)", value: "te" },
90
+ { name: "\u{1F1F9}\u{1F1ED} Thai (th)", value: "th" },
91
+ { name: "\u{1F1F9}\u{1F1F7} Turkish (tr)", value: "tr" },
92
+ { name: "\u{1F1FA}\u{1F1E6} Ukrainian (uk)", value: "uk" },
93
+ { name: "\u{1F1FB}\u{1F1F3} Vietnamese (vi)", value: "vi" }
92
94
  ],
93
95
  default: ["en", "es"]
94
96
  }
95
97
  ]);
96
98
  console.log(import_chalk.default.green(`
97
99
  \u2705 Setting up for ${answers.framework}...`));
100
+ if (answers.framework === "Angular") {
101
+ const configPath = import_path.default.join(process.cwd(), "src/app/app.config.ts");
102
+ if (import_fs.default.existsSync(configPath)) {
103
+ console.log(import_chalk.default.blue("\u2139\uFE0F Detected Angular project structure. Attempting to modify app.config.ts..."));
104
+ let appConfigContent = import_fs.default.readFileSync(configPath, "utf-8");
105
+ if (!appConfigContent.includes("@kopynator/angular")) {
106
+ appConfigContent = `import { provideKopynator } from '@kopynator/angular';
107
+ ` + appConfigContent;
108
+ }
109
+ const providerString = `
110
+ provideKopynator({
111
+ apiKey: 'YOUR_API_KEY_HERE',
112
+ defaultLocale: '${answers.defaultLocale}',
113
+ mode: 'local',
114
+ languages: ${JSON.stringify(answers.languages)},
115
+ }),`;
116
+ if (appConfigContent.includes("provideKopynator")) {
117
+ console.log(import_chalk.default.yellow("\u26A0\uFE0F provideKopynator is already present in app.config.ts. Skipping injection."));
118
+ } else {
119
+ const providersRegex = /(providers:\s*\[)/;
120
+ if (providersRegex.test(appConfigContent)) {
121
+ appConfigContent = appConfigContent.replace(providersRegex, `$1${providerString}`);
122
+ import_fs.default.writeFileSync(configPath, appConfigContent);
123
+ console.log(import_chalk.default.green("\u2705 Successfully injected configuration into src/app/app.config.ts"));
124
+ console.log(import_chalk.default.yellow("\nNext steps:"));
125
+ console.log("1. Get your API Key from https://www.kopynator.com");
126
+ console.log("2. Update the apiKey in src/app/app.config.ts");
127
+ return;
128
+ } else {
129
+ console.log(import_chalk.default.yellow('\u26A0\uFE0F Could not find "providers: []" array in app.config.ts. Falling back to config file.'));
130
+ }
131
+ }
132
+ } else {
133
+ console.log(import_chalk.default.yellow("\u26A0\uFE0F Could not find src/app/app.config.ts. Falling back to config file."));
134
+ }
135
+ }
98
136
  const configContent = {
99
137
  apiKey: "YOUR_API_KEY_HERE",
100
138
  defaultLocale: answers.defaultLocale,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kopynator/cli",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "CLI tool for Kopynator - The i18n management solution",
5
5
  "bin": {
6
6
  "kopynator": "dist/index.js"
@@ -24,9 +24,45 @@ export async function initCommand() {
24
24
  name: 'languages',
25
25
  message: 'Select supported languages:',
26
26
  choices: [
27
- 'en', 'es', 'fr', 'de', 'it', 'pt', 'zh', 'ja',
28
- 'en-US', 'en-GB', 'pt-BR', 'pt-PT',
29
- 'ar', 'bn', 'ca', 'cs', 'da', 'el', 'fi', 'he', 'hi', 'hu', 'id', 'ko', 'ms', 'nl', 'no', 'pl', 'ro', 'ru', 'sv', 'ta', 'te', 'th', 'tr', 'uk', 'vi'
27
+ { name: 'šŸ‡ŗšŸ‡ø English (en)', value: 'en' },
28
+ { name: 'šŸ‡ŖšŸ‡ø Spanish (es)', value: 'es' },
29
+ { name: 'šŸ‡«šŸ‡· French (fr)', value: 'fr' },
30
+ { name: 'šŸ‡©šŸ‡Ŗ German (de)', value: 'de' },
31
+ { name: 'šŸ‡®šŸ‡¹ Italian (it)', value: 'it' },
32
+ { name: 'šŸ‡µšŸ‡¹ Portuguese (pt)', value: 'pt' },
33
+ { name: 'šŸ‡ØšŸ‡³ Chinese (zh)', value: 'zh' },
34
+ { name: 'šŸ‡ÆšŸ‡µ Japanese (ja)', value: 'ja' },
35
+ new inquirer.Separator('--- Variations ---'),
36
+ { name: 'šŸ‡ŗšŸ‡ø English (US) (en-US)', value: 'en-US' },
37
+ { name: 'šŸ‡¬šŸ‡§ English (UK) (en-GB)', value: 'en-GB' },
38
+ { name: 'šŸ‡§šŸ‡· Portuguese (Brazil) (pt-BR)', value: 'pt-BR' },
39
+ { name: 'šŸ‡µšŸ‡¹ Portuguese (Portugal) (pt-PT)', value: 'pt-PT' },
40
+ new inquirer.Separator('--- Others ---'),
41
+ { name: 'šŸ‡øšŸ‡¦ Arabic (ar)', value: 'ar' },
42
+ { name: 'šŸ‡§šŸ‡© Bengali (bn)', value: 'bn' },
43
+ { name: 'šŸ‡ŖšŸ‡ø Catalan (ca)', value: 'ca' },
44
+ { name: 'šŸ‡ØšŸ‡æ Czech (cs)', value: 'cs' },
45
+ { name: 'šŸ‡©šŸ‡° Danish (da)', value: 'da' },
46
+ { name: 'šŸ‡³šŸ‡± Dutch (nl)', value: 'nl' },
47
+ { name: 'šŸ‡«šŸ‡® Finnish (fi)', value: 'fi' },
48
+ { name: 'šŸ‡¬šŸ‡· Greek (el)', value: 'el' },
49
+ { name: 'šŸ‡®šŸ‡± Hebrew (he)', value: 'he' },
50
+ { name: 'šŸ‡®šŸ‡³ Hindi (hi)', value: 'hi' },
51
+ { name: 'šŸ‡­šŸ‡ŗ Hungarian (hu)', value: 'hu' },
52
+ { name: 'šŸ‡®šŸ‡© Indonesian (id)', value: 'id' },
53
+ { name: 'šŸ‡°šŸ‡· Korean (ko)', value: 'ko' },
54
+ { name: 'šŸ‡²šŸ‡¾ Malay (ms)', value: 'ms' },
55
+ { name: 'šŸ‡³šŸ‡“ Norwegian (no)', value: 'no' },
56
+ { name: 'šŸ‡µšŸ‡± Polish (pl)', value: 'pl' },
57
+ { name: 'šŸ‡·šŸ‡“ Romanian (ro)', value: 'ro' },
58
+ { name: 'šŸ‡·šŸ‡ŗ Russian (ru)', value: 'ru' },
59
+ { name: 'šŸ‡øšŸ‡Ŗ Swedish (sv)', value: 'sv' },
60
+ { name: 'šŸ‡®šŸ‡³ Tamil (ta)', value: 'ta' },
61
+ { name: 'šŸ‡®šŸ‡³ Telugu (te)', value: 'te' },
62
+ { name: 'šŸ‡¹šŸ‡­ Thai (th)', value: 'th' },
63
+ { name: 'šŸ‡¹šŸ‡· Turkish (tr)', value: 'tr' },
64
+ { name: 'šŸ‡ŗšŸ‡¦ Ukrainian (uk)', value: 'uk' },
65
+ { name: 'šŸ‡»šŸ‡³ Vietnamese (vi)', value: 'vi' }
30
66
  ],
31
67
  default: ['en', 'es']
32
68
  }
@@ -34,7 +70,52 @@ export async function initCommand() {
34
70
 
35
71
  console.log(chalk.green(`\nāœ… Setting up for ${answers.framework}...`));
36
72
 
37
- // Creates a basic config file
73
+ if (answers.framework === 'Angular') {
74
+ const configPath = path.join(process.cwd(), 'src/app/app.config.ts');
75
+
76
+ if (fs.existsSync(configPath)) {
77
+ console.log(chalk.blue('ā„¹ļø Detected Angular project structure. Attempting to modify app.config.ts...'));
78
+ let appConfigContent = fs.readFileSync(configPath, 'utf-8');
79
+
80
+ // 1. Add Import if missing
81
+ if (!appConfigContent.includes('@kopynator/angular')) {
82
+ appConfigContent = `import { provideKopynator } from '@kopynator/angular';\n` + appConfigContent;
83
+ }
84
+
85
+ // 2. Add Provider
86
+ // Simple regex to find the providers array. This is a heuristic and might need AST for robust handling,
87
+ // but standard regex works for most standard Angular CLI generated files.
88
+ // We look for "providers: [" and insert our provider right after.
89
+ const providerString = `
90
+ provideKopynator({
91
+ apiKey: 'YOUR_API_KEY_HERE',
92
+ defaultLocale: '${answers.defaultLocale}',
93
+ mode: 'local',
94
+ languages: ${JSON.stringify(answers.languages)},
95
+ }),`;
96
+
97
+ if (appConfigContent.includes('provideKopynator')) {
98
+ console.log(chalk.yellow('āš ļø provideKopynator is already present in app.config.ts. Skipping injection.'));
99
+ } else {
100
+ const providersRegex = /(providers:\s*\[)/;
101
+ if (providersRegex.test(appConfigContent)) {
102
+ appConfigContent = appConfigContent.replace(providersRegex, `$1${providerString}`);
103
+ fs.writeFileSync(configPath, appConfigContent);
104
+ console.log(chalk.green('āœ… Successfully injected configuration into src/app/app.config.ts'));
105
+ console.log(chalk.yellow('\nNext steps:'));
106
+ console.log('1. Get your API Key from https://www.kopynator.com');
107
+ console.log('2. Update the apiKey in src/app/app.config.ts');
108
+ return; // Exit successfully without creating json
109
+ } else {
110
+ console.log(chalk.yellow('āš ļø Could not find "providers: []" array in app.config.ts. Falling back to config file.'));
111
+ }
112
+ }
113
+ } else {
114
+ console.log(chalk.yellow('āš ļø Could not find src/app/app.config.ts. Falling back to config file.'));
115
+ }
116
+ }
117
+
118
+ // Fallback: Creates a basic config file
38
119
  const configContent = {
39
120
  apiKey: "YOUR_API_KEY_HERE",
40
121
  defaultLocale: answers.defaultLocale,