| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133 |
1
1
1
1
1
1
1
20
20
400
400
400
20
15
20
9
11
20
| 'use strict';
var program = require('commander');
var pkg = require('../package');
var cli = {};
module.exports = cli;
cli.getProgram = function() {
program.name = pkg.name;
program.version(pkg.version)
.usage('[options] input.html output.html');
Object.keys(cli.options).forEach(function(key) {
program.option('--' + key + ' [value]', cli.options[key].def);
});
program.parse(process.argv);
return program;
};
cli.options = {
'css': {
pMap: 'css',
map: 'cssFile',
def: 'Add an extra CSS file by name' },
'options-file': {
pMap: 'optionsFile',
def: 'Load options from a JSON file' },
'extra-css': {
pMap: 'extraCss',
def: 'Add extra CSS' },
'insert-preserved-extra-css': {
pMap: 'insertPreservedExtraCss',
def: 'insert preserved @font-face and @media into document?',
coercion: JSON.parse },
'apply-style-tags': {
pMap: 'applyStyleTags',
def: 'inline from style tags?',
coercion: JSON.parse },
'remove-style-tags': {
pMap: 'removeStyleTags',
def: 'remove style tags?',
coercion: JSON.parse },
'preserve-media-queries': {
pMap: 'preserveMediaQueries',
def: 'preserve media queries?',
coercion: JSON.parse },
'preserve-font-faces': {
pMap: 'preserveFontFaces',
def: 'preserve media queries?',
coercion: JSON.parse },
'apply-width-attributes': {
pMap: 'applyWidthAttributes',
def: 'apply width attributes to relevent elements?',
coercion: JSON.parse },
'apply-height-attributes': {
pMap: 'applyHeightAttributes',
def: 'apply width attributes to relevent elements?',
coercion: JSON.parse },
'apply-attributes-table-elements': {
pMap: 'applyAttributesTableElements',
def: 'apply attributes with and equivalent CSS value to table elements?',
coercion: JSON.parse },
'web-resources-inline-attribute': {
pMap: 'webResourcesInlineAttribute',
map: 'inlineAttribute',
def: 'see docs for web-resource-inliner inlineAttribute',
coercion: JSON.parse },
'web-resources-images': {
pMap: 'webResourcesImages',
map: 'images',
def: 'see docs for web-resource-inliner images',
coercion: JSON.parse },
'web-resources-links': {
pMap: 'webResourcesLinks',
map: 'links',
def: 'see docs for web-resource-inliner links',
coercion: JSON.parse },
'web-resources-scripts': {
pMap: 'webResourcesScripts',
map: 'scripts',
def: 'see docs for web-resource-inliner scripts',
coercion: JSON.parse },
'web-resources-relative-to': {
pMap: 'webResourcesRelativeTo',
map: 'relativeTo',
def: 'see docs for web-resource-inliner relativeTo' },
'web-resources-rebase-relative-to': {
pMap: 'webResourcesRebaseRelativeTo',
map: 'rebaseRelativeTo',
def: 'see docs for web-resource-inliner rebaseRelativeTo' },
'web-resources-cssmin': {
pMap: 'webResourcesCssmin',
map: 'cssmin',
def: 'see docs for web-resource-inliner cssmin',
coercion: JSON.parse },
'web-resources-uglify': {
pMap: 'webResourcesUglify',
map: 'uglify',
def: 'see docs for web-resource-inliner uglify',
coercion: JSON.parse },
'web-resources-strict': {
pMap: 'webResourcesStrict',
map: 'strict',
def: 'see docs for web-resource-inliner strict',
coercion: JSON.parse }
};
cli.argsToOptions = function(program) {
var result = { webResources: {} };
Object.keys(cli.options).forEach(function(key) {
var option = cli.options[key];
var value = program[option.pMap];
if (value !== undefined) {
if (option.coercion) {
value = option.coercion(value);
}
if (option.pMap.match(/webResources/)) {
result.webResources[option.map] = value;
} else {
result[option.map || option.pMap] = value;
}
}
});
return result;
};
|