Skip to content

Feature/version #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
parser test progress
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed May 31, 2020
commit f5f882c86dfa78d2a86c74aa8164e358e5a03f47
96 changes: 39 additions & 57 deletions src/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ export function parseMdContent(md: string): TutorialFrame | never {

type ParseParams = {
text: string;
config: T.Tutorial;
config: Partial<T.Tutorial | any>;
commits: CommitLogObject;
};

export function parse(params: ParseParams): T.Tutorial {
export function parse(params: ParseParams): any {
const parsed = { ...params.config };

const mdContent: TutorialFrame = parseMdContent(params.text);
Expand All @@ -110,71 +110,53 @@ export function parse(params: ParseParams): T.Tutorial {
if (parsed.levels) {
parsed.levels.forEach((level: T.Level, levelIndex: number) => {
const levelContent = mdContent[level.id];
console.log(levelContent);
if (!levelContent) {
console.log(`Markdown content not found for ${level.id}`);
return;
}
const { steps, ...content } = levelContent;

if (steps) {
steps.forEach((step: T.Step, stepIndex: number) => {
return _.merge(step, steps[step.id]);
// add level setup commits
const levelSetupKey = `L${levelIndex + 1}S`;
if (params.commits[levelSetupKey]) {
if (!level.setup) {
level.setup = {
commits: [],
};
}
level.setup.commits = params.commits[levelSetupKey];
}

// add level step commits
if (levelContent.steps) {
levelContent.steps.forEach((step: T.Step, stepIndex: number) => {
const stepSetupKey = `${levelSetupKey}S${stepIndex + `1`}Q`;
if (params.commits[stepSetupKey]) {
if (!step.setup) {
step.setup = {
commits: [],
};
}
step.setup.commits = params.commits[stepSetupKey];
}

const stepSolutionKey = `${levelSetupKey}S${stepIndex + `1`}A`;
if (params.commits[stepSolutionKey]) {
if (!step.solution) {
step.solution = {
commits: [],
};
}
step.solution.commits = params.commits[stepSolutionKey];
}

return _.merge(step, levelContent.steps[step.id]);
});
}

_.merge(level, content);
_.merge(level);
});
}

return parsed;
}

/*
// Add the content and git hash to the tutorial
if (matches.groups.stepId) {
// If it's a step: add the content and the setup/solution hashes depending on the type
const level: T.Level | null =
tutorial.levels.find(
(level: T.Level) => level.id === matches.groups.levelId
) || null;
if (!level) {
console.log(`Level ${matches.groups.levelId} not found`);
} else {
const theStep: T.Step | null =
level.steps.find(
(step: T.Step) => step.id === matches.groups.stepId
) || null;

if (!theStep) {
console.log(`Step ${matches.groups.stepId} not found`);
} else {
if (matches.groups.stepType === "Q") {
theStep.setup.commits.push(commit.hash.substr(0, 7));
} else if (
matches.groups.stepType === "A" &&
theStep.solution &&
theStep.solution.commits
) {
theStep.solution.commits.push(commit.hash.substr(0, 7));
}
}
}
} else {
// If it's level: add the commit hash (if the level has the commit key) and the content to the tutorial
const theLevel: T.Level | null =
tutorial.levels.find(
(level: T.Level) => level.id === matches.groups.levelId
) || null;

if (!theLevel) {
console.log(`Level ${matches.groups.levelId} not found`);
} else {
if (_.has(theLevel, "tutorial.commits")) {
if (theLevel.setup) {
theLevel.setup.commits.push(commit.hash.substr(0, 7));
}
}
}
}
}
*/
116 changes: 82 additions & 34 deletions tests/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ describe("parse", () => {

`;

const yaml = `version: "0.1.0"`;
const result = parse(md, yaml);
const config = { version: "0.1.0" };
const result = parse({
text: md,
config,
commits: {},
});
const expected = {
summary: {
description: "Short description to be shown as a tutorial's subtitle.",
Expand All @@ -31,11 +35,15 @@ Description.
Some text
`;

const yaml = `version: "0.1.0"
levels:
- id: L1
`;
const result = parse(md, yaml);
const config = {
levels: [{ id: "L1" }],
};

const result = parse({
text: md,
config,
commits: {},
});
const expected = {
levels: [
{
Expand All @@ -62,17 +70,20 @@ Description.
Some text
`;

const yaml = `version: "0.1.0"
levels:
- id: L1
setup:
files: []
commits: []
solution:
files: []
commits: []
`;
const result = parse(md, yaml);
const config = {
levels: [
{
id: "L1",
setup: { files: [], commits: [] },
solution: { files: [], commits: [] },
},
],
};
const result = parse({
text: md,
config,
commits: {},
});
const expected = {
levels: [
{
Expand All @@ -99,11 +110,12 @@ Description.
Some text that becomes the summary
`;

const yaml = `version: "0.1.0"
levels:
- id: L1
`;
const result = parse(md, yaml);
const config = { levels: [{ id: 1 }] };
const result = parse({
text: md,
config,
commits: {},
});
const expected = {
levels: [
{
Expand All @@ -127,11 +139,12 @@ Description.
Some text that becomes the summary and goes beyond the maximum length of 80 so that it gets truncated at the end
`;

const yaml = `version: "0.1.0"
levels:
- id: L1
`;
const result = parse(md, yaml);
const config = { levels: [{ id: "L1" }] };
const result = parse({
text: md,
config,
commits: {},
});
const expected = {
levels: [
{
Expand Down Expand Up @@ -161,11 +174,12 @@ Second line
Third line
`;

const yaml = `version: "0.1.0"
levels:
- id: L1
`;
const result = parse(md, yaml);
const config = { levels: [{ id: "L1" }] };
const result = parse({
text: md,
config,
commits: {},
});
const expected = {
summary: {
description: "Description.\n\nSecond description line",
Expand Down Expand Up @@ -208,7 +222,41 @@ config:
- name: node
version: '>=10'
`;
const result = parse(md, yaml);

const config = {
config: {
testRunner: {
command: "./node_modules/.bin/mocha",
args: {
filter: "--grep",
tap: "--reporter=mocha-tap-reporter",
},
directory: "coderoad",
setup: {
commits: ["abcdefg1"],
commands: [],
},
},
appVersions: {
vscode: ">=0.7.0",
},
repo: {
uri: "https://path.to/repo",
branch: "aBranch",
},
dependencies: [
{
name: "node",
version: ">=10",
},
],
},
};
const result = parse({
text: md,
config,
commits: {},
});
const expected = {
summary: {
description: "Description.\n\nSecond description line",
Expand Down