mirror of
https://github.com/morten-olsen/mini-loader.git
synced 2026-02-08 01:36:26 +01:00
init
This commit is contained in:
20
packages/cli/src/commands/loads/loads.list.ts
Normal file
20
packages/cli/src/commands/loads/loads.list.ts
Normal 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 };
|
||||
39
packages/cli/src/commands/loads/loads.push.ts
Normal file
39
packages/cli/src/commands/loads/loads.push.ts
Normal 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 };
|
||||
10
packages/cli/src/commands/loads/loads.ts
Normal file
10
packages/cli/src/commands/loads/loads.ts
Normal 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 };
|
||||
Reference in New Issue
Block a user