https://github.com/xgfe/bb-plugin-add
a self-defining module generator plugin for bb-mt
https://github.com/xgfe/bb-plugin-add
Last synced: about 2 months ago
JSON representation
a self-defining module generator plugin for bb-mt
- Host: GitHub
- URL: https://github.com/xgfe/bb-plugin-add
- Owner: xgfe
- License: mit
- Created: 2018-06-26T09:28:47.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-14T13:30:48.000Z (over 6 years ago)
- Last Synced: 2025-03-27T13:46:23.452Z (about 2 months ago)
- Language: JavaScript
- Size: 68.4 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bb-plugin-add
[](https://badge.fury.io/js/bb-plugin-add) [](https://travis-ci.org/xgfe/bb-plugin-add)
A self-defining module generator plugin for bb-mt
## Get Start
First, you should install bb and this plugin:
```sh
$ npm install -g bb-mt bb-plugin-add
```
Next, create your own project folder and run init:
```sh
$ mkdir my-project && cd my-project
$ bb init
```
Now, We find .tpl in root path.
```sh
$ cd .tpl
```Then, create bb.config.js
```sh
# bb.config.js
const componentConfig = {
source: './component/', // 模板源
output: './src/components/${HEAD_UPPER(name)}/', // 输出文件路径
queue: [
{
template: 'map.js', // 模板文件
filename: '../index.js', // 输出文件
progress: function (compiler) { // 钩子函数:[email protected]及以上支持
const content = "export { ${HEAD_UPPER(name)}, example as ${HEAD_UPPER(name)}Example} from './${HEAD_UPPER(name)}'";
// 在/** @bb-mt add */前插入内容
compiler.comment('add').before.insert(content);
}
},
{
template: 'index.js',
filename: 'index.js'
},
{
template: 'component.vue',
filename: '${HEAD_UPPER(name)}.vue'
},
{
template: 'component.less',
filename: '${HEAD_UPPER(name)}.less'
},
{
template: 'componentConstants.js',
filename: '${HEAD_UPPER(name)}Constants.js'
},
{
template: 'example/index.js',
filename: 'example/index.js'
},
{
template: 'example/exampleCode.vue',
filename: 'example/exampleCode.vue'
},
{
template: 'example/exampleCodeConstants.js',
filename: 'example/exampleCodeConstants.js'
},
{
template: 'example/exampleCodeStyle.less',
filename: 'example/exampleCodeStyle.less'
}
]
};module.exports = {
add: {
component: componentConfig
}
};
```## Usage
```
bb add component MyComponent
```## Keywords
```sh
# For example, edit template file like this
# Entity name is ${name}
export { default as ${name}} from "${name}"
```### Build-in Keywords
You can use build-in keywords below:
- `name`
Your entity name.
- `datetime`
Datetime in os.
- `fullname`
Username in os.
- `gitname`
Username in git.
- `email`
Email of git.### Self-defining Keywords
You can set up self-defining keywords in config.json
## Build-in Functions
- `UPPERCASE` MyComponent - MYCOMPONENT
- `LOWERCASE` MyComponent - mycomponent
- `HEAD_UPPER` myComponent - MyComponent
- `HEAD_LOWER` MyComponent - myComponent
- `GAP_HYPHEN` MyComponent - -my-component
- `GAP_UNDERSCORE` MyComponent - _my_component
- `CSS_CLASS_HYPHEN_STYLE` MyComponent - my-component## Thanks
@feyy
## License
MIT