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

@beisen/p-cnpm-test

v0.0.6-1

Published

cnpm_test

Downloads

6

Readme

Beisen-module-template

功能

React组件开发,并发布到北森cnpm服务器

使用方法

1)空项目使用

git clone [email protected]:cnpm/beisen-module-template.git

cd beisen-module-template

./renew.js 项目路径/项目名称
#默认在当前目录下
#./renew.js ../testDemo/   **testDemo**为新项目名称,与该空项目平级,新项目不带git信息,一个纯的项目
#cd ../testDemo/
—— Folder
	|
	|—— beisen-module-template
	|
	|—— testDemo
	  |—— dist
	  |—— examples
	  |—— lib 
	  |—— src
	  |—— tests
	  |—— .gitgnore
	  |—— index.js
	  |—— karma.conf.js
	  |—— package.json
	  |—— webpack.config.js
	  |—— webpack.dev.config.js
	  |—— README.md

2)修改package.json

package.json中不允许出现中文

"name": "@beisen/componentName", 
"author": {
    "name": "name",
    "email": "[email protected]"
}, 
"description": "", 
"keywords": [ 
	"beisen",
    "react-component",
    "es6",
    "karma",
    "jasmine"
],
"maintainers": [
	{
		"name": "name",
		"email": "[email protected]" 
	}
] 
// 组件名称(必填)
// 组件作者(必填)
// 组件概述(必填)
// 组件关键词(必填)eg.Form,Icon,DropDown...
// 维护人员 (必填)  

3) 项目文件结构

ReactComponent

—— dist
  |
  |—— index.js (webpack打包后的js)
  |
—— examples
  |
  |—— preview
    |—— 预览图.png (组件截图)
  |
  |—— index.html (可直接打开的示例)
  |
—— lib (babel转换后的语法 es6 —> es5) 
  |
—— src
  |
  |—— index.js (组件源码,webpack打包入口)
  |
—— tests (测试文件夹)
  |
  | —— index-spec.js (测试用例)
  |
—— index.html  (组件调用)
  | 
—— index.js (组件调用)
  |
—— karma.conf.js (karma配置)
  |
—— webpack.config.js (webpack配置)
  |
—— package.json (如有依赖,必须写全)
  |
—— README.md (组件使用说明,配置参数)

4) 项目运行、打包

  • cnpm installnpm install cnpm使用教程
  • npm run dev (开发环境打包 port:8080)
  • npm run test (测试用例)
  • npm run build (生产环境打包)

5) 组件开发流程

  • 新建项目
  • 项目导出
  • 向组织提出申请,将项目加入cnpm组
  • 申请通过后,项目作者需打tag

打tag后,服务器会自动将项目同步或更新到cnpm库中,并添加官方授权,Beisen前端组件库会自动添加或更新组件信息(包含文档,示例和预览图)

默认tag为1.0.0

tag:

  • 大版本:1.x.x
  • 小版本:x.1.x
  • Hotfix: x.x.1
  • 测试版本:x.x.x-1

6) 组件开发要求

  • 必须要有文档,包括组件使用说明,配置参数,版本信息
  • 必须要有使用示例
  • 必须要有预览图
  • 必须编写单元测试

7) 组件开发规范

  • 一个项目只能对应一个组件
  • react组件,不需要redux相关内容
  • 如有依赖其他组件,必须在package.json中写全
  • 最外层index.js不能命名为其他
  • 统一使用ES6语法
  • css统一使用sass
  • 代码应有适当注释,包括函数、参数
  • 测试文件统一以“-spec”为结尾命名,如app-spec.js

React书写规范

每个文件只包含一个React组件

使用JSX语法

Class vs React.createClass

// bad
const Listing = React.createClass({
  render() {
    return <div />;
  }
});

// good
class Listing extends React.Component {
  render() {
    return <div />;
  }
}

对于 JSX 使用双引号,对其它所有 JS 属性使用单引号

// bad
  <Foo style={{ left: "20px" }} />

  // good
  <Foo style={{ left: '20px' }} />

在自闭和标签之前留一个空格,若组件无子组件也应使用自闭标签

// bad
<Foo/>

// very bad
<Foo                 />

// bad
<Foo
 />

// good
<Foo />

如果组件有多行属性,闭合标签应写在新的一行上

// bad
<Foo
bar="bar"
baz="baz" />

// good
<Foo
bar="bar"
baz="baz"
/>

生命周期 Composite Component

* - constructor
*   - componentWillMount
*   - render
*   - [children's construtors]
*     - [children's componentWillMount and render]
*     - [children's componentDidMount]
*     - componentDidMount
*
*       Update Phase:
*       - componentWillReceiveProps (only called if parent updated)
*       - shouldComponentUpdate
*		  - componentWillUpdate
*           - render
* 			- [children's constructors or receive props phase]
*         - componentDidUpdate
*
* 	    - componentWillUnmount
*  		- [children's componentWillUnmount]
*	- [children's destroyed]
* - (destroyed)

执行顺序

constructor
optional static methods
getChildContext
componentWillMount
componentDidMount
componentWillReceiveProps
shouldComponentUpdate
componentWillUpdate
componentDidUpdate
componentWillUnmount
clickHandlers or eventHandlers like onClickSubmit() or onChangeDescription()
getter methods for render like getSelectReason() or getFooterContent()
Optional render methods like renderNavigation() or renderProfilePicture()
render

如何定义propTypes, defaultProps, contextTypes等等

import React, { PropTypes } from 'react';

const propTypes = {
  id: PropTypes.number.isRequired,
  url: PropTypes.string.isRequired,
  text: PropTypes.string
};

const defaultProps = {
  text: 'Hello World'
};

class Link extends React.Component {
  static methodsAreOk() {
    return true;
  }

  render() {
    return <a href={this.props.url} data-id={this.props.id}>{this.props.text}</a>
  }
}

Link.propTypes = propTypes;
Link.defaultProps = defaultProps;

export default Link;

参考资料