mirror of
https://github.com/transloadit/uppy.git
synced 2026-01-23 02:25:07 +00:00
deps: remove execa and refactor update-contributors script
This commit is contained in:
parent
51af8668f2
commit
95a8d871e9
3 changed files with 47 additions and 37 deletions
|
|
@ -1,35 +0,0 @@
|
|||
const execa = require('execa')
|
||||
const fs = require('fs')
|
||||
|
||||
const README_FILE_NAME = 'README.md'
|
||||
|
||||
async function updateContributorsListInReadme () {
|
||||
const readme = fs.readFileSync(README_FILE_NAME, 'utf-8')
|
||||
const args = [
|
||||
'--owner', 'transloadit',
|
||||
'--repo', 'uppy',
|
||||
'--cols', '6',
|
||||
'--format', 'md',
|
||||
'--showlogin', 'true',
|
||||
'--sortOrder', 'desc',
|
||||
]
|
||||
|
||||
if (process.env.GITHUB_TOKEN) {
|
||||
args.push('--authToken', process.env.GITHUB_TOKEN)
|
||||
}
|
||||
|
||||
const { stdout } = await execa('githubcontrib', args, { encoding: 'utf-8' })
|
||||
console.log(stdout)
|
||||
if (stdout === '' || stdout === null) {
|
||||
console.log('Empty response from githubcontrib. GitHub’s rate limit?')
|
||||
return
|
||||
}
|
||||
|
||||
const readmeWithUpdatedContributors = readme.replace(
|
||||
/<!--contributors-->[\s\S]+<!--\/contributors-->/,
|
||||
`<!--contributors-->\n${stdout}\n<!--/contributors-->`
|
||||
)
|
||||
fs.writeFileSync(README_FILE_NAME, readmeWithUpdatedContributors)
|
||||
}
|
||||
|
||||
updateContributorsListInReadme()
|
||||
46
bin/update-contributors.mjs
Normal file
46
bin/update-contributors.mjs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import { spawn } from "node:child_process"
|
||||
import fs from "node:fs/promises"
|
||||
|
||||
const README_FILE_NAME = new URL("../README.md", import.meta.url)
|
||||
|
||||
const readme = await fs.open(README_FILE_NAME, "r+")
|
||||
const readmeContent = await readme.readFile()
|
||||
|
||||
const githubcontrib = spawn("npx", [
|
||||
'githubcontrib',
|
||||
'--owner', 'transloadit',
|
||||
'--repo', 'uppy',
|
||||
'--cols', '6',
|
||||
'--format', 'md',
|
||||
'--showlogin', 'true',
|
||||
'--sortOrder', 'desc',
|
||||
], {
|
||||
stdio: ['ignore', 'pipe', 'inherit'],
|
||||
});
|
||||
|
||||
githubcontrib.on('error', console.error)
|
||||
|
||||
// Detect start of contributors section.
|
||||
const START_TAG = Buffer.from("<!--contributors-->\n")
|
||||
let START_TAG_POSITION = readmeContent.indexOf(START_TAG) + START_TAG.byteLength
|
||||
|
||||
let cursor = START_TAG_POSITION
|
||||
for await (const data of githubcontrib.stdout) {
|
||||
const { bytesWritten } = await readme.write(data.toString('utf-8'), cursor, "utf-8")
|
||||
cursor += bytesWritten
|
||||
}
|
||||
|
||||
if(cursor === START_TAG_POSITION) {
|
||||
console.log('Empty response from githubcontrib. GitHub’s rate limit?')
|
||||
await readme.close()
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// Write the end of the file.
|
||||
await readme.write(
|
||||
readmeContent,
|
||||
readmeContent.indexOf("<!--/contributors-->"),
|
||||
undefined,
|
||||
cursor
|
||||
)
|
||||
await readme.close()
|
||||
|
|
@ -84,7 +84,6 @@
|
|||
"eslint-plugin-promise": "4.2.1",
|
||||
"eslint-plugin-react": "7.22.0",
|
||||
"events.once": "2.0.2",
|
||||
"execa": "4.0.0",
|
||||
"exorcist": "^2.0.0",
|
||||
"express": "^4.17.1",
|
||||
"fakefile": "^1.0.0",
|
||||
|
|
@ -153,7 +152,7 @@
|
|||
"build:lib": "node ./bin/build-lib.js",
|
||||
"build:locale-pack": "node ./bin/locale-packs.js build",
|
||||
"build": "npm-run-all --parallel build:js build:css --serial size",
|
||||
"contributors:save": "node ./bin/update-contributors.js",
|
||||
"contributors:save": "node ./bin/update-contributors.mjs",
|
||||
"dev:browsersync": "browser-sync start --no-open --no-ghost-mode false --server examples/dev --index Dashboard.html --port 3452 --serveStatic packages/uppy/dist --files \"examples/dev/output/*.js, packages/uppy/dist/uppy.min.css, packages/uppy/lib/**/*\"",
|
||||
"dev:watch-sandbox": "npm run --prefix examples/dev watch:sandbox",
|
||||
"dev:with-companion": "npm-run-all --parallel start:companion dev:watch-sandbox watch:js:lib watch:css dev:browsersync",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue