@@ -4,12 +4,15 @@ import { window, workspace } from 'vscode'
44import { getConfig } from './config'
55import { FILE , MSG_PREFIX , URL_PREFIX } from './constants'
66
7+ const UPDATE_MARKER_FALLBACK = 'Last update from upstream'
8+
79export async function fetchLatest ( ) {
810 const repo = getConfig < string > ( 'fileNestingUpdater.upstreamRepo' )
911 const branch = getConfig < string > ( 'fileNestingUpdater.upstreamBranch' )
1012 const url = `${ URL_PREFIX } /${ repo } @${ branch } /${ FILE } `
1113 const md = await fetch ( url ) . then ( r => r . text ( ) )
1214 const content = ( md . match ( / ` ` ` j s o n c ( [ \s \S ] * ?) ` ` ` / ) || [ ] ) [ 1 ] || ''
15+ const updated = content . match ( / ^ \s * \/ \/ u p d a t e d ( .+ ) $ / m) ?. [ 1 ] ?. trim ( )
1316
1417 const json = `{${
1518 content
@@ -21,12 +24,15 @@ export async function fetchLatest() {
2124 } }`
2225
2326 const config = JSON . parse ( json ) || { }
24- return config [ 'explorer.fileNesting.patterns' ]
27+ return {
28+ patterns : config [ 'explorer.fileNesting.patterns' ] ,
29+ updated,
30+ }
2531}
2632
2733export async function fetchAndUpdate ( ctx : ExtensionContext , prompt = true ) {
2834 const config = workspace . getConfiguration ( )
29- const patterns = await fetchLatest ( )
35+ const { patterns, updated } = await fetchLatest ( )
3036 let shouldUpdate = true
3137
3238 const oringalPatterns = { ...( config . get < object > ( 'explorer.fileNesting.patterns' ) || { } ) }
@@ -54,7 +60,9 @@ export async function fetchAndUpdate(ctx: ExtensionContext, prompt = true) {
5460 config . update ( 'explorer.fileNesting.expand' , false , true )
5561
5662 config . update ( 'explorer.fileNesting.patterns' , {
57- '//' : `Last update at ${ new Date ( ) . toLocaleString ( ) } ` ,
63+ '//' : updated
64+ ? `Last update at ${ updated } UTC`
65+ : UPDATE_MARKER_FALLBACK ,
5866 ...patterns ,
5967 } , true )
6068
0 commit comments