From c33eeb7e91acec33227bda87a809bdb0c8c5cf31 Mon Sep 17 00:00:00 2001 From: Kim T Date: Tue, 12 Nov 2024 21:49:11 -0800 Subject: [PATCH] Use core library shared methods --- package-lock.json | 9 +++++---- package.json | 2 +- src/index.ts | 26 +++----------------------- src/validate.ts | 41 +++++------------------------------------ 4 files changed, 14 insertions(+), 64 deletions(-) diff --git a/package-lock.json b/package-lock.json index 156a9cc..aa74d06 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.2", "license": "cc0-1.0", "dependencies": { - "@open-audio-stack/core": "^0.0.10", + "@open-audio-stack/core": "^0.0.13", "chalk": "^5.3.0" }, "devDependencies": { @@ -817,12 +817,13 @@ } }, "node_modules/@open-audio-stack/core": { - "version": "0.0.10", - "resolved": "https://registry.npmjs.org/@open-audio-stack/core/-/core-0.0.10.tgz", - "integrity": "sha512-3WdKgHSvAMk75pVPuACUbomGrGKNV0FGsrr6pXF4TsN28slvHHZ3HynuQpUL0M3qwba28PjcOo9tbIGeoC4URg==", + "version": "0.0.13", + "resolved": "https://registry.npmjs.org/@open-audio-stack/core/-/core-0.0.13.tgz", + "integrity": "sha512-wEwZC+ZGNRY5LO6651tBn3HSC8U6ZmVBjiDdyt8IjRhVbkYAu5WDRsS2j+cgA/LWWK1VNrVX3VMCGOcMmDdUCg==", "license": "cc0-1.0", "dependencies": { "adm-zip": "^0.5.16", + "chalk": "^5.3.0", "fs-extra": "^11.2.0", "glob": "^11.0.0", "js-yaml": "^4.1.0", diff --git a/package.json b/package.json index 1d583b3..83a01ad 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "vitest": "^2.1.4" }, "dependencies": { - "@open-audio-stack/core": "^0.0.10", + "@open-audio-stack/core": "^0.0.13", "chalk": "^5.3.0" }, "repository": { diff --git a/src/index.ts b/src/index.ts index 3089e7c..d6396b6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,9 @@ -import chalk from 'chalk'; import { dirCreate, dirRead, fileJsonCreate, fileReadYaml, + logReport, pathGetSlug, pathGetVersion, Config, @@ -48,30 +48,10 @@ export function generateYaml( const pkgSlug: string = pathGetSlug(subPath); const pkgVersion: string = pathGetVersion(subPath); const pkgFile = fileReadYaml(filePath) as PluginInterface | PresetInterface | ProjectInterface; + const errors: PackageValidationError[] = registry.packageVersionValidate(pkgFile); const recs: PackageValidationRec[] = registry.packageVersionRecommendations(pkgFile); - if (errors.length > 0) { - console.log(chalk.red(`X ${pkgSlug} | ${pkgVersion} | ${filePath}`)); - errors.forEach(error => { - console.log( - chalk.red( - `- ${error.field} (${error.error}) received '${error.valueReceived}' expected '${error.valueExpected}'`, - ), - ); - }); - if (recs.length > 0) { - recs.forEach(rec => { - console.log(chalk.yellow(`- ${rec.field} ${rec.rec}`)); - }); - } - } else { - console.log(chalk.green(`✓ ${pkgSlug} | ${pkgVersion} | ${filePath}`)); - if (recs.length > 0) { - recs.forEach(rec => { - console.log(chalk.yellow(`- ${rec.field} ${rec.rec}`)); - }); - } - } + logReport(`${pkgSlug} | ${pkgVersion} | ${filePath}`, errors, recs); registry.packageVersionAdd(pkgSlug, pkgVersion, pkgFile); dirCreate(`${pathOut}/${pathType}/${pkgSlug}/${pkgVersion}`); diff --git a/src/validate.ts b/src/validate.ts index 1fa32d9..36c1565 100644 --- a/src/validate.ts +++ b/src/validate.ts @@ -4,10 +4,9 @@ import { dirExists, fileCreate, fileExists, - fileHash, fileReadYaml, - fileSize, - PackageValidation, + fileValidateMetadata, + logReport, PackageValidationError, pathGetExt, pathGetSlug, @@ -17,7 +16,6 @@ import { PresetFile, ProjectFile, } from '@open-audio-stack/core'; -import chalk from 'chalk'; import path from 'path'; const DIR_DOWNLOADS: string = 'downloads'; @@ -49,37 +47,8 @@ if (ext === 'yaml') { fileCreate(fileLocalPath, fileBuffer); } - // Validate file vs metadata - const errors: PackageValidationError[] = []; - if (file.hash !== fileHash(fileLocalPath)) { - errors.push({ - field: 'hash', - error: PackageValidation.INVALID_VALUE, - valueExpected: fileHash(fileLocalPath), - valueReceived: file.hash, - }); - } - if (file.size !== fileSize(fileLocalPath)) { - errors.push({ - field: 'size', - error: PackageValidation.INVALID_VALUE, - valueExpected: String(fileSize(fileLocalPath)), - valueReceived: String(file.size), - }); - } - - // Output errors - if (errors.length > 0) { - console.log(chalk.red(`X ${pkgSlug} | ${pkgVersion} | ${fileLocalPath}`)); - errors.forEach(error => { - console.log( - chalk.red( - `- ${error.field} (${error.error}) received '${error.valueReceived}' expected '${error.valueExpected}'`, - ), - ); - }); - } else { - console.log(chalk.green(`✓ ${pkgSlug} | ${pkgVersion} | ${fileLocalPath}`)); - } + // Validate file vs metadata and output errors + const errors: PackageValidationError[] = fileValidateMetadata(fileLocalPath, file); + logReport(`${pkgSlug} | ${pkgVersion} | ${fileLocalPath}`, errors); } }