@kopynator/cli 1.0.7 → 1.0.9
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 +37 -0
- package/package.json +1 -1
- package/src/commands/init.ts +45 -1
package/dist/index.js
CHANGED
|
@@ -97,6 +97,43 @@ 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
|
+
const hasImport = appConfigContent.includes("@kopynator/angular");
|
|
106
|
+
if (!hasImport) {
|
|
107
|
+
appConfigContent = `import { provideKopynator } from '@kopynator/angular';
|
|
108
|
+
` + appConfigContent;
|
|
109
|
+
}
|
|
110
|
+
if (appConfigContent.includes("provideKopynator(")) {
|
|
111
|
+
console.log(import_chalk.default.yellow("\u26A0\uFE0F provideKopynator is already present in app.config.ts. Skipping injection."));
|
|
112
|
+
} else {
|
|
113
|
+
const providerString = `
|
|
114
|
+
provideKopynator({
|
|
115
|
+
apiKey: 'YOUR_API_KEY_HERE',
|
|
116
|
+
defaultLocale: '${answers.defaultLocale}',
|
|
117
|
+
mode: 'local',
|
|
118
|
+
languages: ${JSON.stringify(answers.languages)},
|
|
119
|
+
}),`;
|
|
120
|
+
const providersRegex = /(providers:\s*\[)/;
|
|
121
|
+
if (providersRegex.test(appConfigContent)) {
|
|
122
|
+
appConfigContent = appConfigContent.replace(providersRegex, `$1${providerString}`);
|
|
123
|
+
import_fs.default.writeFileSync(configPath, appConfigContent);
|
|
124
|
+
console.log(import_chalk.default.green("\u2705 Successfully injected configuration into src/app/app.config.ts"));
|
|
125
|
+
console.log(import_chalk.default.yellow("\nNext steps:"));
|
|
126
|
+
console.log("1. Get your API Key from https://www.kopynator.com");
|
|
127
|
+
console.log("2. Update the apiKey in src/app/app.config.ts");
|
|
128
|
+
return;
|
|
129
|
+
} else {
|
|
130
|
+
console.log(import_chalk.default.yellow('\u26A0\uFE0F Could not find "providers: []" array in app.config.ts. Falling back to config file.'));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
console.log(import_chalk.default.yellow("\u26A0\uFE0F Could not find src/app/app.config.ts. Falling back to config file."));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
100
137
|
const configContent = {
|
|
101
138
|
apiKey: "YOUR_API_KEY_HERE",
|
|
102
139
|
defaultLocale: answers.defaultLocale,
|
package/package.json
CHANGED
package/src/commands/init.ts
CHANGED
|
@@ -70,7 +70,51 @@ 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
|
+
const hasImport = appConfigContent.includes('@kopynator/angular');
|
|
82
|
+
if (!hasImport) {
|
|
83
|
+
appConfigContent = `import { provideKopynator } from '@kopynator/angular';\n` + appConfigContent;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// 2. Add Provider
|
|
87
|
+
// Check for the *usage* of the provider, usually a call like provideKopynator({
|
|
88
|
+
if (appConfigContent.includes('provideKopynator(')) {
|
|
89
|
+
console.log(chalk.yellow('⚠️ provideKopynator is already present in app.config.ts. Skipping injection.'));
|
|
90
|
+
} else {
|
|
91
|
+
const providerString = `
|
|
92
|
+
provideKopynator({
|
|
93
|
+
apiKey: 'YOUR_API_KEY_HERE',
|
|
94
|
+
defaultLocale: '${answers.defaultLocale}',
|
|
95
|
+
mode: 'local',
|
|
96
|
+
languages: ${JSON.stringify(answers.languages)},
|
|
97
|
+
}),`;
|
|
98
|
+
|
|
99
|
+
const providersRegex = /(providers:\s*\[)/;
|
|
100
|
+
if (providersRegex.test(appConfigContent)) {
|
|
101
|
+
appConfigContent = appConfigContent.replace(providersRegex, `$1${providerString}`);
|
|
102
|
+
fs.writeFileSync(configPath, appConfigContent);
|
|
103
|
+
console.log(chalk.green('✅ Successfully injected configuration into src/app/app.config.ts'));
|
|
104
|
+
console.log(chalk.yellow('\nNext steps:'));
|
|
105
|
+
console.log('1. Get your API Key from https://www.kopynator.com');
|
|
106
|
+
console.log('2. Update the apiKey in src/app/app.config.ts');
|
|
107
|
+
return; // Exit successfully without creating json
|
|
108
|
+
} else {
|
|
109
|
+
console.log(chalk.yellow('⚠️ Could not find "providers: []" array in app.config.ts. Falling back to config file.'));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
console.log(chalk.yellow('⚠️ Could not find src/app/app.config.ts. Falling back to config file.'));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Fallback: Creates a basic config file
|
|
74
118
|
const configContent = {
|
|
75
119
|
apiKey: "YOUR_API_KEY_HERE",
|
|
76
120
|
defaultLocale: answers.defaultLocale,
|