@open-audio-stack/core 0.0.9 → 0.0.11
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.
- package/build/Registry.js +1 -1
- package/build/helpers/file.d.ts +5 -1
- package/build/helpers/file.js +25 -4
- package/build/helpers/utils.d.ts +4 -0
- package/build/helpers/utils.js +22 -0
- package/build/types/Package.d.ts +2 -2
- package/package.json +2 -1
package/build/Registry.js
CHANGED
package/build/helpers/file.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { PackageInterface } from '../types/Package.js';
|
|
2
|
+
import { PluginFile } from '../types/Plugin.js';
|
|
3
|
+
import { PresetFile } from '../types/Preset.js';
|
|
4
|
+
import { ProjectFile } from '../types/Project.js';
|
|
2
5
|
export declare function dirApp(): string;
|
|
3
6
|
export declare function dirCreate(dir: string): string | false;
|
|
4
7
|
export declare function dirDelete(dir: string): false | void;
|
|
@@ -22,10 +25,11 @@ export declare function fileJsonCreate(filePath: string, data: object): void;
|
|
|
22
25
|
export declare function fileHash(filePath: string, algorithm?: string): string;
|
|
23
26
|
export declare function fileMove(filePath: string, newPath: string): void | boolean;
|
|
24
27
|
export declare function fileOpen(filePath: string): Buffer;
|
|
25
|
-
export declare function fileRead(filePath: string):
|
|
28
|
+
export declare function fileRead(filePath: string): string;
|
|
26
29
|
export declare function fileReadJson(filePath: string): any;
|
|
27
30
|
export declare function fileReadString(filePath: string): string;
|
|
28
31
|
export declare function fileReadYaml(filePath: string): unknown;
|
|
29
32
|
export declare function fileSize(filePath: string): number;
|
|
33
|
+
export declare function fileValidateMetadata(filePath: string, fileMetadata: PluginFile | PresetFile | ProjectFile): void;
|
|
30
34
|
export declare function zipCreate(filesPath: string, zipPath: string): void;
|
|
31
35
|
export declare function zipExtract(content: any, dirPath: string): void;
|
package/build/helpers/file.js
CHANGED
|
@@ -7,6 +7,7 @@ import { moveSync } from 'fs-extra/esm';
|
|
|
7
7
|
import os from 'os';
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import yaml from 'js-yaml';
|
|
10
|
+
import { PackageValidation } from '../types/Package.js';
|
|
10
11
|
export function dirApp() {
|
|
11
12
|
if (process.platform === 'win32')
|
|
12
13
|
return process.env.APPDATA || os.homedir();
|
|
@@ -128,7 +129,8 @@ export function fileJsonCreate(filePath, data) {
|
|
|
128
129
|
}
|
|
129
130
|
export function fileHash(filePath, algorithm = 'sha256') {
|
|
130
131
|
const fileData = fileReadString(filePath);
|
|
131
|
-
|
|
132
|
+
const fileNormalized = fileData.replace(/\r\n/g, '\n');
|
|
133
|
+
return createHash(algorithm).update(fileNormalized, 'utf8').digest('hex');
|
|
132
134
|
}
|
|
133
135
|
export function fileMove(filePath, newPath) {
|
|
134
136
|
if (fileExists(filePath)) {
|
|
@@ -153,18 +155,18 @@ export function fileOpen(filePath) {
|
|
|
153
155
|
}
|
|
154
156
|
export function fileRead(filePath) {
|
|
155
157
|
console.log('⎋', filePath);
|
|
156
|
-
return readFileSync(filePath);
|
|
158
|
+
return readFileSync(filePath, 'utf8');
|
|
157
159
|
}
|
|
158
160
|
export function fileReadJson(filePath) {
|
|
159
161
|
if (fileExists(filePath)) {
|
|
160
162
|
console.log('⎋', filePath);
|
|
161
|
-
return JSON.parse(readFileSync(filePath).toString());
|
|
163
|
+
return JSON.parse(readFileSync(filePath, 'utf8').toString());
|
|
162
164
|
}
|
|
163
165
|
return false;
|
|
164
166
|
}
|
|
165
167
|
export function fileReadString(filePath) {
|
|
166
168
|
console.log('⎋', filePath);
|
|
167
|
-
return readFileSync(filePath).toString();
|
|
169
|
+
return readFileSync(filePath, 'utf8').toString();
|
|
168
170
|
}
|
|
169
171
|
export function fileReadYaml(filePath) {
|
|
170
172
|
const file = fileReadString(filePath);
|
|
@@ -173,6 +175,25 @@ export function fileReadYaml(filePath) {
|
|
|
173
175
|
export function fileSize(filePath) {
|
|
174
176
|
return statSync(filePath).size;
|
|
175
177
|
}
|
|
178
|
+
export function fileValidateMetadata(filePath, fileMetadata) {
|
|
179
|
+
const errors = [];
|
|
180
|
+
if (fileMetadata.hash !== fileHash(filePath)) {
|
|
181
|
+
errors.push({
|
|
182
|
+
field: 'hash',
|
|
183
|
+
error: PackageValidation.INVALID_VALUE,
|
|
184
|
+
valueExpected: fileHash(filePath),
|
|
185
|
+
valueReceived: fileMetadata.hash,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
if (fileMetadata.size !== fileSize(filePath)) {
|
|
189
|
+
errors.push({
|
|
190
|
+
field: 'size',
|
|
191
|
+
error: PackageValidation.INVALID_VALUE,
|
|
192
|
+
valueExpected: String(fileSize(filePath)),
|
|
193
|
+
valueReceived: String(fileMetadata.size),
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
176
197
|
export function zipCreate(filesPath, zipPath) {
|
|
177
198
|
if (fileExists(zipPath)) {
|
|
178
199
|
unlinkSync(zipPath);
|
package/build/helpers/utils.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { PackageValidationError, PackageValidationRec } from '../types/Package.js';
|
|
2
|
+
export declare function logReport(info: string, errors?: PackageValidationError[], recs?: PackageValidationRec[]): void;
|
|
3
|
+
export declare function logErrors(errors: PackageValidationError[]): void;
|
|
4
|
+
export declare function logRecommendations(recs: PackageValidationRec[]): void;
|
|
1
5
|
export declare function pathGetExt(path: string, sep?: string): string;
|
|
2
6
|
export declare function pathGetDirectory(path: string, sep?: string): string;
|
|
3
7
|
export declare function pathGetFilename(path: string, sep?: string): string;
|
package/build/helpers/utils.js
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
export function logReport(info, errors, recs) {
|
|
3
|
+
if (errors) {
|
|
4
|
+
console.log(chalk.red(`X ${info}`));
|
|
5
|
+
logErrors(errors);
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
console.log(chalk.green(`✓ ${info}`));
|
|
9
|
+
}
|
|
10
|
+
if (recs)
|
|
11
|
+
logRecommendations(recs);
|
|
12
|
+
}
|
|
13
|
+
export function logErrors(errors) {
|
|
14
|
+
errors.forEach(error => {
|
|
15
|
+
console.log(chalk.red(`- ${error.field} (${error.error}) received '${error.valueReceived}' expected '${error.valueExpected}'`));
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export function logRecommendations(recs) {
|
|
19
|
+
recs.forEach(rec => {
|
|
20
|
+
console.log(chalk.yellow(`- ${rec.field} ${rec.rec}`));
|
|
21
|
+
});
|
|
22
|
+
}
|
|
1
23
|
export function pathGetExt(path, sep = '.') {
|
|
2
24
|
return path.substring(path.lastIndexOf(sep) + 1);
|
|
3
25
|
}
|
package/build/types/Package.d.ts
CHANGED
|
@@ -35,8 +35,8 @@ export interface PackageValidationField {
|
|
|
35
35
|
export interface PackageValidationError {
|
|
36
36
|
field: string;
|
|
37
37
|
error: PackageValidation;
|
|
38
|
-
valueExpected: string;
|
|
39
|
-
valueReceived: string;
|
|
38
|
+
valueExpected: boolean | number | string;
|
|
39
|
+
valueReceived: boolean | number | string;
|
|
40
40
|
}
|
|
41
41
|
export interface PackageValidationRec {
|
|
42
42
|
field: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-audio-stack/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Open-source audio plugin management software",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./build/index.js",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"adm-zip": "^0.5.16",
|
|
55
|
+
"chalk": "^5.3.0",
|
|
55
56
|
"fs-extra": "^11.2.0",
|
|
56
57
|
"glob": "^11.0.0",
|
|
57
58
|
"js-yaml": "^4.1.0",
|