Skip to content

Commit

Permalink
Merge pull request #5 from lexmin0412/f-20240423-subpkg-init
Browse files Browse the repository at this point in the history
feat(cli): 支持一键创建插件包
  • Loading branch information
lexmin0412 authored Apr 29, 2024
2 parents 67faa5d + b8d644e commit 54ff801
Show file tree
Hide file tree
Showing 4 changed files with 760 additions and 22 deletions.
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"jsnext:main": "./es/index.js",
"module": "./es/index.js",
"dependencies": {
"@lexmin0412/tpc": "^2.3.0",
"@readue/api": "workspace:*",
"@readue/config": "workspace:*",
"@toolkit-fe/request": "^0.1.22",
Expand Down
34 changes: 32 additions & 2 deletions packages/cli/src/commands/create.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { init } from '@lexmin0412/tpc'
import * as path from 'path'
import { execSync } from 'child_process'

/**
* 创建一个插件
*/
Expand All @@ -8,6 +12,19 @@ export const create = () => {
process.exit(1)
}

// 创建目录
console.log('创建目录')
execSync(`mkdir ${process.argv[3]}`, {
cwd: process.cwd(),
})
// npm 初始化
console.log('npm 初始化')
execSync('npm init -y', {
cwd: path.resolve(process.cwd(), process.argv[3]),
})

console.log('即将执行 TPC 初始化')

const content =
`import type { ReadueBlockFunction } from '@readue/config'
Expand All @@ -23,7 +40,20 @@ const generator: ReadueBlockFunction = (readueConfig, pkgJson) => {
export default generator
`
// TODO 通过 tpc 插件注入内容

return content
return init({
cwd: path.resolve(process.cwd(), process.argv[3]),
pkgJsonConfig: {
name: `@readue/block-${process.argv[3]}`,
dependencies: {
'@readue/config': 'latest',
},
},
fileList: [
{
path: path.resolve(process.cwd(), process.argv[3], 'src/index.ts'),
content
}
]
})
}
4 changes: 2 additions & 2 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ program
program
.command('create')
.description('创建 Readue 插件')
.action(() => {
.action(async() => {
try {
create()
await create()
} catch (error) {
console.error(error)
process.exit(1)
Expand Down
Loading

0 comments on commit 54ff801

Please sign in to comment.