Skip to content

Commit

Permalink
docs: remove examples from IntelliSense
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Apr 12, 2023
1 parent 4cee769 commit 1def92a
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 24 deletions.
165 changes: 142 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"ava": "^5.2.0",
"edge-runtime": "^2.1.2",
"esbuild": "^0.17.16",
"glob": "^10.0.0",
"nock": "^13.3.0",
"npm-run-all2": "^6.0.5",
"patch-package": "^6.5.1",
Expand Down
47 changes: 46 additions & 1 deletion tools/postbump.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { x } = require('tar')
const { globSync } = require('glob')

const { execSync } = require('child_process')
const { readFileSync, writeFileSync } = require('fs')
Expand Down Expand Up @@ -42,7 +43,6 @@ execSync('npm run build:browser-bundle', opts)
execSync('npm run build:browser-bundle-min', opts)
execSync('npm run build:browser-umd', opts)
execSync('git add docs/**/*.md', opts)
execSync('git add dist/**/* -f', opts)

for (const path of ['./README.md', './docs/README.md']) {
writeFileSync(
Expand All @@ -51,3 +51,48 @@ for (const path of ['./README.md', './docs/README.md']) {
)
execSync(`git add ${path}`, { stdio: 'inherit' })
}

const ts = globSync('dist/**/**.ts')

function filterExamples(file) {
let inExample = false
return file
.split('\n')
.filter((line) => {
let remove = inExample
if (line.includes('* @example')) {
remove = inExample = true
} else if (line.includes('```') && !line.includes('```js')) {
inExample = false
} else if (inExample) {
remove = true
}
return remove === false
})
.join('\n')
}

function trimExcessComment(file) {
let previousWasEmpty = false
return file
.split('\n')
.filter((line) => {
let remove = false
if (line.trim() === '*' && previousWasEmpty) {
remove = true
} else if (line.trim() === '*' || line.trim() === '/**') {
previousWasEmpty = true
} else {
previousWasEmpty = false
}

return remove === false
})
.join('\n')
}

for (const file of ts) {
writeFileSync(file, trimExcessComment(filterExamples(readFileSync(file, { encoding: 'utf-8' }))))
}

execSync('git add dist/**/* -f', opts)

0 comments on commit 1def92a

Please sign in to comment.