@open-audio-stack/core
Version:
Open-source audio plugin management software
25 lines (24 loc) • 944 B
JavaScript
import path from 'path';
import { fileCreateJson, fileReadJson } from './file.js';
import { Package } from '../classes/Package.js';
import { log, pathGetSlug, pathGetVersion } from './utils.js';
export function packageLoadFile(filePath) {
// Read the file path and parse as json.
if (!filePath)
filePath = path.join('.', 'index.json');
const pkgFile = fileReadJson(filePath);
if (!pkgFile)
log(filePath, `not a valid json file`);
// Validate package json file structure, fields and values.
const pkg = new Package(pathGetSlug(filePath, path.sep));
pkg.addVersion(pathGetVersion(filePath, path.sep), pkgFile);
log(JSON.stringify(pkg.getReport()));
return pkgFile;
}
export function packageSaveFile(pkgFile, filePath) {
// Read the file path and parse as json.
if (!filePath)
filePath = path.join('.', 'index.json');
fileCreateJson(filePath, pkgFile);
return pkgFile;
}