Skip to content

Commit 2e1cc30

Browse files
committed
Added support for Rising Stars CSS bumping
1 parent eff260d commit 2e1cc30

File tree

4 files changed

+159
-78
lines changed

4 files changed

+159
-78
lines changed

Diff for: chatgpt-auto-continue/utils/bump/js-resources.js

+37-17
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525

2626
// Init REGEX
2727
const rePatterns = {
28-
resourceName: /\w+\/\w+\.js(?=#|$)/,
28+
resourceName: /[^/]+\/(?:css|dist)?\/?[^/]+\.(?:css|js)(?=[?#]|$)/,
29+
cssURL: /^\/\/ @resource.+(https:\/\/assets.+\.css.+)$/gm,
2930
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+$)/gm,
30-
commitHash: /@([^/]+)/, sriHash: /[^#]+$/
31+
commitHash: /(@|\?v=)([^/#]+)/, sriHash: /[^#]+$/
3132
}
3233

3334
// Define FUNCTIONS
@@ -76,39 +77,58 @@
7677
} else // bump to today
7778
newVer = today
7879
fs.writeFileSync(userJSfilePath, userJScontent.replace(re_version, `$1${newVer}`), 'utf-8')
79-
console.log(`Updated: ${bw}v${currentVer}${nc}${bg}v${newVer}${nc}\n`)
80+
console.log(`Updated: ${bw}v${currentVer}${nc}${bg}v${newVer}${nc}`)
8081
}
8182

8283
// Run MAIN routine
8384

84-
log.working('\nCollecting JS resources...\n')
85+
// Collect resourcs
86+
log.working('\nCollecting resources...\n')
8587
const userJScontent = fs.readFileSync(userJSfilePath, 'utf-8'),
86-
resourceURLs = [...userJScontent.matchAll(rePatterns.jsURL)].map(match => match[1])
88+
reResourceURL = new RegExp(`(?:${rePatterns.cssURL.source})|(?:${rePatterns.jsURL.source})`, 'gm'),
89+
resourceURLs = [...userJScontent.matchAll(reResourceURL)].map(match => match[1] || match[2])
8790
log.success(`${resourceURLs.length} potentially bumpable resource(s) found.`)
8891

92+
// Fetch latest commit hash for adamlui/ai-web-extensions/assets/styles/rising-stars
93+
const ghEndpoint = 'https://api.github.com/repos/adamlui/ai-web-extensions/commits',
94+
risingStarsPath = 'assets/styles/rising-stars'
95+
log.working(`\nFetching latest commit hash for ${risingStarsPath}...\n`)
96+
const latestCommitHashes = {
97+
risingStars: (await (await fetch(`${ghEndpoint}?path=${risingStarsPath}`)).json())[0]?.sha }
98+
console.log(`${latestCommitHashes.risingStars}`)
99+
89100
log.working('\nProcessing resource(s)...\n')
90101
let urlsUpdatedCnt = 0
91102

92103
// Fetch latest commit hash
93-
console.log('Fetching latest commit hash...')
94-
const latestCommitHash = require('child_process').execFileSync(
95-
'git', ['ls-remote', `https://github.com/adamlui/${repoName}.git`, 'HEAD']).toString().split('\t')[0]
96-
console.log(latestCommitHash + '\n')
104+
if (resourceURLs.some(url => url.includes(repoName))) {
105+
console.log('Fetching latest commit hash for repo...')
106+
latestCommitHashes.repoResources = require('child_process').execFileSync(
107+
'git', ['ls-remote', `https://github.com/adamlui/${repoName}.git`, 'HEAD']).toString().split('\t')[0]
108+
console.log(`${latestCommitHashes.repoResources}\n`)
109+
}
97110

98111
// Process each resource
99112
for (const resourceURL of resourceURLs) {
100-
const resourceName = rePatterns.resourceName.exec(resourceURL)?.[0] || 'resource' // dir/filename.js for logs
113+
const resourceName = rePatterns.resourceName.exec(resourceURL)?.[0] || 'resource' // dir/filename for logs
101114

102115
// Compare commit hashes
103-
if (latestCommitHash.startsWith(rePatterns.commitHash.exec(resourceURL)?.[1] || '')) { // commit hash didn't change...
104-
console.log(`${resourceName} already up-to-date!\n`) ; continue } // ...so skip resource
105-
let updatedURL = resourceURL.replace(rePatterns.commitHash, `@${latestCommitHash}`) // othrwise update commit hash
116+
const resourceLatestCommitHash = latestCommitHashes[
117+
resourceURL.includes(repoName) ? 'repoResources' : 'risingStars']
118+
if (resourceLatestCommitHash.startsWith(
119+
rePatterns.commitHash.exec(resourceURL)?.[2] || '')) { // commit hash didn't change...
120+
console.log(`${resourceName} already up-to-date!`) ; log.hadLineBreak = false
121+
continue // ...so skip resource
122+
}
123+
let updatedURL = resourceURL.replace(rePatterns.commitHash, `$1${resourceLatestCommitHash}`) // otherwise update commit hash
106124

107125
// Generate/compare SRI hash
108-
console.log(`Generating SHA-256 hash for ${resourceName}...`)
126+
console.log(`${ !log.hadLineBreak ? '\n' : '' }Generating SHA-256 hash for ${resourceName}...`)
109127
const newSRIhash = await getSRIhash(updatedURL)
110128
if (rePatterns.sriHash.exec(resourceURL)?.[0] == newSRIhash) { // SRI hash didn't change
111-
console.log(`${resourceName} already up-to-date!\n`) ; continue } // ...so skip resource
129+
console.log(`${resourceName} already up-to-date!`) ; log.hadLineBreak = false
130+
continue // ...so skip resource
131+
}
112132
updatedURL = updatedURL.replace(rePatterns.sriHash, newSRIhash) // otherwise update SRI hash
113133

114134
// Write updated URL to userscript
@@ -119,12 +139,12 @@
119139
urlsUpdatedCnt++
120140
}
121141
if (urlsUpdatedCnt > 0) {
122-
console.log('Bumping userscript version...')
142+
console.log(`${ !log.hadLineBreak ? '\n' : '' }Bumping userscript version...`)
123143
bumpUserJSver(userJSfilePath)
124144
}
125145

126146
// Log final summary
127147
log[urlsUpdatedCnt > 0 ? 'success' : 'info'](
128-
`${ urlsUpdatedCnt > 0 ? 'Success! ' : '' }${urlsUpdatedCnt} resource(s) bumped.`)
148+
`\n${ urlsUpdatedCnt > 0 ? 'Success! ' : '' }${urlsUpdatedCnt} resource(s) bumped.`)
129149

130150
})()

Diff for: chatgpt-infinity/utils/bump/js-resources.js

+37-17
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525

2626
// Init REGEX
2727
const rePatterns = {
28-
resourceName: /\w+\/\w+\.js(?=#|$)/,
28+
resourceName: /[^/]+\/(?:css|dist)?\/?[^/]+\.(?:css|js)(?=[?#]|$)/,
29+
cssURL: /^\/\/ @resource.+(https:\/\/assets.+\.css.+)$/gm,
2930
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+$)/gm,
30-
commitHash: /@([^/]+)/, sriHash: /[^#]+$/
31+
commitHash: /(@|\?v=)([^/#]+)/, sriHash: /[^#]+$/
3132
}
3233

3334
// Define FUNCTIONS
@@ -76,39 +77,58 @@
7677
} else // bump to today
7778
newVer = today
7879
fs.writeFileSync(userJSfilePath, userJScontent.replace(re_version, `$1${newVer}`), 'utf-8')
79-
console.log(`Updated: ${bw}v${currentVer}${nc}${bg}v${newVer}${nc}\n`)
80+
console.log(`Updated: ${bw}v${currentVer}${nc}${bg}v${newVer}${nc}`)
8081
}
8182

8283
// Run MAIN routine
8384

84-
log.working('\nCollecting JS resources...\n')
85+
// Collect resourcs
86+
log.working('\nCollecting resources...\n')
8587
const userJScontent = fs.readFileSync(userJSfilePath, 'utf-8'),
86-
resourceURLs = [...userJScontent.matchAll(rePatterns.jsURL)].map(match => match[1])
88+
reResourceURL = new RegExp(`(?:${rePatterns.cssURL.source})|(?:${rePatterns.jsURL.source})`, 'gm'),
89+
resourceURLs = [...userJScontent.matchAll(reResourceURL)].map(match => match[1] || match[2])
8790
log.success(`${resourceURLs.length} potentially bumpable resource(s) found.`)
8891

92+
// Fetch latest commit hash for adamlui/ai-web-extensions/assets/styles/rising-stars
93+
const ghEndpoint = 'https://api.github.com/repos/adamlui/ai-web-extensions/commits',
94+
risingStarsPath = 'assets/styles/rising-stars'
95+
log.working(`\nFetching latest commit hash for ${risingStarsPath}...\n`)
96+
const latestCommitHashes = {
97+
risingStars: (await (await fetch(`${ghEndpoint}?path=${risingStarsPath}`)).json())[0]?.sha }
98+
console.log(`${latestCommitHashes.risingStars}`)
99+
89100
log.working('\nProcessing resource(s)...\n')
90101
let urlsUpdatedCnt = 0
91102

92103
// Fetch latest commit hash
93-
console.log('Fetching latest commit hash...')
94-
const latestCommitHash = require('child_process').execFileSync(
95-
'git', ['ls-remote', `https://github.com/adamlui/${repoName}.git`, 'HEAD']).toString().split('\t')[0]
96-
console.log(latestCommitHash + '\n')
104+
if (resourceURLs.some(url => url.includes(repoName))) {
105+
console.log('Fetching latest commit hash for repo...')
106+
latestCommitHashes.repoResources = require('child_process').execFileSync(
107+
'git', ['ls-remote', `https://github.com/adamlui/${repoName}.git`, 'HEAD']).toString().split('\t')[0]
108+
console.log(`${latestCommitHashes.repoResources}\n`)
109+
}
97110

98111
// Process each resource
99112
for (const resourceURL of resourceURLs) {
100-
const resourceName = rePatterns.resourceName.exec(resourceURL)?.[0] || 'resource' // dir/filename.js for logs
113+
const resourceName = rePatterns.resourceName.exec(resourceURL)?.[0] || 'resource' // dir/filename for logs
101114

102115
// Compare commit hashes
103-
if (latestCommitHash.startsWith(rePatterns.commitHash.exec(resourceURL)?.[1] || '')) { // commit hash didn't change...
104-
console.log(`${resourceName} already up-to-date!\n`) ; continue } // ...so skip resource
105-
let updatedURL = resourceURL.replace(rePatterns.commitHash, `@${latestCommitHash}`) // othrwise update commit hash
116+
const resourceLatestCommitHash = latestCommitHashes[
117+
resourceURL.includes(repoName) ? 'repoResources' : 'risingStars']
118+
if (resourceLatestCommitHash.startsWith(
119+
rePatterns.commitHash.exec(resourceURL)?.[2] || '')) { // commit hash didn't change...
120+
console.log(`${resourceName} already up-to-date!`) ; log.hadLineBreak = false
121+
continue // ...so skip resource
122+
}
123+
let updatedURL = resourceURL.replace(rePatterns.commitHash, `$1${resourceLatestCommitHash}`) // otherwise update commit hash
106124

107125
// Generate/compare SRI hash
108-
console.log(`Generating SHA-256 hash for ${resourceName}...`)
126+
console.log(`${ !log.hadLineBreak ? '\n' : '' }Generating SHA-256 hash for ${resourceName}...`)
109127
const newSRIhash = await getSRIhash(updatedURL)
110128
if (rePatterns.sriHash.exec(resourceURL)?.[0] == newSRIhash) { // SRI hash didn't change
111-
console.log(`${resourceName} already up-to-date!\n`) ; continue } // ...so skip resource
129+
console.log(`${resourceName} already up-to-date!`) ; log.hadLineBreak = false
130+
continue // ...so skip resource
131+
}
112132
updatedURL = updatedURL.replace(rePatterns.sriHash, newSRIhash) // otherwise update SRI hash
113133

114134
// Write updated URL to userscript
@@ -119,12 +139,12 @@
119139
urlsUpdatedCnt++
120140
}
121141
if (urlsUpdatedCnt > 0) {
122-
console.log('Bumping userscript version...')
142+
console.log(`${ !log.hadLineBreak ? '\n' : '' }Bumping userscript version...`)
123143
bumpUserJSver(userJSfilePath)
124144
}
125145

126146
// Log final summary
127147
log[urlsUpdatedCnt > 0 ? 'success' : 'info'](
128-
`${ urlsUpdatedCnt > 0 ? 'Success! ' : '' }${urlsUpdatedCnt} resource(s) bumped.`)
148+
`\n${ urlsUpdatedCnt > 0 ? 'Success! ' : '' }${urlsUpdatedCnt} resource(s) bumped.`)
129149

130150
})()

Diff for: chatgpt-widescreen/utils/bump/js-resources.js

+37-17
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121

2222
// Init REGEX
2323
const rePatterns = {
24-
resourceName: /\w+\/\w+\.js(?=#|$)/,
24+
resourceName: /[^/]+\/(?:css|dist)?\/?[^/]+\.(?:css|js)(?=[?#]|$)/,
25+
cssURL: /^\/\/ @resource.+(https:\/\/assets.+\.css.+)$/gm,
2526
jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+$)/gm,
26-
commitHash: /@([^/]+)/, sriHash: /[^#]+$/
27+
commitHash: /(@|\?v=)([^/#]+)/, sriHash: /[^#]+$/
2728
}
2829

2930
// Define FUNCTIONS
@@ -72,39 +73,58 @@
7273
} else // bump to today
7374
newVer = today
7475
fs.writeFileSync(userJSfilePath, userJScontent.replace(re_version, `$1${newVer}`), 'utf-8')
75-
console.log(`Updated: ${bw}v${currentVer}${nc}${bg}v${newVer}${nc}\n`)
76+
console.log(`Updated: ${bw}v${currentVer}${nc}${bg}v${newVer}${nc}`)
7677
}
7778

7879
// Run MAIN routine
7980

80-
log.working('\nCollecting JS resources...\n')
81+
// Collect resourcs
82+
log.working('\nCollecting resources...\n')
8183
const userJScontent = fs.readFileSync(userJSfilePath, 'utf-8'),
82-
resourceURLs = [...userJScontent.matchAll(rePatterns.jsURL)].map(match => match[1])
84+
reResourceURL = new RegExp(`(?:${rePatterns.cssURL.source})|(?:${rePatterns.jsURL.source})`, 'gm'),
85+
resourceURLs = [...userJScontent.matchAll(reResourceURL)].map(match => match[1] || match[2])
8386
log.success(`${resourceURLs.length} potentially bumpable resource(s) found.`)
8487

88+
// Fetch latest commit hash for adamlui/ai-web-extensions/assets/styles/rising-stars
89+
const ghEndpoint = 'https://api.github.com/repos/adamlui/ai-web-extensions/commits',
90+
risingStarsPath = 'assets/styles/rising-stars'
91+
log.working(`\nFetching latest commit hash for ${risingStarsPath}...\n`)
92+
const latestCommitHashes = {
93+
risingStars: (await (await fetch(`${ghEndpoint}?path=${risingStarsPath}`)).json())[0]?.sha }
94+
console.log(`${latestCommitHashes.risingStars}`)
95+
8596
log.working('\nProcessing resource(s)...\n')
8697
let urlsUpdatedCnt = 0
8798

8899
// Fetch latest commit hash
89-
console.log('Fetching latest commit hash...')
90-
const latestCommitHash = require('child_process').execFileSync(
91-
'git', ['ls-remote', `https://github.com/adamlui/${repoName}.git`, 'HEAD']).toString().split('\t')[0]
92-
console.log(latestCommitHash + '\n')
100+
if (resourceURLs.some(url => url.includes(repoName))) {
101+
console.log('Fetching latest commit hash for repo...')
102+
latestCommitHashes.repoResources = require('child_process').execFileSync(
103+
'git', ['ls-remote', `https://github.com/adamlui/${repoName}.git`, 'HEAD']).toString().split('\t')[0]
104+
console.log(`${latestCommitHashes.repoResources}\n`)
105+
}
93106

94107
// Process each resource
95108
for (const resourceURL of resourceURLs) {
96-
const resourceName = rePatterns.resourceName.exec(resourceURL)?.[0] || 'resource' // dir/filename.js for logs
109+
const resourceName = rePatterns.resourceName.exec(resourceURL)?.[0] || 'resource' // dir/filename for logs
97110

98111
// Compare commit hashes
99-
if (latestCommitHash.startsWith(rePatterns.commitHash.exec(resourceURL)?.[1] || '')) { // commit hash didn't change...
100-
console.log(`${resourceName} already up-to-date!\n`) ; continue } // ...so skip resource
101-
let updatedURL = resourceURL.replace(rePatterns.commitHash, `@${latestCommitHash}`) // othrwise update commit hash
112+
const resourceLatestCommitHash = latestCommitHashes[
113+
resourceURL.includes(repoName) ? 'repoResources' : 'risingStars']
114+
if (resourceLatestCommitHash.startsWith(
115+
rePatterns.commitHash.exec(resourceURL)?.[2] || '')) { // commit hash didn't change...
116+
console.log(`${resourceName} already up-to-date!`) ; log.hadLineBreak = false
117+
continue // ...so skip resource
118+
}
119+
let updatedURL = resourceURL.replace(rePatterns.commitHash, `$1${resourceLatestCommitHash}`) // otherwise update commit hash
102120

103121
// Generate/compare SRI hash
104-
console.log(`Generating SHA-256 hash for ${resourceName}...`)
122+
console.log(`${ !log.hadLineBreak ? '\n' : '' }Generating SHA-256 hash for ${resourceName}...`)
105123
const newSRIhash = await getSRIhash(updatedURL)
106124
if (rePatterns.sriHash.exec(resourceURL)?.[0] == newSRIhash) { // SRI hash didn't change
107-
console.log(`${resourceName} already up-to-date!\n`) ; continue } // ...so skip resource
125+
console.log(`${resourceName} already up-to-date!`) ; log.hadLineBreak = false
126+
continue // ...so skip resource
127+
}
108128
updatedURL = updatedURL.replace(rePatterns.sriHash, newSRIhash) // otherwise update SRI hash
109129

110130
// Write updated URL to userscript
@@ -115,12 +135,12 @@
115135
urlsUpdatedCnt++
116136
}
117137
if (urlsUpdatedCnt > 0) {
118-
console.log('Bumping userscript version...')
138+
console.log(`${ !log.hadLineBreak ? '\n' : '' }Bumping userscript version...`)
119139
bumpUserJSver(userJSfilePath)
120140
}
121141

122142
// Log final summary
123143
log[urlsUpdatedCnt > 0 ? 'success' : 'info'](
124-
`${ urlsUpdatedCnt > 0 ? 'Success! ' : '' }${urlsUpdatedCnt} resource(s) bumped.`)
144+
`\n${ urlsUpdatedCnt > 0 ? 'Success! ' : '' }${urlsUpdatedCnt} resource(s) bumped.`)
125145

126146
})()

0 commit comments

Comments
 (0)