2.0.40 • Published 6 years ago

easeftp v2.0.40

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

cdn 上传工具

依赖

node : 8.x

示例1 上传文件

const addFile = require('easeftp/upload').addFile;

addFile(['**/**'],{
    username:'wwl',     //用户名,     必填
    password:'123',     //密码,       必填
    path:'f2e/test',    //cdn线上路径, 必填
    cwd:'./dist',       //匹配的根目录,     默认为process.cwd()
    exclude:['*.map'],  //排除不上传的文件,  默认为空   
    debug:true,         //是否开启日志打印,  默认为false
    // otppwd:'123456'  //将军令,外网环境需要传入将军令
}).then((data) =>{
    console.log(data.urls);      //上传成功的访问url    eg: https://static.ws.126.net/163/f2e/test/app.js
},(data) => {
     console.log(data.details);  //所有详细信息
})

示例2 上传文本

    const addContent = require('easeftp/upload').addContent;
    addContent('var a=1;', 'testAddContent.js', {
        username:'...', password:'...',
        path: 'f2e/test',
        debug: true,    //默认为false
        // otppwd:'123456'  //将军令,外网环境需要传入将军令
    }).then(
        (data) => console.log(data.url),    // https://static.ws.126.net/163/f2e/test/testAddContent.js
        (data) => console.log(data.detail)
    )

注意

  • 服务器为UTF8编码。
  • 账号密码要单独建立config文件,以免错误的提交到git上。
  • 注意区分 require('easeftp/upload)version1:require('easeftp')。建议使用 easeftp/upload

addFile()

function addFile(files , {username, password, otppwd, path, cwd, exclude, debug, strict, fileName } )

files

string | array , 必填

支持glob语法,例如: "**/*.js"

内部通过glob组件匹配文件。语法详情参考:glob

username , password

string,必填

无权限的用户,需要先申请权限

otppwd

string,将军令,外网环境必填,公司内网不需要。

path

string | function(filePath) ,默认为"f2e/test"

设置上传cdn后的url路径。

上传成功后的url地址为: https://static.ws.126.net/163/${path}/${fileName} 例如 path:'f2e/test', 则上传成功后,访问路径为:https://static.ws.126.net/163/f2e/test/xxx

也可以设置为function类型,接收string类型的filePath参数,为即将上传的文件绝对路径,转化为url路径。 例如;

addFile('**/*.js', {
    username:'xxx',password:'xxx',
    cwd:'./dist',
    path(filePath){
        if(filePath.indexOf('test.js')){
            return 'f2e/test'
        }
        else{
            return 'f2e/dist'
        }
    }
}).then(({urls, details}) => {
    console.log(urls);
   /*[ 'https://static.ws.126.net/163/f2e/dist/app.js',
       'https://static.ws.126.net/163/f2e/test/test.js' ]*/
})

cwd

string,可选,默认为 process.cwd().

指定查找的目录。

当pattern为相对路径时,在会在cwd下查找匹配的文件。例如:

//只上传dist目录下的js文件。
addFile('*.js',{
    username:username, password:password, path:'f2e/test', 
    cwd:'./dist'
});

cwd可以是绝对路径,也可以是相对路径。如果cwd为相对路径,是相对于process.cwd()的。

exclude

Array,可选,默认为空数组。

设置不匹配的文件。 例如如下示例:会查找./dist下的不是.html后缀和.map后缀的文件。

addFile(['**/*.*'],{ 
    username:'...',password:'...',path:'f2e/test',
    cwd:'./dist',
    exclude:['*.html','*.map']
})

debug

bool,可选,默认为 false

是否在控制台开启调试打印信息

strict

bool,可选,默认为true.

是否严格限定上传的目录结构。 为true时,上传到cdn的目录结构和本地目录结构一致,例如:

/*
假设dist目录结构为:
./dist
├── app.js
└── lib
    └── ajax.js
    
*/
addFile('**/*.js', {
    username:'xxx',password:'xxx',
    path: 'f2e/test/',
    cwd:'./dist',
    strict:true
}).then(({urls, details}) => {
    console.log(urls);
   /*[ 'https://static.ws.126.net/163/f2e/test/app.js',
       'https://static.ws.126.net/163/f2e/test/lib/ajax.js' ]*/
})

addFile('**/*.js', {
    username:'xxx',password:'xxx',
    path: 'f2e/test/',
    cwd:'./dist',
    strict:false,
}).then(({urls, details}) => {
    console.log(urls);
   /*   [ 'https://static.ws.126.net/163/f2e/test/app.js',
          'https://static.ws.126.net/163/f2e/test/ajax.js' ]*/
})

fileName

function(filePath),可选,

默认上传文件名和本地文件名一致。

可以通过该回调更改文件名。

 var addFile=require('easeftp/upload').addFile;
 var path=require('path');
 addFile(['**/**'], {
        username: 'wwl',password: '123',
        path: 'f2e/test',
        cwd: './dist',
        fileName(filePath) {
            return path.basename(filePath).replace('.min', '');
        }
    })

addContent()

function addFile(content, filename, {username, password, otppwd, debug , path })

content

String|Buffer, 文本内容。

filename

String, 文件名称,需要带有后缀名。 例如: "test.js"

username, password, path , debug

和 addFile() 参数作用相同

其中,path值支持string类型(addFile()中的path参数支持function类型。)


Version 1

示例

var easeftp = require('easeftp');
easeftp.verify({
	"username": "...",
	"password": "...",
	//otppwd:'...'
}).then(function() {
	return easeftp.upload({
		online: "test/test1/......",
		file: "绝对路径", 	// 需要上传的文件路径
		files: "绝对路径", 	// 需要上传的文件夹路径
						  	// 文件和文件夹只能选择其一,否则按照文件上传处理
		exclude:["*.js","**.js","..."]   // 排除其中不上传的文件
	})
}).then(([successArr,failArr]) => {
	// successArr 	上传成功
	// failArr 		上传失败
	// complete
})

说明

v1内部还是require的easeftp/upload,只不过兼容之前的参数形式。

如果要使用原v1的代码,使用如下形式:

var easeftp = require('easeftp/index_v1');
2.0.40

6 years ago

2.0.39

6 years ago

2.0.38

6 years ago

2.0.37

6 years ago

2.0.36

6 years ago

2.0.35

6 years ago

2.0.34

6 years ago

2.0.32

6 years ago

2.0.31

6 years ago

2.0.30

6 years ago

2.0.29

6 years ago

2.0.28

6 years ago

2.0.27

6 years ago

2.0.26

6 years ago

2.0.25

6 years ago

2.0.24

6 years ago

2.0.23

6 years ago

2.0.22

6 years ago

2.0.21

6 years ago

2.0.20

6 years ago

2.0.19

6 years ago

2.0.18

6 years ago

2.0.17

6 years ago

2.0.16

6 years ago

2.0.15

6 years ago

2.0.13

6 years ago

2.0.12

6 years ago

2.0.10

6 years ago

2.0.9

6 years ago

2.0.8

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.35

6 years ago

1.0.34

6 years ago

1.0.33

6 years ago

1.0.32

6 years ago

1.0.31

6 years ago

1.0.30

6 years ago

1.0.28

6 years ago

1.0.27

6 years ago

1.0.26

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago