|
1 | 1 | import*aspathfrom"path";
|
2 | 2 | import*asfsfrom"fs";
|
3 | 3 | importutilfrom"util";
|
| 4 | +import*asyamlParserfrom"js-yaml"; |
| 5 | +import{getArg}from"./utils/args"; |
4 | 6 | importgitP,{SimpleGit}from"simple-git/promise";
|
5 | 7 | import{getCommits,CommitLogObject}from"./utils/commits";
|
6 | 8 |
|
7 | 9 | constmkdir=util.promisify(fs.mkdir);
|
8 | 10 | constexists=util.promisify(fs.exists);
|
9 | 11 | constrmdir=util.promisify(fs.rmdir);
|
| 12 | +constread=util.promisify(fs.readFile); |
10 | 13 |
|
11 | 14 | asyncfunctionvalidate(args:string[]){
|
12 | 15 | // dir - default .
|
13 | 16 | constdir=!args.length||args[0].match(/^-/) ?"." :args[0];
|
14 |
| -console.warn("Not yet implemented. Coming soon"); |
15 |
| - |
16 | 17 | constlocalDir=path.join(process.cwd(),dir);
|
17 |
| -constcodeBranch=""; |
18 | 18 |
|
19 |
| -constcommits=getCommits({ localDir, codeBranch}); |
| 19 | +// -y --yaml - default coderoad-config.yml |
| 20 | +constoptions={ |
| 21 | +yaml:getArg(args,{name:"yaml",alias:"y"})||"coderoad.yaml"; |
| 22 | +} |
| 23 | + |
| 24 | +const_yaml=awaitread(path.join(localDir,options.yaml),"utf8"); |
| 25 | + |
| 26 | +// parse yaml config |
| 27 | +letconfig; |
| 28 | +try{ |
| 29 | +config=yamlParser.load(_yaml) |
| 30 | +// TODO: validate yaml |
| 31 | +if(!config||!config.length){ |
| 32 | +thrownewError('Invalid yaml file contents') |
| 33 | +} |
| 34 | +}catch(e){ |
| 35 | +console.error("Error parsing yaml"); |
| 36 | +console.error(e.message); |
| 37 | +} |
| 38 | + |
| 39 | +constcodeBranch:string=config.config.repo.branch; |
| 40 | + |
20 | 41 | // VALIDATE SKELETON WITH COMMITS
|
| 42 | +constcommits=getCommits({ localDir, codeBranch}); |
| 43 | + |
21 | 44 | // parse tutorial skeleton for order and commands
|
22 | 45 |
|
23 | 46 | // on error, warn missing level/step
|
|