@kopynator/cli 1.0.7 → 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 +36 -0
- package/package.json +1 -1
- package/src/commands/init.ts +46 -1
package/dist/index.js
CHANGED
|
@@ -97,6 +97,42 @@ async function initCommand() {
|
|
|
97
97
|
]);
|
|
98
98
|
console.log(import_chalk.default.green(`
|
|
99
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
|
+
}
|
|
100
136
|
const configContent = {
|
|
101
137
|
apiKey: "YOUR_API_KEY_HERE",
|
|
102
138
|
defaultLocale: answers.defaultLocale,
|
package/package.json
CHANGED
package/src/commands/init.ts
CHANGED
|
@@ -70,7 +70,52 @@ export async function initCommand() {
|
|
|
70
70
|
|
|
71
71
|
console.log(chalk.green(`\n✅ Setting up for ${answers.framework}...`));
|
|
72
72
|
|
|
73
|
-
|
|
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
|
|
74
119
|
const configContent = {
|
|
75
120
|
apiKey: "YOUR_API_KEY_HERE",
|
|
76
121
|
defaultLocale: answers.defaultLocale,
|