Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Feature/validate#14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 4 commits intomasterfromfeature/validate
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from1 commit
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
PrevPrevious commit
add schema validation
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
@ShMcK
ShMcK committedMay 31, 2020
commitbf94ae11c338dfa0596585aaa8f0992824ac843c
23 changes: 20 additions & 3 deletionssrc/build.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,6 +6,7 @@ import * as util from "util";
import { parse } from "./utils/parse";
import { getArg } from "./utils/args";
import { getCommits, CommitLogObject } from "./utils/commits";
import { validateSchema } from "./utils/validate";
import * as T from "../typings/tutorial";

const write = util.promisify(fs.writeFile);
Expand DownExpand Up@@ -58,7 +59,7 @@ async function build(args: string[]) {
// path to run build from
const localPath = path.join(process.cwd(), options.dir);

// load files
// loadmarkdown andfiles
let _markdown: string;
let _yaml: string;
try {
Expand All@@ -72,6 +73,7 @@ async function build(args: string[]) {
return;
}

// parse yaml config
let config;
try {
config = yamlParser.load(_yaml);
Expand All@@ -80,6 +82,7 @@ async function build(args: string[]) {
console.error(e.message);
}

// load git commits to use in parse step
let commits: CommitLogObject;
try {
commits = await getCommits({
Expand All@@ -92,7 +95,7 @@ async function build(args: string[]) {
return;
}

//Otherwise, continue with the other options
//parse tutorial from markdown and yaml
let tutorial: T.Tutorial;
try {
tutorial = await parse({
Expand All@@ -106,11 +109,25 @@ async function build(args: string[]) {
return;
}

// validate tutorial based on json schema
try {
const valid = validateSchema(tutorial);
if (!valid) {
console.error("Tutorial validation failed. See above to see what to fix");
return;
}
} catch (e) {
console.error("Error validating tutorial schema:");
console.error(e.message);
}

// write tutorial
if (tutorial) {
try {
await write(options.output, JSON.stringify(tutorial), "utf8");
console.info(`Success! See output at ${options.output}`);
} catch (e) {
console.error("Error writing tutorial json:");
console.error("Error writing tutorial json file:");
console.error(e.message);
}
}
Expand Down
4 changes: 2 additions & 2 deletionssrc/utils/logs.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,12 +7,12 @@ const _info = console.info;

console.error = function () {
// @ts-ignore
_error(red.bold.apply(console, arguments));
_error(red.apply(console, arguments));
};

console.warn = function () {
// @ts-ignore
_warn(yellow.bold.apply(console, arguments));
_warn(yellow.apply(console, arguments));
};

console.info = function () {
Expand Down
1 change: 0 additions & 1 deletionsrc/utils/validate.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,7 +16,6 @@ export function validateSchema(json: any): boolean | PromiseLike<boolean> {
if (!valid) {
// log errors
if (process.env.NODE_ENV !== "test") {
console.error("Validation failed. See below for details");
jsonSchema.errors?.forEach((error: JsonSchema.ErrorObject) => {
console.warn(
`Validation error at ${error.dataPath} - ${error.message}`
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp