This is an automated email from the ASF dual-hosted git repository. raphinesse pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cordova-lib.git
The following commit(s) were added to refs/heads/master by this push: new 3274a78 fix: remove undeclared dependency on underscore (#871) 3274a78 is described below commit 3274a78e8c4ae18a9861f4e871ff66d6bc234db7 Author: Raphael von der GrĂ¼n <raphine...@gmail.com> AuthorDate: Wed Jun 23 12:08:30 2021 +0200 fix: remove undeclared dependency on underscore (#871) * refactor(serve): generate index w/out underscore * refactor(requirements): transform results w/out underscore --- src/cordova/requirements.js | 7 +++++-- src/cordova/serve.js | 41 +++++++++++++++-------------------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/cordova/requirements.js b/src/cordova/requirements.js index 4ee038a..57dbbdc 100644 --- a/src/cordova/requirements.js +++ b/src/cordova/requirements.js @@ -17,7 +17,6 @@ under the License. */ -const { object: zipObject } = require('underscore'); const cordova_util = require('./util'); const { CordovaError } = require('cordova-common'); const knownPlatforms = require('../platforms/platforms'); @@ -37,7 +36,11 @@ module.exports = function check_reqs (platforms) { return Promise.all( normalizedPlatforms.map(getPlatformRequirementsOrError) - ).then(results => zipObject(normalizedPlatforms, results)); + ).then(results => + normalizedPlatforms.reduce((acc, platform, idx) => + Object.assign(acc, { [platform]: results[idx] }) + , {}) + ); }); }; diff --git a/src/cordova/serve.js b/src/cordova/serve.js index 4f6fae8..f50807f 100644 --- a/src/cordova/serve.js +++ b/src/cordova/serve.js @@ -21,7 +21,6 @@ const url = require('url'); const path = require('path'); const globby = require('globby'); const md5File = require('md5-file'); -const { template, object: zipObject } = require('underscore'); const { ConfigParser, events } = require('cordova-common'); const cordovaServe = require('cordova-serve'); @@ -32,60 +31,50 @@ const HooksRunner = require('../hooks/HooksRunner'); let projectRoot, installedPlatforms; -const INDEX_TEMPLATE = ` +const renderIndex = ({ config, plugins, platforms }) => ` <!doctype html> <html> <head> <meta charset=utf-8> - <title>{{ metaData.name }}</title> + <title>${config.name()}</title> </head> <body> <h3>Package Metadata</h3> <table style="text-align: left"> - {% for (const key in metaData) { %} - <tr> - <th>{{ key }}</th><td>{{ metaData[key] }}</td> - </tr> - {% } %} + ${['name', 'packageName', 'version'].map(key => + `<tr><th>${key}</th><td>${config[key]()}</td></tr>` + ).join('\n')} </table> <h3>Platforms</h3> <ul> - {% for (const platform of platforms) { %} - <li> - {% if (platform.url) { %} - <a href="{{ platform.url }}">{{ platform.name }}</a> - {% } else { %} - <em>{{ platform.name }}</em> - {% } %} - </li> - {% } %} + ${platforms.map(platform => + `<li>${ + platform.url + ? `<a href="${platform.url}">${platform.name}</a>` + : `<em>${platform.name}</em>` + }</li>`).join('\n')} </ul> <h3>Plugins</h3> <ul> - {% for (const plugin of plugins) { %} - <li>{{ plugin }}</li> - {% } %} + ${plugins.map(plugin => + `<li>${plugin}</li>` + ).join('\n')} </ul> </body> </html> `; -const renderIndex = template(INDEX_TEMPLATE, { - escape: /\{\{(.+?)\}\}/g, - evaluate: /\{%(.+?)%\}/g -}); function handleRoot (request, response) { const config = new ConfigParser(cordovaUtil.projectConfig(projectRoot)); const contentNode = config.doc.find('content'); const contentSrc = (contentNode && contentNode.attrib.src) || 'index.html'; - const metaDataKeys = ['name', 'packageName', 'version']; const platformUrl = name => installedPlatforms.includes(name) ? `${name}/www/${contentSrc}` : null; response.send(renderIndex({ - metaData: zipObject(metaDataKeys, metaDataKeys.map(k => config[k]())), + config, plugins: cordovaUtil.findPlugins(path.join(projectRoot, 'plugins')), platforms: Object.keys(platforms).map(name => ({ name, url: platformUrl(name) --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org