Skip to content

Commit

Permalink
Merge pull request #4 from lexmin0412/f-20240423-subpkg-init
Browse files Browse the repository at this point in the history
F 20240423 subpkg init
  • Loading branch information
lexmin0412 authored Apr 23, 2024
2 parents 513a946 + 127ce75 commit 9af8d9f
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .readue/template.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
> 本文件由 [readue](https://github.com/yuanhaoliang/readue) 自动生成。
> 本文件由 [readue](https://github.com/lexmin0412/readue) 自动生成。
{{__READUE_PLACEHOLDER__}}
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,18 @@ README 生成器。
|[@readue/block-star_history](https://www.npmjs.com/package/@readue/block-star_history)|![version](https://img.shields.io/npm/v/@readue/block-star_history) ![downloads-month](https://img.shields.io/npm/dm/@readue/block-star_history)|Readue Star History 块插件|
|[@readue/block-techstack](https://www.npmjs.com/package/@readue/block-techstack)|![version](https://img.shields.io/npm/v/@readue/block-techstack) ![downloads-month](https://img.shields.io/npm/dm/@readue/block-techstack)|Readue 技术栈块插件。|
|[@readue/block-tree](https://www.npmjs.com/package/@readue/block-tree)|![version](https://img.shields.io/npm/v/@readue/block-tree) ![downloads-month](https://img.shields.io/npm/dm/@readue/block-tree)|Readue 文件树块插件。|
|[@readue/cli](https://www.npmjs.com/package/@readue/cli)|![version](https://img.shields.io/npm/v/@readue/cli) ![downloads-month](https://img.shields.io/npm/dm/@readue/cli)|Readue 命令行接口|
|[@readue/cli](https://www.npmjs.com/package/@readue/cli)|![version](https://img.shields.io/npm/v/@readue/cli) ![downloads-month](https://img.shields.io/npm/dm/@readue/cli)|Readue 命令行接口|
|[@readue/config](https://www.npmjs.com/package/@readue/config)|![version](https://img.shields.io/npm/v/@readue/config) ![downloads-month](https://img.shields.io/npm/dm/@readue/config)|Readue 的配置包|
|@readue/docs|私有包, 未发布|Readue 文档|

## 项目结构

```bash
readu
readue
├── CHANGELOG.md
├── README.md
├── changelog.config.js
├── es
│ ├── packages
│ └── src
├── lerna.json
├── lib
│ ├── packages
│ └── src
├── package.json
├── packages
│ ├── api
Expand All @@ -49,7 +43,6 @@ readu
│ └── docs
├── pnpm-lock.yaml
├── pnpm-workspace.yaml
├── test
└── tsconfig.json
```

Expand Down
17 changes: 10 additions & 7 deletions packages/block-packages/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import type { PackageJson } from 'pkg-types'
import { ReadueConfig } from '@readue/config'
import { ReadueBlockFunction } from '@readue/config'
import * as fs from 'fs'
import * as path from 'path'

export default function (_readueConfig: ReadueConfig, pkgJson: PackageJson, options: {
/**
* 块插件函数
*/
const generator: ReadueBlockFunction = function (_readueConfig, _pkgJson, options: {
cwd: string
} = {
cwd: process.cwd()
}) {

const {cwd} = options

let content: string[] = []
const content: string[] = []

const packages = fs.readdirSync(path.resolve(cwd, "./packages"));

if (packages?.length) {
content = [
...content,
content.push(
"## Packages",
"",
"|子包|信息|说明|",
"|---|---|---|",
];
)
}

packages.forEach((item) => {
Expand All @@ -48,3 +49,5 @@ export default function (_readueConfig: ReadueConfig, pkgJson: PackageJson, opti
]
}
}

export default generator
8 changes: 6 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@readue/cli",
"version": "0.3.4",
"description": "Readue 命令行接口",
"description": "Readue 命令行接口",
"bin": {
"readue": "./bin/readue.js",
"ru": "./bin/readue.js"
Expand Down Expand Up @@ -42,6 +42,7 @@
"url": "https://github.com/lexmin0412/readu/issues"
},
"devDependencies": {
"@types/figlet": "^1.5.8",
"@types/node": "^20.12.7",
"rimraf": "^5.0.5",
"ts-node": "^10.9.2",
Expand All @@ -53,6 +54,9 @@
"dependencies": {
"@readue/api": "workspace:*",
"@readue/config": "workspace:*",
"@toolkit-fe/request": "^0.1.22"
"@toolkit-fe/request": "^0.1.22",
"commander": "^12.0.0",
"figlet": "^1.7.0",
"picocolors": "^1.0.0"
}
}
29 changes: 29 additions & 0 deletions packages/cli/src/commands/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* 创建一个插件
*/
export const create = () => {
console.log(process.argv)
if (!process.argv[3]) {
console.error('请输入插件名称')
process.exit(1)
}

const content =
`import type { ReadueBlockFunction } from '@readue/config'
const generator: ReadueBlockFunction = (readueConfig, pkgJson) => {
const content: string[] = []
return {
name: '',
content
}
}
export default generator
`
// TODO 通过 tpc 插件注入内容

return content
}
29 changes: 29 additions & 0 deletions packages/cli/src/commands/gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as path from 'path'
import * as fs from 'fs'
import { generate4Monorepo, generate4SinglePkg, isMonorepo } from "@readue/api"
import { writeReadme } from "../utils"

/**
* 生成 RAEDME 文件
*/
export const gen = () => {
const content = fs.readFileSync(path.resolve(process.cwd(), 'package.json')).toString()

const pkgJson = JSON.parse(content)

const genContent = () => {
if (isMonorepo(process.cwd())) {
return generate4Monorepo(pkgJson, process.cwd())
} else {
return generate4SinglePkg(pkgJson)
}
}

const readmeLines = genContent()

// 写到 当前目录的 README.md 中
writeReadme(readmeLines)

console.log('')
}

58 changes: 43 additions & 15 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,55 @@
import * as path from 'path'
import * as fs from 'fs'
import { generate4Monorepo, generate4SinglePkg, isMonorepo } from '@readue/api'
import { writeReadme } from './utils'
import figlet from 'figlet'
import pc from 'picocolors'
import { program } from 'commander'
import { gen } from './commands/gen'
import { create } from './commands/create'

const content = fs.readFileSync(path.resolve(__dirname, '../package.json')).toString()

const pkgJson = JSON.parse(content)

console.log(`
[info] @readue/cli 启动
`)

const content = fs.readFileSync(path.resolve(process.cwd(), 'package.json')).toString()
const artText = figlet.textSync('R e a d u e', {
font: 'Standard',
horizontalLayout: 'default',
verticalLayout: 'default',
width: 80,
whitespaceBreak: true
})

const pkgJson = JSON.parse(content)
console.log(pc.green(artText))

const genContent = () => {
if (isMonorepo(process.cwd())) {
return generate4Monorepo(pkgJson, process.cwd())
} else {
return generate4SinglePkg(pkgJson)
}
}
console.log(`> readue ${process.argv[2]}
`)

const readmeLines = genContent()
program
.version(pkgJson.version)
.command('gen')
.description('生成 README.md 文件')
.action(() => {
try {
gen()
} catch (error) {
console.error(error)
process.exit(1)
}
})

// 写到 当前目录的 README.md 中
writeReadme(readmeLines)
program
.command('create')
.description('创建 Readue 插件')
.action(() => {
try {
create()
} catch (error) {
console.error(error)
process.exit(1)
}
})

console.log('')
program.parse()
3 changes: 2 additions & 1 deletion packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"moduleResolution": "node",
"esModuleInterop": true,
"lib": [
"es6"
],
Expand All @@ -11,4 +12,4 @@
"includes": [
"src/*"
]
}
}
27 changes: 26 additions & 1 deletion pnpm-lock.yaml

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

0 comments on commit 9af8d9f

Please sign in to comment.