feat(automate): add script projects such as statistics and document automatic error correction (#1179)

This commit is contained in:
ajaxzheng 2023-12-19 16:49:36 +08:00 committed by GitHub
parent e6a9c50645
commit 8857f378d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 34 deletions

View File

@ -1,34 +0,0 @@
const fs = require('fs');
const basePath = './examples/sites/demos/pc/app';
const readFile = function (path) {
let componentCount = 0;
let apiCount = 0;
const readDir = fs.readdirSync(path);
readDir.forEach(i => {
const curDir = `${path}/${i}`;
const stat = fs.statSync(curDir);
if (stat.isFile() && i.endsWith('.js')) {
componentCount += 1;
const data = fs.readFileSync(curDir, 'utf-8');
let dataJson = null;
try {
dataJson = JSON.parse(data);
} catch (err) {
console.log('err:', err);
}
if (dataJson !== null) {
apiCount += (dataJson.attrs?.length || 0) + (dataJson.slots?.length || 0) + (dataJson.events?.length || 0) + (dataJson.methods?.length || 0);
}
}
});
console.log('componentCount:', componentCount);
console.log('apiCount:', apiCount);
}
readFile(basePath);

View File

@ -0,0 +1,17 @@
{
"name": "@opentiny/automate",
"version": "1.0.0",
"description": "",
"main": "./src/index.ts",
"type": "module",
"scripts": {
"start": "esno ./src/index.ts"
},
"dependencies": {
"fs-extra": "^11.2.0",
"esno": "^4.0.0"
},
"keywords": [],
"author": "",
"license": "ISC"
}

View File

@ -0,0 +1,34 @@
import path from 'node:path'
import fs from 'fs-extra'
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
}
}
}
export const statistics = () => {
findAllpage(demo)
return {
apiSize,
apiLength,
compNumber
}
}

View File

@ -0,0 +1,8 @@
/* eslint-disable no-console */
import { statistics } from './count'
const { apiSize, apiLength, compNumber } = statistics()
console.log('apiSize', apiSize)
console.log('apiLength', apiLength)
console.log('compNumber', compNumber)