Skip to content

Commit c263369

Browse files
authored
Merge pull request #9 from coderoad/validate/schema
Validate/schema
2 parents ecb6e5e + b2af5f9 commit c263369

File tree

6 files changed

+355
-11
lines changed

6 files changed

+355
-11
lines changed

package-lock.json

Lines changed: 13 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"author": "Argemiro Neto",
2020
"license": "ISC",
2121
"dependencies": {
22+
"ajv": "^6.12.2",
2223
"arg": "^4.1.3",
2324
"esm": "^3.2.25",
2425
"inquirer": "^7.1.0",
@@ -31,6 +32,7 @@
3132
},
3233
"devDependencies": {
3334
"@babel/preset-typescript": "^7.10.1",
35+
"@types/ajv": "^1.0.0",
3436
"@types/inquirer": "^6.5.0",
3537
"@types/jest": "^25.2.3",
3638
"@types/js-yaml": "^3.12.4",

src/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ncp from "ncp";
1+
import ncp from "ncp";
22
import * as path from "path";
33
import { promisify } from "util";
44

src/utils/schema/index.ts

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
import meta from "./meta";
2+
3+
export default {
4+
...meta,
5+
type: "object",
6+
properties: {
7+
version: {
8+
$ref: "#/definitions/semantic_version",
9+
description: "The tutorial version. Must be unique for the tutorial.",
10+
examples: ["0.1.0", "1.0.0"],
11+
},
12+
13+
// summary
14+
summary: {
15+
type: "object",
16+
properties: {
17+
title: {
18+
$ref: "#/definitions/title",
19+
description: "The title of tutorial",
20+
},
21+
description: {
22+
type: "string",
23+
description: "A summary of the the tutorial",
24+
minLength: 10,
25+
maxLength: 400,
26+
},
27+
},
28+
additionalProperties: false,
29+
required: ["title", "description"],
30+
},
31+
32+
// config
33+
config: {
34+
type: "object",
35+
properties: {
36+
testRunner: {
37+
type: "object",
38+
description: "The test runner configuration",
39+
properties: {
40+
command: {
41+
type: "string",
42+
description: "Command line to start the test runner",
43+
examples: ["./node_modules/.bin/mocha"],
44+
},
45+
args: {
46+
type: "object",
47+
description:
48+
"A configuration of command line args for your test runner",
49+
properties: {
50+
filter: {
51+
type: "string",
52+
description:
53+
"the command line arg for filtering tests with a regex pattern",
54+
examples: ["--grep"],
55+
},
56+
tap: {
57+
type: "string",
58+
description:
59+
"The command line arg for configuring a TAP reporter. See https://github.com/sindresorhus/awesome-tap for examples.",
60+
examples: ["--reporter=mocha-tap-reporter"],
61+
},
62+
},
63+
additionalProperties: false,
64+
required: ["tap"],
65+
},
66+
directory: {
67+
type: "string",
68+
description: "An optional folder for the test runner",
69+
examples: ["coderoad"],
70+
},
71+
setup: {
72+
type: "object",
73+
$ref: "#/definitions/setup_action",
74+
description:
75+
"Setup commits or commands used for setting up the test runner on tutorial launch",
76+
},
77+
},
78+
required: ["command", "args"],
79+
},
80+
repo: {
81+
type: "object",
82+
description: "The repo holding the git commits for the tutorial",
83+
properties: {
84+
uri: {
85+
type: "string",
86+
description: "The uri source of the tutorial",
87+
format: "uri",
88+
examples: ["https://github.com/name/tutorial-name.git"],
89+
},
90+
branch: {
91+
description:
92+
"The branch of the repo where the tutorial config file exists",
93+
type: "string",
94+
examples: ["master"],
95+
},
96+
},
97+
additionalProperties: false,
98+
required: ["uri", "branch"],
99+
},
100+
},
101+
dependencies: {
102+
type: "array",
103+
description: "A list of tutorial dependencies",
104+
items: {
105+
type: "object",
106+
properties: {
107+
name: {
108+
type: "string",
109+
description:
110+
"The command line process name of the dependency. It will be checked by running `name --version`",
111+
examples: ["node", "python"],
112+
},
113+
version: {
114+
type: "string",
115+
description:
116+
"The version requirement. See https://github.com/npm/node-semver for options",
117+
examples: [">=10"],
118+
},
119+
},
120+
required: ["name", "version"],
121+
},
122+
},
123+
appVersions: {
124+
type: "object",
125+
description:
126+
"A list of compatable coderoad versions. Currently only a VSCode extension.",
127+
properties: {
128+
vscode: {
129+
type: "string",
130+
description:
131+
"The version range for coderoad-vscode that this tutorial is compatable with",
132+
examples: [">=0.7.0"],
133+
},
134+
},
135+
},
136+
additionalProperties: false,
137+
required: ["testRunner", "repo"],
138+
},
139+
140+
// levels
141+
levels: {
142+
type: "array",
143+
description:
144+
'Levels are the stages a user goes through in the tutorial. A level may contain a group of tasks called "steps" that must be completed to proceed',
145+
items: {
146+
type: "object",
147+
properties: {
148+
title: {
149+
$ref: "#/definitions/title",
150+
description: "A title for the level",
151+
},
152+
summary: {
153+
type: "string",
154+
description: "A high-level summary of the level",
155+
maxLength: 250,
156+
},
157+
content: {
158+
type: "string",
159+
description: "Content for a tutorial written as Markdown",
160+
},
161+
setup: {
162+
$ref: "#/definitions/setup_action",
163+
description:
164+
"An optional point for loading commits, running commands or opening files",
165+
},
166+
steps: {
167+
type: "array",
168+
items: {
169+
type: "object",
170+
properties: {
171+
content: {
172+
type: "string",
173+
description:
174+
"The text displayed explaining information about the current task, written as markdown",
175+
},
176+
setup: {
177+
allOf: [
178+
{
179+
$ref: "#/definitions/setup_action",
180+
description:
181+
"A point for loading commits. It can also run commands and/or open files",
182+
},
183+
{
184+
required: ["commits"],
185+
},
186+
],
187+
},
188+
solution: {
189+
allOf: [
190+
{
191+
$ref: "#/definitions/setup_action",
192+
description:
193+
"The solution commits that can be loaded if the user gets stuck. It can also run commands and/or open files",
194+
},
195+
{
196+
required: ["commits"],
197+
},
198+
],
199+
},
200+
},
201+
required: ["content", "setup", "solution"],
202+
},
203+
},
204+
},
205+
required: ["title", "description", "content"],
206+
},
207+
minItems: 1,
208+
},
209+
},
210+
additionalProperties: false,
211+
required: ["version", "summary", "config", "levels"],
212+
};

0 commit comments

Comments
 (0)