Last active
August 29, 2020 14:35
-
-
Save flying-sheep/b21cc0a3b39512a4c335364043569d88 to your computer and use it in GitHub Desktop.
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
/node_modules/ | |
/package-lock.json |
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
import * as typedJSX from 'typed-jsx' | |
const { data } = typedJSX | |
enum FileType { | |
File = 'file', | |
Directory = 'directory', | |
SymbolicLink = 'symlink', | |
} | |
interface Directory { | |
type: FileType.Directory; | |
name: string; | |
children: Array<File | Directory | SymbolicLink>; | |
} | |
const Directory = (props: Omit<Directory, 'type'>) => ({ type: FileType.Directory, ...props }); | |
interface File { | |
type: FileType.File; | |
name: string; | |
data: Buffer | string; | |
} | |
const File = (props: Omit<File, 'type'>) => ({ type: FileType.File, ...props }); | |
interface SymbolicLink { | |
type: FileType.SymbolicLink; | |
name: string; | |
target: string; | |
} | |
const SymbolicLink = (props: Omit<SymbolicLink, 'type'>) => ({ type: FileType.SymbolicLink, ...props }); | |
const files = ( | |
<Directory name="root"> | |
<Directory name="sub"> | |
<File name="file1" data="..." /> | |
</Directory> | |
<Directory name="sub2"> | |
<File name="file2" data="..." /> | |
<SymbolicLink name="file3" target="../sub/file1" /> | |
</Directory> | |
</Directory> | |
); | |
console.log(JSON.stringify(files, undefined, 2)); |
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
{ | |
"name": "typed-jsx-test", | |
"version": "1.0.0", | |
"type": "module", | |
"description": "", | |
"main": "dirs.js", | |
"scripts": { | |
"build": "tsc" | |
}, | |
"author": "flying-sheep", | |
"license": "GPL-3.0", | |
"dependencies": { | |
"typed-jsx": "^0.1.1" | |
}, | |
"devDependencies": { | |
"@types/node": "^14.6.2", | |
"typescript": "^4.0.2" | |
} | |
} |
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
Show hidden characters
{ | |
"compilerOptions": { | |
"target": "ES2019", | |
"moduleResolution": "node", | |
"lib": ["ES2019", "DOM"], | |
"jsx": "react", | |
"jsxFactory": "data", | |
"strict": true, | |
}, | |
"include": [ | |
"*.tsx" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment