Skip to content

Commit

Permalink
Use core library shared methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kmturley committed Nov 13, 2024
1 parent 353b2b0 commit c33eeb7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 64 deletions.
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
26 changes: 3 additions & 23 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import chalk from 'chalk';
import {
dirCreate,
dirRead,
fileJsonCreate,
fileReadYaml,
logReport,
pathGetSlug,
pathGetVersion,
Config,
Expand Down Expand Up @@ -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}`);
Expand Down
41 changes: 5 additions & 36 deletions src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import {
dirExists,
fileCreate,
fileExists,
fileHash,
fileReadYaml,
fileSize,
PackageValidation,
fileValidateMetadata,
logReport,
PackageValidationError,
pathGetExt,
pathGetSlug,
Expand All @@ -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';
Expand Down Expand Up @@ -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);
}
}

0 comments on commit c33eeb7

Please sign in to comment.