feat: switch to TypeScript, custom ESLint config, update deps

This commit is contained in:
Nex Zhu 2021-12-27 10:44:31 +08:00
parent bc6bc455d8
commit a7c776a85e
No known key found for this signature in database
GPG Key ID: 15C6254AD19362B4
18 changed files with 5655 additions and 12741 deletions

View File

@ -1,12 +1,11 @@
# http://editorconfig.org
root = true
lib
[*]
charset = utf-8
indent_style = space
indent_size = 4
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

View File

@ -1,14 +1,21 @@
module.exports = {
extends: ['@webank/eslint-config-webank/vue.js'],
overrides: [
{
files: [
'**/__tests__/*.{j,t}s?(x)',
'**/tests/unit/**/*.spec.{j,t}s?(x)'
]
}
],
env: {
jest: true
}
};
root: true,
extends: ['@daotl/eslint-config-vue/typescript'],
parserOptions: {
project: 'tsconfig.json',
},
rules: {
'vue/multi-word-component-names': 'off',
},
overrides: [
{
files: [
'**/__tests__/*.{j,t}s?(x)',
'**/tests/unit/**/*.spec.{j,t}s?(x)',
],
env: {
jest: true,
},
},
],
}

52
.fes.js
View File

@ -1,26 +1,34 @@
// .fes.js 只负责管理编译时配置只能使用plain Object
export default {
publicPath: './',
access: {
roles: {
admin: ["*"],
manager: ["/"]
}
publicPath: './',
// TODO: `alias` doesn't support TS for now
// alias: {
// '~': 'src',
// },
access: {
roles: {
admin: ['*'],
manager: ['/'],
},
layout: {
title: "Fes.js",
footer: 'Created by MumbleFe',
multiTabs: false,
menus: [{
name: 'index'
}]
},
devServer: {
port: 8000
},
enums: {
status: [['0', '无效的'], ['1', '有效的']]
}
};
},
layout: {
title: 'Fes.js',
footer: 'Created by MumbleFe',
multiTabs: false,
menus: [
{
name: 'index',
},
],
},
devServer: {
port: 8000,
},
enums: {
status: [
['0', '无效的'],
['1', '有效的'],
],
},
}

View File

@ -1,6 +1,5 @@
// .fes.js 只负责管理编译时配置只能使用plain Object
export default {
publicPath: ''
};
publicPath: '',
}

View File

@ -1,4 +0,0 @@
{
"singleQuote": true,
"trailingComma": "none"
}

View File

@ -1,3 +1,3 @@
# fes-template
# fes-starter
Template for [fes.js](https://github.com/WeBankFinTech/fes.js).
A [fes.js](https://github.com/WeBankFinTech/fes.js) + TypeScript starter template.

18045
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,19 @@
{
"name": "@fesjs/template",
"name": "@daotl/fes-starter",
"version": "2.0.0",
"description": "fes项目模版",
"description": "A fes.js + TypeScript starter template",
"scripts": {
"build": "fes build",
"prod": "FES_ENV=prod fes build",
"analyze": "ANALYZE=1 fes build",
"dev": "fes dev",
"test:unit": "fes test:unit"
"test:unit": "fes test:unit",
"lint": "npm run eslint && npm run stylelint",
"lint:fix": "npm run eslint:fix && npm run stylelint:fix",
"eslint": "npx eslint src/**/*.{js,ts,tsx,vue}",
"eslint:fix": "npx eslint src/**/*.{js,ts,tsx,vue} --fix"
},
"prettier": "@daotl/prettier-config",
"keywords": [
"管理端",
"fes",
@ -16,44 +21,32 @@
"easy",
"strong"
],
"files": [
".eslintrc.js",
".gitignore",
".fes.js",
".fes.prod.js",
"mock.js",
"package.json",
"README.md",
"tsconfig.json",
"/src",
"/config"
],
"repository": {
"type": "git",
"url": "git+https://github.com/WeBankFinTech/fes.js.git",
"directory": "packages/fes-template"
"url": "git+https://github.com/daotl/fes-starter.git"
},
"author": "harrywan",
"author": "Nex Zhu <hitnexup@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/WeBankFinTech/fes.js/issues"
"url": "https://github.com/daotl/fes-starter/issues"
},
"homepage": "https://github.com/WeBankFinTech/fes.js#readme",
"homepage": "https://github.com/daotl/fes-starter#readme",
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@vue/compiler-sfc": "^3.2.6",
"@webank/eslint-config-webank": "0.4.2"
"@daotl/eslint-config-vue": "0.2.3",
"@daotl/prettier-config": "^0.1.2",
"@daotl/tsconfig": "^0.0.4",
"@vue/compiler-sfc": "^3.2.26"
},
"dependencies": {
"@fesjs/fes": "^2.0.0",
"@fesjs/plugin-access": "^2.0.0",
"@fesjs/plugin-enums": "^2.0.0",
"@fesjs/plugin-layout": "^2.0.0",
"@fesjs/plugin-model": "^2.0.0",
"@fesjs/fes": "^2.0.11",
"@fesjs/plugin-access": "^2.0.2",
"@fesjs/plugin-enums": "^2.0.2",
"@fesjs/plugin-layout": "^2.0.9",
"@fesjs/plugin-model": "^2.0.3",
"ant-design-vue": "^2.2.0",
"vue": "^3.2.6"
},
"private": true
}
}

View File

@ -1,25 +0,0 @@
import { access } from '@fesjs/fes';
import PageLoading from '@/components/PageLoading';
import UserCenter from '@/components/UserCenter';
export const beforeRender = {
loading: <PageLoading />,
action() {
const { setRole } = access;
return new Promise((resolve) => {
setTimeout(() => {
setRole('admin');
// 初始化应用的全局状态,可以通过 useModel('@@initialState') 获取,具体用法看@/components/UserCenter 文件
resolve({
userName: 'harrywan'
});
}, 1000);
});
}
};
export const layout = {
customHeader: <UserCenter />
};

29
src/app.ts Normal file
View File

@ -0,0 +1,29 @@
import { access } from '@fesjs/fes'
import PageLoading from '@/components/PageLoading.vue'
import UserCenter from '@/components/UserCenter.vue'
export const beforeRender = {
loading: PageLoading,
action() {
const { setRole } = access
return new Promise((resolve) => {
setTimeout(() => {
void setRole('admin')
// 初始化应用的全局状态,可以通过 useModel('@@initialState') 获取,具体用法看@/components/UserCenter 文件
resolve(state)
}, 1000)
})
},
}
export type State = {
userName: string
}
const state: State = {
userName: 'harrywan',
}
export const layout = {
customHeader: UserCenter,
}

View File

@ -1,27 +1,23 @@
<template>
<div class="page-loading">
<Spin size="large" />
</div>
<div class="page-loading">
<Spin size="large" />
</div>
</template>
<script>
import Spin from 'ant-design-vue/lib/spin';
import 'ant-design-vue/lib/spin/style/css';
export default {
components: {
Spin
}
};
<script setup lang="ts">
import Spin from 'ant-design-vue/lib/spin'
import 'ant-design-vue/lib/spin/style/css'
</script>
<style>
.page-loading{
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
.page-loading {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
}
</style>

View File

@ -1,21 +1,17 @@
<template>
<div class="right">{{initialState.userName}}</div>
<div class="right">{{ initialState.userName }}</div>
</template>
<script>
import { useModel } from '@fesjs/fes';
export default {
setup() {
const initialState = useModel('@@initialState');
return {
initialState
};
}
};
<script setup lang="ts">
import { useModel } from '@fesjs/fes'
import type { State } from '@/app'
const initialState = useModel('@@initialState') as State
</script>
<style scope>
.right {
text-align: right;
padding: 0 20px;
text-align: right;
padding: 0 20px;
}
</style>

View File

@ -1,38 +1,29 @@
<template>
<div style="padding: 32px;">
<h3>fes & 拉夫德鲁 </h3>
<h4>数据字典</h4>
<div v-for="item in enumsGet('status')" :key="item.key">{{item.value}}{{item.key}}</div>
<section>
计数器
<button @click="increment">click me{{count}}</button>
</section>
<div style="padding: 32px">
<h3>fes & 拉夫德鲁</h3>
<h4>数据字典</h4>
<div v-for="item in enumsGet('status')" :key="item.key">
{{ item.value }}{{ item.key }}
</div>
<section>
计数器
<button @click="increment">click me{{ count }}</button>
</section>
</div>
</template>
<script>
import { ref } from 'vue';
import {
enums
} from '@fesjs/fes';
<script setup lang="ts">
import { ref } from 'vue'
import { enums } from '@fesjs/fes'
export default {
setup() {
const fes = ref('fes upgrade to vue3');
const count = ref(0);
const increment = () => {
count.value++;
};
const count = ref(0)
return {
fes,
increment,
count,
enumsGet: enums.get
};
}
};
const increment = () => {
count.value++
}
const enumsGet = enums.get
</script>
<config>

6
src/types/shims.d.ts vendored Normal file
View File

@ -0,0 +1,6 @@
// shims.d.ts
declare module '*.vue' {
import { ComponentOptions } from 'vue'
const component: ComponentOptions
export default component
}

View File

@ -1,25 +1,13 @@
{
"extends": "@daotl/tsconfig/vue.json",
"compilerOptions": {
"outDir": "build/dist",
"module": "esnext",
"target": "esnext",
"lib": ["esnext", "dom"],
"sourceMap": true,
"baseUrl": ".",
"jsx": "preserve",
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"allowJs": true,
"skipLibCheck": true,
"experimentalDecorators": true,
"strict": true,
"paths": {
"@/*": ["./src/*"],
"@@/*": ["./src/.fes/*"]
// TODO: `.fes.js` > `alias` doesn't support TS for now
// "~/*": ["src/*"],
"@/*": ["src/*"],
"@@/*": ["src/.fes/*"]
}
},
"include": [
@ -33,5 +21,13 @@
".stylelintrc.js",
".prettierrc.js"
],
"exclude": ["node_modules", "build", "dist", "scripts", "src/.fes/*", "webpack", "jest"]
"exclude": [
"node_modules",
"build",
"dist",
"scripts",
"src/.fes/*",
"webpack",
"jest"
]
}