prodia-scripts/src/index.ts

38 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-10-25 13:48:42 +08:00
#!node
2024-10-25 13:34:26 +08:00
import { program } from 'commander';
import * as fs from 'fs/promises';
2024-10-25 13:48:42 +08:00
import { defaultProdiaParams, fetchProdia } from './prodia';
2024-10-25 13:34:26 +08:00
program
.name('prodia-scripts')
.description('cli for prodia usage')
.version('0.1.0');
program
.command('sdxl')
.description('generate an image with sdxl')
2024-10-25 13:48:42 +08:00
.argument('[config]', 'path to the config json', './sdxl.gen.json')
.option('--init', 'create a default sdxl.gen.json')
.action(async (config, flags) => {
console.log(config, flags);
if (flags.init) {
console.log('Creating sdxl.gen.json...');
await fs.writeFile(
'./sdxl.gen.json',
JSON.stringify(defaultProdiaParams, null, 4)
);
return;
} else {
console.log(`Reading config=${config}...`);
const txt = await fs.readFile(config, { encoding: 'utf8' });
const json = JSON.parse(txt);
console.log(`Fetching prodia api...`);
const status = await fetchProdia(json);
console.log('done:', status);
}
2024-10-25 13:34:26 +08:00
});
2024-10-25 13:48:42 +08:00
program.parse();