generated from hejny/spacetrim
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatic exports (but only public entities)
- Loading branch information
Showing
10 changed files
with
793 additions
and
153 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ | |
"singleQuote": true, | ||
"trailingComma": "all", | ||
"arrowParens": "always", | ||
"printWidth": 80 | ||
"printWidth": 120 | ||
} |
Large diffs are not rendered by default.
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
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,55 @@ | ||
import { readAllProjectFiles } from './readAllProjectFiles'; | ||
|
||
/** | ||
* All possible entity types in javascript and typescript | ||
*/ | ||
type IEntityType = | ||
| 'const' | ||
| 'let' | ||
| 'class' | ||
| 'function' | ||
| 'interface' | ||
| 'type' /* <- TODO: More */; | ||
|
||
/** | ||
* Metadata of entity in javascript and typescript | ||
*/ | ||
export interface IEntity { | ||
filePath: string; | ||
type: IEntityType; | ||
name: string; | ||
anotation?: string; | ||
tags: string[]; | ||
// TODO: Detect other things like abstract, async... | ||
} | ||
|
||
export async function findAllProjectEntities(): Promise<IEntity[]> { | ||
const files = await readAllProjectFiles(); | ||
|
||
|
||
const entitities: IEntity[] = []; | ||
for (const file of files) { | ||
for (const match of file.content.matchAll( | ||
/(?<anotation>\/\*\*((?!\/\*\*).)*?\*\/\s*)?export(?:\s+declare)?(?:\s+abstract)?(?:\s+async)?(?:\s+(?<type>[a-z]+))(?:\s+(?<name>[a-zA-Z0-9_]+))/gs, | ||
)) { | ||
const { type, name, anotation } = match.groups!; | ||
|
||
const tags = Array.from( | ||
anotation?.match(/@([a-zA-Z0-9_-]+)*/g) || [], | ||
); | ||
|
||
entitities.push({ | ||
filePath: file.path, | ||
type: type as IEntityType, | ||
name, | ||
anotation, | ||
tags, | ||
}); | ||
} | ||
} | ||
|
||
//console.log(entitities.map(({ name }) => name)); | ||
//process.exit(0); | ||
|
||
return entitities; | ||
} |
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,8 @@ | ||
import glob from 'glob-promise'; | ||
import { join } from 'path'; | ||
|
||
export async function findAllProjectFiles(): Promise<Array<string>> { | ||
return await glob( | ||
join(__dirname, '../../src/**/*.{ts,tsx}').split('\\').join('/'), | ||
); | ||
} |
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,21 @@ | ||
import { readFile } from 'fs'; | ||
import { promisify } from 'util'; | ||
import { findAllProjectFiles } from './findAllProjectFiles'; | ||
|
||
export async function readAllProjectFiles(): Promise< | ||
Array<{ path: string; content: string }> | ||
> { | ||
return await Promise.all( | ||
( | ||
await findAllProjectFiles() | ||
).map(async (path) => ({ | ||
path, | ||
content: await promisify(readFile)(path, 'utf8'), | ||
})), | ||
); | ||
} | ||
|
||
|
||
/** | ||
* TODO: !!! Use fs/promises instead of fs | ||
*/ |
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.