Files
JavaScript/.github/workflows/UpdateDirectory.js
Roland Hummel 86d333ee94 feat: Test running overhaul, switch to Prettier & reformat everything (#1407)
* chore: Switch to Node 20 + Vitest

* chore: migrate to vitest mock functions

* chore: code style (switch to prettier)

* test: re-enable long-running test

Seems the switch to Node 20 and Vitest has vastly improved the code's and / or the test's runtime!

see #1193

* chore: code style

* chore: fix failing tests

* Updated Documentation in README.md

* Update contribution guidelines to state usage of Prettier

* fix: set prettier printWidth back to 80

* chore: apply updated code style automatically

* fix: set prettier line endings to lf again

* chore: apply updated code style automatically

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
2023-10-04 02:38:19 +05:30

72 lines
1.8 KiB
JavaScript

import path from 'path'
import fs from 'fs'
import { globby } from 'globby'
function pathPrefix (i) {
const res = ' '.repeat(i)
return res + '*'
}
function printPath (oldPath, newPath, output) {
const oldParts = oldPath.split(path.sep)
const newParts = newPath.split(path.sep)
for (let i = 0; i < newParts.length; ++i) {
const newPart = newParts[i]
if (i + 1 > oldParts.length || oldParts[i] !== newPart) {
if (newPart) {
output.push(`${pathPrefix(i)} **${newPart.replace('_', ' ')}**`)
}
}
}
return newPath
}
function pathsToMarkdown (filePaths) {
const output = []
let oldPath = ''
filePaths.sort(function (a, b) {
if (a.toLowerCase() < b.toLowerCase()) return -1
if (a.toLowerCase() > b.toLowerCase()) return 1
return 0
})
for (let filepath of filePaths) {
let filename = path.basename(filepath)
filepath = path.dirname(filepath)
if (filepath !== oldPath) {
oldPath = printPath(oldPath, filepath, output)
}
let indent = filepath.split(path.sep).length
// prepare the markdown-esque prefix to the file's line
const prefix = pathPrefix(indent)
// remove extension from filename
const name = path.basename(filename, ".js")
const url = path.join(filepath, filename)
output.push(`${prefix} [${name}](${url})`)
}
return output.join('\n')
}
// get paths of all .js files - excluding node_modules, the .github folder, tests and config stuff
globby([
'**/*.js',
'!(node_modules|.github)/**/*',
"!**/test/**/*",
'!**/*.test.js',
'!**/*.manual-test.js',
'!vitest.config.ts'
])
// create markdown content
.then(pathsToMarkdown)
// write markdown to file
.then(markdown => fs.writeFileSync('DIRECTORY.md', markdown + '\n', { encoding: 'utf8' }))