-
Notifications
You must be signed in to change notification settings - Fork 174
/
index.js
52 lines (43 loc) · 1.34 KB
/
index.js
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
/**
* shuji (周氏)
* https://github.com/paazmaya/shuji
*
* Reverse engineering JavaScript and CSS sources from sourcemaps
*
* Copyright (c) Juga Paazmaya <[email protected]> (https://paazmaya.fi)
* Licensed under the MIT license
*/
import readSources from './lib/read-sources.js';
import findMap from './lib/find-map.js';
/**
* @param {string} inputFilepath Contents of the sourceMap file
* @param {object} options Options object
* @param {boolean} options.verbose Shall there be more output
* @param {boolean} options.preserve Preserve original folder structure
*
* @returns {Array} Source contents mapped to file names
*/
const handleInput = async (inputFilepath, options) => {
if (options.verbose) {
console.log(`Processing file "${inputFilepath}"`);
}
const input = findMap(inputFilepath);
if (!input) {
console.error(`Could not find sourceMap from "${inputFilepath}"`);
return [];
}
const output = await readSources(input, {
verbose: typeof options.verbose === 'boolean' ?
options.verbose :
false,
preserve: typeof options.preserve === 'boolean' ?
options.preserve :
false
});
const sourceFiles = Object.entries(output);
if (!sourceFiles.length) {
console.error(`Could not get any sources for "${inputFilepath}"`);
}
return sourceFiles;
};
export default handleInput;