sdadfadas
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
23const { readdirSync, readFileSync } = require("fs");24const process = require("process");25
26const INITIAL_DIRECTORIES = ["spec", "src", "packages"];27const DEFAULT_DIRECTORY = process.cwd();28
29const getDirectories = (source) =>30readdirSync(source, { withFileTypes: true })31.filter((dirent) => dirent.isDirectory())32.map((dirent) => dirent.name);33
34const getFilesByExtensions = (source, extensions) =>35readdirSync(source, { withFileTypes: true })36.filter((dirent) =>37extensions.some((extension) => dirent.name.endsWith(extension))38)39.map((dirent) => dirent.name);40
41const hasClassComponent = (filePath) => {42const fileContent = readFileSync(filePath, "utf8");43const classComponentRegex =44/class\s+\w+\s+extends\s+(React\.Component|React\.PureComponent)/g;45return classComponentRegex.test(fileContent);46};47
48let directories = INITIAL_DIRECTORIES;49
50while (directories.length) {51const curDirectory = directories.pop();52process.chdir(curDirectory);53// Check for existence of class components in js, jsx, ts, and tsx files. Show an empty box if54// it has a class Component and a filled box if it does not.55const files = getFilesByExtensions("./", [".js", ".jsx", ".ts", ".tsx"]);56
57if (files.length > 0) {58const hasClassComponents = files.some((file) =>59hasClassComponent(`./${file}`)60);61if (hasClassComponents) {62console.log(`- [ ] \`${curDirectory}\``);63}64}65
66directories = directories.concat(67getDirectories("./")68.reverse() // For ABC order when pushed into the Array69.filter((name) => name !== "node_modules") // Don't include node_modules in our packages70.map((directory) => `${curDirectory}/${directory}`)71);72process.chdir(DEFAULT_DIRECTORY);73}
74