portfolio-xs
Version:
This is a tool to generate portfolio based with your markdown file
57 lines (53 loc) • 2.2 kB
JavaScript
import { buildSite } from '../lib/generate.js';
import { initAboutPage } from '../lib/init.js';
import { initMarkdown } from '../lib/add.js';
import { spawn } from 'child_process';
import open from 'open';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { readFileSync } from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const pkg = JSON.parse(readFileSync(path.join(__dirname, '../package.json'), 'utf-8'));
// -------- CLI --------
yargs(hideBin(process.argv))
.scriptName('portfolio')
.usage('$0 <command> [options]')
.command('init', 'Initialize about.md in current folder and doc folder', {}, () => {
initAboutPage();
})
.command('add [folderName]', 'Add a new markdown project folder under /doc', yargs => {
return yargs.positional('folderName', {
describe: 'Name of the folder to create under doc/',
type: 'string',
default: 'project'
});
}, argv => {
initMarkdown(argv.folderName);
})
.command('generate', 'Generate the portfolio site and bundle it with esbuild', yargs => {
return yargs
.option('config', { alias: 'c', type: 'string', default: 'setting.json', describe: 'Path to the config file' })
.option('prod', { type: 'boolean', default: true, describe: 'Production build (minify, hashing, drop console)' })
.option('cdn', { type: 'boolean', default: false, describe: 'Externalize react/react-dom to CDN ESM' })
.option('analyze',{ type: 'boolean', default: false, describe: 'Emit esbuild metafile (meta.json)' });
}, async (argv) => {
await buildSite(argv);
})
.command('preview', 'Preview the dist site locally', {}, () => {
const server = spawn('npx', ['serve', './', '--single', '--listen', '3000'], {
stdio: 'inherit',
shell: true,
});
setTimeout(() => open('http://localhost:3000'), 1000);
server.on('exit', (code) => process.exit(code));
})
.version(pkg.version)
.alias('v', 'version')
.help()
.alias('h', 'help')
.demandCommand(1, 'Please provide a valid command')
.argv;