-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: components history and catalog
- Loading branch information
1 parent
d369821
commit 5e76046
Showing
255 changed files
with
14,939 additions
and
10,721 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
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
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,81 @@ | ||
/** | ||
* git commits fields | ||
*/ | ||
export interface Commit { | ||
commitHash?: string; | ||
subject?: string; | ||
authorName?: string; | ||
authorData?: string; | ||
authorEmail?: string; | ||
committerName?: string; | ||
committerDate?: string; | ||
committerEmail?: string; | ||
} | ||
|
||
export type Commits = Commit[]; | ||
|
||
export interface FileInfo { | ||
/** | ||
* date file created | ||
*/ | ||
dateCreated?: Date; | ||
|
||
/** | ||
* date last modified | ||
*/ | ||
dateModified?: Date; | ||
|
||
/** | ||
* git commits for the file | ||
*/ | ||
commits?: Commits; | ||
/** | ||
* number of lines of code | ||
*/ | ||
sloc?: { | ||
/** | ||
* lines of block comments | ||
*/ | ||
block: number; | ||
|
||
/** | ||
* empty lines of block comments | ||
*/ | ||
|
||
blockEmpty: number; | ||
/** | ||
* total lines of comments | ||
*/ | ||
comment: number; | ||
|
||
/** | ||
* empty lines | ||
*/ | ||
empty: number; | ||
|
||
/** | ||
* lines mixed up with source and comments | ||
*/ | ||
mixed: number; | ||
|
||
/** | ||
* lines with single-line comments | ||
*/ | ||
single: number; | ||
|
||
/** | ||
* lines of code (source) | ||
*/ | ||
source: number; | ||
|
||
/** | ||
* lines with TODO's | ||
*/ | ||
todo: number; | ||
|
||
/** | ||
* physical total lines | ||
*/ | ||
total: number; | ||
}; | ||
} |
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
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 * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as os from 'os'; | ||
import { createHash } from 'crypto'; | ||
import findCacheDir from 'find-cache-dir'; | ||
|
||
export class CachedFileResource<T> { | ||
private folderKey: string; | ||
private fileKey: string; | ||
private filePath: string; | ||
|
||
constructor(folderKey: string, fileKey: string, filePath: string) { | ||
this.folderKey = folderKey; | ||
this.fileKey = fileKey; | ||
this.filePath = filePath; | ||
} | ||
|
||
private getCacheFolder = () => { | ||
const folderName = | ||
findCacheDir({ name: `component-controls-${this.folderKey}` }) || | ||
os.tmpdir(); | ||
if (!fs.existsSync(folderName)) { | ||
fs.mkdirSync(folderName, { recursive: true }); | ||
} | ||
return folderName; | ||
}; | ||
|
||
private getCachedFile = () => { | ||
const cachedFolder = this.getCacheFolder(); | ||
return path.join( | ||
cachedFolder, | ||
createHash('md5') | ||
.update(this.fileKey) | ||
.digest('hex'), | ||
); | ||
}; | ||
get = (): T | undefined => { | ||
const cachedFileName = this.getCachedFile(); | ||
if (fs.existsSync(cachedFileName)) { | ||
const cacheStats = fs.statSync(cachedFileName); | ||
const fileStats = fs.statSync(this.filePath); | ||
if (cacheStats.mtime.getTime() >= fileStats.mtime.getTime()) { | ||
const fileData = fs.readFileSync(cachedFileName, 'utf8'); | ||
const json = JSON.parse(fileData); | ||
return Object.keys(json).length ? json : undefined; | ||
} | ||
} | ||
return undefined; | ||
}; | ||
|
||
set = (data: T | undefined): void => { | ||
const cachedFileName = this.getCachedFile(); | ||
fs.writeFileSync(cachedFileName, JSON.stringify(data || {})); | ||
}; | ||
} |
Oops, something went wrong.