处理魔鬼数字

Signed-off-by: yy8545 <854551495@qq.com>
This commit is contained in:
yy8545
2023-09-21 17:41:56 +08:00
parent 283a2f51ce
commit 45c97020bf
@@ -19,6 +19,8 @@ import path from 'path';
import fs from 'fs'; import fs from 'fs';
import type { SourceFile } from 'typescript'; import type { SourceFile } from 'typescript';
const interceptIndex = 2;
/** /**
* generate type alias * generate type alias
* @param typeAliasEntity * @param typeAliasEntity
@@ -56,7 +58,7 @@ function getImportFileFullPath(typeName: string): string {
if (!importRelatePathTmp) { if (!importRelatePathTmp) {
return ''; return '';
} }
const importRelatePath = importRelatePathTmp[0].substring(2, importRelatePathTmp[0].length - 2); const importRelatePath = importRelatePathTmp[0].substring(interceptIndex, importRelatePathTmp[0].length - interceptIndex);
const tmpRealPath = getOhosInterfacesDir() + importRelatePath.replace('../api', '').replace(/\//g, path.sep); const tmpRealPath = getOhosInterfacesDir() + importRelatePath.replace('../api', '').replace(/\//g, path.sep);
if (fs.existsSync(tmpRealPath + '.d.ts')) { if (fs.existsSync(tmpRealPath + '.d.ts')) {
return tmpRealPath + '.d.ts'; return tmpRealPath + '.d.ts';