Skip to content

Commit

Permalink
feat: schema loader
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Apr 9, 2021
1 parent 5a1f9cd commit e2388bb
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules
coverage
dist
types
.gen
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"scripts": {
"build": "yarn unbuild",
"stub": "yarn build --stub",
"dev": "yarn unbuild test/fixture",
"lint": "eslint --ext .ts,.js .",
"unbuild": "jiti ./src/cli",
"prepublishOnly": "yarn build",
Expand All @@ -31,7 +32,7 @@
"consola": "^2.15.3",
"defu": "^3.2.2",
"esbuild": "^0.10.0",
"jiti": "^1.6.4",
"jiti": "^1.8.0",
"mkdist": "^0.1.4",
"mri": "^1.1.6",
"pretty-bytes": "^5.6.0",
Expand Down
1 change: 0 additions & 1 deletion src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,3 @@ export async function build (rootDir: string, stub: boolean) {

consola.log('')
}

14 changes: 13 additions & 1 deletion src/builder/untyped.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import { writeFile, mkdir } from 'fs/promises'
import { resolve, dirname } from 'upath'
import { resolveSchema, generateTypes, generateMarkdown } from 'untyped'
import untypedPlugin from 'untyped/dist/loader/babel'
import jiti from 'jiti'
import { pascalCase } from 'scule'
import type { BuildContext } from '../types'

export async function typesBuild (ctx: BuildContext) {
for (const entry of ctx.entries.filter(entry => entry.builder === 'untyped')) {
const srcConfig = await import(resolve(ctx.rootDir, entry.input)).then(r => r.default)
const _require = jiti(ctx.rootDir, {
transformOptions: {
babel: {
plugins: [
untypedPlugin
]
}
}
})

const srcConfig = _require(resolve(ctx.rootDir, entry.input))
const genDir = resolve(ctx.rootDir, ctx.genDir, entry.name)

const defaults = entry.defaults || {}
Expand Down
8 changes: 8 additions & 0 deletions test/fixture/build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { BuildConfig } from 'unbuild'

export default <BuildConfig>{
entries: [
'src/index',
{ input: 'src/schema', builder: 'untyped' }
]
}
4 changes: 4 additions & 0 deletions test/fixture/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "fixture",
"private": "true"
}
1 change: 1 addition & 0 deletions test/fixture/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foo = 'bar'
3 changes: 3 additions & 0 deletions test/fixture/src/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const config = {
foo: 'bar'
}
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1924,11 +1924,16 @@ isexe@^2.0.0:
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=

jiti@^1.6.3, jiti@^1.6.4:
jiti@^1.6.3:
version "1.6.4"
resolved "https://registry.yarnpkg.com/jiti/-/jiti-1.6.4.tgz#63453b602d0234f8bd7ce638f03f0e74ef99be12"
integrity sha512-ICUtP0/rAyT/GaaDG0vj6fmWzx5yjFc7v+L1MAEARGl1+lrdJ8wtJNChr+ZGEdPoOhFwdhtcDO5VM2TNNgPpjQ==

jiti@^1.8.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/jiti/-/jiti-1.8.0.tgz#8ddec5722b5785eb98cbe4298c0d8080ff5814d1"
integrity sha512-qtwVKO+1YbKIssnbnGN/V6m9g0XvNTCKwk3mJWJD+kEgkxHTozhSZiV7Vb8nkjzKU7asL7m1xOowXBJvjwlZ+g==

joycon@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/joycon/-/joycon-3.0.1.tgz#9074c9b08ccf37a6726ff74a18485f85efcaddaf"
Expand Down

0 comments on commit e2388bb

Please sign in to comment.