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

@wox/cli

v2.0.7

Published

The cli of wox

Downloads

10

Readme

脚手架工具

它依赖于@evio/cli

npm i -g @evio/cli

Usage

cli install @wox/cli

Update Cli

cli update @wox/cli

@wox/cli

它是wox架构的支持工具。

wox:new

格式:cli wox:new [project] [-p]

创建一个新的项目或插件。

  • project 项目名称。不写的话,系统将提示你写入。
  • -p 表示生成一个插件项目。

创建主项目

cli wox:new

创建插件

cli wox:new -p

wox

创建开发辅助文件。我们来看下列表(通过cli wox -h查看):

Usage: wox [options] <path>

create a new wox file by type

Options:
  -p, --component [type]  create a new `Vue.component` file
  -d, --directive         create a new `Vue.directive` file
  -f, --filter            create a new `Vue.filter` file
  -x, --mixin             create a new `Vue.mixin` file
  -c, --controller        create a new `Controller` file
  -m, --middleware        create a new `Middleware` file
  -s, --service           create a new `Service` file
  -t, --decorate          create a new `Decorate` file
  -w, --webview           create a new `Webview` file
  -h, --help              output usage information

通过-符号来区分创建的类型文件。

注意:component比较特殊,它有4种格式-p -p=vue -p=js -p=jsx,每个不同类型将创建不同的文件结尾。

对wox进行插件的工具扩展

我们需要在插件的根目录下存放一个commander.js来编写。

module.exports = (program, client) => {
  program
    .command('wox:store <file>')
    .description('add a new store file for vuex')
    .action(client.require('./addfile.js'));
}
module.exports.__IS_CLI_PLUGIN__ = true;

比如上面的代码,我们创建来一个新的wox:store命令。当这个命令被调用的时候,我们会进入addfile.js

// ./addfile.js
const fs = require('fs');
const path = require('path');
const ejs = require('ejs');
const fse = require('fs-extra');
module.exports = async (ctx, file) => {
  const template = path.resolve(__dirname, '.template.ejs');
  const output = path.resolve(process.cwd(), 'app/vue/storage', file + '.js');
  const result = await render(ctx, template, output, {
    name: prefix(...file.split('/'))
  });
  if (result) {
    console.log('create file success:', output);
  } else {
    console.error('create file failed.');
  }
}

async function render(ctx, template, output, data = {}) {
  if (!fs.existsSync(template)) throw new Error('can not find template:' + template);
  const code = await new Promise((resolve, reject) => {
    ejs.renderFile(template, data, function(err, str){
      if (err) return reject(err);
      resolve(str);
    });
  });
  if (!fs.existsSync(output)) {
    fse.outputFileSync(output, code, 'utf8');
    ctx.catch(() => fs.unlinkSync(output));
    return true;
  }
}

function prefix(...names) {
  const name = names.join('_').replace(/\//g, '_').replace(/[_-][a-z0-9]/ig, s => s.substring(1).toUpperCase());
  let first = name.charAt(0);
  const next = name.substring(1);
  return first.toUpperCase() + next;
}

这样,执行命令的时候,我们会创建一个app/vue/storage下的文件,提高开发速度。

注意:我们约定,所有插件的开发,都必须在主项目下,最好新建plugins文件夹,然后安装在下面。