@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 +75 -37
- package/package.json +1 -1
- package/src/commands/init.ts +85 -4
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
|
-
"
|
|
64
|
-
"en-
|
|
65
|
-
"
|
|
66
|
-
"pt-
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
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
package/src/commands/init.ts
CHANGED
|
@@ -24,9 +24,45 @@ export async function initCommand() {
|
|
|
24
24
|
name: 'languages',
|
|
25
25
|
message: 'Select supported languages:',
|
|
26
26
|
choices: [
|
|
27
|
-
|
|
28
|
-
'
|
|
29
|
-
|
|
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
|
-
|
|
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,
|