Skip to content

Commit e39d95b

Browse files
Bumps commander dependency to version 7.0.
1 parent 3622dcb commit e39d95b

File tree

5 files changed

+43
-42
lines changed

5 files changed

+43
-42
lines changed

History.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
==================
33

44
* Bumps clean-css dependency to 5.0.
5+
* Bumps commander dependency to 7.0.
56

67
[4.3.0 / 2019-04-06](https://github.com/jakubpawlowicz/clean-css-cli/compare/4.2...v4.3.0)
78
==================

index.js

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var fs = require('fs');
22
var path = require('path');
33

44
var CleanCSS = require('clean-css');
5-
var commands = require('commander');
5+
var program = require('commander');
66
var glob = require('glob');
77

88
var COMPATIBILITY_PATTERN = /([\w\.]+)=(\w+)/g;
@@ -14,14 +14,15 @@ function cli(process, beforeMinifyCallback) {
1414
var fromStdin;
1515
var debugMode;
1616
var removeInlinedFiles;
17+
var inputOptions;
1718
var options;
1819
var stdin;
1920
var data;
2021

2122
beforeMinifyCallback = beforeMinifyCallback || Function.prototype;
2223

2324
// Specify commander options to parse command line params correctly
24-
commands
25+
program
2526
.version(buildVersion, '-v, --version')
2627
.usage('[options] <source-file ...>')
2728
.option('-c, --compatibility [ie7|ie8]', 'Force compatibility mode (see Readme for advanced examples)')
@@ -37,7 +38,7 @@ function cli(process, beforeMinifyCallback) {
3738
.option('--source-map-inline-sources', 'Enables inlining sources inside source maps')
3839
.option('--input-source-map [file]', 'Specifies the path of the input source map file');
3940

40-
commands.on('--help', function () {
41+
program.on('--help', function () {
4142
console.log(' Examples:\n');
4243
console.log(' %> cleancss one.css');
4344
console.log(' %> cleancss -o one-min.css one.css');
@@ -118,49 +119,48 @@ function cli(process, beforeMinifyCallback) {
118119
process.exit();
119120
});
120121

121-
commands.parse(process.argv);
122-
123-
if (commands.rawArgs.indexOf('-O0') > -1) {
124-
commands.O0 = true;
125-
}
126-
127-
if (commands.rawArgs.indexOf('-O1') > -1) {
128-
commands.O1 = findArgumentTo('-O1', commands.rawArgs, commands.args);
129-
}
130-
131-
if (commands.rawArgs.indexOf('-O2') > -1) {
132-
commands.O2 = findArgumentTo('-O2', commands.rawArgs, commands.args);
133-
}
122+
program.parse(process.argv);
123+
inputOptions = program.opts();
134124

135125
// If no sensible data passed in just print help and exit
136-
if (commands.args.length === 0) {
126+
if (program.args.length === 0) {
137127
fromStdin = !process.env.__DIRECT__ && !process.stdin.isTTY;
138128
if (!fromStdin) {
139-
commands.outputHelp();
129+
program.outputHelp();
140130
return 0;
141131
}
142132
}
143133

144-
// Now coerce commands into CleanCSS configuration...
145-
debugMode = commands.debug;
146-
removeInlinedFiles = commands.removeInlinedFiles;
134+
// Now coerce arguments into CleanCSS configuration...
135+
debugMode = inputOptions.debug;
136+
removeInlinedFiles = inputOptions.removeInlinedFiles;
147137

148138
options = {
149-
compatibility: commands.compatibility,
150-
format: commands.format,
151-
inline: typeof commands.inline == 'string' ? commands.inline : 'local',
152-
inlineTimeout: commands.inlineTimeout * 1000,
153-
level: commands.O0 || commands.O1 || commands.O2 ?
154-
{ '0': commands.O0, '1': commands.O1, '2': commands.O2 } :
155-
undefined,
156-
output: commands.output,
157-
rebase: commands.withRebase ? true : false,
158-
rebaseTo: ('output' in commands) && commands.output.length > 0 ? path.dirname(path.resolve(commands.output)) : (commands.withRebase ? process.cwd() : undefined),
159-
sourceMap: commands.sourceMap,
160-
sourceMapInlineSources: commands.sourceMapInlineSources
139+
compatibility: inputOptions.compatibility,
140+
format: inputOptions.format,
141+
inline: typeof inputOptions.inline == 'string' ? inputOptions.inline : 'local',
142+
inlineTimeout: inputOptions.inlineTimeout * 1000,
143+
level: { 1: true },
144+
output: inputOptions.output,
145+
rebase: inputOptions.withRebase ? true : false,
146+
rebaseTo: ('output' in inputOptions) && inputOptions.output.length > 0 ? path.dirname(path.resolve(inputOptions.output)) : (inputOptions.withRebase ? process.cwd() : undefined),
147+
sourceMap: inputOptions.sourceMap,
148+
sourceMapInlineSources: inputOptions.sourceMapInlineSources
161149
};
162150

163-
if (commands.inputSourceMap && !options.sourceMap) {
151+
if (program.rawArgs.indexOf('-O0') > -1) {
152+
options.level[0] = true;
153+
}
154+
155+
if (program.rawArgs.indexOf('-O1') > -1) {
156+
options.level[1] = findArgumentTo('-O1', program.rawArgs, program.args);
157+
}
158+
159+
if (program.rawArgs.indexOf('-O2') > -1) {
160+
options.level[2] = findArgumentTo('-O2', program.rawArgs, program.args);
161+
}
162+
163+
if (inputOptions.inputSourceMap && !options.sourceMap) {
164164
options.sourceMap = true;
165165
}
166166

@@ -173,12 +173,12 @@ function cli(process, beforeMinifyCallback) {
173173
beforeMinifyCallback: beforeMinifyCallback,
174174
debugMode: debugMode,
175175
removeInlinedFiles: removeInlinedFiles,
176-
inputSourceMap: commands.inputSourceMap
176+
inputSourceMap: inputOptions.inputSourceMap
177177
};
178178

179179
// ... and do the magic!
180-
if (commands.args.length > 0) {
181-
minify(process, options, configurations, expandGlobs(commands.args));
180+
if (program.args.length > 0) {
181+
minify(process, options, configurations, expandGlobs(program.args));
182182
} else {
183183
stdin = process.openStdin();
184184
stdin.setEncoding('utf-8');

package-lock.json

Lines changed: 3 additions & 3 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
@@ -34,7 +34,7 @@
3434
"homepage": "https://github.com/jakubpawlowicz/clean-css-cli#readme",
3535
"dependencies": {
3636
"clean-css": "^5.0.1",
37-
"commander": "^2.20.3",
37+
"commander": "7.x",
3838
"glob": "^7.1.6"
3939
},
4040
"devDependencies": {

test/binary-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ vows.describe('cleancss')
276276
assert.include(stdout, 'url(test/fixtures/rebasing/components/jquery-ui/images/next.gif)');
277277
}
278278
}),
279-
'relative': binaryContext('--with-rebasing -o test/ui.bundled.css ./test/fixtures/rebasing/assets/ui.css', {
279+
'relative': binaryContext('--with-rebase -o test/ui.bundled.css ./test/fixtures/rebasing/assets/ui.css', {
280280
'should rebase urls correctly': function () {
281281
var minimized = fs.readFileSync('test/ui.bundled.css', 'utf-8');
282282
assert.include(minimized, 'url(fixtures/rebasing/components/bootstrap/images/glyphs.gif)');

0 commit comments

Comments
 (0)