This commit is contained in:
Morten Olsen
2024-01-12 12:43:51 +01:00
commit 6d8e5bf955
109 changed files with 9246 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
import { Command } from 'commander';
import { createClient } from '../../client/client.js';
import { step } from '../../utils/step.js';
const list = new Command('list');
const toInt = (value?: string) => {
if (!value) {
return undefined;
}
return parseInt(value, 10);
};
list
.alias('ls')
.description('List logs')
.option('-r, --run-id <runId>', 'Run ID')
.option('-l, --load-id <loadId>', 'Load ID')
.option('-o, --offset <offset>', 'Offset')
.option('-a, --limit <limit>', 'Limit', '1000')
.action(async () => {
const { runId, loadId, offset, limit } = list.opts();
const client = await step('Connecting to server', async () => {
return createClient();
});
const artifacts = await step('Getting artifacts', async () => {
return await client.artifacts.find.query({
runId,
loadId,
offset: toInt(offset),
limit: toInt(limit),
});
});
console.table(artifacts);
});
export { list };

View File

@@ -0,0 +1,7 @@
import { Command } from 'commander';
import { list } from './artifacts.list.js';
const artifacts = new Command('artifacts');
artifacts.addCommand(list);
export { artifacts };

View File

@@ -0,0 +1,25 @@
import { Command } from 'commander';
import inquerer from 'inquirer';
const login = new Command('login');
login.description('Login to your account');
login.action(async () => {
const { host, token } = await inquerer.prompt([
{
type: 'input',
name: 'host',
message: 'Enter the host of your server',
default: 'http://localhost:4500',
},
{
type: 'password',
name: 'token',
message: 'Enter your token',
},
]);
console.log(host, token);
});
export { login };

View File

@@ -0,0 +1,7 @@
import { Command } from 'commander';
import { login } from './auth.login.js';
const auth = new Command('auth');
auth.addCommand(login);
export { auth };

View File

@@ -0,0 +1,20 @@
import { Command } from 'commander';
import { createClient } from '../../client/client.js';
import { step } from '../../utils/step.js';
const list = new Command('list');
list
.alias('ls')
.description('List loads')
.action(async () => {
const client = await step('Connecting to server', async () => {
return createClient();
});
const loads = step('Getting data', async () => {
await client.loads.find.query({});
});
console.table(loads);
});
export { list };

View File

@@ -0,0 +1,39 @@
import { Command } from 'commander';
import { resolve } from 'path';
import { createClient } from '../../client/client.js';
import { bundle } from '../../bundler/bundler.js';
import { step } from '../../utils/step.js';
const push = new Command('push');
push
.argument('script')
.option('-i, --id <id>', 'Load id')
.option('-n, --name <name>')
.option('-r, --run', 'Run the load')
.option('-ai, --auto-install', 'Auto install dependencies', false)
.action(async (script) => {
const opts = push.opts();
const location = resolve(script);
const client = await step('Connecting to server', async () => {
return createClient();
});
const code = await step('Bundling', async () => {
return await bundle({ entry: location, autoInstall: opts.autoInstall });
});
const id = await step('Creating load', async () => {
return await client.loads.set.mutate({
id: opts.id,
name: opts.name,
script: code,
});
});
console.log('created load with id', id);
if (opts.run) {
await step('Creating run', async () => {
await client.runs.create.mutate({ loadId: id });
});
}
});
export { push };

View File

@@ -0,0 +1,10 @@
import { Command } from 'commander';
import { push } from './loads.push.js';
import { list } from './loads.list.js';
const loads = new Command('loads');
loads.addCommand(push);
loads.addCommand(list);
export { loads };

View File

@@ -0,0 +1,35 @@
import { Command } from 'commander';
import { resolve } from 'path';
import { run as runLoad } from '@morten-olsen/mini-loader-runner';
import { bundle } from '../../bundler/bundler.js';
import { step } from '../../utils/step.js';
const run = new Command('run');
run
.option('-ai, --auto-install', 'Auto install dependencies', false)
.argument('script')
.action(async (script) => {
const location = resolve(script);
const { autoInstall } = run.opts();
const code = await step('Bundling', async () => {
return await bundle({ entry: location, autoInstall });
});
const { promise, emitter } = await runLoad({
script: code,
});
emitter.addListener('message', (message) => {
switch (message.type) {
case 'log':
console.log(message.payload);
break;
case 'artifact:create':
console.log('artifact:create', message.payload.name);
break;
}
});
await promise;
});
export { run };

View File

@@ -0,0 +1,8 @@
import { Command } from 'commander';
import { run } from './local.run.js';
const local = new Command('local');
local.addCommand(run);
export { local };

View File

@@ -0,0 +1,41 @@
import { Command } from 'commander';
import { createClient } from '../../client/client.js';
import { step } from '../../utils/step.js';
const list = new Command('list');
const toInt = (value?: string) => {
if (!value) {
return undefined;
}
return parseInt(value, 10);
};
list
.alias('ls')
.description('List logs')
.option('-r, --run-id <runId>', 'Run ID')
.option('-l, --load-id <loadId>', 'Load ID')
.option('--severities <severities...>', 'Severities')
.option('-o, --offset <offset>', 'Offset')
.option('-a, --limit <limit>', 'Limit', '1000')
.option('-s, --sort <order>', 'Sort', 'desc')
.action(async () => {
const { runId, loadId, severities, offset, limit, order } = list.opts();
const client = await step('Connecting to server', async () => {
return createClient();
});
const logs = await step('Getting logs', async () => {
return await client.logs.find.query({
runId,
loadId,
severities,
offset: toInt(offset),
limit: toInt(limit),
order,
});
});
console.table(logs.reverse());
});
export { list };

View File

@@ -0,0 +1,7 @@
import { Command } from 'commander';
import { list } from './logs.list.js';
const logs = new Command('logs');
logs.addCommand(list);
export { logs };

View File

@@ -0,0 +1,19 @@
import { Command } from 'commander';
import { createClient } from '../../client/client.js';
import { step } from '../../utils/step.js';
const create = new Command('create');
create
.description('Create a new run')
.argument('load-id', 'Load ID')
.action(async (loadId) => {
const client = await step('Connecting to server', async () => {
return createClient();
});
await step('Creating run', async () => {
await client.runs.create.mutate({ loadId });
});
});
export { create };

View File

@@ -0,0 +1,21 @@
import { Command } from 'commander';
import { createClient } from '../../client/client.js';
import { step } from '../../utils/step.js';
const list = new Command('create');
list
.alias('ls')
.description('Find a run')
.argument('[load-id]', 'Load ID')
.action(async (loadId) => {
const client = await step('Connecting to server', async () => {
return createClient();
});
const runs = await step('Getting runs', async () => {
return await client.runs.find.query({ loadId });
});
console.table(runs);
});
export { list };

View File

@@ -0,0 +1,8 @@
import { Command } from 'commander';
import { create } from './runs.create.js';
import { list } from './runs.list.js';
const runs = new Command('runs');
runs.description('Manage runs').addCommand(create).addCommand(list);
export { runs };

View File

@@ -0,0 +1,33 @@
import { Command } from 'commander';
import { createClient } from '../../client/client.js';
import { step } from '../../utils/step.js';
const list = new Command('list');
const toInt = (value?: string) => {
if (!value) {
return undefined;
}
return parseInt(value, 10);
};
list
.alias('ls')
.description('List logs')
.option('-o, --offset <offset>', 'Offset')
.option('-a, --limit <limit>', 'Limit', '1000')
.action(async () => {
const { offset, limit } = list.opts();
const client = await step('Connecting to server', async () => {
return createClient();
});
const secrets = await step('Getting secrets', async () => {
return await client.secrets.find.query({
offset: toInt(offset),
limit: toInt(limit),
});
});
console.table(secrets);
});
export { list };

View File

@@ -0,0 +1,21 @@
import { Command } from 'commander';
import { createClient } from '../../client/client.js';
import { step } from '../../utils/step.js';
const remove = new Command('remove');
remove
.alias('rm')
.argument('<id>')
.action(async (id) => {
const client = await step('Connecting to server', async () => {
return createClient();
});
await step('Removing', async () => {
await client.secrets.remove.mutate({
id,
});
});
});
export { remove };

View File

@@ -0,0 +1,22 @@
import { Command } from 'commander';
import { createClient } from '../../client/client.js';
import { step } from '../../utils/step.js';
const set = new Command('set');
set
.argument('<id>')
.argument('[value]')
.action(async (id, value) => {
const client = await step('Connecting to server', async () => {
return createClient();
});
await step('Setting secret', async () => {
await client.secrets.set.mutate({
id,
value,
});
});
});
export { set };

View File

@@ -0,0 +1,11 @@
import { Command } from 'commander';
import { list } from './secrets.list.js';
import { set } from './secrets.set.js';
import { remove } from './secrets.remove.js';
const secrets = new Command('secrets');
secrets.addCommand(list);
secrets.addCommand(set);
secrets.addCommand(remove);
export { secrets };