Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/commands/publish.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/server/api/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down