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

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 5 commits intomasterfromfeature/version
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from1 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
PrevPrevious commit
NextNext commit
parser test progress
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
@ShMcK
ShMcK committedMay 31, 2020
commitf5f882c86dfa78d2a86c74aa8164e358e5a03f47
96 changes: 39 additions & 57 deletionssrc/utils/parse.ts
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionstests/parse.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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 DownExpand 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

[8]ページ先頭

©2009-2025 Movatter.jp