@byaga/cdk-patterns 0.8.5 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,49 +0,0 @@
1
- import * as crypto from 'crypto'
2
- import * as path from 'path'
3
- import * as fs from 'fs'
4
- import walk, {IIgnoreOptions} from './walk-directory'
5
-
6
- const ALGO = 'sha1';
7
- const ENCODING = 'base64';
8
-
9
- interface HashOptions {
10
- ignore: IIgnoreOptions
11
- }
12
-
13
- export interface HashResult {
14
- hash?: string
15
- children?: HashItem[]
16
- }
17
- export interface HashItem {
18
- hash: string,
19
- path: string,
20
- name: string
21
- }
22
-
23
- export function generateHash(folder: string, opt: HashOptions): string {
24
- const files = walk(folder, opt.ignore);
25
-
26
- const hash = crypto.createHash(ALGO);
27
- const children = files
28
- .sort((a, b) => a.fullpath().localeCompare(b.fullpath()))
29
- .map((child) => {
30
- const relPath = path.relative(process.cwd(), child.fullpath())
31
- const fileHash = crypto.createHash(ALGO);
32
- fileHash.update(relPath);
33
- fileHash.update(fs.readFileSync(child.fullpath()));
34
-
35
- const file = {
36
- name: child.name,
37
- path: relPath,
38
- hash: fileHash.digest(ENCODING)
39
- };
40
- hash.update(file.hash);
41
-
42
- return file;
43
- });
44
-
45
- return JSON.stringify({
46
- hash: hash.digest(ENCODING),
47
- children
48
- }, null, '\t')
49
- }
@@ -1,11 +0,0 @@
1
- import * as path from 'path'
2
-
3
- export const sourceRoot = path.resolve(process.cwd(), "../src");
4
- export const distributionRoot = path.resolve(process.cwd(), "../dist");
5
-
6
- export function getSourceDirectory(type: string, id: string): string {
7
- return path.join(sourceRoot, type, id)
8
- }
9
- export function getBuildDirectory(type: string, id: string): string {
10
- return path.join(distributionRoot, type, id)
11
- }
@@ -1,30 +0,0 @@
1
- import * as path from 'path'
2
- import * as fs from 'fs'
3
-
4
- export interface IIgnoreOptions {
5
- excluded?: (stat: fs.Dirent) => boolean,
6
- included?: (stat: fs.Dirent) => boolean,
7
- childrenExcluded?: (stat: fs.Dirent) => boolean,
8
- childrenIncluded?: (stat: fs.Dirent) => boolean
9
- }
10
- export const yes = () => true
11
- export const no = () => false
12
-
13
- export default function walkDirectory(directory: string, options: IIgnoreOptions, filepaths: DirentExtended[] = []): DirentExtended[] {
14
- const { excluded = no, included = yes, childrenExcluded = no, childrenIncluded = yes} = options;
15
- const files = fs.readdirSync(directory, {withFileTypes: true}) as unknown[] as DirentExtended[];
16
- for (let stats of files) {
17
- const filepath = path.join(directory, stats.name)
18
- stats.fullpath = () => filepath
19
- if (stats.isDirectory() && !childrenExcluded(stats) && childrenIncluded(stats)) {
20
- walkDirectory(filepath, options, filepaths)
21
- } else if (stats.isFile() && !excluded(stats) && included(stats)) {
22
- filepaths.push(stats)
23
- }
24
- }
25
- return filepaths;
26
- }
27
-
28
- export interface DirentExtended extends fs.Dirent {
29
- fullpath: () => string
30
- }