From bb650f1f54139e9093aa94cbcf48004e6cbb870c Mon Sep 17 00:00:00 2001 From: iapyang Date: Tue, 5 Jul 2022 15:41:57 +0800 Subject: [PATCH 01/10] =?UTF-8?q?chore:=20=E4=BF=AE=E6=94=B9eslint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index cb2d8acd2..12defcd8a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -17,7 +17,6 @@ }, "parser": "@typescript-eslint/parser", "parserOptions": { - "project": "./tsconfig.json", "ecmaVersion": 6, "sourceType": "module", "ecmaFeatures": { @@ -34,7 +33,10 @@ "comma-dangle": ["error", "never"] // 多行对象字面量中要求拖尾逗号 } }, { - "files": ["webpack/*.js", "types/*.ts", "typescript/*.ts","typescript/**/*.ts", "./*.js", "lib/**/*.js", "lib/*.js"], + "files": ["webpack/*.js", "./*.js", "lib/**/*.js", "lib/*.js", "./bin/*.js", "./bin/**/*.js"], + "extends": "plugin:@fui/esnext" + }, { + "files": ["types/*.ts", "typescript/*.ts","typescript/**/*.ts"], "extends": "plugin:@fui/typescript" }] } From 34050827bf7f609ea589a83682f7da1c9d883fed Mon Sep 17 00:00:00 2001 From: iapyang Date: Tue, 5 Jul 2022 15:42:18 +0800 Subject: [PATCH 02/10] =?UTF-8?q?feat:=20=E8=AE=BE=E7=BD=AEtemplate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/cli/worker/template/action_type.ts | 0 bin/cli/worker/template/main_thread_template.ts | 5 +++++ bin/cli/worker/template/worker_thread_template.ts | 5 +++++ 3 files changed, 10 insertions(+) create mode 100644 bin/cli/worker/template/action_type.ts create mode 100644 bin/cli/worker/template/main_thread_template.ts create mode 100644 bin/cli/worker/template/worker_thread_template.ts diff --git a/bin/cli/worker/template/action_type.ts b/bin/cli/worker/template/action_type.ts new file mode 100644 index 000000000..e69de29bb diff --git a/bin/cli/worker/template/main_thread_template.ts b/bin/cli/worker/template/main_thread_template.ts new file mode 100644 index 000000000..8df764495 --- /dev/null +++ b/bin/cli/worker/template/main_thread_template.ts @@ -0,0 +1,5 @@ +class CrudMainTreadWorker extends BI.Workers.MainThreadWorker { + protected initActions(): void { + // to init some actions + } +} diff --git a/bin/cli/worker/template/worker_thread_template.ts b/bin/cli/worker/template/worker_thread_template.ts new file mode 100644 index 000000000..fc457c9c7 --- /dev/null +++ b/bin/cli/worker/template/worker_thread_template.ts @@ -0,0 +1,5 @@ +class CrudWorkerTreadWorker extends BI.Workers.MainThreadWorker { + protected initActions(): void { + // to init some actions + } +} From cb490921f22949a6d3fa95fca52a9a3b419ce636 Mon Sep 17 00:00:00 2001 From: iapyang Date: Tue, 5 Jul 2022 15:43:49 +0800 Subject: [PATCH 03/10] =?UTF-8?q?chore:=20=E6=89=93=E5=8C=85=E5=91=BD?= =?UTF-8?q?=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/cli/cli.js | 13 ++++++ bin/cli/worker/cli.worker.js | 87 ++++++++++++++++++++++++++++++++++++ package.json | 8 +++- 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 bin/cli/cli.js create mode 100644 bin/cli/worker/cli.worker.js diff --git a/bin/cli/cli.js b/bin/cli/cli.js new file mode 100644 index 000000000..d5fa75280 --- /dev/null +++ b/bin/cli/cli.js @@ -0,0 +1,13 @@ +const workerCmd = require('./cli.worker'); + +const cmds = new Map([ + ['worker', workerCmd], +]); + +const cmd = process.argv[1]; + +if (cmds.has(cmd)) { + cmds.get(cmd)?.exec(); +} else { + throw new Error('命令不存在'); +} diff --git a/bin/cli/worker/cli.worker.js b/bin/cli/worker/cli.worker.js new file mode 100644 index 000000000..aa742e3fb --- /dev/null +++ b/bin/cli/worker/cli.worker.js @@ -0,0 +1,87 @@ +const fs = require('fs'); +const path = require('path'); + +function getArgs (startIndex = 1) { + const args = {}; + process.argv + .slice(startIndex, process.argv.length) + .forEach(arg => { + // long arg + if (arg.slice(0, 2) === '--') { + const longArg = arg.split('='); + const longArgFlag = longArg[0].slice(2, longArg[0].length); + const longArgValue = longArg.length > 1 ? longArg[1] : true; + args[longArgFlag] = longArgValue; + // flags + } else if (arg[0] === '-') { + const flags = arg.slice(1, arg.length).split(''); + flags.forEach(flag => { + args[flag] = true; + }); + } + }); + + return args; +} + +function scanAndCreate(structure, root = process.cwd()) { + Object.keys(structure) + .forEach(name => { + if (typeof structure[name] === 'object') { + fs.mkdirSync(path.resolve(root, name)); + + scanAndCreate(structure[name], path.resolve(root, `./${name}`)); + } else if (structure[name] === '') { + fs.appendFileSync(path.resolve(root, name), ''); + } else if (typeof structure[name] === 'string') { + const content = fs.readFileSync(structure[name]).toString(); + + fs.appendFileSync(path.resolve(root, name), content); + } + }); +} + +module.exports = { + exec: async () => { + const args = getArgs(process.argv); + + if (!args['-init']) { + throw new Error('command not found'); + } + + if (!args['--name']) { + throw new Error('fileName not found'); + } + + const name = args['--name']; + + const structure = { + [`${name}_worker`]: { + 'main_thread': { + action: {}, + [`${name}_main_thread.ts`]: path.resolve(__dirname, './template/main_thread_template.ts'), + }, + utils: { + 'action_type.ts': '', + }, + 'worker_thread': { + action: {}, + [`${name}_worker_thread.ts`]: path.resolve(__dirname, './template/worker_thread_template.ts'), + }, + }, + }; + + scanAndCreate(structure); + }, +}; + +// 结构 +// -xxx_worker +// -|--main_thread +// -|--|--action +// -|--|--xxx_main_thread.ts +// -|--utils +// -|--|--action_type.ts +// -|--worker_thread +// -|--|--action +// -|--|--worker_main_thread.ts diff --git a/package.json b/package.json index 8f415033a..0dbc4e7a0 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,9 @@ "description": "fineui", "main": "dist/fineui_without_conflict.min.js", "types": "dist/lib/index.d.ts", + "bin": { + "fui-cli": "./bin/cli/cli.js" + }, "devDependencies": { "@babel/core": "^7.17.4", "@babel/polyfill": "7.6.0", @@ -81,5 +84,8 @@ "registry": "https://registry.npmjs.org" }, "author": "fanruan", - "license": "MIT" + "license": "MIT", + "dependencies": { + "shelljs": "0.8.5" + } } From ee920120c2486c0ef4276e541b5c251a36d6e6c6 Mon Sep 17 00:00:00 2001 From: iapyang Date: Tue, 5 Jul 2022 15:45:48 +0800 Subject: [PATCH 04/10] =?UTF-8?q?chore:=20=E5=A2=9E=E5=8A=A0npm=E6=89=93?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .npmignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.npmignore b/.npmignore index a6aad7230..a7aafb1b9 100644 --- a/.npmignore +++ b/.npmignore @@ -38,3 +38,4 @@ !.eslintrc !dist/2.0/jsy.min.css !dist/2.0/bi.min.css +!bin From 195870a0743ac46e32f3ce0b63fe49d5a065edc0 Mon Sep 17 00:00:00 2001 From: iapyang Date: Wed, 6 Jul 2022 10:10:20 +0800 Subject: [PATCH 05/10] =?UTF-8?q?chore:=20=E6=9B=B4=E6=94=B9npm=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .npmignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.npmignore b/.npmignore index a7aafb1b9..a5bc0942a 100644 --- a/.npmignore +++ b/.npmignore @@ -38,4 +38,5 @@ !.eslintrc !dist/2.0/jsy.min.css !dist/2.0/bi.min.css -!bin +!bin/* +!bin/**/* From 66c032118b009167149e1088bfae12f887dfeacf Mon Sep 17 00:00:00 2001 From: iapyang Date: Wed, 6 Jul 2022 10:14:37 +0800 Subject: [PATCH 06/10] =?UTF-8?q?chore:=20=E4=BF=AE=E6=94=B9=E8=B7=AF?= =?UTF-8?q?=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/cli/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cli/cli.js b/bin/cli/cli.js index d5fa75280..c93139651 100644 --- a/bin/cli/cli.js +++ b/bin/cli/cli.js @@ -1,4 +1,4 @@ -const workerCmd = require('./cli.worker'); +const workerCmd = require('./worker/cli.worker'); const cmds = new Map([ ['worker', workerCmd], From 40fb3ecf6e2f78fc43b495a96ce8697eeb5b56c9 Mon Sep 17 00:00:00 2001 From: iapyang Date: Wed, 6 Jul 2022 17:06:21 +0800 Subject: [PATCH 07/10] =?UTF-8?q?chore:=20=E5=A2=9E=E5=8A=A0=E7=8E=AF?= =?UTF-8?q?=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/cli/cli.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/cli/cli.js b/bin/cli/cli.js index c93139651..7cd058e0c 100644 --- a/bin/cli/cli.js +++ b/bin/cli/cli.js @@ -1,3 +1,5 @@ +#!/usr/bin/env node + const workerCmd = require('./worker/cli.worker'); const cmds = new Map([ From 720d4e295790a76c1fe3dd3f80b91c3bf3ed0fe0 Mon Sep 17 00:00:00 2001 From: iapyang Date: Wed, 6 Jul 2022 20:31:06 +0800 Subject: [PATCH 08/10] =?UTF-8?q?chore:=20=E5=B0=8F=E5=B0=8F=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/cli/cli.js | 31 +++++++++++++++++++++++++++++-- bin/cli/worker/cli.worker.js | 35 +++++------------------------------ 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/bin/cli/cli.js b/bin/cli/cli.js index 7cd058e0c..7921da776 100644 --- a/bin/cli/cli.js +++ b/bin/cli/cli.js @@ -2,14 +2,41 @@ const workerCmd = require('./worker/cli.worker'); +function getArgs (startIndex = 1) { + const args = {}; + process.argv + .slice(startIndex, process.argv.length) + .forEach(arg => { + // long arg + if (arg.slice(0, 2) === '--') { + const longArg = arg.split('='); + const longArgFlag = longArg[0].slice(2, longArg[0].length); + const longArgValue = longArg.length > 1 ? longArg[1] : true; + args[longArgFlag] = longArgValue; + // flags + } else if (arg[0] === '-') { + const flags = arg.slice(1, arg.length).split(''); + args[flags] = true; + } + }); + + return args; +} + const cmds = new Map([ ['worker', workerCmd], ]); -const cmd = process.argv[1]; +const startIndex = process.argv.findIndex(argv => argv === 'fui-cli'); + +if (startIndex === -1) { + throw new Error('commad not found'); +} + +const cmd = process.argv[startIndex + 1]; if (cmds.has(cmd)) { - cmds.get(cmd)?.exec(); + cmds.get(cmd)?.exec(getArgs(startIndex + 2)); } else { throw new Error('命令不存在'); } diff --git a/bin/cli/worker/cli.worker.js b/bin/cli/worker/cli.worker.js index aa742e3fb..13ad48a5d 100644 --- a/bin/cli/worker/cli.worker.js +++ b/bin/cli/worker/cli.worker.js @@ -1,29 +1,6 @@ const fs = require('fs'); const path = require('path'); -function getArgs (startIndex = 1) { - const args = {}; - process.argv - .slice(startIndex, process.argv.length) - .forEach(arg => { - // long arg - if (arg.slice(0, 2) === '--') { - const longArg = arg.split('='); - const longArgFlag = longArg[0].slice(2, longArg[0].length); - const longArgValue = longArg.length > 1 ? longArg[1] : true; - args[longArgFlag] = longArgValue; - // flags - } else if (arg[0] === '-') { - const flags = arg.slice(1, arg.length).split(''); - flags.forEach(flag => { - args[flag] = true; - }); - } - }); - - return args; -} - function scanAndCreate(structure, root = process.cwd()) { Object.keys(structure) .forEach(name => { @@ -37,23 +14,21 @@ function scanAndCreate(structure, root = process.cwd()) { const content = fs.readFileSync(structure[name]).toString(); fs.appendFileSync(path.resolve(root, name), content); - } + } }); } module.exports = { - exec: async () => { - const args = getArgs(process.argv); - - if (!args['-init']) { + exec: async args => { + if (!args.init) { throw new Error('command not found'); } - if (!args['--name']) { + if (!args.name) { throw new Error('fileName not found'); } - const name = args['--name']; + const name = args.name; const structure = { [`${name}_worker`]: { From fe167b604bac6f9e77d70e6dd13d6bb826e8295b Mon Sep 17 00:00:00 2001 From: iapyang Date: Wed, 6 Jul 2022 20:42:09 +0800 Subject: [PATCH 09/10] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E4=B8=8Bbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/cli/cli.js | 10 ++++++---- bin/cli/worker/cli.worker.js | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bin/cli/cli.js b/bin/cli/cli.js index 7921da776..732fc1133 100644 --- a/bin/cli/cli.js +++ b/bin/cli/cli.js @@ -15,7 +15,7 @@ function getArgs (startIndex = 1) { args[longArgFlag] = longArgValue; // flags } else if (arg[0] === '-') { - const flags = arg.slice(1, arg.length).split(''); + const flags = arg.slice(1, arg.length); args[flags] = true; } }); @@ -27,10 +27,12 @@ const cmds = new Map([ ['worker', workerCmd], ]); -const startIndex = process.argv.findIndex(argv => argv === 'fui-cli'); +const baseCmd = 'fui-cli'; + +const startIndex = process.argv.findIndex(argv => argv.indexOf(baseCmd) !== -1); if (startIndex === -1) { - throw new Error('commad not found'); + throw new Error(`Command ${baseCmd} not found in args`); } const cmd = process.argv[startIndex + 1]; @@ -38,5 +40,5 @@ const cmd = process.argv[startIndex + 1]; if (cmds.has(cmd)) { cmds.get(cmd)?.exec(getArgs(startIndex + 2)); } else { - throw new Error('命令不存在'); + throw new Error(`Command ${cmd} not supported`); } diff --git a/bin/cli/worker/cli.worker.js b/bin/cli/worker/cli.worker.js index 13ad48a5d..0c086db08 100644 --- a/bin/cli/worker/cli.worker.js +++ b/bin/cli/worker/cli.worker.js @@ -21,11 +21,11 @@ function scanAndCreate(structure, root = process.cwd()) { module.exports = { exec: async args => { if (!args.init) { - throw new Error('command not found'); + throw new Error(`Command init not found in args`); } if (!args.name) { - throw new Error('fileName not found'); + throw new Error('Command --name=... not found in args'); } const name = args.name; From 9c5b3d14fa5f836a18486137d9aa806623101880 Mon Sep 17 00:00:00 2001 From: iapyang Date: Wed, 6 Jul 2022 20:44:25 +0800 Subject: [PATCH 10/10] =?UTF-8?q?chore:=20=E5=8E=BB=E6=8E=89=E4=B8=8D?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E7=9A=84=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/package.json b/package.json index 0dbc4e7a0..8c1132253 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,5 @@ }, "author": "fanruan", "license": "MIT", - "dependencies": { - "shelljs": "0.8.5" - } + "dependencies": {} }