1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var ionic_global_1 = require("./ionic-global");
|
4 | var helpers_1 = require("../util/helpers");
|
5 | var path_1 = require("path");
|
6 | function updateIndexHtml(context) {
|
7 | var indexPath = path_1.join(context.wwwDir, context.wwwIndex);
|
8 | return helpers_1.readFileAsync(indexPath).then(function (indexHtml) {
|
9 | if (!indexHtml) {
|
10 | return Promise.resolve(null);
|
11 | }
|
12 | indexHtml = injectCoreScripts(context, indexHtml);
|
13 | return helpers_1.writeFileAsync(indexPath, indexHtml);
|
14 | });
|
15 | }
|
16 | exports.updateIndexHtml = updateIndexHtml;
|
17 | function injectCoreScripts(context, indexHtml) {
|
18 | var inject = [];
|
19 | inject.push(" <script data-ionic=\"inject\">");
|
20 | inject.push(" " + ionic_global_1.buildIonicGlobal(context));
|
21 | inject.push(" </script>");
|
22 | return injectCoreHtml(indexHtml, inject.join('\n'));
|
23 | }
|
24 | exports.injectCoreScripts = injectCoreScripts;
|
25 | function injectCoreHtml(indexHtml, inject) {
|
26 |
|
27 | var existingTag = indexHtml.match(/<script data-ionic="inject">[\s\S]*?<\/script>/gi);
|
28 | if (existingTag) {
|
29 | return indexHtml.replace(existingTag[0], inject.trim());
|
30 | }
|
31 |
|
32 | var headTag = indexHtml.match(/<head[^>]*>/gi);
|
33 | if (headTag) {
|
34 | return indexHtml.replace(headTag[0], headTag[0] + "\n" + inject);
|
35 | }
|
36 |
|
37 | var htmlTag = indexHtml.match(/<html[^>]*>/gi);
|
38 | if (htmlTag) {
|
39 | return indexHtml.replace(htmlTag[0], htmlTag[0] + "\n" + inject);
|
40 | }
|
41 | return inject + "\n" + indexHtml;
|
42 | }
|
43 | exports.injectCoreHtml = injectCoreHtml;
|