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

Commitc66722b

Browse files
committed
code cleanup
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent14afae3 commitc66722b

File tree

4 files changed

+33
-36
lines changed

4 files changed

+33
-36
lines changed

‎src/build.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import*asyamlParserfrom'js-yaml'
2-
import*aspathfrom'path'
3-
import*asfsfrom'fs'
4-
import*asutilfrom'util'
1+
import{load}from'js-yaml'
2+
import{join}from'path'
3+
import{writeFile,readFile}from'fs'
4+
import{promisify}from'util'
55
import{parse}from'./utils/parse'
66
import{getArg}from'./utils/args'
77
import{getCommits,CommitLogObject}from'./utils/commits'
@@ -11,8 +11,8 @@ import { validateSchema } from './utils/validateSchema'
1111
import{validateMarkdown}from'./utils/validateMarkdown'
1212
import*asTfrom'../typings/tutorial'
1313

14-
constwrite=util.promisify(fs.writeFile)
15-
constread=util.promisify(fs.readFile)
14+
constwrite=promisify(writeFile)
15+
constread=promisify(readFile)
1616

1717
exporttypeBuildConfigOptions={
1818
text:string// text document from markdown
@@ -60,15 +60,15 @@ async function build (args: string[]) {
6060
}
6161

6262
// path to run build from
63-
constlocalPath=path.join(process.cwd(),options.dir)
63+
constlocalPath=join(process.cwd(),options.dir)
6464

6565
// load markdown and files
6666
let_markdown:string
6767
let_yaml:string
6868
try{
6969
;[_markdown,_yaml]=awaitPromise.all([
70-
read(path.join(localPath,options.markdown),'utf8'),
71-
read(path.join(localPath,options.yaml),'utf8')
70+
read(join(localPath,options.markdown),'utf8'),
71+
read(join(localPath,options.yaml),'utf8')
7272
])
7373
}catch(e){
7474
console.error('Error reading file:')
@@ -91,7 +91,7 @@ async function build (args: string[]) {
9191
// parse yaml skeleton config
9292
letskeleton
9393
try{
94-
skeleton=yamlParser.load(_yaml)asT.TutorialSkeleton
94+
skeleton=load(_yaml)asT.TutorialSkeleton
9595
if(!skeleton||!Object.keys(skeleton).length){
9696
thrownewError(`Skeleton at "${options.yaml}" is invalid`)
9797
}

‎src/utils/commits.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import*asfsfrom'fs'
1+
import{mkdir,exists,rmdir}from'fs'
22
importutilfrom'util'
33
import*aspathfrom'path'
4-
import{ListLogSummary}from'simple-git/typings/response'
4+
import{LogResult}from'simple-git/typings/response'
55
importgitP,{SimpleGit}from'simple-git/promise'
66
import{validateCommitOrder}from'./validateCommits'
77

8-
constmkdir=util.promisify(fs.mkdir)
9-
constexists=util.promisify(fs.exists)
10-
constrmdir=util.promisify(fs.rmdir)
8+
constmkdirPromise=util.promisify(mkdir)
9+
constexistsPromise=util.promisify(exists)
10+
constrmdirPromise=util.promisify(rmdir)
1111

1212
typeGetCommitOptions={
1313
localDir:string
@@ -17,7 +17,7 @@ type GetCommitOptions = {
1717
exporttypeCommitLogObject={[position:string]:string[]}
1818

1919
exportfunctionparseCommits(
20-
logs:ListLogSummary<any>
20+
logs:LogResult<any>
2121
):{[hash:string]:string[]}{
2222
// Filter relevant logs
2323
constcommits:CommitLogObject={}
@@ -78,11 +78,11 @@ export async function getCommits ({
7878

7979
// setup .tmp directory
8080
consttmpDir=path.join(localDir,'.tmp')
81-
consttmpDirExists=awaitexists(tmpDir)
81+
consttmpDirExists=awaitexistsPromise(tmpDir)
8282
if(tmpDirExists){
83-
awaitrmdir(tmpDir,{recursive:true})
83+
awaitrmdirPromise(tmpDir,{recursive:true})
8484
}
85-
awaitmkdir(tmpDir)
85+
awaitmkdirPromise(tmpDir)
8686

8787
consttempGit=gitP(tmpDir)
8888
awaittempGit.clone(localDir,tmpDir)
@@ -115,6 +115,6 @@ export async function getCommits ({
115115
// revert back to the original branch on failure
116116
awaitgit.checkout(originalBranch)
117117
// cleanup the tmp directory
118-
awaitrmdir(tmpDir,{recursive:true})
118+
awaitrmdirPromise(tmpDir,{recursive:true})
119119
}
120120
}

‎src/utils/exec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import*asTfrom'../../typings/tutorial'
22
import{execascpExec}from'child_process'
3-
import*aspathfrom'path'
3+
import{join}from'path'
44
import{promisify}from'util'
55

66
constasyncExec=promisify(cpExec)
@@ -50,7 +50,7 @@ export function createCommandRunner (cwd: string) {
5050
console.log(`-->${command}`)
5151
letcwdDir=cwd
5252
if(dir){
53-
cwdDir=path.join(cwd,dir)
53+
cwdDir=join(cwd,dir)
5454
}
5555
const{ stdout, stderr}=awaitcreateExec(cwdDir)(command)
5656

@@ -67,7 +67,7 @@ export function createCommandRunner (cwd: string) {
6767
}
6868

6969
// function isAbsolute(p: string) {
70-
// returnpath.normalize(p + "/") ===path.normalize(path.resolve(p) + "/");
70+
// return normalize(p + "/") === normalize(resolve(p) + "/");
7171
// }
7272

7373
exportfunctioncreateTestRunner(cwd:string,config:T.TestRunnerConfig){
@@ -77,7 +77,7 @@ export function createTestRunner (cwd: string, config: T.TestRunnerConfig) {
7777

7878
letwd=cwd
7979
if(directory){
80-
wd=path.join(cwd,directory)
80+
wd=join(cwd,directory)
8181
}
8282

8383
constcommandWithArgs=`${command}${args.tap}`

‎src/validate.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import*aspathfrom'path'
2-
import*asfsfrom'fs-extra'
3-
import*asyamlParserfrom'js-yaml'
1+
import{join}from'path'
2+
import{readFile,pathExists,emptyDir}from'fs-extra'
3+
import{load}from'js-yaml'
44
import{getArg}from'./utils/args'
55
importgitP,{SimpleGit}from'simple-git/promise'
66
import{
@@ -19,23 +19,20 @@ interface Options {
1919
asyncfunctionvalidate(args:string[]){
2020
// dir - default .
2121
constdir=!args.length||args[0].match(/^-/) ?'.' :args[0]
22-
constlocalDir=path.join(process.cwd(),dir)
22+
constlocalDir=join(process.cwd(),dir)
2323

2424
// -y --yaml - default coderoad-config.yml
2525
constoptions:Options={
2626
yaml:getArg(args,{name:'yaml',alias:'y'})||'coderoad.yaml',
2727
clean:getArg(args,{name:'clean',alias:'c'})!=='false'
2828
}
2929

30-
const_yaml:string=awaitfs.readFile(
31-
path.join(localDir,options.yaml),
32-
'utf8'
33-
)
30+
const_yaml:string=awaitreadFile(join(localDir,options.yaml),'utf8')
3431

3532
// parse yaml config
3633
letskeleton
3734
try{
38-
skeleton=yamlParser.load(_yaml)asTutorialSkeleton
35+
skeleton=load(_yaml)asTutorialSkeleton
3936

4037
if(!skeleton){
4138
thrownewError('Invalid yaml file contents')
@@ -52,11 +49,11 @@ async function validate (args: string[]) {
5249
constcommits:CommitLogObject=awaitgetCommits({ localDir, codeBranch})
5350

5451
// setup tmp dir
55-
consttmpDir=path.join(localDir,'.tmp')
52+
consttmpDir=join(localDir,'.tmp')
5653

5754
try{
58-
if(!(awaitfs.pathExists(tmpDir))){
59-
awaitfs.emptyDir(tmpDir)
55+
if(!(awaitpathExists(tmpDir))){
56+
awaitemptyDir(tmpDir)
6057
}
6158
consttempGit:SimpleGit=gitP(tmpDir)
6259

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp