ultimate-jekyll-manager 0.0.34 → 0.0.35

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.
@@ -221,7 +221,7 @@ function customTransform() {
221
221
  }
222
222
  function defaultsWatcher(complete) {
223
223
  // Quit if in build mode
224
- if (Manager.isBuildMode() || process.env.UJ_SKIP_DEFAULTS_WATCHER === 'true') {
224
+ if (Manager.isBuildMode()) {
225
225
  logger.log('[watcher] Skipping watcher in build mode');
226
226
  return complete();
227
227
  }
@@ -114,13 +114,17 @@ async function processTranslation() {
114
114
  if (!languages.length) {
115
115
  return logger.warn('🚫 No target languages configured.');
116
116
  }
117
- if (!process.env.OPENAI_API_KEY) {
118
- return logger.error('❌ OPENAI_API_KEY not set.');
119
- }
120
117
 
121
118
  // For testing purposes
119
+ const openAIKey = await fetchOpenAIKey();
122
120
  const ujOnly = process.env.UJ_TRANSLATION_ONLY;
123
121
 
122
+ // console.log('--openAIKey', openAIKey);
123
+
124
+ if (!openAIKey) {
125
+ return logger.error('❌ openAIKey not set. Translation requires OpenAI API key.');
126
+ }
127
+
124
128
  // Pull latest cached translations from uj-translations branch
125
129
  if (Manager.isBuildMode()) {
126
130
  await fetchTranslationsBranch();
@@ -237,7 +241,7 @@ async function processTranslation() {
237
241
  logger.log(`📦 Using cached translation for ${relativePath} [${lang}]`);
238
242
  } else {
239
243
  try {
240
- const { result, usage } = await translateWithAPI(bodyText, lang);
244
+ const { result, usage } = await translateWithAPI(openAIKey, bodyText, lang);
241
245
 
242
246
  // Set translated result
243
247
  translated = result;
@@ -339,7 +343,7 @@ async function processTranslation() {
339
343
  }
340
344
  }
341
345
 
342
- async function translateWithAPI(content, lang) {
346
+ async function translateWithAPI(openAIKey, content, lang) {
343
347
  // Prompt
344
348
  const systemPrompt = `
345
349
  You are a professional translator.
@@ -354,7 +358,7 @@ async function translateWithAPI(content, lang) {
354
358
  response: 'json',
355
359
  method: 'POST',
356
360
  headers: {
357
- 'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`,
361
+ 'Authorization': `Bearer ${openAIKey}`,
358
362
  'Content-Type': 'application/json',
359
363
  },
360
364
  timeout: 60000 * 4,
@@ -682,3 +686,25 @@ async function pushTranslationBranch(updatedFiles) {
682
686
 
683
687
  logger.log(`🎉 Finished pushing ${files.length} file(s) to '${TRANSLATION_BRANCH}'`);
684
688
  }
689
+
690
+
691
+ async function fetchOpenAIKey() {
692
+ const url = 'https://api.itwcreativeworks.com/get-api-keys';
693
+
694
+ try {
695
+ const response = await fetch(url, {
696
+ method: 'GET',
697
+ response: 'json',
698
+ headers: {
699
+ 'Authorization': `Bearer ${process.env.GH_TOKEN}`,
700
+ },
701
+ body: {
702
+ authorizationKeyName: 'github',
703
+ }
704
+ });
705
+
706
+ return response.openai.ultimate_jekyll.translation;
707
+ } catch (error) {
708
+ console.error('Error:', error);
709
+ }
710
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ultimate-jekyll-manager",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
4
4
  "description": "Ultimate Jekyll dependency manager",
5
5
  "main": "dist/index.js",
6
6
  "exports": {