owncast/web/.storybook/tools/generate-image-story.mjs

37 lines
940 B
JavaScript
Raw Normal View History

2023-01-27 07:14:52 +03:00
import fs from 'fs';
import path, { resolve } from 'path';
import { readdirSync, lstatSync } from 'fs';
import handlebars from 'handlebars';
handlebars.registerHelper('capitalize', function (str) {
return str.charAt(0).toUpperCase() + str.slice(1);
});
const args = process.argv;
const dir = args[2];
const title = args[3];
2023-01-28 07:07:14 +03:00
const category = args[4];
const publicPath = args[5];
if (args.length < 6) {
console.error('Usage: generate-image-story.mjs <dir> <title> <category> <webpublicpath>');
2023-01-27 07:14:52 +03:00
process.exit(1);
}
const images = readdirSync(dir)
.map(img => {
const resolvedPath = path.resolve(dir, img);
if (lstatSync(resolvedPath).isDirectory()) {
return;
}
2023-01-28 07:07:14 +03:00
return { name: img, src: `${publicPath}/${img}` };
2023-01-27 07:14:52 +03:00
})
.filter(Boolean);
const template = fs.readFileSync('./Images.stories.mdx', 'utf8');
let t = handlebars.compile(template);
2023-01-28 07:07:14 +03:00
let output = t({ images, title, category });
2023-01-27 07:14:52 +03:00
console.log(output);