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

cloudbase-apptpl

v1.0.0-alpha.0

Published

cloudbase app template

Downloads

2

Readme

Cloudbase-apptpl

cloudbase项目模板基类,用于自定义create-cloudbase-app的项目模板。

安装

# npm
npm i cloudbase-apptpl -D
# yarn
yarn add cloudbase-apptpl -D

API

CloudBaseApp

abstract class CloudBaseApp {
  protected _appname;
  protected _lang;
  protected _options;
  constructor(appname: string, lang: LANGUAGES, options?: KV<any>);
  abstract run(): any;
  protected _installDeps(path: string, packageTool: string, dependencies: string[]): void;
}
  • CloudBaseApp是一个抽象类,子类必须实现抽象方法run()。App实例化之后会自动调用run()方法;
  • CloudBaseApp类提供安装依赖的工具方法_installDeps
  • protected类型的属性和方法可在子类中直接访问。

renderTpl()

工具函数,将ejs模板文件渲染并写入目标文件

function renderTpl(filePath: string, targetPath: string, locals?: KV<any>): void;

validPattern()

此函数用来验证pattern的合法性,一般用于调试。

function validPattern(pattern: string): boolean;

pattern是匹配依赖的协议字符串,格式如下

<pre>|<content>
  • pre指的是工具类模块,比如webpack、rollup等。这类模块与content包含的功能模块通常有综合依赖关系,比如webpack与less搭配额外依赖less-loader
  • content指的是项目依赖的第三方模块,比如vuevue-router等等。 precontent的格式一致,如下:
pre1&pre2|content1&content2

matchDeps()

工具函数,在depsMap中匹配pattern的依赖模块,以数组的形式返回。

function matchDeps(pattern: string, depsMap: DepsMap): string[];

LANGUAGES-自定义类型

可选语言

enum LANGUAGES {
  ZH = "zh",
  EN = "en"
}

DepsMap-自定义类型

必须包含common值。

type DepsMap = KV<string[]> & {
  common: string[];
};

示例

import CloudBaseApp,{LANGUAGES,renderTpl} from 'cloudbase-apptpl';

class VanillaApp extends CloudBaseApp{
  constructor(appname,lang,options){
    super(appname,lang,options);
    // ...
  }
  /**
   * 实现抽象方法run
   */
  run(){
    // ...
    // 调用父类方法
    this._installDeps('./myapp','yarn',['vuex','vue']);
  }
}