Skip to content

Commit

Permalink
feat: 🎸 add gen scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
gorgechan committed May 24, 2022
1 parent d12d0c6 commit 3e383b5
Show file tree
Hide file tree
Showing 30 changed files with 1,277 additions and 188 deletions.
26 changes: 26 additions & 0 deletions .plop/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import path from "path";
import minimist from "minimist";
import { fileURLToPath } from "url";
import { Plop, run } from "plop";

// == Types ================================================================

// == Constants ============================================================

const args = process.argv.slice(2);
const argv = minimist(args);
const __dirname = path.dirname(fileURLToPath(import.meta.url));

// == Exports ==============================================================

Plop.prepare(
{
cwd: argv.cwd,
configPath: path.resolve(__dirname, "plopfile.ts"),
preload: argv.preload || [],
completion: argv.completion,
},
(env) => {
return run(env, undefined, true);
}
);
70 changes: 70 additions & 0 deletions .plop/plopfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* eslint-disable import/no-extraneous-dependencies */
import path from 'path';
import { fileURLToPath } from "url";
import { NodePlopAPI } from 'plop';
const __dirname = path.dirname(fileURLToPath(import.meta.url));

export default function (plop: NodePlopAPI) {
plop.setGenerator('component', {
description: '创建一个新组件',
prompts: [
{ type: 'input', name: 'name', message: '请输入组件名称(多个单词以中横线命名)' },
{ type: 'input', name: 'CN', message: '请输入组件中文名称' },
{ type: 'input', name: 'description', message: '请输入组件描述' },
],
actions: [
{
type: 'add',
path: path.resolve(__dirname, '../src/{{kebabCase name}}/index.ts'),
templateFile: path.resolve(__dirname, './template/index.hbs'),
},
{
type: 'add',
path: path.resolve(__dirname, '../src/{{kebabCase name}}/{{pascalCase name}}.tsx'),
templateFile: path.resolve(__dirname, './template/comp.hbs'),
},
{
type: 'add',
path: path.resolve(__dirname, '../src/{{kebabCase name}}/style/index.less'),
templateFile: path.resolve(__dirname, './template/style/style.hbs'),
},
{
type: 'add',
path: path.resolve(__dirname, '../src/{{kebabCase name}}/style/index.ts'),
templateFile: path.resolve(__dirname, './template/style/index.hbs'),
},
{
type: 'add',
path: path.resolve(__dirname, '../docs/components/{{kebabCase name}}.md'),
templateFile: path.resolve(__dirname, './template/doc.hbs'),
},
{
type: 'add',
path: path.resolve(__dirname, '../src/{{kebabCase name}}/{{camelCase name}}Types.ts'),
templateFile: path.resolve(__dirname, './template/types.hbs'),
},
{
type: 'add',
path: path.resolve(__dirname, '../src/{{kebabCase name}}/demos/basic.tsx'),
templateFile: path.resolve(__dirname, './template/demos/basic.hbs'),
},
{
type: 'add',
path: path.resolve(__dirname, '../src/{{kebabCase name}}/__tests__/{{pascalCase name}}.spec.tsx'),
templateFile: path.resolve(__dirname, './template/__tests__/index.spec.hbs'),
},
{
type: 'append',
path: path.resolve(__dirname, '../src/index.ts'),
pattern: '/* PLOP_INJECT_EXPORT */',
template: "export { default as {{pascalCase name}} } from './{{kebabCase name}}'",
},
{
type: 'append',
path: path.resolve(__dirname, '../.umirc.ts'),
pattern: '/* PLOP_INJECT_MD */',
template: "'/components/{{kebabCase name}}.md',",
},
],
});
}
10 changes: 10 additions & 0 deletions .plop/template/__tests__/index.spec.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { render } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import {{pascalCase name}} from '../index';

describe('{{pascalCase name}}', () => {
it('renders without error', () => {

});
});
14 changes: 14 additions & 0 deletions .plop/template/comp.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { {{pascalCase name}}Props } from './{{camelCase name}}Types';

const defaultProps = {

};

const {{pascalCase name}}: React.FC<{{pascalCase name}}Props> = userProps => {
const props = { ...defaultProps, ...userProps };

return <>{{pascalCase name}}</>;
};

export default {{pascalCase name}};
6 changes: 6 additions & 0 deletions .plop/template/demos/basic.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
import {{pascalCase name}} from '../{{pascalCase name}}';

export default () => (
<{{pascalCase name}} />
);
12 changes: 12 additions & 0 deletions .plop/template/doc.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# {{pascalCase name}} {{CN}}

{{description}}

## 代码演示

### 基本用法

<code src="../../src/{{kebabCase name}}/demos/basic.tsx"></code>


<API src="../../src/{{kebabCase name}}/{{pascalCase name}}.tsx"/>
3 changes: 3 additions & 0 deletions .plop/template/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './{{camelCase name}}Types';

export { default } from './{{pascalCase name}}';
1 change: 1 addition & 0 deletions .plop/template/style/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './index.less';
Empty file added .plop/template/style/style.hbs
Empty file.
3 changes: 3 additions & 0 deletions .plop/template/types.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface {{pascalCase name}}Props {

}
37 changes: 32 additions & 5 deletions .umirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { defineConfig } from 'dumi'

let base, publicPath;

console.log(process.env)

if (process.env.NODE_ENV === 'production') {
base = '/k-view-react',
publicPath= '/k-view-react/'
Expand All @@ -16,9 +14,38 @@ const conf = {
exportStatic: {},
dynamicImport: {},
base,
publicPath
publicPath,
navs: [
{
title: '介绍',
path: '/guide'
},
{
title: '组件',
path: '/components',
},
{
title: '贡献',
path: '/contributing',
},
{
title: 'Github',
path: 'https://github.com/SoldierAb/k-view-react'
}
],
menus: {
'/components': [
{
title: '组件',
path: '/components',
children: [
'/components/button.md',
/* PLOP_INJECT_MD */
'/components/popup-box.md',
]
}
]
}
}

console.log('umi conf: ',conf)

export default defineConfig(conf)
2 changes: 1 addition & 1 deletion docs/index.md → docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ hero:
desc: 文档站点基于 dumi 生成
actions:
- text: 快速上手
link: /getting-started
link: /guide
features:
- icon: https://gw.alipayobjects.com/zos/bmw-prod/881dc458-f20b-407b-947a-95104b5ec82b/k79dm8ih_w144_h144.png
title: 特性 1
Expand Down
1 change: 1 addition & 0 deletions docs/components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 组件们
12 changes: 12 additions & 0 deletions docs/components/button.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Button

基础按钮

## 代码演示

### 基本用法

<code src="../../src/button/demos/basic.tsx"></code>


<API src="../../src/button/Button.tsx"/>
12 changes: 12 additions & 0 deletions docs/components/popup-box.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# PopupBox 弹窗

测试gen脚本

## 代码演示

### 基本用法

<code src="../../src/popup-box/demos/basic.tsx"></code>


<API src="../../src/popup-box/PopupBox.tsx"/>
10 changes: 10 additions & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 贡献指南


## Install
```bash

```

## Pull Request

3 changes: 3 additions & 0 deletions docs/guide/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 介绍

基于 typescript 的 React 组件库
12 changes: 12 additions & 0 deletions docs/guide/quick-start.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# quick start

## Install

```bash

npm i -S k-view-react

```


## Usage
17 changes: 16 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
"description": "",
"typings": "lib/index.d.ts",
"main": "lib/index.js",
"module": "es/index.js",
"authors": {
"name": "cgj",
"email": "[email protected]"
},
"files": [
"lib",
"es"
],
"scripts": {
"dev": "dumi dev",
"build:preview": "npm run build:site && serve site",
Expand All @@ -15,7 +24,8 @@
"commit": "git add . && git-cz",
"test": "jest --coverage",
"test:watch": "jest --watch",
"test:update": "jest --updateSnapshot"
"test:update": "jest --updateSnapshot",
"gen": "node --experimental-loader esbuild-node-loader .plop/index.ts"
},
"author": "cgj",
"license": "MIT",
Expand All @@ -39,6 +49,9 @@
"cross-env": "^7.0.3",
"cz-conventional-changelog": "^3.3.0",
"dumi": "^1.1.42",
"esbuild": "^0.14.39",
"esbuild-node-loader": "^0.8.0",
"esmo": "^0.16.3",
"gh-pages": "^4.0.0",
"git-cz": "^4.9.0",
"gulp": "^4.0.2",
Expand All @@ -51,12 +64,14 @@
"jest": "^28.1.0",
"jest-environment-jsdom": "^28.1.0",
"lint-staged": "^12.4.1",
"plop": "^3.1.0",
"prettier": "^2.6.2",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"serve": "^13.0.2",
"through2": "^4.0.2",
"ts-jest": "^28.0.2",
"ts-node": "^10.8.0",
"typescript": "^4.6.4"
},
"sideEffects": [
Expand Down
24 changes: 0 additions & 24 deletions src/button/index.md

This file was deleted.

4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { default as Button } from './button/Button'
export { default as Button } from './button/Button'
/* PLOP_INJECT_EXPORT */
export { default as PopupBox } from './popup-box'
14 changes: 14 additions & 0 deletions src/popup-box/PopupBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { PopupBoxProps } from './popupBoxTypes';

const defaultProps = {

};

const PopupBox: React.FC<PopupBoxProps> = userProps => {
const props = { ...defaultProps, ...userProps };

return <>PopupBox</>;
};

export default PopupBox;
10 changes: 10 additions & 0 deletions src/popup-box/__tests__/PopupBox.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { render } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import PopupBox from '../index';

describe('PopupBox', () => {
it('renders without error', () => {

});
});
6 changes: 6 additions & 0 deletions src/popup-box/demos/basic.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
import PopupBox from '../PopupBox';

export default () => (
<PopupBox />
);
3 changes: 3 additions & 0 deletions src/popup-box/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './popupBoxTypes';

export { default } from './PopupBox';
3 changes: 3 additions & 0 deletions src/popup-box/popupBoxTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface PopupBoxProps {

}
Empty file added src/popup-box/style/index.less
Empty file.
Loading

0 comments on commit 3e383b5

Please sign in to comment.