-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INTERNAL] static translator and normalizer: Add tests
- Loading branch information
1 parent
dd64ff5
commit 595936d
Showing
7 changed files
with
304 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,66 @@ | ||
const log = require("@ui5/logger").getLogger("normalizer:normalizer"); | ||
const projectPreprocessor = require("./projectPreprocessor"); | ||
|
||
|
||
/** | ||
* Generate project and dependency trees via translators. Optionally configure all projects with the projectPreprocessor. | ||
* | ||
* @module normalizer/normalizer | ||
*/ | ||
const Normalizer = { | ||
|
||
/** | ||
* Generates a project and dependency tree via translators and configures all projects via the projectPreprocessor | ||
* | ||
* @param {Object} options Options | ||
* @param {string} options.cwd Current working directory | ||
* @param {string} options.configPath Path to configuration file | ||
* @param {string} options.translator Translator to use | ||
* @returns {Promise} Promise resolving to tree object | ||
*/ | ||
async function generateProjectTree(options) { | ||
const tree = await generateDependencyTree(options); | ||
/** | ||
* Generates a project and dependency tree via translators and configures all projects via the projectPreprocessor | ||
* | ||
* @param {Object} options Options | ||
* @param {string} options.cwd Current working directory | ||
* @param {string} options.configPath Path to configuration file | ||
* @param {string} options.translator Translator to use | ||
* @returns {Promise} Promise resolving to tree object | ||
*/ | ||
generateProjectTree: async function(options = {}) { | ||
const tree = await Normalizer.generateDependencyTree(options); | ||
|
||
if (options.configPath) { | ||
tree.configPath = options.configPath; | ||
} | ||
return projectPreprocessor.processTree(tree); | ||
} | ||
if (options.configPath) { | ||
tree.configPath = options.configPath; | ||
} | ||
return projectPreprocessor.processTree(tree); | ||
}, | ||
/** | ||
* Generates a project and dependency tree via translators | ||
* | ||
* @param {Object} options Options | ||
* @param {string} options.cwd Current working directory | ||
* @param {string} options.configPath Path to configuration file | ||
* @param {string} options.translator Translator to use | ||
* @returns {Promise} Promise resolving to tree object | ||
*/ | ||
generateDependencyTree: async function(options = {}) { | ||
log.verbose("Building dependency tree..."); | ||
const cwd = options && options.cwd || "."; | ||
|
||
/** | ||
* Generates a project and dependency tree via translators | ||
* | ||
* @param {Object} options Options | ||
* @param {string} options.cwd Current working directory | ||
* @param {string} options.configPath Path to configuration file | ||
* @param {string} options.translator Translator to use | ||
* @returns {Promise} Promise resolving to tree object | ||
*/ | ||
async function generateDependencyTree(options) { | ||
log.verbose("Building dependency tree..."); | ||
const cwd = options && options.cwd || "."; | ||
let translatorName = "npm"; // Default is npm translator | ||
let translatorParams = []; | ||
if (options.translator) { | ||
const translatorOptions = options.translator.split(":"); | ||
translatorName = translatorOptions[0]; | ||
translatorParams = translatorOptions.slice(1); | ||
} | ||
|
||
let translatorName = "npm"; // Default is npm translator | ||
let translatorParams = []; | ||
if (options.translator) { | ||
const translatorOptions = options.translator.split(":"); | ||
translatorName = translatorOptions[0]; | ||
translatorParams = translatorOptions.slice(1); | ||
} | ||
let translator; | ||
switch (translatorName) { | ||
case "static": | ||
translator = require("./translators/static"); | ||
break; | ||
case "npm": | ||
translator = require("./translators/npm"); | ||
break; | ||
default: | ||
return Promise.reject(new Error(`Unknown translator ${translatorName}`)); | ||
} | ||
|
||
let translator; | ||
switch (translatorName) { | ||
case "static": | ||
translator = require("./translators/static"); | ||
break; | ||
case "npm": | ||
translator = require("./translators/npm"); | ||
break; | ||
default: | ||
throw new Error(`Unkown translator ${translatorName}`); | ||
return translator.generateDependencyTree(cwd, translatorParams); | ||
} | ||
|
||
return translator.generateDependencyTree(cwd, translatorParams); | ||
} | ||
|
||
module.exports = { | ||
generateProjectTree, | ||
generateDependencyTree | ||
}; | ||
|
||
module.exports = Normalizer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.