Commit de688c46 authored by super-lin0's avatar super-lin0

add nemean simple

parent c97362c6
Pipeline #159 canceled with stages
{
"plugins": [
[
"@babel/plugin-transform-typescript",
{
"isTSX": true
}
]
]
}
# Ant Design Pro
This project is initialized with [Ant Design Pro](https://pro.ant.design). Follow is the quick guide for how to use.
## Environment Prepare
Install `node_modules`:
```bash
npm install
```
or
```bash
yarn
```
## Provided Scripts
Ant Design Pro provides some useful script to help you quick start and build with web project, code style check and test.
Scripts provided in `package.json`. It's safe to modify or add additional script:
### Start project
```bash
npm start
```
### Build project
```bash
npm run build
```
### Check code style
```bash
npm run lint
```
You can also use script to auto fix some lint error:
```bash
npm run lint:fix
```
### Test code
```bash
npm test
```
## More
You can view full document on our [official website](https://pro.ant.design). And welcome any feedback in our [github](https://github.com/ant-design/ant-design-pro).
const filterPkg = (pkgObject, ignoreList) => {
const devObj = {};
Object.keys(pkgObject).forEach(key => {
const isIgnore = ignoreList.some(reg => {
return new RegExp(reg).test(key);
});
if (isIgnore) {
return;
}
devObj[key] = pkgObject[key];
});
return devObj;
};
module.exports = filterPkg;
const debug = require('debug')('create-umi:generator');
const fs = require('fs-extra');
const path = require('path');
const chalk = require('chalk');
const glob = require('glob');
const exec = require('execa');
const BasicGenerator = require('../../BasicGenerator');
const filterPkg = require('./filterPkg');
const prettier = require('prettier');
const sylvanas = require('sylvanas');
const sortPackage = require('sort-package-json');
// const { getFastGithub } = require('umi-utils');
class Generator extends BasicGenerator {
function log(...args) {
console.log(`${chalk.gray('>')}`, ...args);
}
function globList(patternList, options) {
let fileList = [];
patternList.forEach(pattern => {
fileList = [...fileList, ...glob.sync(pattern, options)];
});
return fileList;
}
const getGithubUrl = async () => {
return 'http://platform.kuopu.net:9999/gitlab/nemean-group/nemean-simple.git';
};
const PRO_PATH = process.env.INIT_CWD || process.env.npm_rootpath || process.cwd();
class AntDesignProGenerator extends BasicGenerator {
prompting() {
if (this.opts.args && 'isTypeScript' in this.opts.args && 'reactFeatures' in this.opts.args) {
if (this.opts.args.language) {
this.prompts = {
isTypeScript: this.opts.args.isTypeScript,
reactFeatures: this.opts.args.reactFeatures,
language: this.opts.args.language,
};
} else {
const prompts = [
{
name: 'isTypeScript',
type: 'confirm',
message: 'Do you want to use typescript?',
default: false,
},
{
name: 'reactFeatures',
message: 'What functionality do you want to enable?',
type: 'checkbox',
choices: [
{name: 'antd', value: 'antd'},
{name: 'dva', value: 'dva'},
{name: 'code splitting', value: 'dynamicImport'},
{name: 'dll', value: 'dll'},
{name: 'internationalization', value: 'locale'},
],
name: 'language',
type: 'list',
message: 'Which language do you want to use?',
choices: ['JavaScript'],
},
];
return this.prompt(prompts).then(props => {
......@@ -35,35 +50,93 @@ class Generator extends BasicGenerator {
}
}
writing() {
this.writeFiles({
context: {
name: this.name,
...this.prompts,
},
filterFiles: f => {
const { isTypeScript, reactFeatures } = this.prompts;
if (isTypeScript) {
if (f.endsWith('.js')) return false;
if (!reactFeatures.includes('dva')) {
if (f.startsWith('src/models') || f === 'src/app.ts') return false;
}
if (!reactFeatures.includes('locale')) {
if (f.startsWith('src/locales') || f.includes('umi-plugin-locale')) return false;
}
} else {
if (this.isTsFile(f)) return false;
if (!reactFeatures.includes('dva')) {
if (f.startsWith('src/models') || f === 'src/app.js') return false;
}
if (!reactFeatures.includes('locale')) {
if (f.startsWith('src/locales') || f.includes('umi-plugin-locale')) return false;
}
}
return true;
},
});
async writing() {
const { language } = this.prompts;
const isTypeScript = language === 'TypeScript';
const projectName = this.opts.name || this.opts.env.cwd;
const projectPath = path.resolve(projectName);
const envOptions = {
cwd: projectPath,
};
const githubUrl = await getGithubUrl();
const gitArgs = [`clone`, githubUrl, `--depth=1`];
// Set branch if provided
if (this.opts.args.branch) {
gitArgs.push('--branch', this.opts.args.branch);
}
gitArgs.push(projectName);
// Clone remote branch
log(`git ${gitArgs.join(' ')}`);
await exec(`git`, gitArgs);
const packageJsonPath = path.resolve(projectPath, 'package.json');
const pkg = require(packageJsonPath);
// Handle js version
if (!isTypeScript) {
log('[Sylvanas] Prepare js environment...');
const tsFiles = globList(['**/*.tsx', '**/*.ts'], {
...envOptions,
ignore: ['**/*.d.ts'],
});
sylvanas(tsFiles, {
...envOptions,
action: 'overwrite',
});
log('[JS] Clean up...');
const removeTsFiles = globList(['tsconfig.json', '**/*.d.ts'], envOptions);
removeTsFiles.forEach(filePath => {
const targetPath = path.resolve(projectPath, filePath);
fs.removeSync(targetPath);
});
}
// copy readme
const babelConfig = path.resolve(__dirname, 'README.md');
fs.copySync(babelConfig, path.resolve(projectPath, 'README.md'));
// gen package.json
if (pkg['create-nemean']) {
const { ignoreScript = [], ignoreDependencies = [] } = pkg['create-nemean'];
// filter scripts and devDependencies
const projectPkg = {
...pkg,
version: '1.0.0',
scripts: filterPkg(pkg.scripts, ignoreScript),
devDependencies: filterPkg(pkg.devDependencies, ignoreDependencies),
};
// remove create-nemean config
delete projectPkg['create-nemean'];
fs.writeFileSync(
path.resolve(projectPath, 'package.json'),
// 删除一个包之后 json会多了一些空行。sortPackage 可以删除掉并且排序
// prettier 会容忍一个空行
prettier.format(JSON.stringify(sortPackage(projectPkg)), {
parser: 'json',
}),
);
}
// Clean up useless files
if (pkg['create-nemean'] && pkg['create-nemean'].ignore) {
log('Clean up...');
const ignoreFiles = pkg['create-nemean'].ignore;
const fileList = globList(ignoreFiles, envOptions);
fileList.forEach(filePath => {
const targetPath = path.resolve(projectPath, filePath);
fs.removeSync(targetPath);
});
}
}
}
module.exports = Generator;
module.exports = AntDesignProGenerator;
# 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
**/*.md
**/*.svg
**/*.ejs
**/*.html
package.json
.umi
.umi-production
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"overrides": [
{
"files": ".prettierrc",
"options": { "parser": "json" }
}
]
}
// ref: https://umijs.org/config/
export default {
treeShaking: true,
routes: [
{
path: '/',
component: '../layouts/index',
routes: [
{ path: '/', component: '../pages/index' }
]
}
],
plugins: [
// ref: https://umijs.org/plugin/umi-plugin-react.html
['umi-plugin-react', {
antd: <% if (reactFeatures.includes('antd')) { %>true<% } else { %>false<% } %>,
dva: <% if (reactFeatures.includes('dva')) { %>true<% } else { %>false<% } %>,
dynamicImport: <% if (reactFeatures.includes('dynamicImport')) { %>{ webpackChunkName: true }<% } else { %>false<% } %>,
title: '<%= name %>',
dll: <% if (reactFeatures.includes('dll')) { %>true<% } else { %>false<% } %>,
<% if (reactFeatures.includes('locale')) { %>locale: {
enable: true,
default: 'en-US',
},<% } %>
routes: {
exclude: [<% if (reactFeatures.includes('dva')) { %>
/models\//,
/services\//,
/model\.(t|j)sx?$/,
/service\.(t|j)sx?$/,<% } %>
/components\//,
],
},
}],
],
}
import { IConfig } from 'umi-types';
// ref: https://umijs.org/config/
const config: IConfig = {
treeShaking: true,
routes: [
{
path: '/',
component: '../layouts/index',
routes: [
{ path: '/', component: '../pages/index' }
]
}
],
plugins: [
// ref: https://umijs.org/plugin/umi-plugin-react.html
['umi-plugin-react', {
antd: <% if (reactFeatures.includes('antd')) { %>true<% } else { %>false<% } %>,
dva: <% if (reactFeatures.includes('dva')) { %>true<% } else { %>false<% } %>,
dynamicImport: <% if (reactFeatures.includes('dynamicImport')) { %>{ webpackChunkName: true }<% } else { %>false<% } %>,
title: '<%= name %>',
dll: <% if (reactFeatures.includes('dll')) { %>true<% } else { %>false<% } %>,
<% if (reactFeatures.includes('locale')) { %>locale: {
enable: true,
default: 'en-US',
},<% } %>
routes: {
exclude: [<% if (reactFeatures.includes('dva')) { %>
/models\//,
/services\//,
/model\.(t|j)sx?$/,
/service\.(t|j)sx?$/,<% } %>
/components\//,
],
},
}],
],
}
export default config;
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/npm-debug.log*
/yarn-error.log
/yarn.lock
/package-lock.json
# production
/dist
# misc
.DS_Store
# umi
.umi
.umi-production
{
"private": true,
"scripts": {
"start": "umi dev",
"build": "umi build",
"test": "umi test",
<% if (!isTypeScript) { -%>
"lint": "eslint --ext .js src mock tests",
<% } -%>
<% if (isTypeScript) { -%>
"lint:es": "eslint --ext .js src mock tests",
"lint:ts": "tslint \"src/**/*.ts\" \"src/**/*.tsx\"",
<% } -%>
"precommit": "lint-staged"
},
"dependencies": {
<% if (reactFeatures.includes('dva')) { -%>
"dva": "^2.6.0-beta.6",
<% } -%>
<% if (reactFeatures.includes('antd')) { -%>
"antd": "^3.19.5",
<% } -%>
"react": "^16.8.6",
"react-dom": "^16.8.6"
},
"devDependencies": {
<% if (isTypeScript) { -%>
"@types/jest": "^23.3.12",
"@types/react": "^16.7.18",
"@types/react-dom": "^16.0.11",
"@types/react-test-renderer": "^16.0.3",
<% } -%>
"babel-eslint": "^9.0.0",
"eslint": "^5.4.0",
"eslint-config-umi": "^1.4.0",
"eslint-plugin-flowtype": "^2.50.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-react": "^7.11.1",
"husky": "^0.14.3",
"lint-staged": "^7.2.2",
"react-test-renderer": "^16.7.0",
<% if (isTypeScript) { -%>
"tslint": "^5.12.0",
"tslint-eslint-rules": "^5.4.0",
"tslint-react": "^3.6.0",
"umi": "^2.9.0",
"umi-plugin-react": "^1.8.0",
"umi-types": "^0.3.0"
<% } else { -%>
"umi": "^2.7.7",
"umi-plugin-react": "^1.8.4"
<% } -%>
},
"lint-staged": {
<% if (isTypeScript) { -%>
"*.{ts,tsx}": ["tslint --fix", "git add"],
<% } -%>
"*.{js,jsx}": ["eslint --fix", "git add"]
},
"engines": {
"node": ">=8.0.0"
}
}
export const dva = {
config: {
onError(err) {
err.preventDefault();
console.error(err.message);
},
},
};
export const dva = {
config: {
onError(err: ErrorEvent) {
err.preventDefault();
console.error(err.message);
},
},
};
html, body, #root {
height: 100%;
}
body {
margin: 0;
}
import BasicLayout from '..';
import renderer from 'react-test-renderer';
describe('Layout: BasicLayout', () => {
it('Render correctly', () => {
const wrapper = renderer.create(<BasicLayout />);
expect(wrapper.root.children.length).toBe(1);
const outerLayer = wrapper.root.children[0];
expect(outerLayer.type).toBe('div');
const title = outerLayer.children[0];
expect(title.type).toBe('h1');
expect(title.children[0]).toBe('Yay! Welcome to umi!');
});
});
import 'jest';
import BasicLayout from '..';
import React from 'react';
import renderer, { ReactTestInstance, ReactTestRenderer } from 'react-test-renderer';
describe('Layout: BasicLayout', () => {
it('Render correctly', () => {
const wrapper: ReactTestRenderer = renderer.create(<BasicLayout />);
expect(wrapper.root.children.length).toBe(1);
const outerLayer = wrapper.root.children[0] as ReactTestInstance;
expect(outerLayer.type).toBe('div');
const title = outerLayer.children[0] as ReactTestInstance;
expect(title.type).toBe('h1');
expect(title.children[0]).toBe('Yay! Welcome to umi!');
});
});
.normal {
font-family: Georgia, sans-serif;
text-align: center;
}
.title {
font-size: 2.5rem;
font-weight: normal;
letter-spacing: -1px;
background: darkslateblue;
padding: .6em 0;
color: white;
margin: 0;
}
import styles from './index.css';
function BasicLayout(props) {
return (
<div className={styles.normal}>
<h1 className={styles.title}>Yay! Welcome to umi!</h1>
{props.children}
</div>
);
}
export default BasicLayout;
import React from 'react';
import styles from './index.css';
const BasicLayout: React.FC = props => {
return (
<div className={styles.normal}>
<h1 className={styles.title}>Yay! Welcome to umi!</h1>
{props.children}
</div>
);
};
export default BasicLayout;
export default {
'index.start': 'Getting Started',
}
export default {
'index.start': 'Getting Started',
}
import Index from '..';
import renderer from 'react-test-renderer';
<% if (reactFeatures.includes('locale')) { %>jest.mock('umi-plugin-locale');
<% } %>
describe('Page: index', () => {
it('Render correctly', () => {
const wrapper = renderer.create(<Index />);
expect(wrapper.root.children.length).toBe(1);
const outerLayer = wrapper.root.children[0];
expect(outerLayer.type).toBe('div');
expect(outerLayer.children.length).toBe(2);
<% if (reactFeatures.includes('locale')) { %>const getStartLink = outerLayer.findAllByProps({
href: 'https://umijs.org/guide/getting-started.html',
});
expect(getStartLink.length).toBe(1);
expect(getStartLink[0].children).toMatchObject(['Mock text']);<% } %>
});
});
import 'jest';
import Index from '..';
import React from 'react';
import renderer, { ReactTestInstance, ReactTestRenderer } from 'react-test-renderer';
<% if (reactFeatures.includes('locale')) { %>jest.mock('umi-plugin-locale');
<% } %>
describe('Page: index', () => {
it('Render correctly', () => {
const wrapper: ReactTestRenderer = renderer.create(<Index />);
expect(wrapper.root.children.length).toBe(1);
const outerLayer = wrapper.root.children[0] as ReactTestInstance;
expect(outerLayer.type).toBe('div');
expect(outerLayer.children.length).toBe(2);
<% if (reactFeatures.includes('locale')) { %>const getStartLink = outerLayer.findAllByProps({
href: 'https://umijs.org/guide/getting-started.html',
}) as ReactTestInstance[];
expect(getStartLink.length).toBe(1);
expect(getStartLink[0].children).toMatchObject(['Mock text']);<% } %>
});
});
.normal {
font-family: Georgia, sans-serif;
margin-top: 4em;
text-align: center;
}
.welcome {
height: 328px;
background: url(../assets/yay.jpg) no-repeat center 0;
background-size: 388px 328px;
}
.list {
font-size: 1.2em;
margin-top: 1.8em;
list-style: none;
line-height: 1.5em;
}
.list code {
background: #f7f7f7;
}
import styles from './index.css';
<% if (reactFeatures.includes('locale')) { %>import { formatMessage } from 'umi-plugin-locale';<% } -%>
export default function() {
return (
<div className={styles.normal}>
<div className={styles.welcome} />
<ul className={styles.list}>
<li>To get started, edit <code>src/pages/index.js</code> and save to reload.</li>
<li>
<a href="https://umijs.org/guide/getting-started.html">
<% if (reactFeatures.includes('locale')) { %>{formatMessage({ id: 'index.start' })}<% } else { %>Getting Started<% } %>
</a>
</li>
</ul>
</div>
);
}
import React from 'react';
import styles from './index.css';
<% if (reactFeatures.includes('locale')) { %>import { formatMessage } from 'umi-plugin-locale';<% } -%>
export default function() {
return (
<div className={styles.normal}>
<div className={styles.welcome} />
<ul className={styles.list}>
<li>To get started, edit <code>src/pages/index.js</code> and save to reload.</li>
<li>
<a href="https://umijs.org/guide/getting-started.html">
<% if (reactFeatures.includes('locale')) { %>{formatMessage({ id: 'index.start' })}<% } else { %>Getting Started<% } %>
</a>
</li>
</ul>
</div>
);
}
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"jsx": "react",
"esModuleInterop": true,
"sourceMap": true,
"baseUrl": ".",
"strict": true,
"paths": {
"@/*": ["src/*"]
},
"allowSyntheticDefaultImports": true
}
}
defaultSeverity: error
extends:
- tslint-react
- tslint-eslint-rules
rules:
eofline: true
no-console: true
no-construct: true
no-debugger: true
no-reference: true
declare module '*.css';
declare module "*.png";
/**
* 不是真实的 webpack 配置,仅为兼容 webstorm 和 intellij idea 代码跳转
* ref: https://github.com/umijs/umi/issues/1109#issuecomment-423380125
*/
module.exports = {
resolve: {
alias: {
'@': require('path').resolve(__dirname, 'src'),
},
},
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment