@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 +2 -2
- package/src/api/client.js +0 -1
- package/src/utils/github.js +53 -26
package/package.json
CHANGED
package/src/api/client.js
CHANGED
package/src/utils/github.js
CHANGED
|
@@ -3,17 +3,16 @@ import { promises as fs } from 'fs';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
|
|
5
5
|
export function isGitHubAction() {
|
|
6
|
-
|
|
6
|
+
return process.env.GITHUB_ACTIONS === 'true';
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export async function createGitHubActionFile(basePath, translationPaths) {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const workflowDir = path.join(basePath, '.github', 'workflows');
|
|
11
|
+
const workflowFile = path.join(workflowDir, 'localhero-translate.yml');
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
await fs.mkdir(workflowDir, { recursive: true });
|
|
13
|
+
await fs.mkdir(workflowDir, { recursive: true });
|
|
15
14
|
|
|
16
|
-
|
|
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
|
-
|
|
42
|
-
|
|
46
|
+
await fs.writeFile(workflowFile, actionContent);
|
|
47
|
+
return workflowFile;
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
export function autoCommitChanges(filesPath) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
}
|