diff --git a/src/commands/publish.ts b/src/commands/publish.ts index d1eb977..5616962 100644 --- a/src/commands/publish.ts +++ b/src/commands/publish.ts @@ -1,5 +1,6 @@ import arg from "arg"; import process from "node:process"; +import { checkFrontmatterType } from "../lib/check-frontmatter-type"; import { config } from "../lib/config"; import { QiitaItem } from "../lib/entities/qiita-item"; import { getFileSystemRepo } from "../lib/get-file-system-repo"; @@ -44,16 +45,22 @@ export const publish = async (argv: string[]) => { // Validate const invalidItemMessages = targetItems.reduce((acc, item) => { - const errors = validateItem(item); - if (errors.length > 0) return [...acc, { name: item.name, errors }]; - else return acc; + const frontmatterErrors = checkFrontmatterType(item); + if (frontmatterErrors.length > 0) + return [...acc, { name: item.name, errors: frontmatterErrors }]; + + const validationErrors = validateItem(item); + if (validationErrors.length > 0) + return [...acc, { name: item.name, errors: validationErrors }]; + + return acc; }, [] as { name: string; errors: string[] }[]); if (invalidItemMessages.length > 0) { console.error("Validation error:"); invalidItemMessages.forEach((msg) => { console.error(msg.name, msg.errors); - targetItems = targetItems.filter((item) => item.name !== msg.name); }); + process.exit(1); } if (targetItems.length === 0) { diff --git a/src/server/lib/check-frontmatter-type.test.ts b/src/lib/check-frontmatter-type.test.ts similarity index 100% rename from src/server/lib/check-frontmatter-type.test.ts rename to src/lib/check-frontmatter-type.test.ts diff --git a/src/server/lib/check-frontmatter-type.ts b/src/lib/check-frontmatter-type.ts similarity index 100% rename from src/server/lib/check-frontmatter-type.ts rename to src/lib/check-frontmatter-type.ts diff --git a/src/server/api/items.ts b/src/server/api/items.ts index 8be58e4..f9bee04 100644 --- a/src/server/api/items.ts +++ b/src/server/api/items.ts @@ -9,7 +9,7 @@ import type { ItemsIndexViewModel, } from "../../lib/view-models/items"; import { Item, QiitaApi } from "../../qiita-api"; -import { checkFrontmatterType } from "../lib/check-frontmatter-type"; +import { checkFrontmatterType } from "../../lib/check-frontmatter-type"; import { getCurrentUser } from "../lib/get-current-user"; import { itemUrl } from "../lib/qiita-url";