diff --git a/count-api.js b/count-api.js deleted file mode 100644 index 513ae5d6a..000000000 --- a/count-api.js +++ /dev/null @@ -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); diff --git a/internals/automate/package.json b/internals/automate/package.json new file mode 100644 index 000000000..d4a87e8e9 --- /dev/null +++ b/internals/automate/package.json @@ -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" +} diff --git a/internals/automate/src/count.ts b/internals/automate/src/count.ts new file mode 100644 index 000000000..cc42b7d9d --- /dev/null +++ b/internals/automate/src/count.ts @@ -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 + } +} diff --git a/internals/automate/src/index.ts b/internals/automate/src/index.ts new file mode 100644 index 000000000..dccea8c4f --- /dev/null +++ b/internals/automate/src/index.ts @@ -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)