Skip to content

Commit 086724c

Browse files
authored
Merge pull request #140 from jonycheung/renovate/commander-8.x
fix(deps): update dependency commander to v8 and updated tests for CLI
2 parents e517199 + 4605a35 commit 086724c

File tree

7 files changed

+84
-56
lines changed

7 files changed

+84
-56
lines changed

package-lock.json

Lines changed: 8 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
"dependencies": {
3030
"amdefine": ">= 0.1.0",
31-
"commander": "^7.0.0",
31+
"commander": "^8.0.0",
3232
"extend": ">= 2.0.0",
3333
"global": "^4.3.1",
3434
"less": "^4.0.0",

src/less-watch-compiler.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ var sys = require('util')
2121
, cwd = sh.pwd()
2222
, data
2323
, mainFilePath = undefined
24-
, cmdr = require('commander')
24+
, program = require('commander')
2525
, packagejson = require('../package.json')
2626
, events = require('events');
2727

2828
//bypass maxlistener errors because more files means more listeners #90
2929
events.EventEmitter.defaultMaxListeners = 0;
3030

31-
cmdr
32-
.version(packagejson.version)
31+
program
32+
.version(packagejson.version, '-v, -V, --version', 'Output the current version')
3333
.usage('[options] <source_dir> <destination_dir> [main_file_name]')
3434
.option('--main-file <file>', "Specify <file> as the file to always re-compile e.g. '--main-file style.less'.")
3535
.option('--config <file>', 'Custom configuration file path.', 'less-watch-compiler.config.json')
@@ -40,12 +40,12 @@ cmdr
4040
.option('--source-map', "Less.js Option: To generate source map for css files.")
4141
.option('--plugins <plugin-a>,<plugin-b>', 'Less.js Option: To specify plugins separated by commas.')
4242
.option('--less-args <less-arg1>=<less-arg1-value>,<less-arg1>=<less-arg2-value>', 'Less.js Option: To specify any other less options e.g. \'--less-args math=strict,strict-units=on,include-path=.\/dir1\\;.\/dir2\'.')
43-
.parse(process.argv);
43+
.parse();
4444

45-
const program = cmdr.opts();
45+
const programOption = program.opts();
4646

4747
// Check if configuration file exists
48-
var configPath = program.config ? (path.isAbsolute(program.config))? program.config : (cwd + path.sep + program.config): "less-watch-compiler.config.json";
48+
var configPath = programOption.config ? (path.isAbsolute(programOption.config))? programOption.config : (cwd + path.sep + programOption.config): "less-watch-compiler.config.json";
4949

5050
fs.access(configPath, fs.constants.F_OK, (err) => {
5151
if (!err) {
@@ -59,18 +59,18 @@ const program = cmdr.opts();
5959

6060

6161
function init(){
62-
if (cmdr.args[0]) lessWatchCompilerUtils.config.watchFolder = cmdr.args[0];
63-
if (cmdr.args[1]) lessWatchCompilerUtils.config.outputFolder = cmdr.args[1];
64-
if (cmdr.args[2]) lessWatchCompilerUtils.config.mainFile = cmdr.args[2];
65-
if (program.mainFile) lessWatchCompilerUtils.config.mainFile = program.mainFile;
66-
if (program.sourceMap) lessWatchCompilerUtils.config.sourceMap = program.sourceMap;
67-
if (program.plugins) lessWatchCompilerUtils.config.plugins = program.plugins;
68-
if (program.runOnce) lessWatchCompilerUtils.config.runOnce = program.runOnce;
69-
if (program.inludeHidden) lessWatchCompilerUtils.config.includeHidden = program.includeHidden;
70-
if (program.enableJs) lessWatchCompilerUtils.config.enableJs = program.enableJs;
71-
if (program.lessArgs) lessWatchCompilerUtils.config.lessArgs = program.lessArgs;
72-
73-
lessWatchCompilerUtils.config = Object.assign({}, lessWatchCompilerUtils.config, cmdr.opts())
62+
if (program.args[0]) lessWatchCompilerUtils.config.watchFolder = program.args[0];
63+
if (program.args[1]) lessWatchCompilerUtils.config.outputFolder = program.args[1];
64+
if (program.args[2]) lessWatchCompilerUtils.config.mainFile = program.args[2];
65+
if (programOption.mainFile) lessWatchCompilerUtils.config.mainFile = programOption.mainFile;
66+
if (programOption.sourceMap) lessWatchCompilerUtils.config.sourceMap = programOption.sourceMap;
67+
if (programOption.plugins) lessWatchCompilerUtils.config.plugins = programOption.plugins;
68+
if (programOption.runOnce) lessWatchCompilerUtils.config.runOnce = programOption.runOnce;
69+
if (programOption.inludeHidden) lessWatchCompilerUtils.config.includeHidden = programOption.includeHidden;
70+
if (programOption.enableJs) lessWatchCompilerUtils.config.enableJs = programOption.enableJs;
71+
if (programOption.lessArgs) lessWatchCompilerUtils.config.lessArgs = programOption.lessArgs;
72+
73+
lessWatchCompilerUtils.config = Object.assign({}, lessWatchCompilerUtils.config, program.opts())
7474

7575
/*
7676
3rd parameter is optional, but once you define it, then we will just compile
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.lvl0{
2+
color:black;
3+
}

tests/less-watch-compiler.config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"minified": false,
66
"sourceMap": false,
77
"plugins": "",
8-
"watchFolder": "tests/less",
9-
"outputFolder": "tests/css"
8+
"watchFolder": "tests/examples/with-config/css",
9+
"outputFolder": "tests/examples/with-config/css"
1010
}

tests/less-watch-compiler.js

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,56 @@ exec = require("child_process").exec;
1010
describe("The CLI should", function () {
1111
describe("run correctly with these options:", function () {
1212
describe("--run-once parameter", function () {
13-
it("exit after once", async () => {
14-
let result = await cli(["--run-once", "tests/less", "tests/css"], ".");
15-
assert.strictEqual(result.code, 0);
13+
it("exit after once", () => {
14+
let runCommand = async () => {
15+
let result = await cli(
16+
["--run-once", "tests/less", "tests/css"],
17+
"."
18+
);
19+
return result;
20+
};
21+
runCommand().then((result) => {
22+
assert.strictEqual(result.code, 0);
23+
});
1624
});
1725
});
1826

1927
describe("--config parameter", function () {
20-
it("should load a config json", async () => {
21-
let result = await cli(
22-
["--config", "tests/less-watch-compiler.config.json"],
23-
"."
24-
);
25-
assert.strictEqual(result.code, 0);
28+
const cssDir = cwd + "/tests/examples/with-config/css";
29+
it("should load a config json", () => {
30+
let runCommand = async () => {
31+
let result = await cli(
32+
["--config", "tests/less-watch-compiler.config.json"],
33+
"."
34+
);
35+
return result;
36+
};
37+
38+
runCommand().then((result) => {
39+
assert.strictEqual(result.code, 0);
40+
41+
const contents = fs.readFileSync(cssDir + "/test.css");
42+
const contentsExpected = fs.readFileSync(
43+
cssDir + "/test.expected.css"
44+
);
45+
46+
assert.ok(contents.equals(contentsExpected));
47+
48+
fs.rmSync(cssDir + "/test.css", { force: true });
49+
});
2650
});
2751
});
2852

2953
describe("--include-hidden parameter", function () {
3054
const lessDir = cwd + "/tests/examples/with-hidden-variables-file/less";
3155
const cssDir = cwd + "/tests/examples/with-hidden-variables-file/css";
32-
it("should compile hidden files when parameter is specified", async () => {
33-
let result = await cli(
34-
["--include-hidden"],
35-
lessDir,
36-
cssDir
37-
)
38-
setTimeout(function (){
56+
it("should compile hidden files when parameter is specified", () => {
57+
let runCommand = async () => {
58+
let result = await cli(["--include-hidden"], lessDir, cssDir);
59+
return result;
60+
};
61+
62+
runCommand().then((result) => {
3963
assert.strictEqual(result.code, 0);
4064

4165
const contents = fs.readFileSync(cssDir + "/main.css");
@@ -44,29 +68,31 @@ describe("The CLI should", function () {
4468
assert.ok(contents.equals(contentsExpected));
4569

4670
fs.rmSync(cssDir + "/main.css", { force: true });
47-
48-
},200);
71+
});
4972
});
5073

51-
it("should not compile the hidden variables files when flag not specified", async () => {
74+
it("should not compile the hidden variables files when flag not specified", () => {
5275
const compiledVariablesPath = cssDir + "/_variables.css";
5376
const compiledOtherVariablesPath = cssDir + "/.other-variables.css";
5477

5578
// Make sure we don't detect compiled variables files left over from other runs
5679
fs.rmSync(compiledVariablesPath, { force: true });
5780
fs.rmSync(compiledOtherVariablesPath, { force: true });
5881

59-
let result = await cli([], lessDir, cssDir);
82+
let runCommand = async () => {
83+
let result = await cli([], lessDir, cssDir);
84+
return result;
85+
};
6086

61-
setTimeout(function () {
87+
runCommand().then((result) => {
6288
assert.strictEqual(result.code, 0);
6389

6490
const variablesFilesWereNotCompiled =
6591
!fs.existsSync(compiledVariablesPath) &&
6692
!fs.existsSync(compiledOtherVariablesPath);
6793

6894
assert.ok(variablesFilesWereNotCompiled);
69-
}, 200);
95+
});
7096
});
7197
});
7298
});

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -995,10 +995,10 @@
995995
"resolved" "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz"
996996
"version" "2.20.3"
997997

998-
"commander@^7.0.0":
999-
"integrity" "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw=="
1000-
"resolved" "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz"
1001-
"version" "7.2.0"
998+
"commander@^8.0.0":
999+
"integrity" "sha512-Xvf85aAtu6v22+E5hfVoLHqyul/jyxh91zvqk/ioJTQuJR7Z78n7H558vMPKanPSRgIEeZemT92I2g9Y8LPbSQ=="
1000+
"resolved" "https://registry.npmjs.org/commander/-/commander-8.0.0.tgz"
1001+
"version" "8.0.0"
10021002

10031003
"commitizen@^4.0.3":
10041004
"integrity" "sha512-LlZChbDzg3Ir3O2S7jSo/cgWp5/QwylQVr59K4xayVq8S4/RdKzSyJkghAiZZHfhh5t4pxunUoyeg0ml1q/7aw=="

0 commit comments

Comments
 (0)