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

@syyfe/syy-mp-service

v3.7.2

Published

商业云小程序脚手架主程序服务

Downloads

11

Readme

商业云小程序脚手架

安装

npm i @syyfe/syy-mp-service -D

IOptions 接口

./src/config/appConfig 实现了该接口并同时也实现 IAppConfig

syy-mp-cli 也同样实现该接口,命令调用传递相关的参数

export interface IOptions {
    /** 当前执行路径,默认当前bash 路径 */
    rootPath: string;

    /** 是否开启缓存 默认 true*/
    cache: boolean;

    /** 当前执行用户 */
    mode: string;

    /** 是否上传代码 默认 false*/
    upload: boolean;

    /** 上传代码备注说明 */
    desc: string;
}

AppConfig 系统配置属性

export interface IAppConfig {
    /** 源码所在目录 */
    srcDir: string;

    /** 编译后输出目录 */
    outputDir: string;

    /** tsconfig.json 配置 */
    tsConfig: string;
}

UserConfig 用户配置

export interface IUserConfig {
    appConfig: IAppConfig;

    /**
     * 当前用户配置对象 syy.config.ts
     * @type {*}
     * @memberof UserConfig
     */
    context: any;

    /** 上传图片OSS */
    isUseOSS?: boolean;

    /** SyyImage 图片服务对象,用来开启代理和上传OSS使用 */
    imageOperator: any;

    /** 项目根目录下的package.json */
    srcPackageJsonPath?: string;

    /** 输出目录下的package.json */
    packageJsonPath?: string;

    /** 项目根目录下的project.config.json */
    srcProjectConfigJson?: string;

    /** 输出目录下的project.config.json */
    projectConfigJson?: string;

    /**
     * 加载用户配置 (根目录下的 syy.config.js 文件),在 env 环境变量加载后执行
     * @param rootPath
     */
    initUserOptions(rootPath: string): any;
    /**
     * 初始化图片服务
     */
    initImageService(): Promise<void>;

    /**
     * OSS 图片重写方法
     * @param url 当前文件url
     */
    ossRewriter(url: string): string;
}

插件相关配置

export interface IPlugin {
    /** 插件名称 */
    name: string;
    /**
     * 插件实例方法
     * @param {Service} ctx 上下文 当前service 对象
     * @memberof IPlugin
     */
    apply(ctx: Service): void;
}

插件需添加 name属性 和 实现 apply 方法 , 方法里可以实现相应的插件初始、逻辑等操作

ctx.on 钩子

  • beforeCompile: 插件初始化之后,编译前
  • done: 编译完成后

插件 Demo

import { Service, IPlugin } from "@syyfe/syy-mp-service";
import { Log } from "@syyfe/syy-utils-node";
import { name } from "../package.json";
const fsx = require("fs-extra");
const writeJsonFile = require("write-json-file");

export default class SyyMpPluginLive implements IPlugin {
    name: string = name;
    options: any;

    constructor(options?: any) {
        this.options = options;
    }

    getArgs(): boolean {
        const args = require("minimist")(process.argv.slice(2), {
            boolean: ["live"]
        });
        return args["live"];
    }

    apply(ctx: Service): void {
        const isLive = this.getArgs();
        if (isLive) {
            ctx.on("done", async () => {
                const appJsonPath = ctx.appConfig.outputDir + "/app.json";
                const app = fsx.readJSONSync(appJsonPath);

                Log.info(`当前正在构建 "直播版" 小程序`);
                app.plugins = {
                    "live-player-plugin": {
                        version: "1.3.0",
                        provider: "wx2b03c6e691cd7370"
                    }
                };
                writeJsonFile.sync(appJsonPath, app, { detectIndent: true });
            });
        }
    }
}