@astro-paper/cli
Version:
A comprehensive CLI tool for AstroPaper blog theme management
57 lines (56 loc) • 1.95 kB
JavaScript
import { z } from 'zod';
import { Command } from 'commander';
import { logger } from '../utils/logger.js';
import { handleError } from '../utils/handle-error.js';
import { getProjectRoot } from '../utils/get-project-root.js';
import { getProjectInfo } from '../utils/get-project-info.js';
const optionsSchema = z.object({
fileName: z.string().optional(),
yes: z.boolean().optional(),
draft: z.boolean().optional(),
featured: z.boolean().optional(),
});
export const addNewPost = new Command()
.name('new')
.argument('[fileName]', 'The name of the file to create')
.description('Add a new post to the blog')
.option('-y, --yes', 'Create post with default values')
.option('-d,--draft', 'Create as draft')
.option('-f, --featured', 'Mark as featured')
.action(async (fileName, opts) => {
try {
logger.info('Adding new post');
const projectRoot = await getProjectRoot();
if (!projectRoot) {
logger.error('Not in an AstroPaper project. \nPlease run this command inside your AstroPaper project.');
process.exit(1);
}
const options = optionsSchema.parse({
fileName,
...opts,
});
const postInfo = await getPostInfo(projectRoot, options);
// const meaning = await text({
// message: 'What is the meaning of life?',
// placeholder: 'Not sure',
// initialValue: '42',
// validate(value) {
// if (value.length === 0) return `Value is required!`;
// },
// });
}
catch (error) {
logger.break();
handleError(error);
}
});
async function getPostInfo(projectRoot, options) {
const { siteConfig } = await getProjectInfo(projectRoot);
// console.log(siteConfig);
if (options.yes) {
return {
title: 'Default Title',
description: 'Default Description',
};
}
}