1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _lodash = require('lodash');
|
8 |
|
9 | var _lodash2 = _interopRequireDefault(_lodash);
|
10 |
|
11 | var _yargsParser = require('yargs-parser');
|
12 |
|
13 | var _yargsParser2 = _interopRequireDefault(_yargsParser);
|
14 |
|
15 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
16 |
|
17 | const ARGUMENT_PARSERS = {
|
18 | epstopdf: {
|
19 | alias: {
|
20 | outfile: 'o'
|
21 | },
|
22 | configuration: {
|
23 | 'negation-prefix': 'no'
|
24 | },
|
25 | default: {
|
26 | compress: true,
|
27 | embed: true,
|
28 | gs: true,
|
29 | quiet: true,
|
30 | safer: true
|
31 | },
|
32 | boolean: ['compress', 'debug', 'embed', 'exact', 'filter', 'gray', 'gs', 'hires', 'quiet', 'restricted', 'safer'],
|
33 | string: ['device', 'pdfwrite', 'autorotate', 'gscmd', 'gsopt', 'gsopts', 'outfile']
|
34 | },
|
35 | repstopdf: {
|
36 | alias: {
|
37 | outfile: 'o'
|
38 | },
|
39 | configuration: {
|
40 | 'negation-prefix': 'no'
|
41 | },
|
42 | default: {
|
43 | compress: true,
|
44 | embed: true,
|
45 | gs: true,
|
46 | quiet: true,
|
47 | restricted: true,
|
48 | safer: true
|
49 | },
|
50 | boolean: ['compress', 'debug', 'embed', 'exact', 'filter', 'gray', 'gs', 'hires', 'quiet', 'restricted', 'safer'],
|
51 | string: ['device', 'pdfwrite', 'autorotate', 'gscmd', 'gsopt', 'gsopts', 'outfile']
|
52 | },
|
53 | makeindex: {
|
54 | boolean: ['c', 'g', 'i', 'l', 'q', 'r', 'L', 'T'],
|
55 | string: ['o', 'p', 's', 't']
|
56 | },
|
57 | mendex: {
|
58 | boolean: ['c', 'f', 'g', 'i', 'l', 'q', 'r', 'E', 'J', 'S', 'U'],
|
59 | string: ['d', 'o', 'p', 's', 't', 'I']
|
60 | },
|
61 | upmendex: {
|
62 | boolean: ['c', 'f', 'g', 'i', 'l', 'q', 'r'],
|
63 | string: ['d', 'o', 'p', 's', 't']
|
64 | },
|
65 | splitindex: {
|
66 | alias: {
|
67 | help: 'h',
|
68 | makeindex: 'm',
|
69 | identify: 'i',
|
70 | resultis: 'r',
|
71 | suffixis: 's'
|
72 | },
|
73 | string: ['makeindex', 'identify', 'resultis', 'suffixis'],
|
74 | count: ['verbose'],
|
75 | boolean: ['help', 'version']
|
76 | },
|
77 | texindy: {
|
78 | alias: {
|
79 | codepage: 'C',
|
80 | german: 'g',
|
81 | help: 'h',
|
82 | inputMarkup: 'I',
|
83 | language: 'L',
|
84 | letterOrdering: 'l',
|
85 | logFile: 't',
|
86 | module: 'M',
|
87 | noRanges: 'r',
|
88 | outFile: 'o',
|
89 | quiet: 'q',
|
90 | stdin: 'i',
|
91 | verbose: 'v',
|
92 | version: 'V'
|
93 | },
|
94 | boolean: ['german', 'help', 'letter-ordering', 'no-ranges', 'quiet', 'stdin', 'verbose', 'version'],
|
95 | string: ['codepage', 'input-markup', 'language', 'log-file', 'module', 'out-file']
|
96 | }
|
97 | };
|
98 |
|
99 | function splitCommand(command) {
|
100 | const args = [];
|
101 | let current;
|
102 | let quote;
|
103 |
|
104 | for (let i = 0; i < command.length; i++) {
|
105 | const char = command.substr(i, 1);
|
106 | if (char === quote) {
|
107 | quote = null;
|
108 | } else if (char === '\'' || char === '"') {
|
109 | quote = char;
|
110 | current = current || '';
|
111 | } else if (char === '\\') {
|
112 | current = `${current || ''}${command.substr(++i, 1)}`;
|
113 | } else if (!quote && /^\s$/.test(char)) {
|
114 | if (typeof current === 'string') args.push(current);
|
115 | current = null;
|
116 | } else {
|
117 | current = `${current || ''}${char}`;
|
118 | }
|
119 | }
|
120 |
|
121 | if (typeof current === 'string') args.push(current);
|
122 |
|
123 | return args;
|
124 | }
|
125 |
|
126 | class Log {
|
127 |
|
128 | static hasRunMessage(parsedLog, program, file) {
|
129 | const quote = file.includes(' ') ? '"' : '';
|
130 | const text = `run ${program} on the file: ${quote}${file}${quote}`;
|
131 | return parsedLog.messages.findIndex(message => message.text.includes(text)) !== -1;
|
132 | }
|
133 |
|
134 | static findMessage(parsedLog, pattern) {
|
135 | return parsedLog.messages.find(message => !!message.text.match(pattern));
|
136 | }
|
137 |
|
138 | static findMessageMatches(parsedLog, pattern, category) {
|
139 | return parsedLog.messages
|
140 |
|
141 | .map(message => !category || message.category === category ? message.text.match(pattern) : null).filter(match => match);
|
142 | }
|
143 |
|
144 | static filterCalls(parsedLog, command, filePath, status) {
|
145 | return parsedLog.calls.filter(call => !!call.args[0].match(command) && (!filePath || call.args.includes(filePath)) && (!status || call.status.startsWith(status)));
|
146 | }
|
147 |
|
148 | static findCall(parsedLog, command, filePath, status) {
|
149 | return parsedLog.calls.find(call => !!call.args[0].match(command) && (!filePath || call.args.includes(filePath)) && (!status || call.status.startsWith(status)));
|
150 | }
|
151 |
|
152 | static parseCall(command, status = 'executed') {
|
153 | const args = splitCommand(command);
|
154 | if (args[0] in ARGUMENT_PARSERS) {
|
155 | const argv = (0, _yargsParser2.default)(args, ARGUMENT_PARSERS[args[0]]);
|
156 | return {
|
157 | args: argv._,
|
158 | options: _lodash2.default.omitBy(_lodash2.default.omitBy(_lodash2.default.omit(argv, ['_', '$0']), _lodash2.default.isUndefined), v => v === false),
|
159 | status
|
160 | };
|
161 | }
|
162 |
|
163 | return { args, options: {}, status };
|
164 | }
|
165 | }
|
166 | exports.default = Log; |
\ | No newline at end of file |