@easy-breezy/core
Advanced tools
Comparing version 2.0.16 to 2.0.17
import { dirname } from 'path'; | ||
import { existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'fs'; | ||
import { createHash } from 'crypto'; | ||
import output from './../output/index.js'; | ||
@@ -13,2 +14,12 @@ import i18n from './../i18n/index.js'; | ||
}; | ||
createSignature = (data) => { | ||
if (data) { | ||
const hash = createHash('sha256').update(data, 'utf8'); | ||
return hash.digest('hex'); | ||
} | ||
}; | ||
getSignature = (data) => { | ||
const result = /\/\/ Signature: ([a-z\d]+)$/gm.exec(data); | ||
return result?.[1]; | ||
}; | ||
getOperations = () => { | ||
@@ -27,9 +38,17 @@ return this.operations; | ||
}; | ||
createFile = (path, data) => { | ||
write = (path, data, sign = false) => { | ||
let payload = data; | ||
if (sign && !path.endsWith('.json')) { | ||
const signature = this.createSignature(data); | ||
payload = `// Signature: ${signature}\n${payload}`; | ||
} | ||
writeFileSync(path, payload, { | ||
encoding: 'utf8' | ||
}); | ||
}; | ||
createFile = (path, data, sign) => { | ||
const existsFile = this.exists(path); | ||
if (!existsFile) { | ||
this.createDir(path); | ||
writeFileSync(path, data, { | ||
encoding: 'utf8' | ||
}); | ||
this.write(path, data, sign); | ||
this.operations.created.push(path); | ||
@@ -40,9 +59,13 @@ output.info(i18n.t('core.fs.create.file', { path })); | ||
}; | ||
updateFile = (path, data) => { | ||
if (this.createFile(path, data)) { | ||
updateFile = (path, data, sign) => { | ||
if (this.createFile(path, data, sign)) { | ||
const file = this.readFile(path); | ||
if (file !== data) { | ||
writeFileSync(path, data, { | ||
encoding: 'utf8' | ||
}); | ||
if (sign) { | ||
const signature = this.createSignature(data); | ||
if (this.getSignature(file) === signature) { | ||
return; | ||
} | ||
} | ||
this.write(path, data, sign); | ||
this.operations.changed.push(path); | ||
@@ -49,0 +72,0 @@ output.info(i18n.t('core.fs.create.update', { path })); |
export declare class FS { | ||
private operations; | ||
private createSignature; | ||
private getSignature; | ||
getOperations: () => Record<"created" | "changed" | "removed" | "read" | "exists", string[]>; | ||
createDir: (path: string) => void; | ||
createFile: (path: string, data: string) => boolean; | ||
updateFile: (path: string, data: string) => void; | ||
private write; | ||
createFile: (path: string, data: string, sign?: boolean) => boolean; | ||
updateFile: (path: string, data: string, sign?: boolean) => void; | ||
readFile: (path: string) => string; | ||
@@ -8,0 +11,0 @@ exists: (path: string) => boolean; |
{ | ||
"name": "@easy-breezy/core", | ||
"version": "2.0.16", | ||
"version": "2.0.17", | ||
"main": "dist/index.js", | ||
@@ -49,3 +49,3 @@ "type": "module", | ||
"enquirer": "2.3.6", | ||
"i18next": "22.4.12", | ||
"i18next": "22.4.13", | ||
"lodash.get": "4.4.2", | ||
@@ -52,0 +52,0 @@ "lodash.setwith": "4.3.2" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24433
678
+ Addedi18next@22.4.13(transitive)
- Removedi18next@22.4.12(transitive)
Updatedi18next@22.4.13