-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
可通过`npm run plop`生成指定类型代码,例如:视图代码 或 组件代码
- Loading branch information
ShanYi-Hui
committed
Apr 7, 2024
1 parent
e03c8d2
commit 124dee0
Showing
8 changed files
with
1,799 additions
and
69 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,6 @@ | ||
<script setup lang="ts"> | ||
</script> | ||
|
||
<template> | ||
<div class="{{ kebabName }}">{{ upperFirstName }}</div> | ||
</template> |
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,3 @@ | ||
import {{ upperFirstName }} from './src/{{ upperFirstName }}.vue' | ||
|
||
export { {{ upperFirstName }} } |
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,50 @@ | ||
const toUpperCase = (str) => str.charAt(0).toUpperCase() + str.slice(1) | ||
|
||
export default { | ||
description: '创建组件', | ||
prompts: [ | ||
{ | ||
type: 'input', | ||
name: 'name', | ||
message: '请输入组件名称', | ||
default: 'NewComponent', | ||
validate: (value) => { | ||
if (/^[A-Za-z]+$/.test(value)) { | ||
return true | ||
} | ||
return '组件名称只能为英文字符' | ||
} | ||
} | ||
], | ||
actions: (data) => { | ||
const { name } = data | ||
const upperFirstName = toUpperCase(name) | ||
const kebabName = name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase() | ||
|
||
const actions = [] | ||
if (name) { | ||
actions.push( | ||
{ | ||
type: 'add', | ||
path: `./src/components/${upperFirstName}/src/${upperFirstName}.vue`, | ||
templateFile: './plop/component/component.hbs', | ||
data: { | ||
name, | ||
upperFirstName, | ||
kebabName | ||
} | ||
}, | ||
{ | ||
type: 'add', | ||
path: `./src/components/${upperFirstName}/index.ts`, | ||
templateFile: './plop/component/index.hbs', | ||
data: { | ||
upperFirstName | ||
} | ||
} | ||
) | ||
} | ||
|
||
return actions | ||
} | ||
} |
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,40 @@ | ||
const toUpperCase = (str) => str.charAt(0).toUpperCase() + str.slice(1) | ||
|
||
export default { | ||
description: '创建视图', | ||
prompts: [ | ||
{ | ||
type: 'input', | ||
name: 'path', | ||
message: '请输入路径', | ||
default: 'views/NewView' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'name', | ||
message: '请输入模块名称', | ||
default: 'NewPage' | ||
} | ||
], | ||
actions: (data) => { | ||
const { name, path } = data | ||
const upperFirstName = toUpperCase(name) | ||
const kebabName = name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase() | ||
|
||
const actions = [] | ||
if (name) { | ||
actions.push({ | ||
type: 'add', | ||
path: `./src/${path}/${upperFirstName}.vue`, | ||
templateFile: './plop/view/view.hbs', | ||
data: { | ||
name, | ||
upperFirstName, | ||
kebabName | ||
} | ||
}) | ||
} | ||
|
||
return actions | ||
} | ||
} |
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,7 @@ | ||
<script setup lang="ts"> | ||
import { ContentWrap } from '@/components/ContentWrap' | ||
</script> | ||
|
||
<template> | ||
<ContentWrap class="{{ kebabName }}" title="{{ upperFirstName }}"> {{ name }} </ContentWrap> | ||
</template> |
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,8 @@ | ||
import viewGenerator from './plop/view/prompt.js' | ||
import componentGenerator from './plop/component/prompt.js' | ||
|
||
export default function (plop) { | ||
plop.setWelcomeMessage('请选择代码生成器类型') | ||
plop.setGenerator('view', viewGenerator) | ||
plop.setGenerator('component', componentGenerator) | ||
} |