-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): 引入 command 实现多脚本定义, 引入 figlet 实现 banner
- Loading branch information
1 parent
b727a9f
commit 6cca930
Showing
6 changed files
with
135 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('') | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.