Browse Source

chore: Migrate CJS to ESM (#42068)

* chore: Migrate CJS to ESM

* fix lint
pull/42073/head
lijianan 2 years ago
committed by GitHub
parent
commit
c1760262b9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      package.json
  2. 29
      scripts/check-commit.ts

2
package.json

@ -49,7 +49,7 @@
"authors": "ts-node --esm --project tsconfig.node.json scripts/generate-authors.ts",
"build": "npm run compile && NODE_OPTIONS='--max-old-space-size=4096' npm run dist",
"size-limit": "size-limit",
"check-commit": "node ./scripts/check-commit",
"check-commit": "ts-node --esm --project tsconfig.node.json scripts/check-commit.ts",
"check-ts-demo": "ts-node --esm --project tsconfig.node.json scripts/check-ts-demo.ts",
"clean": "antd-tools run clean && rm -rf es lib coverage dist report.html",
"clean-lockfiles": "rm -rf package-lock.json yarn.lock",

29
scripts/check-commit.js → scripts/check-commit.ts

@ -1,14 +1,15 @@
/* eslint-disable import/no-dynamic-require, no-console */
const chalk = require('chalk');
const path = require('path');
const fetch = require('isomorphic-fetch');
const simpleGit = require('simple-git');
/* eslint-disable no-console */
import chalk from 'chalk';
import fetch from 'isomorphic-fetch';
import type { StatusResult } from 'simple-git';
import simpleGit from 'simple-git';
import localPackage from '../package.json';
const { version } = localPackage;
const cwd = process.cwd();
const git = simpleGit(cwd);
const { version } = require(path.resolve(cwd, 'package.json'));
function exitProcess(code = 1) {
console.log(''); // Keep an empty line here to make looks good~
process.exit(code);
@ -16,18 +17,20 @@ function exitProcess(code = 1) {
async function checkVersion() {
try {
const { versions } = await fetch('http://registry.npmjs.org/antd').then((res) => res.json());
const { versions } = await fetch('http://registry.npmjs.org/antd').then((res: any) =>
res.json(),
);
if (version in versions) {
console.log(chalk.yellow('😈 Current version already exists. Forget update package.json?'));
console.log(chalk.cyan(' => Current:'), version);
exitProcess();
}
} catch (error) {
} catch {
console.log(chalk.red('🚨 Check version failed. Skip...'));
}
}
async function checkBranch({ current }) {
async function checkBranch({ current }: StatusResult) {
if (
version.includes('-alpha.') ||
version.includes('-beta.') ||
@ -41,7 +44,7 @@ async function checkBranch({ current }) {
}
}
async function checkCommit({ files }) {
async function checkCommit({ files }: StatusResult) {
if (files.length) {
console.log(chalk.yellow('🙄 You forgot something to commit.'));
files.forEach(({ path: filePath, working_dir: mark }) => {
@ -54,13 +57,13 @@ async function checkCommit({ files }) {
async function checkRemote() {
try {
const { remote } = await git.fetch('origin', 'master');
if (remote?.indexOf('ant-design/ant-design') === -1) {
if (!remote?.includes('ant-design/ant-design')) {
console.log(
chalk.yellow('😓 Your remote origin is not ant-design/ant-design, did you fork it?'),
);
exitProcess();
}
} catch (error) {
} catch {
console.log(chalk.red('🚨 Check remote failed. Skip...'));
}
}
Loading…
Cancel
Save