├── .editorconfig ├── .eslintrc ├── .eslintrc.js ├── .gitignore ├── .npmrc ├── .stylelintrc ├── LICENSE ├── README.md ├── config ├── deploy.js ├── env.js ├── jest │ ├── cssTransform.js │ ├── fileTransform.js │ └── jest-puppeteer.config.js ├── paths.js ├── webpack.config.dev.js ├── webpack.config.prod.js └── webpackDevServer.config.js ├── package.json ├── public ├── config.js ├── favicon.png ├── index.html └── manifest.json ├── scripts ├── build.js ├── start.js └── test.js └── src ├── App.js ├── assets ├── common.less ├── images │ └── avatar.png └── theme.less ├── common ├── menu.js ├── request.js ├── router.js └── urlMaps.js ├── components ├── Attr │ └── index.js ├── CodeArea │ ├── CodeArea.js │ ├── Monaco.js │ ├── index.js │ ├── index.scss │ └── monaco.less ├── Edit │ └── index.js ├── Exception │ ├── demo │ │ ├── 403.md │ │ ├── 404.md │ │ └── 500.md │ ├── index.css │ ├── index.d.ts │ ├── index.en-US.md │ ├── index.js │ ├── index.less │ ├── index.md │ ├── index.scss │ ├── index.zh-CN.md │ └── typeConfig.js ├── ExtraField │ └── index.js ├── ExtraFieldConfig │ ├── index.js │ └── index.less ├── ExtraTemplate │ └── index.js ├── FileTree │ └── index.js ├── HeaderSearch │ ├── demo │ │ └── basic.md │ ├── index.d.ts │ ├── index.js │ ├── index.less │ └── index.md ├── List │ └── index.js ├── MonacoEditor │ └── index.js ├── PageHeader │ ├── demo │ │ ├── image.md │ │ ├── simple.md │ │ ├── standard.md │ │ └── structure.md │ ├── index.d.ts │ ├── index.js │ ├── index.less │ ├── index.md │ └── index.test.js ├── SiderMenu │ ├── BaseMenu.js │ ├── SiderMenu.js │ ├── SiderMenu.test.js │ ├── index.js │ └── index.less ├── SimpleTable │ └── index.js ├── package │ ├── App.js │ ├── components │ │ ├── LocalProvider │ │ │ └── index.js │ │ ├── MockSelect │ │ │ └── index.js │ │ └── SchemaComponents │ │ │ ├── FieldInput.js │ │ │ ├── SchemaJson.js │ │ │ ├── SchemaOther.js │ │ │ └── schemaJson.css │ ├── index.css │ ├── index.js │ ├── index.less │ ├── models │ │ └── schema.js │ ├── schema.js │ └── utils.js └── utils │ ├── pathTools.js │ └── pathTools.test.js ├── defaultSettings.js ├── e2e ├── home.e2e.js └── login.e2e.js ├── index.js ├── layouts ├── BasicLayout.js ├── BasicLayout.less ├── BlankLayout.js ├── GlobalFooter │ ├── index.js │ └── index.less ├── GlobalHeader │ ├── index.js │ └── index.less ├── GlobalSider │ ├── index.js │ └── index.less ├── Layout.js ├── PageHeaderLayout.js ├── PageHeaderLayout.less ├── UserLayout.js └── UserLayout.less ├── logo.svg ├── models ├── app.js ├── component.js ├── global.js ├── inter.js ├── interApp.js ├── layout.js ├── page.js ├── preview.js ├── scaffold.js ├── template.js ├── user.js └── valid.js ├── modules ├── About │ └── About.js ├── App │ ├── Add.js │ └── List.js ├── Component │ ├── Add.js │ └── List.js ├── Exception │ ├── 403.js │ ├── 404.js │ ├── 500.js │ ├── style.less │ └── triggerException.js ├── Inter │ ├── Add.js │ └── List.js ├── Layout │ ├── Add.js │ └── List.js ├── Page │ ├── Add.js │ ├── CommonTemplate.js │ ├── ComponentExtraField.js │ ├── ComponentTree.js │ ├── List.js │ └── Template.js ├── Preview │ ├── Preview.js │ ├── buildPage.js │ └── testPreview.js ├── Scaffold │ ├── Add.js │ └── List.js ├── Template │ ├── Add.js │ └── List.js ├── User │ ├── Login.js │ ├── Login.less │ ├── Register.js │ ├── Register.less │ ├── RegisterResult.js │ ├── RegisterResult.less │ ├── UserLogin.js │ ├── UserLogin.less │ ├── UserLogin.test.js │ └── UserRegister.js └── Valid │ ├── Add.js │ └── List.js ├── registerServiceWorker.js ├── setupProxy.js └── utils ├── formLayout.js ├── jsonp.js ├── md5.js ├── native.js └── utils.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | 15 | [Makefile] 16 | indent_style = tab 17 | 18 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "extends": "airbnb", 4 | "plugins": ["compat"], 5 | "env": { 6 | "browser": true, 7 | "node": true, 8 | "es6": true, 9 | "mocha": true, 10 | "jest": true, 11 | "jasmine": true 12 | }, 13 | "rules": { 14 | "generator-star-spacing": [0], 15 | "consistent-return": [0], 16 | "react/forbid-prop-types": [0], 17 | "react/jsx-filename-extension": [1, { "extensions": [".js"] }], 18 | "global-require": [1], 19 | "import/prefer-default-export": [0], 20 | "react/jsx-no-bind": [0], 21 | "react/prop-types": [0], 22 | "react/prefer-stateless-function": [0], 23 | "react/jsx-wrap-multilines": ["error", { 24 | "declaration": "parens-new-line", 25 | "assignment": "parens-new-line", 26 | "return": "parens-new-line", 27 | "arrow": "parens-new-line", 28 | "condition": "parens-new-line", 29 | "logical": "parens-new-line", 30 | "prop": "ignore" 31 | }], 32 | "no-else-return": [0], 33 | "no-restricted-syntax": [0], 34 | "import/no-extraneous-dependencies": [0], 35 | "no-use-before-define": [0], 36 | "jsx-a11y/no-static-element-interactions": [0], 37 | "jsx-a11y/no-noninteractive-element-interactions": [0], 38 | "jsx-a11y/click-events-have-key-events": [0], 39 | "jsx-a11y/anchor-is-valid": [0], 40 | "no-nested-ternary": [0], 41 | "arrow-body-style": [0], 42 | "import/extensions": [0], 43 | "no-bitwise": [0], 44 | "no-cond-assign": [0], 45 | "import/no-unresolved": [0], 46 | "comma-dangle": ["error", { 47 | "arrays": "always-multiline", 48 | "objects": "always-multiline", 49 | "imports": "always-multiline", 50 | "exports": "always-multiline", 51 | "functions": "ignore" 52 | }], 53 | "object-curly-newline": [0], 54 | "function-paren-newline": [0], 55 | "no-restricted-globals": [0], 56 | "require-yield": [1], 57 | "compat/compat": "error" 58 | }, 59 | "parserOptions": { 60 | "ecmaFeatures": { 61 | "experimentalObjectRestSpread": true 62 | } 63 | }, 64 | "settings": { 65 | "polyfills": ["fetch", "promises"] 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: 'babel-eslint', 3 | 4 | extends: ['react-app'], 5 | parserOptions: { 6 | ecmaFeatures: { 7 | legacyDecorators: true 8 | } 9 | }, 10 | env: { 11 | browser: true, 12 | node: true, 13 | es6: true, 14 | mocha: true, 15 | jest: true, 16 | jasmine: true 17 | }, 18 | rules: {} 19 | }; 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | # roadhog-api-doc ignore 6 | /src/utils/request-temp.js 7 | _roadhog-api-doc 8 | 9 | # production 10 | /dist 11 | /build 12 | 13 | # misc 14 | .DS_Store 15 | npm-debug.log* 16 | yarn-error.log 17 | 18 | /coverage 19 | .idea 20 | yarn.lock 21 | package-lock.json 22 | *bak 23 | jsconfig.json 24 | .prettierrc 25 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | registry=https://registry.npm.taobao.org 2 | disturl=https://registry.npm.taobao.org/node 3 | nvm_nodejs_org_mirror=https://cdn.npm.taobao.org/dist/node 4 | sass_binary_site=https://npm.taobao.org/mirrors/node-sass/ 5 | fse_binary_host_mirror=https://registry.npm.taobao.org/fsevents 6 | phantomjs_cdnurl=https://npm.taobao.org/dist/phantomjs 7 | chromedriver_cdnurl=https://npm.taobao.org/mirrors/chromedriver 8 | operadriver_cdnurl=https://npm.taobao.org/mirrors/operadriver 9 | electron_mirror=http://npm.taobao.org/mirrors/electron 10 | puppeteer_download_host=https://cdn.npm.taobao.org/dist 11 | nwjs_urlbase=https://cdn.npm.taobao.org/dist/nwjs/v 12 | flow_binary_mirror=https://github.com/facebook/flow/releases/download/v -------------------------------------------------------------------------------- /.stylelintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "stylelint-config-prettier", 4 | "stylelint-config-standard", 5 | "./node_modules/prettier-stylelint/config.js" 6 | ], 7 | "rules": { 8 | "indentation": 2, 9 | "selector-pseudo-class-no-unknown": null, 10 | "shorthand-property-no-redundant-values": null, 11 | "at-rule-empty-line-before": null, 12 | "at-rule-name-space-after": null, 13 | "comment-empty-line-before": null, 14 | "declaration-bang-space-before": null, 15 | "declaration-empty-line-before": null, 16 | "function-comma-newline-after": null, 17 | "function-name-case": null, 18 | "function-parentheses-newline-inside": null, 19 | "function-max-empty-lines": null, 20 | "function-whitespace-after": null, 21 | "no-missing-end-of-source-newline": null, 22 | "number-leading-zero": null, 23 | "number-no-trailing-zeros": null, 24 | "rule-empty-line-before": null, 25 | "selector-combinator-space-after": null, 26 | "selector-descendant-combinator-no-non-space": null, 27 | "selector-list-comma-newline-after": null, 28 | "selector-pseudo-element-colon-notation": null, 29 | "unit-no-unknown": null, 30 | "no-descending-specificity": null, 31 | "value-list-max-empty-lines": null 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 daycool 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 如果您对此项目感兴趣欢迎 [star](https://github.com/genany/gen),如果您对有问题和建议欢迎 [issues](https://github.com/genany/gen/issues/new) 4 | 5 | 6 | # 通过接口生成一切 7 | 8 | 9 | --- 10 | 11 | 我们程序员每天都跟代码打交道,前端程序员coding, 后端程序员coding。 12 | 然而我们经常做重复性工作或者复制粘贴,或者前后端因为接口变动扯皮。 13 | 为了解决这些问题我打算通过接口生成代码。 14 | 15 | ## 为什么通过接口生成一切 16 | ### 任何语言都是在跟数据打交道 17 | 18 | 1. 在web前端html用来展现数据,javascript处理数据 19 | 1. go、java、php、nodejs等后端语言都在处理前端给的数据,或者给前端的数据 20 | 1. mysql、oracle、mongodb、postsql等数据库用来存储数据 21 | 22 | ### 接口是前后端通讯的桥梁 23 | 24 | ### 接口可以约定json格式 25 | 1. json易于人阅读和编写 26 | 2. json易于机器解析和生成 27 | 28 | ## 我理想的目标 29 | 1. 根据接口一键生成一套前可运行后端接口方案 30 | 1. 不改变我的开发方式 31 | 1. 低门槛轻松上手 32 | 1. 可视化配置 33 | 1. 如果是web页面所见即所得 34 | 1. 有丰富的项目脚手架方便二次开发 35 | 1. 生成接口文档 36 | 37 | ## 如何实现这些目标 38 | 39 | 1. 我们把每个文件都看做一个大模版,而这个大模版又有多个小模版组成,小模版我们把它叫做组件,组件又有组件属性,这样就组成了一个component tree,而接口本省又是个data tree, 两者渲染成最终我们想要的文件,这里模版引擎我们用了unjuncks 40 | 1. 接口使用hjson我通过注释表明这个字段对应的组件类型mock数据。 41 | hjson和jsonSchema相互转换,这样我就可以使用jsonSchema进行可视化配置 42 | 1. 通过jsonSchema配置字段对应的组件和定制组件扩展信息 43 | 1. 配置完即可动态渲染实时得到渲染结果, 如果是web页面我们可以iframe在区块内实时预览 44 | 1. 定制可服用模版和组件, 这样我们就可以定制各种页面 45 | 1. 通过把组件生成可动态配置的组件文件,然后把配置组件属性通过postMessage传递给iframe页进行实时修改 46 | 1. 把我们最佳项目实践直接做为脚手架,通用的文件设置为模版,或分隔多个小组件 47 | 48 | ## 在线运行太慢,或者网上代码不安全 49 | 1. 使用辅助工具,直接把渲染结果输出到本地,同时调用git命令保存修改文件,方便查看修改记录或回滚 50 | 51 | 52 | ![扩展字段](http://gen.sdemo.cn/gen.gif) 53 | -------------------------------------------------------------------------------- /config/deploy.js: -------------------------------------------------------------------------------- 1 | const client = require('deploy-kit') 2 | const path = require('path') 3 | client 4 | .sftp({ 5 | // sever account, address, port 6 | server: 'dev:zc-user!Q@W3e@223.203.221.60', 7 | // deploy all files in the directory 8 | workspace: path.join(__dirname, '..', 'build'), 9 | // ignore the matched files (glob pattern: https://github.com/isaacs/node-glob#glob-primer) 10 | // support array of glob pattern 11 | ignore: '**/*.map', 12 | // where the files are placed on the server 13 | deployTo: '/home/share/pay-admin/', 14 | // you can specify different place for each file 15 | rules: [ 16 | // { 17 | // test: /dist\/(.*)$/, 18 | // // $1, $2... means the parenthesized substring matches 19 | // // [$n] will be replaced with matched string 20 | // dest: 'public/static/[$1]' 21 | // }, 22 | // { 23 | // test: /views\/((?:[^/]+\/)*?[^\/]+).html$/, 24 | // dest: 'app/views/[$1].phtml' 25 | // } 26 | ] 27 | }) 28 | .exec() 29 | -------------------------------------------------------------------------------- /config/env.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | const path = require('path'); 5 | const paths = require('./paths'); 6 | 7 | // Make sure that including paths.js after env.js will read .env variables. 8 | delete require.cache[require.resolve('./paths')]; 9 | 10 | const NODE_ENV = process.env.NODE_ENV; 11 | if (!NODE_ENV) { 12 | throw new Error( 13 | 'The NODE_ENV environment variable is required but was not specified.' 14 | ); 15 | } 16 | 17 | // https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use 18 | var dotenvFiles = [ 19 | `${paths.dotenv}.${NODE_ENV}.local`, 20 | `${paths.dotenv}.${NODE_ENV}`, 21 | // Don't include `.env.local` for `test` environment 22 | // since normally you expect tests to produce the same 23 | // results for everyone 24 | NODE_ENV !== 'test' && `${paths.dotenv}.local`, 25 | paths.dotenv, 26 | ].filter(Boolean); 27 | 28 | // Load environment variables from .env* files. Suppress warnings using silent 29 | // if this file is missing. dotenv will never modify any environment variables 30 | // that have already been set. Variable expansion is supported in .env files. 31 | // https://github.com/motdotla/dotenv 32 | // https://github.com/motdotla/dotenv-expand 33 | dotenvFiles.forEach(dotenvFile => { 34 | if (fs.existsSync(dotenvFile)) { 35 | require('dotenv-expand')( 36 | require('dotenv').config({ 37 | path: dotenvFile, 38 | }) 39 | ); 40 | } 41 | }); 42 | 43 | // We support resolving modules according to `NODE_PATH`. 44 | // This lets you use absolute paths in imports inside large monorepos: 45 | // https://github.com/facebook/create-react-app/issues/253. 46 | // It works similar to `NODE_PATH` in Node itself: 47 | // https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders 48 | // Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored. 49 | // Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims. 50 | // https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421 51 | // We also resolve them to make sure all tools using them work consistently. 52 | const appDirectory = fs.realpathSync(process.cwd()); 53 | process.env.NODE_PATH = (process.env.NODE_PATH || '') 54 | .split(path.delimiter) 55 | .filter(folder => folder && !path.isAbsolute(folder)) 56 | .map(folder => path.resolve(appDirectory, folder)) 57 | .join(path.delimiter); 58 | 59 | // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be 60 | // injected into the application via DefinePlugin in Webpack configuration. 61 | const REACT_APP = /^REACT_APP_/i; 62 | 63 | function getClientEnvironment(publicUrl) { 64 | const raw = Object.keys(process.env) 65 | .filter(key => REACT_APP.test(key)) 66 | .reduce( 67 | (env, key) => { 68 | env[key] = process.env[key]; 69 | return env; 70 | }, 71 | { 72 | // Useful for determining whether we’re running in production mode. 73 | // Most importantly, it switches React into the correct mode. 74 | NODE_ENV: process.env.NODE_ENV || 'development', 75 | // Useful for resolving the correct path to static assets in `public`. 76 | // For example, . 77 | // This should only be used as an escape hatch. Normally you would put 78 | // images into the `src` and `import` them in code to get their paths. 79 | PUBLIC_URL: publicUrl, 80 | } 81 | ); 82 | // Stringify all values so we can feed into Webpack DefinePlugin 83 | const stringified = { 84 | 'process.env': Object.keys(raw).reduce((env, key) => { 85 | env[key] = JSON.stringify(raw[key]); 86 | return env; 87 | }, {}), 88 | }; 89 | 90 | return { raw, stringified }; 91 | } 92 | 93 | module.exports = getClientEnvironment; 94 | -------------------------------------------------------------------------------- /config/jest/cssTransform.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // This is a custom Jest transformer turning style imports into empty objects. 4 | // http://facebook.github.io/jest/docs/en/webpack.html 5 | 6 | module.exports = { 7 | process() { 8 | return 'module.exports = {};'; 9 | }, 10 | getCacheKey() { 11 | // The output is always the same. 12 | return 'cssTransform'; 13 | }, 14 | }; 15 | -------------------------------------------------------------------------------- /config/jest/fileTransform.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const path = require('path'); 4 | 5 | // This is a custom Jest transformer turning file imports into filenames. 6 | // http://facebook.github.io/jest/docs/en/webpack.html 7 | 8 | module.exports = { 9 | process(src, filename) { 10 | const assetFilename = JSON.stringify(path.basename(filename)); 11 | 12 | if (filename.match(/\.svg$/)) { 13 | return `module.exports = { 14 | __esModule: true, 15 | default: ${assetFilename}, 16 | ReactComponent: (props) => ({ 17 | $$typeof: Symbol.for('react.element'), 18 | type: 'svg', 19 | ref: null, 20 | key: null, 21 | props: Object.assign({}, props, { 22 | children: ${assetFilename} 23 | }) 24 | }), 25 | };`; 26 | } 27 | 28 | return `module.exports = ${assetFilename};`; 29 | }, 30 | }; 31 | -------------------------------------------------------------------------------- /config/jest/jest-puppeteer.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | server: { 3 | command: 'node server.js', 4 | port: 4444 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /config/paths.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const path = require('path'); 4 | const fs = require('fs'); 5 | const url = require('url'); 6 | 7 | // Make sure any symlinks in the project folder are resolved: 8 | // https://github.com/facebook/create-react-app/issues/637 9 | const appDirectory = fs.realpathSync(process.cwd()); 10 | const resolveApp = relativePath => path.resolve(appDirectory, relativePath); 11 | 12 | const envPublicUrl = process.env.PUBLIC_URL; 13 | 14 | function ensureSlash(inputPath, needsSlash) { 15 | const hasSlash = inputPath.endsWith('/'); 16 | if (hasSlash && !needsSlash) { 17 | return inputPath.substr(0, inputPath.length - 1); 18 | } else if (!hasSlash && needsSlash) { 19 | return `${inputPath}/`; 20 | } else { 21 | return inputPath; 22 | } 23 | } 24 | 25 | const getPublicUrl = appPackageJson => 26 | envPublicUrl || require(appPackageJson).homepage; 27 | 28 | // We use `PUBLIC_URL` environment variable or "homepage" field to infer 29 | // "public path" at which the app is served. 30 | // Webpack needs to know it to put the right