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

pok

v1.1.5

Published

Simple and Elegant project creator

Downloads

7

Readme

❯ 安装

npm install pok -g

❯ 使用

在终端中使用

# initial a project by pok-template
pok ssh://xxx.git

在NodeJS中使用

const pok = require('pok')

pok.create({
    remote: 'ssh://xxx.git',
    branch: 'master'
})

❯ 创建一个Pok模板项目

初始化模板

pok [email protected]:blankPen/pok-example.git

配置pok.config.js

module.exports = function creator(ctx) {
    return {
        name: 'pok-template',
        // 在模板初始化前执行,根据setup配置的参数进行项目生成
        async setup() {
            // 通过prompts与用户进行交互获取用户配置项
            const res = await ctx.prompts([
                {
                    name: 'projectName',
                    type: 'text',
                    message: '项目名:',
                    initial: defaultProjectName,
                    onState: (state) => (String(state.value).trim() || defaultProjectName)
                },
            ], {
                onCancel() {
                    process.exit(1);
                }
            });
            let sourceDir = 'normal';
            if (res.needRematch) sourceDir = 'rematch';

            // 返回setup所需配置参数
            return {
                autoInstall: true,
                sourceDir: sourceDir,
                outputDir: res.projectName,
                env: res
            };
        },
        // 项目创建结束后回调,一般用于打印结束日志
        end() {
            console.log(ctx.chalk.green(`\n  项目创建完成,快速启动: `))
            console.log(`    cd ${ctx.setupConfig.outputDir}`)
            console.log(`    npm run dev`)
        }
    }
}

setup配置项

  • sourceDir, 模板代码所在的文件夹,默认值:./
  • outputDir, 要生成模板代码的输出目录,当未进行配置时 pok 会主动询问用户要输出的目录地址
  • autoInstall, 是否自动执行 npm install 安装项目依赖,默认值:false
  • env, 模板环境参数,配置的参数将用于hbs模板生成,具体参考:https://handlebarsjs.com/

Context

为了方便模板创建提供的上下文,内置一些常用库

  • setupConfig, setup() 返回的结果,方便在end()中使用
  • prompts Lightweight, beautiful and user-friendly interactive prompts
  • shelljs 🐚 Portable Unix shell commands for Node.js
  • chalk 🖍 Terminal string styling done right

❯ Licence

MIT