Skip to content

Commit db717f8

Browse files
committed
Split up modules and add linting
1 parent b07e139 commit db717f8

8 files changed

Lines changed: 832 additions & 60 deletions

File tree

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["pretty-standard"]
3+
}

bin/lernaupdate

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

3-
var cli = require("../index.js");
4-
5-
cli.run();
3+
require("../src/index.js").run(process.argv.slice(2));

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,10 @@
1212
"inquirer-autocomplete-prompt": "^0.12.1",
1313
"lodash": "^4.17.4",
1414
"minimist": "^1.2.0"
15+
},
16+
"devDependencies": {
17+
"eslint": "^4.14.0",
18+
"eslint-config-pretty-standard": "^1.1.0",
19+
"prettier": "^1.9.2"
1520
}
1621
}

index.js renamed to src/index.js

Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,25 @@
11
const path = require("path");
22
const fs = require("fs");
33
const inquirer = require("inquirer");
4-
const { spawn } = require("child_process");
54
const chalk = require("chalk");
6-
const minimist = require("minimist");
5+
76
const uniq = require("lodash/uniq");
87
const flatten = require("lodash/flatten");
98

10-
const argv = require("minimist")(process.argv.slice(2));
11-
const ui = new inquirer.ui.BottomBar();
12-
13-
let bottomMessageUpdateId = null;
14-
let bottomMessage = "";
15-
16-
const showBottomMessage = (message = "") => {
17-
const chars = "/-\\|";
18-
let index = 0;
19-
20-
if (message !== bottomMessage) {
21-
clearInterval(bottomMessageUpdateId);
22-
23-
if (message !== "") {
24-
bottomMessageUpdateId = setInterval(() => {
25-
if (chars.charAt(index) === "") index = 0;
26-
27-
ui.updateBottomBar(`${chars.charAt(index++)} ${message}`);
28-
}, 100);
29-
} else {
30-
ui.updateBottomBar("");
31-
}
32-
}
33-
34-
bottomMessage = message;
35-
};
36-
37-
const fileExists = async path =>
38-
new Promise(resolve => fs.stat(path, err => resolve(!err)));
39-
40-
const runCommand = async (options = {}) => {
41-
showBottomMessage(options.startMessage);
42-
const proc = spawn(options.cmd, { shell: true });
43-
44-
if (options.logOutput !== false) proc.stdout.pipe(ui.log);
45-
46-
let data = "";
47-
return new Promise((resolve, reject) => {
48-
proc.stdout.on("data", d => (data = data + d.toString()));
49-
proc.stdout.on("end", () => {
50-
showBottomMessage("");
51-
options.endMessage && ui.log.write(options.endMessage);
52-
ui.log.write("");
53-
resolve(data);
54-
});
55-
proc.stdout.on("error", reject);
56-
});
57-
};
9+
const fileExists = require("./utils/fileExists");
10+
const ui = require("./utils/ui");
11+
const runCommand = require("./utils/runCommand");
5812

5913
inquirer.registerPrompt(
6014
"autocomplete",
6115
require("inquirer-autocomplete-prompt")
6216
);
6317

64-
const run = async () => {
18+
const run = async args => {
6519
"use strict";
66-
const { resolve, basename } = path;
20+
21+
const argv = require("minimist")(args);
22+
const { resolve } = path;
6723
const dir = argv._[0] || ".";
6824

6925
const projectPackagePath = resolve(dir, "package.json");
@@ -107,7 +63,7 @@ const run = async () => {
10763
name: "targetDependency",
10864
message: "Select a dependency to upgrade:",
10965
pageSize: 15,
110-
source: (undefined, input) =>
66+
source: (_ignore_, input) =>
11167
Promise.resolve(
11268
input
11369
? allDependencies.filter(name => new RegExp(input).test(name))

src/utils/fileExists.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const fs = require("fs");
2+
3+
module.exports = async path =>
4+
new Promise(resolve => fs.stat(path, err => resolve(!err)));

src/utils/runCommand.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { spawn } = require("child_process");
2+
3+
const ui = require("./ui");
4+
5+
module.exports = async (options = {}) => {
6+
ui.logBottom(options.startMessage);
7+
const proc = spawn(options.cmd, { shell: true });
8+
9+
if (options.logOutput !== false) proc.stdout.pipe(ui.log);
10+
11+
let data = "";
12+
return new Promise((resolve, reject) => {
13+
proc.stdout.on("data", d => (data = data + d.toString()));
14+
proc.stdout.on("end", () => {
15+
ui.logBottom("");
16+
options.endMessage && ui.log.write(options.endMessage);
17+
ui.log.write("");
18+
resolve(data);
19+
});
20+
proc.stdout.on("error", reject);
21+
});
22+
};

src/utils/ui.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const inquirer = require("inquirer");
2+
const ui = new inquirer.ui.BottomBar();
3+
4+
let bottomMessageUpdateId = null;
5+
let bottomMessage = "";
6+
7+
module.exports.logBottom = (message = "") => {
8+
const chars = "/-\\|";
9+
let index = 0;
10+
11+
if (message !== bottomMessage) {
12+
clearInterval(bottomMessageUpdateId);
13+
14+
if (message !== "") {
15+
bottomMessageUpdateId = setInterval(() => {
16+
if (chars.charAt(index) === "") index = 0;
17+
18+
ui.updateBottomBar(`${chars.charAt(index++)} ${message}`);
19+
}, 100);
20+
} else {
21+
ui.updateBottomBar("");
22+
}
23+
}
24+
25+
bottomMessage = message;
26+
};
27+
28+
module.exports.log = ui.log;

0 commit comments

Comments
 (0)