@kopynator/cli 1.0.8 → 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 CHANGED
@@ -102,20 +102,21 @@ async function initCommand() {
102
102
  if (import_fs.default.existsSync(configPath)) {
103
103
  console.log(import_chalk.default.blue("\u2139\uFE0F Detected Angular project structure. Attempting to modify app.config.ts..."));
104
104
  let appConfigContent = import_fs.default.readFileSync(configPath, "utf-8");
105
- if (!appConfigContent.includes("@kopynator/angular")) {
105
+ const hasImport = appConfigContent.includes("@kopynator/angular");
106
+ if (!hasImport) {
106
107
  appConfigContent = `import { provideKopynator } from '@kopynator/angular';
107
108
  ` + appConfigContent;
108
109
  }
109
- const providerString = `
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 = `
110
114
  provideKopynator({
111
115
  apiKey: 'YOUR_API_KEY_HERE',
112
116
  defaultLocale: '${answers.defaultLocale}',
113
117
  mode: 'local',
114
118
  languages: ${JSON.stringify(answers.languages)},
115
119
  }),`;
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
120
  const providersRegex = /(providers:\s*\[)/;
120
121
  if (providersRegex.test(appConfigContent)) {
121
122
  appConfigContent = appConfigContent.replace(providersRegex, `$1${providerString}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kopynator/cli",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "CLI tool for Kopynator - The i18n management solution",
5
5
  "bin": {
6
6
  "kopynator": "dist/index.js"
@@ -78,15 +78,17 @@ export async function initCommand() {
78
78
  let appConfigContent = fs.readFileSync(configPath, 'utf-8');
79
79
 
80
80
  // 1. Add Import if missing
81
- if (!appConfigContent.includes('@kopynator/angular')) {
81
+ const hasImport = appConfigContent.includes('@kopynator/angular');
82
+ if (!hasImport) {
82
83
  appConfigContent = `import { provideKopynator } from '@kopynator/angular';\n` + appConfigContent;
83
84
  }
84
85
 
85
86
  // 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 = `
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 = `
90
92
  provideKopynator({
91
93
  apiKey: 'YOUR_API_KEY_HERE',
92
94
  defaultLocale: '${answers.defaultLocale}',
@@ -94,9 +96,6 @@ export async function initCommand() {
94
96
  languages: ${JSON.stringify(answers.languages)},
95
97
  }),`;
96
98
 
97
- if (appConfigContent.includes('provideKopynator')) {
98
- console.log(chalk.yellow('⚠️ provideKopynator is already present in app.config.ts. Skipping injection.'));
99
- } else {
100
99
  const providersRegex = /(providers:\s*\[)/;
101
100
  if (providersRegex.test(appConfigContent)) {
102
101
  appConfigContent = appConfigContent.replace(providersRegex, `$1${providerString}`);