fix(automate): fix reviews comments (#1187)

This commit is contained in:
ajaxzheng 2023-12-20 16:11:18 +08:00 committed by GitHub
parent c4a7391bdd
commit 642e31eee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 23 deletions

View File

@ -12,6 +12,9 @@
"fs-extra": "^11.2.0",
"esno": "^4.0.0"
},
"devDependencies": {
"@types/node": "^20.10.5"
},
"keywords": [],
"author": "",
"license": "ISC"

View File

@ -1,31 +1,24 @@
import path from 'node:path'
import fs from 'fs-extra'
import { findAllFiles } from './utils/find-all-files'
const demo = path.resolve('../../examples/sites/demos/pc/app')
let apiSize = 0
let apiLength = 0
let compNumber = 0
// 递归遍历所有的组件,然后依次修改文件内容和修改文件格式
const findAllpage = (packagesPath) => {
if (fs.statSync(packagesPath).isDirectory()) {
fs.readdirSync(packagesPath).forEach((childPatch) => {
findAllpage(path.join(packagesPath, childPatch))
})
} else {
if (packagesPath.includes('webdoc') && packagesPath.endsWith('.js')) {
const stats = fs.statSync(packagesPath)
const string = fs.readFileSync(packagesPath, 'utf8').replace(/\s/g, '')
compNumber++
apiLength += string.length
apiSize += stats.size
}
}
}
const demoUrl = path.join(process.cwd(), '../../examples/sites/demos/pc/app')
export const statistics = () => {
findAllpage(demo)
let apiSize = 0
let apiLength = 0
let compNumber = 0
const readAndProcessFile = (filePath) => {
const stats = fs.statSync(filePath)
const string = fs.readFileSync(filePath, 'utf8').replace(/\s/g, '')
compNumber++
apiLength += string.length
apiSize += stats.size
}
findAllFiles(demoUrl, readAndProcessFile)
return {
apiSize,
apiLength,

View File

@ -0,0 +1,25 @@
import fs from 'fs-extra'
import path from 'node:path'
/**
* @param packagesPath {String}
* @param callback {Function}
*/
export const findAllFiles = (packagesPath: string, callback: (path: string) => void) => {
const findAllpage = (packagesPath) => {
try {
if (fs.statSync(packagesPath).isDirectory()) {
fs.readdirSync(packagesPath).forEach((childPatch) => {
findAllpage(path.join(packagesPath, childPatch))
})
} else {
if (packagesPath.includes('webdoc') && packagesPath.endsWith('.js')) {
callback(packagesPath)
}
}
} catch (error) {
console.error(`Error processing ${packagesPath}: ${error.message}`)
}
}
findAllpage(packagesPath)
}

View File

@ -0,0 +1,18 @@
{
"compilerOptions": {
"module": "ESNext",
"target": "esnext",
"moduleResolution": "node",
"strict": true,
"declaration": true,
"noUnusedLocals": true,
"esModuleInterop": true,
"outDir": "dist",
"lib": ["ESNext"],
"sourceMap": false,
"noEmitOnError": true,
"noImplicitAny": false
},
"include": ["src/**/*", "*.d.ts"],
"exclude": ["dist", "node_modules"]
}