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:
35
packages/cli/src/commands/local/local.run.ts
Normal file
35
packages/cli/src/commands/local/local.run.ts
Normal 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 };
|
||||
Reference in New Issue
Block a user