From 7a66cb738729180004fa70840eb9867e54c2e5bf Mon Sep 17 00:00:00 2001 From: shmck Date: Mon, 1 Jun 2020 20:44:37 -0700 Subject: [PATCH] setup validate Signed-off-by: shmck --- src/build.ts | 2 +- src/cli.ts | 17 ++++++-- src/help.ts | 30 ++++++++++---- src/utils/{validate.ts => validateSchema.ts} | 0 src/validate.ts | 43 ++++++++++++++++++++ 5 files changed, 78 insertions(+), 14 deletions(-) rename src/utils/{validate.ts => validateSchema.ts} (100%) create mode 100644 src/validate.ts diff --git a/src/build.ts b/src/build.ts index d17198c..3f5662a 100644 --- a/src/build.ts +++ b/src/build.ts @@ -6,7 +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 { validateSchema } from "./utils/validateSchema"; import * as T from "../typings/tutorial"; const write = util.promisify(fs.writeFile); diff --git a/src/cli.ts b/src/cli.ts index f4f1f61..7f2edb9 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,7 +1,8 @@ import "./utils/logs"; import build from "./build"; import create from "./create"; -import { help, create as createHelp, build as buildHelp } from "./help"; +import validate from "./validate"; +import * as help from "./help"; export async function cli(rawArgs: string[]): Promise { const command: string = rawArgs[2]; @@ -16,7 +17,7 @@ export async function cli(rawArgs: string[]): Promise { case "build": if (args.length && ["--help", "-h"].includes(args[0])) { - buildHelp(); + help.build(); return; } build(args); @@ -24,15 +25,23 @@ export async function cli(rawArgs: string[]): Promise { case "create": if (args.length && ["--help", "-h"].includes(args[0])) { - createHelp(); + help.create(); return; } create(args); break; + case "validate": + if (args.length && ["--help", "-h"].includes(args[0])) { + help.validate(); + return; + } + validate(args); + break; + case "--help": case "-h": default: - help(); + help.main(); } } diff --git a/src/help.ts b/src/help.ts index 8767247..dbf7c23 100644 --- a/src/help.ts +++ b/src/help.ts @@ -1,5 +1,6 @@ -export function help() { +export function main() { console.log(` +CodeRoad CLI Usage: coderoad [options] Options: @@ -7,13 +8,14 @@ Options: --version (-v) show coderoad cli version create start a new tutorial from a template build generate a coderoad.json file from markdown and yaml +validate run a variety of tests to ensure a tutorial works as intended -More docs at https://github.com/coderoad/coderoad-cli - `); +More docs at https://github.com/coderoad/coderoad-cli`); } export function create() { - console.log(` + console.log(`Create a new CodeRoad tutorial project from a template. + Usage: coderoad create [path] [options] Options: @@ -21,12 +23,12 @@ Options: --lang (-l) programming language for template --testRunner (-t) test runner module for template -More docs at https://github.com/coderoad/coderoad-cli -`); +More docs at https://github.com/coderoad/coderoad-cli`); } export function build() { - console.log(` + console.log(`Compile a coderoad.json file from markdown & yaml. + Usage: coderoad build [path] [options] Options: @@ -35,6 +37,16 @@ Options: --yaml (-y) custom path to the tutorial yaml file (coderoad.yaml) --output (-o) custom path to tutorial json config file (coderoad.json) -More docs at https://github.com/coderoad/coderoad-cli -`); +More docs at https://github.com/coderoad/coderoad-cli`); +} + +export function validate() { + console.log(`Validates commits and tests across a tutorial. + +Usage: coderoad validate [path] [options] + +Options: +--help (-h) display these help docs + +More docs at https://github.com/coderoad/coderoad-cli`); } diff --git a/src/utils/validate.ts b/src/utils/validateSchema.ts similarity index 100% rename from src/utils/validate.ts rename to src/utils/validateSchema.ts diff --git a/src/validate.ts b/src/validate.ts new file mode 100644 index 0000000..04ab543 --- /dev/null +++ b/src/validate.ts @@ -0,0 +1,43 @@ +async function validate(args: string[]) { + // dir - default . + const dir = !args.length || args[0].match(/^-/) ? "." : args[0]; + console.warn("Not yet implemented. Coming soon"); + return; + + // setup .tmp directory + // git clone branch + + // VALIDATE SKELETON WITH COMMITS + // parse tutorial skeleton for order and commands + + // on error, warn missing level/step + + // VALIDATE COMMIT ORDER + // list all commits in order + // validate that a level number doesn't come before another level + // validate that a step falls within a level + // validate that steps are in order + + // on error, show level/step out of order + + // VALIDATE TUTORIAL TESTS + // load INIT commit(s) + // run test runner setup command(s) + // loop over commits: + // - load level commit + // - run level setup command(s) + // - load step setup commit(s) + // - run step setup command(s) + // - if next solution: + // - run test - expect fail + // - if solution + // - run test - expect pass + + // log level/step + // on error, show level/step & error message + + // CLEANUP + // finally: remove .tmp directory +} + +export default validate;