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

Commitcc36f25

Browse files
authored
Merge pull request#13 from coderoad/fixes
Fixes
2 parents86c5a2a +9344d9d commitcc36f25

File tree

9 files changed

+112
-23
lines changed

9 files changed

+112
-23
lines changed

‎package-lock.json

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

‎package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"esm":"^3.2.25",
2525
"inquirer":"^7.1.0",
2626
"js-yaml":"^3.14.0",
27+
"kleur":"^3.0.3",
2728
"listr":"^0.14.3",
2829
"lodash":"^4.17.15",
2930
"ncp":"^2.0.0",

‎src/build.ts

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,72 @@ const parseArgs = (args: string[]): BuildArgs => {
4646
};
4747

4848
asyncfunctionbuild(args:string[]){
49-
constoptions=parseArgs(args);
49+
letoptions:BuildArgs;
50+
try{
51+
options=parseArgs(args);
52+
}catch(e){
53+
console.error("Error parsing build logs");
54+
console.error(e.message);
55+
return;
56+
}
5057

5158
// path to run build from
5259
constlocalPath=path.join(process.cwd(),options.dir);
5360

5461
// load files
55-
const[_markdown,_yaml]=awaitPromise.all([
56-
read(path.join(localPath,options.markdown),"utf8"),
57-
read(path.join(localPath,options.yaml),"utf8"),
58-
]);
62+
let_markdown:string;
63+
let_yaml:string;
64+
try{
65+
[_markdown,_yaml]=awaitPromise.all([
66+
read(path.join(localPath,options.markdown),"utf8"),
67+
read(path.join(localPath,options.yaml),"utf8"),
68+
]);
69+
}catch(e){
70+
console.error("Error reading file:");
71+
console.error(e.message);
72+
return;
73+
}
5974

60-
constconfig=yamlParser.load(_yaml);
75+
letconfig;
76+
try{
77+
config=yamlParser.load(_yaml);
78+
}catch(e){
79+
console.error("Error parsing yaml");
80+
console.error(e.message);
81+
}
6182

62-
constcommits:CommitLogObject=awaitgetCommits(config.config.repo.branch);
83+
letcommits:CommitLogObject;
84+
try{
85+
commits=awaitgetCommits({
86+
localDir:localPath,
87+
codeBranch:config.config.repo.branch,
88+
});
89+
}catch(e){
90+
console.error("Error loading commits:");
91+
console.error(e.message);
92+
return;
93+
}
6394

6495
// Otherwise, continue with the other options
65-
consttutorial:T.Tutorial=awaitparse({
66-
text:_markdown,
67-
config,
68-
commits,
69-
});
96+
lettutorial:T.Tutorial;
97+
try{
98+
tutorial=awaitparse({
99+
text:_markdown,
100+
config,
101+
commits,
102+
});
103+
}catch(e){
104+
console.error("Error parsing tutorial:");
105+
console.error(e.message);
106+
return;
107+
}
70108

71109
if(tutorial){
72-
if(options.output){
110+
try{
73111
awaitwrite(options.output,JSON.stringify(tutorial),"utf8");
74-
}else{
75-
console.log(JSON.stringify(tutorial,null,2));
112+
}catch(e){
113+
console.error("Error writing tutorial json:");
114+
console.error(e.message);
76115
}
77116
}
78117
}

‎src/cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import"./utils/logs";
12
importbuildfrom"./build";
23
importcreatefrom"./create";
4+
importhelpfrom"./help";
35

46
exportasyncfunctioncli(rawArgs:string[]):Promise<void>{
57
constcommand:string=rawArgs[2];
@@ -23,8 +25,6 @@ export async function cli(rawArgs: string[]): Promise<void> {
2325
case"--help":
2426
case"-h":
2527
default:
26-
console.log(
27-
"Docs can be found at github: https://github.com/coderoad/coderoad-cli/"
28-
);
28+
help();
2929
}
3030
}

‎src/help.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
exportdefaultfunctionhelp(){
2+
console.log(`
3+
Usage: coderoad [options]
4+
5+
Options:
6+
help display these help docs
7+
version show coderoad cli version
8+
create start a new tutorial from a template
9+
build generate a coderoad.json file from markdown and yaml
10+
11+
More docs at https://github.com/coderoad/coderoad-cli
12+
`);
13+
}

‎src/utils/commits.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,26 @@ export async function getCommits({
3737
consttempGit=gitP(tmpDir);
3838
awaittempGit.clone(localDir,tmpDir);
3939

40+
constbranches=awaitgit.branch();
41+
42+
if(!branches.all.length){
43+
thrownewError("No branches found");
44+
}elseif(!branches.all.includes(codeBranch)){
45+
thrownewError(`Code branch "${codeBranch}" not found`);
46+
}
47+
48+
console.log("branches",branches);
49+
4050
// Checkout the code branches
4151
awaitgit.checkout(codeBranch);
4252

53+
console.log("checked out");
54+
4355
// Load all logs
4456
constlogs=awaitgit.log();
4557

58+
console.log("logs",logs);
59+
4660
// Filter relevant logs
4761
constcommits:CommitLogObject={};
4862

@@ -63,6 +77,8 @@ export async function getCommits({
6377
}
6478
}
6579
}
80+
81+
console.log("remove");
6682
// cleanup the tmp directory
6783
awaitrmdir(tmpDir,{recursive:true});
6884
returncommits;

‎src/utils/logs.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import{red,yellow,blue}from"kleur";
2+
3+
const_error=console.error;
4+
const_warn=console.warn;
5+
const_info=console.info;
6+
// const log = console.log;
7+
8+
console.error=function(){
9+
//@ts-ignore
10+
_error(red.apply(console,arguments));
11+
};
12+
13+
console.warn=function(){
14+
//@ts-ignore
15+
_warn(yellow.apply(console,arguments));
16+
};
17+
18+
console.info=function(){
19+
//@ts-ignore
20+
_info(blue.apply(console,arguments));
21+
};

‎tests/parse.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ describe("parse", () => {
55
it("should parse summary",()=>{
66
constmd=`# Insert Tutorial's Title here
77
8-
Short description to be shown as a tutorial's subtitle.
8+
Short description to be shown as a tutorial's subtitle.
99
10-
`;
10+
`;
1111

1212
constconfig={version:"0.1.0"};
1313
constresult=parse({

‎tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
"skipLibCheck":true,
2424
"esModuleInterop":true
2525
},
26-
"exclude": ["node_modules",".vscode","bin","build","tests"]
26+
"exclude": ["node_modules",".vscode","bin","build","tests","coverage"]
2727
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp