bootstrap.js 2.49 KB
Newer Older
dengxiaofeng's avatar
dengxiaofeng committed
1 2 3 4 5 6 7 8 9 10 11
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';

  const pkgs = readdirSync(join(__dirname, '../packages')).filter((pkg) => pkg.charAt(0) !== '.');

  pkgs.forEach((shortName) => {
dengxiaofeng's avatar
dengxiaofeng committed
12
    const name = `@wisdom-components/pro-${shortName}`;
dengxiaofeng's avatar
dengxiaofeng committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

    const pkgJSONPath = join(__dirname, '..', 'packages', shortName, 'package.json');
    const pkgJSONExists = existsSync(pkgJSONPath);
    let json;
    if (args.force || !pkgJSONExists) {
      json = {
        name,
        version,
        description: name,
        module: 'es/index.js',
        main: 'lib/index.js',
        types: 'lib/index.d.ts',
        files: ['lib', 'src', 'dist', 'es'],
        repository: {
          type: 'git',
邓晓峰's avatar
邓晓峰 committed
28
          url: 'https://g.civnet.cn:8443/ReactWeb5/winsdom-components',
dengxiaofeng's avatar
dengxiaofeng committed
29 30 31
        },
        browserslist: ['last 2 versions', 'Firefox ESR', '> 1%', 'ie >= 11'],
        keywords: ['antd', 'admin', 'ant-design', 'ant-design-pro'],
邓晓峰's avatar
邓晓峰 committed
32
        authors: ['dengxiaofeng'],
dengxiaofeng's avatar
dengxiaofeng committed
33
        license: 'MIT',
邓晓峰's avatar
邓晓峰 committed
34 35
        bugs: 'https://g.civnet.cn:8443/ReactWeb5/winsdom-components/plugins/issues',
        homepage: `https://g.civnet.cn:8443/ReactWeb5/winsdom-components/tree/master/packages/${shortName}#readme`,
dengxiaofeng's avatar
dengxiaofeng committed
36 37 38 39 40 41 42 43
        peerDependencies: {
          umi: '3.x',
        },
        publishConfig: {
          access: 'public',
        },
      };
      if (pkgJSONExists) {
邓晓峰's avatar
邓晓峰 committed
44
        // eslint-disable-next-line global-require,import/no-dynamic-require
dengxiaofeng's avatar
dengxiaofeng committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
        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`);
    }

    const readmePath = join(__dirname, '..', 'packages', shortName, 'README.md');
    if (args.force || !existsSync(readmePath)) {
      writeFileSync(
        readmePath,
        `# ${name}
> ${json.description}.
See our website [${name}](https://umijs.org/plugins/${shortName}) for more information.
## Install
Using npm:
\`\`\`bash
$ npm install --save ${name}
\`\`\`
or using yarn:
\`\`\`bash
$ yarn add ${name}
\`\`\`
`,
      );
    }
  });
邓晓峰's avatar
邓晓峰 committed
86
})();