Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta: enable linter on mjs scripts #3364

Merged
merged 1 commit into from Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -166,6 +166,7 @@ module.exports = {
{
files: [
'bin/**.js',
'bin/**.mjs',
'examples/**/*.js',
'packages/@uppy/companion/test/**/*.js',
'test/**/*.js',
Expand Down
44 changes: 23 additions & 21 deletions bin/update-contributors.mjs 100644 → 100755
@@ -1,36 +1,38 @@
import { spawn } from "node:child_process"
import fs from "node:fs/promises"
#!/usr/bin/env node

const README_FILE_NAME = new URL("../README.md", import.meta.url)
import { spawn } from 'node:child_process'
import fs from 'node:fs/promises'

const readme = await fs.open(README_FILE_NAME, "r+")
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'],
});
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
const START_TAG = Buffer.from('<!--contributors-->\n')
const 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")
const { bytesWritten } = await readme.write(data.toString('utf-8'), cursor, 'utf-8')
cursor += bytesWritten
}

if(cursor === START_TAG_POSITION) {
if (cursor === START_TAG_POSITION) {
console.log('Empty response from githubcontrib. GitHub’s rate limit?')
await readme.close()
process.exit(1)
Expand All @@ -39,8 +41,8 @@ if(cursor === START_TAG_POSITION) {
// Write the end of the file.
await readme.write(
readmeContent,
readmeContent.indexOf("<!--/contributors-->"),
readmeContent.indexOf('<!--/contributors-->'),
undefined,
cursor
cursor,
)
await readme.close()