|
1 | 1 | const log = require("@ui5/logger").getLogger("normalizer:normalizer"); |
2 | 2 | const projectPreprocessor = require("./projectPreprocessor"); |
3 | 3 |
|
| 4 | + |
4 | 5 | /** |
5 | 6 | * Generate project and dependency trees via translators. Optionally configure all projects with the projectPreprocessor. |
6 | 7 | * |
7 | 8 | * @module normalizer/normalizer |
8 | 9 | */ |
| 10 | +const Normalizer = { |
9 | 11 |
|
10 | | -/** |
11 | | - * Generates a project and dependency tree via translators and configures all projects via the projectPreprocessor |
12 | | - * |
13 | | - * @param {Object} options Options |
14 | | - * @param {string} options.cwd Current working directory |
15 | | - * @param {string} options.configPath Path to configuration file |
16 | | - * @param {string} options.translator Translator to use |
17 | | - * @returns {Promise} Promise resolving to tree object |
18 | | - */ |
19 | | -async function generateProjectTree(options) { |
20 | | - const tree = await generateDependencyTree(options); |
| 12 | + /** |
| 13 | + * Generates a project and dependency tree via translators and configures all projects via the projectPreprocessor |
| 14 | + * |
| 15 | + * @param {Object} options Options |
| 16 | + * @param {string} options.cwd Current working directory |
| 17 | + * @param {string} options.configPath Path to configuration file |
| 18 | + * @param {string} options.translator Translator to use |
| 19 | + * @returns {Promise} Promise resolving to tree object |
| 20 | + */ |
| 21 | + generateProjectTree: async function(options = {}) { |
| 22 | + const tree = await Normalizer.generateDependencyTree(options); |
21 | 23 |
|
22 | | - if (options.configPath) { |
23 | | - tree.configPath = options.configPath; |
24 | | - } |
25 | | - return projectPreprocessor.processTree(tree); |
26 | | -} |
| 24 | + if (options.configPath) { |
| 25 | + tree.configPath = options.configPath; |
| 26 | + } |
| 27 | + return projectPreprocessor.processTree(tree); |
| 28 | + }, |
| 29 | + /** |
| 30 | + * Generates a project and dependency tree via translators |
| 31 | + * |
| 32 | + * @param {Object} options Options |
| 33 | + * @param {string} options.cwd Current working directory |
| 34 | + * @param {string} options.configPath Path to configuration file |
| 35 | + * @param {string} options.translator Translator to use |
| 36 | + * @returns {Promise} Promise resolving to tree object |
| 37 | + */ |
| 38 | + generateDependencyTree: async function(options = {}) { |
| 39 | + log.verbose("Building dependency tree..."); |
| 40 | + const cwd = options && options.cwd || "."; |
27 | 41 |
|
28 | | -/** |
29 | | - * Generates a project and dependency tree via translators |
30 | | - * |
31 | | - * @param {Object} options Options |
32 | | - * @param {string} options.cwd Current working directory |
33 | | - * @param {string} options.configPath Path to configuration file |
34 | | - * @param {string} options.translator Translator to use |
35 | | - * @returns {Promise} Promise resolving to tree object |
36 | | - */ |
37 | | -async function generateDependencyTree(options) { |
38 | | - log.verbose("Building dependency tree..."); |
39 | | - const cwd = options && options.cwd || "."; |
| 42 | + let translatorName = "npm"; // Default is npm translator |
| 43 | + let translatorParams = []; |
| 44 | + if (options.translator) { |
| 45 | + const translatorOptions = options.translator.split(":"); |
| 46 | + translatorName = translatorOptions[0]; |
| 47 | + translatorParams = translatorOptions.slice(1); |
| 48 | + } |
40 | 49 |
|
41 | | - let translatorName = "npm"; // Default is npm translator |
42 | | - let translatorParams = []; |
43 | | - if (options.translator) { |
44 | | - const translatorOptions = options.translator.split(":"); |
45 | | - translatorName = translatorOptions[0]; |
46 | | - translatorParams = translatorOptions.slice(1); |
47 | | - } |
| 50 | + let translator; |
| 51 | + switch (translatorName) { |
| 52 | + case "static": |
| 53 | + translator = require("./translators/static"); |
| 54 | + break; |
| 55 | + case "npm": |
| 56 | + translator = require("./translators/npm"); |
| 57 | + break; |
| 58 | + default: |
| 59 | + return Promise.reject(new Error(`Unknown translator ${translatorName}`)); |
| 60 | + } |
48 | 61 |
|
49 | | - let translator; |
50 | | - switch (translatorName) { |
51 | | - case "static": |
52 | | - translator = require("./translators/static"); |
53 | | - break; |
54 | | - case "npm": |
55 | | - translator = require("./translators/npm"); |
56 | | - break; |
57 | | - default: |
58 | | - throw new Error(`Unkown translator ${translatorName}`); |
| 62 | + return translator.generateDependencyTree(cwd, translatorParams); |
59 | 63 | } |
60 | | - |
61 | | - return translator.generateDependencyTree(cwd, translatorParams); |
62 | | -} |
63 | | - |
64 | | -module.exports = { |
65 | | - generateProjectTree, |
66 | | - generateDependencyTree |
67 | 64 | }; |
| 65 | + |
| 66 | +module.exports = Normalizer; |
0 commit comments