From 71bb35175496929bfe52eef03d84c7678504cd93 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 16 May 2023 15:03:54 +0000 Subject: [PATCH] feat: add `--prepare` mode for local types support --- example/tsconfig.json | 2 +- package.json | 5 +++++ pnpm-lock.yaml | 3 +++ src/cli.ts | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/example/tsconfig.json b/example/tsconfig.json index 9dd826f..4b34df1 100644 --- a/example/tsconfig.json +++ b/example/tsconfig.json @@ -1,3 +1,3 @@ { - "extends": "./playground/.nuxt/tsconfig.json" + "extends": "./.nuxt/tsconfig.json" } diff --git a/package.json b/package.json index 03f1003..dbfa04d 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 37321ff..6e20962 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -44,6 +44,9 @@ importers: jiti: specifier: ^1.18.2 version: 1.18.2 + nuxi: + specifier: ^3.5.0 + version: 3.5.0 nuxt: specifier: ^3.5.0 version: 3.5.0(@types/node@20.1.3)(eslint@8.40.0)(rollup@3.21.7)(typescript@5.0.4) diff --git a/src/cli.ts b/src/cli.ts index ae217a0..8d70123 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -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({ @@ -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)