npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

easeftp

v2.0.40

Published

cdn 上传工具

Downloads

16

Readme

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');