1/* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15const fs = require("fs"); 16const path = require("path"); 17 18function getAPINote(node) { 19 return node.getFullText().replace(node.getText(), ""); 20} 21exports.getAPINote = getAPINote; 22 23function hasAPINote(node) { 24 const apiNote = getAPINote(node).replace(/[\s]/g, ""); 25 if (apiNote && apiNote.length !== 0) { 26 return true; 27 } 28 return false; 29} 30exports.hasAPINote = hasAPINote; 31 32function removeDir(url) { 33 let statObj = fs.statSync(url); 34 if (statObj.isDirectory()) { 35 let dirs = fs.readdirSync(url); 36 dirs = dirs.map(dir => path.join(url, dir)); 37 for (let i = 0; i < dirs.length; i++) { 38 removeDir(dirs[i]); 39 } 40 fs.rmdirSync(url); 41 } else { 42 fs.unlinkSync(url); 43 } 44} 45exports.removeDir = removeDir; 46 47function writeResultFile(resultData, outputPath, option) { 48 fs.writeFile(path.resolve(__dirname, outputPath), JSON.stringify(resultData, null, 2), option, err => { 49 if (err) { 50 console.error(`ERROR FOR CREATE FILE:${err}`); 51 } else { 52 console.log('API CHECK FINISH!'); 53 } 54 }) 55} 56exports.writeResultFile = writeResultFile; 57 58function overwriteIndexOf(item, array) { 59 let indexArr = []; 60 for (var i = 0; i < array.length; i++) { 61 if (array[i] === item) { 62 indexArr.push(i); 63 } 64 } 65 return indexArr; 66} 67exports.overwriteIndexOf = overwriteIndexOf; 68 69const error_type = { 70 UNKNOW_DECORATOR: 'unknow decorator', 71 MISSPELL_WORDS: 'misspell words', 72 NAMING_ERRORS: 'naming errors', 73 UNKNOW_PERMISSION: 'unknow permission', 74 UNKNOW_SYSCAP: 'unknow syscap', 75 UNKNOW_DEPRECATED: 'unknow deprecated', 76 INVALID_IMPORT: 'invalid import' 77} 78exports.error_type = error_type; 79