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