Skip to content

Latest commit

 

History

History
163 lines (133 loc) · 3.92 KB

README-en.md

File metadata and controls

163 lines (133 loc) · 3.92 KB

app-file-create

NPM

Build Status Dependencies Language License

A package to create files and directory for WeChat and Alipay miniProgram, and also support for other programs to use, 中文

Install

npm install app-file-create --save-dev

Options

Name Type Default Description
root String process.cwd() Output directory
env String wechat Running environment,alipaywechat or empty string
debug Boolean false Use debug mode, if true will show log info
replace Boolean false Replace old files
dirname String index Folder name
filename String -- Subfile name,the default filename is the same as dirname abolve
files Array [
fileOption
]
Subfiles Array, fileOption is an object,or file extension string
fileOption.ext String -- File extension
fileOption.filename String -- Filename, the default filename is the same as options.filename, or options.dirname
fileOption.template String | Function -- File's template, if it is Function, the first argument is args below
fileOption.args Object {} The argumant for rending template, if fileOption.template is Function, args will be effective

Methods

  • config - config default options, notice: when to use AppFileCreate([options]), the options will cover default config
const AppFileCreate = require('app-file-create');

const pageRoot = __dirname + '/pages';

AppFileCreate.config({
    root: pageRoot,
    debug: true
});

Examples

  • Create WeChat miniProgram page (微信小程序)
// both example1 and example2 have the same effect

// example1:
AppFileCreate({
    dirname: 'wx_page',
    files: ['js', 'json', 'wxml', 'wxss']
});

// example2:
AppFileCreate({
    dirname: 'wx_page',
    files: [{
        ext: 'js'
    }, {
        ext: 'json'
    }, {
        ext: 'wxml'
    }, {
        ext: 'wxss'
    }]
});
  • Create Alipay miniProgram page (支付宝小程序)
AppFileCreate({
    env: 'alipay',
    dirname: 'ali_page',
    files: [
        'js',
        'axml',
        'acss',
        {
            ext: 'json',
            args: {
                title: '个人信息'
            }
        }
    ]
});
  • Create web page
AppFileCreate({
    env: '',
    dirname: 'web_page',
    files: [
        'js',
        {
            ext: 'html',
            template: 
`<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>

    </body>
</html>`
        }
    ]
});
  • Create other files, folder name is different from subfile name
AppFileCreate({
    env: '',
    dirname: 'diff_dir_page',
    filename: 'child',
    files: ['js', 'css']
});
  • Create other files,subfile name is different
AppFileCreate({
    env: '',
    dirname: 'diff_filename_page',
    files: [{
        ext: 'js',
        filename: 'a'
    },{
        ext: 'css',
        filename: 'b'
    }]
});

License

license