zhangweicheng 5 лет назад
Родитель
Сommit
67648af94c

+ 1 - 0
types/.eslintignore

@@ -0,0 +1 @@
+/dist

+ 40 - 0
types/.eslintrc.js

@@ -0,0 +1,40 @@
+module.exports = {
+  env: {
+    browser: true,
+    es2021: true,
+    node: true,
+  },
+  extends: ['airbnb-base', 'plugin:@typescript-eslint/recommended', 'prettier'],
+  parser: '@typescript-eslint/parser',
+  parserOptions: {
+    ecmaVersion: 12,
+    sourceType: 'module',
+  },
+  plugins: ['@typescript-eslint', 'prettier'],
+  rules: {
+    'prettier/prettier': 'error',
+    'import/extensions': [
+      'error',
+      {
+        js: 'never',
+        jsx: 'never',
+        ts: 'never',
+        tsx: 'never',
+        json: 'always',
+      },
+    ],
+    'import/no-unresolved': 'off',
+    '@typescript-eslint/no-empty-function': 'off',
+    '@typescript-eslint/no-explicit-any': 'off',
+    'no-unused-expressions': [
+      'error',
+      {
+        allowShortCircuit: true,
+      },
+    ],
+    'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
+    'no-restricted-syntax': 'off',
+    'no-shadow': 'off',
+    '@typescript-eslint/no-shadow': 'error',
+  },
+};

+ 23 - 0
types/.gitignore

@@ -0,0 +1,23 @@
+.DS_Store
+node_modules
+dist
+package-lock.json*
+
+# local env files
+.env.local
+.env.*.local
+
+# Log files
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+pnpm-debug.log*
+
+# Editor directories and files
+.idea
+.vscode
+*.suo
+*.ntvs*
+*.njsproj
+*.sln
+*.sw?

+ 6 - 0
types/.huskyrc.js

@@ -0,0 +1,6 @@
+module.exports = {
+  hooks: {
+    'pre-commit': 'lint-staged',
+    'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
+  },
+};

+ 13 - 0
types/README.md

@@ -0,0 +1,13 @@
+前后端共用的类型文件
+
+### 开始
+
+基于本仓库进行开发,可以 fork 一个仓库或自行拷贝目录结构。
+
+### 初始化
+
+npm install
+
+### 构建
+
+npm run build

+ 29 - 0
types/commitlint.config.js

@@ -0,0 +1,29 @@
+module.exports = {
+  ignores: [commit => commit.includes('init')],
+  extends: ['@commitlint/config-conventional'],
+  rules: {
+    'body-leading-blank': [2, 'always'],
+    'footer-leading-blank': [1, 'always'],
+    'header-max-length': [2, 'always', 108],
+    'subject-empty': [2, 'never'],
+    'type-empty': [2, 'never'],
+    'type-enum': [
+      2,
+      'always',
+      [
+        'feat', // 新增功能、变更需求
+        'fix', // 修复bug
+        'perf', // 优化性能
+        'refactor', // 代码重构
+        'style', // 代码格式(不影响功能,例如空格、分号等格式修正)
+        'docs', // 文档变更
+        'test', // 测试
+        'ci', // 更改持续集成软件的配置文件和package中的scripts命令,例如scopes: Travis, Circle等
+        'chore', // 变更构建流程或辅助工具(依赖更新/脚手架配置修改/webpack、gulp、npm等)
+        'revert', // 代码回退
+        'types', // ts类型定义文件更改
+        'wip', // work in process开发中
+      ],
+    ],
+  },
+};

+ 9 - 0
types/lint-staged.config.js

@@ -0,0 +1,9 @@
+module.exports = {
+  '*.{js,jsx,ts,tsx}': ['eslint --fix', 'prettier --write'],
+  '{!(package)*.json,*.code-snippets,.!(browserslist)*rc}': [
+    'prettier --write--parser json',
+  ],
+  'package.json': ['prettier --write'],
+  '*.vue': ['prettier --write'],
+  '*.md': ['prettier --write'],
+};

+ 49 - 0
types/package.json

@@ -0,0 +1,49 @@
+{
+  "name": "@sc/types",
+  "version": "1.0.0",
+  "description": "共用类型文件",
+  "main": "./dist/index.cjs.js",
+  "module": "./dist/index.esm.js",
+  "browser": "./dist/index.min.js",
+  "types": "./dist/index.d.ts",
+  "files": [
+    "dist",
+    "README.md"
+  ],
+  "scripts": {
+    "test": "cross-env TS_NODE_COMPILER_OPTIONS={\\\"module\\\":\\\"commonjs\\\"} mocha -r ts-node/register 'tests/**/*.ts'",
+    "build": "rollup -c"
+  },
+  "keywords": [],
+  "author": "smartcost",
+  "license": "ISC",
+  "devDependencies": {
+    "@commitlint/cli": "^11.0.0",
+    "@commitlint/config-conventional": "^11.0.0",
+    "@types/chai": "^4.2.14",
+    "@types/mocha": "^8.0.4",
+    "@types/ms": "^0.7.31",
+    "@typescript-eslint/eslint-plugin": "^4.4.1",
+    "@typescript-eslint/parser": "^4.4.1",
+    "chai": "^4.2.0",
+    "cross-env": "^7.0.2",
+    "eslint": "^7.11.0",
+    "eslint-config-airbnb-base": "^14.2.0",
+    "eslint-config-prettier": "^6.12.0",
+    "eslint-plugin-import": "^2.22.1",
+    "eslint-plugin-prettier": "^3.1.4",
+    "husky": "^4.3.0",
+    "lint-staged": "^10.5.0",
+    "mocha": "^8.2.1",
+    "prettier": "^2.1.2",
+    "rollup": "^2.30.0",
+    "rollup-plugin-commonjs": "^10.1.0",
+    "rollup-plugin-node-resolve": "^5.2.0",
+    "rollup-plugin-terser": "^7.0.2",
+    "rollup-plugin-typescript2": "^0.27.3",
+    "ts-node": "^9.0.0",
+    "tslib": "^2.0.3",
+    "typescript": "^4.0.3"
+  },
+  "dependencies": {}
+}

+ 6 - 0
types/prettier.config.js

@@ -0,0 +1,6 @@
+module.exports = {
+  singleQuote: true, // 单引号
+  trailingComma: 'es5', // 对象末尾以逗号结束
+  arrowParens: 'avoid', // 箭头函数只有一个参数的时候,不使用()
+  endOfLine: 'auto', // CRLF,LF都可以
+};

+ 28 - 0
types/rollup.config.js

@@ -0,0 +1,28 @@
+// import resolve from 'rollup-plugin-node-resolve';
+// import commonjs from 'rollup-plugin-commonjs';
+import typescript from 'rollup-plugin-typescript2'; // 一定要是typescript2,如果使用typescript,没法自动生成.d.ts文件
+// import { terser } from 'rollup-plugin-terser';
+import pkg from './package.json';
+
+export default [
+  // UMD for browser
+  /* {
+    input: 'src/index.ts',
+    output: {
+      name: 'howLongUntilLunch',
+      file: pkg.browser,
+      format: 'umd',
+    },
+    plugins: [resolve(), commonjs(), typescript(), terser()], // 浏览器使用的代码文件进行简化
+  }, */
+  // CommonJS for Node and ES module for bundlers build
+  {
+    input: 'src/index.ts',
+    external: ['ms'],
+    plugins: [typescript()],
+    output: [
+      { file: pkg.main, format: 'cjs' },
+      // { file: pkg.module, format: 'es' },
+    ],
+  },
+];

+ 1 - 0
types/src/index.ts

@@ -0,0 +1 @@
+export * from './interface/index';

+ 31 - 0
types/src/interface/Compliation.ts

@@ -0,0 +1,31 @@
+/* eslint-disable camelcase */
+import { ELockInfo } from './User';
+
+export interface ICptItem {
+  ID: string;
+  name: string;
+  description: string;
+}
+
+export interface IbillValuation {
+  engineering_list: any;
+  enable: boolean;
+  id: string;
+  name: string;
+}
+
+export enum versionType {
+  FREE = 'free', // 免费版
+  PRO = 'pro', // 专业版
+}
+
+export interface IComplication {
+  ID: string;
+  name: string;
+  description: string;
+  rationValuations?: any;
+  billValuations?: IbillValuation[];
+  version?: versionType; // 版本
+  versionText?: string; // 版本对应的显示文字:免费版,学习版,专业版
+  lockInfo?: ELockInfo; //
+}

+ 33 - 0
types/src/interface/User.ts

@@ -0,0 +1,33 @@
+/* eslint-disable camelcase */
+export enum ELockInfo {
+  BORROW = 1, // 借用
+  BUY = 2, // 销售
+}
+
+export interface IupgradeInfo {
+  compilationID: string;
+  isUpgrade: boolean;
+  lock?: ELockInfo;
+  [key: string]: any;
+}
+
+export interface IUserResult {
+  _id?: string;
+  ssoId?: number;
+  username?: string;
+  email?: string;
+  mobile?: string;
+  qq?: string;
+  upgrade_list?: IupgradeInfo[]; // 升级购买信息
+  // eslint-disable-next-line camelcase
+  real_name?: string;
+  company?: string;
+  province?: number;
+  token?: string;
+  isSmsLogin?: number;
+  // 最后登录时间
+  latest_login?: number;
+  // 最近使用编办
+  latest_used?: string;
+  [key: string]: any;
+}

+ 2 - 0
types/src/interface/index.ts

@@ -0,0 +1,2 @@
+export * from './Compliation';
+export * from './User';

+ 9 - 0
types/tests/test.ts

@@ -0,0 +1,9 @@
+import { expect } from 'chai';
+import justTest from '../src/index';
+
+describe('Demo Test', () => {
+  it('just a test', () => {
+    const testStr = justTest();
+    expect(testStr).to.equal('just a test');
+  });
+});

+ 17 - 0
types/tsconfig.json

@@ -0,0 +1,17 @@
+{
+  "compilerOptions": {
+    "target": "ESNext",
+    "module": "ESNext",
+    "declaration": true,
+    "outDir": "./",
+    "strict": true,
+    "esModuleInterop": true,
+  },
+  "include": [
+    "src/**/*.ts",
+  ],
+  "exclude": [
+    "node_modules",
+    "test"
+  ]
+}