generateSizeLimit.js 1.03 KB
Newer Older
dengxiaofeng's avatar
dengxiaofeng committed
1 2 3
const path = require('path');
const fs = require('fs');
const writePkg = require('write-pkg');
4
const getPackages = require('./utils/getPackages');
dengxiaofeng's avatar
dengxiaofeng committed
5 6 7 8 9

const cwd = process.cwd();
const ignoreDirPath = ['.DS_Store'];

const filePath = path.resolve(cwd, 'package.json');
10
// const packagesDir = path.resolve(cwd, 'packages');
dengxiaofeng's avatar
dengxiaofeng committed
11 12 13 14
const json = JSON.parse(fs.readFileSync(filePath, 'utf8'));

delete json['size-limit'];

15
let componentsNames = getPackages();
dengxiaofeng's avatar
dengxiaofeng committed
16 17 18 19 20
componentsNames = componentsNames.filter((dir) => ignoreDirPath.indexOf(dir) === -1);

(async () => {
  const sizeLimitConfig = [];
  componentsNames.forEach((component) => {
21
    const [shortName, p] = component.split('!');
dengxiaofeng's avatar
dengxiaofeng committed
22
    sizeLimitConfig.push({
23
      path: `packages/${p}/${shortName}/lib/**/*.js`,
dengxiaofeng's avatar
dengxiaofeng committed
24 25 26 27 28
      limit: '2 s',
      webpack: false,
      running: false,
    });
    sizeLimitConfig.push({
29
      path: `packages/${p}/${shortName}/es/**/*.js`,
dengxiaofeng's avatar
dengxiaofeng committed
30 31 32 33 34 35 36
      limit: '2 s',
      webpack: false,
      running: false,
    });
  });

  await writePkg(cwd, { ...json, 'size-limit': sizeLimitConfig });
邓晓峰's avatar
邓晓峰 committed
37
})();