@arc-js/initiator 0.0.1 → 0.0.3

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/index.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ declare function TranslationInitiator(dirname?: string | undefined): Promise<void>;
2
+
3
+ declare function ConfigInitiator(dirname?: string | undefined): Promise<void>;
4
+
1
5
  declare function export_default(dirname?: string | undefined): void;
2
6
 
3
- export { export_default as default };
7
+ export { ConfigInitiator, TranslationInitiator, export_default as default };
package/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
3
5
  var fs = require('fs');
4
6
  var path = require('path');
5
7
  var url = require('url');
@@ -194418,19 +194420,19 @@ function requirePajo () {
194418
194420
 
194419
194421
  var pajoExports = requirePajo();
194420
194422
 
194421
- const __filename$1 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
194422
- const __dirname$1 = path.dirname(__filename$1);
194423
+ const __filename$2 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
194424
+ const __dirname$2 = path.dirname(__filename$2);
194423
194425
  class TranslationGenerator {
194424
- constructor(config = {}, dirname = __dirname$1) {
194426
+ constructor(config = {}, dirname = __dirname$2) {
194425
194427
  this.keys = [];
194426
194428
  this.modules = new Set();
194427
194429
  this.importedModules = new Set();
194428
194430
  this.config = {
194429
- srcDir: config.srcDir || pajoExports.Pajo.join(dirname, '..\\src') || '',
194431
+ srcDir: config.srcDir || pajoExports.Pajo.join(dirname, 'src') || '',
194430
194432
  supportedLocales: config.supportedLocales || ['en', 'fr'],
194431
- outputFile: config.outputFile || pajoExports.Pajo.join(dirname, '..\\src\\auto-intl.ts') || '',
194432
- modulesDir: config.modulesDir || pajoExports.Pajo.join(dirname, '..\\src\\modules') || '',
194433
- localesDir: config.localesDir || pajoExports.Pajo.join(dirname, '..\\src\\locales') || ''
194433
+ outputFile: config.outputFile || pajoExports.Pajo.join(dirname, 'src\\auto-intl.ts') || '',
194434
+ modulesDir: config.modulesDir || pajoExports.Pajo.join(dirname, 'src\\modules') || '',
194435
+ localesDir: config.localesDir || pajoExports.Pajo.join(dirname, 'src\\locales') || ''
194434
194436
  };
194435
194437
  console.log(`--> this.config:: `, this.config);
194436
194438
  }
@@ -194633,82 +194635,16 @@ class TranslationGenerator {
194633
194635
  }).join(',\n');
194634
194636
  return ` '${moduleName}': {\n${moduleLocales}\n }`;
194635
194637
  }).join(',\n');
194636
- return `// AUTO-GENERATED FILE - DO NOT EDIT MANUALLY
194637
- // This file is automatically generated by the translation generator
194638
- // Last generated: ${new Date().toISOString()}
194639
-
194640
- export interface TranslationMap {
194641
- [locale: string]: () => Promise<Record<string, any>>;
194642
- }
194643
-
194644
- export interface ModuleTranslations {
194645
- [moduleName: string]: TranslationMap;
194646
- }
194647
-
194648
- /**
194649
- * Auto-generated translations map
194650
- * Includes all detected translations from the source code
194651
- */
194652
- export const translations = {
194653
- ${baseImports},
194654
- modules: {
194638
+ return `export const translations = {
194639
+ 'base': {
194640
+ ${baseImports}
194641
+ },
194642
+ 'modules': {
194655
194643
  ${modulesImports.length > 0 ? modulesImports : ' // No modules with translations found'}
194656
194644
  }
194657
194645
  };
194658
194646
 
194659
- /**
194660
- * Helper to check if a key exists in translations
194661
- */
194662
- export const hasTranslation = (key: string, moduleName?: string): boolean => {
194663
- if (import.meta.env.PROD) {
194664
- // In production, rely on runtime checking
194665
- return true;
194666
- }
194667
-
194668
- // In development, log warning for missing keys
194669
- const fullKey = moduleName ? \`\${moduleName}:\${key}\` : key;
194670
- console.warn(\`[i18n] Translation key validation is only available in development mode. Key: \${fullKey}\`);
194671
- return true;
194672
- };
194673
-
194674
- /**
194675
- * Get all detected translation keys (for debugging)
194676
- */
194677
- export const getTranslationKeys = (): Array<{ key: string; module?: string; defaultValue?: string }> => {
194678
- return [
194679
- ${this.keys.length > 0 ? this.keys.map(key => JSON.stringify({
194680
- key: key.key,
194681
- module: key.module,
194682
- defaultValue: key.defaultValue
194683
- })).join(',\n ') : '// No translation keys found'}
194684
- ];
194685
- };
194686
-
194687
- /**
194688
- * Preload all translations (useful for production)
194689
- */
194690
- export const preloadAllTranslations = async (): Promise<void> => {
194691
- const promises: Promise<any>[] = [];
194692
-
194693
- // Preload base translations
194694
- Object.values(translations)
194695
- .filter(loader => typeof loader === 'function')
194696
- .forEach(loader => {
194697
- promises.push(loader());
194698
- });
194699
-
194700
- // Preload module translations
194701
- Object.values(translations.modules).forEach(moduleTranslations => {
194702
- Object.values(moduleTranslations).forEach(loader => {
194703
- promises.push(loader());
194704
- });
194705
- });
194706
-
194707
- await Promise.all(promises);
194708
- };
194709
-
194710
- export default translations;
194711
- `;
194647
+ export default translations;`;
194712
194648
  }
194713
194649
  generateTypeDefinitions() {
194714
194650
  if (this.keys.length === 0) {
@@ -194733,7 +194669,7 @@ export default translations;
194733
194669
  }
194734
194670
  }
194735
194671
  function TranslationInitiator() {
194736
- return __awaiter(this, arguments, void 0, function* (dirname = __dirname$1) {
194672
+ return __awaiter(this, arguments, void 0, function* (dirname = __dirname$2) {
194737
194673
  const config = {};
194738
194674
  const generator = new TranslationGenerator(config, dirname);
194739
194675
  generator.generate().then(() => {
@@ -194744,8 +194680,108 @@ function TranslationInitiator() {
194744
194680
  });
194745
194681
  }
194746
194682
 
194683
+ const __filename$1 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
194684
+ const __dirname$1 = path.dirname(__filename$1);
194685
+ class ConfigGenerator {
194686
+ constructor(config = {}, dirname = __dirname$1) {
194687
+ this.modules = new Set();
194688
+ this.config = {
194689
+ srcDir: config.srcDir || pajoExports.Pajo.join(dirname, 'src') || '',
194690
+ outputFile: config.outputFile || pajoExports.Pajo.join(dirname, 'src\\auto-config.ts') || '',
194691
+ modulesDir: config.modulesDir || pajoExports.Pajo.join(dirname, 'src\\modules') || '',
194692
+ rootConfigPath: config.rootConfigPath || pajoExports.Pajo.join(dirname, 'config.json') || ''
194693
+ };
194694
+ console.log(`--> ConfigGenerator config:: `, this.config);
194695
+ }
194696
+ generate() {
194697
+ return __awaiter(this, void 0, void 0, function* () {
194698
+ console.log('🔍 Scanning for configuration files...');
194699
+ yield this.discoverModules();
194700
+ yield this.generateAutoConfigFile();
194701
+ console.log(`✅ Generated ${this.config.outputFile}`);
194702
+ console.log(`📦 Found modules with config: ${Array.from(this.modules).join(', ')}`);
194703
+ });
194704
+ }
194705
+ discoverModules() {
194706
+ return __awaiter(this, void 0, void 0, function* () {
194707
+ try {
194708
+ if (!fs.existsSync(this.config.modulesDir)) {
194709
+ console.log(`⚠️ Modules directory not found: ${this.config.modulesDir}`);
194710
+ return;
194711
+ }
194712
+ const moduleDirs = fs.readdirSync(this.config.modulesDir, { withFileTypes: true })
194713
+ .filter(dirent => dirent.isDirectory())
194714
+ .map(dirent => dirent.name);
194715
+ for (const moduleName of moduleDirs) {
194716
+ const configPath = path.join(this.config.modulesDir, moduleName, 'config.json');
194717
+ if (fs.existsSync(configPath)) {
194718
+ this.modules.add(moduleName);
194719
+ console.log(`📁 Found config for module: ${moduleName}`);
194720
+ }
194721
+ }
194722
+ }
194723
+ catch (error) {
194724
+ console.error('Error discovering modules:', error);
194725
+ }
194726
+ });
194727
+ }
194728
+ generateAutoConfigFile() {
194729
+ return __awaiter(this, void 0, void 0, function* () {
194730
+ const outputDir = path.dirname(this.config.outputFile);
194731
+ if (!fs.existsSync(outputDir)) {
194732
+ fs.mkdirSync(outputDir, { recursive: true });
194733
+ }
194734
+ const content = this.generateFileContent();
194735
+ fs.writeFileSync(this.config.outputFile, content, 'utf-8');
194736
+ });
194737
+ }
194738
+ generateFileContent() {
194739
+ const { rootConfigPath, modulesDir } = this.config;
194740
+ const sortedModules = Array.from(this.modules).sort();
194741
+ const rootConfigExists = fs.existsSync(rootConfigPath);
194742
+ const baseConfig = rootConfigExists
194743
+ ? ` 'app': (() => import('../config.json').then(module => module.default || module))`
194744
+ : ` 'app': (() => Promise.resolve({}))`;
194745
+ const modulesImports = sortedModules.map(moduleName => {
194746
+ const configPath = path.join(modulesDir, moduleName, 'config.json');
194747
+ const configExists = fs.existsSync(configPath);
194748
+ if (configExists) {
194749
+ const relativePath = path.relative(path.dirname(this.config.outputFile), configPath).replace(/\\/g, '/');
194750
+ return ` '${moduleName}': (() => import('${relativePath}').then(module => module.default || module))`;
194751
+ }
194752
+ else {
194753
+ return ` '${moduleName}': (() => Promise.resolve({}))`;
194754
+ }
194755
+ }).join(',\n');
194756
+ return `export const configs = {
194757
+ 'base': {
194758
+ ${baseConfig}
194759
+ },
194760
+ 'modules': {
194761
+ ${modulesImports.length > 0 ? modulesImports : ' // No modules with config.json found'}
194762
+ }
194763
+ };
194764
+
194765
+ export default configs;`;
194766
+ }
194767
+ }
194768
+ function ConfigInitiator() {
194769
+ return __awaiter(this, arguments, void 0, function* (dirname = __dirname$1) {
194770
+ const config = {};
194771
+ const generator = new ConfigGenerator(config, dirname);
194772
+ generator.generate().then(() => {
194773
+ console.log('🎉 Config generation completed successfully!');
194774
+ }).catch((err) => {
194775
+ console.error('❌ Failed to generate config: ', err);
194776
+ });
194777
+ });
194778
+ }
194779
+
194747
194780
  function index (dirname = __dirname) {
194748
194781
  TranslationInitiator(dirname);
194782
+ ConfigInitiator(dirname);
194749
194783
  }
194750
194784
 
194751
- module.exports = index;
194785
+ exports.ConfigInitiator = ConfigInitiator;
194786
+ exports.TranslationInitiator = TranslationInitiator;
194787
+ exports.default = index;
package/index.min.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ declare function TranslationInitiator(dirname?: string | undefined): Promise<void>;
2
+
3
+ declare function ConfigInitiator(dirname?: string | undefined): Promise<void>;
4
+
1
5
  declare function export_default(dirname?: string | undefined): void;
2
6
 
3
- export { export_default as default };
7
+ export { ConfigInitiator, TranslationInitiator, export_default as default };