• 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 { JSDocModifierImpl } from './core/entry';
17import type { IJSDocModifier } from './core/typedef';
18import { ConstantValue, StringResourceId } from './utils/constant';
19import { StringResource, StringUtils } from './utils/stringUtils';
20
21function main(): void {
22  checkEnvVersion();
23  const jsDocModifier: IJSDocModifier = new JSDocModifierImpl();
24  jsDocModifier.start();
25}
26
27function checkEnvVersion(): void {
28  const version = process.version;
29  const versionRegExp = /^v(\d+)\.(\d+)\.(\d+).*/;
30  const matchArray = version.match(versionRegExp);
31  const requiredVersions = [ConstantValue.MAJOR_V, ConstantValue.MINOR_V, ConstantValue.PATCH_V];
32  let showVersionWarning = true;
33  const MAX_LENGTH = 4;
34  const LOOP_MAX_LENGTH = 3;
35  if (matchArray && matchArray.length === MAX_LENGTH) {
36    for (let index = 0; index < LOOP_MAX_LENGTH; index++) {
37      const curV = Number(matchArray[index + 1]);
38      const requiredV = requiredVersions[index];
39      if (curV > requiredV || curV < requiredV) {
40        showVersionWarning = curV > requiredV;
41        break;
42      } else {
43        continue;
44      }
45    }
46  }
47  if (showVersionWarning) {
48    return;
49  }
50  let hintMessage = StringResource.getString(StringResourceId.VERSION_HINT);
51  hintMessage = StringUtils.formatString(hintMessage, requiredVersions);
52  console.warn('jsdoc-tool:', hintMessage);
53}
54
55main();