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

Commit8041a08

Browse files
authored
Merge pull request#16 from coderoad/fix/create
fix coderoad create
2 parents12fa899 +60367b2 commit8041a08

File tree

10 files changed

+89
-45
lines changed

10 files changed

+89
-45
lines changed

‎package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name":"@coderoad/cli",
3-
"version":"0.1.1",
3+
"version":"0.1.2",
44
"description":"A CLI to build the configuration file for Coderoad Tutorials",
55
"keywords": [
66
"coderoad",

‎src/build.ts

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,28 @@ type BuildArgs = {
2525
output:string;
2626
};
2727

28-
constparseArgs=(args:string[]):BuildArgs=>{
29-
// default .
30-
constdir=args[0]||".";
31-
32-
// -m --markdown - default TUTORIAL.md
33-
constmarkdown=
34-
getArg(args,{name:"markdown",alias:"m"})||"TUTORIAL.md";
35-
// -y --yaml - default coderoad-config.yml
36-
constyaml=getArg(args,{name:"yaml",alias:"y"})||"coderoad.yaml";
37-
// -o --output - default coderoad.json
38-
constoutput=
39-
getArg(args,{name:"output",alias:"o"})||"tutorial.json";
40-
41-
return{
42-
dir,
43-
output,
44-
markdown,
45-
yaml,
46-
};
47-
};
48-
4928
asyncfunctionbuild(args:string[]){
5029
letoptions:BuildArgs;
5130
try{
52-
options=parseArgs(args);
31+
// default .
32+
constdir=args[0].match(/^-/) ?"." :args[0];
33+
// -m --markdown - default TUTORIAL.md
34+
constmarkdown=
35+
getArg(args,{name:"markdown",alias:"m"})||"TUTORIAL.md";
36+
// -y --yaml - default coderoad-config.yml
37+
constyaml=getArg(args,{name:"yaml",alias:"y"})||"coderoad.yaml";
38+
// -o --output - default coderoad.json
39+
constoutput=
40+
getArg(args,{name:"output",alias:"o"})||"tutorial.json";
41+
42+
console.log(`Building CodeRoad${output}...`);
43+
44+
options={
45+
dir,
46+
output,
47+
markdown,
48+
yaml,
49+
};
5350
}catch(e){
5451
console.error("Error parsing build logs");
5552
console.error(e.message);

‎src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function cli(rawArgs: string[]): Promise<void> {
1919
break;
2020

2121
case"create":
22-
create(process.cwd());
22+
create(args);
2323
break;
2424

2525
case"--help":

‎src/create.ts

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,75 @@
11
importncpfrom"ncp";
22
import*aspathfrom"path";
33
import{promisify}from"util";
4+
import{getArg}from"./utils/args";
45

56
constcopy=promisify(ncp);
67

7-
constcopyFiles=async(filePath:string):Promise<void>=>{
8+
typeCreateArgs={
9+
dir:string;
10+
lang:string;
11+
testRunner:string;
12+
};
13+
14+
asyncfunctioncreate(args:string[]):Promise<void>{
15+
letoptions:CreateArgs;
16+
17+
// default .
18+
constdir=!args.length||args[0].match(/^-/) ?"." :args[0];
19+
constlang=getArg(args,{name:"lang",alias:"l"})||"js";
20+
consttestRunner=
21+
getArg(args,{name:"testRunner",alias:"t"})||"mocha";
22+
23+
// validate lang
24+
if(!["js"].includes(lang)){
25+
thrownewError(`Language${lang} not supported yet in create`);
26+
}
27+
28+
// validate test runner
29+
if(!["mocha"].includes(testRunner)){
30+
thrownewError(`Test Runner${testRunner} not supported yet in create`);
31+
}
32+
33+
console.info(`Creating CodeRoad project for${lang}${testRunner}`);
34+
35+
options={
36+
dir,
37+
lang,
38+
testRunner,
39+
};
40+
41+
constlocalPath=path.join(process.cwd(),options.dir);
42+
43+
// TODO: git init ?
44+
45+
// copy tutorial file
46+
constpathToSrc=path.join(__dirname,"..","src");
47+
consttemplateDirectory=path.resolve(pathToSrc,"templates");
48+
49+
constmarkdownPath=path.join(templateDirectory,"TUTORIAL.md");
50+
consttargetMarkdownPath=path.join(localPath,"TUTORIAL.md");
851
try{
9-
constpathToSrc=path.join(__dirname,"..","src");
10-
consttemplateDirectory=path.resolve(pathToSrc,"templates");
11-
consttargetDirectory=process.cwd();
52+
awaitcopy(markdownPath,targetMarkdownPath,{
53+
clobber:false,
54+
});
55+
}catch(e){
56+
console.error("Error on creating markdown file");
57+
console.error(e.message);
58+
}
1259

13-
awaitcopy(templateDirectory,targetDirectory,{
60+
// TODO: copy master yaml
61+
constpathToYaml=path.join(templateDirectory,`${lang}-${testRunner}`);
62+
consttargetYamlPath=path.join(localPath,"coderoad.yaml");
63+
try{
64+
awaitcopy(pathToYaml,targetYamlPath,{
1465
clobber:false,
1566
});
1667
}catch(e){
17-
console.log("Error on creatingthe files:");
18-
console.log(JSON.stringify(e,null,1));
68+
console.error("Error on creatingyaml file");
69+
console.error(e.message);
1970
}
20-
};
2171

22-
constcreate=copyFiles;
72+
// TODO: copy code files with commits
73+
}
2374

2475
exportdefaultcreate;
File renamed without changes.
File renamed without changes.

‎src/templates/TUTORIAL.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,37 @@
22

33
Short description to be shown as a tutorial's subtitle
44

5-
65
##L1 Put Level's title here
76

87
>Level's summary: a short description of the level's content in one line.
98
10-
The level is identified and distributed following the regex:
9+
The level is identified and distributed following the regex:
1110

1211
```js
13-
/^(##\s(?<levelId>L\d+)\s(?<levelTitle>.*)\n*(>\s*(?<levelSummary>.*))?\n+(?<levelContent>[^]*))/
12+
/^(##\s(?<levelId>L\d+)\s(?<levelTitle>.*)\n*(>\s*(?<levelSummary>.*))?\n+(?<levelContent>[^]*))/;
1413
```
1514

1615
The Level can be split into steps or have no steps. Levels without steps are meant to be used as only informative content, for example: use a Level without steps at the end of the tutorial to congratulate the student and provide some additional related resources.
1716

18-
Tutorial's content. It can span through multiple paragraphs and use headers`####` and`#####`.
17+
Tutorial's content. It can span through multiple paragraphs and use headers`####` and`#####`.
1918

2019
Steps are identified and their content described using the following regex:
2120

2221
```js
23-
/^(###\s(?<stepId>(?<levelId>L\d+)S\d+)\s(?<stepTitle>.*)\n+(?<stepContent>[^]*))/
22+
/^(###\s(?<stepId>(?<levelId>L\d+)S\d+)\s(?<stepTitle>.*)\n+(?<stepContent>[^]*))/;
2423
```
2524

2625
The numbers identifying the levels and steps are irrelevant but keep in mind that they will be executed in order. A level with id`10` will be executed before another one with id`20` and so on. These`ids` should have a match in the configuration file (`coderoad.yaml`).
2726

28-
2927
###L1S1 A step title (not being shown on the extension at this moment)
3028

3129
Short description of the step's purpose. Should be short and fit in one line
3230

3331
**Important**
32+
3433
1. Both level and step ids must have an entry with the same id on the configuration file;
3534
2. Step Ids are based on its level id. Any step from level`L234` must start with`L234S`, followed by the sequential digits.
3635

37-
3836
###L1S2 Another step
3937

40-
Step's short description.
38+
Step's short description.

‎src/templates/coderoad.yamlrenamed to‎src/templates/js-mocha/coderoad.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ config:
2121
## Commits to load to setup the test runner. Optional.
2222
##
2323
setup:
24-
## A list of commits to load to setup the tutorial
25-
commits:[]
2624
# - commit1
2725
# - commit2
2826
## A list of commands to run to configure the tutorial

‎src/utils/validate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
importschemafrom"./schema";
1+
importschemafrom"../schema";
22

33
// https://www.npmjs.com/package/ajv
44
//@ts-ignore ajv typings not working

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp