Skip to content

Commit 240e640

Browse files
committed
Merge branch 'releases/v1'
2 parents 577754d + 5eb3944 commit 240e640

File tree

6 files changed

+89
-75
lines changed

6 files changed

+89
-75
lines changed

.github/workflows/release.yml

+7
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ jobs:
6969
tag: ${{ steps.changelog.outputs.tag }}
7070
token: ${{ secrets.PAT }}
7171

72+
- name: Update download links
73+
if: steps.release.outputs.id != ''
74+
run: |
75+
node docs/download_links.mjs
76+
git add README.md
77+
git diff --cached --quiet || (git commit -m "docs: update download links" && git push origin ${{ github.ref }})
78+
7279
- name: Merge release branch
7380
if: steps.release.outputs.id != ''
7481
run: |

.github/workflows/versioning.yml

-14
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,3 @@ jobs:
1111
- uses: Actions-R-Us/actions-tagger@latest
1212
with:
1313
publish_latest_tag: true
14-
15-
- uses: actions/checkout@v4
16-
- uses: actions/setup-node@v4
17-
with:
18-
node-version: 18
19-
- run: |
20-
npm install -g pnpm
21-
pnpm install
22-
- name: Update download links
23-
run: |
24-
node docs/download_links.mjs
25-
git add README.md
26-
git diff --cached --quiet || (git commit -m "docs: update download links" && git push origin ${{ github.ref }})
27-
git push origin ${{ github.ref }}

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Open `powershell` and run the following command. This will start setting up your
3535

3636
<!-- WINDOWS_LINK_X64_START -->
3737
```shell
38-
powershell.exe -Command "Invoke-WebRequest -Uri https://github.com/DinosauriaLab/npm-env-setup/releases/download/v1.0.1/env-setup-win-x64.exe -OutFile env-setup-win-x64.exe; Start-Process env-setup-win-x64.exe -Wait; Remove-Item env-setup-win-x64.exe -Force"
38+
powershell.exe -Command "Invoke-WebRequest -Uri https://github.com/leoli0605/npm-env-setup/releases/download/v1.0.2/env-setup-win-x64.exe -OutFile env-setup-win-x64.exe; Start-Process env-setup-win-x64.exe -Wait; Remove-Item env-setup-win-x64.exe -Force"
3939
```
4040
<!-- WINDOWS_LINK_X64_END -->
4141

@@ -47,15 +47,15 @@ For Mac users, the process is just as simple. Depending on the type of chip your
4747

4848
<!-- MACOS_LINK_X64_START -->
4949
```shell
50-
curl -L https://github.com/DinosauriaLab/npm-env-setup/releases/download/v1.0.1/env-setup-macos-x64 -o env-setup-macos-x64 && chmod +x env-setup-macos-x64 && ./env-setup-macos-x64 && rm -f env-setup-macos-x64
50+
curl -L https://github.com/leoli0605/npm-env-setup/releases/download/v1.0.2/env-setup-macos-x64 -o env-setup-macos-x64 && chmod +x env-setup-macos-x64 && ./env-setup-macos-x64 && rm -f env-setup-macos-x64
5151
```
5252
<!-- MACOS_LINK_X64_END -->
5353

5454
- If you have a newer Mac model with Apple's own chip (like the M1 or M2, found in Macs from late 2020 onwards):
5555

5656
<!-- MACOS_LINK_ARM64_START -->
5757
```shell
58-
curl -L https://github.com/DinosauriaLab/npm-env-setup/releases/download/v1.0.1/env-setup-macos-arm64 -o env-setup-macos-arm64 && chmod +x env-setup-macos-arm64 && ./env-setup-macos-arm64 && rm -f env-setup-macos-arm64
58+
curl -L https://github.com/leoli0605/npm-env-setup/releases/download/v1.0.2/env-setup-macos-arm64 -o env-setup-macos-arm64 && chmod +x env-setup-macos-arm64 && ./env-setup-macos-arm64 && rm -f env-setup-macos-arm64
5959
```
6060
<!-- MACOS_LINK_ARM64_END -->
6161

@@ -65,7 +65,7 @@ For Linux users running Ubuntu 18.04 LTS or newer versions, execute the followin
6565

6666
<!-- LINUX_LINK_X64_START -->
6767
```shell
68-
curl -L https://github.com/DinosauriaLab/npm-env-setup/releases/download/v1.0.1/env-setup-linux-x64 -o env-setup-linux-x64 && chmod +x env-setup-linux-x64 && ./env-setup-linux-x64 && rm -f env-setup-linux-x64
68+
curl -L https://github.com/leoli0605/npm-env-setup/releases/download/v1.0.2/env-setup-linux-x64 -o env-setup-linux-x64 && chmod +x env-setup-linux-x64 && ./env-setup-linux-x64 && rm -f env-setup-linux-x64
6969
```
7070
<!-- LINUX_LINK_X64_END -->
7171

docs/download_links.mjs

+34-56
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1+
import fetch from 'node-fetch';
12
import fs from 'fs';
2-
import https from 'node:https';
33

4-
// 生成 Markdown 內容並更新 README.md 檔案
54
function generateMarkdown({ beforeMarker, afterMarker, content }) {
65
let readme = fs.readFileSync('README.md', 'utf8');
76
let before = readme.substring(0, readme.indexOf(beforeMarker) + beforeMarker.length);
87
let after = readme.substring(readme.indexOf(afterMarker));
9-
108
fs.writeFileSync('README.md', `${before}\n${content}\n${after}`);
119
}
1210

13-
// 根據資產名稱和下載 URL 生成對應的 shell 命令
1411
function generateShellCommand(asset) {
1512
if (asset.name.includes('win-x64')) {
1613
return `powershell.exe -Command "Invoke-WebRequest -Uri ${asset.browser_download_url} -OutFile ${asset.name}; Start-Process ${asset.name} -Wait; Remove-Item ${asset.name} -Force"`;
@@ -19,7 +16,6 @@ function generateShellCommand(asset) {
1916
}
2017
}
2118

22-
// 根據資產名稱選擇對應的標記
2319
function selectMarkers(asset) {
2420
if (asset.name.includes('env-setup-win-x64')) {
2521
return { beforeMarker: '<!-- WINDOWS_LINK_X64_START -->', afterMarker: '<!-- WINDOWS_LINK_X64_END -->' };
@@ -32,60 +28,42 @@ function selectMarkers(asset) {
3228
}
3329
}
3430

35-
const MAX_RETRIES = 10; // 最大重試次數
36-
const RETRY_DELAY = 5000; // 重試間隔時間,單位毫秒
37-
38-
function fetchReleaseData(retryCount = 0) {
39-
const url = `https://api.github.com/repos/DinosauriaLab/npm-env-setup/releases/latest`;
40-
const options = {
41-
headers: {
42-
'User-Agent': 'node.js',
43-
},
44-
};
31+
const MAX_RETRIES = 10;
32+
const RETRY_DELAY = 5000;
4533

46-
https
47-
.get(url, options, (res) => {
48-
let data = '';
49-
res.on('data', (chunk) => {
50-
data += chunk;
51-
});
52-
res.on('end', () => {
53-
try {
54-
const release = JSON.parse(data);
55-
console.log(`Latest release: ${release.name}`);
56-
release.assets.forEach((asset) => {
57-
console.log(`Download URL: ${asset.browser_download_url}`);
58-
console.log(`Asset name: ${asset.name}`);
59-
const shellCommand = generateShellCommand(asset);
60-
const { beforeMarker, afterMarker } = selectMarkers(asset);
61-
if (beforeMarker && afterMarker) {
62-
generateMarkdown({
63-
beforeMarker,
64-
afterMarker,
65-
content: '```shell\n' + shellCommand + '\n```',
66-
});
67-
}
68-
});
69-
} catch (error) {
70-
console.error('Error parsing response: ', error.message);
71-
retryOrFail(retryCount);
72-
}
73-
});
74-
})
75-
.on('error', (err) => {
76-
console.error('HTTPS request failed: ', err.message);
77-
retryOrFail(retryCount);
34+
async function fetchReleaseData(retryCount = 0) {
35+
const url = `https://api.github.com/repos/leoli0605/npm-env-setup/releases/latest`;
36+
try {
37+
const response = await fetch(url, {
38+
headers: {
39+
'User-Agent': 'node.js',
40+
},
7841
});
79-
}
80-
81-
function retryOrFail(retryCount) {
82-
if (retryCount < MAX_RETRIES) {
83-
console.log(`Retry ${retryCount + 1}/${MAX_RETRIES} after ${RETRY_DELAY}ms...`);
84-
setTimeout(() => fetchReleaseData(retryCount + 1), RETRY_DELAY);
85-
} else {
86-
console.log('Max retries reached. Giving up.');
42+
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
43+
const release = await response.json();
44+
console.log(`Latest release: ${release.name}`);
45+
release.assets.forEach((asset) => {
46+
console.log(`Download URL: ${asset.browser_download_url}`);
47+
console.log(`Asset name: ${asset.name}`);
48+
const shellCommand = generateShellCommand(asset);
49+
const { beforeMarker, afterMarker } = selectMarkers(asset);
50+
if (beforeMarker && afterMarker) {
51+
generateMarkdown({
52+
beforeMarker,
53+
afterMarker,
54+
content: '```shell\n' + shellCommand + '\n```',
55+
});
56+
}
57+
});
58+
} catch (error) {
59+
console.error('Error fetching release data: ', error.message);
60+
if (retryCount < MAX_RETRIES) {
61+
console.log(`Retry ${retryCount + 1}/${MAX_RETRIES} after ${RETRY_DELAY}ms...`);
62+
setTimeout(() => fetchReleaseData(retryCount + 1), RETRY_DELAY);
63+
} else {
64+
console.log('Max retries reached. Giving up.');
65+
}
8766
}
8867
}
8968

90-
// 初始調用
9169
fetchReleaseData();

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
"chalk": "^5.3.0",
3939
"fuzzyset": "^1.0.7",
4040
"inquirer": "^9.2.15",
41-
"markdown-table-prettify": "^3.6.0"
41+
"markdown-table-prettify": "^3.6.0",
42+
"node-fetch": "^3.3.2"
4243
},
4344
"devDependencies": {
4445
"@babel/cli": "^7.23.9",

pnpm-lock.yaml

+42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)