Skip to content

Commit

Permalink
fix(directories): fix bug on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
lonr committed Mar 2, 2023
1 parent 1aa28c2 commit 8f67b2c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 71 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@typescript-eslint/parser": "^5.48.1",
"chokidar": "^3.5.3",
"cz-conventional-changelog": "^3.3.0",
"directories-js": "^0.1.0",
"env-paths": "^3.0.0",
"eslint": "^8.32.0",
"eslint-config-prettier": "^8.6.0",
"husky": "^8.0.3",
Expand Down
13 changes: 7 additions & 6 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export { pkg };
export type PKG = typeof pkg;

// handwrite the version as `package.json` will be inlined by rollup
pkg.version = '1.1.3';
pkg.version = '1.1.4';
const SPEC_VERSION = '1.5';
const PAGES_REPO = 'https://github.com/tldr-pages/tldr';
const ROOT_DIR = fileURLToPath(new URL('../', import.meta.url));
Expand Down
19 changes: 3 additions & 16 deletions src/directories.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
import { projectDirs, projectToString } from 'directories-js';
import envPaths from 'env-paths';

interface Project {
qualifier: string;
organization: string;
application: string;
}

function directories(project: Project) {
const projectString = projectToString(project);
function wrap(resolver: (p: string) => string | null) {
return () => resolver(projectString);
}
return {
config: wrap(projectDirs.config),
data: wrap(projectDirs.data),
};
function directories(name: string) {
return envPaths(name, { suffix: '' });
}

export default directories;
80 changes: 39 additions & 41 deletions src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,48 @@ const exampleCodeHighlighted = pico.underline;

const spaces = ' ';

function render(mkd: string): string {
let res = '';
let buffer = '';
let i = 0;
while (i < mkd.length) {
const c = mkd[i];
if (c === '\n') {
if (buffer === '') {
res += '\n';
} else {
switch (buffer[0]) {
case '#':
break;
case '>':
res += spaces + buffer.slice(2) + '\n';
break;
case '-':
res += spaces + exampleText(buffer.slice(2)) + '\n';
break;
case '`':
res +=
spaces.repeat(2) +
exampleCode(
buffer
.slice(1, buffer.length - 1)
.replaceAll(/{{([^}]*)}}/g, exampleCodeHighlighted('$1'))
) +
'\n';
break;
export class Page {
constructor(private path: string) {}
async render() {
const mkd = await readFile(this.path, 'utf8');

let res = '';
let buffer = '';
let i = 0;
while (i < mkd.length) {
const c = mkd[i];
if (c === '\n') {
if (buffer === '') {
res += '\n';
} else {
switch (buffer[0]) {
case '#':
break;
case '>':
res += spaces + buffer.slice(2) + '\n';
break;
case '-':
res += spaces + exampleText(buffer.slice(2)) + '\n';
break;
case '`':
res +=
spaces.repeat(2) +
exampleCode(
buffer
.slice(1, buffer.length - 1)
.replaceAll(/{{([^}]*)}}/g, exampleCodeHighlighted('$1'))
) +
'\n';
break;
}
buffer = '';
}
buffer = '';
} else {
buffer += c;
}
} else {
buffer += c;
i += 1;
}
i += 1;
}
return res;
}

export class Page {
constructor(private path: string) {}

async render() {
console.log(render(await readFile(this.path, 'utf8')));
console.log(res);
}
}
8 changes: 2 additions & 6 deletions src/tldr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ export function resolveConfig(
pageRepo: string,
readmePath: string
): Config {
const dirs = directories({
qualifier: 'org',
organization: pkg.author,
application: pkg.name,
});
const dataDir = dirs.data();
const dirs = directories(pkg.name);
const dataDir = dirs.data;
if (dataDir === null) {
throw new Error('failed to get data dir');
}
Expand Down

0 comments on commit 8f67b2c

Please sign in to comment.