sdadfadas

Форк
0
/
generate_frontend_class_component_tasklist.js 
73 строки · 2.7 Кб
1
/**
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19

20
// Run this from the superset-frontend directory with
21
// `node ../scripts/generate_frontend_ts_tasklist.js `, then copy and paste the output into
22
// https://github.com/apache/superset/discussions/26076
23
const { readdirSync, readFileSync } = require("fs");
24
const process = require("process");
25

26
const INITIAL_DIRECTORIES = ["spec", "src", "packages"];
27
const DEFAULT_DIRECTORY = process.cwd();
28

29
const getDirectories = (source) =>
30
  readdirSync(source, { withFileTypes: true })
31
    .filter((dirent) => dirent.isDirectory())
32
    .map((dirent) => dirent.name);
33

34
const getFilesByExtensions = (source, extensions) =>
35
  readdirSync(source, { withFileTypes: true })
36
    .filter((dirent) =>
37
      extensions.some((extension) => dirent.name.endsWith(extension))
38
    )
39
    .map((dirent) => dirent.name);
40

41
const hasClassComponent = (filePath) => {
42
  const fileContent = readFileSync(filePath, "utf8");
43
  const classComponentRegex =
44
    /class\s+\w+\s+extends\s+(React\.Component|React\.PureComponent)/g;
45
  return classComponentRegex.test(fileContent);
46
};
47

48
let directories = INITIAL_DIRECTORIES;
49

50
while (directories.length) {
51
  const curDirectory = directories.pop();
52
  process.chdir(curDirectory);
53
  // Check for existence of class components in js, jsx, ts, and tsx files. Show an empty box if
54
  // it has a class Component and a filled box if it does not.
55
  const files = getFilesByExtensions("./", [".js", ".jsx", ".ts", ".tsx"]);
56

57
  if (files.length > 0) {
58
    const hasClassComponents = files.some((file) =>
59
      hasClassComponent(`./${file}`)
60
    );
61
    if (hasClassComponents) {
62
      console.log(`- [ ] \`${curDirectory}\``);
63
    }
64
  }
65

66
  directories = directories.concat(
67
    getDirectories("./")
68
      .reverse() // For ABC order when pushed into the Array
69
      .filter((name) => name !== "node_modules") // Don't include node_modules in our packages
70
      .map((directory) => `${curDirectory}/${directory}`)
71
  );
72
  process.chdir(DEFAULT_DIRECTORY);
73
}
74

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.