Skip to content

Commit

Permalink
refactor: TS config
Browse files Browse the repository at this point in the history
  • Loading branch information
HydenLiu committed Apr 29, 2024
1 parent a4f96f1 commit a29e9e5
Show file tree
Hide file tree
Showing 12 changed files with 657 additions and 48 deletions.
14 changes: 12 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"files.eol": "\n",
"cSpell.words": ["datav", "polyline", "vuepress", "execa", "jiaminghi", "dataview", "RGBA"],
"cSpell.words": [
"datav",
"polyline",
"vuepress",
"execa",
"jiaminghi",
"dataview",
"RGBA"
],
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"typescript.tsdk": "./node_modules/typescript/lib",
Expand All @@ -14,5 +22,7 @@
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"eslint.validate": ["javascript"]
"eslint.validate": [
"javascript"
]
}
2 changes: 1 addition & 1 deletion docs/.vuepress/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Components } from '../components';

export default defineClientConfig({
async enhance({ app }) {
Components.forEach((CMP) => app.component(CMP.name, CMP));
Components.forEach((CMP) => app.component(CMP.name!, CMP));

if (!__VUEPRESS_SSR__) {
const DataV = await import('../../es');
Expand Down
2 changes: 1 addition & 1 deletion docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default defineUserConfig({
},
],
sidebar: {
'/guide/': ['/guide/index.md/', '/guide/borderBox.md', '/guide/decoration.md/'],
'/guide/': ['/guide/index.md', '/guide/borderBox.md', '/guide/decoration.md'],
},
}),
bundler: viteBundler({
Expand Down
2 changes: 1 addition & 1 deletion docs/.vuepress/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function init() {
spinner.info('Building es output...');

const buildProcess = execa('yarn', ['build:es'], { shell: true });
buildProcess.stdout.pipe(process.stdout);
buildProcess.stdout!.pipe(process.stdout);
await buildProcess;

spinner.succeed('Es output build successfully!');
Expand Down
2 changes: 1 addition & 1 deletion docs/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export function copy(str: string) {
inputEle.select();
document.execCommand('copy');

inputEle.parentNode.removeChild(inputEle);
inputEle.parentNode?.removeChild(inputEle);
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@
"@vitejs/plugin-vue-jsx": "^2.1.1",
"@vue/eslint-config-prettier": "^7.1.0",
"@vue/eslint-config-typescript": "^11.0.3",
"@vuepress/bundler-vite": "^2.0.0-rc.9",
"@vuepress/theme-default": "^2.0.0-rc.26",
"eslint": "^8.57.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-vue": "^9.25.0",
"execa": "5.1.1",
"fs-extra": "^11.2.0",
"glob": "^8.1.0",
"glob": "^10.3.12",
"husky": "^8.0.3",
"less": "^4.2.0",
"ora": "5.4.1",
Expand All @@ -60,7 +62,7 @@
"semver": "^7.6.0",
"ts-morph": "^17.0.1",
"ts-node": "^10.9.2",
"typescript": "^4.9.5",
"typescript": "~5.1.0",
"vite": "^4.5.3",
"vite-plugin-dts": "^1.7.3",
"vue": "^3.4.25",
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path';

import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import glob from 'glob';
import * as glob from 'glob';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';

Expand Down
10 changes: 5 additions & 5 deletions scripts/plugins/compileStyledComponentsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ export function compileStyledComponentsPlugin(styledPlaceholder: string) {
return {
name: 'compileStyledComponentsPlugin',

async transform(content, id) {
async transform(content: any, id: any) {
if (!/tsx$/.test(id)) {
return;
}

const source = project.getSourceFile(id);

if (fileMap.has(id) && fileMap.get(id) !== content) {
source.refreshFromFileSystemSync();
source!.refreshFromFileSystemSync();
}
fileMap.set(id, content);

const needTransformNode: NoSubstitutionTemplateLiteral[] = [];

source.forEachDescendant((node) => {
source!.forEachDescendant((node) => {
if (!node.isKind(SyntaxKind.NoSubstitutionTemplateLiteral)) {
return;
}

const isStyledTemplate = node.getParentIf((parent) =>
parent.getChildAtIndex(0).getFullText().trim().startsWith('styled')
parent!.getChildAtIndex(0).getFullText().trim().startsWith('styled')
);
if (!isStyledTemplate) {
return;
Expand Down Expand Up @@ -70,7 +70,7 @@ export function compileStyledComponentsPlugin(styledPlaceholder: string) {
);

return {
code: source.getFullText(),
code: source!.getFullText(),
map: null,
};
},
Expand Down
6 changes: 4 additions & 2 deletions scripts/release/version-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (!validVersionType.includes(type as VersionType)) {
process.exit(1);
}

const VersionGenerateMap: Record<VersionType, (version: SemVer) => SemVer> = {
const VersionGenerateMap: Record<string, (version: SemVer) => SemVer> = {
[VersionType.TEST]: (version: SemVer) => {
version.prerelease = ['test', Date.now()];
return version;
Expand All @@ -36,7 +36,9 @@ async function versionGenerator() {
(res) => res.map((r) => JSON.parse(r.toString()))
);

pkg.version = VersionGenerateMap[type](semver.parse(pkg.version)).format();
if (type) {
pkg.version = VersionGenerateMap[type](semver.parse(pkg.version)!).format();
}

const pkgJsonStr = prettier.format(JSON.stringify(pkg), {
parser: 'json-stringify',
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export default function DataV(app: App, { classNamePrefix }: { classNamePrefix?:
Loading,
];

DataVComponents.forEach((CMP) => app.component(CMP.name, CMP));
DataVComponents.forEach((CMP) => {
if (CMP.name) app.component(CMP.name, CMP);
});

if (classNamePrefix) {
setClassNamePrefix(classNamePrefix);
Expand Down
17 changes: 12 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,33 @@
"composite": true,
"target": "ES6",
"types": [
"vue/jsx"
"vue/jsx",
"node"
],
"allowJs": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"lib": [
"ESNext",
"DOM",
"DOM.Iterable"
],
},
"include": [
"./**/*.*",
"env.d.ts",
"src/**/*",
"src/**/*.ts",
"src/**/*.tsx",
"./.dev/*.*",
"./docs/.vuepress/*.*"
"./docs/**/*.*",
"./scripts/**/*.*",
"./package.json"
],
"exclude": [
"node_modules",
"scripts/dev/dev-env",
"docs/guide/refreshLayoutSizeDemo.tsx",
"es",
"./**/*.js",
"node_modules/"
]
}
Loading

0 comments on commit a29e9e5

Please sign in to comment.