@localheroai/cli 0.0.1 → 0.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@localheroai/cli",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "CLI tool for managing translations with LocalHero.ai",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -59,4 +59,4 @@
59
59
  ]
60
60
  }
61
61
  }
62
- }
62
+ }
package/src/api/client.js CHANGED
@@ -18,7 +18,6 @@ export async function apiRequest(endpoint, options = {}) {
18
18
  headers['Authorization'] = `Bearer ${apiKey}`;
19
19
  }
20
20
 
21
- console.log('API Request:', url);
22
21
  const response = await fetch(url, {
23
22
  ...options,
24
23
  headers,
@@ -3,17 +3,16 @@ import { promises as fs } from 'fs';
3
3
  import path from 'path';
4
4
 
5
5
  export function isGitHubAction() {
6
- return process.env.GITHUB_ACTIONS === 'true';
6
+ return process.env.GITHUB_ACTIONS === 'true';
7
7
  }
8
8
 
9
9
  export async function createGitHubActionFile(basePath, translationPaths) {
10
- const workflowDir = path.join(basePath, '.github', 'workflows');
11
- const workflowFile = path.join(workflowDir, 'localhero-translate.yml');
10
+ const workflowDir = path.join(basePath, '.github', 'workflows');
11
+ const workflowFile = path.join(workflowDir, 'localhero-translate.yml');
12
12
 
13
- // Create directories if they don't exist
14
- await fs.mkdir(workflowDir, { recursive: true });
13
+ await fs.mkdir(workflowDir, { recursive: true });
15
14
 
16
- const actionContent = `name: Localhero.ai - I18n translation
15
+ const actionContent = `name: Localhero.ai - I18n translation
17
16
 
18
17
  on:
19
18
  pull_request:
@@ -23,10 +22,16 @@ on:
23
22
  jobs:
24
23
  translate:
25
24
  runs-on: ubuntu-latest
25
+ permissions:
26
+ contents: write
27
+ pull-requests: write
26
28
 
27
29
  steps:
28
30
  - name: Checkout code
29
31
  uses: actions/checkout@v4
32
+ with:
33
+ ref: \${{ github.head_ref }}
34
+ fetch-depth: 0
30
35
 
31
36
  - name: Set up Node.js
32
37
  uses: actions/setup-node@v4
@@ -38,28 +43,50 @@ jobs:
38
43
  LOCALHERO_API_KEY: \${{ secrets.LOCALHERO_API_KEY }}
39
44
  run: npx @localheroai/cli translate`;
40
45
 
41
- await fs.writeFile(workflowFile, actionContent);
42
- return workflowFile;
46
+ await fs.writeFile(workflowFile, actionContent);
47
+ return workflowFile;
43
48
  }
44
49
 
45
50
  export function autoCommitChanges(filesPath) {
46
- if (!isGitHubAction()) return;
47
-
48
- console.log("Running in GitHub Actions. Committing changes...");
49
- try {
50
- execSync(`git config --global user.name "LocalHero Bot"`, { stdio: "inherit" });
51
- execSync(`git config --global user.email "bot@localhero.ai"`, { stdio: "inherit" });
52
- execSync(`git add ${filesPath}`, { stdio: "inherit" });
53
- execSync(`git commit -m "Update translations"`, { stdio: "inherit" });
54
- const branchName = process.env.GITHUB_HEAD_REF;
55
- execSync(`git push origin ${branchName}`, { stdio: "inherit" });
56
- console.log("Changes committed and pushed.");
57
- } catch (error) {
58
- if (error.message.includes("nothing to commit")) {
59
- console.log("No changes to commit.");
60
- return;
61
- }
62
- console.error("Auto-commit failed:", error.message);
63
- throw error;
51
+ if (!isGitHubAction()) return;
52
+
53
+ console.log("Running in GitHub Actions. Committing changes...");
54
+ try {
55
+ execSync('git config --global user.name "LocalHero Bot"', { stdio: "inherit" });
56
+ execSync('git config --global user.email "hi@localhero.ai"', { stdio: "inherit" });
57
+
58
+ const branchName = process.env.GITHUB_HEAD_REF;
59
+ if (!branchName) {
60
+ throw new Error('Could not determine branch name from GITHUB_HEAD_REF');
64
61
  }
62
+
63
+ execSync(`git add ${filesPath}`, { stdio: "inherit" });
64
+
65
+ const status = execSync('git status --porcelain').toString();
66
+ if (!status) {
67
+ console.log("No changes to commit.");
68
+ return;
69
+ }
70
+
71
+ execSync('git commit -m "Update translations"', { stdio: "inherit" });
72
+
73
+ const token = process.env.GITHUB_TOKEN;
74
+ if (!token) {
75
+ throw new Error('GITHUB_TOKEN is not set');
76
+ }
77
+
78
+ const repository = process.env.GITHUB_REPOSITORY;
79
+ if (!repository) {
80
+ throw new Error('GITHUB_REPOSITORY is not set');
81
+ }
82
+
83
+ const remoteUrl = `https://x-access-token:${token}@github.com/${repository}.git`;
84
+
85
+ execSync(`git remote set-url origin ${remoteUrl}`, { stdio: "inherit" });
86
+ execSync(`git push origin HEAD:${branchName}`, { stdio: "inherit" });
87
+ console.log("Changes committed and pushed successfully.");
88
+ } catch (error) {
89
+ console.error("Auto-commit failed:", error.message);
90
+ throw error;
91
+ }
65
92
  }