Skip to content

a self-defining module generator plugin for bb-mt

License

Notifications You must be signed in to change notification settings

xgfe/bb-plugin-add

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bb-plugin-add

npm version Build Status

A self-defining module generator plugin for bb-mt

Get Start

First, you should install bb and this plugin:

$ npm install -g bb-mt bb-plugin-add

Next, create your own project folder and run init:

$ mkdir my-project && cd my-project
$ bb init

Now, We find .tpl in root path.

$ cd .tpl

Then, create bb.config.js

# bb.config.js
const componentConfig = {
	source: './component/', // 模板源
	output: './src/components/${HEAD_UPPER(name)}/', // 输出文件路径
	queue: [
		{
			template: 'map.js', // 模板文件
			filename: '../index.js', // 输出文件
			progress: function (compiler) { // 钩子函数:bb-plugin-add@0.3.x及以上支持
        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

# 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

About

a self-defining module generator plugin for bb-mt

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published