Skip to content

Commit fce5176

Browse files
author
根号三
authored
feat(extension): make the url configurable (#95)
1 parent 7eb1df5 commit fce5176

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

extension/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ A config to make your file tree cleaner with the <a href="https://code.visualstu
1515
<a href="https://marketplace.visualstudio.com/items?itemName=antfu.file-nesting" target="__blank"><img src="https://img.shields.io/visual-studio-marketplace/v/antfu.file-nesting.svg?color=blue&amp;label=VS%20Code%20Marketplace&logo=visual-studio-code" alt="Visual Studio Marketplace Version" /></a>
1616
</p>
1717

18-
1918
![](https://user-images.githubusercontent.com/11247099/157142238-b00deecb-8d56-424f-9b20-ef6a6f5ddf99.png)
2019

2120
## Configurations
@@ -25,6 +24,8 @@ A config to make your file tree cleaner with the <a href="https://code.visualstu
2524
"fileNestingUpdater.autoUpdate": true,
2625
"fileNestingUpdater.autoUpdateInterval": 720,
2726
"fileNestingUpdater.promptOnAutoUpdate": true,
27+
"fileNestingUpdater.upstreamRepo": "antfu/vscode-file-nesting-config",
28+
"fileNestingUpdater.upstreamBranch": "main"
2829
}
2930
```
3031

extension/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@
4242
"type": "number",
4343
"description": "The minimal interval for auto update, in minutes",
4444
"default": 720
45+
},
46+
"fileNestingUpdater.upstreamRepo": {
47+
"type": "string",
48+
"description": "The upstream repo you want to update from",
49+
"default": "antfu/vscode-file-nesting-config"
50+
},
51+
"fileNestingUpdater.upstreamBranch": {
52+
"type": "string",
53+
"description": "The branch name of upstream repo",
54+
"default": "main"
4555
}
4656
}
4757
}

extension/src/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
export const URL = 'https://cdn.jsdelivr.net/gh/antfu/vscode-file-nesting-config@main/README.md'
1+
export const URL_PREFIX = 'https://cdn.jsdelivr.net/gh'
2+
export const FILE = 'README.md'
23
export const MSG_PREFIX = 'File Nesting Updater:'

extension/src/fetch.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import fetch from 'node-fetch'
22
import type { ExtensionContext } from 'vscode'
33
import { window, workspace } from 'vscode'
4-
import { MSG_PREFIX, URL } from './constants'
4+
import { MSG_PREFIX, URL_PREFIX, FILE } from './constants'
5+
import { getConfig } from './config'
56

67
export async function fetchLatest() {
7-
const md = await fetch(URL).then(r => r.text())
8+
const repo = getConfig<string>('fileNestingUpdater.upstreamRepo')
9+
const branch = getConfig<string>('fileNestingUpdater.upstreamBranch')
10+
const url = `${URL_PREFIX}/${repo}@${branch}/${FILE}`
11+
const md = await fetch(url).then(r => r.text())
812
const content = (md.match(/```jsonc([\s\S]*?)```/) || [])[1] || ''
913

1014
const json = `{${

0 commit comments

Comments
 (0)