Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc0e7cd0

Browse files
committed
validate yaml setup
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent7a1ebe0 commitc0e7cd0

File tree

8 files changed

+40
-13
lines changed

8 files changed

+40
-13
lines changed

‎src/build.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ async function build(args: string[]) {
7474
letconfig;
7575
try{
7676
config=yamlParser.load(_yaml);
77+
// TODO: validate yaml
78+
if(!config||!config.length){
79+
thrownewError("Invalid yaml file contents");
80+
}
7781
}catch(e){
7882
console.error("Error parsing yaml");
7983
console.error(e.message);

‎src/utils/commits.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from "fs";
22
importutilfrom"util";
33
import*aspathfrom"path";
44
importgitP,{SimpleGit}from"simple-git/promise";
5-
import{addToCommitOrder,validateCommitOrder}from"./commitOrder";
5+
import{validateCommitOrder}from"./validateCommits";
66

77
constmkdir=util.promisify(fs.mkdir);
88
constexists=util.promisify(fs.exists);

‎src/utils/parse.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ export function parse(params: ParseParams): any {
106106

107107
// add init commits
108108
if(params.commits.INIT&&params.commits.INIT.length){
109-
console.log(JSON.stringify(parsed.config?.testRunner));
110109
//@ts-ignore
111110
parsed.config.testRunner.setup={
112111
...(parsed.config?.testRunner?.setup||{}),

‎src/utils/commitOrder.tsrenamed to‎src/utils/validateCommits.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
// should flag commits that are out of order based on the previous commit
22
// position is a string like 'INIT', 'L1', 'L1S1'
3-
exportfunctionaddToCommitOrder(position:string){
4-
// add position to list
5-
}
6-
73
exportfunctionvalidateCommitOrder(positions:string[]):boolean{
84
// loop over positions
95
consterrors:number[]=[];
@@ -12,7 +8,6 @@ export function validateCommitOrder(positions: string[]): boolean {
128
positions.forEach((position:string,index:number)=>{
139
if(position==="INIT"){
1410
if(previous.level!==0&&previous.step!==0){
15-
console.log("ERROR HERE");
1611
errors.push(index);
1712
}
1813
current={level:0,step:0};
@@ -46,7 +41,7 @@ export function validateCommitOrder(positions: string[]): boolean {
4641
previous=current;
4742
});
4843

49-
if(errors.length){
44+
if(errors.length&&process.env.NODE_ENV!=="test"){
5045
console.warn("Found commit positions out of order");
5146
positions.forEach((position,index)=>{
5247
if(errors.includes(index)){

‎src/utils/validateYaml.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exportfunctionvalidateYaml(yaml:string){
2+
returntrue;
3+
}

‎src/validate.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,46 @@
11
import*aspathfrom"path";
22
import*asfsfrom"fs";
33
importutilfrom"util";
4+
import*asyamlParserfrom"js-yaml";
5+
import{getArg}from"./utils/args";
46
importgitP,{SimpleGit}from"simple-git/promise";
57
import{getCommits,CommitLogObject}from"./utils/commits";
68

79
constmkdir=util.promisify(fs.mkdir);
810
constexists=util.promisify(fs.exists);
911
constrmdir=util.promisify(fs.rmdir);
12+
constread=util.promisify(fs.readFile);
1013

1114
asyncfunctionvalidate(args:string[]){
1215
// dir - default .
1316
constdir=!args.length||args[0].match(/^-/) ?"." :args[0];
14-
console.warn("Not yet implemented. Coming soon");
15-
1617
constlocalDir=path.join(process.cwd(),dir);
17-
constcodeBranch="";
1818

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+
2041
// VALIDATE SKELETON WITH COMMITS
42+
constcommits=getCommits({ localDir, codeBranch});
43+
2144
// parse tutorial skeleton for order and commands
2245

2346
// on error, warn missing level/step

‎tests/commitOrder.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import{validateCommitOrder}from"../src/utils/commitOrder";
1+
import{validateCommitOrder}from"../src/utils/validateCommits";
22

33
describe("commitOrder",()=>{
44
it("should return true if order is valid",()=>{

‎tests/yaml.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
describe("yaml",()=>{
2+
it.todo("should parse a valid yaml file");
3+
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp