/* * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const fs = require("fs"); const path = require("path"); function getAPINote(node) { return node.getFullText().replace(node.getText(), ""); } exports.getAPINote = getAPINote; function hasAPINote(node) { const apiNote = getAPINote(node).replace(/[\s]/g, ""); if (apiNote && apiNote.length !== 0) { return true; } return false; } exports.hasAPINote = hasAPINote; function removeDir(url) { let statObj = fs.statSync(url); if (statObj.isDirectory()) { let dirs = fs.readdirSync(url); dirs = dirs.map(dir => path.join(url, dir)); for (let i = 0; i < dirs.length; i++) { removeDir(dirs[i]); } fs.rmdirSync(url); } else { fs.unlinkSync(url); } } exports.removeDir = removeDir; function writeResultFile(resultData, outputPath, option) { fs.writeFile(path.resolve(__dirname, outputPath), JSON.stringify(resultData, null, 2), option, err => { if (err) { console.error(`ERROR FOR CREATE FILE:${err}`); } else { console.log('API CHECK FINISH!'); } }) } exports.writeResultFile = writeResultFile; function overwriteIndexOf(item, array) { let indexArr = []; for (var i = 0; i < array.length; i++) { if (array[i] === item) { indexArr.push(i); } } return indexArr; } exports.overwriteIndexOf = overwriteIndexOf; const error_type = { UNKNOW_DECORATOR: 'unknow decorator', MISSPELL_WORDS: 'misspell words', NAMING_ERRORS: 'naming errors', UNKNOW_PERMISSION: 'unknow permission', UNKNOW_SYSCAP: 'unknow syscap', UNKNOW_DEPRECATED: 'unknow deprecated', INVALID_IMPORT: 'invalid import' } exports.error_type = error_type;