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

Commite27add1

Browse files
authored
Merge pull request#3 from coderoad/convert/typescript
Convert/typescript
2 parentsdc0e70a +aeaab0b commite27add1

File tree

12 files changed

+6369
-340
lines changed

12 files changed

+6369
-340
lines changed

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
build
12
node_modules

‎.vscode/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"source.organizeImports":false,
55
"source.fixAll":true
66
},
7-
"eslint.validate": ["javascript"],
7+
"eslint.validate": ["javascript","typescript"],
88
"files.exclude": {},
9-
"git.alwaysSignOff":true
9+
"git.alwaysSignOff":true,
10+
"typescript.tsdk":"./node_modules/typescript/lib"
1011
}

‎bin/coderoad

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env node
22

3-
require=require('esm')(module/*, options*/);
4-
require('../src/cli').cli(process.argv);
3+
require=require("esm")(module/*, options*/);
4+
require("../build/cli").cli(process.argv);

‎package-lock.json

Lines changed: 6068 additions & 223 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎package.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"access":"public"
1212
},
1313
"scripts": {
14-
"test":"echo\"Error: no test specified\" && exit 1"
14+
"build":"del-cli --force ./build && npm run compile",
15+
"compile":"tsc",
16+
"test":"jest"
1517
},
1618
"keywords": [],
1719
"author":"Argemiro Neto",
@@ -26,5 +28,21 @@
2628
"ncp":"^2.0.0",
2729
"npc":"0.0.1",
2830
"simple-git":"^2.5.0"
31+
},
32+
"devDependencies": {
33+
"@babel/preset-typescript":"^7.10.1",
34+
"@types/inquirer":"^6.5.0",
35+
"@types/jest":"^25.2.3",
36+
"@types/js-yaml":"^3.12.4",
37+
"@types/lodash":"^4.14.154",
38+
"@types/ncp":"^2.0.4",
39+
"del-cli":"^3.0.1",
40+
"jest":"^26.0.1",
41+
"ts-jest":"^26.0.0",
42+
"typescript":"^3.9.3"
43+
},
44+
"jest": {
45+
"preset":"ts-jest",
46+
"testEnvironment":"node"
2947
}
3048
}

‎src/parse.jsrenamed to‎src/build.ts

Lines changed: 85 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
importsimpleGitfrom"simple-git/promise";
2-
importyamlParserfrom"js-yaml";
3-
importpathfrom"path";
4-
import_from"lodash";
5-
importfsfrom"fs";
1+
import*asyamlParserfrom"js-yaml";
2+
import*aspathfrom"path";
3+
import*as_from"lodash";
4+
import*asfsfrom"fs";
5+
import*asTfrom"../typings/tutorial";
66
// import validate from './validator';
77

8+
// import not working
9+
constsimpleGit=require("simple-git/promise");
10+
811
constworkingDir="tmp";
912

10-
functionparseContent(md){
11-
letstart=-1;
12-
constparts=[];
13+
typeTutorialContent={};
14+
15+
functionparseContent(md:string):TutorialContent{
16+
letstart:number=-1;
17+
constparts:any[]=[];
1318

1419
constlines=md.split("\n");
1520

@@ -76,7 +81,7 @@ function parseContent(md) {
7681
returnsections;
7782
}
7883

79-
functionrmDir(dir,rmSelf){
84+
functionrmDir(dir:string,rmSelf=false){
8085
try{
8186
letfiles;
8287
rmSelf=rmSelf===undefined ?true :rmSelf;
@@ -89,11 +94,11 @@ function rmDir(dir, rmSelf) {
8994
}
9095

9196
if(files.length>0){
92-
files.forEach(function(x,i){
93-
if(fs.statSync(path.join(dir,x)).isDirectory()){
94-
rmDir(path.join(dir,x));
97+
files.forEach(function(filePath:string){
98+
if(fs.statSync(path.join(dir,filePath)).isDirectory()){
99+
rmDir(path.join(dir,filePath));
95100
}else{
96-
fs.unlinkSync(path.join(dir,x));
101+
fs.unlinkSync(path.join(dir,filePath));
97102
}
98103
});
99104
}
@@ -107,7 +112,7 @@ function rmDir(dir, rmSelf) {
107112
}
108113
}
109114

110-
asyncfunctioncleanupFiles(workingDir){
115+
asyncfunctioncleanupFiles(workingDir:string){
111116
try{
112117
constgitModule=simpleGit(process.cwd());
113118

@@ -121,17 +126,18 @@ async function cleanupFiles(workingDir) {
121126
}
122127
}
123128

124-
/**
125-
*
126-
*@param {string} repo Git url to the repo. It should finish with .git
127-
*@param {string} codeBranch The branch containing the tutorial code
128-
*@param {string} setupBranch The branch containing the configuration files
129-
*@param {string} isLocal define if the repo is local or remote
130-
*/
131-
asyncfunctionbuild({ repo, codeBranch, setupBranch, isLocal}){
132-
letgit;
129+
exporttypeBuildOptions={
130+
repo:string;// Git url to the repo. It should finish with .git
131+
codeBranch:string;// The branch containing the tutorial code
132+
setupBranch:string;// The branch containing the tutorialuration files
133+
isLocal:boolean;// define if the repo is local or remote
134+
output:string;
135+
};
136+
137+
asyncfunctionbuild({ repo, codeBranch, setupBranch, isLocal}:BuildOptions){
138+
letgit:any;
133139
letisSubModule=false;
134-
letlocalPath;
140+
letlocalPath:string;
135141

136142
if(isLocal){
137143
git=simpleGit(repo);
@@ -154,30 +160,33 @@ async function build({ repo, codeBranch, setupBranch, isLocal }) {
154160

155161
awaitgit.fetch();
156162

157-
// checkout the branch to loadconfiguration and content branch
163+
// checkout the branch to loadtutorialuration and content branch
158164
awaitgit.checkout(setupBranch);
159165

160166
// Load files
161167
const_mdContent=fs.readFileSync(
162168
path.join(localPath,"TUTORIAL.md"),
163169
"utf8"
164170
);
165-
let_config=fs.readFileSync(path.join(localPath,"coderoad.yaml"),"utf8");
171+
let_tutorial=fs.readFileSync(
172+
path.join(localPath,"coderoad.yaml"),
173+
"utf8"
174+
);
166175

167176
// Add one more line to the content as per Shawn's request
168-
constmdContent=parseContent(_mdContent);
177+
constmdContent:any=parseContent(_mdContent);
169178

170-
// Parseconfig to JSON
171-
constconfig=yamlParser.load(_config);
179+
// Parsetutorial to JSON
180+
consttutorial:T.Tutorial=yamlParser.load(_tutorial);
172181

173-
// Add the summary to theconfig file
174-
config["summary"]=mdContent.summary;
182+
// Add the summary to thetutorial file
183+
tutorial.summary=mdContent.summary;
175184

176-
// merge content andconfig
177-
config.levels.forEach((level)=>{
185+
// merge content andtutorial
186+
tutorial.levels.forEach((level:T.Level)=>{
178187
const{ steps, ...content}=mdContent[level.id];
179188

180-
level.steps.forEach((step)=>_.merge(step,steps[step.id]));
189+
level.steps.forEach((step:T.Step)=>_.merge(step,steps[step.id]));
181190

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

203-
// Add the content and git hash to theconfig
212+
// Add the content and git hash to thetutorial
204213
if(matches.groups.stepId){
205214
// If it's a step: add the content and the setup/solution hashes depending on the type
206-
consttheStep=config.levels
207-
.find((level)=>level.id===matches.groups.levelId)
208-
.steps.find((step)=>step.id===matches.groups.stepId);
209-
210-
if(matches.groups.stepType==="Q"){
211-
theStep.setup.commits.push(commit.hash.substr(0,7));
212-
}elseif(
213-
matches.groups.stepType==="A"&&
214-
theStep.solution.commits
215-
){
216-
theStep.solution.commits.push(commit.hash.substr(0,7));
215+
constlevel:T.Level|null=
216+
tutorial.levels.find(
217+
(level:T.Level)=>level.id===matches.groups.levelId
218+
)||null;
219+
if(!level){
220+
console.log(`Level${matches.groups.levelId} not found`);
221+
}else{
222+
consttheStep:T.Step|null=
223+
level.steps.find(
224+
(step:T.Step)=>step.id===matches.groups.stepId
225+
)||null;
226+
227+
if(!theStep){
228+
console.log(`Step${matches.groups.stepId} not found`);
229+
}else{
230+
if(matches.groups.stepType==="Q"){
231+
theStep.setup.commits.push(commit.hash.substr(0,7));
232+
}elseif(
233+
matches.groups.stepType==="A"&&
234+
theStep.solution&&
235+
theStep.solution.commits
236+
){
237+
theStep.solution.commits.push(commit.hash.substr(0,7));
238+
}
239+
}
217240
}
218241
}else{
219-
// If it's level: add the commit hash (if the level has the commit key) and the content to the config
220-
consttheLevel=config.levels.find(
221-
(level)=>level.id===matches.groups.levelId
222-
);
223-
224-
if(_.has(theLevel,"config.commits")){
225-
theLevel.setup.commits.push(commit.hash.substr(0,7));
242+
// If it's level: add the commit hash (if the level has the commit key) and the content to the tutorial
243+
consttheLevel:T.Level|null=
244+
tutorial.levels.find(
245+
(level:T.Level)=>level.id===matches.groups.levelId
246+
)||null;
247+
248+
if(!theLevel){
249+
console.log(`Level${matches.groups.levelId} not found`);
250+
}else{
251+
if(_.has(theLevel,"tutorial.commits")){
252+
if(theLevel.setup){
253+
theLevel.setup.commits.push(commit.hash.substr(0,7));
254+
}
255+
}
226256
}
227257
}
228258
}
@@ -247,14 +277,14 @@ async function build({ repo, codeBranch, setupBranch, isLocal }) {
247277
}
248278
}
249279

250-
// const isValid = validate(config);
280+
// const isValid = validate(tutorial);
251281

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

257-
returnconfig;
287+
returntutorial;
258288
}
259289

260290
exportdefaultbuild;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp