MCPcopy Create free account
hub / github.com/Effect-TS/effect / getExampleFiles

Function getExampleFiles

packages/tools/docgen/src/Core.ts:218–333  ·  view source on GitHub ↗
(modules: ReadonlyArray<Domain.Module>)

Source from the content-addressed store, hash-verified

216 * Generates example files for the given modules.
217 */
218const getExampleFiles = (modules: ReadonlyArray<Domain.Module>) =>
219 Effect.gen(function*() {
220 const config = yield* Configuration.Configuration
221 const path = yield* Path.Path
222 let warnings: Array<string> = []
223 const files = Array.flatMap(modules, (module) => {
224 const prefix = module.path.join("-")
225
226 const getFiles =
227 (exampleId: string) =>
228 (namedDoc: { readonly name: string; readonly doc: Domain.Doc }): ReadonlyArray<Domain.File> => {
229 let descriptionExamples: Array<string> = []
230 if (namedDoc.doc.description !== undefined) {
231 const [es, ws] = extractFencedCode(namedDoc.doc.description)
232 warnings = warnings.concat(ws)
233 descriptionExamples = es
234 }
235 let exampleTagExamples: Array<string> = []
236 for (const example of namedDoc.doc.examples) {
237 const [es, ws] = extractFencedCode(example)
238 warnings = warnings.concat(ws)
239 exampleTagExamples = exampleTagExamples.concat(es)
240 }
241 const examples = descriptionExamples.concat(exampleTagExamples)
242 return Array.map(
243 examples,
244 (example, i) => {
245 return new Domain.File(
246 path.join(
247 config.outDir,
248 "examples",
249 `${prefix}-${exampleId}-${namedDoc.name}-${i}.ts`
250 ),
251 example,
252 true // make the file overwritable
253 )
254 }
255 )
256 }
257
258 const allPrefixedNamespaces = Array.flatMap(module.namespaces, (namespace) =>
259 extractPrefixedNestedNamespaces(namespace, ""))
260
261 const moduleExamples = getFiles("module")(module)
262 const classExamples = Array.flatMap(module.classes, (c) =>
263 Array.flatten([
264 getFiles("class")(c),
265 Array.flatMap(
266 c.methods,
267 getFiles(`${c.name}-method`)
268 ),
269 Array.flatMap(
270 c.staticMethods,
271 getFiles(`${c.name}-staticmethod`)
272 )
273 ]))
274 const allPrefixedInterfaces = [
275 ...module.interfaces.map((iface) =>

Callers 1

typeCheckAndRunExamplesFunction · 0.85

Calls 5

getFilesFunction · 0.85
filterJoinFunction · 0.85
joinMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected