• 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 rollupObject 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 os from 'os';
17import fs from "fs";
18import path from "path";
19import { PROJECT_ROOT } from "../mock/rollup_mock/path_config";
20import { DEFAULT_PROJECT } from "../mock/rollup_mock/path_config";
21
22export function cpus() {
23  return os.cpus().length < 16 ? os.cpus().length : 16;
24}
25
26export function getProjectPath(name?: string) {
27  return name ? `${PROJECT_ROOT}/${name}` : `${PROJECT_ROOT}/${DEFAULT_PROJECT}`;
28}
29
30export function scanFiles(filepath: string, fileList: Set<string>) {
31  if (!fs.existsSync(filepath)) {
32    return;
33  }
34  const files = fs.readdirSync(filepath);
35  files.forEach((file) => {
36    const child = path.join(filepath, file);
37    const stat = fs.statSync(child);
38    if (stat.isDirectory()) {
39      scanFiles(child, fileList);
40    } else {
41      fileList.add(child);
42    }
43  });
44}
45export function sleep(ms) {
46  return new Promise(resolve => setTimeout(resolve, ms));
47}
48