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

Commita6a66cd

Browse files
committed
coderoadJson validator
1 parent69c0755 commita6a66cd

File tree

11 files changed

+177
-17
lines changed

11 files changed

+177
-17
lines changed

‎lib/cli.js

100755100644
File mode changed.
File renamed without changes.

‎lib/tutorials/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"use strict";
22
varchalk_1=require('chalk');
33
varfind_tutorials_1=require('./find-tutorials');
4-
varget_1=require('../packageJson/get');
4+
varpackageJson_1=require('../get/packageJson');
55
functiontutorials(dir){
6-
varpj=get_1.default(dir);
6+
varpj=packageJson_1.default(dir);
77
if(!pj){
88
console.log(chalk_1.red("No package.json available"));
99
returnnull;

‎lib/validate/coderoadJson.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
"use strict";
2+
varvalidKeys={
3+
info:['title','description'],
4+
page:['title','description','onPageComplete','tasks','video','link'],
5+
task:['description','tests','actions','hints'],
6+
actions:['open','set','insert'],
7+
};
8+
functionvalidateCoderoadJson(json){
9+
varerrors=[];
10+
varwarnings=[];
11+
try{
12+
json.parse(json);
13+
}
14+
catch(e){
15+
errors.push({
16+
name:'json',
17+
msg:'is invalid'
18+
});
19+
return{
20+
errors:errors,warnings:warnings
21+
};
22+
}
23+
varinfoKeys=Object.keys(json.info);
24+
infoKeys.forEach(function(key){
25+
if(validKeys.info.indexOf(key)<0){
26+
errors.push({
27+
name:key,
28+
msg:'is missing',
29+
location:"info."+key,
30+
});
31+
}
32+
});
33+
json.pages.forEach(function(page,pIndex){
34+
varpageKeys=Object.keys(page);
35+
pageKeys.forEach(function(key){
36+
if(validKeys.page.indexOf(key)<0){
37+
errors.push({
38+
name:key,
39+
msg:'is an invalid key',
40+
location:"pages["+pIndex+"]",
41+
example:json.pages[pIndex],
42+
});
43+
}
44+
});
45+
if(page.tasks&&page.tasks.length>0){
46+
page.tasks.forEach(function(task,tIndex){
47+
vartaskKeys=Object.keys(task);
48+
taskKeys.forEach(function(key){
49+
if(validKeys.task.indexOf(key)<0){
50+
errors.push({
51+
name:'page task',
52+
msg:"Invalid Task key \""+key+"\"",
53+
location:"pages["+pIndex+"].tasks[]"+tIndex+"]",
54+
});
55+
}
56+
});
57+
if(!task.tests||task.tests.length<1){
58+
errors.push({
59+
name:'task test',
60+
msg:'Missing Task Test',
61+
location:"pages["+pIndex+"].tasks["+tIndex+"]",
62+
});
63+
}
64+
});
65+
}
66+
else{
67+
warnings.push({
68+
name:'page tasks',
69+
msg:'are missing',
70+
location:"pages["+pIndex+"]",
71+
});
72+
}
73+
});
74+
return{
75+
errors:errors,
76+
warnings:warnings,
77+
};
78+
}
79+
Object.defineProperty(exports,"__esModule",{value:true});
80+
exports.default=validateCoderoadJson;

‎lib/validate/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"use strict";
22
varchalk_1=require('chalk');
33
varpackageJson_1=require('./packageJson');
4-
varget_1=require('../packageJson/get');
4+
varpackageJson_2=require('../get/packageJson');
55
functionvalidate(){
6-
varpj=get_1.default(process.cwd());
6+
varpj=packageJson_2.default(process.cwd());
77
if(!pj){
88
console.log(chalk_1.red('Error: No package.json.'));
99
returnfalse;

‎lib/validate/name.js

Lines changed: 0 additions & 10 deletions
This file was deleted.
File renamed without changes.

‎src/tutorials/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import{red}from'chalk';
22
importfindTutorialsfrom'./find-tutorials';
3-
importgetPackageJsonfrom'../packageJson/get';
3+
importgetPackageJsonfrom'../get/packageJson';
44

55
exportdefaultfunctiontutorials(dir:string):string[]{
66
constpj:PackageJson=getPackageJson(dir);

‎src/validate/coderoadJson.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
constvalidKeys={
2+
info:['title','description'],
3+
page:['title','description','onPageComplete','tasks','video','link'],
4+
task:['description','tests','actions','hints'],
5+
actions:['open','set','insert'],
6+
};
7+
8+
9+
exportdefaultfunctionvalidateCoderoadJson(json):ValidatePjOutput{
10+
consterrors=[];
11+
constwarnings=[];
12+
13+
// test for invalid json
14+
try{
15+
json.parse(json);
16+
}catch(e){
17+
errors.push({
18+
name:'json',
19+
msg:'is invalid'
20+
});
21+
return{
22+
errors, warnings
23+
};
24+
}
25+
26+
// info =>
27+
constinfoKeys=Object.keys(json.info);
28+
infoKeys.forEach((key)=>{
29+
if(validKeys.info.indexOf(key)<0){
30+
errors.push({
31+
name:key,
32+
msg:'is missing',
33+
location:`info.${key}`,
34+
});
35+
}
36+
});
37+
38+
json.pages.forEach((page:CR.Page,pIndex:number)=>{
39+
40+
// pages =>
41+
constpageKeys=Object.keys(page);
42+
pageKeys.forEach((key)=>{
43+
if(validKeys.page.indexOf(key)<0){
44+
errors.push({
45+
name:key,
46+
msg:'is an invalid key',
47+
location:`pages[${pIndex}]`,
48+
example:json.pages[pIndex],
49+
});
50+
}
51+
});
52+
53+
// pages => tasks
54+
if(page.tasks&&page.tasks.length>0){
55+
page.tasks.forEach((task:CR.Task,tIndex:number)=>{
56+
lettaskKeys=Object.keys(task);
57+
58+
taskKeys.forEach((key)=>{
59+
if(validKeys.task.indexOf(key)<0){
60+
errors.push({
61+
name:'page task',
62+
msg:`Invalid Task key "${key}"`,
63+
location:`pages[${pIndex}].tasks[]${tIndex}]`,
64+
});
65+
}
66+
});
67+
68+
if(!task.tests||task.tests.length<1){
69+
errors.push({
70+
name:'task test',
71+
msg:'Missing Task Test',
72+
location:`pages[${pIndex}].tasks[${tIndex}]`,
73+
});
74+
}
75+
});
76+
}else{
77+
warnings.push({
78+
name:'page tasks',
79+
msg:'are missing',
80+
location:`pages[${pIndex}]`,
81+
});
82+
}
83+
});
84+
85+
return{
86+
errors,
87+
warnings,
88+
};
89+
}

‎src/validate/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import{red,yellow}from'chalk';
22
importvalidatePackageJsonfrom'./packageJson';
3-
importgetPackageJsonfrom'../packageJson/get';
3+
importgetPackageJsonfrom'../get/packageJson';
44

55
exportdefaultfunctionvalidate():boolean{
66
constpj=getPackageJson(process.cwd());

‎tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"src/create/index.ts",
3232
"src/create/validate.ts",
3333
"src/create/write-demo.ts",
34-
"src/packageJson/get.ts",
34+
"src/get/packageJson.ts",
3535
"src/publish/index.ts",
3636
"src/publish/validate.ts",
3737
"src/search/index.ts",
@@ -59,6 +59,7 @@
5959
"src/typings/sort-package-json/index.d.ts",
6060
"src/typings/tsd.d.ts",
6161
"src/update/index.ts",
62+
"src/validate/coderoadJson.ts",
6263
"src/validate/index.ts",
6364
"src/validate/packageJson.ts"
6465
],

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp