当前位置:网站首页>more-copy. JS specifies that the file template is generated to the specified file directory

more-copy. JS specifies that the file template is generated to the specified file directory

2022-06-12 20:01:00 Pengshiyu

more-copy.js

The specified file template is generated to the specified file directory

install

#  Global installation is recommended 
npm i more-copy -g

Use

1、 Command line

$ mcp [ Template path ] [ The output path ] [-p json character string ] [-c  Profile path ]

eg:
$ mcp template.js demo.js

Parameters

-c  Specify the profile path   The default is  ./more-copy.config.js
-p  Pass in the parameter , receive json Format string 

2、 user designation codes

const {
     renderToFile } = require('more-copy');

renderToFile({
     input, output });

Templates

Template rendering based on Nunjuck.js, The implication , Support Nunjuck.js All template syntax for
https://nunjucks.bootcss.com/templating.html

Command line

Usually , The file generation path of a project is fixed , Can combine package.json perhaps make Simplify the command line

To configure

The current directory can be configured more-copy.config.js

//  Plug in Example 
const {
     MkdirPlugin, ParsePlugin, TimePlugin } = require('more-copy');

//  Use custom plug-ins 
const CustomPlugin = require('./custom-plugin.js');

module.exports = {
    
  //  Open the debug 
  debug: true,
  //  The use of plug-in , In order 
  plugins: [new CustomPlugin()],
};

The plug-in has been implemented

Users can use plug-ins to give options Add parameter

The plug-in contract adds options Properties on objects , Name the plug-in , Except for special .

for example : Use ParsePlugin Attributes will be added options.parse

//  Plug in base class , Custom plug-ins are recommended to inherit this base class , And implement its method 
Plugin(options);

// 1、 Create target folder recursively 
MkdirPlugin();

// 2、 Change the naming style of the output file name , Support naming-style All style parameters of 
// eg: {style: 'pascal'}
OutputNamingPlugin({
     style });

// 3、 Resolve path parameters 
ParsePlugin();

// 4、ThinkPHP Required parameters 
//  Support additional parameters  -p '{"name": "table_name"}'
ThinkphpPlugin({
     prefix: ' Table prefix ' });

// 5、 Time plug in 
TimePlugin();

// 6、Vue Required parameters 
//  Support additional parameters  -p '{"name": "name"}'
VuePlugin();

// 7、 from MySQL Query data in 
// -p '{sql, data}'
MySQLPlugin({
    
  config
});

// 8、 from MySQL Query table data in 
// -p '{table}'
TablePlugin({
    
  config
});

// 9、 Change the naming style of the output folder , Support naming-style All style parameters of 
OutputDirnameNamingPlugin({
    style})

Custom plug in

custom-plugin.js Used to process template input parameters

const Plugin = require('more-copy');

class CustomPlugin extends Plugin {
    
  process_options(options) {
    
    options.custom = {
    
      name: 'Tom',
    };

    return options;
  }
}

module.exports = CustomPlugin;
原网站

版权声明
本文为[Pengshiyu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202281514338696.html