Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@studiorack/cli",
"version": "3.0.5",
"version": "3.0.6",
"description": "Audio project manager tool",
"type": "module",
"main": "./build/index.js",
Expand Down Expand Up @@ -39,7 +39,7 @@
"node": ">=18"
},
"dependencies": {
"@open-audio-stack/core": "^0.1.45",
"@open-audio-stack/core": "^0.1.47",
"cli-table3": "^0.6.5",
"commander": "^12.1.0",
"ora": "^9.0.0"
Expand Down
36 changes: 22 additions & 14 deletions src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Command } from 'commander';
import { CliOptions } from '../types/options.js';
import { ConfigInterface, ConfigLocal, isTests } from '@open-audio-stack/core';
import { CONFIG_LOCAL_TEST } from '../data/Config.js';
import { output, OutputType } from '../utils.js';

const config: ConfigLocal = new ConfigLocal(isTests() ? CONFIG_LOCAL_TEST : undefined);
const program = new Command();
Expand All @@ -13,13 +14,16 @@ configCmd
.option('-l, --log', 'Enable logging')
.description('Get a config setting by key')
.action((key: keyof ConfigInterface, options: CliOptions) => {
if (options.log) config.logEnable();
if (options.json) {
const obj: any = {};
obj[key] = config.get(key);
console.log({ key });
} else {
console.log(config.get(key));
{
const message = `Get config ${String(key)}`;
output(OutputType.START, message, options, config);
try {
const payload = options && options.json ? { key, value: config.get(key) } : String(config.get(key));
output(OutputType.SUCCESS, payload, options, config);
} catch (err: any) {
output(OutputType.ERROR, err, options, config);
process.exit(1);
}
}
});

Expand All @@ -29,12 +33,16 @@ configCmd
.option('-l, --log', 'Enable logging')
.description('Set a config setting by key and value')
.action((key: keyof ConfigInterface, val: any, options: CliOptions) => {
// if (options.log) config.logEnable();
if (options.json) {
const obj: any = {};
obj[key] = config.set(key, val);
console.log(obj);
} else {
console.log(config.set(key, val));
{
const message = `Set config ${String(key)}`;
output(OutputType.START, message, options, config);
try {
const res = config.set(key, val);
const payload = options && options.json ? { key, value: res } : String(res);
output(OutputType.SUCCESS, payload, options, config);
} catch (err: any) {
output(OutputType.ERROR, err, options, config);
process.exit(1);
}
}
});
22 changes: 16 additions & 6 deletions src/commands/create.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import { Command } from 'commander';
import { CliOptions } from '../types/options.js';
import { ManagerLocal } from '@open-audio-stack/core';
import { output, OutputType } from '../utils.js';

export function create(command: Command, manager: ManagerLocal) {
command
.command('create <path>')
.command('create')
.option('-j, --json', 'Output results as json')
.option('-l, --log', 'Enable logging')
.description('Create a new package locally')
.action(async (path: string, options: CliOptions) => {
if (options.log) manager.logEnable();
else manager.logDisable();
console.log(await manager.create());
console.log(path);
.action(async (options: CliOptions) => {
const message = `Create package`;
output(OutputType.START, message, options, manager);
try {
const result = await manager.create();
// For JSON mode return the object; for textual mode, stringify objects
const payload =
options && options.json ? result : typeof result === 'string' ? result : JSON.stringify(result, null, 2);
output(OutputType.SUCCESS, payload, options, manager);
} catch (err: any) {
output(OutputType.ERROR, err, options, manager);
process.exit(1);
}
});
}
29 changes: 24 additions & 5 deletions src/commands/filter.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
import { Command } from 'commander';
import { CliOptions } from '../types/options.js';
import { ManagerLocal, PackageVersion } from '@open-audio-stack/core';
import { formatOutput } from '../utils.js';
import { formatOutput, output, OutputType } from '../utils.js';

export function filter(command: Command, manager: ManagerLocal) {
command
.command('filter <field> <value>')
.option('-j, --json', 'Output results as json')
.option('-l, --log', 'Enable logging')
.description('Filter the by field and matching value')
.action((field: keyof PackageVersion, value: string, options: CliOptions) => {
if (options.log) manager.logEnable();
else manager.logDisable();
console.log(formatOutput(manager.filter(pkgVersion => pkgVersion[field] === value)));
.action(async (field: keyof PackageVersion, value: string, options: CliOptions) => {
const message = `Filter ${manager.type} by ${String(field)}=${value}`;
output(OutputType.START, message, options, manager);
try {
const predicate = (pkgVersion: PackageVersion) => {
const fieldVal: any = pkgVersion[field];
if (Array.isArray(fieldVal)) {
return fieldVal.some((v: any) => String(v).toLowerCase() === value.toLowerCase());
}
if (typeof fieldVal === 'string') {
return fieldVal.toLowerCase().includes(value.toLowerCase());
}
if (fieldVal === undefined || fieldVal === null) return false;
return String(fieldVal) === value;
};
const result = await manager.filter(predicate);
const payload = options && options.json ? result : formatOutput(result);
output(OutputType.SUCCESS, payload, options, manager);
} catch (err: any) {
output(OutputType.ERROR, err, options, manager);
process.exit(1);
}
});
}
24 changes: 17 additions & 7 deletions src/commands/get.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import { Command } from 'commander';
import { CliOptions } from '../types/options.js';
import { inputGetParts, ManagerLocal } from '@open-audio-stack/core';
import { formatOutput } from '../utils.js';
import { formatOutput, output, OutputType } from '../utils.js';

export function get(command: Command, manager: ManagerLocal) {
command
.command('get <input>')
.option('-j, --json', 'Output results as json')
.option('-l, --log', 'Enable logging')
.description('Get package metadata from registry')
.action((input: string, options: CliOptions) => {
if (options.log) manager.logEnable();
else manager.logDisable();
const [slug, version] = inputGetParts(input);
const pkg = manager.getPackage(slug);
const versions = version ? [version] : Array.from(pkg?.versions.keys() || new Map().keys());
console.log(formatOutput(pkg, versions));
const message = `Get package ${input}`;
output(OutputType.START, message, options, manager);
try {
const [slug, version] = inputGetParts(input);
const pkg = manager.getPackage(slug);
if (!pkg) throw new Error(`No package found with slug: ${slug}`);
const payload =
options && options.json
? { pkg, version }
: formatOutput(pkg, version ? [version] : Array.from(pkg.versions.keys()), false);
output(OutputType.SUCCESS, payload, options, manager);
} catch (err: any) {
output(OutputType.ERROR, err, options, manager);
process.exit(1);
}
});
}
24 changes: 13 additions & 11 deletions src/commands/install.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import { Command } from 'commander';
import ora from 'ora';
import { CliOptions } from '../types/options.js';
import { inputGetParts, ManagerLocal, isTests } from '@open-audio-stack/core';
import { inputGetParts, ManagerLocal } from '@open-audio-stack/core';
import { output, OutputType } from '../utils.js';

export function install(command: Command, manager: ManagerLocal) {
command
.command('install <input>')
.option('-j, --json', 'Output results as json')
.option('-l, --log', 'Enable logging')
.description('Install a package locally by slug/version')
.action(async (input: string, options: CliOptions) => {
if (options.log) manager.logEnable();
else manager.logDisable();
const [slug, version] = inputGetParts(input);
const spinner = ora(`Installing ${slug}${version ? `@${version}` : ''}...`).start();
const message = `Install ${slug}${version ? `@${version}` : ''}`;
output(OutputType.START, message, options, manager);
try {
await manager.install(slug, version);
spinner.succeed(`Installed ${slug}${version ? `@${version}` : ''}`);
if (isTests()) console.log(`Installed ${slug}${version ? `@${version}` : ''}`);
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
spinner.fail(errorMessage);
if (isTests()) console.log(errorMessage);
const payload =
options && options.json
? { slug, version: version || null, installed: true }
: `Installed ${slug}${version ? `@${version}` : ''}`;
output(OutputType.SUCCESS, payload, options, manager);
} catch (err: any) {
output(OutputType.ERROR, err, options, manager);
process.exit(1);
}
});
}
16 changes: 12 additions & 4 deletions src/commands/list.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Command } from 'commander';
import { CliOptions } from '../types/options.js';
import { ManagerLocal } from '@open-audio-stack/core';
import { formatOutput } from '../utils.js';
import { formatOutput, output, OutputType } from '../utils.js';

interface ListOptions extends CliOptions {
incompatible: boolean;
Expand All @@ -13,11 +13,19 @@ export function list(command: Command, manager: ManagerLocal) {
.command('list')
.option('-c, --incompatible', 'List incompatible packages')
.option('-i, --installed', 'Only list installed packages')
.option('-j, --json', 'Output results as json')
.option('-l, --log', 'Enable logging')
.description('List packages')
.action(async (options: ListOptions) => {
if (options.log) manager.logEnable();
else manager.logDisable();
console.log(formatOutput(manager.listPackages(options.installed, options.incompatible)));
const message = `List ${manager.type}`;
output(OutputType.START, message, options, manager);
try {
const result = await manager.listPackages(options.installed, options.incompatible);
const payload = options && options.json ? result : formatOutput(result);
output(OutputType.SUCCESS, payload, options, manager);
} catch (err: any) {
output(OutputType.ERROR, err, options, manager);
process.exit(1);
}
});
}
13 changes: 7 additions & 6 deletions src/commands/open.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { Command } from 'commander';
import { CliOptions } from '../types/options.js';
import { inputGetParts, ManagerLocal } from '@open-audio-stack/core';
import { output, OutputType } from '../utils.js';

export function open(command: Command, manager: ManagerLocal) {
command
.command('open <input> [options...]')
.option('-l, --log', 'Enable logging')
.description('Open a package by slug/version')
.action(async (input: string, options: string[], cliOptions: CliOptions) => {
if (cliOptions.log) manager.logEnable();
else manager.logDisable();
const [slug, version] = inputGetParts(input);
const message = `Open ${input}`;
output(OutputType.START, message, cliOptions, manager);
try {
const [slug, version] = inputGetParts(input);
await manager.open(slug, version, options);
} catch (error: any) {
const errorMessage = error instanceof Error ? error.message : String(error);
console.error(errorMessage);
output(OutputType.SUCCESS, `Opened ${input}`, cliOptions, manager);
} catch (err: any) {
output(OutputType.ERROR, err, cliOptions, manager);
process.exit(1);
}
});
Expand Down
16 changes: 12 additions & 4 deletions src/commands/reset.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { Command } from 'commander';
import { CliOptions } from '../types/options.js';
import { ManagerLocal } from '@open-audio-stack/core';
import { output, OutputType } from '../utils.js';

export function reset(command: Command, manager: ManagerLocal) {
command
.command('reset')
.option('-l, --log', 'Enable logging')
.description('Reset the synced package cache')
.action((options: CliOptions) => {
if (options.log) manager.logEnable();
else manager.logDisable();
manager.reset();
console.log(`${manager.type} cache has been reset`);
const message = `Reset ${manager.type}`;
output(OutputType.START, message, options, manager);
try {
manager.reset();
const payload =
options && options.json ? { type: manager.type, status: 'reset' } : `Reset complete ${manager.type}`;
output(OutputType.SUCCESS, payload, options, manager);
} catch (err: any) {
output(OutputType.ERROR, err, options, manager);
process.exit(1);
}
});
}
Loading
Loading