mirror of
https://gitee.com/openharmony/interface_sdk-js
synced 2024-11-23 15:20:17 +00:00
commit
9c8db0fef4
@ -17,6 +17,7 @@ const ts = require('typescript');
|
||||
const { ApiDigestInfo } = require('./api_data');
|
||||
const { DiffReporter } = require('./reporter');
|
||||
const { StatusCode } = require('./reporter');
|
||||
const { getCheckApiVersion } = require('../../api_check_plugin/src/utils')
|
||||
|
||||
class TagItem {
|
||||
constructor() { }
|
||||
@ -253,6 +254,7 @@ function compareJSDocs(oldApi, newApi, diffReporter) {
|
||||
const newTagItem = getTagItemFromJSDoc(newApi);
|
||||
const useinstead = getApiUseInstead(newApi);
|
||||
const hint = useinstead.length > 0 ? `useinstead: ${useinstead[0]}` : '';
|
||||
diffHistoricalJsDoc(oldApi, newApi, diffReporter, hint);
|
||||
diffErrorCode(diffReporter, oldTagItem, newTagItem, oldApi, newApi, hint);
|
||||
diffPermission(diffReporter, oldTagItem, newTagItem, oldApi, newApi, hint);
|
||||
diffForm(diffReporter, oldTagItem, newTagItem, oldApi, newApi, hint);
|
||||
@ -263,6 +265,64 @@ function compareJSDocs(oldApi, newApi, diffReporter) {
|
||||
diffType(diffReporter, oldTagItem, newTagItem, oldApi, newApi, hint);
|
||||
}
|
||||
|
||||
function getLatestVersion(jsdocs) {
|
||||
if (!jsdocs) {
|
||||
return;
|
||||
}
|
||||
const jsdoc = jsdocs[jsdocs.length - 1];
|
||||
let apiLatestVersion = '';
|
||||
jsdoc.tags.forEach(tagObject => {
|
||||
if (tagObject.tag === 'since') {
|
||||
apiLatestVersion = tagObject.name;
|
||||
}
|
||||
})
|
||||
return apiLatestVersion;
|
||||
}
|
||||
|
||||
function diffHistoricalJsDoc(oldApi, newApi, diffReporter, hint) {
|
||||
const currentVersion = getCheckApiVersion();
|
||||
const oldJsDocTextArr = oldApi.getAstNode().getFullText().replace(oldApi.getAstNode().getText(), '').split('*/');
|
||||
const newJsDocTextArr = newApi.getAstNode().getFullText().replace(oldApi.getAstNode().getText(), '').split('*/');
|
||||
if (!oldApi.jsdoc) {
|
||||
return;
|
||||
}
|
||||
const oldLatestVersion = getLatestVersion(oldApi.jsdoc);
|
||||
const newLatestVersion = getLatestVersion(newApi.jsdoc);
|
||||
if (oldLatestVersion === currentVersion) {
|
||||
oldJsDocTextArr.splice(-2);
|
||||
} else {
|
||||
oldJsDocTextArr.splice(-1);
|
||||
}
|
||||
|
||||
if (newLatestVersion === currentVersion) {
|
||||
newJsDocTextArr.splice(-2);
|
||||
} else {
|
||||
newJsDocTextArr.splice(-1);
|
||||
}
|
||||
|
||||
if (oldJsDocTextArr.length !== newJsDocTextArr.length) {
|
||||
diffReporter.addDiffInfo(wrapApiChanges(newApi, StatusCode.HOSTORICAL_JSDOC_CHANGE,
|
||||
'',
|
||||
'',
|
||||
hint,
|
||||
oldApi.node,
|
||||
newApi.node
|
||||
));
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < oldJsDocTextArr.length; i++) {
|
||||
if (oldJsDocTextArr[i].replace(/\r|\n|\s+/g, '') !== newJsDocTextArr[i].replace(/\r|\n|\s+/g, '')) {
|
||||
diffReporter.addDiffInfo(wrapApiChanges(newApi, StatusCode.HOSTORICAL_JSDOC_CHANGE,
|
||||
'',
|
||||
'',
|
||||
hint,
|
||||
oldApi.node,
|
||||
newApi.node
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 比较@type
|
||||
*
|
||||
@ -708,7 +768,7 @@ function createTagItemFromJSDoc(jsdocs) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (firstJsDoc.tags) {
|
||||
firstJsDoc.tags.forEach((tagObject) => {
|
||||
if (tagObject.tag.toLowerCase() === 'since') {
|
||||
|
@ -39,6 +39,7 @@ const ApiStatusCode = {
|
||||
CROSSPLATFORM_CHANGED: 20,
|
||||
NEW_DTS: 21,
|
||||
NEW_CLASS: 22,
|
||||
HOSTORICAL_JSDOC_CHANGE: 23
|
||||
};
|
||||
|
||||
const StatusMessages = [];
|
||||
@ -65,6 +66,7 @@ StatusMessages[ApiStatusCode.CHANGELOG] = 'changelog';
|
||||
StatusMessages[ApiStatusCode.DTS_CHANGED] = 'd.ts有变化';
|
||||
StatusMessages[ApiStatusCode.FORM_CHANGED] = '卡片应用支持性有变化';
|
||||
StatusMessages[ApiStatusCode.CROSSPLATFORM_CHANGED] = '跨平台能力有变化';
|
||||
StatusMessages[ApiStatusCode.HOSTORICAL_JSDOC_CHANGE] = '历史jsdoc有变化';
|
||||
|
||||
function reportDeletedApi(api, syscap) {
|
||||
return wrapApiDiffInfo(api, ApiStatusCode.DELETE, '', '', '', syscap);
|
||||
|
Loading…
Reference in New Issue
Block a user