Skip to content

Commit 8a3aef5

Browse files
authored
Merge pull request #25 from coderoad/feature/validate
setup validate
2 parents 2b2ddd6 + 7a66cb7 commit 8a3aef5

File tree

5 files changed

+78
-14
lines changed

5 files changed

+78
-14
lines changed

src/build.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as util from "util";
66
import { parse } from "./utils/parse";
77
import { getArg } from "./utils/args";
88
import { getCommits, CommitLogObject } from "./utils/commits";
9-
import { validateSchema } from "./utils/validate";
9+
import { validateSchema } from "./utils/validateSchema";
1010
import * as T from "../typings/tutorial";
1111

1212
const write = util.promisify(fs.writeFile);

src/cli.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import "./utils/logs";
22
import build from "./build";
33
import create from "./create";
4-
import { help, create as createHelp, build as buildHelp } from "./help";
4+
import validate from "./validate";
5+
import * as help from "./help";
56

67
export async function cli(rawArgs: string[]): Promise<void> {
78
const command: string = rawArgs[2];
@@ -16,23 +17,31 @@ export async function cli(rawArgs: string[]): Promise<void> {
1617

1718
case "build":
1819
if (args.length && ["--help", "-h"].includes(args[0])) {
19-
buildHelp();
20+
help.build();
2021
return;
2122
}
2223
build(args);
2324
break;
2425

2526
case "create":
2627
if (args.length && ["--help", "-h"].includes(args[0])) {
27-
createHelp();
28+
help.create();
2829
return;
2930
}
3031
create(args);
3132
break;
3233

34+
case "validate":
35+
if (args.length && ["--help", "-h"].includes(args[0])) {
36+
help.validate();
37+
return;
38+
}
39+
validate(args);
40+
break;
41+
3342
case "--help":
3443
case "-h":
3544
default:
36-
help();
45+
help.main();
3746
}
3847
}

src/help.ts

+21-9
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
1-
export function help() {
1+
export function main() {
22
console.log(`
3+
CodeRoad CLI
34
Usage: coderoad [options]
45
56
Options:
67
--help (-h) display these help docs
78
--version (-v) show coderoad cli version
89
create start a new tutorial from a template
910
build generate a coderoad.json file from markdown and yaml
11+
validate run a variety of tests to ensure a tutorial works as intended
1012
11-
More docs at https://github.com/coderoad/coderoad-cli
12-
`);
13+
More docs at https://github.com/coderoad/coderoad-cli`);
1314
}
1415

1516
export function create() {
16-
console.log(`
17+
console.log(`Create a new CodeRoad tutorial project from a template.
18+
1719
Usage: coderoad create [path] [options]
1820
1921
Options:
2022
--help (-h) display these help docs
2123
--lang (-l) programming language for template
2224
--testRunner (-t) test runner module for template
2325
24-
More docs at https://github.com/coderoad/coderoad-cli
25-
`);
26+
More docs at https://github.com/coderoad/coderoad-cli`);
2627
}
2728

2829
export function build() {
29-
console.log(`
30+
console.log(`Compile a coderoad.json file from markdown & yaml.
31+
3032
Usage: coderoad build [path] [options]
3133
3234
Options:
@@ -35,6 +37,16 @@ Options:
3537
--yaml (-y) custom path to the tutorial yaml file (coderoad.yaml)
3638
--output (-o) custom path to tutorial json config file (coderoad.json)
3739
38-
More docs at https://github.com/coderoad/coderoad-cli
39-
`);
40+
More docs at https://github.com/coderoad/coderoad-cli`);
41+
}
42+
43+
export function validate() {
44+
console.log(`Validates commits and tests across a tutorial.
45+
46+
Usage: coderoad validate [path] [options]
47+
48+
Options:
49+
--help (-h) display these help docs
50+
51+
More docs at https://github.com/coderoad/coderoad-cli`);
4052
}
File renamed without changes.

src/validate.ts

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
async function validate(args: string[]) {
2+
// dir - default .
3+
const dir = !args.length || args[0].match(/^-/) ? "." : args[0];
4+
console.warn("Not yet implemented. Coming soon");
5+
return;
6+
7+
// setup .tmp directory
8+
// git clone branch
9+
10+
// VALIDATE SKELETON WITH COMMITS
11+
// parse tutorial skeleton for order and commands
12+
13+
// on error, warn missing level/step
14+
15+
// VALIDATE COMMIT ORDER
16+
// list all commits in order
17+
// validate that a level number doesn't come before another level
18+
// validate that a step falls within a level
19+
// validate that steps are in order
20+
21+
// on error, show level/step out of order
22+
23+
// VALIDATE TUTORIAL TESTS
24+
// load INIT commit(s)
25+
// run test runner setup command(s)
26+
// loop over commits:
27+
// - load level commit
28+
// - run level setup command(s)
29+
// - load step setup commit(s)
30+
// - run step setup command(s)
31+
// - if next solution:
32+
// - run test - expect fail
33+
// - if solution
34+
// - run test - expect pass
35+
36+
// log level/step
37+
// on error, show level/step & error message
38+
39+
// CLEANUP
40+
// finally: remove .tmp directory
41+
}
42+
43+
export default validate;

0 commit comments

Comments
 (0)