Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Upgrade to Umi 3 #107

Merged
merged 9 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions lib/generators/plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,15 @@ class Generator extends BasicGenerator {

// lang: ts || js
isUIFiles(file, lang) {
const uiFile = lang === 'ts'
? 'ui/index.tsx'
: 'ui/index.js';
const uiFile = lang === 'ts' ? 'ui/index.tsx' : 'ui/index.js';
return file === uiFile;
}

writing() {
this.writeFiles({
context: this.prompts,
filterFiles: f => {
const { isTypeScript, withUmiUI } = this.prompts;
const { isTypeScript = true, withUmiUI } = this.prompts;
if (isTypeScript) {
if (f.endsWith('.js')) return false;
// filter ui files
Expand Down
16 changes: 16 additions & 0 deletions lib/generators/plugin/templates/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
40 changes: 30 additions & 10 deletions lib/generators/plugin/templates/.fatherrc.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
<% if (withUmiUI) { -%>
const isProd = process.env.NODE_ENV === 'prod';

export default [
{
cjs: 'babel',
},
<% } -%>
export default [{
target: 'node',
cjs: { type: 'babel', lazy: true },
disableTypeCheck: true,
extraBabelPlugins: [
[
'babel-plugin-import',
{ libraryName: 'antd', libraryDirectory: 'es', style: true },
'antd',
],
],
<% if (withUmiUI) { -%>
{
entry: 'ui/index.js',
umd: {
name: '<%= name %>',
minFile: false,
},
{
entry: 'ui/index.tsx',
umd: {
name: 'tasks',
minFile: isProd,
sourcemap: !isProd,
},
extraExternals: ['antd', 'react', 'react-dom', 'xterm'],
typescriptOpts: {
check: false,
globals: {
antd: 'window.antd',
react: 'window.React',
'react-dom': 'window.ReactDOM',
},
},
<% } -%>
];
}];
43 changes: 30 additions & 13 deletions lib/generators/plugin/templates/.fatherrc.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
<% if (withUmiUI) { -%>
const isProd = process.env.NODE_ENV === 'prod';

export default [
{
cjs: 'babel',
},
<% } -%>
export default [{
target: 'node',
cjs: { type: 'babel', lazy: true },
disableTypeCheck: true,
extraBabelPlugins: [
[
'babel-plugin-import',
{ libraryName: 'antd', libraryDirectory: 'es', style: true },
'antd',
],
],
<% if (withUmiUI) { -%>
{
entry: 'ui/index.tsx',
typescriptOpts: {
check: false,
},
umd: {
name: '<%= name %>',
minFile: false,
},
{
entry: 'ui/index.tsx',
umd: {
name: 'tasks',
minFile: isProd,
sourcemap: !isProd,
},
extraExternals: ['antd', 'react', 'react-dom', 'xterm'],
typescriptOpts: {
check: false,
globals: {
antd: 'window.antd',
react: 'window.React',
'react-dom': 'window.ReactDOM',
},
},
<% } -%>
];
}];
8 changes: 8 additions & 0 deletions lib/generators/plugin/templates/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
.changelog
.umi
.umi-test
.umi-production
.DS_Store
/lib
dist
8 changes: 8 additions & 0 deletions lib/generators/plugin/templates/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
**/node_modules/**
package.json

# fixtures
**/fixtures/**

# templates
**/templates/**
14 changes: 14 additions & 0 deletions lib/generators/plugin/templates/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"printWidth": 80,
"singleQuote": true,
"trailingComma": "all",
"proseWrap": "never",
"overrides": [
{
"files": ".prettierrc",
"options": {
"parser": "json"
}
}
]
}
40 changes: 40 additions & 0 deletions lib/generators/plugin/templates/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Contributing to plugin

## Set up

Install dev deps after git clone the repo.

```bash
# npm is not allowed.
$ yarn
```

## Build

Transform with babel and rollup.

```bash
$ yarn build

# Build and monitor file changes
$ yarn build --watch

```

## Dev Plugin

```bash
# This Step must only be executed in Build
$ yarn dev
```

## Debug

TODO

## Test

```bash
$ yarn test
```

21 changes: 0 additions & 21 deletions lib/generators/plugin/templates/LICENSE

This file was deleted.

13 changes: 2 additions & 11 deletions lib/generators/plugin/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,11 @@ $ npm install
<% if (withUmiUI) { -%>
## Development UI

UI start:

```bash
$ npm run build --watch
$ npm run start
```

<img src="https://user-images.githubusercontent.com/13595509/67025108-10925980-f138-11e9-8f46-899eef3e098b.png" width="768" />

UI mini start:

```bash
$ npm run build --watch
$ npm run start:mini
$ npm run start
xiaohuoni marked this conversation as resolved.
Show resolved Hide resolved
```

<img src="https://user-images.githubusercontent.com/13595509/67024897-bbeede80-f137-11e9-9f19-6a3f0ea3f6cd.png" width="768" />
Expand All @@ -46,7 +37,7 @@ Configure in `.umirc.js`,
```js
export default {
plugins: [
['umi-plugin-<%= name %>', options],
['<%= name %>'],
],
}
```
Expand Down
11 changes: 0 additions & 11 deletions lib/generators/plugin/templates/_gitignore

This file was deleted.

5 changes: 5 additions & 0 deletions lib/generators/plugin/templates/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.umi
/.umi-production
/dist
/node_modules
/yarn.lock
16 changes: 7 additions & 9 deletions lib/generators/plugin/templates/example/.umirc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { join } from 'path';
import { defineConfig } from 'umi';

export default {
routes: [
{ path: '/', component: './index' },
],
plugins: [
join(__dirname, '..', require('../package').main || 'index.js'),
],
}
export default defineConfig({
<% if (withUmiUI) { -%>
presets: [require.resolve('@umijs/preset-ui')],
<% } -%>
plugins: [require.resolve('../lib')],
});
17 changes: 7 additions & 10 deletions lib/generators/plugin/templates/example/.umirc.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { join } from 'path';
import { IConfig } from 'umi-types';
import { defineConfig } from 'umi';

export default {
routes: [
{ path: '/', component: './index' },
],
plugins: [
join(__dirname, '..', require('../package').main || 'index.js'),
],
} as IConfig;
export default defineConfig({
<% if (withUmiUI) { -%>
presets: [require.resolve('@umijs/preset-ui')],
<% } -%>
plugins: [require.resolve('../lib')],
});
3 changes: 3 additions & 0 deletions lib/generators/plugin/templates/example/app.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function render(oldRender) {
oldRender();
}
3 changes: 3 additions & 0 deletions lib/generators/plugin/templates/example/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function render(oldRender: Function) {
oldRender();
}
4 changes: 3 additions & 1 deletion lib/generators/plugin/templates/example/package.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"dependencies": {}
}
15 changes: 14 additions & 1 deletion lib/generators/plugin/templates/example/pages/index.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
body,
html,
#root {
height: 100%;
margin: 0;
}

a {
color: #1890ff;
cursor: pointer;
}

.normal {
background: #79F2AA;
background: #ddd;
height: 100vh;
padding: 48px;
}
13 changes: 13 additions & 0 deletions lib/generators/plugin/templates/example/pages/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

xiaohuoni marked this conversation as resolved.
Show resolved Hide resolved
import React from 'react';

xiaohuoni marked this conversation as resolved.
Show resolved Hide resolved
import styles from './index.css';

export default () => {

xiaohuoni marked this conversation as resolved.
Show resolved Hide resolved
return (
<div className={styles.normal}>
Hello Umi!
</div>
);
};
9 changes: 6 additions & 3 deletions lib/generators/plugin/templates/example/pages/index.tsx
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@

import React from 'react';

import styles from './index.css';

export default function() {
export default () => {

return (
<div className={styles.normal}>
<h1>Page index</h1>
Hello Umi!
</div>
);
}
};
Loading