MCPcopy Create free account
hub / github.com/dailydotdev/apps / startDev

Function startDev

packages/world-cli/src/dev.js:139–429  ·  view source on GitHub ↗
({ directory, port, targets, user })

Source from the content-addressed store, hash-verified

137const withoutPayload = ({ payload: _payload, ...report }) => report;
138
139export async function startDev({ directory, port, targets, user }) {
140 const clients = new Set();
141 const builders = new Map();
142 const removedTargets = new Map();
143 const fileHashes = new Map();
144 let version = 0;
145
146 const send = (res, event) => {
147 res.write(`data: ${JSON.stringify(event)}\n\n`);
148 };
149 const broadcast = (event) => {
150 for (const res of clients) send(res, event);
151 };
152 const snapshot = () => ({
153 protocol: PROTOCOL_VERSION,
154 user,
155 version,
156 entries: [...builders.values()].flatMap(({ good }) =>
157 good ? [good] : []
158 ),
159 reports: [...builders.values()].map(({ status }) => status),
160 removals: [...removedTargets.values()],
161 });
162 const readyFrame = () => ({
163 type: "ready",
164 protocol: PROTOCOL_VERSION,
165 user,
166 version,
167 builders: snapshot().entries.length,
168 });
169
170 const removeFile = (file) => {
171 const removals = [];
172 for (const [key, builder] of builders) {
173 if (builder.file !== file) continue;
174 builders.delete(key);
175 if (builder.good) {
176 removals.push(builder.target);
177 removedTargets.set(key, builder.target);
178 }
179 }
180 fileHashes.delete(file);
181 return removals;
182 };
183
184 const install = (file, target, report) => {
185 const frame = frameFor(report, target);
186 const key = keyOf(target);
187 const previous = builders.get(key);
188 if (report.ok) removedTargets.delete(key);
189 const status = withoutPayload(frame);
190 builders.set(key, {
191 file,
192 target,
193 status,
194 good: report.ok ? frame : previous?.good,
195 });
196 printReport(report, { json: false, file });

Callers 1

runDevFunction · 0.90

Calls 10

rebuildFileFunction · 0.85
resolveFunction · 0.85
allowedOriginFunction · 0.85
jsonFunction · 0.85
corsForFunction · 0.85
readyFrameFunction · 0.85
snapshotFunction · 0.85
compressedJsonFunction · 0.85
flushFunction · 0.85
sendFunction · 0.70

Tested by

no test coverage detected