From 16dd7ba3cb44973bae8ff5cd6ffbb0f4b70fffa5 Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Fri, 28 Apr 2023 16:08:39 +0800 Subject: [PATCH] chore: Migrate CJS to ESM (#42059) * chore: Migrate CJS to ESM * fix * rename --- ...heck-version-md.js => check-version-md.ts} | 28 +++++++++---------- scripts/test-all.sh | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) rename scripts/{check-version-md.js => check-version-md.ts} (77%) diff --git a/scripts/check-version-md.js b/scripts/check-version-md.ts similarity index 77% rename from scripts/check-version-md.js rename to scripts/check-version-md.ts index 6bddf07949..b12f4980d0 100644 --- a/scripts/check-version-md.js +++ b/scripts/check-version-md.ts @@ -1,13 +1,19 @@ -/* eslint no-console: 0 */ -const chalk = require('chalk'); -const fs = require('fs'); -const { join } = require('path'); -const dayjs = require('dayjs'); +/* eslint-disable no-console */ +import chalk from 'chalk'; +import dayjs from 'dayjs'; +import isBetween from 'dayjs/plugin/isBetween'; +import fs from 'fs'; +import { join } from 'path'; +import localPackage from '../package.json'; -const getChangelogByVersion = (content, version) => { +const { version } = localPackage; + +dayjs.extend(isBetween); + +const getChangelogByVersion = (content: string, vers: string) => { const lines = content.split('\n'); - const changeLog = []; - const startPattern = new RegExp(`^## ${version}`); + const changeLog: string[] = []; + const startPattern = new RegExp(`^## ${vers}`); const stopPattern = /^## /; // 前一个版本 let begin = false; for (let i = 0; i < lines.length; i += 1) { @@ -22,15 +28,9 @@ const getChangelogByVersion = (content, version) => { begin = startPattern.test(line); } } - return changeLog.join('\n'); }; -// eslint-disable-next-line import/no-dynamic-require -const packageJson = require(join(__dirname, '..', 'package.json')); - -const { version } = packageJson; - if (!/^\d+\.\d+\.\d+$/.test(version)) { console.log('\n'); console.log(chalk.blue('[check-version-md]: Prerelease Version. Skipped.')); diff --git a/scripts/test-all.sh b/scripts/test-all.sh index d9f958908e..d0bf67832d 100755 --- a/scripts/test-all.sh +++ b/scripts/test-all.sh @@ -2,7 +2,7 @@ echo "[TEST ALL] test changelog" echo "[TEST ALL] test changelog" > ~test-all.txt -# node ./scripts/check-version-md.js +# node ./scripts/check-version-md.ts echo "[TEST ALL] check-commit" echo "[TEST ALL] check-commit" > ~test-all.txt