• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 - 2025 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 */
15import Logger, { LOG_MODULE_TYPE } from 'arkanalyzer/lib/utils/logger';
16import { processAfterCheck } from './utils/common/AfterCheck';
17import { CheckEntry, checkEntryBuilder, getSelectFileList } from './utils/common/CheckEntry';
18import { ConfigUtils } from './utils/common/ConfigUtils';
19import { DefaultMessage } from './model/Message';
20import { Utils } from './utils/common/Utils';
21
22const logger = Logger.getLogger(LOG_MODULE_TYPE.HOMECHECK, 'Main');
23
24export async function start(checkEntry: CheckEntry): Promise<boolean> {
25    // 外部没有建立消息通道,使用默认通道
26    if (!checkEntry.message) {
27        checkEntry.message = new DefaultMessage();
28    }
29
30    // 前处理
31    if (!await checkEntryBuilder(checkEntry)) {
32        return false;
33    }
34
35    // 开始检查
36    await checkEntry.runAll();
37
38    // 后处理
39    await processAfterCheck(checkEntry);
40    logger.info('Checking completed.');
41    return true;
42}
43
44export async function run(): Promise<boolean> {
45    const startTime = new Date().getTime();
46    const checkEntry = new CheckEntry();
47    // 构建ruleConfig和projectConfig,保存至checkEntry中
48    if (!ConfigUtils.parseConfig(Utils.parseCliOptions(process.argv), checkEntry)) {
49        return false;
50    }
51
52    // 设置指定文件检查,不设置默认检查所有文件
53    checkEntry.setCheckFileList(getSelectFileList(checkEntry.projectConfig.checkPath));
54
55    // 启动homecheck检查
56    await start(checkEntry);
57
58    const endTime = new Date().getTime();
59    logger.info(`HomeCheck took: ${(endTime - startTime) / 1000} s.`);
60    return true;
61};