Browse Source

Merge pull request #97804 in DEC/fineui from master to feature/x

* commit 'd4cc84dafdb8d84981f9f3ea4d074edfc0c60c20':
  chore: 去掉不需要的依赖
  fix: 修改下bug
  chore: 小小重构下
  chore: 增加环境
  chore: 修改路径
  chore: 更改npm包
  chore: 增加npm打包
  chore: 打包命令
  feat: 设置template
  chore: 修改eslint
es6
superman 2 years ago
parent
commit
e8eeeaf9a0
  1. 6
      .eslintrc
  2. 2
      .npmignore
  3. 44
      bin/cli/cli.js
  4. 62
      bin/cli/worker/cli.worker.js
  5. 0
      bin/cli/worker/template/action_type.ts
  6. 5
      bin/cli/worker/template/main_thread_template.ts
  7. 5
      bin/cli/worker/template/worker_thread_template.ts
  8. 3
      package.json

6
.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"
}]
}

2
.npmignore

@ -38,3 +38,5 @@
!.eslintrc
!dist/2.0/jsy.min.css
!dist/2.0/bi.min.css
!bin/*
!bin/**/*

44
bin/cli/cli.js

@ -0,0 +1,44 @@
#!/usr/bin/env node
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);
args[flags] = true;
}
});
return args;
}
const cmds = new Map([
['worker', workerCmd],
]);
const baseCmd = 'fui-cli';
const startIndex = process.argv.findIndex(argv => argv.indexOf(baseCmd) !== -1);
if (startIndex === -1) {
throw new Error(`Command ${baseCmd} not found in args`);
}
const cmd = process.argv[startIndex + 1];
if (cmds.has(cmd)) {
cmds.get(cmd)?.exec(getArgs(startIndex + 2));
} else {
throw new Error(`Command ${cmd} not supported`);
}

62
bin/cli/worker/cli.worker.js

@ -0,0 +1,62 @@
const fs = require('fs');
const path = require('path');
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 args => {
if (!args.init) {
throw new Error(`Command init not found in args`);
}
if (!args.name) {
throw new Error('Command --name=... not found in args');
}
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

0
bin/cli/worker/template/action_type.ts

5
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
}
}

5
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
}
}

3
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",

Loading…
Cancel
Save