diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index b81ca2d5..3b7f8187 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,14 +1,14 @@ # default onwer -* anncwb vince292007 +* anncwb@126.com vince292007@gmail.com # vben core onwer -/.github/ anncwb vince292007 -/.vscode/ anncwb vince292007 -/packages/ anncwb vince292007 -/packages/@core/ anncwb vince292007 -/internal/ anncwb vince292007 -/scripts/ anncwb vince292007 +/.github/ anncwb@126.com vince292007@gmail.com +/.vscode/ anncwb@126.com vince292007@gmail.com +/packages/ anncwb@126.com vince292007@gmail.com +/packages/@core/ anncwb@126.com vince292007@gmail.com +/internal/ anncwb@126.com vince292007@gmail.com +/scripts/ anncwb@126.com vince292007@gmail.com # vben team onwer -apps/ @vbenjs/team-v5 -docs/ @vbenjs/team-v5 +apps/ anncwb@126.com vince292007@gmail.com @vbenjs/team-v5 +docs/ anncwb@126.com vince292007@gmail.com @vbenjs/team-v5 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0b7202e4..5356b08a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -26,6 +26,12 @@ jobs: sed -i "s#VITE_COMPRESS\s*=.*#VITE_COMPRESS = gzip#g" ./apps/web-antd/.env.production sed -i "s#VITE_PWA\s*=.*#VITE_PWA = true#g" ./apps/web-antd/.env.production cat ./apps/web-antd/.env.production + sed -i "s#VITE_COMPRESS\s*=.*#VITE_COMPRESS = gzip#g" ./apps/web-ele/.env.production + sed -i "s#VITE_PWA\s*=.*#VITE_PWA = true#g" ./apps/web-ele/.env.production + cat ./apps/web-ele/.env.production + sed -i "s#VITE_COMPRESS\s*=.*#VITE_COMPRESS = gzip#g" ./apps/web-naive/.env.production + sed -i "s#VITE_PWA\s*=.*#VITE_PWA = true#g" ./apps/web-naive/.env.production + cat ./apps/web-naive/.env.production - name: Install pnpm uses: pnpm/action-setup@v4 diff --git a/internal/node-utils/package.json b/internal/node-utils/package.json index d88fb281..78ee13d2 100644 --- a/internal/node-utils/package.json +++ b/internal/node-utils/package.json @@ -35,7 +35,6 @@ "dayjs": "^1.11.12", "execa": "^9.3.0", "find-up": "^7.0.0", - "fs-extra": "^11.2.0", "nanoid": "^5.0.7", "ora": "^8.0.1", "pkg-types": "^1.1.3", @@ -43,7 +42,6 @@ "rimraf": "^6.0.1" }, "devDependencies": { - "@types/chalk": "^2.2.0", - "@types/fs-extra": "^11.0.4" + "@types/chalk": "^2.2.0" } } diff --git a/internal/node-utils/src/fs.ts b/internal/node-utils/src/fs.ts new file mode 100644 index 00000000..3bc682bc --- /dev/null +++ b/internal/node-utils/src/fs.ts @@ -0,0 +1,41 @@ +import { promises as fs } from 'node:fs'; +import { dirname } from 'node:path'; + +export async function outputJSON( + filePath: string, + data: any, + spaces: number = 2, +) { + try { + const dir = dirname(filePath); + await fs.mkdir(dir, { recursive: true }); + const jsonData = JSON.stringify(data, null, spaces); + await fs.writeFile(filePath, jsonData, 'utf8'); + console.log(`JSON data written to ${filePath}`); + } catch (error) { + console.error('Error writing JSON file:', error); + throw error; + } +} + +export async function ensureFile(filePath: string) { + try { + const dir = dirname(filePath); + await fs.mkdir(dir, { recursive: true }); + await fs.writeFile(filePath, '', { flag: 'a' }); // 'a' flag to append if file exists, otherwise create + console.log(`File ensured: ${filePath}`); + } catch (error) { + console.error('Error ensuring file:', error); + throw error; + } +} + +export async function readJSON(filePath: string) { + try { + const data = await fs.readFile(filePath, 'utf8'); + return JSON.parse(data); + } catch (error) { + console.error('Error reading JSON file:', error); + throw error; + } +} diff --git a/internal/node-utils/src/index.ts b/internal/node-utils/src/index.ts index 6156cc36..cd9028d7 100644 --- a/internal/node-utils/src/index.ts +++ b/internal/node-utils/src/index.ts @@ -1,5 +1,6 @@ export * from './constants'; export * from './date'; +export * from './fs'; export * from './git'; export { add as gitAdd, getStagedFiles } from './git'; export { generatorContentHash } from './hash'; @@ -12,8 +13,9 @@ export { default as colors } from 'chalk'; export { consola } from 'consola'; export * from 'execa'; -export * as fs from 'fs-extra'; export { nanoid } from 'nanoid'; -export { type PackageJson, readPackageJSON } from 'pkg-types'; +export { default as fs } from 'node:fs/promises'; + +export { type PackageJson, readPackageJSON } from 'pkg-types'; export { rimraf } from 'rimraf'; diff --git a/internal/node-utils/src/prettier.ts b/internal/node-utils/src/prettier.ts index 58d60f90..1e1525db 100644 --- a/internal/node-utils/src/prettier.ts +++ b/internal/node-utils/src/prettier.ts @@ -1,4 +1,5 @@ -import fs from 'fs-extra'; +import fs from 'node:fs/promises'; + import { format, getFileInfo, resolveConfig } from 'prettier'; async function prettierFormat(filepath: string) { @@ -12,7 +13,7 @@ async function prettierFormat(filepath: string) { parser: fileInfo.inferredParser as any, }); if (output !== input) { - fs.writeFileSync(filepath, output, 'utf8'); + await fs.writeFile(filepath, output, 'utf8'); } return output; } diff --git a/internal/tailwind-config/src/index.ts b/internal/tailwind-config/src/index.ts index 7402e913..ac5512c9 100644 --- a/internal/tailwind-config/src/index.ts +++ b/internal/tailwind-config/src/index.ts @@ -1,8 +1,9 @@ import type { Config } from 'tailwindcss'; +import fs from 'node:fs'; import path from 'node:path'; -import { fs, getPackagesSync } from '@vben/node-utils'; +import { getPackagesSync } from '@vben/node-utils'; import { addDynamicIconSelectors } from '@iconify/tailwind'; import typographyPlugin from '@tailwindcss/typography'; diff --git a/internal/vite-config/src/plugins/inject-app-loading/index.ts b/internal/vite-config/src/plugins/inject-app-loading/index.ts index 3d7c20b3..9b9d3c4b 100644 --- a/internal/vite-config/src/plugins/inject-app-loading/index.ts +++ b/internal/vite-config/src/plugins/inject-app-loading/index.ts @@ -1,7 +1,8 @@ +import fs from 'node:fs'; import { join } from 'node:path'; import { fileURLToPath } from 'node:url'; -import { fs, readPackageJSON } from '@vben/node-utils'; +import { readPackageJSON } from '@vben/node-utils'; import { type PluginOption } from 'vite'; @@ -61,7 +62,7 @@ async function getLoadingRawByHtmlTemplate(loadingTemplate: string) { return; } - const htmlRaw = await fs.readFile(loadingPath, 'utf8'); + const htmlRaw = fs.readFileSync(loadingPath, 'utf8'); return htmlRaw; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1d8ccbb8..3b636f0a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -491,9 +491,6 @@ importers: find-up: specifier: ^7.0.0 version: 7.0.0 - fs-extra: - specifier: ^11.2.0 - version: 11.2.0 nanoid: specifier: ^5.0.7 version: 5.0.7 @@ -513,9 +510,6 @@ importers: '@types/chalk': specifier: ^2.2.0 version: 2.2.0 - '@types/fs-extra': - specifier: ^11.0.4 - version: 11.0.4 internal/tailwind-config: dependencies: @@ -3126,7 +3120,6 @@ packages: '@ls-lint/ls-lint@2.2.3': resolution: {integrity: sha512-ekM12jNm/7O2I/hsRv9HvYkRdfrHpiV1epVuI2NP+eTIcEgdIdKkKCs9KgQydu/8R5YXTov9aHdOgplmCHLupw==} - cpu: [x64, arm64, s390x] os: [darwin, linux, win32] hasBin: true diff --git a/scripts/vsh/src/code-workspace/index.ts b/scripts/vsh/src/code-workspace/index.ts index d89de092..d5ec4ee9 100644 --- a/scripts/vsh/src/code-workspace/index.ts +++ b/scripts/vsh/src/code-workspace/index.ts @@ -6,9 +6,9 @@ import { colors, consola, findMonorepoRoot, - fs, getPackages, gitAdd, + outputJSON, prettierFormat, toPosixPath, } from '@vben/node-utils'; @@ -38,7 +38,7 @@ async function createCodeWorkspace({ const monorepoRoot = findMonorepoRoot(); const outputPath = join(monorepoRoot, CODE_WORKSPACE_FILE); - await fs.outputJSON(outputPath, { folders }, { encoding: 'utf8', spaces }); + await outputJSON(outputPath, { folders }, spaces); await prettierFormat(outputPath); if (autoCommit) { diff --git a/scripts/vsh/src/publint/index.ts b/scripts/vsh/src/publint/index.ts index e727ff78..f9461458 100644 --- a/scripts/vsh/src/publint/index.ts +++ b/scripts/vsh/src/publint/index.ts @@ -6,10 +6,12 @@ import { basename, dirname, join } from 'node:path'; import { colors, consola, + ensureFile, findMonorepoRoot, - fs, generatorContentHash, getPackages, + outputJSON, + readJSON, UNICODE, } from '@vben/node-utils'; @@ -56,8 +58,8 @@ function getCacheFile() { async function readCache(cacheFile: string) { try { - await fs.ensureFile(cacheFile); - return await fs.readJSON(cacheFile, { encoding: 'utf8' }); + await ensureFile(cacheFile); + return await readJSON(cacheFile); } catch { return {}; } @@ -73,7 +75,7 @@ async function runPublint(files: string[], { check }: PubLintCommandOptions) { const results = await Promise.all( lintFiles.map(async (file) => { try { - const pkgJson = await fs.readJSON(file); + const pkgJson = await readJSON(file); if (pkgJson.private) { return null; @@ -106,7 +108,7 @@ async function runPublint(files: string[], { check }: PubLintCommandOptions) { }), ); - await fs.outputJSON(cacheFile, cache); + await outputJSON(cacheFile, cache); printResult(results, check); }