@open-audio-stack/core 0.1.23 → 0.1.25
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Package } from './Package.js';
|
|
1
2
|
import { PackageVersion } from '../types/Package.js';
|
|
2
3
|
import { Manager } from './Manager.js';
|
|
3
4
|
import { RegistryType } from '../types/Registry.js';
|
|
@@ -9,6 +10,7 @@ export declare class ManagerLocal extends Manager {
|
|
|
9
10
|
scan(ext?: string, installable?: boolean): void;
|
|
10
11
|
export(dir: string, ext?: string): boolean;
|
|
11
12
|
install(slug: string, version?: string): Promise<void | PackageVersion>;
|
|
13
|
+
installAll(): Promise<Package[]>;
|
|
12
14
|
installDependency(slug: string, version?: string, filePath?: string, type?: RegistryType): Promise<any>;
|
|
13
15
|
installDependencies(filePath?: string, type?: RegistryType): Promise<any>;
|
|
14
16
|
open(filePath?: string): void;
|
|
@@ -112,18 +112,18 @@ export class ManagerLocal extends Manager {
|
|
|
112
112
|
this.addPackage(pkg);
|
|
113
113
|
}
|
|
114
114
|
scan(ext = 'json', installable = true) {
|
|
115
|
-
const filePaths = dirRead(
|
|
115
|
+
const filePaths = dirRead(path.join(this.typeDir, '**', `index.${ext}`));
|
|
116
116
|
filePaths.forEach((filePath) => {
|
|
117
|
-
let subPath = filePath.replace(`${this.typeDir}
|
|
117
|
+
let subPath = filePath.replace(`${this.typeDir}` + path.sep, '');
|
|
118
118
|
// TODO improve this code.
|
|
119
|
-
const parts = subPath.split(
|
|
119
|
+
const parts = subPath.split(path.sep);
|
|
120
120
|
parts.shift();
|
|
121
|
-
subPath = parts.join(
|
|
121
|
+
subPath = parts.join(path.sep);
|
|
122
122
|
const pkgJson = ext === 'yaml' ? fileReadYaml(filePath) : fileReadJson(filePath);
|
|
123
123
|
if (installable)
|
|
124
124
|
pkgJson.installed = true;
|
|
125
|
-
const pkg = new Package(pathGetSlug(subPath));
|
|
126
|
-
const version = pathGetVersion(subPath);
|
|
125
|
+
const pkg = new Package(pathGetSlug(subPath, path.sep));
|
|
126
|
+
const version = pathGetVersion(subPath, path.sep);
|
|
127
127
|
pkg.addVersion(version, pkgJson);
|
|
128
128
|
this.addPackage(pkg);
|
|
129
129
|
});
|
|
@@ -212,6 +212,12 @@ export class ManagerLocal extends Manager {
|
|
|
212
212
|
fileOpen(filePath);
|
|
213
213
|
else
|
|
214
214
|
fileInstall(filePath);
|
|
215
|
+
// Currently we don't get a list of paths from the installer.
|
|
216
|
+
// Create empty directory and save package version information.
|
|
217
|
+
// Installers have to be manually uninstalled for now.
|
|
218
|
+
const dirTarget = path.join(this.typeDir, 'Installers', slug, versionNum);
|
|
219
|
+
dirCreate(dirTarget);
|
|
220
|
+
fileCreateJson(path.join(dirTarget, 'index.json'), pkgVersion);
|
|
215
221
|
}
|
|
216
222
|
// If archive, extract the archive to temporary directory, then move individual files.
|
|
217
223
|
if (file.type === FileType.Archive) {
|
|
@@ -243,6 +249,22 @@ export class ManagerLocal extends Manager {
|
|
|
243
249
|
pkgVersion.installed = true;
|
|
244
250
|
return pkgVersion;
|
|
245
251
|
}
|
|
252
|
+
async installAll() {
|
|
253
|
+
// Elevate permissions if not running as admin.
|
|
254
|
+
if (!isAdmin() && !isTests()) {
|
|
255
|
+
let command = `--appDir "${this.config.get('appDir')}" --operation "installAll" --type "${this.type}"`;
|
|
256
|
+
if (this.debug)
|
|
257
|
+
command += ` --log`;
|
|
258
|
+
await runCliAsAdmin(command);
|
|
259
|
+
return this.listPackages();
|
|
260
|
+
}
|
|
261
|
+
// Loop through all packages and install each one.
|
|
262
|
+
for (const [slug, pkg] of this.packages) {
|
|
263
|
+
const versionNum = pkg.latestVersion();
|
|
264
|
+
await this.install(slug, versionNum);
|
|
265
|
+
}
|
|
266
|
+
return this.listPackages();
|
|
267
|
+
}
|
|
246
268
|
async installDependency(slug, version, filePath, type = RegistryType.Plugins) {
|
|
247
269
|
// Get dependency package information from registry.
|
|
248
270
|
const manager = new ManagerLocal(type, this.config.config);
|
|
@@ -311,18 +333,18 @@ export class ManagerLocal extends Manager {
|
|
|
311
333
|
return this.getPackage(slug)?.getVersion(versionNum);
|
|
312
334
|
}
|
|
313
335
|
// Delete all directories for this package version.
|
|
314
|
-
const versionDirs = dirRead(
|
|
336
|
+
const versionDirs = dirRead(path.join(this.typeDir, '**', slug, versionNum));
|
|
315
337
|
versionDirs.forEach((versionDir) => {
|
|
316
338
|
dirDelete(versionDir);
|
|
317
339
|
});
|
|
318
340
|
// Delete all empty directories for this package.
|
|
319
|
-
const pkgDirs = dirRead(
|
|
341
|
+
const pkgDirs = dirRead(path.join(this.typeDir, '**', slug));
|
|
320
342
|
pkgDirs.forEach((pkgDir) => {
|
|
321
343
|
if (dirEmpty(pkgDir))
|
|
322
344
|
dirDelete(pkgDir);
|
|
323
345
|
});
|
|
324
346
|
// Delete all empty directories for the org.
|
|
325
|
-
const orgDirs = dirRead(
|
|
347
|
+
const orgDirs = dirRead(path.join(this.typeDir, '**', slug.split('/')[0]));
|
|
326
348
|
orgDirs.forEach((orgDir) => {
|
|
327
349
|
if (dirEmpty(orgDir))
|
|
328
350
|
dirDelete(orgDir);
|
package/build/helpers/admin.js
CHANGED
package/build/helpers/file.d.ts
CHANGED
|
@@ -40,5 +40,5 @@ export declare function fileSize(filePath: string): number;
|
|
|
40
40
|
export declare function isAdmin(): boolean;
|
|
41
41
|
export declare function fileValidateMetadata(filePath: string, fileMetadata: PluginFile | PresetFile | ProjectFile): Promise<ZodIssue[]>;
|
|
42
42
|
export declare function getPlatform(): SystemType;
|
|
43
|
-
export declare function runCliAsAdmin(args: string): Promise<
|
|
43
|
+
export declare function runCliAsAdmin(args: string): Promise<void>;
|
|
44
44
|
export declare function zipCreate(filesPath: string, zipPath: string): void;
|
package/build/helpers/file.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import AdmZip from 'adm-zip';
|
|
2
|
-
import { execFileSync, execSync } from 'child_process';
|
|
2
|
+
import { execFileSync, execSync, spawn } from 'child_process';
|
|
3
3
|
import { createReadStream, chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, unlinkSync, writeFileSync, } from 'fs';
|
|
4
4
|
import { createHash } from 'crypto';
|
|
5
5
|
import { unpack } from '7zip-min';
|
|
@@ -175,7 +175,7 @@ export function fileInstall(filePath) {
|
|
|
175
175
|
let command = null;
|
|
176
176
|
switch (ext) {
|
|
177
177
|
case '.dmg':
|
|
178
|
-
command = `hdiutil attach -nobrowse "${filePath}" && sudo installer -pkg "$(find /Volumes -name '*.pkg' -maxdepth 2 | head -n 1)" -target / && hdiutil detach "$(find /Volumes -
|
|
178
|
+
command = `hdiutil attach -nobrowse "${filePath}" && sudo installer -pkg "$(find /Volumes -name '*.pkg' -maxdepth 2 | head -n 1)" -target / && hdiutil detach "$(dirname "$(find /Volumes -name '*.pkg' -maxdepth 2 | head -n 1)")"`;
|
|
179
179
|
break;
|
|
180
180
|
case '.pkg':
|
|
181
181
|
command = `sudo installer -pkg "${filePath}" -target /`;
|
|
@@ -312,19 +312,25 @@ export function runCliAsAdmin(args) {
|
|
|
312
312
|
const filename = fileURLToPath(import.meta.url).replace('src/', 'build/');
|
|
313
313
|
const dirPathClean = dirname(filename).replace('app.asar', 'app.asar.unpacked');
|
|
314
314
|
const script = path.join(dirPathClean, 'admin.js');
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
315
|
+
// Temp file for logging
|
|
316
|
+
const logFile = path.join(dirPathClean, 'admin.log');
|
|
317
|
+
writeFileSync(logFile, ''); // Clear previous logs
|
|
318
|
+
log(`Running as admin: node "${script}" ${args}`);
|
|
319
|
+
// Tail the log file in real-time
|
|
320
|
+
const tail = spawn('tail', ['-f', logFile]);
|
|
321
|
+
const grep = spawn('grep', ['.']);
|
|
322
|
+
tail.stdout.pipe(grep.stdin);
|
|
323
|
+
grep.stdout.on('data', data => {
|
|
324
|
+
log(data.toString());
|
|
325
|
+
});
|
|
326
|
+
// Run the script with sudoPrompt
|
|
327
|
+
sudoPrompt.exec(`node "${script}" ${args} >> "${logFile}" 2>&1`, { name: 'Open Audio Stack' }, error => {
|
|
328
|
+
tail.kill();
|
|
323
329
|
if (error) {
|
|
324
330
|
reject(error);
|
|
325
331
|
}
|
|
326
332
|
else {
|
|
327
|
-
resolve(
|
|
333
|
+
resolve();
|
|
328
334
|
}
|
|
329
335
|
});
|
|
330
336
|
});
|
|
@@ -10,8 +10,8 @@ export function packageLoadFile(filePath) {
|
|
|
10
10
|
if (!pkgFile)
|
|
11
11
|
log(filePath, `not a valid json file`);
|
|
12
12
|
// Validate package json file structure, fields and values.
|
|
13
|
-
const pkg = new Package(pathGetSlug(filePath));
|
|
14
|
-
pkg.addVersion(pathGetVersion(filePath), pkgFile);
|
|
13
|
+
const pkg = new Package(pathGetSlug(filePath, path.sep));
|
|
14
|
+
pkg.addVersion(pathGetVersion(filePath, path.sep), pkgFile);
|
|
15
15
|
log(JSON.stringify(pkg.getReport()));
|
|
16
16
|
return pkgFile;
|
|
17
17
|
}
|