ultimate-jekyll-manager 0.0.34 → 0.0.36

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.
@@ -1,3 +1,4 @@
1
+ // @TODO: DELETE THIS FILE when the project is ready
1
2
  // Module
2
3
  export default (Manager) => {
3
4
  return new Promise(async function (resolve, reject) {
@@ -1,3 +1,5 @@
1
+ // @TODO: DELETE THIS FILE when the project is ready
2
+
1
3
  // Module
2
4
  export default (Manager) => {
3
5
  // Shortcuts
@@ -1,3 +1,5 @@
1
+ // @TODO: DELETE THIS FILE when the project is ready
2
+
1
3
  // Libraries
2
4
  import helper from './helper.js';
3
5
 
@@ -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,15 @@ 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
+ if (!openAIKey) {
123
+ return logger.error('❌ openAIKey not set. Translation requires OpenAI API key.');
124
+ }
125
+
124
126
  // Pull latest cached translations from uj-translations branch
125
127
  if (Manager.isBuildMode()) {
126
128
  await fetchTranslationsBranch();
@@ -237,7 +239,7 @@ async function processTranslation() {
237
239
  logger.log(`📦 Using cached translation for ${relativePath} [${lang}]`);
238
240
  } else {
239
241
  try {
240
- const { result, usage } = await translateWithAPI(bodyText, lang);
242
+ const { result, usage } = await translateWithAPI(openAIKey, bodyText, lang);
241
243
 
242
244
  // Set translated result
243
245
  translated = result;
@@ -339,7 +341,7 @@ async function processTranslation() {
339
341
  }
340
342
  }
341
343
 
342
- async function translateWithAPI(content, lang) {
344
+ async function translateWithAPI(openAIKey, content, lang) {
343
345
  // Prompt
344
346
  const systemPrompt = `
345
347
  You are a professional translator.
@@ -354,7 +356,7 @@ async function translateWithAPI(content, lang) {
354
356
  response: 'json',
355
357
  method: 'POST',
356
358
  headers: {
357
- 'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`,
359
+ 'Authorization': `Bearer ${openAIKey}`,
358
360
  'Content-Type': 'application/json',
359
361
  },
360
362
  timeout: 60000 * 4,
@@ -682,3 +684,28 @@ async function pushTranslationBranch(updatedFiles) {
682
684
 
683
685
  logger.log(`🎉 Finished pushing ${files.length} file(s) to '${TRANSLATION_BRANCH}'`);
684
686
  }
687
+
688
+ async function fetchOpenAIKey() {
689
+ const url = 'https://api.itwcreativeworks.com/get-api-keys';
690
+
691
+ try {
692
+ const response = await fetch(url, {
693
+ method: 'GET',
694
+ response: 'json',
695
+ headers: {
696
+ 'Authorization': `Bearer ${process.env.GH_TOKEN}`,
697
+ },
698
+ query: {
699
+ authorizationKeyName: 'github',
700
+ }
701
+ });
702
+
703
+ // Log
704
+ logger.log('OpenAI API response:', response);
705
+
706
+ // Return
707
+ return response.openai.ultimate_jekyll.translation;
708
+ } catch (error) {
709
+ logger.error('Error:', error);
710
+ }
711
+ }
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.36",
4
4
  "description": "Ultimate Jekyll dependency manager",
5
5
  "main": "dist/index.js",
6
6
  "exports": {