i18ntk 2.0.3 → 2.1.0

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.
@@ -151,13 +151,40 @@ class I18nManager {
151
151
  }
152
152
  }
153
153
 
154
- // Check if i18n framework is installed - configuration-based check without prompts
155
- async checkI18nDependencies() {
156
- const packageJsonPath = path.resolve('./package.json');
157
-
158
- if (!SecurityUtils.safeExistsSync(packageJsonPath)) {
159
- console.log(this.ui ? this.ui.t('errors.noPackageJson') : 'No package.json found');
160
- return false; // Treat as no framework detected
154
+ // Check if i18n framework is installed - configuration-based check without prompts
155
+ async checkI18nDependencies() {
156
+ const markInternalFrameworkDetected = () => {
157
+ const cfg = configManager.loadSettings ? configManager.loadSettings() : (configManager.getConfig ? configManager.getConfig() : {});
158
+ cfg.framework = cfg.framework || {};
159
+ cfg.framework.detected = true;
160
+ cfg.framework.preference = cfg.framework.preference || 'i18ntk';
161
+ const existing = Array.isArray(cfg.framework.installed) ? cfg.framework.installed : [];
162
+ if (!existing.includes('i18ntk')) {
163
+ cfg.framework.installed = [...existing, 'i18ntk'];
164
+ }
165
+ if (configManager.saveSettings) {
166
+ configManager.saveSettings(cfg);
167
+ } else if (configManager.saveConfig) {
168
+ configManager.saveConfig(cfg);
169
+ }
170
+ };
171
+
172
+ try {
173
+ const { checkInitialized } = require('../../utils/init-helper');
174
+ const initStatus = await checkInitialized();
175
+ if (initStatus?.initialized || initStatus?.config?.setup?.completed) {
176
+ markInternalFrameworkDetected();
177
+ return true;
178
+ }
179
+ } catch (_) {
180
+ // Continue with package.json detection.
181
+ }
182
+
183
+ const packageJsonPath = path.resolve('./package.json');
184
+
185
+ if (!SecurityUtils.safeExistsSync(packageJsonPath)) {
186
+ console.log(this.ui ? this.ui.t('errors.noPackageJson') : 'No package.json found');
187
+ return false; // Treat as no framework detected
161
188
  }
162
189
 
163
190
  try {
@@ -174,11 +201,12 @@ class I18nManager {
174
201
  'vue-i18n',
175
202
  'angular-i18n',
176
203
  'i18next',
177
- 'next-i18next',
178
- 'svelte-i18n',
179
- '@nuxtjs/i18n',
180
- 'i18ntk-runtime'
181
- ];
204
+ 'next-i18next',
205
+ 'svelte-i18n',
206
+ '@nuxtjs/i18n',
207
+ 'i18ntk-runtime',
208
+ 'i18ntk'
209
+ ];
182
210
 
183
211
  const installedFrameworks = i18nFrameworks.filter(framework => dependencies[framework]);
184
212
 
@@ -484,21 +512,39 @@ class I18nManager {
484
512
  const settings = configManager.loadSettings ? configManager.loadSettings() : (configManager.getConfig ? configManager.getConfig() : {});
485
513
 
486
514
  // Ensure framework configuration exists with all required fields
487
- if (!settings.framework) {
488
- settings.framework = {
489
- detected: false,
490
- preference: null,
491
- prompt: 'always',
515
+ if (!settings.framework) {
516
+ settings.framework = {
517
+ detected: false,
518
+ preference: null,
519
+ prompt: 'always',
492
520
  lastPromptedVersion: null,
493
521
  installed: [],
494
- version: '1.0' // Schema version for future compatibility
495
- };
496
- }
497
-
498
- // Check if we need to prompt for framework detection
499
- if (!settings.framework.detected &&
500
- settings.framework.prompt !== 'suppress' &&
501
- settings.framework.lastPromptedVersion !== pkg.version) {
522
+ version: '1.0' // Schema version for future compatibility
523
+ };
524
+ }
525
+
526
+ const setupCompleted = Boolean(config?.setup?.completed || settings?.setup?.completed);
527
+ if (setupCompleted) {
528
+ settings.framework.detected = true;
529
+ settings.framework.preference = settings.framework.preference || 'i18ntk';
530
+ settings.framework.installed = Array.isArray(settings.framework.installed)
531
+ ? Array.from(new Set([...settings.framework.installed, 'i18ntk']))
532
+ : ['i18ntk'];
533
+ settings.framework.lastDetected = new Date().toISOString();
534
+
535
+ if (configManager.saveSettings) {
536
+ await configManager.saveSettings(settings);
537
+ } else if (configManager.saveConfig) {
538
+ await configManager.saveConfig(settings);
539
+ }
540
+
541
+ return { ...config, ...settings };
542
+ }
543
+
544
+ // Check if we need to prompt for framework detection
545
+ if (!settings.framework.detected &&
546
+ settings.framework.prompt !== 'suppress' &&
547
+ settings.framework.lastPromptedVersion !== pkg.version) {
502
548
 
503
549
  console.log('\nWe noticed you haven\'t set up an i18n framework yet.');
504
550
  console.log('Would you like to detect your i18n framework automatically?');
@@ -557,11 +603,11 @@ class I18nManager {
557
603
  return { ...config, ...settings };
558
604
  }
559
605
 
560
- async detectEnvironmentAndFramework() {
561
- // Defensive check to ensure SecurityUtils is available
562
- if (!SecurityUtils) {
563
- throw new Error('SecurityUtils is not available. This may indicate a module loading issue.');
564
- }
606
+ async detectEnvironmentAndFramework() {
607
+ // Defensive check to ensure SecurityUtils is available
608
+ if (!SecurityUtils) {
609
+ throw new Error('SecurityUtils is not available. This may indicate a module loading issue.');
610
+ }
565
611
  const fs = require('fs');
566
612
  const path = require('path');
567
613
 
@@ -572,13 +618,23 @@ class I18nManager {
572
618
  const pomPath = path.join(process.cwd(), 'pom.xml');
573
619
  const composerPath = path.join(process.cwd(), 'composer.json');
574
620
 
575
- let detectedLanguage = 'generic';
576
- let detectedFramework = 'generic';
577
-
578
- if (SecurityUtils.safeExistsSync(packageJsonPath)) {
579
- detectedLanguage = 'javascript';
580
- try {
581
- const packageJson = JSON.parse(SecurityUtils.safeReadFileSync(packageJsonPath, path.dirname(packageJsonPath), 'utf8'));
621
+ let detectedLanguage = 'generic';
622
+ let detectedFramework = 'generic';
623
+
624
+ try {
625
+ const { checkInitialized } = require('../../utils/init-helper');
626
+ const initStatus = await checkInitialized();
627
+ if (initStatus?.initialized || initStatus?.config?.setup?.completed) {
628
+ return { detectedLanguage: 'javascript', detectedFramework: 'i18ntk' };
629
+ }
630
+ } catch (_) {
631
+ // Continue with filesystem/package detection.
632
+ }
633
+
634
+ if (SecurityUtils.safeExistsSync(packageJsonPath)) {
635
+ detectedLanguage = 'javascript';
636
+ try {
637
+ const packageJson = JSON.parse(SecurityUtils.safeReadFileSync(packageJsonPath, path.dirname(packageJsonPath), 'utf8'));
582
638
  const deps = {
583
639
  ...(packageJson.dependencies || {}),
584
640
  ...(packageJson.devDependencies || {}),
@@ -586,13 +642,18 @@ class I18nManager {
586
642
  };
587
643
 
588
644
  // Check for i18ntk-runtime first (check both package names)
589
- const hasI18nTkRuntime = deps['i18ntk-runtime'] || deps['i18ntk/runtime'];
590
-
591
- // Check for common i18n patterns in source code if not found in package.json
592
- if (!hasI18nTkRuntime) {
593
- const i18nPatterns = [
594
- /i18n\.t\(['\"`]/,
595
- /useI18n\(/,
645
+ const hasI18nTkRuntime = deps['i18ntk-runtime'] || deps['i18ntk/runtime'];
646
+ const hasI18nTkToolkit = Boolean(deps['i18ntk']);
647
+
648
+ if (hasI18nTkToolkit) {
649
+ detectedFramework = 'i18ntk';
650
+ }
651
+
652
+ // Check for common i18n patterns in source code if not found in package.json
653
+ if (!hasI18nTkRuntime && detectedFramework !== 'i18ntk') {
654
+ const i18nPatterns = [
655
+ /i18n\.t\(['\"`]/,
656
+ /useI18n\(/,
596
657
  /from ['\"]i18ntk[\/\\]runtime['\"]/,
597
658
  /require\(['\"]i18ntk[\/\\]runtime['\"]\)/
598
659
  ];
@@ -614,9 +675,9 @@ class I18nManager {
614
675
  continue;
615
676
  }
616
677
  }
617
- } else {
618
- detectedFramework = 'i18ntk-runtime';
619
- }
678
+ } else if (hasI18nTkRuntime) {
679
+ detectedFramework = 'i18ntk-runtime';
680
+ }
620
681
 
621
682
  // Only check other frameworks if i18ntk-runtime wasn't detected
622
683
  if (detectedFramework !== 'i18ntk-runtime') {
@@ -850,27 +911,34 @@ class I18nManager {
850
911
  const choice = await this.prompt('\n' + t('menu.selectOptionPrompt'));
851
912
 
852
913
  switch (choice.trim()) {
853
- case '1':
854
- await this.executeCommand('init', {fromMenu: true});
855
- break;
856
- case '2':
857
- await this.executeCommand('analyze', {fromMenu: true});
858
- break;
859
- case '3':
860
- await this.executeCommand('validate', {fromMenu: true});
861
- break;
862
- case '4':
863
- await this.executeCommand('usage', {fromMenu: true});
864
- break;
865
- case '5':
866
- await this.executeCommand('complete', {fromMenu: true});
867
- break;
868
- case '6':
869
- await this.executeCommand('sizing', {fromMenu: true});
870
- break;
871
- case '7':
872
- await this.executeCommand('fix', {fromMenu: true});
873
- break;
914
+ case '1':
915
+ await this.executeCommand('init', {fromMenu: true});
916
+ await this.showInteractiveMenu();
917
+ return;
918
+ case '2':
919
+ await this.executeCommand('analyze', {fromMenu: true});
920
+ await this.showInteractiveMenu();
921
+ return;
922
+ case '3':
923
+ await this.executeCommand('validate', {fromMenu: true});
924
+ await this.showInteractiveMenu();
925
+ return;
926
+ case '4':
927
+ await this.executeCommand('usage', {fromMenu: true});
928
+ await this.showInteractiveMenu();
929
+ return;
930
+ case '5':
931
+ await this.executeCommand('complete', {fromMenu: true});
932
+ await this.showInteractiveMenu();
933
+ return;
934
+ case '6':
935
+ await this.executeCommand('sizing', {fromMenu: true});
936
+ await this.showInteractiveMenu();
937
+ return;
938
+ case '7':
939
+ await this.executeCommand('fix', {fromMenu: true});
940
+ await this.showInteractiveMenu();
941
+ return;
874
942
  case '8':
875
943
  // Check for PIN protection
876
944
  const authRequired = await this.adminAuth.isAuthRequiredForScript('summaryReports');
@@ -943,9 +1011,10 @@ class I18nManager {
943
1011
  case '12':
944
1012
  await this.showLanguageMenu();
945
1013
  break;
946
- case '13':
947
- await this.executeCommand('scanner', {fromMenu: true});
948
- break;
1014
+ case '13':
1015
+ await this.executeCommand('scanner', {fromMenu: true});
1016
+ await this.showInteractiveMenu();
1017
+ return;
949
1018
  case '0':
950
1019
  console.log(t('menu.goodbye'));
951
1020
  this.safeClose();