Skip to content

Commit

Permalink
compiling and adding dist files
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenengland committed Feb 25, 2024
1 parent 0571bb8 commit 8a540ca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
28 changes: 20 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ const nodemon_1 = __importDefault(require("nodemon"));
const os_1 = require("os");
const path = __importStar(require("path"));
const ps_tree_1 = __importDefault(require("ps-tree"));
const rimraf_1 = require("rimraf");
const semver_1 = require("semver");
const source_map_1 = require("source-map");
const ws_1 = __importDefault(require("ws"));
const jsonConfig_1 = require("./jsonConfig");
const logger_1 = require("./logger");
const chalk = require("chalk");
const rimraf_1 = require("rimraf");
const acorn = require("acorn");
const EventEmitter = require("events");
const DEFAULT_TEMP_DIR_NAME = '.dev-server';
Expand Down Expand Up @@ -280,6 +280,18 @@ class DevServer {
}
return port;
}
getJsonConfigPath() {
const jsonConfigPath = path.resolve(this.rootDir, 'admin/jsonConfig.json');
if ((0, fs_extra_1.existsSync)(jsonConfigPath)) {
return jsonConfigPath;
}
else if ((0, fs_extra_1.existsSync)(jsonConfigPath + '5')) {
return jsonConfigPath + '5';
}
else {
return '';
}
}
////////////////// Command Handlers //////////////////
async setup(adminPort, dependencies, backupFile, force, useSymlinks = false) {
if (force) {
Expand Down Expand Up @@ -518,7 +530,7 @@ class DevServer {
ws: true,
}));
}
else if ((0, fs_extra_1.existsSync)(path.resolve(this.rootDir, 'admin/jsonConfig.json'))) {
else if (this.getJsonConfigPath()) {
// JSON config
await this.createJsonConfigProxy(app, this.config);
}
Expand Down Expand Up @@ -587,25 +599,25 @@ class DevServer {
async createJsonConfigProxy(app, config) {
const browserSyncPort = this.getPort(config.adminPort, HIDDEN_BROWSER_SYNC_PORT_OFFSET);
const bs = this.startBrowserSync(browserSyncPort, false);
// whenever jsonConfig.json changes, we upload the new file
const jsonConfig = path.resolve(this.rootDir, 'admin/jsonConfig.json');
bs.watch(jsonConfig, undefined, async (e) => {
// whenever jsonConfig.json[5] changes, we upload the new file
const jsonConfigFile = this.getJsonConfigPath();
bs.watch(jsonConfigFile, undefined, async (e) => {
var _a;
if (e === 'change') {
const content = await (0, fs_extra_1.readFile)(jsonConfig);
const content = await (0, fs_extra_1.readFile)(jsonConfigFile);
(_a = this.websocket) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify([
3,
46,
'writeFile',
[`${this.adapterName}.admin`, 'jsonConfig.json', Buffer.from(content).toString('base64')],
[`${this.adapterName}.admin`, path.basename(jsonConfigFile), Buffer.from(content).toString('base64')],
]));
}
});
// "proxy" for the main page which injects our script
const adminUrl = `http://127.0.0.1:${this.getPort(config.adminPort, HIDDEN_ADMIN_PORT_OFFSET)}`;
app.get('/', async (_req, res) => {
const { data } = await axios_1.default.get(adminUrl);
res.send((0, jsonConfig_1.injectCode)(data, this.adapterName));
res.send((0, jsonConfig_1.injectCode)(data, this.adapterName, path.basename(jsonConfigFile)));
});
// browser-sync proxy
app.use((0, http_proxy_middleware_1.createProxyMiddleware)(['/browser-sync/**'], {
Expand Down
4 changes: 2 additions & 2 deletions dist/jsonConfig.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.injectCode = void 0;
function injectCode(html, adapterName) {
function injectCode(html, adapterName, jsonConfigFileName) {
return html.replace('</head>', `
<script type="module">
import { io } from "https://cdn.socket.io/4.4.1/socket.io.esm.min.js";
Expand Down Expand Up @@ -32,7 +32,7 @@ socket.on("browser:reload", async () => {
async function readJsonConfig() {
return new Promise((resolve, reject) => {
window.io.emit("readFile", "${adapterName}.admin", "jsonConfig.json", (err, data, type) => {
window.io.emit("readFile", "${adapterName}.admin", "${jsonConfigFileName}", (err, data, type) => {
if (err) reject(err);
else resolve(data);
});
Expand Down

0 comments on commit 8a540ca

Please sign in to comment.