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

http-push-plugin

v1.0.3

Published

本地工程文件实时上传服务器

Downloads

6

Readme

http-push-plugin

NPM

Features

  • 在无打包工具下的node插件
  • 本地与服务器实现文件上传http通信
  • 修改本地文件/文件夹,实时上传
  • 添加/删除本地文件/文件夹,实时更新
  • 上传成功失败提醒
  • 添加ignoreDir选项(默认过滤"node_modules", ".git"文件夹),对其匹配的文件及文件夹进行过滤
  • 服务端脚本同样支持webpack/fis等部署

Installation

npm install http-push-plugin -D

Example

  • 本地部署 放在本地目标工程${project}中
vim ./plugin.js
const HttpPushPlugin = require('http-push-plugin');
// 服务端文件上传接口
const USER_RECEIVER = 'http://ip:port/receiver';
// 上传文件目录
const UPLOAD_TO = '/home/**';

new HttpPushPlugin({
    receiver: USER_RECEIVER,
    to: UPLOAD_TO,
    ignoreDir: []
});
  • 服务端部署

创建作为服务器的文件夹

mkdir receiver && cd receiver && vim server.js

填充server.js文件

#!/usr/bin/env node
 
var http = require('http');
var formidable = require('formidable');
var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
var PORT = parseInt(process.argv[2]) || 8900;


function isDir(path) {
    const stat = fs.lstatSync(path);
    return stat.isDirectory();
}

function deleteall(path) {
    var files = [];
    if(fs.existsSync(path) && isDir(path)) {
        files = fs.readdirSync(path);
        files.forEach(function(file, index) {
            var curPath = path + "/" + file;
            deleteall(curPath);
        });
        fs.rmdirSync(path);
    } else if (fs.existsSync(path) && !isDir(path)) {
        fs.unlinkSync(path);
    }
};
 
var server = http.createServer(function (req, res) {
     
    function error(err) {
        res.writeHead(500, {'Content-Type': 'text/plain'});
        res.end(err.toString());
    }
 
    function next(from, to) {
        fs.readFile(from, function (err, content) {
            if (err) {
                error(err);
            } else {
                fs.writeFile(to, content, function (err) {
                    if (err) {
                        error(err);
                    }
                    res.writeHead(200, {'Content-Type': 'text/plain'});
                    res.end('0');
                });
            }
        });
    }

    if (req.url == '/') {
        res.writeHead(200, {'content-type': 'text/html'});
        res.end('I\'m ready for that, you know.');
    } else if (req.url == '/receiver' && req.method.toLowerCase() == 'post') {
        var form = new formidable.IncomingForm();
        form.parse(req, function (err, fields, files) {
            if (err) {
                error(err);
            } else {
                var to = fields['to'];
                var type = fields['type'];
                if (type === 'remove') {
                    try {
                        deleteall(to);
                        res.end('0');
                    } catch (err) {
                        error(err);
                        return;
                    }
                } else {
                    fs.exists(to, function (exists) {
                        if (exists) {
                            fs.unlink(to, function (err) {
                                next(files.file.path, to);
                            });
                        } else {
                            fs.exists(path.dirname(to), function (exists) {
                                if (exists) {
                                    next(files.file.path, to);
                                } else {
                                    mkdirp(path.dirname(to), 0777, function (err) {
                                        if (err) {
                                            error(err);
                                            return;
                                        }                                
                                        next(files.file.path, to);
                                    });
                                }
                            });
                        }
                    });
                }
            }
        });
    }
});

server.listen(PORT, function () {
    console.log('receiver listening *:' + PORT);
});

持续启动服务

nohup node server.js &

启动

  • 本地启动
cd ${project}
node ./plugin.js