-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: auto update USER_AGENT version to urllib package.version (#449)
- Loading branch information
Showing
5 changed files
with
36 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env node | ||
|
||
import fs from 'fs/promises'; | ||
import path from 'path'; | ||
|
||
async function main() { | ||
const root = process.cwd(); | ||
const pkg = JSON.parse(await fs.readFile(path.join(root, 'package.json'))); | ||
const files = [ | ||
path.join(root, 'src/cjs/HttpClient.js'), | ||
path.join(root, 'src/esm/HttpClient.js'), | ||
]; | ||
for (const file of files) { | ||
const content = await fs.readFile(file, 'utf-8'); | ||
// replace "('node-urllib', 'VERSION')" to "('node-urllib', 'pkg.version')" | ||
const newContent = content.replace(/\(\'node-urllib\', \'VERSION\'\)/, (match) => { | ||
const after = `('node-urllib', '${pkg.version}')`; | ||
console.log('[%s] %s => %s', file, match, after); | ||
return after; | ||
}); | ||
if (newContent !== content) { | ||
await fs.writeFile(file, newContent); | ||
console.log('Replace version on %s', file); | ||
} | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters