Skip to content

Commit

Permalink
fix: remove undeclared dependency on underscore (#871)
Browse files Browse the repository at this point in the history
* refactor(serve): generate index w/out underscore
* refactor(requirements): transform results w/out underscore
  • Loading branch information
raphinesse authored Jun 23, 2021
1 parent ec67ccb commit 3274a78
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
7 changes: 5 additions & 2 deletions src/cordova/requirements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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] })
, {})
);
});
};

Expand Down
41 changes: 15 additions & 26 deletions src/cordova/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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)
Expand Down

0 comments on commit 3274a78

Please sign in to comment.