@open-audio-stack/core 0.0.24 → 0.1.0

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.
Files changed (50) hide show
  1. package/README.md +18 -4
  2. package/build/classes/Config.d.ts +41 -0
  3. package/build/{Config.js → classes/Config.js} +16 -22
  4. package/build/classes/ConfigLocal.d.ts +10 -0
  5. package/build/classes/ConfigLocal.js +32 -0
  6. package/build/classes/Manager.d.ts +20 -0
  7. package/build/classes/Manager.js +85 -0
  8. package/build/classes/ManagerLocal.d.ts +11 -0
  9. package/build/classes/ManagerLocal.js +135 -0
  10. package/build/classes/Package.d.ts +13 -0
  11. package/build/classes/Package.js +50 -0
  12. package/build/classes/Registry.d.ts +14 -0
  13. package/build/classes/Registry.js +37 -0
  14. package/build/helpers/admin.d.ts +9 -0
  15. package/build/helpers/admin.js +28 -0
  16. package/build/helpers/config.d.ts +2 -0
  17. package/build/helpers/config.js +11 -0
  18. package/build/helpers/configLocal.d.ts +2 -0
  19. package/build/helpers/configLocal.js +11 -0
  20. package/build/helpers/file.d.ts +9 -3
  21. package/build/helpers/file.js +117 -29
  22. package/build/helpers/package.d.ts +25 -23
  23. package/build/helpers/package.js +17 -1
  24. package/build/helpers/registry.d.ts +2 -0
  25. package/build/helpers/registry.js +10 -0
  26. package/build/helpers/utils.d.ts +11 -1
  27. package/build/helpers/utils.js +53 -3
  28. package/build/index-browser.d.ts +6 -3
  29. package/build/index-browser.js +10 -3
  30. package/build/index.d.ts +9 -3
  31. package/build/index.js +10 -3
  32. package/build/types/Config.d.ts +5 -3
  33. package/build/types/Package.d.ts +4 -8
  34. package/build/types/Package.js +1 -6
  35. package/build/types/Plugin.d.ts +2 -2
  36. package/build/types/PluginFormat.d.ts +5 -1
  37. package/build/types/PluginFormat.js +23 -6
  38. package/build/types/Preset.d.ts +2 -2
  39. package/build/types/PresetFormat.d.ts +5 -1
  40. package/build/types/PresetFormat.js +15 -1
  41. package/build/types/Project.d.ts +2 -2
  42. package/build/types/ProjectFormat.d.ts +4 -0
  43. package/build/types/ProjectFormat.js +14 -0
  44. package/build/types/Registry.d.ts +3 -3
  45. package/package.json +6 -2
  46. package/build/Config.d.ts +0 -40
  47. package/build/Manager.d.ts +0 -26
  48. package/build/Manager.js +0 -64
  49. package/build/Registry.d.ts +0 -21
  50. package/build/Registry.js +0 -102
package/README.md CHANGED
@@ -3,13 +3,27 @@
3
3
  ![Test](https://github.com/open-audio-stack/open-audio-stack-core/workflows/Test/badge.svg)
4
4
  ![Release](https://github.com/open-audio-stack/open-audio-stack-core/workflows/Release/badge.svg)
5
5
 
6
- Common methods package shared across Open Audio Stack compatible registries, command-line tools, apps and websites for handling installing DAW VST plugin dependencies.
6
+ Common package shared across Open Audio Stack compatible registries, command-line tools, apps and websites for handling installing DAW VST plugin dependencies.
7
7
 
8
8
  ## Features
9
9
 
10
- - Config - Get types, formats, values, paths and urls.
11
- - FileSystem - Perform operations on directories and files.
12
- - Registry - Create an audio registry with packages and files.
10
+ High-level classes enable use without writing business-logic:
11
+
12
+ - Config - Set and get common configuration types, formats, values, paths and urls.
13
+ - ConfigLocal - All the Config functionality including ability to load and save configuration to a json file.
14
+ - Manager - Search, filter and get packages from a registry.
15
+ - ManagerLocal - Install/uninstall packages locally and scan directories for existing packages.
16
+ - Package - Create a new package to add to a registry.
17
+ - Registry - Create an audio package registry with packages and files.
18
+
19
+ Low-level methods/utilities for more custom/advanced implementations:
20
+
21
+ - api - get different types of data using web requests
22
+ - config - default config options
23
+ - file - directory and file helper functions
24
+ - package - validation and recommendation functions
25
+ - registry - default registry config
26
+ - utils - various other utilities
13
27
 
14
28
  ## Installation
15
29
 
@@ -0,0 +1,41 @@
1
+ import { Architecture } from '../types/Architecture.js';
2
+ import { ConfigInterface } from '../types/Config.js';
3
+ import { FileFormat } from '../types/FileFormat.js';
4
+ import { FileType } from '../types/FileType.js';
5
+ import { License } from '../types/License.js';
6
+ import { PluginFormat } from '../types/PluginFormat.js';
7
+ import { PluginType } from '../types/PluginType.js';
8
+ import { PresetFormat } from '../types/PresetFormat.js';
9
+ import { PresetType } from '../types/PresetType.js';
10
+ import { ProjectFormat } from '../types/ProjectFormat.js';
11
+ import { ProjectType } from '../types/ProjectType.js';
12
+ import { SystemType } from '../types/SystemType.js';
13
+ export declare class Config {
14
+ config: ConfigInterface;
15
+ constructor(config?: ConfigInterface);
16
+ get(key: keyof ConfigInterface): string | import("../types/Config.js").ConfigRegistry[] | undefined;
17
+ getAll(): ConfigInterface;
18
+ set(key: keyof ConfigInterface, val: any): void;
19
+ architecture(type: Architecture): import("../types/Architecture.js").ArchitectureOption;
20
+ architectures(): import("../types/Architecture.js").ArchitectureOption[];
21
+ fileFormat(format: FileFormat): import("../types/FileFormat.js").FileFormatOption;
22
+ fileFormats(): import("../types/FileFormat.js").FileFormatOption[];
23
+ fileType(type: FileType): import("../types/FileType.js").FileTypeOption;
24
+ fileTypes(): import("../types/FileType.js").FileTypeOption[];
25
+ license(type: License): import("../types/License.js").LicenseOption;
26
+ licenses(): import("../types/License.js").LicenseOption[];
27
+ pluginFormat(format: PluginFormat): import("../types/PluginFormat.js").PluginFormatOption;
28
+ pluginFormats(): import("../types/PluginFormat.js").PluginFormatOption[];
29
+ pluginType(type: PluginType): import("../types/PluginType.js").PluginTypeOption;
30
+ pluginTypes(): import("../types/PluginType.js").PluginTypeOption[];
31
+ presetFormat(format: PresetFormat): import("../types/PresetFormat.js").PresetFormatOption;
32
+ presetFormats(): import("../types/PresetFormat.js").PresetFormatOption[];
33
+ presetType(type: PresetType): import("../types/PresetType.js").PresetTypeOption;
34
+ presetTypes(): import("../types/PresetType.js").PresetTypeOption[];
35
+ projectFormat(format: ProjectFormat): import("../types/ProjectFormat.js").ProjectFormatOption;
36
+ projectFormats(): import("../types/ProjectFormat.js").ProjectFormatOption[];
37
+ projectType(type: ProjectType): import("../types/ProjectType.js").ProjectTypeOption;
38
+ projectTypes(): import("../types/ProjectType.js").ProjectTypeOption[];
39
+ system(type: SystemType): import("../types/SystemType.js").SystemTypeOption;
40
+ systems(): import("../types/SystemType.js").SystemTypeOption[];
41
+ }
@@ -1,34 +1,28 @@
1
- import { architectures } from './types/Architecture.js';
2
- import { fileFormats } from './types/FileFormat.js';
3
- import { fileTypes } from './types/FileType.js';
4
- import { licenses } from './types/License.js';
5
- import { pluginFormats } from './types/PluginFormat.js';
6
- import { pluginTypes } from './types/PluginType.js';
7
- import { presetFormats } from './types/PresetFormat.js';
8
- import { presetTypes } from './types/PresetType.js';
9
- import { projectFormats } from './types/ProjectFormat.js';
10
- import { projectTypes } from './types/ProjectType.js';
11
- import { systemTypes } from './types/SystemType.js';
1
+ import { architectures } from '../types/Architecture.js';
2
+ import { configDefaults } from '../helpers/config.js';
3
+ import { fileFormats } from '../types/FileFormat.js';
4
+ import { fileTypes } from '../types/FileType.js';
5
+ import { licenses } from '../types/License.js';
6
+ import { pluginFormats } from '../types/PluginFormat.js';
7
+ import { pluginTypes } from '../types/PluginType.js';
8
+ import { presetFormats } from '../types/PresetFormat.js';
9
+ import { presetTypes } from '../types/PresetType.js';
10
+ import { projectFormats } from '../types/ProjectFormat.js';
11
+ import { projectTypes } from '../types/ProjectType.js';
12
+ import { systemTypes } from '../types/SystemType.js';
12
13
  export class Config {
13
14
  config;
14
15
  constructor(config) {
15
- this.config = Object.assign({
16
- registries: [
17
- {
18
- name: 'Open Audio Registry',
19
- url: 'https://open-audio-stack.github.io/open-audio-stack-registry',
20
- },
21
- ],
22
- }, config);
16
+ this.config = { ...configDefaults(), ...config };
23
17
  }
24
18
  get(key) {
25
- if (key)
26
- return this.config[key];
19
+ return this.config[key];
20
+ }
21
+ getAll() {
27
22
  return this.config;
28
23
  }
29
24
  set(key, val) {
30
25
  this.config[key] = val;
31
- return this.get(key);
32
26
  }
33
27
  // Architectures.
34
28
  architecture(type) {
@@ -0,0 +1,10 @@
1
+ import { Config } from './Config.js';
2
+ import { ConfigInterface } from '../types/Config.js';
3
+ export declare class ConfigLocal extends Config {
4
+ path: string;
5
+ constructor(configPath: string, config?: ConfigInterface);
6
+ delete(): boolean | void;
7
+ load(): ConfigInterface;
8
+ save(): void;
9
+ set(key: keyof ConfigInterface, val: any): void;
10
+ }
@@ -0,0 +1,32 @@
1
+ import path from 'path';
2
+ import { Config } from './Config.js';
3
+ import { dirCreate, fileCreateJson, fileDelete, fileExists, fileReadJson } from '../helpers/file.js';
4
+ import { configDefaultsLocal } from '../helpers/configLocal.js';
5
+ export class ConfigLocal extends Config {
6
+ path;
7
+ constructor(configPath, config) {
8
+ super(config);
9
+ this.config = { ...configDefaultsLocal(), ...config };
10
+ this.path = configPath;
11
+ if (fileExists(this.path)) {
12
+ this.config = { ...this.config, ...this.load() };
13
+ }
14
+ else {
15
+ this.save();
16
+ }
17
+ }
18
+ delete() {
19
+ return fileDelete(this.path);
20
+ }
21
+ load() {
22
+ return fileReadJson(this.path);
23
+ }
24
+ save() {
25
+ dirCreate(path.dirname(this.path));
26
+ return fileCreateJson(this.path, this.getAll());
27
+ }
28
+ set(key, val) {
29
+ super.set(key, val);
30
+ this.save();
31
+ }
32
+ }
@@ -0,0 +1,20 @@
1
+ import { Config } from './Config.js';
2
+ import { ConfigInterface } from '../types/Config.js';
3
+ import { Package } from './Package.js';
4
+ import { PackageVersion } from '../types/Package.js';
5
+ import { RegistryPackages, RegistryType } from '../types/Registry.js';
6
+ export declare class Manager {
7
+ protected config: Config;
8
+ protected packages: Map<string, Package>;
9
+ type: RegistryType;
10
+ constructor(type: RegistryType, config?: ConfigInterface);
11
+ addPackage(pkg: Package): void;
12
+ filter(query: string | number | object, field: keyof PackageVersion): Package[];
13
+ getPackage(slug: string): Package | undefined;
14
+ listPackages(): Package[];
15
+ removePackage(slug: string): void;
16
+ reset(): void;
17
+ search(query: string): Package[];
18
+ sync(): Promise<void>;
19
+ toJSON(): RegistryPackages;
20
+ }
@@ -0,0 +1,85 @@
1
+ import { apiJson } from '../helpers/api.js';
2
+ import { Config } from './Config.js';
3
+ import { Package } from './Package.js';
4
+ export class Manager {
5
+ config;
6
+ packages;
7
+ type;
8
+ constructor(type, config) {
9
+ this.config = new Config(config);
10
+ this.packages = new Map();
11
+ this.type = type;
12
+ }
13
+ addPackage(pkg) {
14
+ const pkgExisting = this.packages.get(pkg.slug);
15
+ if (pkgExisting) {
16
+ for (const [version, pkgVersion] of pkg.versions) {
17
+ pkgExisting.addVersion(version, pkgVersion);
18
+ }
19
+ }
20
+ else {
21
+ this.packages.set(pkg.slug, pkg);
22
+ }
23
+ }
24
+ filter(query, field) {
25
+ const results = [];
26
+ for (const [, pkg] of this.packages) {
27
+ const pkgVersion = pkg.getVersionLatest();
28
+ if (!pkgVersion)
29
+ continue;
30
+ if (pkgVersion[field] === query) {
31
+ results.push(pkg);
32
+ }
33
+ }
34
+ return results;
35
+ }
36
+ getPackage(slug) {
37
+ return this.packages.get(slug);
38
+ }
39
+ listPackages() {
40
+ return Array.from(this.packages.values());
41
+ }
42
+ removePackage(slug) {
43
+ if (!this.packages.has(slug))
44
+ return;
45
+ this.packages.delete(slug);
46
+ }
47
+ reset() {
48
+ this.packages.clear();
49
+ }
50
+ search(query) {
51
+ const queryLower = query.trim().toLowerCase();
52
+ const results = [];
53
+ for (const [slug, pkg] of this.packages) {
54
+ const pkgVersion = pkg.getVersionLatest();
55
+ if (!pkgVersion)
56
+ continue;
57
+ const pkgTags = pkgVersion.tags.map((str) => str.trim().toLowerCase());
58
+ if (slug.indexOf(queryLower) !== -1 ||
59
+ pkgVersion.name.trim().toLowerCase().indexOf(queryLower) !== -1 ||
60
+ pkgVersion.description.trim().toLowerCase().indexOf(queryLower) !== -1 ||
61
+ pkgTags.includes(queryLower)) {
62
+ results.push(pkg);
63
+ }
64
+ }
65
+ return results;
66
+ }
67
+ async sync() {
68
+ const registries = this.config.get('registries');
69
+ for (const index in registries) {
70
+ const json = await apiJson(registries[index].url);
71
+ const type = this.type;
72
+ for (const slug in json[type]) {
73
+ const pkg = new Package(slug, json[type][slug].versions);
74
+ this.addPackage(pkg);
75
+ }
76
+ }
77
+ }
78
+ toJSON() {
79
+ const data = {};
80
+ for (const [slug, pkg] of this.packages.entries()) {
81
+ data[slug] = pkg.toJSON();
82
+ }
83
+ return data;
84
+ }
85
+ }
@@ -0,0 +1,11 @@
1
+ import { PackageVersion } from '../types/Package.js';
2
+ import { Manager } from './Manager.js';
3
+ import { RegistryType } from '../types/Registry.js';
4
+ import { ConfigInterface } from '../types/Config.js';
5
+ export declare class ManagerLocal extends Manager {
6
+ protected typeDir: string;
7
+ constructor(type: RegistryType, config: ConfigInterface);
8
+ scan(): void;
9
+ install(slug: string, version?: string): Promise<void | PackageVersion>;
10
+ uninstall(slug: string, version?: string): Promise<void | PackageVersion>;
11
+ }
@@ -0,0 +1,135 @@
1
+ import path from 'path';
2
+ import { Package } from './Package.js';
3
+ import { Manager } from './Manager.js';
4
+ import { archiveExtract, dirCreate, dirDelete, dirEmpty, dirRead, fileCreate, fileCreateJson, fileExists, fileHash, fileOpen, fileReadJson, filesMove, isAdmin, runCliAsAdmin, } from '../helpers/file.js';
5
+ import { isTests, pathGetSlug, pathGetVersion } from '../helpers/utils.js';
6
+ import { apiBuffer } from '../helpers/api.js';
7
+ import { FileType } from '../types/FileType.js';
8
+ import { RegistryType } from '../types/Registry.js';
9
+ import { pluginFormatDir } from '../types/PluginFormat.js';
10
+ import { ConfigLocal } from './ConfigLocal.js';
11
+ import { packageCompatibleFiles } from '../helpers/package.js';
12
+ import { presetFormatDir } from '../types/PresetFormat.js';
13
+ import { projectFormatDir } from '../types/ProjectFormat.js';
14
+ export class ManagerLocal extends Manager {
15
+ typeDir;
16
+ constructor(type, config) {
17
+ super(type, config);
18
+ const configPath = path.join(config.appDir || '', 'config.json');
19
+ this.config = new ConfigLocal(configPath, config);
20
+ this.typeDir = this.config.get(`${type}Dir`);
21
+ }
22
+ scan() {
23
+ const filePaths = dirRead(`${this.typeDir}/**/index.json`);
24
+ filePaths.forEach((filePath) => {
25
+ const subPath = filePath.replace(`${this.typeDir}/`, '');
26
+ const pkgJson = fileReadJson(filePath);
27
+ pkgJson.installed = true;
28
+ const pkg = new Package(pathGetSlug(subPath));
29
+ pkg.addVersion(pathGetVersion(subPath), pkgJson);
30
+ this.addPackage(pkg);
31
+ });
32
+ }
33
+ async install(slug, version) {
34
+ // Get package information from registry.
35
+ const pkg = this.getPackage(slug);
36
+ if (!pkg)
37
+ return console.error(`Package ${slug} not found in registry`);
38
+ const versionNum = version || pkg.latestVersion();
39
+ const pkgVersion = pkg?.getVersion(versionNum);
40
+ if (!pkgVersion)
41
+ return console.error(`Package ${slug} version ${versionNum} not found in registry`);
42
+ if (pkgVersion.installed)
43
+ return pkgVersion;
44
+ // Elevate permissions if not running as admin.
45
+ if (!isAdmin() && !isTests()) {
46
+ let command = `--operation install --type ${this.type} --slug ${slug}`;
47
+ if (version)
48
+ command += ` --ver ${version}`;
49
+ await runCliAsAdmin(command);
50
+ return this.getPackage(slug)?.getVersion(versionNum);
51
+ }
52
+ // Create temporary directory to store downloaded files.
53
+ const dirDownloads = path.join(this.config.get('appDir'), 'downloads', this.type, slug, versionNum);
54
+ dirCreate(dirDownloads);
55
+ // Filter for compatible files and download.
56
+ const files = packageCompatibleFiles(pkgVersion);
57
+ if (!files.length)
58
+ return console.error(`Error: No compatible files found for ${slug}`);
59
+ for (const key in files) {
60
+ // Download file to temporary directory if not already downloaded.
61
+ const file = files[key];
62
+ const filePath = path.join(dirDownloads, path.basename(file.url));
63
+ if (!fileExists(filePath)) {
64
+ const fileBuffer = await apiBuffer(file.url);
65
+ fileCreate(filePath, Buffer.from(fileBuffer));
66
+ }
67
+ // Check file hash matches expected hash.
68
+ const hash = await fileHash(filePath);
69
+ if (hash !== file.sha256)
70
+ return console.error(`Error: ${filePath} hash mismatch`);
71
+ // If installer, run the installer.
72
+ if (file.type === FileType.Installer) {
73
+ fileOpen(filePath);
74
+ }
75
+ // If archive, extract the archive to temporary directory, then move individual files.
76
+ if (file.type === FileType.Archive) {
77
+ const dirSource = path.join(this.config.get('appDir'), file.type, this.type, slug, versionNum);
78
+ const dirSub = path.join(slug, versionNum);
79
+ let formatDir = pluginFormatDir;
80
+ if (this.type === RegistryType.Presets)
81
+ formatDir = presetFormatDir;
82
+ if (this.type === RegistryType.Projects)
83
+ formatDir = projectFormatDir;
84
+ archiveExtract(filePath, dirSource);
85
+ const filesMoved = filesMove(dirSource, this.typeDir, dirSub, formatDir);
86
+ // Output json metadata into every directory a file was added to.
87
+ filesMoved.forEach((fileMoved) => {
88
+ const fileJson = path.join(path.dirname(fileMoved), 'index.json');
89
+ fileCreateJson(fileJson, pkgVersion);
90
+ });
91
+ }
92
+ }
93
+ pkgVersion.installed = true;
94
+ return pkgVersion;
95
+ }
96
+ async uninstall(slug, version) {
97
+ // Get package information from registry.
98
+ const pkg = this.getPackage(slug);
99
+ if (!pkg)
100
+ return console.error(`Package ${slug} not found in registry`);
101
+ const versionNum = version || pkg.latestVersion();
102
+ const pkgVersion = pkg?.getVersion(versionNum);
103
+ if (!pkgVersion)
104
+ return console.error(`Package ${slug} version ${versionNum} not found in registry`);
105
+ if (!pkgVersion.installed)
106
+ return console.error(`Package ${slug} version ${versionNum} not installed`);
107
+ // Elevate permissions if not running as admin.
108
+ if (!isAdmin() && !isTests()) {
109
+ let command = `--operation uninstall --type ${this.type} --slug ${slug}`;
110
+ if (version)
111
+ command += ` --ver ${version}`;
112
+ await runCliAsAdmin(command);
113
+ return this.getPackage(slug)?.getVersion(versionNum);
114
+ }
115
+ // Delete all directories for this package version.
116
+ const versionDirs = dirRead(`${this.typeDir}/**/${slug}/${versionNum}`);
117
+ versionDirs.forEach((versionDir) => {
118
+ dirDelete(versionDir);
119
+ });
120
+ // Delete all empty directories for this package.
121
+ const pkgDirs = dirRead(`${this.typeDir}/**/${slug}`);
122
+ pkgDirs.forEach((pkgDir) => {
123
+ if (dirEmpty(pkgDir))
124
+ dirDelete(pkgDir);
125
+ });
126
+ // Delete all empty directories for the org.
127
+ const orgDirs = dirRead(`${this.typeDir}/**/${slug.split('/')[0]}`);
128
+ orgDirs.forEach((orgDir) => {
129
+ if (dirEmpty(orgDir))
130
+ dirDelete(orgDir);
131
+ });
132
+ delete pkgVersion.installed;
133
+ return this.getPackage(slug)?.getVersion(versionNum);
134
+ }
135
+ }
@@ -0,0 +1,13 @@
1
+ import { PackageInterface, PackageVersion, PackageVersions } from '../types/Package.js';
2
+ export declare class Package {
3
+ slug: string;
4
+ version: string;
5
+ versions: Map<string, PackageVersion>;
6
+ constructor(slug: string, versions?: PackageVersions);
7
+ addVersion(version: string, details: PackageVersion): void;
8
+ removeVersion(version: string): void;
9
+ getVersion(version: string): PackageVersion | undefined;
10
+ getVersionLatest(): PackageVersion | undefined;
11
+ latestVersion(): string;
12
+ toJSON(): PackageInterface;
13
+ }
@@ -0,0 +1,50 @@
1
+ import * as semver from 'semver';
2
+ import { PackageVersionValidator } from '../helpers/package.js';
3
+ import { isValidSlug } from '../helpers/utils.js';
4
+ export class Package {
5
+ slug;
6
+ version;
7
+ versions;
8
+ constructor(slug, versions) {
9
+ if (!isValidSlug(slug))
10
+ console.error('Invalid package slug', slug);
11
+ this.slug = slug;
12
+ this.versions = versions ? new Map(Object.entries(versions)) : new Map();
13
+ this.version = this.latestVersion();
14
+ }
15
+ addVersion(version, details) {
16
+ if (this.versions.has(version))
17
+ return;
18
+ const validationError = PackageVersionValidator.safeParse(details).error;
19
+ if (validationError)
20
+ return console.error('Invalid package version', validationError.issues);
21
+ this.versions.set(version, details);
22
+ this.version = this.latestVersion();
23
+ }
24
+ removeVersion(version) {
25
+ if (!this.versions.has(version))
26
+ return;
27
+ this.versions.delete(version);
28
+ this.version = this.latestVersion();
29
+ }
30
+ getVersion(version) {
31
+ return this.versions.get(version);
32
+ }
33
+ getVersionLatest() {
34
+ return this.versions.get(this.latestVersion());
35
+ }
36
+ latestVersion() {
37
+ return Array.from(this.versions.keys()).sort(semver.rcompare)[0] || '0.0.0';
38
+ }
39
+ toJSON() {
40
+ const data = {
41
+ slug: this.slug,
42
+ version: this.version,
43
+ versions: {},
44
+ };
45
+ this.versions.forEach((details, version) => {
46
+ data.versions[version] = details;
47
+ });
48
+ return data;
49
+ }
50
+ }
@@ -0,0 +1,14 @@
1
+ import { Manager } from './Manager.js';
2
+ import { RegistryInterface, RegistryType } from '../types/Registry.js';
3
+ export declare class Registry {
4
+ name: string;
5
+ url: string;
6
+ version: string;
7
+ private managers;
8
+ constructor(name: string, url: string, version: string);
9
+ addManager(manager: Manager): void;
10
+ getManager(type: RegistryType): Manager;
11
+ reset(): void;
12
+ sync(): Promise<void>;
13
+ toJSON(): RegistryInterface;
14
+ }
@@ -0,0 +1,37 @@
1
+ export class Registry {
2
+ name;
3
+ url;
4
+ version;
5
+ managers;
6
+ constructor(name, url, version) {
7
+ this.name = name;
8
+ this.url = url;
9
+ this.version = version;
10
+ this.managers = {};
11
+ }
12
+ addManager(manager) {
13
+ this.managers[manager.type] = manager;
14
+ }
15
+ getManager(type) {
16
+ return this.managers[type];
17
+ }
18
+ reset() {
19
+ Object.values(this.managers).forEach(manager => manager.reset());
20
+ }
21
+ async sync() {
22
+ for (const [, manager] of Object.entries(this.managers)) {
23
+ await manager.sync();
24
+ }
25
+ }
26
+ toJSON() {
27
+ const data = {
28
+ name: this.name,
29
+ url: this.url,
30
+ version: this.version,
31
+ };
32
+ for (const [type, manager] of Object.entries(this.managers)) {
33
+ data[type] = manager.toJSON();
34
+ }
35
+ return data;
36
+ }
37
+ }
@@ -0,0 +1,9 @@
1
+ import { RegistryType } from '../types/Registry.js';
2
+ export interface Arguments {
3
+ operation: string;
4
+ type: RegistryType;
5
+ id: string;
6
+ ver: string;
7
+ }
8
+ export declare function adminArguments(): Arguments;
9
+ export declare function adminInit(): Promise<void>;
@@ -0,0 +1,28 @@
1
+ // Run when Electron needs elevated privileges
2
+ // npm run build && node ./build/helpers/admin.js --operation install --type plugins --id surge-synthesizer/surge
3
+ // npm run build && node ./build/helpers/admin.js --operation uninstall --type plugins --id surge-synthesizer/surge
4
+ import { ManagerLocal } from '../classes/ManagerLocal.js';
5
+ import { dirApp } from './file.js';
6
+ export function adminArguments() {
7
+ return {
8
+ operation: process.argv[3],
9
+ type: process.argv[5],
10
+ id: process.argv[7],
11
+ ver: process.argv[9],
12
+ };
13
+ }
14
+ export async function adminInit() {
15
+ const argv = adminArguments();
16
+ const manager = new ManagerLocal(argv.type, { appDir: dirApp() });
17
+ manager.sync();
18
+ if (argv.operation === 'install') {
19
+ await manager.install(argv.id, argv.ver);
20
+ }
21
+ else if (argv.operation === 'uninstall') {
22
+ await manager.uninstall(argv.id, argv.ver);
23
+ }
24
+ else {
25
+ console.log('Missing --operation argument');
26
+ }
27
+ }
28
+ adminInit();
@@ -0,0 +1,2 @@
1
+ import { ConfigInterface } from '../types/Config.js';
2
+ export declare function configDefaults(): ConfigInterface;
@@ -0,0 +1,11 @@
1
+ export function configDefaults() {
2
+ return {
3
+ registries: [
4
+ {
5
+ name: 'Open Audio Registry',
6
+ url: 'https://open-audio-stack.github.io/open-audio-stack-registry',
7
+ },
8
+ ],
9
+ version: '1.0.0',
10
+ };
11
+ }
@@ -0,0 +1,2 @@
1
+ import { ConfigInterface } from '../types/Config.js';
2
+ export declare function configDefaultsLocal(): ConfigInterface;
@@ -0,0 +1,11 @@
1
+ import { configDefaults } from './config.js';
2
+ import { dirApp, dirPlugins, dirPresets, dirProjects } from './file.js';
3
+ export function configDefaultsLocal() {
4
+ return {
5
+ ...configDefaults(),
6
+ appDir: dirApp(),
7
+ pluginsDir: dirPlugins(),
8
+ presetsDir: dirPresets(),
9
+ projectsDir: dirProjects(),
10
+ };
11
+ }
@@ -3,7 +3,10 @@ import { PluginFile } from '../types/Plugin.js';
3
3
  import { PresetFile } from '../types/Preset.js';
4
4
  import { ProjectFile } from '../types/Project.js';
5
5
  import { ZodIssue } from 'zod';
6
- export declare function dirApp(): string;
6
+ import { SystemType } from '../types/SystemType.js';
7
+ export declare function archiveExtract(filePath: string, dirPath: string): Promise<void>;
8
+ export declare function dirApp(dirName?: string): string;
9
+ export declare function dirContains(parentDir: string, childDir: string): boolean;
7
10
  export declare function dirCreate(dir: string): string | false;
8
11
  export declare function dirDelete(dir: string): false | void;
9
12
  export declare function dirEmpty(dir: string): boolean;
@@ -18,19 +21,22 @@ export declare function dirProjects(): string;
18
21
  export declare function dirRead(dir: string, options?: any): string[];
19
22
  export declare function dirRename(dir: string, dirNew: string): void | boolean;
20
23
  export declare function fileCreate(filePath: string, data: string | Buffer): void;
24
+ export declare function fileCreateJson(filePath: string, data: object): void;
21
25
  export declare function fileDate(filePath: string): Date;
22
26
  export declare function fileDelete(filePath: string): boolean | void;
23
27
  export declare function fileExec(filePath: string): void;
24
28
  export declare function fileExists(filePath: string): boolean;
25
- export declare function fileJsonCreate(filePath: string, data: object): void;
26
29
  export declare function fileHash(filePath: string, algorithm?: string): Promise<string>;
27
30
  export declare function fileMove(filePath: string, newPath: string): void | boolean;
31
+ export declare function filesMove(dirSource: string, dirTarget: string, dirSub: string, formatDir: Record<string, string>): string[];
28
32
  export declare function fileOpen(filePath: string): Buffer;
29
33
  export declare function fileRead(filePath: string): string;
30
34
  export declare function fileReadJson(filePath: string): any;
31
35
  export declare function fileReadString(filePath: string): string;
32
36
  export declare function fileReadYaml(filePath: string): unknown;
33
37
  export declare function fileSize(filePath: string): number;
38
+ export declare function isAdmin(): boolean;
34
39
  export declare function fileValidateMetadata(filePath: string, fileMetadata: PluginFile | PresetFile | ProjectFile): Promise<ZodIssue[]>;
40
+ export declare function getPlatform(): SystemType;
41
+ export declare function runCliAsAdmin(args: string): Promise<string>;
35
42
  export declare function zipCreate(filesPath: string, zipPath: string): void;
36
- export declare function zipExtract(content: any, dirPath: string): void;