|
1 | | -import type { AbsolutePosixFilePath, RelativePosixFilePath } from '@contentlayer/utils' |
2 | | -import { filePathJoin, fs } from '@contentlayer/utils' |
3 | | -import type { OT } from '@contentlayer/utils/effect' |
4 | | -import { pipe, T } from '@contentlayer/utils/effect' |
5 | | -import type { GetContentlayerVersionError } from '@contentlayer/utils/node' |
6 | | -import { getContentlayerVersion } from '@contentlayer/utils/node' |
7 | | - |
8 | | -import type { HasCwd } from './cwd.js' |
9 | | -import { getCwd } from './cwd.js' |
10 | | -// import utilsPkg from '@contentlayer/utils/package.json' |
11 | | - |
12 | | -export namespace ArtifactsDir { |
13 | | - export const getDirPath = ({ cwd }: { cwd: AbsolutePosixFilePath }): AbsolutePosixFilePath => |
14 | | - filePathJoin(cwd, '.contentlayer' as AbsolutePosixFilePath) |
15 | | - |
16 | | - export const mkdir: T.Effect<OT.HasTracer & HasCwd & fs.HasFs, fs.MkdirError, AbsolutePosixFilePath> = T.gen( |
17 | | - function* ($) { |
18 | | - const cwd = yield* $(getCwd) |
19 | | - const dirPath = getDirPath({ cwd }) |
20 | | - |
21 | | - yield* $(fs.mkdirp(dirPath)) |
22 | | - |
23 | | - return dirPath |
24 | | - }, |
25 | | - ) |
26 | | - |
27 | | - export const getCacheDirPath: T.Effect< |
28 | | - OT.HasTracer & HasCwd & fs.HasFs, |
29 | | - GetContentlayerVersionError, |
30 | | - AbsolutePosixFilePath |
31 | | - > = pipe( |
32 | | - T.struct({ |
33 | | - contentlayerVersion: getContentlayerVersion(), |
34 | | - cwd: getCwd, |
35 | | - }), |
36 | | - T.map(({ contentlayerVersion, cwd }) => |
37 | | - filePathJoin( |
38 | | - getDirPath({ cwd }), |
39 | | - '.cache' as RelativePosixFilePath, |
40 | | - `v${contentlayerVersion}` as RelativePosixFilePath, |
41 | | - ), |
42 | | - ), |
43 | | - ) |
44 | | - |
45 | | - export const mkdirCache: T.Effect< |
46 | | - OT.HasTracer & HasCwd & fs.HasFs, |
47 | | - fs.MkdirError | GetContentlayerVersionError, |
48 | | - AbsolutePosixFilePath |
49 | | - > = pipe( |
50 | | - getCacheDirPath, |
51 | | - T.tap((_) => fs.mkdirp(_)), |
52 | | - ) |
53 | | -} |
| 1 | +export * as ArtifactsDir from './_ArtifactsDir.js' |
0 commit comments