-
-
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.
Merge pull request #4 from lexmin0412/f-20240423-subpkg-init
F 20240423 subpkg init
- Loading branch information
Showing
9 changed files
with
148 additions
and
36 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
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__}} |
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
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.