Skip to content

Commit

Permalink
feat: add --prepare mode for local types support
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed May 16, 2023
1 parent d88d8a8 commit 71bb351
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "./playground/.nuxt/tsconfig.json"
"extends": "./.nuxt/tsconfig.json"
}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
"pathe": "^1.1.0",
"unbuild": "^1.2.1"
},
"peerDependencies": {
"@nuxt/kit": "^3.5.0",
"nuxi": "^3.5.0"
},
"devDependencies": {
"@nuxt/kit": "^3.5.0",
"@nuxt/schema": "^3.5.0",
Expand All @@ -45,6 +49,7 @@
"@vitest/coverage-c8": "^0.31.0",
"eslint": "^8.40.0",
"jiti": "^1.18.2",
"nuxi": "^3.5.0",
"nuxt": "^3.5.0",
"standard-version": "^9.5.0",
"vitest": "^0.31.0"
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ import mri from 'mri'
import { resolve } from 'pathe'
import { buildModule } from './build'

// TODO: use citty
async function main () {
const args = mri(process.argv.slice(2))
if ('prepare' in args) {
return prepare()
}
return build()
}

async function build () {
const args = mri(process.argv.slice(2))
const rootDir = resolve(args._[0] || '.')
await buildModule({
Expand All @@ -15,6 +24,33 @@ async function main () {
})
}

async function prepare () {
const { runCommand } = await import('nuxi')
const args = mri(process.argv.slice(2))
const rootDir = resolve(args._[0] || '.')

return runCommand('prepare', [rootDir], {
overrides: {
typescript: {
builder: 'shared'
},
imports: {
autoImport: false
},
modules: [
resolve(rootDir, './src/module'),
function (options, nuxt) {
nuxt.hooks.hook('app:templates', app => {
for (const template of app.templates) {
template.write = true
}
})
}
]
}
})
}

main().catch((err) => {
console.error(err)
process.exit(1)
Expand Down

0 comments on commit 71bb351

Please sign in to comment.