@kopynator/cli 1.0.9 → 1.0.10

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
@@ -98,17 +98,29 @@ async function initCommand() {
98
98
  console.log(import_chalk.default.green(`
99
99
  \u2705 Setting up for ${answers.framework}...`));
100
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");
101
+ const appConfigPath = import_path.default.join(process.cwd(), "src/app/app.config.ts");
102
+ const appModulePath = import_path.default.join(process.cwd(), "src/app/app.module.ts");
103
+ let targetPath = null;
104
+ let isModule = false;
105
+ if (import_fs.default.existsSync(appConfigPath)) {
106
+ targetPath = appConfigPath;
107
+ isModule = false;
108
+ console.log(import_chalk.default.blue("\u2139\uFE0F Detected Angular standalone project (app.config.ts)"));
109
+ } else if (import_fs.default.existsSync(appModulePath)) {
110
+ targetPath = appModulePath;
111
+ isModule = true;
112
+ console.log(import_chalk.default.blue("\u2139\uFE0F Detected Angular NgModule project (app.module.ts)"));
113
+ }
114
+ if (targetPath) {
115
+ let fileContent = import_fs.default.readFileSync(targetPath, "utf-8");
116
+ const hasImport = fileContent.includes("@kopynator/angular");
106
117
  if (!hasImport) {
107
- appConfigContent = `import { provideKopynator } from '@kopynator/angular';
108
- ` + appConfigContent;
118
+ fileContent = `import { provideKopynator } from '@kopynator/angular';
119
+ ` + fileContent;
109
120
  }
110
- if (appConfigContent.includes("provideKopynator(")) {
111
- console.log(import_chalk.default.yellow("\u26A0\uFE0F provideKopynator is already present in app.config.ts. Skipping injection."));
121
+ if (fileContent.includes("provideKopynator(")) {
122
+ console.log(import_chalk.default.yellow("\u26A0\uFE0F provideKopynator is already present. Skipping injection."));
123
+ return;
112
124
  } else {
113
125
  const providerString = `
114
126
  provideKopynator({
@@ -117,21 +129,21 @@ async function initCommand() {
117
129
  mode: 'local',
118
130
  languages: ${JSON.stringify(answers.languages)},
119
131
  }),`;
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"));
132
+ const providersRegex = isModule ? /(providers:\s*\[)/ : /(providers:\s*\[)/;
133
+ if (providersRegex.test(fileContent)) {
134
+ fileContent = fileContent.replace(providersRegex, `$1${providerString}`);
135
+ import_fs.default.writeFileSync(targetPath, fileContent);
136
+ console.log(import_chalk.default.green(`\u2705 Successfully injected configuration into ${isModule ? "app.module.ts" : "app.config.ts"}`));
125
137
  console.log(import_chalk.default.yellow("\nNext steps:"));
126
138
  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");
139
+ console.log(`2. Update the apiKey in ${isModule ? "src/app/app.module.ts" : "src/app/app.config.ts"}`);
128
140
  return;
129
141
  } else {
130
- console.log(import_chalk.default.yellow('\u26A0\uFE0F Could not find "providers: []" array in app.config.ts. Falling back to config file.'));
142
+ console.log(import_chalk.default.yellow(`\u26A0\uFE0F Could not find "providers: []" array. Falling back to config file.`));
131
143
  }
132
144
  }
133
145
  } else {
134
- console.log(import_chalk.default.yellow("\u26A0\uFE0F Could not find src/app/app.config.ts. Falling back to config file."));
146
+ console.log(import_chalk.default.yellow("\u26A0\uFE0F Could not find app.config.ts or app.module.ts. Falling back to config file."));
135
147
  }
136
148
  }
137
149
  const configContent = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kopynator/cli",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "CLI tool for Kopynator - The i18n management solution",
5
5
  "bin": {
6
6
  "kopynator": "dist/index.js"
@@ -71,22 +71,37 @@ export async function initCommand() {
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');
74
+ // Try app.config.ts first (Angular 17+ standalone)
75
+ const appConfigPath = path.join(process.cwd(), 'src/app/app.config.ts');
76
+ const appModulePath = path.join(process.cwd(), 'src/app/app.module.ts');
75
77
 
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');
78
+ let targetPath: string | null = null;
79
+ let isModule = false;
80
+
81
+ if (fs.existsSync(appConfigPath)) {
82
+ targetPath = appConfigPath;
83
+ isModule = false;
84
+ console.log(chalk.blue('ℹ️ Detected Angular standalone project (app.config.ts)'));
85
+ } else if (fs.existsSync(appModulePath)) {
86
+ targetPath = appModulePath;
87
+ isModule = true;
88
+ console.log(chalk.blue('ℹ️ Detected Angular NgModule project (app.module.ts)'));
89
+ }
90
+
91
+ if (targetPath) {
92
+ let fileContent = fs.readFileSync(targetPath, 'utf-8');
79
93
 
80
94
  // 1. Add Import if missing
81
- const hasImport = appConfigContent.includes('@kopynator/angular');
95
+ const hasImport = fileContent.includes('@kopynator/angular');
82
96
  if (!hasImport) {
83
- appConfigContent = `import { provideKopynator } from '@kopynator/angular';\n` + appConfigContent;
97
+ fileContent = `import { provideKopynator } from '@kopynator/angular';\n` + fileContent;
84
98
  }
85
99
 
86
100
  // 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.'));
101
+ // Check for the *usage* of the provider
102
+ if (fileContent.includes('provideKopynator(')) {
103
+ console.log(chalk.yellow('⚠️ provideKopynator is already present. Skipping injection.'));
104
+ return; // Exit successfully, assuming manual config is sufficient
90
105
  } else {
91
106
  const providerString = `
92
107
  provideKopynator({
@@ -96,21 +111,25 @@ export async function initCommand() {
96
111
  languages: ${JSON.stringify(answers.languages)},
97
112
  }),`;
98
113
 
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'));
114
+ // Different regex for NgModule vs standalone config
115
+ const providersRegex = isModule
116
+ ? /(providers:\s*\[)/ // NgModule: providers: [ in @NgModule decorator
117
+ : /(providers:\s*\[)/; // Standalone: providers: [ in ApplicationConfig
118
+
119
+ if (providersRegex.test(fileContent)) {
120
+ fileContent = fileContent.replace(providersRegex, `$1${providerString}`);
121
+ fs.writeFileSync(targetPath, fileContent);
122
+ console.log(chalk.green(`✅ Successfully injected configuration into ${isModule ? 'app.module.ts' : 'app.config.ts'}`));
104
123
  console.log(chalk.yellow('\nNext steps:'));
105
124
  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');
125
+ console.log(`2. Update the apiKey in ${isModule ? 'src/app/app.module.ts' : 'src/app/app.config.ts'}`);
107
126
  return; // Exit successfully without creating json
108
127
  } else {
109
- console.log(chalk.yellow('⚠️ Could not find "providers: []" array in app.config.ts. Falling back to config file.'));
128
+ console.log(chalk.yellow(`⚠️ Could not find "providers: []" array. Falling back to config file.`));
110
129
  }
111
130
  }
112
131
  } else {
113
- console.log(chalk.yellow('⚠️ Could not find src/app/app.config.ts. Falling back to config file.'));
132
+ console.log(chalk.yellow('⚠️ Could not find app.config.ts or app.module.ts. Falling back to config file.'));
114
133
  }
115
134
  }
116
135