UNPKG

@ionic/cli-plugin-ionic1

Version:

Ionic CLI build plugin for Ionic 1 projects

48 lines (47 loc) 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const path = require("path"); function createLiveReloadServer(options) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const tinylr = yield Promise.resolve().then(function () { return require('tiny-lr'); }); const liveReloadServer = tinylr(); liveReloadServer.listen(options.livereloadPort); return (changedFiles) => { liveReloadServer.changed({ body: { files: changedFiles.map(changedFile => ('/' + path.relative(options.wwwDir, changedFile))) } }); }; }); } exports.createLiveReloadServer = createLiveReloadServer; function injectLiveReloadScript(content, host, port) { let contentStr = content.toString(); const liveReloadScript = getLiveReloadScript(host, port); if (contentStr.indexOf('/livereload.js') > -1) { // already added script return content; } let match = contentStr.match(/<\/body>(?![\s\S]*<\/body>)/i); if (!match) { match = contentStr.match(/<\/html>(?![\s\S]*<\/html>)/i); } if (match) { contentStr = contentStr.replace(match[0], `${liveReloadScript}\n${match[0]}`); } else { contentStr += liveReloadScript; } return contentStr; } exports.injectLiveReloadScript = injectLiveReloadScript; function getLiveReloadScript(host, port) { if (host === '0.0.0.0') { host = 'localhost'; } const src = `//${host}:${port}/livereload.js?snipver=1`; return ` <!-- Ionic Dev Server: Injected LiveReload Script -->\n` + ` <script src="${src}" async="" defer=""></script>`; }