├── templates ├── HISTORY.md ├── npmignore ├── .travis.yml ├── .github │ └── workflows │ │ └── publish.yml ├── gitignore ├── index.html ├── README_EN.md ├── README.md ├── package.json └── demo │ ├── index-demo-base.js │ └── atom-one-dark.css ├── HISTORY.md ├── bin ├── bee-tools.js └── bee-tools-run.js ├── npm-shrinkwrap.json ├── .gitignore ├── src ├── cli │ ├── run.js │ └── index.js ├── test │ ├── demo.js │ ├── Demo1.js │ ├── test1.js │ └── test.js ├── tokenIndex.js ├── ac-tools.js ├── global.js ├── webpack.dev.js ├── util.js ├── create.js ├── create-acs.js ├── create-acs_bak.js └── gulpfile.js ├── LICENSE ├── README.md └── package.json /templates/HISTORY.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | # history 2 | -------------------------------------------------------------------------------- /bin/bee-tools.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('../src/cli/'); 3 | -------------------------------------------------------------------------------- /bin/bee-tools-run.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('../src/cli/run'); 3 | -------------------------------------------------------------------------------- /npm-shrinkwrap.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "graceful-fs": { 4 | "version": "4.2.3" 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | *.log 3 | .idea/ 4 | .ipr 5 | .iws 6 | *~ 7 | ~* 8 | *.diff 9 | *.patch 10 | *.bak 11 | .DS_Store 12 | Thumbs.db 13 | .project 14 | .*proj 15 | .svn/ 16 | *.swp 17 | *.swo 18 | *.pyc 19 | *.pyo 20 | .build 21 | node_modules 22 | _site 23 | sea-modules 24 | spm_modules 25 | .cache 26 | build 27 | assets/**/*.css 28 | npm-debug.log* 29 | -------------------------------------------------------------------------------- /templates/npmignore: -------------------------------------------------------------------------------- 1 | bower_components/ 2 | *.cfg 3 | node_modules/ 4 | nohup.out 5 | *.iml 6 | .idea/ 7 | .ipr 8 | .iws 9 | *~ 10 | ~* 11 | *.diff 12 | *.log 13 | *.patch 14 | *.bak 15 | .DS_Store 16 | Thumbs.db 17 | .project 18 | .*proj 19 | .svn/ 20 | *.swp 21 | out/ 22 | .build 23 | node_modules 24 | _site 25 | sea-modules 26 | spm_modules 27 | .cache 28 | coverage 29 | demo 30 | docs 31 | test 32 | dist 33 | .npmignore -------------------------------------------------------------------------------- /templates/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: node_js 4 | 5 | node_js: 6 | - "6" 7 | 8 | service_name: travis-ci 9 | repo_token: add 10 | 11 | env: 12 | global: 13 | - NODE_ENV=travisci 14 | - NPM_CONFIG_PROGRESS="false" 15 | 16 | before_install: 17 | - npm install -g bee-tools 18 | - npm install -g bee-tools-test 19 | 20 | script: npm test 21 | 22 | after_script: 23 | - npm run coveralls 24 | -------------------------------------------------------------------------------- /templates/.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | tags: 4 | - 'v*' 5 | name: Publish 6 | jobs: 7 | publish: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - uses: actions/setup-node@v1 12 | with: 13 | node-version: 10 14 | registry-url: https://registry.npmjs.org/ 15 | - run: npm i -g bee-tools 16 | - run: npm i 17 | - run: npm publish 18 | env: 19 | NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} 20 | - uses: iuap-design/actions-ynpm-sync@master -------------------------------------------------------------------------------- /src/cli/run.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | var program = require('commander'); 4 | var colors = require('colors/safe'); 5 | colors.setTheme({ 6 | info: ['bold', 'green'], 7 | list: ['bold', 'blue'] 8 | }); 9 | 10 | program.on('--help', function() { 11 | console.log(colors.info('Usage')); 12 | console.log(); 13 | console.log(colors.blue('$ bee-tools run build'), 'compile src files to es3 standard') 14 | }); 15 | 16 | program.parse(process.argv); 17 | 18 | var task = program.args[0]; 19 | 20 | if (!task) { 21 | program.help() 22 | } else { 23 | var gulp = require('gulp'); 24 | require('../gulpfile'); 25 | gulp.start(task); 26 | } 27 | -------------------------------------------------------------------------------- /templates/gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | 27 | # Dependency directories 28 | node_modules 29 | jspm_packages 30 | 31 | # Optional npm cache directory 32 | .npm 33 | 34 | # Optional REPL history 35 | .node_repl_history 36 | 37 | dist 38 | coverage 39 | .idea/ -------------------------------------------------------------------------------- /src/test/demo.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @title 取色板 4 | * @description 提供预制色板的取色板组件 5 | * 6 | */ 7 | import React, { Component } from 'react'; 8 | import { FormControl, Button, Dnd } from 'tinper-bee'; 9 | import Datepicker from 'bee-datepicker'; 10 | import Timepicker from 'bee-timepicker' 11 | 12 | import ZZZ from 'zzz' 13 | 14 | class Demo1 extends Component { 15 | state = { 16 | value : "#E14C46" 17 | } 18 | 19 | handleChange = (v) => { 20 | console.log("选择的色彩信息 :" , v); 21 | this.setState({ 22 | value: v.hex || '' 23 | }) 24 | } 25 | render () { 26 | return ( 27 | 33 | ) 34 | } 35 | } 36 | export default Demo1 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 tinper-bee 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 | -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | tinper-bee demo 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/tokenIndex.js: -------------------------------------------------------------------------------- 1 | var promfig = require('promfig') 2 | , Github = require('github'); 3 | 4 | module.exports = getGithubToken 5 | 6 | 7 | 8 | function getGithubToken(scopes, note, noteUrl, github, ready) { 9 | if(!ready) { 10 | ready = github 11 | 12 | github = new Github({ 13 | version: '3.0.0' 14 | , protocol: 'https' 15 | }) 16 | } 17 | promfig({ 18 | username: 'username: ' 19 | , password: 'password: ' 20 | , '@secret': 'password' 21 | }, {}, onlogin); 22 | 23 | function onlogin(err,config) { 24 | if(err) { 25 | return ready(err) 26 | } 27 | github.authenticate({ 28 | type: 'basic' 29 | , username: config.username 30 | , password: config.password 31 | }) 32 | 33 | attempt(null) 34 | 35 | function attempt(headers) { 36 | github.authorization.create({ 37 | note: note 38 | , scopes: scopes 39 | , note_url: noteUrl 40 | , headers: headers 41 | }, onready) 42 | } 43 | 44 | function onreattempt(err, config) { 45 | if(err) { 46 | return ready(err) 47 | } 48 | 49 | attempt({'X-GitHub-OTP': config.twofactor}) 50 | } 51 | 52 | function onready(err, res) { 53 | if(err && /OTP/.test(err.message)) { 54 | return promfig({ 55 | 'twofactor': 'Two Factor Code: ' 56 | }, {}, onreattempt) 57 | } 58 | 59 | if(err) { 60 | return ready(err) 61 | } 62 | return ready(err,{"token":res.token,"user":config.username}) 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /templates/README_EN.md: -------------------------------------------------------------------------------- 1 | # <%= packageName%> 2 | 3 | [![npm version](https://img.shields.io/npm/v/<%= packageName%>.svg)](https://www.npmjs.com/package/<%= packageName%>) 4 | [![Build Status](https://img.shields.io/travis/tinper-bee/<%= packageName%>/master.svg)](https://travis-ci.org/tinper-bee/<%= packageName%>) 5 | [![Coverage Status](https://coveralls.io/repos/github/tinper-bee/<%= packageName%>/badge.svg?branch=master)](https://coveralls.io/github/tinper-bee/<%= packageName%>?branch=master) 6 | [![devDependency Status](https://img.shields.io/david/dev/tinper-bee/<%= packageName%>.svg)](https://david-dm.org/tinper-bee/<%= packageName%>#info=devDependencies) 7 | [![NPM downloads](http://img.shields.io/npm/dm/<%= packageName%>.svg?style=flat)](https://npmjs.org/package/<%= packageName%>) 8 | [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/tinper-bee/<%= packageName%>.svg)](http://isitmaintained.com/project/tinper-bee/<%= packageName%> "Average time to resolve an issue") 9 | [![Percentage of issues still open](http://isitmaintained.com/badge/open/tinper-bee/<%= packageName%>.svg)](http://isitmaintained.com/project/tinper-bee/<%= packageName%> "Percentage of issues still open") 10 | 11 | 12 | 13 | react <%= packageName%> component for tinper-bee 14 | 15 | ## Rely 16 | 17 | - react >= 15.3.0 18 | - react-dom >= 15.3.0 19 | - prop-types >= 15.6.0 20 | 21 | ## Usage 22 | 23 | ```js 24 | 25 | 26 | ``` 27 | 28 | 29 | 30 | ## API 31 | 32 | |参数|说明|类型|默认值| 33 | |:--|:---:|:--:|---:| 34 | 35 | #### develop 36 | 37 | ```sh 38 | $ npm install -g bee-tools 39 | $ git clone https://github.com/tinper-bee/<%= packageName%> 40 | $ cd <%= packageName%> 41 | $ npm install 42 | $ npm run dev 43 | ``` 44 | -------------------------------------------------------------------------------- /templates/README.md: -------------------------------------------------------------------------------- 1 | # <%= packageName%> 2 | 3 | [![npm version](https://img.shields.io/npm/v/<%= packageName%>.svg)](https://www.npmjs.com/package/<%= packageName%>) 4 | [![Build Status](https://img.shields.io/travis/tinper-bee/<%= packageName%>/master.svg)](https://travis-ci.org/tinper-bee/<%= packageName%>) 5 | [![Coverage Status](https://coveralls.io/repos/github/tinper-bee/<%= packageName%>/badge.svg?branch=master)](https://coveralls.io/github/tinper-bee/<%= packageName%>?branch=master) 6 | [![devDependency Status](https://img.shields.io/david/dev/tinper-bee/<%= packageName%>.svg)](https://david-dm.org/tinper-bee/<%= packageName%>#info=devDependencies) 7 | [![NPM downloads](http://img.shields.io/npm/dm/<%= packageName%>.svg?style=flat)](https://npmjs.org/package/<%= packageName%>) 8 | [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/tinper-bee/<%= packageName%>.svg)](http://isitmaintained.com/project/tinper-bee/<%= packageName%> "Average time to resolve an issue") 9 | [![Percentage of issues still open](http://isitmaintained.com/badge/open/tinper-bee/<%= packageName%>.svg)](http://isitmaintained.com/project/tinper-bee/<%= packageName%> "Percentage of issues still open") 10 | 11 | 12 | react <%= packageName%> component for tinper-bee 13 | 14 | some description... 15 | 16 | ## 依赖 17 | 18 | - react >= 15.3.0 19 | - react-dom >= 15.3.0 20 | - prop-types >= 15.6.0 21 | 22 | ## 使用方法 23 | 24 | ```js 25 | 26 | ``` 27 | 28 | 29 | 30 | ## API 31 | 32 | |参数|说明|类型|默认值| 33 | |:--|:---:|:--:|---:| 34 | 35 | #### 开发调试 36 | 37 | ```sh 38 | $ npm install -g bee-tools 39 | $ git clone https://github.com/tinper-bee/<%= packageName%> 40 | $ cd <%= packageName%> 41 | $ npm install 42 | $ npm run dev 43 | ``` 44 | -------------------------------------------------------------------------------- /src/cli/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | var program = require('commander'); 4 | var inquirer = require("inquirer"); 5 | var packageInfo = require('../../package.json'); 6 | 7 | var questions = { 8 | component:{ 9 | type: 'list', 10 | name: 'choose', 11 | message: 'Please choose ?', 12 | choices:["ac-xx component","bee-xx component"], 13 | default: function() { 14 | return 'Default is ac-xx ' 15 | } 16 | } 17 | } 18 | 19 | program 20 | .version(packageInfo.version) 21 | .command('run [name]', 'run specified task'); 22 | 23 | 24 | // https://github.com/tj/commander.js/pull/260 25 | var proc = program.runningCommand; 26 | if (proc) { 27 | proc.on('close', process.exit.bind(process)); 28 | proc.on('error', function() { 29 | process.exit(1); 30 | }); 31 | } 32 | 33 | //脚手架开始 34 | program 35 | .command('create [dir]') 36 | .description('生成一个空组件') 37 | .option('-a, --author ', '作者') 38 | .option('-p, --port ', '服务端口号') 39 | .option('--pkgName ', '模块名') 40 | .option('-v, --tbVersion ', '版本号') 41 | .option('-r, --repoUrl ', '仓库地址') 42 | .action(function (dir,otherDirs){ 43 | inquirer.prompt(questions.component).then(function(answers) { 44 | if(/bee-/.test(dir)){ 45 | require('../create')(dir,otherDirs); 46 | }else{ 47 | require('../create-acs')(dir,otherDirs); 48 | } 49 | }); 50 | }); 51 | 52 | program.parse(process.argv); 53 | 54 | 55 | // var subCmd = program.args[0]; 56 | 57 | // if (!subCmd || !(subCmd == 'run' || subCmd == 'create')) { 58 | // program.help(); 59 | // } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bee-tools 2 | 3 | [![NPM downloads](http://img.shields.io/npm/dm/bee-tools.svg?style=flat)](https://npmjs.org/package/bee-tools) 4 | [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/tinper-bee/bee-tools.svg)](http://isitmaintained.com/project/tinper-bee/bee-tools "Average time to resolve an issue") 5 | [![Percentage of issues still open](http://isitmaintained.com/badge/open/tinper-bee/bee-tools.svg)](http://isitmaintained.com/project/tinper-bee/bee-tools "Percentage of issues still open") 6 | 7 | tinper-bee 组件库编写组件开发工具 8 | bee-tools 集成了ynpm 包的安装,新增了包的发布,且自动生成releases,并解决了不兼容node>8的版本报错的问题。 9 | 10 | ## 下载 11 | ``` 12 | npm install -g bee-tools 13 | 14 | >由于changelog依赖commitizen,所以需要安装commitizen 15 | 16 | >npm install -g commitizen 17 | 18 | ``` 19 | ## 使用 20 | 21 | `cd` 直接进入项目根目录,使用以下命令完成对应功能。 22 | 23 | ### 初始化项目 24 | 25 | ``` 26 | bee-tools create 组件名称 27 | 28 | 选择组件类型,应用组件选择 ac-xxx component。 基础组件选择 bee-xxx component 29 | 30 | ``` 31 | 32 | ### 本地运行 33 | 34 | ``` 35 | 修改 demo/demolist/Demo1.js 文件内容 36 | 37 | 运行 npm run dev 即可 38 | 39 | 新增demo请在 demo/demolist下新建文件,例如 Demo2.js、Demo3.js等 40 | 41 | ``` 42 | 43 | ### 发布到 npm 上 44 | 45 | ``` 46 | 运行 npm run pub 47 | 填写 changelog,会提交到git并发布 48 | ``` 49 | 50 | 51 | 52 | | # | Scripts 脚本命令 | Description 功能描述 | 53 | | --- | --- | --- | 54 | | 1 | bee-tools create ac-xx/bee-xx | 创建项目(应用组件、基础组件) | 55 | | 2 | bee-tools run dev | 打开浏览器,调试代码和demo | 56 | | 3 | bee-tools run build | 打包代码到build文件夹 | 57 | | 4 | bee-tools run pub | 集成了(发布npm包、提交github、生成changelog)功能| 58 | | 5 | bee-tools run dep | 下载依赖 | 59 | | 6 | bee-tools run update | 更新依赖 | 60 | | 7 | bee-tools run changelogInit | 初始化cz-conventional-changelog | 61 | | 8 | bee-tools run changelog | 生成CHANGELOG.md | 62 | | 9 | bee-tools run releases | 创建releases | 63 | -------------------------------------------------------------------------------- /templates/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "<%= packageName%>", 3 | "version": "<%= version%>", 4 | "description": "<%= appname%> ui component for react", 5 | "keywords": [ 6 | "react", 7 | "react-component", 8 | "<%= packageName%>", 9 | "iuap-design", 10 | "tinper-bee", 11 | "<%= appname%>" 12 | ], 13 | "engines": { 14 | "node": ">=4.0.0" 15 | }, 16 | "homepage": "<%= repo_url%>", 17 | "author": "<%= author%>", 18 | "repository": "http://github.com/tinper-bee/<%= packageName%>", 19 | "bugs": "<%= repo_url%>/issues", 20 | "license": "MIT", 21 | "main": "./build/index.js", 22 | "config": { 23 | "port": <%= port%>, 24 | "commitizen": { 25 | "path": "./node_modules/cz-conventional-changelog" 26 | } 27 | }, 28 | "scripts": { 29 | "dev": "bee-tools run start", 30 | "build": "bee-tools run build", 31 | "lint": "bee-tools-test run lint", 32 | "test": "bee-tools-test run test", 33 | "chrome": "bee-tools-test run chrome", 34 | "coveralls": "bee-tools-test run coverage", 35 | "browsers": "bee-tools-test run browsers", 36 | "pub": "bee-tools run pub", 37 | "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0", 38 | "version": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md", 39 | "postversion": "git push --follow-tags" 40 | }, 41 | "dependencies": { 42 | "classnames": "^2.2.5", 43 | "tinper-bee-core": "latest", 44 | "babel-runtime": "^6.23.0" 45 | }, 46 | "devDependencies": { 47 | "chai": "^3.5.0", 48 | "enzyme": "^2.4.1", 49 | "react": "15.3.2", 50 | "react-addons-test-utils": "15.3.2", 51 | "react-dom": "15.3.2", 52 | "console-polyfill": "~0.2.1", 53 | "cz-conventional-changelog": "^2.1.0", 54 | "es5-shim": "~4.1.10", 55 | "bee-drawer": "0.0.2", 56 | "bee-clipboard": "^2.0.0", 57 | "bee-panel": "latest", 58 | "bee-layout": "latest", 59 | "bee-button": "latest" 60 | }, 61 | "peerDependencies": { 62 | "react": ">= 15.3.0", 63 | "react-dom": ">= 15.3.0", 64 | "prop-types": ">= 15.6.0" 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/ac-tools.js: -------------------------------------------------------------------------------- 1 | // dependency 2 | // var fs = require("fs"); 3 | // var inquirer = require("inquirer"); 4 | // var spawn = require("cross-spawn"); 5 | // var file = require("html-wiring"); 6 | // var colors = require("colors/safe"); 7 | // var util = require("./util"); 8 | // var path = require("path"); 9 | 10 | // var browserSync = require("browser-sync"); 11 | // var reload = browserSync.reload; 12 | // var shelljs = require("shelljs"); 13 | 14 | // gulp & gulp plugin 15 | // var gulp = require("gulp"); 16 | // var babel = require("gulp-babel"); 17 | // var sass = require("gulp-sass"); 18 | // var sourcemaps = require("gulp-sourcemaps"); 19 | // var autoprefix = require("gulp-autoprefixer"); 20 | // var concat = require("gulp-concat"); 21 | // var replace = require("gulp-just-replace"); 22 | // var es3ify = require("gulp-es3ify"); 23 | // var eslint = require("gulp-eslint"); 24 | // var conven = require("gulp-conventional-changelog"); 25 | // var fse = require("fs-extra"); 26 | 27 | var download = require('download-git-repo'); 28 | // const chalk = require('chalk'); 29 | 30 | // webpack 31 | // var webpack = require("webpack"); 32 | 33 | 34 | // gulp.task("download", function() { 35 | // console.log(" ----download------- "); 36 | // // console.log(chalk.cyan(`Downloading \'ac\' please wait.`)); 37 | // // download('direct:https://github.com/iuap-design/tinper-bee.git', 'test/tmp', function (err) { 38 | // // if (!err) { 39 | // // console.log(err ? 'Error' : 'Success') 40 | // // } else { 41 | // // console.error(requestBody.message); 42 | // // } 43 | // // }) 44 | // }); 45 | 46 | // function download(){ 47 | // console.log(" ----download------- "); 48 | // download('direct:https://github.com/iuap-design/tinper-bee.git', 'test/tmp', function (err) { 49 | // if (!err) { 50 | // console.log(err ? 'Error' : 'Success') 51 | // } else { 52 | // console.error(requestBody.message); 53 | // } 54 | // }); 55 | // } 56 | 57 | function writeThemColor(){ 58 | 59 | } 60 | 61 | module.exports = function (name, options) { 62 | console.log(" p--- ",name); 63 | console.log(" options--- ",options); 64 | } 65 | 66 | 67 | // module.exports = { 68 | // download:download() 69 | // } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bee-tools", 3 | "version": "1.1.3", 4 | "description": "development tools for tinper-bee", 5 | "main": "index.js", 6 | "scripts": {}, 7 | "author": "yonyou iuapfed", 8 | "license": "MIT", 9 | "bin": { 10 | "bee-tools": "./bin/bee-tools.js" 11 | }, 12 | "dependencies": { 13 | "babel-core": "~6.9.0", 14 | "babel-loader": "~6.2.1", 15 | "babel-plugin-add-module-exports": "^0.2.1", 16 | "babel-plugin-transform-es3-member-expression-literals": "^6.8.0", 17 | "babel-plugin-transform-es3-property-literals": "^6.8.0", 18 | "babel-plugin-transform-object-assign": "^6.8.0", 19 | "babel-plugin-transform-object-entries": "^1.0.0", 20 | "babel-plugin-transform-object-rest-spread": "^6.19.0", 21 | "babel-plugin-transform-runtime": "^6.15.0", 22 | "babel-preset-es2015-ie": "~6.6.2", 23 | "babel-preset-react": "~6.5.0", 24 | "babel-preset-stage-1": "~6.5.0", 25 | "babel-preset-stage-3": "^6.17.0", 26 | "babel-runtime": "^6.20.0", 27 | "browser-sync": "^2.17.3", 28 | "colors": "^1.3.3", 29 | "commander": "~2.9.0", 30 | "console-polyfill": "^0.2.2", 31 | "copy-webpack-plugin": "^5.0.3", 32 | "core-js": "^3.0.1", 33 | "cross-spawn": "~4.0.0", 34 | "es3ify-loader": "^0.2.0", 35 | "es5-shim": "^4.5.8", 36 | "file-loader": "^0.9.0", 37 | "ghreleases": "^3.0.2", 38 | "git-rev": "~0.2.1", 39 | "github": "^0.1.14", 40 | "gulp": "~3.9.0", 41 | "gulp-autoprefixer": "^3.1.1", 42 | "gulp-babel": "~6.1.1", 43 | "gulp-concat": "~2.6.0", 44 | "gulp-conventional-changelog": "^1.1.6", 45 | "gulp-es3ify": "0.0.0", 46 | "gulp-eslint": "~2.0.0", 47 | "gulp-just-replace": "~1.0.2", 48 | "gulp-rename": "^1.4.0", 49 | "gulp-sass": "^4.0.2", 50 | "gulp-sourcemaps": "~1.6.0", 51 | "html-wiring": "~1.2.0", 52 | "inquirer": "~1.0.0", 53 | "istanbul-instrumenter-loader": "~0.2.0", 54 | "mkdirp": "^0.5.1", 55 | "open": "0.0.5", 56 | "parseurl": "~1.3.1", 57 | "promfig": "^0.1.2", 58 | "promise": "~7.1.1", 59 | "properties-parser": "^0.3.1", 60 | "send": "~0.13.2", 61 | "shelljs": "~0.7.0", 62 | "sorted-object": "^2.0.1", 63 | "svg2react-loader": "^1.0.3", 64 | "url-loader": "^0.5.7", 65 | "gulp-svg-symbols": "^3.2.3", 66 | "webpack": "~1.x", 67 | "webpack-dev-middleware": "~1.6.1" 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/global.js: -------------------------------------------------------------------------------- 1 | var propertiesParser = require('properties-parser') 2 | var file = require('html-wiring'); 3 | var path = require('path'); 4 | var Promise = require('promise'); 5 | var git = require('git-rev'); 6 | var colors = require("colors/safe"); 7 | var fs = require('fs'); 8 | var inquirer = require("inquirer"); 9 | const gh = require('ghreleases'); 10 | 11 | var filePath = process.env.HOME+"/.bee-tools"; 12 | 13 | var utils = { 14 | getGithubToken 15 | } 16 | 17 | //检测文件或者文件夹存在 nodeJS 18 | function fsExistsSync(path) { 19 | try{ 20 | fs.accessSync(path,fs.F_OK); 21 | }catch(e){ 22 | return false; 23 | } 24 | return true; 25 | } 26 | 27 | async function getRcFileDate(){ 28 | let data = null; 29 | if(await fsExistsSync(filePath)){ 30 | return propertiesParser.read(filePath); 31 | } 32 | return null; 33 | } 34 | 35 | function setRcFile(data){ 36 | let editor = propertiesParser.createEditor(); 37 | for (var item in data) { 38 | editor.set(item, data[item]); 39 | } 40 | fs.writeFileSync(filePath,editor.toString()); 41 | } 42 | 43 | async function getProPack(data){ 44 | let _package = await fs.readFileSync(path.join(process.cwd()+"/package.json"),'utf-8') 45 | if(!_package){ 46 | console.log(comp+" path is error ,please go to tinper-bee directory to execute this command !"); 47 | return null; 48 | } 49 | return JSON.parse(_package); 50 | } 51 | 52 | 53 | async function getGithubToken(){ 54 | let data = await getRcFileDate(),token = ""; 55 | if(!data || !data.token){ 56 | var getToken = require('./tokenIndex.js') 57 | getToken(['repo'], new Date().getTime(), 'http://noteurl.com/',async function(err, _data) { 58 | setRcFile(_data); 59 | await createRelease(_data); 60 | }); 61 | }else{ 62 | await createRelease(data); 63 | } 64 | } 65 | 66 | async function createRelease(auth){ 67 | let questions = { 68 | type: 'input', 69 | name: 'describe', 70 | message: 'Describe this release ' 71 | } 72 | let answers = await inquirer.prompt(questions); 73 | pack = await getProPack(); 74 | if(!pack){ 75 | console.log(" createRelease function get pack is not define null ! "); 76 | return; 77 | }; 78 | const data = { 79 | tag_name:(pack.name+"v"+pack.version), 80 | name: ("v"+pack.version), 81 | body: answers.describe 82 | } 83 | gh.create(auth,'tinper-acs', pack.name, data, (err, release) => { 84 | err?console.log(err):console.log(colors.info("\n \(^o^) create release is success !")); 85 | }) 86 | } 87 | 88 | 89 | module.exports = utils; -------------------------------------------------------------------------------- /templates/demo/index-demo-base.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import { Con, Row, Col } from 'bee-layout'; 4 | import { Panel } from 'bee-panel'; 5 | import Drawer from 'bee-drawer'; 6 | import Clipboard from 'bee-clipboard'; 7 | 8 | 9 | 10 | {demolist} 11 | 12 | class Demo extends Component { 13 | constructor(props){ 14 | super(props); 15 | this.state = { 16 | open: false 17 | } 18 | } 19 | handleClick=()=> { 20 | this.setState({ open: !this.state.open }) 21 | } 22 | fCloseDrawer=()=>{ 23 | this.setState({ 24 | open: false 25 | }) 26 | } 27 | 28 | render () { 29 | const { title, example, code, desc, scss_code } = this.props; 30 | 31 | const header = ( 32 |
33 |

{ title }

34 |

{ desc }

35 | 查看源码 36 |
37 | ); 38 | return ( 39 | 40 | 41 | {example} 42 | 43 | 44 | 45 |
JS代码 46 | 47 |
48 |
49 |                 { code }
50 |             
51 | {!!scss_code ?
SCSS代码 52 | 53 |
:null } 54 | { !!scss_code ?
55 |                  { scss_code }
56 |                  
: null } 57 |
58 | 59 | ) 60 | } 61 | } 62 | 63 | class DemoGroup extends Component { 64 | constructor(props){ 65 | super(props) 66 | } 67 | render () { 68 | return ( 69 | 70 | {DemoArray.map((child,index) => { 71 | 72 | return ( 73 | 74 | ) 75 | 76 | })} 77 | 78 | ) 79 | } 80 | } 81 | 82 | ReactDOM.render(, document.getElementById('tinperBeeDemo')); 83 | -------------------------------------------------------------------------------- /src/webpack.dev.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var webpack = require('webpack'); 3 | var path = require('path'); 4 | 5 | var node_modules_whitelist = [ // 需要webpack解析的库 6 | path.join(process.cwd(), './node_modules/lodash-es'), 7 | path.join(process.cwd(), './node_modules/@tinper/next-ui') 8 | ] 9 | 10 | function getLoaderExclude(path) { 11 | if (!!path.match("@tinper/next-ui") || !!path.match(/lodash-es/)) { 12 | return false 13 | } 14 | var isNpmModule = !!path.match(/node_modules/); 15 | return isNpmModule; 16 | } 17 | 18 | module.exports = { 19 | cache: true, 20 | entry: { 21 | demo: './demo/index' 22 | }, 23 | output: { 24 | path: path.join(process.cwd(), './dist'), 25 | filename: "[name].js", 26 | sourceMapFilename: "[name].js.map" 27 | }, 28 | module: { 29 | loaders: [ 30 | { 31 | 32 | test: /\.js(x)*$/, 33 | // npm modules 都不需要经过babel解析 34 | exclude: getLoaderExclude, 35 | include: [path.join(process.cwd(), './src'), path.join(process.cwd(), './demo'), path.join(process.cwd(), './test'), ...node_modules_whitelist], 36 | loader: 'babel-loader', 37 | query: { 38 | presets: ['react', 'es2015-ie', 'stage-1'].map(function(item) { 39 | return require.resolve('babel-preset-' + item); 40 | }), 41 | plugins: [ 42 | 'transform-es3-member-expression-literals', 43 | 'transform-es3-property-literals', 44 | 'transform-object-assign', 45 | 'transform-object-entries', 46 | 'add-module-exports', 47 | 'transform-object-rest-spread' 48 | ].map(function(item) { 49 | return require.resolve('babel-plugin-' + item); 50 | }), 51 | cacheDirectory: true 52 | } 53 | } 54 | 55 | ] 56 | }, 57 | resolve: { 58 | root: [ 59 | path.join(process.cwd(), './node_modules') 60 | ], 61 | extensions: ['', '.js', '.jsx'], 62 | }, 63 | resolveLoader: { 64 | root: [ 65 | path.join(__dirname, '../node_modules') 66 | ] 67 | }, 68 | externals: { 69 | react: 'var React', // 相当于把全局的React作为模块的返回 module.exports = React; 70 | 'react-dom': 'var ReactDOM', 71 | 'prop-types': 'PropTypes' 72 | }, 73 | devtool: 'source-map', 74 | plugins: [ 75 | // SourceMap plugin will define process.env.NODE_ENV as development 76 | // new webpack.SourceMapDevToolPlugin({ 77 | // columns: false 78 | // }) 79 | ] 80 | }; 81 | -------------------------------------------------------------------------------- /src/test/Demo1.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @title 列过滤面板 4 | * @parent 列操作-隐藏 Hide 5 | * @description 点击表头右侧按钮,设置显示或隐藏表格列。可以自定义设置显示某列,通过ifshow属性控制,默认值为true(显示表格所有列)。afterFilter方法为列过滤后触发的回调函数。 6 | * demo0802 7 | */ 8 | 9 | 10 | import React, { Component } from 'react'; 11 | import {Icon,Popover} from "tinper-bee"; 12 | import Table from '../../src'; 13 | import filterColumn from '../../src/lib/filterColumn'; 14 | import sum from '../../src/lib/sum'; 15 | 16 | const data = [ 17 | { 18 | orderCode:"NU0391025", 19 | supplierName: "xx供应商", 20 | type_name: "1", 21 | purchasing:'组织c', 22 | purchasingGroup:"aa", 23 | voucherDate:"2018年03月18日", 24 | approvalState_name:"已审批", 25 | confirmState_name:"执行中", 26 | closeState_name:"未关闭", 27 | key: "1" 28 | }, 29 | { 30 | orderCode:"NU0391026", 31 | supplierName: "xx供应商", 32 | type_name: "2", 33 | purchasing:'组织a', 34 | purchasingGroup:"bb", 35 | voucherDate:"2018年02月05日", 36 | approvalState_name:"已审批", 37 | confirmState_name:"待确认", 38 | closeState_name:"未关闭", 39 | key: "2" 40 | }, 41 | { 42 | orderCode:"NU0391027", 43 | supplierName: "xx供应商", 44 | type_name: "3", 45 | purchasing:'组织b', 46 | purchasingGroup:"aa", 47 | voucherDate:"2018年07月01日", 48 | approvalState_name:"已审批", 49 | confirmState_name:"终止", 50 | closeState_name:"已关闭", 51 | key: "3" 52 | } 53 | ]; 54 | 55 | const FilterColumnTable = filterColumn(Table, Popover, Icon); 56 | 57 | const defaultProps21 = { 58 | prefixCls: "bee-table" 59 | }; 60 | 61 | class Demo21 extends Component { 62 | constructor(props) { 63 | super(props); 64 | this.state ={ 65 | columns: [ 66 | { 67 | title: "序号", 68 | dataIndex: "index", 69 | key: "index", 70 | width: 80, 71 | fixed: 'left', 72 | render(text, record, index){return index + 1} 73 | }, 74 | { 75 | title: "订单编号", 76 | dataIndex: "orderCode", 77 | key: "orderCode", 78 | width: 100, 79 | fixed: 'left', 80 | }, 81 | { 82 | title: "供应商名称", 83 | dataIndex: "supplierName", 84 | key: "supplierName", 85 | width: 150 86 | }, 87 | { 88 | title: "类型", 89 | dataIndex: "type_name", 90 | key: "type_name", 91 | width: 100 92 | }, 93 | { 94 | title: "采购组织", 95 | dataIndex: "purchasing", 96 | key: "purchasing", 97 | width: 100 98 | }, 99 | ]}; 100 | } 101 | afterFilter = (optData,columns)=>{ 102 | if(optData.key == 'b'){ 103 | if(optData.ifshow){ 104 | columns[2].ifshow = false; 105 | }else{ 106 | columns[2].ifshow = true; 107 | } 108 | this.setState({ 109 | columns21 :columns, 110 | showFilterPopover:true 111 | }); 112 | } 113 | 114 | } 115 | 116 | render() { 117 | return ; 123 | } 124 | } 125 | 126 | Demo21.defaultProps = defaultProps21; 127 | export default Demo21; -------------------------------------------------------------------------------- /src/test/test1.js: -------------------------------------------------------------------------------- 1 | //bee-xx 从tinper-bee中引入 2 | //bee-xx-xx 从tinper-bee中引入 3 | // 特殊的几个单独引入 4 | // 其它的 ../../src 改为 组件名称 5 | 6 | 7 | var fs = require("fs"); 8 | 9 | var data = fs.readFileSync('./Demo1.js', "utf-8"); 10 | 11 | 12 | //单独引入的组件 13 | var externals = ['bee-datepicker','bee-timepicker','bee-dnd','bee-calendar','bee-carousel','bee-viewer'] 14 | 15 | var replaceBees=[] 16 | 17 | var name = 'zzz'; 18 | var beeAry=[];//所有 bee 组件 19 | //匹配当前组件名称 20 | var thisBee = /import +([a-zA-Z_]+) +from +["']\.\.\/([a-z0-9A-Z-\.]+\/)+([a-z0-9A-Z-\._]+)["'] ?;?/g; 21 | //匹配使用到的bee组件 22 | var bee_reg = /import +{?([a-zA-Z_\, ]+)}? +from +["']bee-[a-zA-Z-]+["'] ?;?[\r\n]?/g; 23 | var bee_reg1 = /import +{?([a-zA-Z_\, ]+)}? +from +["']bee-[a-zA-Z-]+["'] ?;?[\r\n]?/; 24 | //匹配react 25 | var react_reg = /import[a-zA-Z_\, ]+{?([a-zA-Z_\, ]+)}? +from +["']react([a-zA-Z_\, ]?)+["'] ?;?/g; 26 | 27 | //匹配src 28 | var src_reg = /import +{?([a-zA-Z_\, ]+)}? +from +["']..\/..\/src["'] ?;?/; 29 | //匹配src/lib 30 | // var src_reg_lib = /..\/..\/src\/lib/g; 31 | 32 | //匹配 src/ 33 | var src_reg_ = /..\/..\/src\//g; 34 | 35 | //匹配 from tinper-bee 36 | var tinperBeeReg = /import +{?([a-zA-Z_\, ]+)}? +from +["']tinper-bee["'] ?;?/; 37 | 38 | 39 | //匹配到 from 'bee-xxx',放到 beeAry数组中,已排除externals内组件 40 | var component_arr = data.match(bee_reg); 41 | if (component_arr && component_arr.length > 0) { 42 | for (var j = component_arr.length - 1; j >= 0; j--) { 43 | var externalFlag = true; 44 | var matchs = component_arr[j].match(bee_reg1); 45 | for(var l = 0;l0){ 74 | for(var i = 0; i0){ 93 | return match+"\nimport { " + beeAry.join(", ") + " } from 'tinper-bee';" 94 | }else{ 95 | return match; 96 | } 97 | }); 98 | 99 | var srcMatch = data.match(src_reg); 100 | if(srcMatch){ 101 | data = data.replace(srcMatch[0],'') 102 | } 103 | 104 | 105 | 106 | // var srcLibMatch = data.match(src_reg_lib); 107 | // if(srcLibMatch){ 108 | // data = data.replace(src_reg_lib,`${name}/build/lib`) 109 | // } 110 | 111 | 112 | var src_reg_Match = data.match(src_reg_); 113 | if(src_reg_Match){ 114 | data = data.replace(src_reg_,`${name}/build/`) 115 | } 116 | 117 | 118 | console.log(data); 119 | 120 | -------------------------------------------------------------------------------- /templates/demo/atom-one-dark.css: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Atom One Dark by Daniel Gamage 4 | Original One Dark Syntax theme from https://github.com/atom/one-dark-syntax 5 | 6 | base: #282c34 7 | mono-1: #abb2bf 8 | mono-2: #818896 9 | mono-3: #5c6370 10 | hue-1: #56b6c2 11 | hue-2: #61aeee 12 | hue-3: #c678dd 13 | hue-4: #98c379 14 | hue-5: #e06c75 15 | hue-5-2: #be5046 16 | hue-6: #d19a66 17 | hue-6-2: #e6c07b 18 | 19 | */ 20 | 21 | .hljs { 22 | display: block; 23 | overflow-x: auto; 24 | padding: 0.5em; 25 | color: #424242; 26 | background: #FAFAFA; 27 | } 28 | 29 | .hljs-comment, 30 | .hljs-quote { 31 | color: #424242; 32 | font-style: italic; 33 | } 34 | 35 | .hljs-doctag, 36 | .hljs-keyword, 37 | .hljs-formula { 38 | color: #c678dd; 39 | } 40 | 41 | .hljs-section, 42 | .hljs-name, 43 | .hljs-selector-tag, 44 | .hljs-deletion, 45 | .hljs-subst { 46 | color: #e06c75; 47 | } 48 | 49 | .hljs-literal { 50 | color: #56b6c2; 51 | } 52 | 53 | .hljs-string, 54 | .hljs-regexp, 55 | .hljs-addition, 56 | .hljs-attribute, 57 | .hljs-meta-string { 58 | color: #98c379; 59 | } 60 | 61 | .hljs-built_in, 62 | .hljs-class .hljs-title { 63 | color: #e6c07b; 64 | } 65 | 66 | .hljs-attr, 67 | .hljs-variable, 68 | .hljs-template-variable, 69 | .hljs-type, 70 | .hljs-selector-class, 71 | .hljs-selector-attr, 72 | .hljs-selector-pseudo, 73 | .hljs-number { 74 | color: #d19a66; 75 | } 76 | 77 | .hljs-symbol, 78 | .hljs-bullet, 79 | .hljs-link, 80 | .hljs-meta, 81 | .hljs-selector-id, 82 | .hljs-title { 83 | color: #61aeee; 84 | } 85 | 86 | .hljs-emphasis { 87 | font-style: italic; 88 | } 89 | 90 | .hljs-strong { 91 | font-weight: bold; 92 | } 93 | 94 | .hljs-link { 95 | text-decoration: underline; 96 | } 97 | 98 | .component-demo .u-panel { 99 | padding: 18px 20px; 100 | border: 1px solid #F0F0F0; 101 | } 102 | .component-demo .u-panel-default .u-panel-heading{ 103 | background-color: #fff; 104 | padding: 0; 105 | position: relative; 106 | margin-bottom: 20px; 107 | } 108 | .component-demo p{ 109 | margin: 0; 110 | font-size: 14px; 111 | } 112 | 113 | .component-demo .component-title{ 114 | font-size: 14px; 115 | font-weight: bold; 116 | } 117 | 118 | .component-demo .component-code{ 119 | position: absolute; 120 | right: 0; 121 | top: 0; 122 | color: #E14C46; 123 | font-size: 14px; 124 | cursor: pointer; 125 | } 126 | .component-demo .u-panel .u-panel-body{ 127 | padding: 0; 128 | } 129 | 130 | .component-drawerc .pre-js,.component-drawerc .pre-css{ 131 | margin: 0; 132 | } 133 | 134 | 135 | .component-drawerc .drawer-body { 136 | padding: 20px 20px; 137 | } 138 | .component-drawerc .component-code-copy { 139 | font-size: 14px; 140 | font-weight: 800; 141 | color: #424242; 142 | padding: 10px 0; 143 | position: relative; 144 | } 145 | .component-drawerc .component-code-copy .uf-copy::before{ 146 | content: "\e6fc"; 147 | } 148 | .component-drawerc .component-code-copy .uf{ 149 | font-weight: 100; 150 | } 151 | .component-drawerc .component-code-copy.copy-css{ 152 | margin-top: 20px; 153 | } 154 | 155 | .component-drawerc .component-code-copy .u-clipboard{ 156 | position: absolute; 157 | right: 0; 158 | } 159 | /* 抽屉组件样式覆盖 */ 160 | .component-drawerc{ 161 | position: fixed; 162 | top: 0; 163 | left: 0; 164 | z-index: 100000; 165 | width: 0; 166 | height: 100%; 167 | } 168 | .component-drawerc .drawer-mask{ 169 | background-color: rgba(0,0,0,.3); 170 | width: 100%; 171 | height: 100%; 172 | position: fixed; 173 | top: 0; 174 | left: 0; 175 | transition: transform 300ms ease-in-out, opacity 300ms ease-in-out; 176 | } 177 | .component-drawerc .drawer-close{ 178 | position: absolute; 179 | top: 10px; 180 | right: 10px; 181 | font-size: 20px; 182 | cursor: pointer; 183 | } 184 | .component-drawerc .drawer{ 185 | position: fixed; 186 | background-color: #fff; 187 | transition: transform 300ms ease-in-out; 188 | overflow: auto; 189 | } 190 | .component-drawerc .drawer-left{ 191 | top: 0; 192 | left: 0; 193 | height: 100%; 194 | } 195 | .component-drawerc .drawer-right{ 196 | top: 0; 197 | right: 0; 198 | height: 100%; 199 | } 200 | .component-drawerc .drawer-top{ 201 | top: 0; 202 | left: 0; 203 | width: 100%; 204 | } 205 | .component-drawerc .drawer-bottom{ 206 | bottom: 0; 207 | left: 0; 208 | width: 100%; 209 | } 210 | .component-drawerc .drawer-header{ 211 | padding: 0 20px; 212 | border-radius: 0; 213 | background: #E14C46; 214 | color: #fff; 215 | border-bottom: 1px solid #e8e8e8; 216 | } 217 | .component-drawerc .drawer-header-title{ 218 | margin: 0; 219 | color: #fff; 220 | height: 40px; 221 | line-height: 40px; 222 | } -------------------------------------------------------------------------------- /src/test/test.js: -------------------------------------------------------------------------------- 1 | //bee-xx 从tinper-bee中引入 2 | //bee-xx-xx 从tinper-bee中引入 3 | // 特殊的几个单独引入 4 | // 其它的 ../../src 改为 组件名称 5 | 6 | 7 | var fs = require("fs"); 8 | 9 | var data = fs.readFileSync('./Demo1.js', "utf-8"); 10 | 11 | 12 | var libBee = ['Datepicker','Timepicker','Dnd','Calendar','Carousel','Viewer'] 13 | 14 | 15 | // data = data.replace(/export(\s+)(.*)/gi, ""); 16 | 17 | // console.log(data); 18 | 19 | // fs.writeFileSync('demo.js',data) 20 | 21 | var name = 'bee-colorpicker'; 22 | // var beeAry=[];//所有 bee 组件 23 | // var bee_reg = /import +{?([a-zA-Z_\, ]+)}? +from +["']bee-[a-zA-Z-]+["'] ?;?[\r\n]?/g; 24 | // var bee_reg1 = /import +{?([a-zA-Z_\, ]+)}? +from +["']bee-[a-zA-Z-]+["'] ?;?[\r\n]?/; 25 | 26 | // var component_arr = data.match(bee_reg);//匹配到 from 'bee-xxx' 27 | 28 | // if (component_arr && component_arr.length > 0) { 29 | // for (var j = component_arr.length - 1; j >= 0; j--) { 30 | // // console.log(component_arr[j].match(bee_reg1)[1]) 31 | // beeAry.push(component_arr[j].match(bee_reg1)[1]); 32 | // } 33 | // } 34 | 35 | 36 | // console.log(data.match(bee_reg)) 37 | 38 | //替换 39 | var react_reg = /import[a-zA-Z_\, ]+{?([a-zA-Z_\, ]+)}? +from +["']react([a-zA-Z_\, ]?)+["'] ?;?/g; 40 | var src_reg = /import +{?([bd-zBD-Z_\, ]+)}? +from +["']..\/..\/src["'] ?;?/g; 41 | var src_reg1 = /import +{?([a-zA-Z_\, ]+)}? +from +["']..\/..\/src["'] ?;?/; 42 | var extra_src_reg = /import +{?([a-zA-Z_\, ]+)}? +from +["']..\/..\/src\/index(\.js)?["'] ?;?/g; 43 | var lib_reg = /import +([a-zA-Z_]+) +from +["']\.\.\/([a-z0-9A-Z-\.]+\/)+([a-z0-9A-Z-\._]+)["'] ?;?/g; 44 | var component_reg = /import +{?([a-zA-Z_\, ]+)}? +from +["']bee-[a-zA-Z-]+["'] ?;?[\r\n]?/g; 45 | var component_reg1 = /import +{?([a-zA-Z_\, ]+)}? +from +["']bee-[a-zA-Z-]+["'] ?;?[\r\n]?/; 46 | var data_array = data.match(src_reg), 47 | component_arr = data.match(component_reg), 48 | extra_src_arr = data.match(extra_src_reg), 49 | all_arr = []; 50 | if (data_array && data_array.length > 0) {console.log('1') 51 | for (var i = data_array.length - 1; i >= 0; i--) { 52 | all_arr.push(data_array[i].match(src_reg1)[1]); 53 | } 54 | } 55 | if (component_arr && component_arr.length > 0) {console.log('2') 56 | for (var j = component_arr.length - 1; j >= 0; j--) { 57 | var component = component_arr[j].match(component_reg1)[1]; 58 | if(libBee.indexOf(component)==-1)all_arr.push(component_arr[j].match(component_reg1)[1]); 59 | } 60 | } 61 | //将组件放到tinper-bee组件数组里 62 | console.log(lib_reg.exec(data)) 63 | var thisCom = lib_reg.exec(data)&&lib_reg.exec(data)[1]; 64 | console.log(thisCom) 65 | if(thisCom){ 66 | all_arr.push(thisCom) 67 | } 68 | 69 | data = data.replace(component_reg, ""); 70 | if(extra_src_arr && extra_src_arr.length > 0){console.log(3) 71 | data = data.replace( 72 | extra_src_reg, 73 | function(match, p1, p2, p3, offset, string) { 74 | //对DatePicker和Timepicker处理成首字母大写 75 | var p1_ = p1; 76 | if(p1_ === 'DatePicker' || p1_ === 'Timepicker'){ 77 | p1_ = p1_.toLowerCase().replace(/( |^)[a-z]/g, (L) => L.toUpperCase()); 78 | } 79 | if(all_arr && all_arr.length>0){console.log('4') 80 | return "import " + p1 + ' from "tinper-bee/lib/' + p1_ + '";'+"\nimport { " + all_arr.join(", ") + " } from 'tinper-bee';" 81 | }else{console.log('5') 82 | if(name.toUpperCase().search("AC") != -1 || name.toUpperCase().search("REF") != -1){ 83 | return "import " + p1 + ' from "' + name + '";' 84 | }else{ 85 | return "import " + p1 + ' from "tinper-bee/lib/' + p1_ + '";' 86 | } 87 | } 88 | } 89 | ); 90 | }else if(data_array && data_array.length > 0){console.log('6') 91 | if(name.toUpperCase().search("AC") != -1 || name.toUpperCase().search("REF") != -1){ 92 | data = data.replace( 93 | src_reg, 94 | "import " + all_arr.join(", ") + " from '"+name+"';"); 95 | }else{ 96 | data = data.replace( 97 | src_reg, 98 | "import { " + all_arr.join(", ") + " } from 'tinper-bee';"); 99 | } 100 | }else{ 101 | console.log('7') 102 | data = data.replace( 103 | react_reg, 104 | function(match, p1, p2, p3, offset, string) { 105 | if(all_arr.length>0){ 106 | return match+"\nimport { " + all_arr.join(", ") + " } from 'tinper-bee';" 107 | } 108 | }); 109 | } 110 | 111 | data = data.replace( 112 | lib_reg, 113 | function(match, p1, p2, p3, offset, string) { 114 | console.log('8') 115 | console.log(match,p1,p3) 116 | //对DatePicker和Timepicker处理成首字母大写 117 | var p1_ = p3; 118 | if(p1_ === 'DatePicker' || p1_ === 'Timepicker'){console.log('9') 119 | p1_ = p1_.toLowerCase().replace(/( |^)[a-z]/g, (L) => L.toUpperCase()); 120 | } 121 | if(name.toUpperCase().search("AC") != -1 || name.toUpperCase().search("REF") != -1){ 122 | return "import " + p1 + ' from "' + name + '"'; 123 | }else{console.log('10') 124 | return '' 125 | } 126 | } 127 | ); 128 | 129 | 130 | console.log(data); 131 | 132 | fs.writeFileSync('demo.js',data) -------------------------------------------------------------------------------- /src/util.js: -------------------------------------------------------------------------------- 1 | var file = require('html-wiring'); 2 | var path = require('path'); 3 | var Promise = require('promise'); 4 | var git = require('git-rev'); 5 | var fs = require('fs'); 6 | // var pkg = getPackage(); 7 | var pkg = JSON.parse(file.readFileAsString('package.json')); 8 | 9 | async function getPackage() { 10 | if(fsExistsSync("package.json")){ 11 | let _pack = JSON.parse(await fs.readFileSync(path.join("package.json"),'utf-8')); 12 | return _pack; 13 | } 14 | return ""; 15 | } 16 | 17 | //检测文件或者文件夹存在 nodeJS 18 | function fsExistsSync(path) { 19 | try{ 20 | fs.accessSync(path,fs.F_OK); 21 | }catch(e){ 22 | return false; 23 | } 24 | return true; 25 | } 26 | 27 | // if(file.readFileAsString('package.json')){ 28 | // pkg = JSON.parse(file.readFileAsString('package.json')); 29 | // } 30 | // // var pkg = JSON.parse(file.readFileAsString('package.json')); 31 | 32 | var utils = { 33 | versionCompare: function(a, b) { 34 | var aArr = a.split('.'); 35 | var bArr = b.split('.'); 36 | var larger = false; 37 | for (var i = 0; i < 3; i++) { 38 | if (parseInt(aArr[i]) === parseInt(bArr[i])) { 39 | 40 | } 41 | else { 42 | larger = parseInt(aArr[i]) > parseInt(bArr[i]); 43 | break; 44 | } 45 | } 46 | return larger; 47 | }, 48 | runCmd: function(cmd, args, fn) { 49 | args = args || []; 50 | var runner = require('child_process').spawn(cmd, args, { 51 | // keep color 52 | stdio: 'inherit', 53 | }); 54 | runner.on('close', (code) => { 55 | if (fn) { 56 | fn(code); 57 | } 58 | }); 59 | }, 60 | getFromCwd: function() { 61 | var args = [].slice.call(arguments, 0); 62 | args.unshift(process.cwd()); 63 | return path.join.apply(path, args); 64 | }, 65 | getPkg: function() { 66 | return JSON.parse(file.readFileAsString('package.json'));; 67 | }, 68 | getPackages: function() { 69 | if(!pkg){ 70 | pkg = this.getPkg(); 71 | } 72 | var commands = []; 73 | for (var item in pkg.devDependencies) { 74 | if (item !== 'bee-tools') { 75 | commands.push(item + '@' + pkg.devDependencies[item]); 76 | } 77 | } 78 | commands.push('--production'); 79 | return commands; 80 | }, 81 | getQuestions:async function() { 82 | if(!pkg){ 83 | pkg = getPkg(); 84 | } 85 | var me = this; 86 | return new Promise(function(resolve, reject) { 87 | git.branch(function(branch) { 88 | var defaultBranch = branch; 89 | var defaultNpm = /@ali/.test(pkg.name) ? 'tnpm' : 'npm'; 90 | var questions = [ 91 | { 92 | type: 'input', 93 | name: 'version', 94 | message: 'please enter the package version to publish (should be xx.xx.xx)', 95 | default: pkg.version, 96 | validate: function(input) { 97 | if (/\d+\.\d+\.\d+/.test(input)) { 98 | if (me.versionCompare(input, pkg.version)) { 99 | return true; 100 | } 101 | else { 102 | return "the version you entered should be larger than now" 103 | } 104 | } 105 | else { 106 | return "the version you entered is not valid" 107 | } 108 | } 109 | }, 110 | { 111 | type: 'input', 112 | name: 'branch', 113 | message: 'which branch you want to push', 114 | default: defaultBranch 115 | }, 116 | { 117 | type: 'input', 118 | name: 'npm', 119 | message: 'which npm you want to publish', 120 | default: defaultNpm, 121 | validate: function(input) { 122 | if (/npm/.test(input)) { 123 | return true; 124 | } 125 | else { 126 | return "it seems not a valid npm" 127 | } 128 | } 129 | }, 130 | { 131 | type: 'input', 132 | name: 'checkChangelog', 133 | message: 'do you wang run changelog ?(y/n)', 134 | default: 'y' 135 | } 136 | ]; 137 | resolve(questions); 138 | }); 139 | }) 140 | } 141 | } 142 | 143 | module.exports = utils; 144 | -------------------------------------------------------------------------------- /src/create.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var fse = require('fs-extra'); 3 | var fs = require('fs'); 4 | //var moment = require('moment'); 5 | 6 | module.exports = function (name, options) { 7 | if(!/bee-/.test(name)){ 8 | name = "bee-"+name; 9 | } 10 | var author = options.author || 'Yonyou FED', 11 | pkgName = options.pkgName || name, 12 | version = options.tbVersion || '0.0.1', 13 | repoUrl = options.repoUrl || 'https://github.com/tinper-bee/' + name + '.git', 14 | port = options.port || 3000; 15 | 16 | 17 | 18 | 19 | if(!/bee-/.test(name)){ 20 | console.log('component name should be bee-componentName'); 21 | return; 22 | } 23 | 24 | //创建基本目录 25 | fse.mkdirsSync(path.resolve(name, 'src')); 26 | fse.mkdirsSync(path.resolve(name, 'demo')); 27 | fse.mkdirsSync(path.resolve(name, 'demo/demolist')); 28 | fse.mkdirsSync(path.resolve(name, 'test')); 29 | fse.mkdirsSync(path.resolve(name, 'docs')); 30 | var templateDir = path.resolve(__dirname, '../templates'); 31 | 32 | fse.copySync(templateDir, name); 33 | 34 | var appname = name.replace(/\s/g, '-').split("-").splice(1).join('-'); 35 | var AppName = appname.charAt(0).toUpperCase() + camelCase(appname.slice(1)); 36 | 37 | var srcComponentContent = [ 38 | "import React, { Component } from 'react';", 39 | "import PropTypes from 'prop-types';", 40 | "const propTypes = {};", 41 | "const defaultProps = {};", 42 | "class " + AppName + " extends Component {render(){return(

Welcome use tinper-bee

)}};", 43 | AppName + ".propTypes = propTypes;", 44 | AppName + ".defaultProps = defaultProps;", 45 | "export default " + AppName + ";" 46 | ].join('\n'); 47 | 48 | var srcIndexContent = [ 49 | "import " + AppName + " from './" + AppName + "';", 50 | "export default " + AppName + ";" 51 | ].join('\n'); 52 | 53 | var srcComponentScss = [ 54 | '@import "../node_modules/tinper-bee-core/scss/minxin-variables";', 55 | '@import "../node_modules/tinper-bee-core/scss/minxin-mixins";' 56 | ].join('\n'); 57 | 58 | var demoScss = [ 59 | // '@import "../node_modules/tinper-bee-core/scss/index.scss";', 60 | '@import "../src/' + AppName + '.scss";', 61 | // '@import "../node_modules/bee-panel/src/Panel.scss";', 62 | // '@import "../node_modules/bee-layout/src/Layout.scss";', 63 | // '@import "../node_modules/bee-button/src/Button.scss";', 64 | // '@import "../node_modules/bee-transition/src/Transition.scss";' 65 | ].join('\n'); 66 | 67 | var demojs = [ 68 | "import " + AppName + " from '../src/index';", 69 | "import React, { Component } from 'react';", 70 | "import ReactDOM from 'react-dom';", 71 | "class Demo extends Component {render(){return( <" + AppName + "/> )}}", 72 | "export default Demo;" 73 | ].join('\n'); 74 | 75 | var demoIndexJs = [ 76 | "import Demo from './" + AppName + "Demo';", 77 | "import ReactDOM from 'react-dom';", 78 | "ReactDOM.render(, document.getElementById('tinperBeeDemo'));" 79 | ].join('\n'); 80 | 81 | var testComponentjs = [ 82 | "import React from 'react';", 83 | "import {shallow, mount, render} from 'enzyme';", 84 | "import {expect} from 'chai';", 85 | "import " + AppName + " from '../src/index';" 86 | ].join('\n'); 87 | 88 | var docsContent = [ 89 | "# "+AppName, 90 | "\n\n ## 何时使用", 91 | "\n\n ## 如何使用", 92 | "\n\n ## 代码演示", 93 | "\n ## API", 94 | "\n |参数|说明|类型|默认值|", 95 | "|:---|:-----|:----|:------|", 96 | "\n\n ## 注意事项", 97 | "\n 暂无", 98 | "\n ## 更新日志", 99 | ].join('\n'); 100 | 101 | var docsContentEn = [ 102 | "# "+AppName, 103 | "\n\n ## When to use", 104 | "\n\n ## How to use", 105 | "\n\n ## Code display", 106 | "\n ## API", 107 | "\n |Property|Description|Type|Default|", 108 | "|:---|:-----|:----|:------|", 109 | "\n\n ## 注意事项", 110 | "\n 暂无", 111 | "\n ## 更新日志", 112 | ].join('\n'); 113 | 114 | var demo1 = [ 115 | "/**", 116 | "*", 117 | "* @title 这是标题", 118 | "* @description 这是描述", 119 | "*", 120 | "*/", 121 | "import React, { Component } from 'react';", 122 | "class Demo1 extends Component {", 123 | "render () {", 124 | "return (", 125 | "
", 126 | "欢迎使用老赵DEMO系统", 127 | "
", 128 | ")", 129 | "}", 130 | "}", 131 | "export default Demo1" 132 | ].join('\n'); 133 | 134 | var mapFileContent = [ 135 | { 136 | file: path.resolve(name, 'src', AppName + '.js'), 137 | content: srcComponentContent 138 | }, 139 | { 140 | file: path.resolve(name, 'src', 'index.js'), 141 | content: srcIndexContent 142 | }, 143 | { 144 | file: path.resolve(name, 'src', AppName + '.scss'), 145 | content: srcComponentScss 146 | }, 147 | { 148 | file: path.resolve(name, 'demo', AppName + 'Demo.scss'), 149 | content: demoScss 150 | }, 151 | { 152 | file: path.resolve(name, 'demo', AppName + 'Demo.js'), 153 | content: demojs 154 | }, 155 | //{ 156 | // file: path.resolve(name, 'demo', 'index.js'), 157 | // content: demoIndexJs 158 | //}, 159 | { 160 | file: path.resolve(name, 'test','index.test.js'), 161 | content: testComponentjs 162 | }, 163 | { 164 | file: path.resolve(name, 'docs','api.md'), 165 | content: docsContent 166 | }, 167 | { 168 | file: path.resolve(name, 'docs','api_en.md'), 169 | content: docsContentEn 170 | }, 171 | { 172 | file: path.resolve(name, 'demo','demolist','Demo1.js'), 173 | content: demo1 174 | } 175 | ] 176 | 177 | function writeFile(content, file){ 178 | fse.outputFile(file, content, function (err) { 179 | if(err) throw err; // => null 180 | 181 | }); 182 | } 183 | //写入文件 184 | for(var i = 0, len = mapFileContent.length; i < len; i ++){ 185 | var fileObject = mapFileContent[i]; 186 | writeFile(fileObject.content, fileObject.file); 187 | } 188 | 189 | 190 | 191 | fs.renameSync(path.resolve(name, 'gitignore'), path.resolve(name, '.gitignore')); 192 | fs.renameSync(path.resolve(name, 'npmignore'), path.resolve(name, '.npmignore')); 193 | 194 | 195 | function replaceVariate (file, changeArray) { 196 | fs.readFile(path.resolve(name, file),{encoding:'utf-8'}, function (err,bytesRead) { 197 | if (err) throw err; 198 | //var data=JSON.parse(bytesRead); 199 | //<%= packageName%> 200 | var content = bytesRead, 201 | changeMap, 202 | replaceRegexp; 203 | if(changeArray){ 204 | for(var i = 0, len = changeArray.length; i < len; i ++) { 205 | changeMap = changeArray[i]; 206 | replaceRegexp = new RegExp(changeMap.old, 'g'); 207 | content = content.replace(replaceRegexp, changeMap.new); 208 | } 209 | } 210 | 211 | fse.outputFile(path.resolve(name, file), content, function (err) { 212 | if(err) throw err; // => null 213 | 214 | }); 215 | 216 | }); 217 | } 218 | replaceVariate('README.md', [{ old: '<%= packageName%>', new: name}]); 219 | replaceVariate('README_EN.md', [{ old: '<%= packageName%>', new: name}]); 220 | replaceVariate('package.json', [ 221 | { old: '<%= packageName%>', new: name}, 222 | { old: '<%= version%>', new: version}, 223 | { old: '<%= port%>', new: port}, 224 | { old: '<%= appname%>', new: AppName}, 225 | { old: '<%= author%>', new: author}, 226 | { old: '<%= repo_url%>', new: repoUrl} 227 | ]); 228 | replaceVariate('./demo/index-demo-base.js', [{ old: '<%= appname%>', new: AppName}]); 229 | 230 | function camelCase(name) { 231 | return name.replace(/-\w/g, function (m) { 232 | return m.charAt(1).toUpperCase(); 233 | }) 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /src/create-acs.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var fse = require('fs-extra'); 3 | var fs = require('fs'); 4 | const spawn = require('cross-spawn'); 5 | var inquirer = require("inquirer"); 6 | const propertiesParser = require('properties-parser') 7 | 8 | module.exports = async function (name, options) { 9 | if(!/ac-/.test(name)){ 10 | name = "ac-"+name; 11 | } 12 | var author = options.author || 'Yonyou FED', 13 | pkgName = options.pkgName || name, 14 | version = options.tbVersion || '0.0.1', 15 | repoUrl = options.repoUrl || 'https://github.com/tinper-acs/' + name + '.git', 16 | port = options.port || 3000; 17 | 18 | if(!/ac-/.test(name)){ 19 | console.log('component name should be ac-componentName'); 20 | return; 21 | } 22 | //创建基本目录 23 | fse.mkdirsSync(path.resolve(name, 'src')); 24 | fse.mkdirsSync(path.resolve(name, 'demo')); 25 | fse.mkdirsSync(path.resolve(name, 'demo/demolist')); 26 | fse.mkdirsSync(path.resolve(name, 'test')); 27 | fse.mkdirsSync(path.resolve(name, 'docs')); 28 | var templateDir = path.resolve(__dirname, '../templates'); 29 | 30 | fse.copySync(templateDir, name); 31 | 32 | var appname = name.replace(/\s/g, '-').split("-").splice(1).join('-'); 33 | var AppName = appname.charAt(0).toUpperCase() + camelCase(appname.slice(1)); 34 | 35 | var srcComponentContent = [ 36 | "import React, { Component } from 'react';", 37 | "import PropTypes from 'prop-types';", 38 | "const propTypes = {};", 39 | "const defaultProps = {};", 40 | "class " + AppName + " extends Component {render(){return(

Welcome use tinper-acs

)}};", 41 | AppName + ".propTypes = propTypes;", 42 | AppName + ".defaultProps = defaultProps;", 43 | "export default " + AppName + ";" 44 | ].join('\n'); 45 | 46 | var srcIndexContent = [ 47 | "import " + AppName + " from './" + AppName + "';", 48 | "export default " + AppName + ";" 49 | ].join('\n'); 50 | 51 | var srcComponentScss = [ 52 | '@import "../node_modules/tinper-bee-core/scss/minxin-variables";', 53 | '@import "../node_modules/tinper-bee-core/scss/minxin-mixins";' 54 | ].join('\n'); 55 | 56 | var demoScss = [ 57 | '@import "../src/' + AppName + '.scss";', 58 | ].join('\n'); 59 | 60 | var demojs = [ 61 | "import " + AppName + " from '../src/index';", 62 | "import React, { Component } from 'react';", 63 | "import ReactDOM from 'react-dom';", 64 | "class Demo extends Component {render(){return( <" + AppName + "/> )}}", 65 | "export default Demo;" 66 | ].join('\n'); 67 | 68 | var demoIndexJs = [ 69 | "import Demo from './" + AppName + "Demo';", 70 | "import ReactDOM from 'react-dom';", 71 | "ReactDOM.render(, document.getElementById('tinperBeeDemo'));" 72 | ].join('\n'); 73 | 74 | var testComponentjs = [ 75 | "import React from 'react';", 76 | "import {shallow, mount, render} from 'enzyme';", 77 | "import {expect} from 'chai';", 78 | "import " + AppName + " from '../src/index';" 79 | ].join('\n'); 80 | 81 | var docsContent = [ 82 | "# "+AppName, 83 | "\n\n ## 何时使用", 84 | "\n\n ## 如何使用", 85 | "\n\n ## 代码演示", 86 | "\n ## API", 87 | "\n |参数|说明|类型|默认值|", 88 | "|:---|:-----|:----|:------|", 89 | "\n\n ## 注意事项", 90 | "\n 暂无", 91 | "\n ## 更新日志", 92 | ].join('\n'); 93 | 94 | var docsContentEn = [ 95 | "# "+AppName, 96 | "\n\n ## When to use", 97 | "\n\n ## How to use", 98 | "\n\n ## Code display", 99 | "\n ## API", 100 | "\n |Property|Description|Type|Default|", 101 | "|:---|:-----|:----|:------|", 102 | "\n\n ## 注意事项", 103 | "\n 暂无", 104 | "\n ## 更新日志", 105 | ].join('\n'); 106 | 107 | var demo1 = [ 108 | "/**", 109 | "*", 110 | "* @title 这是标题", 111 | "* @description 这是描述", 112 | "*", 113 | "*/", 114 | "import React, { Component } from 'react';", 115 | "class Demo1 extends Component {", 116 | "render () {", 117 | "return (", 118 | "
", 119 | "欢迎使用老赵DEMO系统", 120 | "
", 121 | ")", 122 | "}", 123 | "}", 124 | "export default Demo1" 125 | ].join('\n'); 126 | 127 | var mapFileContent = [ 128 | { 129 | file: path.resolve(name, 'src', AppName + '.js'), 130 | content: srcComponentContent 131 | }, 132 | { 133 | file: path.resolve(name, 'src', 'index.js'), 134 | content: srcIndexContent 135 | }, 136 | { 137 | file: path.resolve(name, 'src', AppName + '.scss'), 138 | content: srcComponentScss 139 | }, 140 | { 141 | file: path.resolve(name, 'demo', AppName + 'Demo.scss'), 142 | content: demoScss 143 | }, 144 | { 145 | file: path.resolve(name, 'demo', AppName + 'Demo.js'), 146 | content: demojs 147 | }, 148 | //{ 149 | // file: path.resolve(name, 'demo', 'index.js'), 150 | // content: demoIndexJs 151 | //}, 152 | { 153 | file: path.resolve(name, 'test','index.test.js'), 154 | content: testComponentjs 155 | }, 156 | { 157 | file: path.resolve(name, 'docs','api.md'), 158 | content: docsContent 159 | }, 160 | { 161 | file: path.resolve(name, 'docs','api_en.md'), 162 | content: docsContentEn 163 | }, 164 | { 165 | file: path.resolve(name, 'demo','demolist','Demo1.js'), 166 | content: demo1 167 | } 168 | ] 169 | 170 | function writeFile(content, file){ 171 | fse.outputFile(file, content, function (err) { 172 | if(err) throw err; // => null 173 | 174 | }); 175 | } 176 | //写入文件 177 | for(var i = 0, len = mapFileContent.length; i < len; i ++){ 178 | var fileObject = mapFileContent[i]; 179 | writeFile(fileObject.content, fileObject.file); 180 | } 181 | 182 | 183 | 184 | fs.renameSync(path.resolve(name, 'gitignore'), path.resolve(name, '.gitignore')); 185 | fs.renameSync(path.resolve(name, 'npmignore'), path.resolve(name, '.npmignore')); 186 | 187 | 188 | function replaceVariate (file, changeArray) { 189 | fs.readFile(path.resolve(name, file),{encoding:'utf-8'}, function (err,bytesRead) { 190 | if (err) throw err; 191 | //var data=JSON.parse(bytesRead); 192 | //<%= packageName%> 193 | var content = bytesRead, 194 | changeMap, 195 | replaceRegexp; 196 | if(changeArray){ 197 | for(var i = 0, len = changeArray.length; i < len; i ++) { 198 | changeMap = changeArray[i]; 199 | replaceRegexp = new RegExp(changeMap.old, 'g'); 200 | content = content.replace(replaceRegexp, changeMap.new); 201 | } 202 | } 203 | 204 | fse.outputFile(path.resolve(name, file), content, function (err) { 205 | if(err) throw err; // => null 206 | 207 | }); 208 | 209 | }); 210 | } 211 | replaceVariate('README.md', [{ old: '<%= packageName%>', new: name}]); 212 | replaceVariate('README_EN.md', [{ old: '<%= packageName%>', new: name}]); 213 | replaceVariate('package.json', [ 214 | { old: '<%= packageName%>', new: name}, 215 | { old: '<%= version%>', new: version}, 216 | { old: '<%= port%>', new: port}, 217 | { old: '<%= appname%>', new: AppName}, 218 | { old: '<%= author%>', new: author}, 219 | { old: '<%= repo_url%>', new: repoUrl} 220 | ]); 221 | replaceVariate('./demo/index-demo-base.js', [{ old: '<%= appname%>', new: AppName}]); 222 | queryInstall(name); 223 | function camelCase(name) { 224 | return name.replace(/-\w/g, function (m) { 225 | return m.charAt(1).toUpperCase(); 226 | }) 227 | } 228 | } 229 | 230 | 231 | function queryInstall(name) { 232 | let questions = { 233 | type: 'input', 234 | name: 'name', 235 | message: 'Automatically install YNPM dependent packages ?', 236 | default: function() { 237 | return 'y/n' 238 | } 239 | } 240 | inquirer.prompt(questions).then(function(answers) { 241 | if(answers.name.toLowerCase() === "y"){ 242 | let url = process.cwd()+"/"+name; 243 | process.chdir(url); 244 | install(); 245 | } 246 | }) 247 | } 248 | 249 | function install(){ 250 | console.log(`Install YNPM dependence packages,please wait.`); 251 | var args = ['install'].filter(function(e) { 252 | return e; 253 | }); 254 | var proc = spawn('ynpm', args, { 255 | stdio: 'inherit' 256 | }); 257 | proc.on('close', function(code) { 258 | if (code !== 0) { 259 | console.error('`ynpm ' + args.join(' ') + '` failed'); 260 | return; 261 | } 262 | console.log(`YNPM package installed `); 263 | }); 264 | } -------------------------------------------------------------------------------- /src/create-acs_bak.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var fse = require('fs-extra'); 3 | var fs = require('fs'); 4 | const spawn = require('cross-spawn'); 5 | var inquirer = require("inquirer"); 6 | const propertiesParser = require('properties-parser') 7 | 8 | module.exports = async function (name, options) { 9 | if(!/ac-/.test(name)){ 10 | name = "ac-"+name; 11 | } 12 | var author = options.author || 'Yonyou FED', 13 | pkgName = options.pkgName || name, 14 | version = options.tbVersion || '0.0.1', 15 | repoUrl = options.repoUrl || 'https://github.com/tinper-acs/' + name + '.git', 16 | port = options.port || 3000; 17 | 18 | if(!/ac-/.test(name)){ 19 | console.log('component name should be ac-componentName'); 20 | return; 21 | } 22 | //创建基本目录 23 | fse.mkdirsSync(path.resolve(name, 'src')); 24 | fse.mkdirsSync(path.resolve(name, 'demo')); 25 | fse.mkdirsSync(path.resolve(name, 'demo/demolist')); 26 | fse.mkdirsSync(path.resolve(name, 'test')); 27 | fse.mkdirsSync(path.resolve(name, 'docs')); 28 | var templateDir = path.resolve(__dirname, '../templates'); 29 | 30 | fse.copySync(templateDir, name); 31 | 32 | var appname = name.replace(/\s/g, '-').split("-").splice(1).join('-'); 33 | var AppName = appname.charAt(0).toUpperCase() + camelCase(appname.slice(1)); 34 | 35 | var srcComponentContent = [ 36 | "import React, { Component } from 'react';", 37 | "import PropTypes from 'prop-types';", 38 | "const propTypes = {};", 39 | "const defaultProps = {};", 40 | "class " + AppName + " extends Component {render(){return(

Welcome use tinper-acs

)}};", 41 | AppName + ".propTypes = propTypes;", 42 | AppName + ".defaultProps = defaultProps;", 43 | "export default " + AppName + ";" 44 | ].join('\n'); 45 | 46 | var srcIndexContent = [ 47 | "import " + AppName + " from './" + AppName + "';", 48 | "export default " + AppName + ";" 49 | ].join('\n'); 50 | 51 | var srcComponentScss = [ 52 | '@import "../node_modules/tinper-bee-core/scss/minxin-variables";', 53 | '@import "../node_modules/tinper-bee-core/scss/minxin-mixins";' 54 | ].join('\n'); 55 | 56 | var demoScss = [ 57 | '@import "../src/' + AppName + '.less";', 58 | ].join('\n'); 59 | 60 | var demojs = [ 61 | "import " + AppName + " from '../src/index';", 62 | "import React, { Component } from 'react';", 63 | "import ReactDOM from 'react-dom';", 64 | "class Demo extends Component {render(){return( <" + AppName + "/> )}}", 65 | "export default Demo;" 66 | ].join('\n'); 67 | 68 | var demoIndexJs = [ 69 | "import Demo from './" + AppName + "Demo';", 70 | "import ReactDOM from 'react-dom';", 71 | "ReactDOM.render(, document.getElementById('tinperBeeDemo'));" 72 | ].join('\n'); 73 | 74 | var testComponentjs = [ 75 | "import React from 'react';", 76 | "import {shallow, mount, render} from 'enzyme';", 77 | "import {expect} from 'chai';", 78 | "import " + AppName + " from '../src/index';" 79 | ].join('\n'); 80 | 81 | var docsContent = [ 82 | "# "+AppName, 83 | "\n\n ## 何时使用", 84 | "\n\n ## 如何使用", 85 | "\n\n ## 代码演示", 86 | "\n ## API", 87 | "\n |参数|说明|类型|默认值|", 88 | "|:---|:-----|:----|:------|", 89 | "\n\n ## 注意事项", 90 | "\n 暂无", 91 | "\n ## 更新日志", 92 | ].join('\n'); 93 | 94 | var docsContentEn = [ 95 | "# "+AppName, 96 | "\n\n ## When to use", 97 | "\n\n ## How to use", 98 | "\n\n ## Code display", 99 | "\n ## API", 100 | "\n |Property|Description|Type|Default|", 101 | "|:---|:-----|:----|:------|", 102 | "\n\n ## 注意事项", 103 | "\n 暂无", 104 | "\n ## 更新日志", 105 | ].join('\n'); 106 | 107 | var demo1 = [ 108 | "/**", 109 | "*", 110 | "* @title 这是标题", 111 | "* @description 这是描述", 112 | "*", 113 | "*/", 114 | "import React, { Component } from 'react';", 115 | "class Demo1 extends Component {", 116 | "render () {", 117 | "return (", 118 | "
", 119 | "欢迎使用老赵DEMO系统", 120 | "
", 121 | ")", 122 | "}", 123 | "}", 124 | "export default Demo1" 125 | ].join('\n'); 126 | 127 | var mapFileContent = [ 128 | { 129 | file: path.resolve(name, 'src', AppName + '.js'), 130 | content: srcComponentContent 131 | }, 132 | { 133 | file: path.resolve(name, 'src', 'index.js'), 134 | content: srcIndexContent 135 | }, 136 | { 137 | file: path.resolve(name, 'src', AppName + '.less'), 138 | content: srcComponentScss 139 | }, 140 | { 141 | file: path.resolve(name, 'demo', AppName + 'Demo.less'), 142 | content: demoScss 143 | }, 144 | { 145 | file: path.resolve(name, 'demo', AppName + 'Demo.js'), 146 | content: demojs 147 | }, 148 | //{ 149 | // file: path.resolve(name, 'demo', 'index.js'), 150 | // content: demoIndexJs 151 | //}, 152 | { 153 | file: path.resolve(name, 'test','index.test.js'), 154 | content: testComponentjs 155 | }, 156 | { 157 | file: path.resolve(name, 'docs','api.md'), 158 | content: docsContent 159 | }, 160 | { 161 | file: path.resolve(name, 'docs','api_en.md'), 162 | content: docsContentEn 163 | }, 164 | { 165 | file: path.resolve(name, 'demo','demolist','Demo1.js'), 166 | content: demo1 167 | } 168 | ] 169 | 170 | function writeFile(content, file){ 171 | fse.outputFile(file, content, function (err) { 172 | if(err) throw err; // => null 173 | 174 | }); 175 | } 176 | //写入文件 177 | for(var i = 0, len = mapFileContent.length; i < len; i ++){ 178 | var fileObject = mapFileContent[i]; 179 | writeFile(fileObject.content, fileObject.file); 180 | } 181 | 182 | 183 | 184 | fs.renameSync(path.resolve(name, 'gitignore'), path.resolve(name, '.gitignore')); 185 | fs.renameSync(path.resolve(name, 'npmignore'), path.resolve(name, '.npmignore')); 186 | 187 | 188 | function replaceVariate (file, changeArray) { 189 | fs.readFile(path.resolve(name, file),{encoding:'utf-8'}, function (err,bytesRead) { 190 | if (err) throw err; 191 | //var data=JSON.parse(bytesRead); 192 | //<%= packageName%> 193 | var content = bytesRead, 194 | changeMap, 195 | replaceRegexp; 196 | if(changeArray){ 197 | for(var i = 0, len = changeArray.length; i < len; i ++) { 198 | changeMap = changeArray[i]; 199 | replaceRegexp = new RegExp(changeMap.old, 'g'); 200 | content = content.replace(replaceRegexp, changeMap.new); 201 | } 202 | } 203 | 204 | fse.outputFile(path.resolve(name, file), content, function (err) { 205 | if(err) throw err; // => null 206 | 207 | }); 208 | 209 | }); 210 | } 211 | replaceVariate('README.md', [{ old: '<%= packageName%>', new: name}]); 212 | replaceVariate('README_EN.md', [{ old: '<%= packageName%>', new: name}]); 213 | replaceVariate('package.json', [ 214 | { old: '<%= packageName%>', new: name}, 215 | { old: '<%= version%>', new: version}, 216 | { old: '<%= port%>', new: port}, 217 | { old: '<%= appname%>', new: AppName}, 218 | { old: '<%= author%>', new: author}, 219 | { old: '<%= repo_url%>', new: repoUrl} 220 | ]); 221 | replaceVariate('./demo/index-demo-base.js', [{ old: '<%= appname%>', new: AppName}]); 222 | queryInstall(name); 223 | function camelCase(name) { 224 | return name.replace(/-\w/g, function (m) { 225 | return m.charAt(1).toUpperCase(); 226 | }) 227 | } 228 | } 229 | 230 | 231 | function queryInstall(name) { 232 | let questions = { 233 | type: 'input', 234 | name: 'name', 235 | message: 'Automatically install YNPM dependent packages ?', 236 | default: function() { 237 | return 'y/n' 238 | } 239 | } 240 | inquirer.prompt(questions).then(function(answers) { 241 | if(answers.name.toLowerCase() === "y"){ 242 | let url = process.cwd()+"/"+name; 243 | process.chdir(url); 244 | install(); 245 | } 246 | }) 247 | } 248 | 249 | function install(){ 250 | console.log(`Install YNPM dependence packages,please wait.`); 251 | var args = ['install'].filter(function(e) { 252 | return e; 253 | }); 254 | var proc = spawn('ynpm', args, { 255 | stdio: 'inherit' 256 | }); 257 | proc.on('close', function(code) { 258 | if (code !== 0) { 259 | console.error('`ynpm ' + args.join(' ') + '` failed'); 260 | return; 261 | } 262 | console.log(`YNPM package installed `); 263 | }); 264 | } -------------------------------------------------------------------------------- /src/gulpfile.js: -------------------------------------------------------------------------------- 1 | // dependency 2 | var fs = require("fs"); 3 | var inquirer = require("inquirer"); 4 | var spawn = require("cross-spawn"); 5 | var file = require("html-wiring"); 6 | var colors = require("colors/safe"); 7 | var util = require("./util"); 8 | var path = require("path"); 9 | var global = require("./global"); 10 | 11 | var browserSync = require("browser-sync"); 12 | var reload = browserSync.reload; 13 | var shelljs = require("shelljs"); 14 | var svgSymbols = require('gulp-svg-symbols'); 15 | var rename = require("gulp-rename"); 16 | // gulp & gulp plugin 17 | var gulp = require("gulp"); 18 | var babel = require("gulp-babel"); 19 | var sass = require("gulp-sass"); 20 | // var csso = require('gulp-csso'); 21 | var sourcemaps = require("gulp-sourcemaps"); 22 | var autoprefix = require("gulp-autoprefixer"); 23 | var concat = require("gulp-concat"); 24 | var replace = require("gulp-just-replace"); 25 | var es3ify = require("gulp-es3ify"); 26 | var eslint = require("gulp-eslint"); 27 | var conven = require("gulp-conventional-changelog"); 28 | var fse = require("fs-extra"); 29 | 30 | colors.setTheme({ 31 | silly: 'rainbow', 32 | input: 'grey', 33 | verbose: 'cyan', 34 | prompt: 'grey', 35 | info: 'green', 36 | data: 'grey', 37 | help: 'cyan', 38 | warn: 'yellow', 39 | debug: 'blue', 40 | error: 'red' 41 | }); 42 | 43 | // webpack 44 | var webpack = require("webpack"); 45 | 46 | // 读取进程参数值 47 | function getArgsValue(argName){ 48 | // console.log("getArgsValue--->"+argName,process.argv) 49 | //限制只能支持以下参数 50 | if(!['--JS_SRC','--JS_BUILD','--CSS_SRC','--CSS_BUILD'].includes(argName))return ; 51 | var argIdx = process.argv.indexOf(argName); 52 | if(argIdx<=0)return; 53 | var argVal = process.argv.slice(argIdx+1,argIdx+2); 54 | // console.log("getArgsValue--->value:",argVal[0]); 55 | return argVal[0]; 56 | } 57 | 58 | colors.setTheme({ 59 | info: ["bold", "green"] 60 | }); 61 | 62 | gulp.task("changelogInit", function () { 63 | //设置镜像 64 | spawn.sync( 65 | "npm", 66 | ["--registry", "https://registry.npm.taobao.org", "install", "express"], { 67 | stdio: "inherit" 68 | } 69 | ); 70 | //init commitizen 71 | spawn.sync( 72 | "commitizen", 73 | ["init", "cz-conventional-changelog", "--save", "--save-exact", "--force"], { 74 | stdio: "inherit" 75 | } 76 | ); 77 | }); 78 | 79 | gulp.task("changelog", function () { 80 | console.log(colors.info("###### build changelog ######")); 81 | if (!fs.accessSync("CHANGELOG.md")) { 82 | fse.outputFileSync(path.join(process.cwd(), "./CHANGELOG.md"), ""); 83 | } 84 | gulp 85 | .src(path.join(process.cwd(), "./CHANGELOG.md")) 86 | .pipe( 87 | conven({ 88 | preset: "angular", 89 | releaseCount: 0, 90 | samefile: true 91 | }) 92 | ) 93 | .pipe(gulp.dest("./")); 94 | }); 95 | 96 | gulp.task("pack_demo", function (cb) { 97 | var p = path.join(process.cwd(), "./demo/demolist"); 98 | 99 | function explorer(paths) { 100 | var arr = [], 101 | scss_arr = [], 102 | code = []; 103 | fs.readdir(paths, function (err, files) { 104 | if (err) { 105 | console.log("error:\n" + err); 106 | return; 107 | } 108 | 109 | function sortNumber(a, b) { 110 | return a.replace(/[^0-9]/ig, "") - b.replace(/[^0-9]/ig, "") 111 | } 112 | 113 | 114 | files = files.sort(sortNumber); 115 | 116 | files.forEach(function (file) { 117 | if (file.search(/Demo\d+.js/) !== -1) { 118 | var fileName = file.replace(".js", ""); 119 | 120 | fs.stat(paths + "//" + file, function (err, stat) { 121 | //console.log(stat); 122 | if (err) { 123 | console.log(err); 124 | return; 125 | } 126 | if (stat.isDirectory()) { 127 | //console.log(paths + "\/" + file + "\/"); 128 | explorer(path + "/" + file); 129 | } else { 130 | // console.log(paths + "\/" + file); 131 | } 132 | }); 133 | var data = fs.readFileSync(paths + "//" + file, "utf-8"); 134 | var title, desc; 135 | try { 136 | title = data.match(/@title.{0,30}/) || []; 137 | title = title.join("").replace(/@title/, ""); 138 | } catch (e) { 139 | console.log("please write title like @title"); 140 | } 141 | 142 | try { 143 | desc = data.match(/@description.{0,150}/) || []; 144 | desc = desc.join("").replace(/@description/, ""); 145 | } catch (e) { 146 | console.log("please write description like @description"); 147 | } 148 | 149 | try { 150 | // data = data.replace(/export(\s+)(.*)/gi, ""); 151 | var package = fs.readFileSync( 152 | path.join(process.cwd(), "./package.json"), 153 | "utf-8" 154 | ); 155 | var name = JSON.parse(package).name; 156 | 157 | 158 | // //替换 159 | // var react_reg = /import[a-zA-Z_\, ]+{?([a-zA-Z_\, ]+)}? +from +["']react([a-zA-Z_\, ]?)+["'] ?;?/g; 160 | // var src_reg = /import +{?([bd-zBD-Z_\, ]+)}? +from +["']..\/..\/src["'] ?;?/g; 161 | // var src_reg1 = /import +{?([a-zA-Z_\, ]+)}? +from +["']..\/..\/src["'] ?;?/; 162 | // var extra_src_reg = /import +{?([a-zA-Z_\, ]+)}? +from +["']..\/..\/src\/index(\.js)?["'] ?;?/g; 163 | // var lib_reg = /import +([a-zA-Z_]+) +from +["']\.\.\/([a-z0-9A-Z-\.]+\/)+([a-z0-9A-Z-\._]+)["']/g; 164 | // var component_reg = /import +{?([a-zA-Z_\, ]+)}? +from +["']bee-[a-zA-Z-]+["'] ?;?[\r\n]?/g; 165 | // var component_reg1 = /import +{?([a-zA-Z_\, ]+)}? +from +["']bee-[a-zA-Z-]+["'] ?;?[\r\n]?/; 166 | // var data_array = data.match(src_reg), 167 | // component_arr = data.match(component_reg), 168 | // extra_src_arr = data.match(extra_src_reg), 169 | // all_arr = []; 170 | // if (data_array && data_array.length > 0) { 171 | // for (var i = data_array.length - 1; i >= 0; i--) { 172 | // all_arr.push(data_array[i].match(src_reg1)[1]); 173 | // } 174 | // } 175 | // if (component_arr && component_arr.length > 0) { 176 | // for (var j = component_arr.length - 1; j >= 0; j--) { 177 | // all_arr.push(component_arr[j].match(component_reg1)[1]); 178 | // } 179 | // } 180 | // data = data.replace(component_reg, ""); 181 | // if(extra_src_arr && extra_src_arr.length > 0){ 182 | // data = data.replace( 183 | // extra_src_reg, 184 | // function(match, p1, p2, p3, offset, string) { 185 | // //对DatePicker和Timepicker处理成首字母大写 186 | // var p1_ = p1; 187 | // if(p1_ === 'DatePicker' || p1_ === 'Timepicker'){ 188 | // p1_ = p1_.toLowerCase().replace(/( |^)[a-z]/g, (L) => L.toUpperCase()); 189 | // } 190 | // if(all_arr && all_arr.length>0){ 191 | // return "import " + p1 + ' from "tinper-bee/lib/' + p1_ + '";'+"\nimport { " + all_arr.join(", ") + " } from 'tinper-bee';" 192 | // }else{ 193 | // if(name.toUpperCase().search("AC") != -1 || name.toUpperCase().search("REF") != -1){ 194 | // return "import " + p1 + ' from "' + name + '";' 195 | // }else{ 196 | // return "import " + p1 + ' from "tinper-bee/lib/' + p1_ + '";' 197 | // } 198 | // } 199 | // } 200 | // ); 201 | // }else if(data_array && data_array.length > 0){ 202 | // if(name.toUpperCase().search("AC") != -1 || name.toUpperCase().search("REF") != -1){ 203 | // data = data.replace( 204 | // src_reg, 205 | // "import " + all_arr.join(", ") + " from '"+name+"';"); 206 | // }else{ 207 | // data = data.replace( 208 | // src_reg, 209 | // "import { " + all_arr.join(", ") + " } from 'tinper-bee';"); 210 | // } 211 | // }else{ 212 | // data = data.replace( 213 | // react_reg, 214 | // function(match, p1, p2, p3, offset, string) { 215 | // return match+"\nimport { " + all_arr.join(", ") + " } from 'tinper-bee';" 216 | // }); 217 | // } 218 | 219 | // data = data.replace( 220 | // lib_reg, 221 | // function(match, p1, p2, p3, offset, string) { 222 | // //对DatePicker和Timepicker处理成首字母大写 223 | // var p1_ = p3; 224 | // if(p1_ === 'DatePicker' || p1_ === 'Timepicker'){ 225 | // p1_ = p1_.toLowerCase().replace(/( |^)[a-z]/g, (L) => L.toUpperCase()); 226 | // } 227 | // if(name.toUpperCase().search("AC") != -1 || name.toUpperCase().search("REF") != -1){ 228 | // return "import " + p1 + ' from "' + name + '"'; 229 | // }else{ 230 | // return "import " + p1 + ' from "tinper-bee/lib/' + p1_ + '";'; 231 | // } 232 | // } 233 | // ); 234 | //单独引入的组件 235 | var externals = ['bee-datepicker', 'bee-timepicker', 'bee-dnd', 'bee-calendar', 'bee-carousel', 'bee-viewer','bee-complex-grid'] 236 | 237 | var replaceBees = [] 238 | 239 | var beeAry = []; //所有 bee 组件 240 | //匹配当前组件名称 241 | var thisBee = /import +([a-zA-Z_]+) +from +["']\.\.\/([a-z0-9A-Z-\.]+\/)+([a-z0-9A-Z-\._]+)["'] ?;?/g; 242 | //匹配使用到的bee组件 243 | var bee_reg = /import +{?([a-zA-Z_\, ]+)}? +from +["']bee-[a-zA-Z-]+["'] ?;?[\r\n]?/g; 244 | var bee_reg1 = /import +{?([a-zA-Z_\, ]+)}? +from +["']bee-[a-zA-Z-]+["'] ?;?[\r\n]?/; 245 | //匹配react 246 | var react_reg = /import[a-zA-Z_\, ]+{?([a-zA-Z_\, ]+)}? +from +["']react([a-zA-Z_\, ]?)+["'] ?;?/g; 247 | 248 | //匹配src 249 | var src_reg = /import +{?([a-zA-Z_\, ]+)}? +from +["']..\/..\/src["'] ?;?/; 250 | 251 | //匹配src/lib 252 | // var src_reg_lib = /..\/..\/src\/lib/g; 253 | 254 | //匹配 src/ 255 | var src_reg_ = /..\/..\/src\//g; 256 | 257 | //匹配 from tinper-bee 258 | var tinperBeeReg = /import +{?([a-zA-Z_\, ]+)}? +from +["']tinper-bee["'] ?;?/; 259 | 260 | 261 | //匹配到 from 'bee-xxx',放到 beeAry数组中,已排除externals内组件 262 | var component_arr = data.match(bee_reg); 263 | if (component_arr && component_arr.length > 0) { 264 | for (var j = component_arr.length - 1; j >= 0; j--) { 265 | var externalFlag = true; 266 | var matchs = component_arr[j].match(bee_reg1); 267 | for (var l = 0; l < externals.length; l++) { 268 | if (matchs[0].indexOf(externals[l]) != -1) { 269 | externalFlag = false; 270 | } 271 | } 272 | if (externalFlag) { 273 | var component = matchs[1]; 274 | beeAry.push(component); 275 | replaceBees.push(matchs[0]) 276 | } 277 | } 278 | } 279 | 280 | //将当前组件放到tinper-bee中引用 281 | var thisBeeExec = thisBee.exec(data) 282 | if (thisBeeExec) { 283 | var thisCom = thisBeeExec[1]; 284 | if (thisCom) { 285 | if ((externals.indexOf(name) == -1) && (name.split('-')[0] == 'bee')) { //判断是bee开头,而且不被排除的 286 | beeAry.push(thisCom) 287 | } else { //其它组件一律从 name 中引入,例如:ac-xxx,xxx 288 | data = data.replace('../../src', name) 289 | } 290 | } 291 | } 292 | 293 | 294 | //去掉 from bee-xxx 295 | if (replaceBees.length > 0) { 296 | for (var i = 0; i < replaceBees.length; i++) { 297 | var item = replaceBees[i]; 298 | data = data.replace(item, '') 299 | } 300 | } 301 | 302 | //如果有从 tinper-bee 引入的组件 303 | var formTinper = tinperBeeReg.exec(data); 304 | if (formTinper) { 305 | beeAry.push(formTinper[1]); 306 | data = data.replace(formTinper[0], '') 307 | } 308 | 309 | 310 | //bee-xxx合并到 tinper-bee里 311 | data = data.replace( 312 | react_reg, 313 | function (match, p1, p2, p3, offset, string) { 314 | if (beeAry.length > 0) { 315 | return match + "\nimport { " + beeAry.join(", ") + " } from 'tinper-bee';" 316 | } else { 317 | return match; 318 | } 319 | }); 320 | 321 | // 去掉 ../../src 322 | var srcMatch = data.match(src_reg); 323 | if (srcMatch) { 324 | data = data.replace(srcMatch[0], '') 325 | } 326 | 327 | // 去掉 ../../src/lib 替换为 组件名/build/lib 例如 bee-table 328 | // var srcLibMatch = data.match(src_reg_lib); 329 | // if(srcLibMatch){ 330 | // data = data.replace(src_reg_lib,`${name}/build/lib`) 331 | // } 332 | // 去掉 ../../src/ 例如 bee-datepicker : import zhCN from "../../src/locale/zh_CN"; 333 | var src_reg_Match = data.match(src_reg_); 334 | if(src_reg_Match){ 335 | data = data.replace(src_reg_,`${name}/build/`) 336 | } 337 | 338 | } catch (e) { 339 | console.log(e); 340 | } 341 | 342 | arr.push({ 343 | example: "<" + fileName + " />", 344 | title: title || fileName, 345 | code: data, 346 | desc: desc 347 | }); 348 | // code.push(data); 349 | code.push( 350 | "var " + fileName + ' = require("./demolist/' + fileName + '");' 351 | ); 352 | } else if (file.search(/Demo\d+.scss/) !== -1) { 353 | var fileName = file.replace(".scss", ""); 354 | 355 | fs.stat(paths + "//" + file, function (err, stat) { 356 | //console.log(stat); 357 | if (err) { 358 | console.log(err); 359 | return; 360 | } 361 | if (stat.isDirectory()) { 362 | //console.log(paths + "\/" + file + "\/"); 363 | explorer(path + "/" + file); 364 | } else { 365 | // console.log(paths + "\/" + file); 366 | } 367 | }); 368 | var data = fs.readFileSync(paths + "//" + file, "utf-8"); 369 | 370 | scss_arr.push({ 371 | example: "<" + fileName + " />", 372 | scss_code: data 373 | }); 374 | } 375 | }); 376 | for (var index = 0; index < scss_arr.length; index++) { 377 | var element = scss_arr[index]; 378 | for (var j = 0; j < arr.length; j++) { 379 | if (element.example === arr[j].example) { 380 | Object.assign(arr[j], element); 381 | } 382 | } 383 | } 384 | 385 | var index = fs.readFileSync( 386 | path.join(process.cwd(), "./demo/index-demo-base.js"), 387 | "utf-8" 388 | ); 389 | 390 | var str = "var DemoArray = " + JSON.stringify(arr) + "\n"; 391 | 392 | str = str.replace(/ple":" { 468 | // console.log("name--", name) 469 | return name; 470 | }, 471 | }) 472 | ) 473 | .pipe(rename((path) => { 474 | path.basename = 'loading'; 475 | }), (a, b) => { 476 | // console.log("a-", a); 477 | // console.log("b-", b) 478 | }) 479 | .pipe(gulp.dest('build/static/images/')); 480 | // .pipe(gulp.dest('build')); 481 | // .pipe(gulp.dest(function(file){return 'build/static/images/'+file.base+'.svg';})); 482 | }) 483 | 484 | gulp.task("sass_demo", function (cb) { 485 | gulp 486 | .src([path.join(process.cwd(), "./demo/**/*.scss")]) 487 | .pipe(sourcemaps.init()) 488 | .pipe(sass()) 489 | .pipe(concat("demo.css")) 490 | .pipe( 491 | autoprefix({ 492 | browsers: ["last 2 versions", "not ie < 8"], 493 | cascade: false 494 | }) 495 | ) 496 | .pipe( 497 | replace([{ 498 | search: /\/\*#\ssourceMappingURL=([^\*\/]+)\.map\s\*\//g, 499 | replacement: "/* end for `$1` */\n" 500 | }]) 501 | ) 502 | .pipe(sourcemaps.write(".")) 503 | .pipe(gulp.dest("./dist")) 504 | .on("end", function () { 505 | console.info(colors.info("###### sass_demo done ######")); 506 | cb(); 507 | }); 508 | }); 509 | 510 | gulp.task("clean_build", function () { 511 | return shelljs.rm("-rf", util.getFromCwd("build")); 512 | }); 513 | 514 | gulp.task("reload_by_js", ["pack_demo"], function () { 515 | reload(); 516 | }); 517 | 518 | gulp.task("reload_by_demo_css", ["sass_demo"], function () { 519 | reload(); 520 | }); 521 | 522 | gulp.task("server", ["pack_demo", "sass_demo"], function () { 523 | var port = util.getPkg().config.port || 3000; 524 | browserSync({ 525 | server: { 526 | baseDir: path.join(process.cwd(), "./"), 527 | port: port 528 | }, 529 | open: "external" 530 | }); 531 | //监听js源码文件变化 532 | gulp.watch( 533 | [ 534 | path.join(process.cwd(), "./src/**/*.js"), 535 | path.join(process.cwd(), "./demo/**/*.js") 536 | ], 537 | ["reload_by_js"] 538 | ); 539 | //监听scss源码文件变化 540 | gulp.watch(path.join(process.cwd(), "src/**/*.scss"), ["reload_by_demo_css"]); 541 | //监听demo里面的scss源码文件变化 542 | gulp.watch(path.join(process.cwd(), "demo/**/*.scss"), [ 543 | "reload_by_demo_css" 544 | ]); 545 | //监听demo里面的js源码文件变化 546 | gulp.watch(path.join(process.cwd(), "./demo/demolist/*.js"), ["pack_demo"]); 547 | }); 548 | 549 | gulp.task("build", ["pack_build", "sass_component", "svgScript"], function () {}); 550 | 551 | gulp.task("start", ["server"]); 552 | 553 | gulp.task("dep", function () { 554 | var commands = util.getPackages(); 555 | commands.forEach(function (item) { 556 | util.runCmd("npm", ["i", "-d", item]); 557 | }); 558 | }); 559 | 560 | gulp.task("update", function () { 561 | var commands = util.getPackages(); 562 | commands.forEach(function (item) { 563 | util.runCmd("npm", ["update", "-d", item]); 564 | }); 565 | }); 566 | 567 | gulp.task("pub", ["pack_build", "sass_component"], async function () { 568 | let questions = await util.getQuestions(); 569 | let answers = await inquirer.prompt(questions); 570 | var pkg = util.getPkg(); 571 | pkg.version = answers.version; 572 | file.writeFileFromString(JSON.stringify(pkg, null, " "), "package.json"); 573 | 574 | if (answers.checkChangelog === "y") { 575 | spawn.sync("git", ["add", "."], { 576 | stdio: "inherit" 577 | }); 578 | spawn.sync("git", ["cz"], { 579 | stdio: "inherit" 580 | }); 581 | 582 | console.log(colors.info("#### Npm Info ####")); 583 | spawn.sync("bee-tools", ["run", "changelog"], { 584 | stdio: "inherit" 585 | }); 586 | } 587 | console.log(colors.info("#### Git Info ####")); 588 | spawn.sync("git", ["add", "."], { 589 | stdio: "inherit" 590 | }); 591 | spawn.sync("git", ["commit", "-m", "publish " + pkg.version], { 592 | stdio: "inherit" 593 | }); 594 | spawn.sync("git", ["tag", "v" + pkg.version]); 595 | spawn.sync("git", ["push", "origin", "v" + pkg.version], { 596 | stdio: "inherit" 597 | }); 598 | spawn.sync("git", ["push", "origin", answers.branch], { 599 | stdio: "inherit" 600 | }); 601 | spawn.sync(answers.npm, ["publish"], { 602 | stdio: "inherit" 603 | }); 604 | // await global.getGithubToken(); 605 | }); 606 | 607 | gulp.task("releases", async function () { 608 | await global.getGithubToken(); 609 | }) 610 | --------------------------------------------------------------------------------