-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support webui, service, filesCheck, project analyse, create entry
- Loading branch information
Showing
15 changed files
with
1,213 additions
and
1,025 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as fs from "fs-extra" | ||
import * as _ from "lodash" | ||
import * as path from "path" | ||
import * as prettier from "prettier" | ||
import { storesPath } from "pri" | ||
|
||
export async function addStore( | ||
projectRootPath: string, | ||
options: { | ||
name: string | ||
withDemo: boolean | ||
} | ||
) { | ||
const camelName = _.camelCase(options.name) | ||
const camelUpperFirstName = _.upperFirst(camelName) | ||
const kebabName = _.kebabCase(options.name) | ||
const fileFullPath = path.join(projectRootPath, storesPath.dir, kebabName) + ".tsx" | ||
|
||
if (fs.existsSync(fileFullPath)) { | ||
throw Error(`${kebabName} already exist!`) | ||
} | ||
|
||
fs.outputFileSync( | ||
fileFullPath, | ||
prettier.format( | ||
` | ||
import { observable, inject, Action } from "dob" | ||
@observable | ||
export class ${camelUpperFirstName}Store { | ||
${options.withDemo ? `public testValue = 1` : ""} | ||
} | ||
export class ${camelUpperFirstName}Action { | ||
@inject(${camelUpperFirstName}Store) public ${camelName}Store: ${camelUpperFirstName}Store | ||
${ | ||
options.withDemo | ||
? ` | ||
@Action public test() { | ||
this.${camelName}Store.testValue++ | ||
} | ||
` | ||
: "" | ||
} | ||
} | ||
`, | ||
{ | ||
semi: false, | ||
parser: "typescript" | ||
} | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Icon } from "antd" | ||
import { Connect } from "dob-react" | ||
import * as React from "react" | ||
import { NewStoreComponent } from "./new-store/new-store.component" | ||
import * as S from "./style" | ||
import { Props, State } from "./type" | ||
|
||
const TreeIcon = (props: any) => <Icon style={{ marginRight: 5 }} {...props} /> | ||
|
||
@Connect | ||
class View extends React.Component<Props, State> { | ||
public static defaultProps = new Props() | ||
public state = new State() | ||
|
||
public render() { | ||
return <NewStoreComponent /> | ||
} | ||
} | ||
|
||
export default { | ||
position: "menu", | ||
view: View | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { Button, Form, Input, Switch } from "antd" | ||
import { Connect } from "dob-react" | ||
import * as React from "react" | ||
import { Props, State } from "./new-store.type" | ||
import * as S from "./style" | ||
|
||
const FormItem = Form.Item | ||
|
||
const formItemLayout = { | ||
labelCol: { | ||
xs: { span: 24 }, | ||
sm: { span: 8 } | ||
}, | ||
wrapperCol: { | ||
xs: { span: 24 }, | ||
sm: { span: 16 } | ||
} | ||
} | ||
|
||
const tailFormItemLayout = { | ||
wrapperCol: { | ||
xs: { | ||
span: 24, | ||
offset: 0 | ||
}, | ||
sm: { | ||
span: 16, | ||
offset: 8 | ||
} | ||
} | ||
} | ||
|
||
function hasErrors(fieldsError: any) { | ||
return Object.keys(fieldsError).some((field: string) => fieldsError[field]) | ||
} | ||
|
||
@Connect | ||
class FormComponent extends React.PureComponent<Props, State> { | ||
public static defaultProps = new Props() | ||
public state = new State() | ||
|
||
public render() { | ||
return ( | ||
<Form onSubmit={this.handleSubmit}> | ||
<FormItem {...formItemLayout} label="Name"> | ||
{this.props.form.getFieldDecorator("name", { | ||
initialValue: "application", | ||
rules: [ | ||
{ | ||
type: "string", | ||
message: "Name must be string!" | ||
}, | ||
{ | ||
required: true, | ||
message: "Name is required!" | ||
} | ||
] | ||
})(<Input />)} | ||
</FormItem> | ||
|
||
<FormItem {...formItemLayout} label="With demo"> | ||
{this.props.form.getFieldDecorator("withDemo", { | ||
initialValue: true, | ||
valuePropName: "checked" | ||
})(<Switch />)} | ||
</FormItem> | ||
|
||
<FormItem {...tailFormItemLayout}> | ||
<Button type="primary" htmlType="submit" disabled={hasErrors(this.props.form.getFieldsError())}> | ||
Ok | ||
</Button> | ||
</FormItem> | ||
</Form> | ||
) | ||
} | ||
|
||
private handleSubmit = async (e: any) => { | ||
e.preventDefault() | ||
await this.props.ApplicationAction.addStore(this.props.form.getFieldsValue()) | ||
this.props.onSuccess() | ||
} | ||
} | ||
|
||
export default Form.create()(FormComponent as any) as any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Modal } from "antd" | ||
import { Connect } from "dob-react" | ||
import * as React from "react" | ||
import { Props, State } from "./new-store.type" | ||
import * as S from "./style" | ||
|
||
import FormComponent from "./form" | ||
|
||
@Connect | ||
export class NewStoreComponent extends React.PureComponent<Props, State> { | ||
public static defaultProps = new Props() | ||
public state = new State() | ||
|
||
public render() { | ||
return ( | ||
<S.Container> | ||
<S.Button onClick={this.showModal}> | ||
<S.MenuIcon type="plus" /> | ||
New Store | ||
</S.Button> | ||
|
||
<Modal | ||
title="New Store" | ||
visible={this.state.visible} | ||
footer={null} | ||
onOk={this.handleOk} | ||
onCancel={this.handleCancel} | ||
> | ||
<FormComponent onSuccess={this.handleCancel} /> | ||
</Modal> | ||
</S.Container> | ||
) | ||
} | ||
|
||
private showModal = () => { | ||
this.setState({ | ||
visible: true | ||
}) | ||
} | ||
private handleOk = () => { | ||
this.setState({ | ||
visible: false | ||
}) | ||
} | ||
private handleCancel = () => { | ||
this.setState({ | ||
visible: false | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export class Props { | ||
public form?: any | ||
public onSuccess?: () => void = () => { | ||
// | ||
} | ||
[x: string]: any | ||
} | ||
|
||
export class State { | ||
public visible = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Icon } from "antd" | ||
import * as React from "react" | ||
import styled from "styled-components" | ||
|
||
export const MenuIcon = (props: any) => <Icon style={{ fontSize: 15, marginRight: 10 }} {...props} /> | ||
|
||
export const Container = styled.div` | ||
display: flex; | ||
` | ||
|
||
export const Button = styled.div` | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
font-size: 14px; | ||
color: #666; | ||
border-right: 1px solid #eee; | ||
padding: 0 10px; | ||
cursor: pointer; | ||
transition: background-color 0.2s; | ||
&:hover { | ||
background-color: whitesmoke; | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import styled from "styled-components" | ||
|
||
export const Container = styled.div`` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export class Props { | ||
[x: string]: any | ||
} | ||
|
||
export class State {} |
Oops, something went wrong.