From c8e97dbae2b89cd196e04d3c41b480c228775b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Sun, 6 Jun 2021 16:47:04 +0200 Subject: [PATCH 1/2] refactor(serve): generate index w/out underscore --- src/cordova/serve.js | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/src/cordova/serve.js b/src/cordova/serve.js index 4f6fae853..f50807f73 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 }) => ` - {{ metaData.name }} + ${config.name()}

Package Metadata

- {% for (const key in metaData) { %} - - - - {% } %} + ${['name', 'packageName', 'version'].map(key => + `` + ).join('\n')}
{{ key }}{{ metaData[key] }}
${key}${config[key]()}

Platforms

Plugins

`; -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) From 86e1aa416f623ef25a4c4f658b6104e90c1e57d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Sun, 6 Jun 2021 17:25:51 +0200 Subject: [PATCH 2/2] refactor(requirements): transform results w/out underscore --- src/cordova/requirements.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cordova/requirements.js b/src/cordova/requirements.js index 4ee038ad8..57dbbdc95 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] }) + , {}) + ); }); };