新增diff报告

Signed-off-by: wangqing <wangqing136@huawei.com>
This commit is contained in:
wangqing 2024-05-11 10:52:43 +08:00
parent 06e4cac68d
commit 7eea4ad304
11 changed files with 750 additions and 70 deletions

View File

@ -21,7 +21,14 @@ import { FileUtils } from '../utils/FileUtils';
import { LogUtil } from '../utils/logUtil';
import { FilesMap, Parser } from '../coreImpl/parser/parser';
import { DiffHelper } from '../coreImpl/diff/diff';
import { BasicDiffInfo, diffTypeMap, ApiDiffType } from '../typedef/diff/ApiInfoDiff';
import {
BasicDiffInfo,
diffTypeMap,
ApiDiffType,
DiffNumberInfo,
apiChangeMap,
isNotApiSet,
} from '../typedef/diff/ApiInfoDiff';
import { WriterHelper } from './writer';
import { LocalEntry } from '../coreImpl/checker/local_entry';
import { ApiResultMessage, ApiResultSimpleInfo } from '../typedef/checker/result_type';
@ -29,10 +36,12 @@ import { NumberConstant } from '../utils/Constant';
import { ApiStatisticsHelper } from '../coreImpl/statistics/Statistics';
import { ApiStatisticsInfo, StatisticsInfoValueType } from '../typedef/statistics/ApiStatistics';
import { SyscapProcessorHelper } from '../coreImpl/diff/syscapFieldProcessor';
import { FunctionUtils } from '../utils/FunctionUtils';
import { ApiCountInfo } from '../typedef/count/ApiCount';
import { ApiCountHelper } from '../coreImpl/count/count'
import { CommonFunctions } from '../utils/checkUtils';
import { FunctionUtils, KitData } from '../utils/FunctionUtils';
import { ApiType } from '../typedef/parser/ApiInfoDefination';
/**
*
@ -162,6 +171,10 @@ export const Plugin: PluginType = {
isRequiredOption: false,
options: ['--changelogUrl <string>', 'changelog url', ''],
},
{
isRequiredOption: false,
options: ['--all <boolean>', 'is all sheet', ''],
},
],
},
@ -192,6 +205,7 @@ export const Plugin: PluginType = {
format: argv.format,
changelogUrl: argv.changelogUrl,
excel: argv.excel,
all: argv.all,
};
const methodInfos: ToolNameValueType = method(options);
@ -229,7 +243,7 @@ function outputInfos(infos: ToolReturnData, options: OptionObjType, callback: To
);
break;
case formatType.EXCEL:
WriterHelper.ExcelReporter(infos, options.output, `${options.toolName}.xlsx`, callback);
WriterHelper.ExcelReporter(infos, options.output, `${options.toolName}.xlsx`, callback, options);
break;
case formatType.CHANGELOG:
WriterHelper.JSONReporter(String(infos[0]), options.output, `${options.toolName}.json`);
@ -258,12 +272,12 @@ function collectApi(options: OptionObjType): ToolNameValueType {
} else {
allApis = Parser.parseFile(path.resolve(fileDir, '..'), fileDir);
}
const statisticsInfosObject: StatisticsInfoValueType = ApiStatisticsHelper.getApiStatisticsInfos(allApis)
const statisticsInfosObject: StatisticsInfoValueType = ApiStatisticsHelper.getApiStatisticsInfos(allApis);
const fileContent: string = Parser.getParseResults(allApis);
let data: ApiStatisticsInfo[] | string [] = [fileContent];
if (options.format === 'excel') {
const allApiStatisticsInfos: ApiStatisticsInfo[] | undefined = statisticsInfosObject.allApiStatisticsInfos;
data = statisticsInfosObject.apiStatisticsInfos
data = statisticsInfosObject.apiStatisticsInfos;
if (allApiStatisticsInfos) {
WriterHelper.ExcelReporter(
allApiStatisticsInfos,
@ -288,17 +302,33 @@ function collectApi(options: OptionObjType): ToolNameValueType {
}
}
function collectApiCallback(apiData: ApiStatisticsInfo[], sheet: ExcelJS.Worksheet): void {
function collectApiCallback(apiData: ApiStatisticsInfo[], workbook: ExcelJS.Workbook, dest?: string,
options?: OptionObjType): void {
const sheet: ExcelJS.Worksheet = workbook.addWorksheet();
const apiRelationsSet: Set<string> = new Set();
const kitObject = FunctionUtils.readKitFile();
const subsystemMap: Map<string, string> = kitObject.subsystemMap;
const kitMap: Map<string, string> = kitObject.kitNameMap;
const kitData: KitData = FunctionUtils.readKitFile();
sheet.name = 'JsApi';
sheet.views = [{ xSplit: 1 }];
sheet.getRow(1).values = ['模块名', '类名', '方法名', '函数', '类型',
'起始版本', '废弃版本', 'syscap', '错误码', '是否为系统API',
'模型限制', '权限', '是否支持跨平台', '是否支持卡片应用', '是否为高阶API',
'装饰器', 'kit', '文件路径', '子系统',
sheet.getRow(1).values = [
'模块名',
'类名',
'方法名',
'函数',
'类型',
'起始版本',
'废弃版本',
'syscap',
'错误码',
'是否为系统API',
'模型限制',
'权限',
'是否支持跨平台',
'是否支持卡片应用',
'是否为高阶API',
'装饰器',
'kit',
'文件路径',
'子系统',
];
let lineNumber = 2;
apiData.forEach((apiInfo: ApiStatisticsInfo) => {
@ -323,9 +353,84 @@ function collectApiCallback(apiData: ApiStatisticsInfo[], sheet: ExcelJS.Workshe
apiInfo.getIsForm(),
apiInfo.getIsAutomicService(),
apiInfo.getDecorators()?.join(),
apiInfo.getKitInfo() === '' ? kitMap.get(apiInfo.getFilePath().replace(/\\/g, '/')) : apiInfo.getKitInfo(),
apiInfo.getKitInfo() === ''
? kitData.kitNameMap.get(apiInfo.getFilePath().replace(/\\/g, '/').replace('api/', ''))
: apiInfo.getKitInfo(),
apiInfo.getFilePath(),
subsystemMap.get(apiInfo.getFilePath().replace(/\\/g, '/')),
kitData.subsystemMap.get(apiInfo.getFilePath().replace(/\\/g, '/').replace('api/', '')),
];
lineNumber++;
apiRelationsSet.add(apiRelations);
});
if (options?.all) {
handleCollectData(apiData, workbook);
}
}
/**
*
*
* @param apiData
* @param workbook
*/
function handleCollectData(apiData: ApiStatisticsInfo[], workbook: ExcelJS.Workbook){
const sheet: ExcelJS.Worksheet = workbook.addWorksheet();
const apiRelationsSet: Set<string> = new Set();
const kitData: KitData = FunctionUtils.readKitFile();
sheet.name = 'JsApi定制版本';
sheet.views = [{ xSplit: 1 }];
sheet.getRow(1).values = [
'模块名',
'类名',
'方法名',
'函数',
'类型',
'起始版本',
'废弃版本',
'syscap',
'错误码',
'是否为系统API',
'模型限制',
'权限',
'是否支持跨平台',
'是否支持卡片应用',
'是否为高阶API',
'装饰器',
'kit',
'文件路径',
'子系统',
'接口全路径'
];
let lineNumber = 2;
apiData.forEach((apiInfo: ApiStatisticsInfo) => {
const apiRelations: string = `${apiInfo.getHierarchicalRelations()},${apiInfo.getDefinedText()}`;
if (apiRelationsSet.has(apiRelations)) {
return;
}
sheet.getRow(lineNumber).values = [
apiInfo.getPackageName(),
apiInfo.getParentModuleName(),
apiInfo.getApiName(),
apiInfo.getDefinedText(),
apiInfo.getApiType(),
apiInfo.getSince() === '-1' ? '' : apiInfo.getSince(),
apiInfo.getDeprecatedVersion() === '-1' ? '' : apiInfo.getDeprecatedVersion(),
apiInfo.getSyscap(),
apiInfo.getErrorCodes().join() === '-1' ? '' : apiInfo.getErrorCodes().join(),
apiInfo.getApiLevel(),
apiInfo.getModelLimitation(),
apiInfo.getPermission(),
apiInfo.getIsCrossPlatForm(),
apiInfo.getIsForm(),
apiInfo.getIsAutomicService(),
apiInfo.getDecorators()?.join(),
apiInfo.getKitInfo() === ''
? kitData.kitNameMap.get(apiInfo.getFilePath().replace(/\\/g, '/').replace('api/', ''))
: apiInfo.getKitInfo(),
apiInfo.getFilePath(),
kitData.subsystemMap.get(apiInfo.getFilePath().replace(/\\/g, '/').replace('api/', '')),
apiInfo.getHierarchicalRelations().replace(/\//g, '#').replace('api\\', ''),
];
lineNumber++;
apiRelationsSet.add(apiRelations);
@ -356,6 +461,7 @@ function checkApi(): ToolNameValueType {
};
}
}
/**
* api检查工具调用方法
*
@ -418,11 +524,11 @@ function diffApi(options: OptionObjType): ToolNameValueType {
if (status.isDirectory()) {
const oldSDKApiMap: FilesMap = Parser.parseDir(oldFileDir);
const newSDKApiMap: FilesMap = Parser.parseDir(newFileDir);
data = DiffHelper.diffSDK(oldSDKApiMap, newSDKApiMap);
data = DiffHelper.diffSDK(oldSDKApiMap, newSDKApiMap, options.all);
} else {
const oldSDKApiMap: FilesMap = Parser.parseFile(path.resolve(oldFileDir, '..'), oldFileDir);
const newSDKApiMap: FilesMap = Parser.parseFile(path.resolve(newFileDir, '..'), newFileDir);
data = DiffHelper.diffSDK(oldSDKApiMap, newSDKApiMap);
data = DiffHelper.diffSDK(oldSDKApiMap, newSDKApiMap, options.all);
}
let finalData: (string | BasicDiffInfo)[] = [];
if (options.format === formatType.JSON) {
@ -461,17 +567,21 @@ function detectionApi(options: OptionObjType): ToolNameValueType {
allApis = Parser.parseFile(path.resolve(fileDir, '..'), fileDir);
}
const fileContent: string = Parser.getParseResults(allApis);
WriterHelper.JSONReporter(
fileContent,
path.dirname(options.output),
'detection.json'
);
WriterHelper.JSONReporter(fileContent, path.dirname(options.output), 'detection.json');
let runningCommand: string = '';
if (process.env.NODE_ENV === 'development') {
runningCommand = `python ${path.resolve(FileUtils.getBaseDirName(), '../api_label_detection/src/main.py')} -N detection -L ${options.checkLabels} -P ${path.resolve(path.dirname(options.output), 'detection.json')} -O ${path.resolve(options.output)}`;
runningCommand = `python ${path.resolve(
FileUtils.getBaseDirName(),
'../api_label_detection/src/main.py'
)} -N detection -L ${options.checkLabels} -P ${path.resolve(
path.dirname(options.output),
'detection.json'
)} -O ${path.resolve(options.output)}`;
} else if (process.env.NODE_ENV === 'production') {
runningCommand = `${path.resolve(FileUtils.getBaseDirName(), './main.exe')} -N detection -L ${options.checkLabels} -P ${path.resolve(path.dirname(options.output), 'detection.json')} -O ${path.resolve(options.output)}`;
runningCommand = `${path.resolve(FileUtils.getBaseDirName(), './main.exe')} -N detection -L ${
options.checkLabels
} -P ${path.resolve(path.dirname(options.output), 'detection.json')} -O ${path.resolve(options.output)}`;
}
buffer = execSync(runningCommand, {
timeout: 120000,
@ -485,7 +595,6 @@ function detectionApi(options: OptionObjType): ToolNameValueType {
return {
data: [],
};
}
/**
@ -512,7 +621,7 @@ function countApi(options: OptionObjType): ToolNameValueType {
let finalData: (string | ApiCountInfo)[] = [];
if (options.format === formatType.JSON) {
finalData = [JSON.stringify(apiCountInfos, null, NumberConstant.INDENT_SPACE)];
}else {
} else {
finalData = apiCountInfos;
}
return {
@ -529,7 +638,8 @@ function countApi(options: OptionObjType): ToolNameValueType {
}
}
function countApiCallback(data: ApiCountInfo[], sheet: ExcelJS.Worksheet): void {
function countApiCallback(data: ApiCountInfo[], workbook: ExcelJS.Workbook): void {
const sheet: ExcelJS.Worksheet = workbook.addWorksheet();
sheet.name = 'api数量';
sheet.views = [{ xSplit: 1 }];
sheet.getRow(1).values = ['子系统', 'kit', '文件', 'api数量'];
@ -547,26 +657,219 @@ function countApiCallback(data: ApiCountInfo[], sheet: ExcelJS.Worksheet): void
* diffApi工具导出excel时的回调方法
*
* @param {BasicDiffInfo[]} data diffApi工具获取到的数据
* @param {ExcelJS.Worksheet} sheet ExcelJS构建的Worksheet对象
* @param {ExcelJS.Workbook} workbook ExcelJS构建的Workbook对象
*/
function diffApiCallback(data: BasicDiffInfo[], sheet: ExcelJS.Worksheet, dest?: string): void {
sheet.name = 'api差异';
sheet.views = [{ xSplit: 1 }];
function diffApiCallback(
data: BasicDiffInfo[],
workbook: ExcelJS.Workbook,
dest?: string,
options?: OptionObjType
): void {
const relationsSet: Set<string> = new Set();
const kitData: KitData = FunctionUtils.readKitFile();
const sheet: ExcelJS.Worksheet = workbook.addWorksheet('api差异');
sheet.views = [{ xSplit: 2 }];
sheet.getRow(1).values = ['操作标记', '差异项-旧版本', '差异项-新版本', 'd.ts文件', '归属子系统', 'kit'];
data.forEach((diffInfo: BasicDiffInfo, index: number) => {
relationsSet.add(getRelation(diffInfo));
const dtsName = diffInfo.getNewDtsName() ? diffInfo.getNewDtsName() : diffInfo.getOldDtsName();
sheet.getRow(index + NumberConstant.LINE_IN_EXCEL).values = [
diffTypeMap.get(diffInfo.getDiffType()),
joinOldMessage(diffInfo),
joinNewMessage(diffInfo),
dtsName.replace(/\\/g, '/'),
SyscapProcessorHelper.matchSubsystem(diffInfo),
SyscapProcessorHelper.getSingleKitInfo(diffInfo)
kitData.subsystemMap.get(dtsName.replace(/\\/g, '/').replace('api/', '')),
SyscapProcessorHelper.getSingleKitInfo(diffInfo) === ''
? kitData.kitNameMap.get(dtsName.replace(/\\/g, '/').replace('api/', ''))
: SyscapProcessorHelper.getSingleKitInfo(diffInfo),
];
});
WriterHelper.MarkdownReporter.writeInMarkdown(data, dest);
if (options?.all) {
addApiNumberSheet(relationsSet, workbook, data, kitData)
}
}
/**
* diff工具结果的另一个sheet页API变更信息的次数+
*
* @param relationsSet
* @param workbook
* @param data
* @param kitData
*/
function addApiNumberSheet(relationsSet: Set<string>, workbook: ExcelJS.Workbook, data: BasicDiffInfo[], kitData: KitData){
const numberSheet: ExcelJS.Worksheet = workbook.addWorksheet('api变更数量统计');
numberSheet.views = [{ xSplit: 2 }];
numberSheet.getRow(1).values = [
'api名称',
'kit名称',
'归属子系统',
'是否是api',
'api类型',
'操作标记',
'变更类型',
'兼容性',
'变更次数',
'差异项-旧版本',
'差异项-新版本',
'兼容性列表',
'全路径'
];
let diffTypeNumberArr: DiffNumberInfo[] = [];
relationsSet.forEach((apiRelation: string) => {
let apiName: string = '';
const diffNumberInfo: DiffNumberInfo = new DiffNumberInfo();
data.forEach((diffInfo: BasicDiffInfo) => {
const dtsName: string = diffInfo.getNewDtsName() ? diffInfo.getNewDtsName() : diffInfo.getOldDtsName();
const kitName =
SyscapProcessorHelper.getSingleKitInfo(diffInfo) === ''
? kitData.kitNameMap.get(dtsName.replace(/\\/g, '/').replace('api/', ''))
: SyscapProcessorHelper.getSingleKitInfo(diffInfo);
if (apiRelation === getRelation(diffInfo)) {
apiName = getDiffApiName(diffInfo);
diffNumberInfo
.setAllDiffType(diffInfo.getDiffMessage())
.setAllChangeType(apiChangeMap.get(diffInfo.getDiffType()))
.setOldDiffMessage(diffInfo.getOldDescription())
.setNewDiffMessage(diffInfo.getNewDescription())
.setAllCompatible(diffInfo.getIsCompatible())
.setIsApi(!isNotApiSet.has(diffInfo.getApiType()))
.setKitName(kitName)
.setSubsystem(kitData.subsystemMap.get(dtsName.replace(/\\/g, '/').replace('api/', '')))
.setApiName(diffInfo.getApiType() === ApiType.SOURCE_FILE ? 'SOURCEFILE' : getDiffApiName(diffInfo))
.setApiRelation(getRelation(diffInfo).replace(/\,/g, '#').replace('api\\', ''));
}
});
diffTypeNumberArr.push(diffNumberInfo);
});
diffTypeNumberArr = handleData(data, diffTypeNumberArr);
diffTypeNumberArr.forEach((diffNumberInfo: DiffNumberInfo, index: number) => {
numberSheet.getRow(index + NumberConstant.LINE_IN_EXCEL).values = [
diffNumberInfo.getApiName(),
diffNumberInfo.getKitName(),
diffNumberInfo.getSubsystem(),
diffNumberInfo.getIsApi(),
diffNumberInfo.getApiType(),
diffNumberInfo.getAllDiffType().join(' #&# '),
diffNumberInfo.getAllChangeType().join(' #&# '),
getCompatibleObject(diffNumberInfo),
calculateChangeNumber(diffNumberInfo),
diffNumberInfo.getOldDiffMessage().join(' #&# '),
diffNumberInfo.getNewDiffMessage().join(' #&# '),
diffNumberInfo.getAllCompatible().join(' #&# '),
diffNumberInfo.getApiRelation(),
];
});
}
/**
* diff数据的钩子函数
*
* @param data
* @param diffTypeNumberArr
* @returns
*/
function handleData(data: BasicDiffInfo[], diffTypeNumberArr: DiffNumberInfo[]): DiffNumberInfo[] {
return diffTypeNumberArr;
}
/**
* API的变更集合是否兼容
*
* @param diffNumberInfo
* @returns
*/
function getCompatibleObject(diffNumberInfo: DiffNumberInfo) {
const compatibleInfoSet: Set<boolean> = new Set(diffNumberInfo.getAllCompatible());
let compatibleSign = 0;
let incompatibleSign = 0;
if (compatibleInfoSet.size === 2) {
compatibleSign = 1;
incompatibleSign = 1;
return `{
"兼容性":${compatibleSign},
"非兼容性":${incompatibleSign}
}`;
}
if (compatibleInfoSet.has(true)) {
compatibleSign = 1;
return `{
"兼容性":${compatibleSign},
"非兼容性":${incompatibleSign}
}`;
}
if (compatibleInfoSet.has(false)) {
incompatibleSign = 1;
return `{
"兼容性":${compatibleSign},
"非兼容性":${incompatibleSign}
}`;
}
}
/**
*
*
* @param diffNumberInfo
* @returns
*/
function calculateChangeNumber(diffNumberInfo: DiffNumberInfo) {
const changeTypeSet: Set<string> = new Set(diffNumberInfo.getAllChangeType());
let newApiNumber: number = 0,
apiDeleteNumber = 0,
apiDeprecatedNumber = 0,
apiChangeNumber = 0,
apiConstrainedChange = 0,
apiPrototypeChange = 0;
if (changeTypeSet.has('API修改原型修改')) {
apiPrototypeChange++;
}
if (changeTypeSet.has('API修改约束变化')) {
apiConstrainedChange++;
}
if (changeTypeSet.has('API修改原型修改') || changeTypeSet.has('API修改约束变化')) {
apiChangeNumber++;
}
if (changeTypeSet.has('API废弃')) {
apiDeprecatedNumber++;
}
if (changeTypeSet.has('API新增')) {
newApiNumber++;
}
if (changeTypeSet.has('API删除')) {
apiDeleteNumber++;
}
return `{
"API新增": ${newApiNumber},
"API删除": ${apiDeleteNumber},
"API废弃": ${apiDeprecatedNumber},
"API修改": ${apiChangeNumber},
"API修改原型修改": ${apiPrototypeChange},
"API修改约束变化": ${apiConstrainedChange}
}`;
}
function getDiffApiName(diffInfo: BasicDiffInfo): string {
if (diffInfo.getNewApiName() !== '') {
return diffInfo.getNewApiName();
}
return diffInfo.getOldApiName();
}
function getRelation(diffInfo: BasicDiffInfo): string {
const relationsArr = diffInfo.getNewHierarchicalRelations();
if (relationsArr.length > 0) {
return relationsArr.join();
} else {
return diffInfo.getOldHierarchicalRelations().join();
}
}
export function joinOldMessage(diffInfo: BasicDiffInfo): string {
@ -632,6 +935,7 @@ export type OptionObjType = {
format: formatType;
changelogUrl: string;
excel: string;
all: boolean;
};
/**
@ -640,7 +944,12 @@ export type OptionObjType = {
* @param { ToolReturnData } data
* @param { ExcelJS.Worksheet } sheet ExcelJS构建的Worksheet对象
*/
export type ToolNameExcelCallback = (data: ToolReturnData, sheet: ExcelJS.Worksheet, dest?: string) => void;
export type ToolNameExcelCallback = (
data: ToolReturnData,
sheet: ExcelJS.Workbook,
dest?: string,
options?: OptionObjType
) => void;
/**
*

View File

@ -19,7 +19,7 @@ import fs from 'fs';
import { LogUtil } from '../utils/logUtil';
import { ToolNameExcelCallback, joinNewMessage, joinOldMessage, ToolReturnData } from './config';
import { BasicDiffInfo, diffTypeMap } from '../typedef/diff/ApiInfoDiff';
import { FunctionUtils } from '../utils/FunctionUtils';
import { OptionObjType } from './config'
import { SyscapProcessorHelper } from '../coreImpl/diff/syscapFieldProcessor';
export namespace WriterHelper {
@ -33,14 +33,13 @@ export namespace WriterHelper {
data: ToolReturnData,
dest: string,
fileName: string,
callback: ToolNameExcelCallback | undefined
callback: ToolNameExcelCallback | undefined,
options?: OptionObjType
) {
const workbook: ExcelJS.Workbook = new ExcelJS.Workbook();
const sheet: ExcelJS.Worksheet = workbook.addWorksheet();
if (typeof callback === 'function') {
//callback是一个函数才能当回调函数使用
callback(data, sheet, dest);
callback(data, workbook, dest, options);
}
const buffer: NodeJS.ArrayBufferView = (await workbook.xlsx.writeBuffer()) as NodeJS.ArrayBufferView;

View File

@ -58,11 +58,11 @@ export class ApiChangeCheck {
if (status.isDirectory()) {
const oldSDKApiMap: FilesMap = Parser.parseDir(oldFileDir);
const newSDKApiMap: FilesMap = Parser.parseDir(newFileDir);
diffInfos = DiffHelper.diffSDK(oldSDKApiMap, newSDKApiMap, true);
diffInfos = DiffHelper.diffSDK(oldSDKApiMap, newSDKApiMap, false, true);
} else {
const oldSDKApiMap: FilesMap = Parser.parseFile(path.resolve(oldFileDir, '..'), oldFileDir);
const newSDKApiMap: FilesMap = Parser.parseFile(path.resolve(newFileDir, '..'), newFileDir);
diffInfos = DiffHelper.diffSDK(oldSDKApiMap, newSDKApiMap, true);
diffInfos = DiffHelper.diffSDK(oldSDKApiMap, newSDKApiMap, false, true);
}
diffInfos.forEach((diffInfo: BasicDiffInfo) => {
if (diffInfo.getIsCompatible() !== false) {

View File

@ -69,7 +69,13 @@ export namespace DiffProcessorHelper {
*
*/
export class JsDocDiffHelper {
static diffJsDocInfo(oldApiInfo: ApiInfo, newApiInfo: ApiInfo, diffInfos: BasicDiffInfo[]): void {
static diffJsDocInfo(
oldApiInfo: ApiInfo,
newApiInfo: ApiInfo,
diffInfos: BasicDiffInfo[],
isAllDeprecated?: boolean,
isAllSheet?: boolean
): void {
const oldJsDocInfo: Comment.JsDocInfo | undefined = oldApiInfo.getLastJsDocInfo();
const newJsDocInfo: Comment.JsDocInfo | undefined = newApiInfo.getLastJsDocInfo();
JsDocDiffHelper.diffSinceVersion(oldApiInfo, newApiInfo, diffInfos);
@ -80,7 +86,7 @@ export namespace DiffProcessorHelper {
});
for (let i = 0; i < jsDocDiffProcessors.length; i++) {
const jsDocDiffProcessor: JsDocDiffProcessor | undefined = jsDocDiffProcessors[i];
const diffType: DiffTypeInfo | undefined = jsDocDiffProcessor(oldJsDocInfo, newJsDocInfo);
const diffType: DiffTypeInfo | undefined = jsDocDiffProcessor(oldJsDocInfo, newJsDocInfo, isAllDeprecated, isAllSheet);
if (!diffType) {
continue;
}
@ -351,7 +357,9 @@ export namespace DiffProcessorHelper {
static diffDeprecated(
oldJsDocInfo: Comment.JsDocInfo | undefined,
newJsDocInfo: Comment.JsDocInfo | undefined
newJsDocInfo: Comment.JsDocInfo | undefined,
isAllDeprecated?: boolean,
isAllSheet?: boolean
): DiffTypeInfo | undefined {
const diffTypeInfo: DiffTypeInfo = new DiffTypeInfo();
const deprecatedVersionOfOld: string = oldJsDocInfo ? oldJsDocInfo.getDeprecatedVersion() : '-1';
@ -363,12 +371,27 @@ export namespace DiffProcessorHelper {
if (deprecatedVersionOfNew === deprecatedVersionOfOld) {
return undefined;
}
if (deprecatedVersionOfOld === '-1') {
return diffTypeInfo.setDiffType(ApiDiffType.DEPRECATED_NA_TO_HAVE);
if (isAllSheet) {
if (deprecatedVersionOfOld === '-1' && !isAllDeprecated) {
return diffTypeInfo.setDiffType(ApiDiffType.DEPRECATED_NOT_All);
}
if (deprecatedVersionOfOld === '-1' && isAllDeprecated) {
return diffTypeInfo.setDiffType(ApiDiffType.DEPRECATED_NA_TO_HAVE);
}
} else {
if (deprecatedVersionOfOld === '-1') {
return diffTypeInfo.setDiffType(ApiDiffType.DEPRECATED_NA_TO_HAVE);
}
if (deprecatedVersionOfNew === '-1') {
return diffTypeInfo.setDiffType(ApiDiffType.DEPRECATED_HAVE_TO_NA);
}
}
if (deprecatedVersionOfNew === '-1') {
return diffTypeInfo.setDiffType(ApiDiffType.DEPRECATED_HAVE_TO_NA);
}
return diffTypeInfo.setDiffType(ApiDiffType.DEPRECATED_A_TO_B);
}
}
@ -1049,14 +1072,8 @@ export namespace DiffProcessorHelper {
static diffMethodParamType(oldApiInfo: ParamInfo, newApiInfo: ParamInfo): ApiDiffType | undefined {
const oldParamType: string[] = oldApiInfo.getType();
const newParamType: string[] = newApiInfo.getType();
const oldParamTypeStr: string = oldParamType
.toString()
.replace(/\r|\n|\s+|'|"/g, '')
.replace(/\|/g, '\\|');
const newParamTypeStr: string = newParamType
.toString()
.replace(/\r|\n|\s+|'|"/g, '')
.replace(/\|/g, '\\|');
const oldParamTypeStr: string = oldParamType.toString().replace(/\r|\n|\s+|'|"/g, '').replace(/\|/g, "\\|");
const newParamTypeStr: string = newParamType.toString().replace(/\r|\n|\s+|'|"/g, '').replace(/\|/g, `\\|`);
if (oldParamTypeStr === newParamTypeStr) {
return undefined;
}

View File

@ -41,7 +41,7 @@ export class DiffHelper {
* @param { FilesMap } newSDKApiMap SDK解析后的结果
* @returns { BasicDiffInfo[] }
*/
static diffSDK(oldSDKApiMap: FilesMap, newSDKApiMap: FilesMap, isCheck?: boolean): BasicDiffInfo[] {
static diffSDK(oldSDKApiMap: FilesMap, newSDKApiMap: FilesMap, isAllSheet: boolean, isCheck?: boolean): BasicDiffInfo[] {
const clonedOldSDKApiMap: FilesMap = _.cloneDeep(oldSDKApiMap);
const clonedNewSDKApiMap: FilesMap = _.cloneDeep(newSDKApiMap);
const diffInfos: BasicDiffInfo[] = [];
@ -67,7 +67,7 @@ export class DiffHelper {
}
// 新旧版本均存在,则进行对比
const newApiInfos: ApiInfo[] = Parser.getApiInfo(apiLocation, clonedNewSDKApiMap) as ApiInfo[];
DiffHelper.diffApis(oldApiInfos, newApiInfos, diffInfos, isCheck);
DiffHelper.diffApis(oldApiInfos, newApiInfos, diffInfos, isAllSheet, isCheck);
// 对比完则将新版本中的对应API进行删除
newSDKApiLocations.delete(key);
}
@ -152,7 +152,7 @@ export class DiffHelper {
* @param { ApiInfo[] } newApiInfos API信息
* @param { BasicDiffInfo[] } diffInfos api差异结果集
*/
static diffApis(oldApiInfos: ApiInfo[], newApiInfos: ApiInfo[], diffInfos: BasicDiffInfo[], isCheck?: boolean): void {
static diffApis(oldApiInfos: ApiInfo[], newApiInfos: ApiInfo[], diffInfos: BasicDiffInfo[], isAllSheet: boolean, isCheck?: boolean): void {
const diffSets: Map<string, ApiInfo>[] = DiffHelper.getDiffSet(oldApiInfos, newApiInfos);
const oldReduceNewMap: Map<string, ApiInfo> = diffSets[0];
const newReduceOldMap: Map<string, ApiInfo> = diffSets[1];
@ -180,7 +180,58 @@ export class DiffHelper {
});
return;
}
DiffHelper.diffSameNumberFunction(oldApiInfos, newApiInfos, diffInfos, isCheck);
if (isAllSheet) {
DiffHelper.diffSameFunction(oldApiInfos, newApiInfos, diffInfos, isAllSheet, isCheck);
} else {
DiffHelper.diffSameNumberFunction(oldApiInfos, newApiInfos, diffInfos, isCheck);
}
}
/**
*
* @param oldApiInfos
* @param newApiInfos
* @param diffInfos
* @param isCheck
*/
static diffSameFunction(
oldApiInfos: ApiInfo[],
newApiInfos: ApiInfo[],
diffInfos: BasicDiffInfo[],
isAllSheet: boolean,
isCheck?: boolean
): void {
const isAllDeprecated: boolean = DiffHelper.judgeIsAllDeprecated(newApiInfos);
if (oldApiInfos.length === newApiInfos.length) {
const apiNumber: number = oldApiInfos.length;
for (let i = 0; i < apiNumber; i++) {
DiffProcessorHelper.JsDocDiffHelper.diffJsDocInfo(oldApiInfos[i], newApiInfos[i], diffInfos, isAllDeprecated, isAllSheet);
DiffProcessorHelper.ApiDecoratorsDiffHelper.diffDecorator(oldApiInfos[i], newApiInfos[i], diffInfos);
DiffProcessorHelper.ApiNodeDiffHelper.diffNodeInfo(oldApiInfos[i], newApiInfos[i], diffInfos, isCheck);
}
} else {
const newMethodInfoMap: Map<string, ApiInfo> = DiffHelper.setmethodInfoMap(newApiInfos);
const oldMethodInfoMap: Map<string, ApiInfo> = DiffHelper.setmethodInfoMap(oldApiInfos);
oldApiInfos.forEach((oldApiInfo: ApiInfo) => {
const newApiInfo: ApiInfo | undefined = newMethodInfoMap.get(oldApiInfo.getDefinedText());
if (newApiInfo) {
DiffProcessorHelper.JsDocDiffHelper.diffJsDocInfo(oldApiInfo, newApiInfo, diffInfos, isAllDeprecated);
DiffProcessorHelper.ApiDecoratorsDiffHelper.diffDecorator(oldApiInfo, newApiInfo, diffInfos);
newMethodInfoMap.delete(oldApiInfo.getDefinedText());
oldMethodInfoMap.delete(oldApiInfo.getDefinedText());
}
});
const oldApiDefinedText = this.joinApiText(oldMethodInfoMap);
const newApiDefinedText = this.joinApiText(newMethodInfoMap);
const diffTypeInfo: DiffTypeInfo = new DiffTypeInfo();
diffTypeInfo
.setOldMessage(oldApiDefinedText)
.setNewMessage(newApiDefinedText)
.setDiffType(ApiDiffType.FUNCTION_CHANGES);
diffInfos.push(DiffProcessorHelper.wrapDiffInfo(oldApiInfos[0], newApiInfos[0], diffTypeInfo));
}
}
static diffSameNumberFunction(
@ -227,6 +278,55 @@ export class DiffHelper {
}
}
static judgeIsAllDeprecated(apiInfos: ApiInfo[]): boolean {
let isAllDeprecated: boolean = true;
apiInfos.forEach((apiInfo: ApiInfo)=>{
const deprecatedVersion = apiInfo.getLastJsDocInfo()?.getDeprecatedVersion();
if (deprecatedVersion === '-1' || !deprecatedVersion) {
isAllDeprecated = false;
}
});
return isAllDeprecated;
}
static handleDeprecatedVersion(apiInfos: ApiInfo[]) {
let isAllDeprecated: boolean = true;
apiInfos.forEach((apiInfo: ApiInfo)=>{
const deprecatedVersion = apiInfo.getLastJsDocInfo()?.getDeprecatedVersion();
if (deprecatedVersion === '-1' || !deprecatedVersion) {
isAllDeprecated = false;
}
});
if (isAllDeprecated) {
return;
}
apiInfos.forEach((apiInfo: ApiInfo)=>{
apiInfo.getLastJsDocInfo()?.setDeprecatedVersion('-1');
})
}
/**
* API声明
*
* @param methodInfoMap
* @returns
*/
static joinApiText(methodInfoMap: Map<string, ApiInfo>): string {
let allApiText: string = '';
const apiTextArr: string[] = [];
for (const apiText of methodInfoMap.keys()) {
apiTextArr.push(apiText);
}
return apiTextArr.join(' #&# ');
}
/**
* mapkey为API声明value为API信息
*
* @param apiInfos
* @returns
*/
static setmethodInfoMap(apiInfos: ApiInfo[]): Map<string, ApiInfo> {
const methodInfoMap: Map<string, ApiInfo> = new Map();
apiInfos.forEach((apiInfo: ApiInfo) => {
@ -235,6 +335,13 @@ export class DiffHelper {
return methodInfoMap;
}
/**
* API
*
* @param oldApiInfos
* @param newApiInfos
* @returns
*/
static getDiffSet(oldApiInfos: ApiInfo[], newApiInfos: ApiInfo[]): Map<string, ApiInfo>[] {
const oldApiInfoMap: Map<string, ApiInfo> = new Map();
const newApiInfoMap: Map<string, ApiInfo> = new Map();
@ -353,7 +460,7 @@ export class DiffHelper {
if (/\@[S|s][Y|y][S|s][C|c][A|a][P|p]\s*((\w|\.|\/|\{|\@|\}|\s)+)/g.test(sourceFileContent)) {
sourceFileContent.replace(
/\@[S|s][Y|y][S|s][C|c][A|a][P|p]\s*((\w|\.|\/|\{|\@|\}|\s)+)/g,
(sysCapInfo: string, args:[]) => {
(sysCapInfo: string, args: []) => {
syscap = sysCapInfo.replace(/\@[S|s][Y|y][S|s][C|c][A|a][P|p]/g, '').trim();
return syscap;
}

View File

@ -96,6 +96,7 @@ export class Parser {
}
const sourceFileInfo: ApiInfo = new ApiInfo(ApiType.SOURCE_FILE, sourceFile, undefined);
sourceFileInfo.setFilePath(relFilePath);
sourceFileInfo.setFileAbsolutePath(filePath);
sourceFileInfo.setApiName(relFilePath);
sourceFileInfo.setIsStruct(filePath.endsWith(StringConstant.ETS_EXTENSION));
const currentApiMap: FileInfoMap = new Map();

View File

@ -203,7 +203,8 @@ export class ApiStatisticsHelper {
.setApiName(apiInfo.getApiName())
.setPos(apiInfo.getPos())
.setHierarchicalRelations(relations.join('/'))
.setDecorators(apiInfo.getDecorators());
.setDecorators(apiInfo.getDecorators())
.setAbsolutePath(apiInfo.getFileAbsolutePath());
if (notJsDocApiTypes.has(apiInfo.getApiType())) {
return apiStatisticsInfo;
}

View File

@ -14,7 +14,7 @@
*/
import ts from 'typescript';
import { ApiInfo, MethodInfo } from '../parser/ApiInfoDefination';
import { ApiInfo, MethodInfo, ApiType } from '../parser/ApiInfoDefination';
import { Comment } from '../parser/Comment';
import { NumberConstant } from '../../utils/Constant';
export class BasicDiffInfo {
@ -60,7 +60,7 @@ export class BasicDiffInfo {
newSyscapField: string = '';
//kit信息
oldKitInfo: string = '';
newKitInfo: string = '';
newKitInfo:string = '';
setApiType(apiType: string): BasicDiffInfo {
if (apiType) {
@ -341,8 +341,147 @@ export class DiffTypeInfo {
return this;
}
}
export class DiffNumberInfo {
apiName: string = '';
kitName: string = '';
subsystem: string = '';
apiType: string = '';
allDiffType: string[] = [];
allChangeType: string[] = [];
compatibleInfo: object = {};
oldDiffMessage: string[] = [];
newDiffMessage: string[] = [];
allCompatible: boolean[] = [];
diffTypeNumber: number = 0;
isApi: boolean = true;
apiRelation: string = '';
setApiName(apiName: string): DiffNumberInfo {
this.apiName = apiName;
return this;
}
getApiName(): string {
return this.apiName;
}
setKitName(kitName: string | undefined): DiffNumberInfo {
if (!kitName) {
return this;
}
this.kitName = kitName;
return this;
}
getKitName(): string {
return this.kitName;
}
setSubsystem(subsystem: string | undefined): DiffNumberInfo {
if (!subsystem) {
return this;
}
this.subsystem = subsystem;
return this;
}
getSubsystem(): string {
return this.subsystem;
}
setApiType(apiType: string): DiffNumberInfo {
this.apiType = apiType;
return this;
}
getApiType(): string {
return this.apiType;
}
setAllDiffType(diffType: string): DiffNumberInfo{
this.allDiffType.push(diffType);
return this;
}
getAllDiffType(): string[] {
return this.allDiffType;
}
setOldDiffMessage(oldDiffMessage: string): DiffNumberInfo {
if (oldDiffMessage === '-1') {
return this;
}
this.oldDiffMessage.push(oldDiffMessage);
return this;
}
getOldDiffMessage(): string[] {
return this.oldDiffMessage;
}
setNewDiffMessage(newDiffMessage: string): DiffNumberInfo {
if (newDiffMessage === '-1') {
return this;
}
this.newDiffMessage.push(newDiffMessage);
return this;
}
getNewDiffMessage(): string[] {
return this.newDiffMessage;
}
setAllChangeType(changeType: string | undefined): DiffNumberInfo{
if (!changeType) {
return this
}
this.allChangeType.push(changeType);
return this;
}
getAllChangeType(): string[] {
return this.allChangeType;
}
setAllCompatible(isCompatible: boolean): DiffNumberInfo{
this.allCompatible.push(isCompatible);
return this;
}
getAllCompatible(): boolean[] {
return this.allCompatible;
}
setDiffTypeNumber(diffTypeNumber: number): DiffNumberInfo {
this.diffTypeNumber = diffTypeNumber;
return this;
}
getDiffTypeNumber(): number {
return this.diffTypeNumber;
}
setIsApi(isApi: boolean) {
this.isApi = isApi;
return this;
}
getIsApi(): boolean {
return this.isApi;
}
setApiRelation(apiRelation: string) {
this.apiRelation = apiRelation;
return this;
}
getApiRelation(): string{
return this.apiRelation;
}
}
export interface JsDocDiffProcessor {
(oldJsDocInfo: Comment.JsDocInfo | undefined, newJsDocInfo: Comment.JsDocInfo | undefined): DiffTypeInfo | undefined;
(oldJsDocInfo: Comment.JsDocInfo | undefined, newJsDocInfo: Comment.JsDocInfo | undefined, isAllDeprecated?: boolean, isAllSheet?: boolean): DiffTypeInfo | undefined;
}
export interface ApiSceneDiffProcessor {
@ -408,6 +547,7 @@ export enum ApiDiffType {
DEPRECATED_NA_TO_HAVE,
DEPRECATED_HAVE_TO_NA,
DEPRECATED_A_TO_B,
DEPRECATED_NOT_All,
ERROR_CODE_NA_TO_HAVE,
ERROR_CODE_ADD,
ERROR_CODE_REDUCE,
@ -447,6 +587,8 @@ export enum ApiDiffType {
/** 函数的参数类型范围缩小 */
FUNCTION_PARAM_TYPE_REDUCE,
FUNCTION_PARAM_CHANGE,
/** 同名函数变更类型 */
FUNCTION_CHANGES,
PROPERTY_READONLY_TO_UNREQUIRED,
PROPERTY_READONLY_TO_REQUIRED,
PROPERTY_WRITABLE_TO_UNREQUIRED,
@ -512,6 +654,7 @@ export const diffTypeMap: Map<ApiDiffType, string> = new Map([
[ApiDiffType.SYSCAP_A_TO_B, 'syscap变更'],
[ApiDiffType.DEPRECATED_NA_TO_HAVE, 'API废弃版本变更'],
[ApiDiffType.DEPRECATED_HAVE_TO_NA, 'API废弃版本变更'],
[ApiDiffType.DEPRECATED_NOT_All, 'API废弃版本变更'],
[ApiDiffType.DEPRECATED_A_TO_B, 'API废弃版本变更'],
[ApiDiffType.ERROR_CODE_NA_TO_HAVE, '错误码变更'],
[ApiDiffType.ERROR_CODE_ADD, '错误码变更'],
@ -540,6 +683,7 @@ export const diffTypeMap: Map<ApiDiffType, string> = new Map([
[ApiDiffType.FUNCTION_PARAM_TYPE_ADD, '函数变更'],
[ApiDiffType.FUNCTION_PARAM_TYPE_REDUCE, '函数变更'],
[ApiDiffType.FUNCTION_PARAM_CHANGE, '函数变更'],
[ApiDiffType.FUNCTION_CHANGES, '函数变更'],
[ApiDiffType.PROPERTY_READONLY_TO_UNREQUIRED, '属性变更'],
[ApiDiffType.PROPERTY_READONLY_TO_REQUIRED, '属性变更'],
[ApiDiffType.PROPERTY_WRITABLE_TO_UNREQUIRED, '属性变更'],
@ -597,6 +741,7 @@ export const diffMap: Map<ApiDiffType, string> = new Map([
[ApiDiffType.SYSCAP_A_TO_B, 'syscap发生改变'],
[ApiDiffType.DEPRECATED_NA_TO_HAVE, '接口变更为废弃'],
[ApiDiffType.DEPRECATED_HAVE_TO_NA, '废弃接口变更为不废弃'],
[ApiDiffType.DEPRECATED_NOT_All, '接口变更为废弃'],
[ApiDiffType.DEPRECATED_A_TO_B, '接口废弃版本发生变化'],
[ApiDiffType.ERROR_CODE_NA_TO_HAVE, '错误码从无到有'],
[ApiDiffType.ERROR_CODE_ADD, '错误码增加'],
@ -625,6 +770,7 @@ export const diffMap: Map<ApiDiffType, string> = new Map([
[ApiDiffType.FUNCTION_PARAM_TYPE_ADD, '函数的参数类型范围扩大'],
[ApiDiffType.FUNCTION_PARAM_TYPE_REDUCE, '函数的参数类型范围缩小'],
[ApiDiffType.FUNCTION_PARAM_CHANGE, '函数的参数变更'],
[ApiDiffType.FUNCTION_CHANGES, '函数有变化'],
[ApiDiffType.PROPERTY_READONLY_TO_UNREQUIRED, '只读属性由必选变为可选'],
[ApiDiffType.PROPERTY_READONLY_TO_REQUIRED, '只读属性由可选变为必选'],
[ApiDiffType.PROPERTY_WRITABLE_TO_UNREQUIRED, '可写属性由必选变为可选'],
@ -666,6 +812,80 @@ export const diffMap: Map<ApiDiffType, string> = new Map([
[ApiDiffType.ATOMIC_SERVICE_NA_TO_HAVE, 'API从不支持元服务到支持元服务'],
]);
export const apiChangeMap: Map<ApiDiffType, string> = new Map([
[ApiDiffType.SYSTEM_TO_PUBLIC, 'API修改约束变化'],
[ApiDiffType.PUBLIC_TO_SYSTEM, 'API修改约束变化'],
[ApiDiffType.NA_TO_STAGE, 'API修改约束变化'],
[ApiDiffType.NA_TO_FA, 'API修改约束变化'],
[ApiDiffType.FA_TO_STAGE, 'API修改约束变化'],
[ApiDiffType.STAGE_TO_FA, 'API修改约束变化'],
[ApiDiffType.STAGE_TO_NA, 'API修改约束变化'],
[ApiDiffType.FA_TO_NA, 'API修改约束变化'],
[ApiDiffType.NA_TO_CARD, 'API修改约束变化'],
[ApiDiffType.CARD_TO_NA, 'API修改约束变化'],
[ApiDiffType.NA_TO_CROSS_PLATFORM, 'API修改约束变化'],
[ApiDiffType.CROSS_PLATFORM_TO_NA, 'API修改约束变化'],
[ApiDiffType.SYSCAP_NA_TO_HAVE, 'API修改约束变化'],
[ApiDiffType.SYSCAP_HAVE_TO_NA, 'API修改约束变化'],
[ApiDiffType.SYSCAP_A_TO_B, 'API修改约束变化'],
[ApiDiffType.DEPRECATED_NA_TO_HAVE, 'API废弃'],
[ApiDiffType.DEPRECATED_HAVE_TO_NA, 'API废弃'],
[ApiDiffType.DEPRECATED_NOT_All, 'API修改约束变化'],
[ApiDiffType.DEPRECATED_A_TO_B, 'API废弃'],
[ApiDiffType.ERROR_CODE_NA_TO_HAVE, 'API修改约束变化'],
[ApiDiffType.ERROR_CODE_ADD, 'API修改原型修改'],
[ApiDiffType.ERROR_CODE_REDUCE, 'API修改原型修改'],
[ApiDiffType.ERROR_CODE_CHANGE, 'API修改原型修改'],
[ApiDiffType.PERMISSION_NA_TO_HAVE, 'API修改约束变化'],
[ApiDiffType.PERMISSION_HAVE_TO_NA, 'API修改约束变化'],
[ApiDiffType.PERMISSION_RANGE_BIGGER, 'API修改约束变化'],
[ApiDiffType.PERMISSION_RANGE_SMALLER, 'API修改约束变化'],
[ApiDiffType.PERMISSION_RANGE_CHANGE, 'API修改约束变化'],
[ApiDiffType.TYPE_RANGE_BIGGER, 'API修改原型修改'],
[ApiDiffType.TYPE_RANGE_SMALLER, 'API修改原型修改'],
[ApiDiffType.TYPE_RANGE_CHANGE, 'API修改原型修改'],
[ApiDiffType.API_NAME_CHANGE, 'API修改原型修改'],
[ApiDiffType.FUNCTION_RETURN_TYPE_ADD, 'API修改原型修改'],
[ApiDiffType.FUNCTION_RETURN_TYPE_REDUCE, 'API修改原型修改'],
[ApiDiffType.FUNCTION_RETURN_TYPE_CHANGE, 'API修改原型修改'],
[ApiDiffType.FUNCTION_PARAM_POS_CHANGE, 'API修改原型修改'],
[ApiDiffType.FUNCTION_PARAM_UNREQUIRED_ADD, 'API修改原型修改'],
[ApiDiffType.FUNCTION_PARAM_REQUIRED_ADD, 'API修改原型修改'],
[ApiDiffType.FUNCTION_PARAM_REDUCE, 'API修改原型修改'],
[ApiDiffType.FUNCTION_PARAM_TO_UNREQUIRED, 'API修改原型修改'],
[ApiDiffType.FUNCTION_PARAM_TO_REQUIRED, 'API修改原型修改'],
[ApiDiffType.FUNCTION_PARAM_NAME_CHANGE, 'API修改原型修改'],
[ApiDiffType.FUNCTION_PARAM_TYPE_CHANGE, 'API修改原型修改'],
[ApiDiffType.FUNCTION_PARAM_TYPE_ADD, 'API修改原型修改'],
[ApiDiffType.FUNCTION_PARAM_TYPE_REDUCE, 'API修改原型修改'],
[ApiDiffType.FUNCTION_CHANGES, 'API修改原型修改'],
[ApiDiffType.PROPERTY_READONLY_TO_UNREQUIRED, 'API修改约束变化'],
[ApiDiffType.PROPERTY_READONLY_TO_REQUIRED, 'API修改约束变化'],
[ApiDiffType.PROPERTY_WRITABLE_TO_UNREQUIRED, 'API修改约束变化'],
[ApiDiffType.PROPERTY_WRITABLE_TO_REQUIRED, 'API修改约束变化'],
[ApiDiffType.PROPERTY_TYPE_CHANGE, 'API修改原型修改'],
[ApiDiffType.PROPERTY_READONLY_ADD, 'API修改约束变化'],
[ApiDiffType.PROPERTY_READONLY_REDUCE, 'API修改约束变化'],
[ApiDiffType.PROPERTY_WRITABLE_ADD, 'API修改约束变化'],
[ApiDiffType.PROPERTY_WRITABLE_REDUCE, 'API修改约束变化'],
[ApiDiffType.CONSTANT_VALUE_CHANGE, 'API修改原型修改'],
[ApiDiffType.TYPE_ALIAS_CHANGE, 'API修改原型修改'],
[ApiDiffType.TYPE_ALIAS_ADD, 'API修改原型修改'],
[ApiDiffType.TYPE_ALIAS_REDUCE, 'API修改原型修改'],
[ApiDiffType.ENUM_MEMBER_VALUE_CHANGE, 'API修改原型修改'],
[ApiDiffType.ADD, 'API新增'],
[ApiDiffType.REDUCE, 'API删除'],
[ApiDiffType.DELETE_DECORATOR, 'API修改约束变化'],
[ApiDiffType.NEW_DECORATOR, 'API修改约束变化'],
[ApiDiffType.SINCE_VERSION_A_TO_B, 'API修改约束变化'],
[ApiDiffType.SINCE_VERSION_HAVE_TO_NA, 'API修改约束变化'],
[ApiDiffType.SINCE_VERSION_NA_TO_HAVE, 'API修改约束变化'],
[ApiDiffType.KIT_CHANGE, '非API变更'],
]);
/**
*
*/
export const incompatibleApiDiffTypes: Set<ApiDiffType> = new Set([
ApiDiffType.PUBLIC_TO_SYSTEM,
ApiDiffType.NA_TO_STAGE,
@ -689,6 +909,7 @@ export const incompatibleApiDiffTypes: Set<ApiDiffType> = new Set([
ApiDiffType.FUNCTION_PARAM_TYPE_CHANGE,
ApiDiffType.FUNCTION_PARAM_TYPE_REDUCE,
ApiDiffType.FUNCTION_PARAM_CHANGE,
ApiDiffType.FUNCTION_CHANGES,
ApiDiffType.PROPERTY_READONLY_TO_REQUIRED,
ApiDiffType.PROPERTY_WRITABLE_TO_UNREQUIRED,
ApiDiffType.PROPERTY_WRITABLE_TO_REQUIRED,
@ -711,4 +932,10 @@ export const incompatibleApiDiffTypes: Set<ApiDiffType> = new Set([
ApiDiffType.TYPE_ALIAS_FUNCTION_PARAM_CHANGE,
ApiDiffType.ATOMIC_SERVICE_HAVE_TO_NA,
ApiDiffType.DELETE_DECORATOR,
]);
]);
export const isNotApiSet: Set<string> = new Set([
ApiType.NAMESPACE,
ApiType.ENUM,
ApiType.SOURCE_FILE,
])

View File

@ -67,6 +67,7 @@ export class BasicApiInfo {
isJoinType: boolean = false;
genericInfo: GenericInfo[] = [];
parentApiType: string | undefined = '';
fileAbsolutePath: string = ''; //绝对路径
constructor(apiType: string = '', node: ts.Node, parentApi: BasicApiInfo | undefined) {
this.node = node;
@ -74,6 +75,7 @@ export class BasicApiInfo {
this.setParentApiType(parentApi?.getApiType())
if (parentApi) {
this.setFilePath(parentApi.getFilePath());
this.setFileAbsolutePath(parentApi.getFileAbsolutePath())
this.setIsStruct(parentApi.getIsStruct());
}
this.setApiType(apiType);
@ -106,6 +108,14 @@ export class BasicApiInfo {
return this.filePath;
}
setFileAbsolutePath(absolutePath: string): void {
this.fileAbsolutePath = absolutePath;
}
getFileAbsolutePath(): string {
return this.fileAbsolutePath;
}
setApiType(apiType: string): void {
this.apiType = apiType as ApiType;
}

View File

@ -50,6 +50,8 @@ export class ApiStatisticsInfo {
decorators: Array<string> | undefined = [];
errorCodes: number[] = [];
kitInfo: string = '';
absolutePath: string = ''; //文件绝对路径
setFilePath(fileFilePath: string): ApiStatisticsInfo {
this.filePath = fileFilePath;
this.packageName = FunctionUtils.getPackageName(fileFilePath);
@ -238,6 +240,15 @@ export class ApiStatisticsInfo {
getKitInfo(): string {
return this.kitInfo;
}
setAbsolutePath(absolutePath: string): ApiStatisticsInfo {
this.absolutePath = absolutePath;
return this;
}
getAbsolutePath(): string {
return this.absolutePath;
}
}
/**

View File

@ -14,11 +14,9 @@
*/
import path from 'path';
import fs from 'fs';
import { FileUtils } from './FileUtils';
import { NumberConstant } from './Constant';
import { kitData } from '../../kit.json'
import { fileContent } from '../../subsystem.json'
import { kitData } from '../../kit.json';
import { fileContent } from '../../subsystem.json';
export class FunctionUtils {
/**