Skip to content

Commit

Permalink
fix: use mkdirp
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Apr 9, 2021
1 parent c2c6cd5 commit c54e393
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"defu": "^3.2.2",
"esbuild": "^0.11.6",
"jiti": "^1.9.1",
"mkdirp": "^1.0.4",
"mkdist": "^0.1.5",
"mri": "^1.1.6",
"pretty-bytes": "^5.6.0",
Expand All @@ -46,6 +47,7 @@
},
"devDependencies": {
"@nuxtjs/eslint-config-typescript": "latest",
"@types/mkdirp": "^1.0.1",
"@types/mri": "latest",
"@types/node": "latest",
"@types/rimraf": "latest",
Expand Down
5 changes: 3 additions & 2 deletions src/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { promisify } from 'util'
import Module from 'module'
import { mkdir, unlink } from 'fs/promises'
import { unlink } from 'fs/promises'
import mkdirp from 'mkdirp'
import { resolve, basename } from 'upath'
import chalk from 'chalk'
import consola from 'consola'
Expand Down Expand Up @@ -77,7 +78,7 @@ export async function build (rootDir: string, stub: boolean) {
const outDir = resolve(ctx.rootDir, ctx.outDir)
await unlink(outDir).catch(() => { })
await promisify(rimraf)(outDir)
await mkdir(outDir).catch(() => { })
await mkdirp(outDir)
}

// selflink
Expand Down
8 changes: 4 additions & 4 deletions src/builder/untyped.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { writeFile, mkdir } from 'fs/promises'
import { resolve, dirname } from 'upath'
import { writeFile } from 'fs/promises'
import { resolve } from 'upath'
import { resolveSchema, generateTypes, generateMarkdown } from 'untyped'
import untypedPlugin from 'untyped/dist/loader/babel'
import jiti from 'jiti'
import { pascalCase } from 'scule'
import mkdirp from 'mkdirp'
import type { BuildContext } from '../types'

export async function typesBuild (ctx: BuildContext) {
Expand All @@ -25,8 +26,7 @@ export async function typesBuild (ctx: BuildContext) {
const defaults = entry.defaults || {}
const schema = resolveSchema(srcConfig, defaults)

await mkdir(dirname(genDir)).catch(() => { })
await mkdir(genDir).catch(() => { })
await mkdirp(genDir)
await writeFile(resolve(genDir, `${entry.name}.md`), generateMarkdown(schema))
await writeFile(resolve(genDir, `${entry.name}.schema.json`), JSON.stringify(schema, null, 2))
await writeFile(resolve(genDir, `${entry.name}.defaults.json`), JSON.stringify(defaults, null, 2))
Expand Down
3 changes: 3 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import fsp from 'fs/promises'
import { dirname } from 'upath'
import mkdirp from 'mkdirp'

export async function symlink (from: string, to: string, force: boolean = true) {
await mkdirp(dirname(from))
if (force) {
await fsp.unlink(to).catch(() => { })
}
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,13 @@
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.1.tgz#283f669ff76d7b8260df8ab7a4262cc83d988256"
integrity sha512-fZQQafSREFyuZcdWFAExYjBiCL7AUCdgsk80iO0q4yihYYdcIiH28CcuPTGFgLOCC8RlW49GSQxdHwZP+I7CNg==

"@types/mkdirp@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@types/mkdirp/-/mkdirp-1.0.1.tgz#0930b948914a78587de35458b86c907b6e98bbf6"
integrity sha512-HkGSK7CGAXncr8Qn/0VqNtExEE+PHMWb+qlR1faHMao7ng6P3tAaoWWBMdva0gL5h4zprjIO89GJOLXsMcDm1Q==
dependencies:
"@types/node" "*"

"@types/mri@latest":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@types/mri/-/mri-1.1.0.tgz#66555e4d797713789ea0fefdae0898d8170bf5af"
Expand Down Expand Up @@ -2228,6 +2235,11 @@ minimist@^1.1.3, minimist@^1.2.0, minimist@^1.2.5:
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==

mkdirp@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==

mkdist@^0.1.5:
version "0.1.5"
resolved "https://registry.yarnpkg.com/mkdist/-/mkdist-0.1.5.tgz#ce1401916f388f42ed6f7a95b342cac6b165d863"
Expand Down

0 comments on commit c54e393

Please sign in to comment.