gen_less_entry.js 743 Bytes
Newer Older
邓晓峰's avatar
邓晓峰 committed
1 2 3
const fs = require('fs');
const { join } = require('path');
const fg = require('fast-glob');
4
const getPackages = require('./utils/getPackages');
邓晓峰's avatar
邓晓峰 committed
5

6
const pkgList = getPackages();
邓晓峰's avatar
邓晓峰 committed
7

8 9 10
pkgList.map(async (pkg) => {
  const [name, path] = pkg.split('!');
  const baseUrl = `${join(__dirname, '../', 'packages')}/${path}/${name}/src`;
邓晓峰's avatar
邓晓峰 committed
11 12 13 14 15 16 17 18
  const lessFiles = await fg(`${baseUrl}/**/*.less`, {
    ignore: ['**/demos/**'],
    deep: 5,
  });
  const importFiles = lessFiles.map((lessPath) => {
    return `@import "../es${lessPath.replace(baseUrl, '')}";`;
  });

19 20 21 22
  const distPath = `${join(__dirname, '../', 'packages', path, name, 'dist', `${name}.less`)}`;
  if (fs.existsSync(distPath)) {
    fs.writeFileSync(distPath, importFiles.join('\n'));
  }
涂茜's avatar
涂茜 committed
23
});