• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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 */
15
16import path from 'path';
17
18import { initConfig } from '../common/init_config';
19import { projectConfig } from '../../../main';
20import {
21  serviceChecker,
22  watchChecker
23} from '../../ets_checker';
24
25export function etsChecker() {
26  let executedOnce: boolean = false;
27  return {
28    name: 'etsChecker',
29    buildStart() {
30      if (executedOnce) {
31        return;
32      }
33      Object.assign(projectConfig, this.share.projectConfig);
34      Object.assign(this.share.projectConfig, {
35        compileHar: projectConfig.compileHar,
36        compileShared: projectConfig.compileShared,
37        moduleRootPath: projectConfig.moduleRootPath,
38        buildPath: projectConfig.buildPath
39      });
40      const logger = this.share.getLogger('etsChecker');
41      const rootFileNames: string[] = [];
42      Object.values(projectConfig.entryObj).forEach((fileName: string) => {
43        rootFileNames.push(path.resolve(fileName));
44      });
45      if (process.env.watchMode === 'true') {
46        executedOnce = true;
47        watchChecker(rootFileNames, logger);
48      } else {
49        serviceChecker(rootFileNames, logger);
50      }
51    }
52  };
53}
54
55