@@ -5,6 +5,7 @@ import * as yamlParser from "js-yaml";
55import { getArg } from "./utils/args" ;
66import gitP , { SimpleGit } from "simple-git/promise" ;
77import { getCommits , CommitLogObject } from "./utils/commits" ;
8+ import simplegit from "simple-git/promise" ;
89
910const mkdir = util . promisify ( fs . mkdir ) ;
1011const exists = util . promisify ( fs . exists ) ;
@@ -24,52 +25,58 @@ async function validate(args: string[]) {
2425 const _yaml = await read ( path . join ( localDir , options . yaml ) , "utf8" ) ;
2526
2627 // parse yaml config
27- let config ;
28+ let skeleton ;
2829 try {
29- config = yamlParser . load ( _yaml ) ;
30+ skeleton = yamlParser . load ( _yaml ) ;
31+
32+ console . log ( "config" , skeleton ) ;
3033 // TODO: validate yaml
31- if ( ! config || ! config . length ) {
34+ if ( ! skeleton ) {
3235 throw new Error ( "Invalid yaml file contents" ) ;
3336 }
3437 } catch ( e ) {
3538 console . error ( "Error parsing yaml" ) ;
3639 console . error ( e . message ) ;
3740 }
3841
39- const codeBranch : string = config . config . repo . branch ;
40-
41- // VALIDATE SKELETON WITH COMMITS
42- const commits = getCommits ( { localDir, codeBranch } ) ;
42+ const codeBranch : string = skeleton . config . repo . branch ;
4343
44- // parse tutorial skeleton for order and commands
44+ // validate commits
45+ const commits = await getCommits ( { localDir, codeBranch } ) ;
4546
46- // on error, warn missing level/step
47+ // setup tmp dir
48+ const tmpDir = path . join ( localDir , ".tmp" ) ;
4749
48- // VALIDATE COMMIT ORDER
49- // list all commits in order
50- // validate that a level number doesn't come before another level
51- // validate that a step falls within a level
52- // validate that steps are in order
50+ try {
51+ if ( ! ( await exists ( tmpDir ) ) ) {
52+ await mkdir ( tmpDir ) ;
53+ }
54+ const tempGit : SimpleGit = gitP ( tmpDir ) ;
55+ await tempGit . init ( ) ;
5356
54- // on error, show level/step out of order
57+ // VALIDATE TUTORIAL TESTS
5558
56- // VALIDATE TUTORIAL TESTS
57- // load INIT commit(s)
58- // run test runner setup command(s)
59- // loop over commits:
60- // - load level commit
61- // - run level setup command(s)
62- // - load step setup commit(s)
63- // - run step setup command(s)
64- // - if next solution:
65- // - run test - expect fail
66- // - if solution
67- // - run test - expect pass
59+ // run test runner setup command(s)
60+ // loop over commits:
61+ // - load level commit
62+ // - run level setup command(s)
63+ // - load step setup commit(s)
64+ // - run step setup command(s)
65+ // - if next solution:
66+ // - run test - expect fail
67+ // - if solution
68+ // - run test - expect pass
6869
69- // log level/step
70- // on error, show level/step & error message
70+ // log level/step
71+ // on error, show level/step & error message
7172
72- // CLEANUP
73+ // load INIT commit(s)
74+ } catch ( e ) {
75+ console . error ( e . message ) ;
76+ } finally {
77+ // cleanup
78+ await rmdir ( tmpDir ) ;
79+ }
7380}
7481
7582export default validate ;
0 commit comments