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

Convert/typescript#3

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 intomasterfromconvert/typescript
May 30, 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
convert to ts
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
@ShMcK
ShMcK committedMay 30, 2020
commit12fb0525f58d4c79b4c6c89ed24a1d74d33b80bf
4 changes: 2 additions & 2 deletionsbin/coderoad
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node

require = require('esm')(module /*, options*/);
require('../src/cli').cli(process.argv);
require = require("esm")(module /*, options*/);
require("../build/cli").cli(process.argv);
6,855 changes: 6,324 additions & 531 deletionspackage-lock.json
View file
Open in desktop

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletionpackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,9 @@
"access": "public"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"build": "del-cli --force ./build && npm run compile",
"compile": "tsc",
"test": "jest"
},
"keywords": [],
"author": "Argemiro Neto",
Expand All@@ -28,10 +30,19 @@
"simple-git": "^2.5.0"
},
"devDependencies": {
"@babel/preset-typescript": "^7.10.1",
"@types/inquirer": "^6.5.0",
"@types/jest": "^25.2.3",
"@types/js-yaml": "^3.12.4",
"@types/lodash": "^4.14.154",
"@types/ncp": "^2.0.4",
"del-cli": "^3.0.1",
"jest": "^26.0.1",
"ts-jest": "^26.0.0",
"typescript": "^3.9.3"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node"
}
}
138 changes: 84 additions & 54 deletionssrc/parse.js → src/build.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
import simpleGit from "simple-git/promise";
import yamlParser from "js-yaml";
import path from "path";
import _ from "lodash";
import fs from "fs";
import * as yamlParser from "js-yaml";
import * as path from "path";
import * as _ from "lodash";
import * as fs from "fs";
import * as T from "../typings/tutorial";
// import validate from './validator';

const workingDir = "tmp";

function parseContent(md) {
let start = -1;
const parts = [];
type TutorialContent = {};

function parseContent(md: string): TutorialContent {
let start: number = -1;
const parts: any[] = [];

const lines = md.split("\n");

Expand DownExpand Up@@ -76,7 +79,7 @@ function parseContent(md) {
return sections;
}

function rmDir(dir, rmSelf) {
function rmDir(dir: string, rmSelf = false) {
try {
let files;
rmSelf = rmSelf === undefined ? true : rmSelf;
Expand All@@ -89,11 +92,11 @@ function rmDir(dir, rmSelf) {
}

if (files.length > 0) {
files.forEach(function (x, i) {
if (fs.statSync(path.join(dir,x)).isDirectory()) {
rmDir(path.join(dir,x));
files.forEach(function (filePath: string) {
if (fs.statSync(path.join(dir,filePath)).isDirectory()) {
rmDir(path.join(dir,filePath));
} else {
fs.unlinkSync(path.join(dir,x));
fs.unlinkSync(path.join(dir,filePath));
}
});
}
Expand All@@ -107,7 +110,7 @@ function rmDir(dir, rmSelf) {
}
}

async function cleanupFiles(workingDir) {
async function cleanupFiles(workingDir: string) {
try {
const gitModule = simpleGit(process.cwd());

Expand All@@ -121,17 +124,18 @@ async function cleanupFiles(workingDir) {
}
}

/**
*
* @param {string} repo Git url to the repo. It should finish with .git
* @param {string} codeBranch The branch containing the tutorial code
* @param {string} setupBranch The branch containing the configuration files
* @param {string} isLocal define if the repo is local or remote
*/
async function build({ repo, codeBranch, setupBranch, isLocal }) {
let git;
export type BuildOptions = {
repo: string; // Git url to the repo. It should finish with .git
codeBranch: string; // The branch containing the tutorial code
setupBranch: string; // The branch containing the tutorialuration files
isLocal: boolean; // define if the repo is local or remote
output: string;
};

async function build({ repo, codeBranch, setupBranch, isLocal }: BuildOptions) {
let git: any;
let isSubModule = false;
let localPath;
let localPath: string;

if (isLocal) {
git = simpleGit(repo);
Expand All@@ -154,30 +158,35 @@ async function build({ repo, codeBranch, setupBranch, isLocal }) {

await git.fetch();

// checkout the branch to loadconfiguration and content branch
// checkout the branch to loadtutorialuration and content branch
await git.checkout(setupBranch);

// Load files
const _mdContent = fs.readFileSync(
path.join(localPath, "TUTORIAL.md"),
"utf8"
);
let _config = fs.readFileSync(path.join(localPath, "coderoad.yaml"), "utf8");
let _tutorial = fs.readFileSync(
path.join(localPath, "coderoad.yaml"),
"utf8"
);

// Add one more line to the content as per Shawn's request
const mdContent = parseContent(_mdContent);
const mdContent: any = parseContent(_mdContent);

// Parse config to JSON
const config = yamlParser.load(_config);
console.log(mdContent);

//Add the summarytothe config file
config["summary"] = mdContent.summary;
//Parse tutorialtoJSON
const tutorial: T.Tutorial = yamlParser.load(_tutorial);

// merge content and config
config.levels.forEach((level) => {
// Add the summary to the tutorial file
tutorial.summary = mdContent.summary;

// merge content and tutorial
tutorial.levels.forEach((level: T.Level) => {
const { steps, ...content } = mdContent[level.id];

level.steps.forEach((step) => _.merge(step, steps[step.id]));
level.steps.forEach((step: T.Step) => _.merge(step, steps[step.id]));

_.merge(level, content);
});
Expand All@@ -200,29 +209,50 @@ async function build({ repo, codeBranch, setupBranch, isLocal }) {
// Uses a set to make sure only the latest commit is proccessed
parts.add(matches[0]);

// Add the content and git hash to theconfig
// Add the content and git hash to thetutorial
if (matches.groups.stepId) {
// If it's a step: add the content and the setup/solution hashes depending on the type
const theStep = config.levels
.find((level) => level.id === matches.groups.levelId)
.steps.find((step) => step.id === matches.groups.stepId);

if (matches.groups.stepType === "Q") {
theStep.setup.commits.push(commit.hash.substr(0, 7));
} else if (
matches.groups.stepType === "A" &&
theStep.solution.commits
) {
theStep.solution.commits.push(commit.hash.substr(0, 7));
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 config
const theLevel = config.levels.find(
(level) => level.id === matches.groups.levelId
);

if (_.has(theLevel, "config.commits")) {
theLevel.setup.commits.push(commit.hash.substr(0, 7));
// 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));
}
}
}
}
}
Expand All@@ -247,14 +277,14 @@ async function build({ repo, codeBranch, setupBranch, isLocal }) {
}
}

// const isValid = validate(config);
// const isValid = validate(tutorial);

// if (!isValid) {
// console.log(JSON.stringify(validate.errors, null, 2));
// return;
// }

returnconfig;
returntutorial;
}

export default build;
Loading

[8]ページ先頭

©2009-2025 Movatter.jp