generated from jonahsnider/typescript-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0a14b5
commit a32255f
Showing
10 changed files
with
3,109 additions
and
4,816 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
Binary file not shown.
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
File renamed without changes.
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,15 @@ | ||
const examples = /`(.*)`/gm; | ||
const exampleHeadings = /^- (.*)/gm; | ||
const doubleBrackets = /{{|}}/g; | ||
|
||
export function format(tldr: string): string { | ||
return tldr | ||
.replaceAll( | ||
examples, | ||
`\`\`\`sh | ||
$1 | ||
\`\`\`` | ||
) | ||
.replaceAll(exampleHeadings, '## $1') | ||
.replaceAll(doubleBrackets, ''); | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,8 +1,55 @@ | ||
/** | ||
* Says hello world. | ||
* @param subject What the subject of the message is. | ||
* @returns Hello world message | ||
*/ | ||
export function helloWorld(subject?: string): string { | ||
return `Hello, ${subject ?? 'world'}.`; | ||
import execa from 'execa'; | ||
import fs from 'fs/promises'; | ||
import {homedir} from 'os'; | ||
import path from 'path'; | ||
import {stdout} from 'process'; | ||
import {format} from './format.js'; | ||
|
||
const tldrPath = path.join(homedir(), '.cache', 'how', 'tldr'); | ||
|
||
try { | ||
await fs.access(tldrPath); | ||
} catch (error) { | ||
await fs.mkdir(tldrPath, {recursive: true}); | ||
await execa(`git`, ['clone', 'https://github.com/tldr-pages/tldr.git', tldrPath]); | ||
} | ||
|
||
if (Math.random() > 0.95) { | ||
try { | ||
await execa(`git`, ['pull'], {cwd: tldrPath}); | ||
console.error('you got unlucky and the cache was refreshed'); | ||
} catch (error) { | ||
console.error('failed to refresh cache'); | ||
} | ||
} | ||
|
||
const command = process.argv[process.argv.length - 1]; | ||
|
||
// Command was probably a path (ex. '/home/jonah/programming/how/tsc_output') | ||
if (command.includes(path.sep)) { | ||
console.error('no program'); | ||
process.exit(1); | ||
} | ||
|
||
const potentialPaths = ['common', 'linux'].map(dir => path.join(tldrPath, 'pages', dir, `${command}.md`)); | ||
|
||
for (const potentialPath of potentialPaths) { | ||
try { | ||
await fs.access(potentialPath); | ||
} catch { | ||
continue; | ||
} | ||
|
||
const contents = await fs.readFile(potentialPath, 'utf-8'); | ||
const formatted = format(contents); | ||
|
||
const tldr = await execa('./lib/glow-1.3.0', ['-s', 'dark', '-'], { | ||
input: formatted | ||
}); | ||
|
||
stdout.write(format(tldr.stdout)); | ||
process.exit(0); | ||
} | ||
|
||
console.error('no'); | ||
process.exit(1); |
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
Oops, something went wrong.