@edryslabs/edrys-dev 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat.js +16 -7
- package/dist/index.js +1 -0
- package/dist/server.js +7 -4
- package/package.json +1 -1
- package/views/panel.js +2 -0
package/dist/chat.js
CHANGED
|
@@ -97,11 +97,6 @@ export class Chat extends EventEmitter {
|
|
|
97
97
|
// e.g. a form that was closed in the meantime
|
|
98
98
|
res.sendStatus(409);
|
|
99
99
|
});
|
|
100
|
-
for (const [file, source] of Object.entries(PANEL_FILES)) {
|
|
101
|
-
// dotfiles: sendFile checks the whole absolute path, and installs often
|
|
102
|
-
// live under one (~/.nvm, ~/.npm/_npx); the path is ours, not the request's
|
|
103
|
-
app.get('/edrys-dev/' + file, (req, res) => res.sendFile(source(), { dotfiles: 'allow' }));
|
|
104
|
-
}
|
|
105
100
|
}
|
|
106
101
|
add(entry) {
|
|
107
102
|
this.entries.push(entry);
|
|
@@ -132,5 +127,19 @@ const PANEL_FILES = {
|
|
|
132
127
|
'marked.js': () => path.join(path.dirname(require.resolve('marked/package.json')), 'lib', 'marked.umd.js'),
|
|
133
128
|
'purify.js': () => require.resolve('dompurify/purify.min.js'),
|
|
134
129
|
};
|
|
135
|
-
/**
|
|
136
|
-
export
|
|
130
|
+
/** Serves panel.js and the libraries its chat uses. */
|
|
131
|
+
export function panelFiles(app) {
|
|
132
|
+
for (const [file, source] of Object.entries(PANEL_FILES)) {
|
|
133
|
+
// dotfiles: sendFile checks the whole absolute path, and installs often
|
|
134
|
+
// live under one (~/.nvm, ~/.npm/_npx); the path is ours, not the request's
|
|
135
|
+
app.get('/edrys-dev/' + file, (req, res) => res.sendFile(source(), { dotfiles: 'allow' }));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The script tag that brings panel.js into the edrys-Lite page: it reloads
|
|
140
|
+
* student and station tabs when a local module changed, and with `chat` (an
|
|
141
|
+
* agent is connected) shows the chat in the class tab.
|
|
142
|
+
*/
|
|
143
|
+
export function panelScript(chat) {
|
|
144
|
+
return `<script src="/edrys-dev/panel.js" defer${chat ? ' data-chat' : ''}></script>`;
|
|
145
|
+
}
|
package/dist/index.js
CHANGED
package/dist/server.js
CHANGED
|
@@ -9,7 +9,7 @@ import { unpack } from 'msgpackr';
|
|
|
9
9
|
import { watchFile, watchModules } from './watch.js';
|
|
10
10
|
import { moduleApp } from './modules.js';
|
|
11
11
|
import { sameOrigin } from './origin.js';
|
|
12
|
-
import { Chat,
|
|
12
|
+
import { Chat, panelFiles, panelScript } from './chat.js';
|
|
13
13
|
// entries the log keeps, oldest first out
|
|
14
14
|
const LOG_MAX = 300;
|
|
15
15
|
// a body in the log is cut to this many characters of JSON
|
|
@@ -158,11 +158,14 @@ export async function startDevServer(options) {
|
|
|
158
158
|
res.sendStatus(204);
|
|
159
159
|
});
|
|
160
160
|
const chat = new Chat(path.join(path.dirname(options.lab), '.edrys-dev', 'chat.json'));
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
// without an agent, nobody would answer
|
|
162
|
+
if (options.agent)
|
|
163
|
+
chat.routes(app);
|
|
164
|
+
panelFiles(app);
|
|
165
|
+
// edrys-Lite's page, with panel.js (the chat shows only in the class tab)
|
|
163
166
|
app.get(['/', '/index.html'], async (req, res) => {
|
|
164
167
|
const page = await fs.readFile(path.join(edrysDist(), 'index.html'), 'utf8');
|
|
165
|
-
res.type('html').send(page +
|
|
168
|
+
res.type('html').send(page + panelScript(!!options.agent));
|
|
166
169
|
});
|
|
167
170
|
app.use(express.static(edrysDist()));
|
|
168
171
|
const server = http.createServer(app);
|
package/package.json
CHANGED