bootstrap.js 2.75 KB
Newer Older
dengxiaofeng's avatar
dengxiaofeng committed
1 2 3 4 5 6 7
const { existsSync, writeFileSync, readdirSync } = require('fs');
const { join } = require('path');
const { yParser } = require('@umijs/utils');

(async () => {
  const args = yParser(process.argv);
  const version = '1.0.0-beta.1';
8 9 10 11 12 13 14
  // readdirSync(join(__dirname, '../packages')).filter((pkg) => pkg.charAt(0) !== '.');
  const pkgs = ['base-components', 'extend-components']
    .map((dir) => {
      const list = readdirSync(join(__dirname, '../packages', dir)).map((item) => `${item}!${dir}`);
      return list.filter((pkg) => pkg.charAt(0) !== '.');
    })
    .flat();
dengxiaofeng's avatar
dengxiaofeng committed
15 16

  pkgs.forEach((shortName) => {
17 18 19
    const [name, dir] = shortName.split('!');
    const desc = `@wisdom-components/pro-${name}`;
    const pkgJSONPath = join(__dirname, '..', 'packages', dir, name, 'package.json');
dengxiaofeng's avatar
dengxiaofeng committed
20 21 22 23 24 25 26

    const pkgJSONExists = existsSync(pkgJSONPath);
    let json;
    if (args.force || !pkgJSONExists) {
      json = {
        name,
        version,
27
        description: desc,
dengxiaofeng's avatar
dengxiaofeng committed
28 29 30 31 32 33
        module: 'es/index.js',
        main: 'lib/index.js',
        types: 'lib/index.d.ts',
        files: ['lib', 'src', 'dist', 'es'],
        repository: {
          type: 'git',
邓晓峰's avatar
邓晓峰 committed
34
          url: 'https://g.civnet.cn:8443/ReactWeb5/winsdom-components',
dengxiaofeng's avatar
dengxiaofeng committed
35 36 37
        },
        browserslist: ['last 2 versions', 'Firefox ESR', '> 1%', 'ie >= 11'],
        keywords: ['antd', 'admin', 'ant-design', 'ant-design-pro'],
邓晓峰's avatar
邓晓峰 committed
38
        authors: ['dengxiaofeng'],
dengxiaofeng's avatar
dengxiaofeng committed
39
        license: 'MIT',
邓晓峰's avatar
邓晓峰 committed
40
        bugs: 'https://g.civnet.cn:8443/ReactWeb5/winsdom-components/plugins/issues',
41
        homepage: `https://g.civnet.cn:8443/ReactWeb5/winsdom-components/tree/master/packages/${name}#readme`,
dengxiaofeng's avatar
dengxiaofeng committed
42 43 44 45 46 47 48 49
        peerDependencies: {
          umi: '3.x',
        },
        publishConfig: {
          access: 'public',
        },
      };
      if (pkgJSONExists) {
邓晓峰's avatar
邓晓峰 committed
50
        // eslint-disable-next-line global-require,import/no-dynamic-require
dengxiaofeng's avatar
dengxiaofeng committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
        const pkg = require(pkgJSONPath);
        [
          'dependencies',
          'devDependencies',
          'peerDependencies',
          'bin',
          'version',
          'files',
          'authors',
          'types',
          'sideEffects',
          'main',
          'module',
          'description',
        ].forEach((key) => {
          if (pkg[key]) json[key] = pkg[key];
        });
      }
      writeFileSync(pkgJSONPath, `${JSON.stringify(json, null, 2)}\n`);
    }

72
    const readmePath = join(__dirname, '..', 'packages', name, 'README.md');
dengxiaofeng's avatar
dengxiaofeng committed
73 74 75 76 77
    if (args.force || !existsSync(readmePath)) {
      writeFileSync(
        readmePath,
        `# ${name}
> ${json.description}.
78
See our website [${name}](https://umijs.org/plugins/${name}) for more information.
dengxiaofeng's avatar
dengxiaofeng committed
79 80 81 82 83 84 85 86 87 88 89 90 91
## Install
Using npm:
\`\`\`bash
$ npm install --save ${name}
\`\`\`
or using yarn:
\`\`\`bash
$ yarn add ${name}
\`\`\`
`,
      );
    }
  });
邓晓峰's avatar
邓晓峰 committed
92
})();