From 0c80282dbbdd27890f74651ac20474e2fe741118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Fri, 21 Oct 2022 22:31:41 +0800 Subject: [PATCH] chore: add migrate script --- bin/rc-test-migrate.js | 63 ++++++++++++++++++++++++++++++++++++++++++ package.json | 3 +- 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100755 bin/rc-test-migrate.js diff --git a/bin/rc-test-migrate.js b/bin/rc-test-migrate.js new file mode 100755 index 0000000..4ea423e --- /dev/null +++ b/bin/rc-test-migrate.js @@ -0,0 +1,63 @@ +#!/usr/bin/env node + +const path = require("path"); +const semver = require("semver"); +const fs = require("fs-extra"); + +const VER_FATHER = "father"; +const RM_DEPS = ["jest", "father-build", "react-test-renderer"]; + +const pkg = require(path.resolve(process.cwd(), "package.json")); + +// ================================================================== +// Upgrade father version if exist +const fatherVer = pkg.devDependencies[VER_FATHER]; +if (fatherVer) { + const fatherMajor = semver.major(semver.minVersion(fatherVer)); + + if (fatherMajor < 4) { + console.log("Upgrading father version to ^4.0.0 ..."); + pkg.devDependencies[VER_FATHER] = "^4.0.0"; + + console.log("Override .fatherrc..."); + fs.writeFileSync( + path.resolve(process.cwd(), ".fatherrc.js"), + ` +import { defineConfig } from 'father'; + +export default defineConfig({ + platform: 'browser', + cjs: { output: 'lib' }, + esm: { + output: 'es', + alias: { 'rc-util/lib': 'rc-util/es' }, + }, +}); +`.trim(), + "utf-8" + ); + } +} + +// ================================================================== +// Update script +pkg.scripts.test = "rc-test"; + +// Remove origin test content +RM_DEPS.forEach((dep) => { + delete pkg.devDependencies[dep]; +}); + +fs.writeFileSync( + path.resolve(process.cwd(), "package.json"), + JSON.stringify(pkg, null, 2), + "utf-8" +); + +// ================================================================== +// Print Tips +console.log("更新完成,请检查以下内容:"); +console.log(" - 更新 .github/workflows 中 CI node 版本至 16"); +console.log( + " - 移除 jest.config.js 中关于 @testing-library/jsdom 的 setupFilesAfterEnv 配置" +); diff --git a/package.json b/package.json index c918632..68ccf53 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ }, "license": "MIT", "bin": { - "rc-test": "./bin/rc-test.js" + "rc-test": "./bin/rc-test.js", + "rc-test-migrate": "./bin/rc-test-migrate.js" }, "main": "./lib/index", "module": "./es/index",