Skip to content

Commit 869c604

Browse files
committed
lint
Signed-off-by: shmck <[email protected]>
1 parent 6fe672d commit 869c604

25 files changed

+2133
-2135
lines changed

Diff for: src/build.ts

+86-86
Original file line numberDiff line numberDiff line change
@@ -1,171 +1,171 @@
1-
import * as yamlParser from "js-yaml";
2-
import * as path from "path";
3-
import * as fs from "fs";
4-
import * as util from "util";
5-
import { parse } from "./utils/parse";
6-
import { getArg } from "./utils/args";
7-
import { getCommits, CommitLogObject } from "./utils/commits";
8-
import skeletonSchema from "./schema/skeleton";
9-
import tutorialSchema from "./schema/tutorial";
10-
import { validateSchema } from "./utils/validateSchema";
11-
import { validateMarkdown } from "./utils/validateMarkdown";
12-
import * as T from "../typings/tutorial";
13-
14-
const write = util.promisify(fs.writeFile);
15-
const read = util.promisify(fs.readFile);
1+
import * as yamlParser from 'js-yaml'
2+
import * as path from 'path'
3+
import * as fs from 'fs'
4+
import * as util from 'util'
5+
import { parse } from './utils/parse'
6+
import { getArg } from './utils/args'
7+
import { getCommits, CommitLogObject } from './utils/commits'
8+
import skeletonSchema from './schema/skeleton'
9+
import tutorialSchema from './schema/tutorial'
10+
import { validateSchema } from './utils/validateSchema'
11+
import { validateMarkdown } from './utils/validateMarkdown'
12+
import * as T from '../typings/tutorial'
13+
14+
const write = util.promisify(fs.writeFile)
15+
const read = util.promisify(fs.readFile)
1616

1717
export type BuildConfigOptions = {
18-
text: string; // text document from markdown
19-
config: T.Tutorial; // yaml config file converted to json
20-
commits: CommitLogObject; // an object of tutorial positions with a list of commit hashes
21-
};
18+
text: string // text document from markdown
19+
config: T.Tutorial // yaml config file converted to json
20+
commits: CommitLogObject // an object of tutorial positions with a list of commit hashes
21+
}
2222

2323
type BuildArgs = {
24-
dir: string;
25-
markdown: string;
26-
yaml: string;
27-
output: string;
28-
validate: boolean;
29-
};
24+
dir: string
25+
markdown: string
26+
yaml: string
27+
output: string
28+
validate: boolean
29+
}
3030

31-
async function build(args: string[]) {
32-
let options: BuildArgs;
31+
async function build (args: string[]) {
32+
let options: BuildArgs
3333

3434
try {
3535
// dir - default .
36-
const dir = !args.length || args[0].match(/^-/) ? "." : args[0];
36+
const dir = !args.length || args[0].match(/^-/) ? '.' : args[0]
3737
// -m --markdown - default TUTORIAL.md
3838
const markdown =
39-
getArg(args, { name: "markdown", alias: "m" }) || "TUTORIAL.md";
39+
getArg(args, { name: 'markdown', alias: 'm' }) || 'TUTORIAL.md'
4040
// -y --yaml - default coderoad-config.yml
41-
const yaml = getArg(args, { name: "yaml", alias: "y" }) || "coderoad.yaml";
41+
const yaml = getArg(args, { name: 'yaml', alias: 'y' }) || 'coderoad.yaml'
4242
// -o --output - default coderoad.json
4343
const output =
44-
getArg(args, { name: "output", alias: "o" }) || "tutorial.json";
45-
const validate = getArg(args, { name: "validate", alias: "v" }) !== "false";
44+
getArg(args, { name: 'output', alias: 'o' }) || 'tutorial.json'
45+
const validate = getArg(args, { name: 'validate', alias: 'v' }) !== 'false'
4646

47-
console.log(`Building CodeRoad ${output}...`);
47+
console.log(`Building CodeRoad ${output}...`)
4848

4949
options = {
5050
dir,
5151
output,
5252
markdown,
5353
yaml,
54-
validate,
55-
};
54+
validate
55+
}
5656
} catch (e) {
57-
console.error("Error parsing build logs");
58-
console.error(e.message);
59-
return;
57+
console.error('Error parsing build logs')
58+
console.error(e.message)
59+
return
6060
}
6161

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

6565
// load markdown and files
66-
let _markdown: string;
67-
let _yaml: string;
66+
let _markdown: string
67+
let _yaml: string
6868
try {
69-
[_markdown, _yaml] = await Promise.all([
70-
read(path.join(localPath, options.markdown), "utf8"),
71-
read(path.join(localPath, options.yaml), "utf8"),
72-
]);
69+
;[_markdown, _yaml] = await Promise.all([
70+
read(path.join(localPath, options.markdown), 'utf8'),
71+
read(path.join(localPath, options.yaml), 'utf8')
72+
])
7373
} catch (e) {
74-
console.error("Error reading file:");
75-
console.error(e.message);
76-
return;
74+
console.error('Error reading file:')
75+
console.error(e.message)
76+
return
7777
}
7878

7979
// validate markdown loosely
8080
try {
81-
const isValid = validateMarkdown(_markdown);
81+
const isValid = validateMarkdown(_markdown)
8282
if (!isValid) {
83-
console.warn("Invalid markdown");
83+
console.warn('Invalid markdown')
8484
}
8585
} catch (e) {
86-
console.error("Error validating markdown:");
87-
console.error(e.message);
88-
return;
86+
console.error('Error validating markdown:')
87+
console.error(e.message)
88+
return
8989
}
9090

9191
// parse yaml skeleton config
92-
let skeleton;
92+
let skeleton
9393
try {
94-
skeleton = yamlParser.load(_yaml);
94+
skeleton = yamlParser.load(_yaml)
9595
if (!skeleton || !Object.keys(skeleton).length) {
96-
throw new Error(`Skeleton at "${options.yaml}" is invalid`);
96+
throw new Error(`Skeleton at "${options.yaml}" is invalid`)
9797
}
9898
} catch (e) {
99-
console.error("Error parsing yaml");
100-
console.error(e.message);
101-
return;
99+
console.error('Error parsing yaml')
100+
console.error(e.message)
101+
return
102102
}
103103

104104
// validate skeleton based on skeleton json schema
105105
try {
106-
const valid = validateSchema(skeletonSchema, skeleton);
106+
const valid = validateSchema(skeletonSchema, skeleton)
107107
if (!valid) {
108-
console.error("Skeleton validation failed. See above to see what to fix");
109-
return;
108+
console.error('Skeleton validation failed. See above to see what to fix')
109+
return
110110
}
111111
} catch (e) {
112-
console.error("Error validating tutorial schema:");
113-
console.error(e.message);
112+
console.error('Error validating tutorial schema:')
113+
console.error(e.message)
114114
}
115115

116116
// load git commits to use in parse step
117-
let commits: CommitLogObject;
117+
let commits: CommitLogObject
118118
try {
119119
commits = await getCommits({
120120
localDir: localPath,
121-
codeBranch: skeleton.config.repo.branch,
122-
});
121+
codeBranch: skeleton.config.repo.branch
122+
})
123123
} catch (e) {
124-
console.error("Error loading commits:");
125-
console.error(e.message);
126-
return;
124+
console.error('Error loading commits:')
125+
console.error(e.message)
126+
return
127127
}
128128

129129
// parse tutorial from markdown and yaml
130-
let tutorial: T.Tutorial;
130+
let tutorial: T.Tutorial
131131
try {
132132
tutorial = await parse({
133133
text: _markdown,
134134
skeleton,
135-
commits,
136-
});
135+
commits
136+
})
137137
} catch (e) {
138-
console.error("Error parsing tutorial:");
139-
console.error(e.message);
140-
return;
138+
console.error('Error parsing tutorial:')
139+
console.error(e.message)
140+
return
141141
}
142142

143143
// validate tutorial based on tutorial json schema
144144
try {
145145
if (options.validate) {
146-
const valid = validateSchema(tutorialSchema, tutorial);
146+
const valid = validateSchema(tutorialSchema, tutorial)
147147
if (!valid) {
148148
console.error(
149-
"Tutorial validation failed. See above to see what to fix"
150-
);
149+
'Tutorial validation failed. See above to see what to fix'
150+
)
151151
// continue rather than exiting early
152152
}
153153
}
154154
} catch (e) {
155-
console.error("Error validating tutorial schema:");
156-
console.error(e.message);
155+
console.error('Error validating tutorial schema:')
156+
console.error(e.message)
157157
}
158158

159159
// write tutorial
160160
if (tutorial) {
161161
try {
162-
await write(options.output, JSON.stringify(tutorial, null, 2), "utf8");
163-
console.info(`Success! See output at ${options.output}`);
162+
await write(options.output, JSON.stringify(tutorial, null, 2), 'utf8')
163+
console.info(`Success! See output at ${options.output}`)
164164
} catch (e) {
165-
console.error("Error writing tutorial json file:");
166-
console.error(e.message);
165+
console.error('Error writing tutorial json file:')
166+
console.error(e.message)
167167
}
168168
}
169169
}
170170

171-
export default build;
171+
export default build

Diff for: src/cli.ts

+34-34
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
1-
import "./utils/logs";
2-
import build from "./build";
3-
import create from "./create";
4-
import validate from "./validate";
5-
import * as help from "./help";
1+
import './utils/logs'
2+
import build from './build'
3+
import create from './create'
4+
import validate from './validate'
5+
import * as help from './help'
66

7-
export async function cli(rawArgs: string[]): Promise<void> {
8-
const command: string = rawArgs[2];
9-
const args = rawArgs.slice(3);
7+
export async function cli (rawArgs: string[]): Promise<void> {
8+
const command: string = rawArgs[2]
9+
const args = rawArgs.slice(3)
1010

1111
switch (command) {
12-
case "--version":
13-
case "-v":
14-
const version = require("../package.json").version;
15-
console.log(`v${version}`);
16-
return;
12+
case '--version':
13+
case '-v':
14+
const version = require('../package.json').version
15+
console.log(`v${version}`)
16+
return
1717

18-
case "build":
19-
if (args.length && ["--help", "-h"].includes(args[0])) {
20-
help.build();
21-
return;
18+
case 'build':
19+
if (args.length && ['--help', '-h'].includes(args[0])) {
20+
help.build()
21+
return
2222
}
23-
build(args);
24-
break;
23+
build(args)
24+
break
2525

26-
case "create":
27-
if (args.length && ["--help", "-h"].includes(args[0])) {
28-
help.create();
29-
return;
26+
case 'create':
27+
if (args.length && ['--help', '-h'].includes(args[0])) {
28+
help.create()
29+
return
3030
}
31-
create(args);
32-
break;
31+
create(args)
32+
break
3333

34-
case "validate":
35-
if (args.length && ["--help", "-h"].includes(args[0])) {
36-
help.validate();
37-
return;
34+
case 'validate':
35+
if (args.length && ['--help', '-h'].includes(args[0])) {
36+
help.validate()
37+
return
3838
}
39-
validate(args);
40-
break;
39+
validate(args)
40+
break
4141

42-
case "--help":
43-
case "-h":
42+
case '--help':
43+
case '-h':
4444
default:
45-
help.main();
45+
help.main()
4646
}
4747
}

0 commit comments

Comments
 (0)