Skip to content

Commit 20a4083

Browse files
authored
Merge pull request #50 from coderoad/fixes
Fixes
2 parents a00362b + ef3666d commit 20a4083

File tree

6 files changed

+86
-11
lines changed

6 files changed

+86
-11
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing 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.4.1",
3+
"version": "0.4.2",
44
"description": "A CLI to build the configuration file for Coderoad Tutorials",
55
"keywords": [
66
"coderoad",

src/utils/parse.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export function parse(params: ParseParams): any {
140140
// add level step commits
141141
const { steps, ...configLevelProps } = configLevel;
142142
level = { ...configLevelProps, ...level };
143+
143144
if (steps) {
144145
steps.forEach((step: T.Step, index: number) => {
145146
try {
@@ -151,12 +152,14 @@ export function parse(params: ParseParams): any {
151152
};
152153

153154
const stepSetupKey = `${step.id}:T`;
155+
156+
if (!step?.setup) {
157+
step.setup = {};
158+
}
159+
if (!step.setup.commits) {
160+
step.setup.commits = [];
161+
}
154162
if (params.commits[stepSetupKey]) {
155-
if (!step.setup) {
156-
step.setup = {
157-
commits: [],
158-
};
159-
}
160163
step.setup.commits = params.commits[stepSetupKey];
161164
}
162165

src/utils/validateMarkdown.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,17 @@ const codeBlockRegex = /```[a-z]*\n[\s\S]*?\n```/gm;
5353

5454
export function validateMarkdown(md: string): boolean {
5555
// remove codeblocks which might contain any valid combinations
56-
const text = md.replace(codeBlockRegex, "");
56+
// trim white space
57+
const text = md.replace(codeBlockRegex, "").trim();
5758

5859
let valid = true;
5960

6061
for (const v of validations) {
6162
if (!v.validate(text)) {
6263
valid = false;
63-
// if (process.env.NODE_ENV !== "test") {
64-
console.warn(v.message);
65-
// }
64+
if (process.env.NODE_ENV !== "test") {
65+
console.warn(v.message);
66+
}
6667
}
6768
}
6869

tests/markdown.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,26 @@ Should not be an issue
132132
First Step`;
133133
expect(validateMarkdown(md)).toBe(true);
134134
});
135+
it("should ignore empty space at the top", () => {
136+
const md = `
137+
138+
# Title
139+
140+
Description.`;
141+
expect(validateMarkdown(md)).toBe(true);
142+
});
143+
it("should ignore empty space at the bottom", () => {
144+
const md = `
145+
146+
# Title
147+
148+
Description.
149+
150+
151+
152+
153+
154+
`;
155+
expect(validateMarkdown(md)).toBe(true);
156+
});
135157
});

tests/parse.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,55 @@ The first step
786786
};
787787
expect(result.levels).toEqual(expected.levels);
788788
});
789+
it("should load no commits if none found for a step", () => {
790+
const md = `# Title
791+
792+
Description.
793+
794+
## 1. Title
795+
796+
First line
797+
798+
### 1.1
799+
800+
The first step
801+
`;
802+
const skeleton = {
803+
levels: [
804+
{
805+
id: "1",
806+
steps: [{ id: "1" }],
807+
},
808+
],
809+
};
810+
const result = parse({
811+
text: md,
812+
skeleton,
813+
commits: {},
814+
});
815+
const expected = {
816+
summary: {
817+
description: "Description.",
818+
},
819+
levels: [
820+
{
821+
id: "1",
822+
summary: "First line",
823+
content: "First line",
824+
steps: [
825+
{
826+
id: "1.1",
827+
content: "The first step",
828+
setup: {
829+
commits: [],
830+
},
831+
},
832+
],
833+
},
834+
],
835+
};
836+
expect(result.levels[0].steps[0]).toEqual(expected.levels[0].steps[0]);
837+
});
789838
});
790839

791840
describe("config", () => {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy