-
Notifications
You must be signed in to change notification settings - Fork 438
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
404ccd9
commit 07a2e33
Showing
5 changed files
with
53 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,49 @@ | ||
const path = require('path'); | ||
import { readFileSync, readdirSync, statSync, Stats } from 'fs'; | ||
import { join, resolve } from 'path'; | ||
|
||
const md5 = require('md5'); | ||
|
||
export const projectRoot = (relativePath) => { | ||
return path.resolve(__dirname, '..', relativePath); | ||
return resolve(__dirname, '..', relativePath); | ||
}; | ||
|
||
export const globalCSSImports = () => { | ||
return [ | ||
projectRoot(path.join('src', 'styles', '_variables.scss')), | ||
projectRoot(path.join('src', 'styles', '_mixins.scss')), | ||
projectRoot(join('src', 'styles', '_variables.scss')), | ||
projectRoot(join('src', 'styles', '_mixins.scss')), | ||
]; | ||
}; | ||
|
||
/** | ||
* Calculates the md5 hash of a file | ||
* | ||
* @param filePath The path of the file | ||
*/ | ||
export function calculateFileHash(filePath: string): string { | ||
const fileContent: Buffer = readFileSync(filePath); | ||
return md5(fileContent); | ||
} | ||
|
||
module.exports = { | ||
projectRoot, | ||
globalCSSImports | ||
}; | ||
/** | ||
* Calculate the hashes of all the files (matching the given regex) in a certain folder | ||
* | ||
* @param folderPath The path of the folder | ||
* @param regExp A regex of the files in the folder for which a hash needs to be generated | ||
*/ | ||
export function getFileHashes(folderPath: string, regExp: RegExp): { [fileName: string]: string } { | ||
const files: string[] = readdirSync(folderPath); | ||
let hashes: { [fileName: string]: string } = {}; | ||
|
||
for (const file of files) { | ||
if (file.match(regExp)) { | ||
const filePath: string = join(folderPath, file); | ||
const stats: Stats = statSync(filePath); | ||
|
||
if (stats.isFile()) { | ||
hashes[file] = calculateFileHash(filePath); | ||
} | ||
} | ||
} | ||
|
||
return hashes; | ||
} |
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