Skip to content

Commit 7deaf07

Browse files
authored
Merge pull request #16 from increments/add-error-status
Add error status
2 parents ec6018c + dc0238d commit 7deaf07

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

src/commands/publish.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import arg from "arg";
22
import process from "node:process";
3+
import { checkFrontmatterType } from "../lib/check-frontmatter-type";
34
import { config } from "../lib/config";
45
import { QiitaItem } from "../lib/entities/qiita-item";
56
import { getFileSystemRepo } from "../lib/get-file-system-repo";
@@ -44,16 +45,22 @@ export const publish = async (argv: string[]) => {
4445

4546
// Validate
4647
const invalidItemMessages = targetItems.reduce((acc, item) => {
47-
const errors = validateItem(item);
48-
if (errors.length > 0) return [...acc, { name: item.name, errors }];
49-
else return acc;
48+
const frontmatterErrors = checkFrontmatterType(item);
49+
if (frontmatterErrors.length > 0)
50+
return [...acc, { name: item.name, errors: frontmatterErrors }];
51+
52+
const validationErrors = validateItem(item);
53+
if (validationErrors.length > 0)
54+
return [...acc, { name: item.name, errors: validationErrors }];
55+
56+
return acc;
5057
}, [] as { name: string; errors: string[] }[]);
5158
if (invalidItemMessages.length > 0) {
5259
console.error("Validation error:");
5360
invalidItemMessages.forEach((msg) => {
5461
console.error(msg.name, msg.errors);
55-
targetItems = targetItems.filter((item) => item.name !== msg.name);
5662
});
63+
process.exit(1);
5764
}
5865

5966
if (targetItems.length === 0) {

src/server/api/items.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
ItemsIndexViewModel,
1010
} from "../../lib/view-models/items";
1111
import { Item, QiitaApi } from "../../qiita-api";
12-
import { checkFrontmatterType } from "../lib/check-frontmatter-type";
12+
import { checkFrontmatterType } from "../../lib/check-frontmatter-type";
1313
import { getCurrentUser } from "../lib/get-current-user";
1414
import { itemUrl } from "../lib/qiita-url";
1515

0 commit comments

Comments
 (0)