UNPKG

@vidavidorra/create-project

Version:
52 lines 1.86 kB
import fs from 'node:fs'; import { z } from 'zod'; import validatePackageName from 'validate-npm-package-name'; const schema = z .object({ project: z.string().min(1), package: z.string().superRefine((value, context) => { const { validForNewPackages, errors, warnings } = validatePackageName(value); if (!validForNewPackages) { for (const message of [...(errors ?? []), ...(warnings ?? [])]) { context.addIssue({ code: z.ZodIssueCode.custom, message }); } } }), public: z.boolean().default(false), description: z.string(), author: z.string().min(1), typescript: z.boolean(), testing: z.boolean().default(false), reportCodeCoverage: z.boolean().default(false), githubOwner: z.string().regex(/^[\w-.]+$/), githubRepository: z.string().regex(/^[\w-.]+$/), path: z .string() .min(1) .superRefine((value, context) => { const exists = fs.existsSync(value); if (exists) { if (!fs.statSync(value).isDirectory()) { context.addIssue({ code: z.ZodIssueCode.custom, message: 'Expected an empty directory, received a file.', }); return z.NEVER; } const { files } = fs.statfsSync(value); if (files !== 0) { context.addIssue({ code: z.ZodIssueCode.custom, message: [ 'Expected an empty directory, received a directory with', `${files} file${files === 1 ? '' : 's'}.`, ].join(' '), }); } } }), dryRun: z.boolean().default(false), }) .strict(); export { schema, schema as options }; //# sourceMappingURL=options.js.map