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

server-file-sync

v1.7.2

Published

把本地文件同步到服务器指定目录,方便前端更新代码到服务器

Downloads

62

Readme

server-file-sync

把本地文件夹下的文件同步到服务器指定目录下,方便前端更新代码

使用方法

  • npm i server-file-sync -g 全局安装

  • 在项目目录下执行 sfs -i 生成配置文件,然后按照里面的选项配置

  • 然后就能执行 sfs 同步文件了

命令介绍

sfs -h 查看所有命令和使用方式

连接方式

  • 建议通过 ssh 密钥的连接方式,因为这个是最安全的,如果直接用密码连接万一泄露了就麻烦了。

  • 如果只指定了密钥没配置密钥密码的话会再次提示输入密码的,所以最好不要把密码也写到配置文件中

  • 首先在某个目录下执行 ssh-keygen -f 生成一对密钥(期间会提示你输密码),不带 pub 的是私钥带 pub 的是公共密钥,你要把公钥的内容添加到服务器的/root/.ssh/authorized_keys 文件中,然后把私钥和对应的密码添加进本工具的配置文件中(具体字段见配置文件),这时就能连接到服务器并同步文件了。

注意事项

  • 最好在项目中把密钥从版本控制系统中忽略,防止被人连接到这台服务器造成无法控制的影响

配置文件格式

/**
 * 配置文件类型
 */
import { Matcher } from "anymatch";
import { Client, ConnectConfig } from "ssh2";

/** 基础连接配置 */
export type TConnectConfig = Pick<
  ConnectConfig,
  "host" | "port" | "username" | "passphrase" | "privateKey"
>;

/**
 * 配置文件类型
 * TODO 关于ssh2配置信息的合并顺序是先connectConfig中的字段,再是配置文件中的字段,,再是syncList中的字段
 */
export type TConfig = TConnectConfig & {
  /** 同步列表 */
  syncList?: ({
    /** key */
    key: string;
    /** 标题 */
    title: string;
    /** 路径列表 */
    paths: {
      /** 本地地址 */
      local: string;
      /** 远程地址 */
      remote: string;
      /** 文件忽略,请注意不支持 Windows 样式的反斜杠作为分隔符*/
      ignored?: Matcher;
    }[];
    /** 开始同步之前的回调 */
    beforeF?: (connF: () => Promise<Client>) => Promise<void>;
    /** 同步之后的回调 */
    laterF?: (connF: () => Promise<Client>) => Promise<void>;
  } & TConnectConfig)[];
  /** ssh2的连接配置 */
  connectConfig?: ConnectConfig;
  /** 是否监听 */
  watch?: boolean;
  /** 开始同步之前的回调 */
  beforeF?: (connF: (op?: TConnectConfig) => Promise<Client>) => Promise<void>;
  /** 同步之后的回调 */
  laterF?: (connF: (op?: TConnectConfig) => Promise<Client>) => Promise<void>;
};

建议使用方法 getConfig 获取 config,这样就有全类型提示了,该方法的声明如下

function getConfig(f: () => TConfig | Promise<TConfig>);

使用方法如下

const { getConfig } = require("server-file-sync");

/**
 * server-file-sync 的默认配置文件
 */
module.exports = getConfig(() => {
    // 可以是异步的
    return {
        ...
    };
});