Skip to content

Commit 1abb841

Browse files
committed
refactor(serve): generate index w/out underscore
1 parent d817d16 commit 1abb841

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

src/cordova/serve.js

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const url = require('url');
2121
const path = require('path');
2222
const globby = require('globby');
2323
const md5File = require('md5-file');
24-
const { template, object: zipObject } = require('underscore');
2524

2625
const { ConfigParser, events } = require('cordova-common');
2726
const cordovaServe = require('cordova-serve');
@@ -32,60 +31,50 @@ const HooksRunner = require('../hooks/HooksRunner');
3231

3332
let projectRoot, installedPlatforms;
3433

35-
const INDEX_TEMPLATE = `
34+
const renderIndex = ({ config, plugins, platforms }) => `
3635
<!doctype html>
3736
<html>
3837
<head>
3938
<meta charset=utf-8>
40-
<title>{{ metaData.name }}</title>
39+
<title>${config.name()}</title>
4140
</head>
4241
<body>
4342
<h3>Package Metadata</h3>
4443
<table style="text-align: left">
45-
{% for (const key in metaData) { %}
46-
<tr>
47-
<th>{{ key }}</th><td>{{ metaData[key] }}</td>
48-
</tr>
49-
{% } %}
44+
${['name', 'packageName', 'version'].map(key =>
45+
`<tr><th>${key}</th><td>${config[key]()}</td></tr>`
46+
).join('\n')}
5047
</table>
5148
5249
<h3>Platforms</h3>
5350
<ul>
54-
{% for (const platform of platforms) { %}
55-
<li>
56-
{% if (platform.url) { %}
57-
<a href="{{ platform.url }}">{{ platform.name }}</a>
58-
{% } else { %}
59-
<em>{{ platform.name }}</em>
60-
{% } %}
61-
</li>
62-
{% } %}
51+
${platforms.map(platform =>
52+
`<li>${
53+
platform.url
54+
? `<a href="${platform.url}">${platform.name}</a>`
55+
: `<em>${platform.name}</em>`
56+
}</li>`).join('\n')}
6357
</ul>
6458
6559
<h3>Plugins</h3>
6660
<ul>
67-
{% for (const plugin of plugins) { %}
68-
<li>{{ plugin }}</li>
69-
{% } %}
61+
${plugins.map(plugin =>
62+
`<li>${plugin}</li>`
63+
).join('\n')}
7064
</ul>
7165
</body>
7266
</html>
7367
`;
74-
const renderIndex = template(INDEX_TEMPLATE, {
75-
escape: /\{\{(.+?)\}\}/g,
76-
evaluate: /\{%(.+?)%\}/g
77-
});
7868

7969
function handleRoot (request, response) {
8070
const config = new ConfigParser(cordovaUtil.projectConfig(projectRoot));
8171
const contentNode = config.doc.find('content');
8272
const contentSrc = (contentNode && contentNode.attrib.src) || 'index.html';
83-
const metaDataKeys = ['name', 'packageName', 'version'];
8473
const platformUrl = name => installedPlatforms.includes(name)
8574
? `${name}/www/${contentSrc}` : null;
8675

8776
response.send(renderIndex({
88-
metaData: zipObject(metaDataKeys, metaDataKeys.map(k => config[k]())),
77+
config,
8978
plugins: cordovaUtil.findPlugins(path.join(projectRoot, 'plugins')),
9079
platforms: Object.keys(platforms).map(name => ({
9180
name, url: platformUrl(name)

0 commit comments

Comments
 (0)