Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ascoders committed Feb 3, 2019
1 parent d7fc59e commit 2c8e1ba
Show file tree
Hide file tree
Showing 19 changed files with 138 additions and 139 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
/.nyc_output
/npm-debug.log
/.idea
/package-lock.json
/package-lock.json
/declaration
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
/tests
/.idea
/package-lock.json
/packages
/packages
/declaration
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pri-plugin-dob",
"version": "1.1.6",
"types": "src/index.tsx",
"version": "2.0.0",
"types": "src/index.ts",
"main": "dist/index.js",
"scripts": {
"start": "pri dev",
Expand All @@ -16,16 +16,16 @@
"format": "tslint --fix './src/**/*.?(ts|tsx)' && prettier --write './src/**/*.?(ts|tsx)'"
},
"devDependencies": {
"pri": "^1.0.0"
"pri": "^2.0.3"
},
"pri": {
"web-entry": [
"./dist/web-store/index.js",
"./dist/web-menu/index.js"
],
"type": "plugin"
"type": "plugin",
"version": "2.0.4"
},
"dependencies": {
"@babel/runtime": "^7.0.0"
},
"tnpm": {
"mode": "npm"
}
}
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const getPlugin = () => import('./plugin');

export const getUIPlugins = () => [import('./web-menu'), import('./web-store')];
35 changes: 18 additions & 17 deletions src/index.tsx → src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import * as fs from 'fs-extra';
import * as _ from 'lodash';
import * as normalizePath from 'normalize-path';
import * as path from 'path';
import * as prettier from 'prettier';
import { pri, storesPath, tempJsEntryPath, tempPath, tempTypesPath } from 'pri';
import { pri, storesPath, tempJsEntryPath, tempTypesPath } from 'pri';
import { addStore } from './methods';

const LAYOUT_TEMP = 'LayoutTempComponent';
Expand All @@ -23,18 +22,18 @@ interface IResult {
};
}

export default async (instance: typeof pri) => {
export const entry = (instance: typeof pri) => {
const storeFilePath = path.join(instance.projectRootPath, tempTypesPath.dir, 'stores.ts');
const storeFilePathInfo = path.parse(storeFilePath);

instance.build.pipeConfig(config => {
if (!config.resolve.alias) {
config.resolve.alias = {};
instance.build.pipeConfig(buildConfig => {
if (!buildConfig.resolve.alias) {
buildConfig.resolve.alias = {};
}

config.resolve.alias['pri/stores'] = storeFilePath;
buildConfig.resolve.alias['pri/stores'] = storeFilePath;

return config;
return buildConfig;
});

const whiteList = ['src/stores'];
Expand Down Expand Up @@ -75,7 +74,7 @@ export default async (instance: typeof pri) => {
} as IResult;
});

instance.project.onCreateEntry((analyseInfo: IResult, entry) => {
instance.project.onCreateEntry(async (analyseInfo: IResult, entryInfo) => {
if (analyseInfo.projectAnalyseDob.storeFiles.length === 0) {
if (fs.existsSync(storeFilePath)) {
fs.removeSync(storeFilePath);
Expand All @@ -85,24 +84,24 @@ export default async (instance: typeof pri) => {
}

// Connect normal pages
entry.pipe.set('normalPagesImportEnd', importEnd => {
entryInfo.pipe.set('normalPagesImportEnd', importEnd => {
return `
${importEnd}.then(component => Connect()(component.default))
`;
});

// Connect layout
entry.pipe.set('analyseLayoutImportName', text => LAYOUT_TEMP);
entry.pipe.set('analyseLayoutBody', body => {
entryInfo.pipe.set('analyseLayoutImportName', text => LAYOUT_TEMP);
entryInfo.pipe.set('analyseLayoutBody', body => {
return `
${body}
const ${LAYOUT} = Connect()(${LAYOUT_TEMP})
`;
});

// Connect markdown layout
entry.pipe.set('analyseMarkdownLayoutImportName', text => MARKDOWN_LAYOUT_TEMP);
entry.pipe.set('analyseMarkdownLayoutBody', body => {
entryInfo.pipe.set('analyseMarkdownLayoutImportName', text => MARKDOWN_LAYOUT_TEMP);
entryInfo.pipe.set('analyseMarkdownLayoutBody', body => {
return `
${body}
const ${MARKDOWN_LAYOUT} = Connect()(${MARKDOWN_LAYOUT_TEMP})
Expand All @@ -113,7 +112,7 @@ export default async (instance: typeof pri) => {
path.relative(path.join(tempJsEntryPath.dir), path.join(storeFilePathInfo.dir, storeFilePathInfo.name))
);

entry.pipeAppHeader(header => {
entryInfo.pipeAppHeader(header => {
return `
${header}
import { useStrict } from "dob"
Expand All @@ -122,14 +121,14 @@ export default async (instance: typeof pri) => {
`;
});

entry.pipeAppBody(body => {
entryInfo.pipeAppBody(body => {
return `
${body}
useStrict()
`;
});

entry.pipeAppRouter(router => {
entryInfo.pipeAppRouter(router => {
return `
<Provider {...stores}>
${router}
Expand Down Expand Up @@ -161,6 +160,8 @@ export default async (instance: typeof pri) => {
export { stores }
`;

const prettier = await import('prettier');

// If has stores, create helper.ts
fs.outputFileSync(
storeFilePath,
Expand Down
33 changes: 17 additions & 16 deletions src/methods.ts → src/plugin/methods.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import * as fs from "fs-extra"
import * as _ from "lodash"
import * as path from "path"
import * as prettier from "prettier"
import { storesPath } from "pri"
import * as fs from 'fs-extra';
import * as _ from 'lodash';
import * as path from 'path';
import { storesPath } from 'pri';

export async function addStore(
projectRootPath: string,
options: {
name: string
withDemo: boolean
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"
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!`)
throw Error(`${kebabName} already exist!`);
}

const prettier = await import('prettier');

fs.outputFileSync(
fileFullPath,
prettier.format(
Expand All @@ -28,7 +29,7 @@ export async function addStore(
@observable
export class ${camelUpperFirstName}Store {
${options.withDemo ? `public testValue = 1` : ""}
${options.withDemo ? `public testValue = 1` : ''}
}
export class ${camelUpperFirstName}Action {
Expand All @@ -41,14 +42,14 @@ export async function addStore(
this.${camelName}Store.testValue++
}
`
: ""
: ''
}
}
`,
{
semi: false,
parser: "typescript"
parser: 'typescript'
}
)
)
);
}
8 changes: 0 additions & 8 deletions src/utils/md5.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/utils/npm.d.ts

This file was deleted.

24 changes: 12 additions & 12 deletions src/web-menu/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +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"
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} />
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 static defaultProps = new Props();
public state = new State();

public render() {
return <NewStoreComponent />
return <NewStoreComponent />;
}
}

export default {
position: "menu",
position: 'menu',
view: View
}
};
48 changes: 24 additions & 24 deletions src/web-menu/new-store/form.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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"
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 FormItem = Form.Item;

const formItemLayout = {
labelCol: {
Expand All @@ -15,7 +15,7 @@ const formItemLayout = {
xs: { span: 24 },
sm: { span: 16 }
}
}
};

const tailFormItemLayout = {
wrapperCol: {
Expand All @@ -28,40 +28,40 @@ const tailFormItemLayout = {
offset: 8
}
}
}
};

function hasErrors(fieldsError: any) {
return Object.keys(fieldsError).some((field: string) => fieldsError[field])
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 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",
{this.props.form.getFieldDecorator('name', {
initialValue: 'application',
rules: [
{
type: "string",
message: "Name must be string!"
type: 'string',
message: 'Name must be string!'
},
{
required: true,
message: "Name is required!"
message: 'Name is required!'
}
]
})(<Input />)}
</FormItem>

<FormItem {...formItemLayout} label="With demo">
{this.props.form.getFieldDecorator("withDemo", {
{this.props.form.getFieldDecorator('withDemo', {
initialValue: true,
valuePropName: "checked"
valuePropName: 'checked'
})(<Switch />)}
</FormItem>

Expand All @@ -71,14 +71,14 @@ class FormComponent extends React.PureComponent<Props, State> {
</Button>
</FormItem>
</Form>
)
);
}

private handleSubmit = async (e: any) => {
e.preventDefault()
await this.props.ApplicationAction.addStore(this.props.form.getFieldsValue())
this.props.onSuccess()
}
e.preventDefault();
await this.props.ApplicationAction.addStore(this.props.form.getFieldsValue());
this.props.onSuccess();
};
}

export default Form.create()(FormComponent as any) as any
export default Form.create()(FormComponent as any) as any;
Loading

0 comments on commit 2c8e1ba

Please sign in to comment.