Skip to content

Commit

Permalink
feat: add prepare command for local types support (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed May 26, 2023
1 parent 0bfe4ef commit 612c6b2
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 8 deletions.
4 changes: 2 additions & 2 deletions example/package.json
Expand Up @@ -17,10 +17,10 @@
"dist"
],
"scripts": {
"prepack": "jiti ../src/cli.ts",
"prepack": "JITI_ESM_RESOLVE=1 jiti ../src/cli.ts",
"dev": "nuxi dev playground",
"dev:build": "nuxi build playground",
"dev:prepare": "jiti ../src/cli.ts --stub && nuxi prepare playground"
"dev:prepare": "JITI_ESM_RESOLVE=1 jiti ../src/cli.ts --stub && JITI_ESM_RESOLVE=1 jiti ../src/cli.ts prepare"
},
"dependencies": {
"@nuxt/kit": "^3.5.1"
Expand Down
2 changes: 1 addition & 1 deletion example/tsconfig.json
@@ -1,3 +1,3 @@
{
"extends": "./playground/.nuxt/tsconfig.json"
"extends": "./.nuxt/tsconfig.json"
}
7 changes: 6 additions & 1 deletion package.json
Expand Up @@ -23,7 +23,7 @@
"build": "unbuild",
"example:build": "pnpm nuxt-module-build ./example",
"lint": "eslint --ext .ts,.js,.mjs .",
"nuxt-module-build": "jiti ./src/cli.ts",
"nuxt-module-build": "JITI_ESM_RESOLVE=1 jiti ./src/cli.ts",
"prepack": "pnpm build",
"release": "pnpm test && standard-version && git push --follow-tags && npm publish",
"test": "pnpm vitest"
Expand All @@ -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.1",
"@nuxt/schema": "^3.5.1",
Expand All @@ -45,6 +49,7 @@
"@vitest/coverage-c8": "^0.31.1",
"eslint": "^8.41.0",
"jiti": "^1.18.2",
"nuxi": "^3.5.1",
"nuxt": "^3.5.1",
"standard-version": "^9.5.0",
"vitest": "^0.31.1"
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.

16 changes: 12 additions & 4 deletions src/cli.ts
Expand Up @@ -4,12 +4,20 @@
import mri from 'mri'
import { resolve } from 'pathe'
import { buildModule } from './build'
import { prepareModule } from './prepare'

async function main () {
// TODO: use citty
function main () {
const args = mri(process.argv.slice(2))
const rootDir = resolve(args._[0] || '.')
await buildModule({
rootDir,

if (args._[0] === 'prepare') {
return prepareModule({
rootDir: resolve(args._[1] || '.')
})
}

return buildModule({
rootDir: resolve(args._[0] || '.'),
outDir: args.outDir,
stub: args.stub
})
Expand Down
30 changes: 30 additions & 0 deletions src/prepare.ts
@@ -0,0 +1,30 @@
import { resolve } from 'pathe'

export interface PrepareModuleOptions {
rootDir: string
}

export async function prepareModule (options: PrepareModuleOptions) {
const { runCommand } = await import('nuxi')

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

0 comments on commit 612c6b2

Please sign in to comment.