Skip to content

Commit b3b03b9

Browse files
committed
add vscode linting
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent c73fa9a commit b3b03b9

File tree

7 files changed

+165
-154
lines changed

7 files changed

+165
-154
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
node_modules
2-
.vscode
1+
node_modules

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
// See http://go.microsoft.com/fwlink/?LinkId=827846
3+
// for the documentation about the extensions.json format
4+
"recommendations": ["dbaeumer.vscode-eslint"]
5+
}

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.codeActionsOnSave": {
4+
"source.organizeImports": false,
5+
"source.fixAll": true
6+
},
7+
"eslint.validate": ["javascript"],
8+
"files.exclude": {},
9+
"git.alwaysSignOff": true
10+
}

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ npm install -g @coderoad/cli
1818
## Create
1919

2020
```shell
21-
$ coderoad create
21+
coderoad create
2222
```
2323

2424
Create templates files in the current folder for the content and setup files.
2525

26-
2726
## Build
2827

29-
```
28+
```text
3029
$ coderoad build [options]
3130
3231
options:
@@ -35,22 +34,22 @@ options:
3534
-d, --dir Tutorial's local directory. Either --git or --dir should be provided.
3635
-c, --code Branch that contains the code.
3736
-s, --setup Branch that contains the TUTORIAL.md and coderoad.yaml files.
38-
-o, --output (Optional) Save the configuration in the output file.
37+
-o, --output (Optional) Save the configuration in the output file.
3938
Log into the console if not set
4039
-h, --help (Optional) Show the help message
41-
```
40+
```
4241

4342
Build the configuration file to be used by the extension to run the tutorial. The configuration file is created by matching the `level` and `step` ids between the `TUTORIAL.md` and `coderoad.yaml` files against git commit messages with the same ids. For example:
4443

45-
4644
**TUTORIAL.md**
45+
4746
```markdown
4847
...
48+
4949
## L10 This is a level with id = 10
5050

5151
This level has two steps...
5252

53-
5453
### L10S1 First step
5554

5655
The first step with id L10S1. The Step id should start with the level id.
@@ -61,8 +60,9 @@ The second step...
6160
```
6261

6362
**coderoad.yaml**
63+
6464
```yaml
65-
...
65+
---
6666
levels:
6767
- id: L10
6868
config: {}
@@ -98,7 +98,7 @@ levels:
9898
9999
... and the commit messages
100100
101-
```
101+
```text
102102
commit 8e0e3a42ae565050181fdb68298114df21467a74 (HEAD -> v2, origin/v2)
103103
Author: creator <author@email.com>
104104
Date: Sun May 3 16:16:01 2020 -0700

src/cli.js

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,85 @@
1-
import arg from 'arg';
2-
import inquirer from 'inquirer';
3-
import simpleGit from 'simple-git/promise';
4-
import build from './parse';
5-
import create from './create';
6-
import fs from 'fs';
1+
import arg from "arg";
2+
import inquirer from "inquirer";
3+
import simpleGit from "simple-git/promise";
4+
import build from "./parse";
5+
import create from "./create";
6+
import fs from "fs";
77

8-
const localGit = 'Local directory';
9-
const remoteGit = 'Git remote address';
8+
const localGit = "Local directory";
9+
const remoteGit = "Git remote address";
1010

1111
function parseArgumentsIntoOptions(rawArgs) {
1212
const args = arg(
1313
{
14-
'--git': String,
15-
'--dir': String,
16-
'--code': String,
17-
'--setup': String,
18-
'--output': String,
19-
'--help': Boolean,
20-
'-g': '--git',
21-
'-d': '--dir',
22-
'-c': '--code',
23-
'-s': '--setup',
24-
'-o': '--output',
25-
'-h': '--help',
14+
"--git": String,
15+
"--dir": String,
16+
"--code": String,
17+
"--setup": String,
18+
"--output": String,
19+
"--help": Boolean,
20+
"-g": "--git",
21+
"-d": "--dir",
22+
"-c": "--code",
23+
"-s": "--setup",
24+
"-o": "--output",
25+
"-h": "--help",
2626
},
2727
{
2828
argv: rawArgs.slice(2),
2929
}
3030
);
3131
return {
32-
command: args['_'][0],
33-
git: args['--git'],
34-
dir: args['--dir'],
35-
codeBranch: args['--code'],
36-
setupBranch: args['--setup'],
37-
output: args['--output'],
38-
help: args['--help'] || false,
32+
command: args["_"][0],
33+
git: args["--git"],
34+
dir: args["--dir"],
35+
codeBranch: args["--code"],
36+
setupBranch: args["--setup"],
37+
output: args["--output"],
38+
help: args["--help"] || false,
3939
};
4040
}
4141

4242
async function promptForMissingOptions(options) {
43-
4443
const questions = [];
4544

4645
// if no git remote addres is provided, assume current folder
4746
if (!options.git && !options.dir) {
48-
4947
// check if the current dir is a valid repo
5048
const git = simpleGit(process.cwd());
5149
const isRepo = await git.checkIsRepo();
5250

5351
if (!isRepo) {
54-
5552
questions.push({
56-
type: 'list',
57-
name: 'source',
53+
type: "list",
54+
name: "source",
5855
message: `The current directory (${process.cwd()}) is not a valid git repo. Would you like to provide a...`,
5956
choices: [localGit, remoteGit],
6057
default: localGit,
6158
});
6259

6360
questions.push({
64-
type: 'input',
65-
name: 'localGit',
66-
message: 'Please, provide a local directory of the valid git repository: ',
61+
type: "input",
62+
name: "localGit",
63+
message:
64+
"Please, provide a local directory of the valid git repository: ",
6765
when: (answers) => answers.source === localGit,
6866
});
6967

7068
questions.push({
71-
type: 'input',
72-
name: 'remoteGit',
73-
message: 'Please, provide the address of a remote git repository: ',
69+
type: "input",
70+
name: "remoteGit",
71+
message: "Please, provide the address of a remote git repository: ",
7472
when: (answers) => answers.source === remoteGit,
7573
});
7674
}
7775
}
7876
// if both local dir and remote repos are provided
7977
else if (options.git && options.dir) {
8078
questions.push({
81-
type: 'list',
82-
name: 'source',
83-
message: 'A local git directory and a remote address were both provided. Please, choose either one or those to parse: ',
79+
type: "list",
80+
name: "source",
81+
message:
82+
"A local git directory and a remote address were both provided. Please, choose either one or those to parse: ",
8483
choices: [localGit, remoteGit],
8584
default: localGit,
8685
});
@@ -89,18 +88,19 @@ async function promptForMissingOptions(options) {
8988
// if the branch containing the code is not provided
9089
if (!options.codeBranch) {
9190
questions.push({
92-
type: 'input',
93-
name: 'codeBranch',
94-
message: 'Please, provide the branch with the code commits: ',
91+
type: "input",
92+
name: "codeBranch",
93+
message: "Please, provide the branch with the code commits: ",
9594
});
9695
}
9796

9897
// if the branch containing the setup files is not provided
9998
if (!options.setupBranch) {
10099
questions.push({
101-
type: 'input',
102-
name: 'setupBranch',
103-
message: 'Please, provide the branch with the setup files (coderoad.yaml and tutorial.md): ',
100+
type: "input",
101+
name: "setupBranch",
102+
message:
103+
"Please, provide the branch with the setup files (coderoad.yaml and tutorial.md): ",
104104
});
105105
}
106106

@@ -112,8 +112,7 @@ async function promptForMissingOptions(options) {
112112
if (answers.source) {
113113
repo = answers.source === localGit ? options.dir : options.git;
114114
isLocal = answers.source === localGit;
115-
}
116-
else {
115+
} else {
117116
repo = options.dir || options.git || process.cwd();
118117
isLocal = options.git ? false : true;
119118
}
@@ -129,35 +128,36 @@ async function promptForMissingOptions(options) {
129128

130129
export async function cli(args) {
131130
let options = parseArgumentsIntoOptions(args);
132-
131+
133132
// If help called just print the help text and exit
134133
if (options.help) {
135-
console.log('Docs can be found at github: https://github.com/coderoad/coderoad-cli/');
136-
}
137-
else if (!options.command) {
138-
console.log(`The command is missing. Choose either 'create' or 'build' and its options.`)
139-
}
140-
else {
134+
console.log(
135+
"Docs can be found at github: https://github.com/coderoad/coderoad-cli/"
136+
);
137+
} else if (!options.command) {
138+
console.log(
139+
`The command is missing. Choose either 'create' or 'build' and its options.`
140+
);
141+
} else {
141142
switch (options.command) {
142-
case 'build':
143+
case "build":
143144
// Otherwise, continue with the other options
144145
options = await promptForMissingOptions(options);
145146
console.log(options);
146147
const config = await build(options);
147148

148149
if (config) {
149150
if (options.output) {
150-
fs.writeFileSync(options.output, JSON.stringify(config), 'utf8');
151-
}
152-
else {
151+
fs.writeFileSync(options.output, JSON.stringify(config), "utf8");
152+
} else {
153153
console.log(JSON.stringify(config, null, 2));
154154
}
155155
}
156156
break;
157-
158-
case 'create':
157+
158+
case "create":
159159
create(process.cwd());
160160
break;
161161
}
162162
}
163-
}
163+
}

src/create.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
1-
import ncp from 'ncp';
2-
import path from 'path';
3-
import { promisify } from 'util';
4-
import * as os from 'os';
1+
import ncp from "ncp";
2+
import path from "path";
3+
import { promisify } from "util";
4+
import * as os from "os";
55

66
const copy = promisify(ncp);
7-
8-
const copyFiles = async (filePath) => {
97

8+
const copyFiles = async (filePath) => {
109
try {
11-
1210
let filePath = new URL(import.meta.url).pathname;
1311

14-
if (os.platform() === 'win32') {
12+
if (os.platform() === "win32") {
1513
// removes the leading drive letter from the path
1614
filePath = filePath.substr(3);
1715
}
1816

19-
const templateDirectory = path.resolve(
20-
filePath, '..', 'templates',
21-
);
17+
const templateDirectory = path.resolve(filePath, "..", "templates");
2218

2319
const targetDirectory = process.cwd();
2420

2521
await copy(templateDirectory, targetDirectory, {
2622
clobber: false,
2723
});
28-
}
29-
catch(e) {
30-
console.log('Error on creating the files:');
24+
} catch (e) {
25+
console.log("Error on creating the files:");
3126
console.log(JSON.stringify(e, null, 1));
3227
}
33-
}
28+
};
3429

35-
export default copyFiles;
30+
export default copyFiles;

0 commit comments

Comments
 (0)