MCPcopy Create free account
hub / github.com/contentlayerdev/contentlayer / runMain

Function runMain

packages/@contentlayer/core/src/runMain.ts:13–78  ·  view source on GitHub ↗
({
    tracingServiceName,
    verbose,
    useInMemoryFs = false,
    customCwd,
  }: {
    tracingServiceName: string
    verbose: boolean
    useInMemoryFs?: boolean
    customCwd?: AbsolutePosixFilePath
  })

Source from the content-addressed store, hash-verified

11
12export const runMain =
13 <TResult>({
14 tracingServiceName,
15 verbose,
16 useInMemoryFs = false,
17 customCwd,
18 }: {
19 tracingServiceName: string
20 verbose: boolean
21 useInMemoryFs?: boolean
22 customCwd?: AbsolutePosixFilePath
23 }) =>
24 (eff: T.Effect<OT.HasTracer & HasClock & HasCwd & HasConsole & fs.HasFs, unknown, TResult>) =>
25 pipe(
26 T.gen(function* ($) {
27 if (process.platform === 'win32') {
28 yield* $(T.log('Warning: Contentlayer might not work as expected on Windows'))
29 }
30
31 const provideCwd_ = customCwd ? provideCwdCustom(customCwd) : provideCwd
32
33 const result = yield* $(pipe(eff, provideTracing(tracingServiceName, 'based-on-env'), provideCwd_, T.result))
34
35 if (result._tag === 'Failure') {
36 const failOrCause = Cause.failureOrCause(result.cause)
37 const errorWasManaged = failOrCause._tag === 'Left'
38
39 if (!errorWasManaged) {
40 yield* $(
41 T.log(`\
42This error shouldn't have happened. Please consider opening a GitHub issue with the stack trace below here:
43https://github.com/contentlayerdev/contentlayer/issues`),
44 )
45 }
46
47 // If failure was a managed error and no `--verbose` flag was provided, print the error message
48 if (errorWasManaged && !verbose) {
49 if (!core.isSourceFetchDataError(failOrCause.left) || !failOrCause.left.alreadyHandled) {
50 yield* $(T.log(failOrCause.left))
51 }
52 }
53 // otherwise for unmanaged errors or with `--verbose` flag provided, print the entire stack trace
54 else {
55 yield* $(T.log(pretty(result.cause)))
56
57 const contentlayerVersion = yield* $(getContentlayerVersion()['|>'](T.provide(DummyTracing)))
58
59 yield* $(
60 T.log(`
61OS: ${process.platform} ${os.release()} (arch: ${process.arch})
62Process: ${process.argv.join(' ')}
63Node version: ${process.version}
64Contentlayer version: ${contentlayerVersion}
65`),
66 )
67 }
68
69 yield* $(T.succeedWith(() => process.exit(1)))
70 return undefined as never

Callers 1

Calls 3

provideCwdCustomFunction · 0.90
provideTracingFunction · 0.90
getContentlayerVersionFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…