Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-test into dev
  • Loading branch information
ruan-cat committed Oct 25, 2024
2 parents 02ff4a0 + 4c472a9 commit 53b61b9
Show file tree
Hide file tree
Showing 47 changed files with 1,129 additions and 39 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,7 @@ vercel.null.def.json
.eslint-config-inspector

# 忽略掉自己配置的 vitest 报告文件 忽略掉其生成的缓存文件
.vitest-reporter-html
.vitest-reporter-html

# 我们自动生成工作区文件 所以不提交到仓库内
*.code-workspace
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"Spades.vs-picgo"
],
"unwantedRecommendations": []
}
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@
// https://nodejs.org/en/learn/typescript/run#registering-tsx-via-node
"typescript": "pnpm dotenvx run -- node --import=tsx $fullFileName"
}
}
}
2 changes: 1 addition & 1 deletion commitlint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function getPackagesNameAndDescription() {

/**
* pnpm-workspace.yaml 的配置
* @type { import("./types/pnpm-workspace.yaml.shim.ts").PnpmWorkspace }
* @type { import("@ruan-cat/utils/src/types/pnpm-workspace.yaml.shim.ts").PnpmWorkspace }
*/
// @ts-ignore 忽略unknown的警告
const workspaceConfig = yaml.load(workspaceFile);
Expand Down
2 changes: 1 addition & 1 deletion configs-package/commitlint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
"peerDependencies": {
"typescript": "catalog:"
}
}
}
7 changes: 7 additions & 0 deletions demos/vercel-deploy-tool/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @ruan-cat/vercel-deploy-tool

## 0.1.1

### Patch Changes

- Updated dependencies
- @ruan-cat/utils@1.2.0

## 0.1.0

### Minor Changes
Expand Down
6 changes: 3 additions & 3 deletions demos/vercel-deploy-tool/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ruan-cat/vercel-deploy-tool",
"version": "0.1.0",
"version": "0.1.1",
"description": "阮喵喵自用的vercel部署工具,用于实现复杂项目的部署。",
"type": "module",
"main": "./src/index.ts",
Expand Down Expand Up @@ -59,7 +59,7 @@
"lodash-es": "catalog:",
"mkdirp": "^3.0.1",
"pathe": "^1.1.2",
"rimraf": "^5.0.7",
"rimraf": "^6.0.1",
"shx": "^0.3.4",
"vercel": "^34.2.7"
},
Expand All @@ -71,4 +71,4 @@
"@vitest/ui": "^2.0.5",
"vitest": "^2.0.5"
}
}
}
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
"changeset:version": "changeset version",
"changeset:publish": "changeset publish",
"turbo:publish": "turbo do-publish",
"code-workspace:del": "trash *.code-workspace",
"precode-workspace:create": "pnpm run code-workspace:del",
"code-workspace:create": "node --import=tsx ./scripts/generate.code-workspace.ts",
"turbo:do-create-code-workspace": "turbo do-create-code-workspace",
"deploy-vercel": "node --import=tsx ./demos/vercel-deploy-tool/src/index.ts"
},
"devDependencies": {
Expand All @@ -62,10 +66,12 @@
"@types/node": "^20.16.11",
"@vuepress/bundler-vite": "2.0.0-rc.18",
"commitizen": "^4.3.1",
"consola": "^3.2.3",
"cpx2": "^7.0.2",
"cross-env": "^7.0.3",
"cz-git": "^1.10.1",
"czg": "^1.10.1",
"del": "^8.0.0",
"esbuild": "^0.23.1",
"esbuild-register": "^3.6.0",
"eslint": "^9.12.0",
Expand All @@ -84,8 +90,9 @@
"pkg-types": "^1.2.1",
"prettier": "^3.3.3",
"prettier-plugin-lint-md": "^1.0.1",
"rimraf": "^5.0.10",
"rimraf": "^6.0.1",
"shx": "^0.3.4",
"trash-cli": "^6.0.0",
"tsx": "^4.19.1",
"turbo": "^2.1.3",
"type-fest": "^4.26.1",
Expand All @@ -103,7 +110,6 @@
},
"dependencies": {
"@dotenvx/dotenvx": "^1.17.0",
"consola": "^3.2.3",
"lodash-es": "catalog:"
}
}
2 changes: 1 addition & 1 deletion packages/docs-01-star/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
"vitepress": "^1.3.0",
"vue": "^3.4.30"
}
}
}
2 changes: 1 addition & 1 deletion packages/vuepress-preset-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@
"vuepress-plugin-search-pro": "2.0.0-rc.57",
"vuepress-theme-hope": "2.0.0-rc.58"
}
}
}
2 changes: 2 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ packages:
- "demos/*"
- "utils"
- "learn-create-compoents-lib/*"
# 在monorepo环境下,测试该依赖包是否存在内部bug?实在不行就自己发包。
- "vite-plugin-autogeneration-import-file/*"
# 配置系列的依赖包 为了实现便捷快速的配置分发
- "configs-package/*"

Expand Down
161 changes: 161 additions & 0 deletions scripts/generate.code-workspace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// TODO: 等待封装成一个独立的子包 实现跨项目的复用
import { dirname, resolve, join } from "node:path";
import { fileURLToPath } from "node:url";
import * as fs from "node:fs";

import { sync } from "glob";
import yaml from "js-yaml";

import { type PackageJson } from "pkg-types";
import { type PnpmWorkspace } from "@ruan-cat/utils/src/types/pnpm-workspace.yaml.shim.ts";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

/** 工作区文件的目录配置类型 */
interface Folder {
name: string;
path: string;
}

/**
* 路径转换工具
*/
function pathChange(path: string) {
return path.replace(/\\/g, "/");
}

/**
* 根据 pnpm-workspace.yaml 生成工作区配置数组
* @description
*/
function getFolders() {
// TODO: 待优化 这里的路径读取还是不够智能 有写死的情况
// 读取 pnpm-workspace.yaml 文件 文件路径
const workspaceConfigPath = join(__dirname, "..", "pnpm-workspace.yaml");

// 文件
const workspaceFile = fs.readFileSync(workspaceConfigPath, "utf8");

/**
* pnpm-workspace.yaml 的配置
*/
const workspaceConfig = <PnpmWorkspace>yaml.load(workspaceFile);

/**
* packages配置 包的匹配语法
*/
const pkgPatterns = workspaceConfig.packages;

// console.log(" ? pkgPatterns ", pkgPatterns);

/**
* 全部的 package.json 文件路径
*/
let pkgPaths: string[] = [];

// 根据每个模式匹配相应的目录
pkgPatterns!.map((pkgPattern) => {
// TODO: 待优化 这里的路径读取还是不够智能 有写死的情况
const matchedPath = pathChange(join(__dirname, "..", pkgPattern, "package.json"));

// console.log(" 检查拼接出来的路径: ", matchedPath);

const matchedPaths = sync(matchedPath, {
ignore: "**/node_modules/**",
});

// 找到包路径,就按照顺序逐个填充准备
pkgPaths = pkgPaths.concat(...matchedPaths);
return matchedPaths;
});

// console.log("pkgPaths :>> ", pkgPaths);

/**
* 目前项目的根目录
* @description
* 绝对路径
*/
const workspaceRoot = pathChange(process.cwd());

const folders: Folder[] = pkgPaths.map(function (pkgJsonPath) {
/**
* 包配置文件数据
*/
const pkgJson = <PackageJson>JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));

/** 包名 且不可能为空包名 */
const pkgJsonName = <string>pkgJson.name;

// console.log(" ? 变换后的路径 ", pathChange(pkgJsonPath));

// 输入
// E:/store/gitHub-desktop/vercel-monorepo-test
// E:/store/gitHub-desktop/vercel-monorepo-test/packages/vuepress-preset-config/package.json
// 输出
// ./packages/vuepress-preset-config

/** 相对路径 */
const relativePath = pathChange(pkgJsonPath).replace(`${workspaceRoot}/`, "");

/** 没有 package.json 的相对路径 */
const relativePathWithNoPkgJson = relativePath.replace(/\/package\.json$/, "");

/** 最终用于工作区配置的路径 */
const pathForCodeWorkspace = `./${relativePathWithNoPkgJson}`;

// console.log(" ? pathForCodeWorkspace ", pathForCodeWorkspace);

return <Folder>{
name: pkgJsonName,
path: pathForCodeWorkspace,
};

// 如果确实存在该文件,就处理。否则不管了。
// 我们不判断文件是否存在了,这些路径都是存在文件的,
// if (fs.existsSync(pkgJsonPath)) {
// return {
// name: createLabelName(pkgJson),
// value: createPackagescopes(pkgJson),
// };
// }
});

return folders;
}

/**
* 默认的工作区文件夹配置
* @description
* 默认要把根目录准备好 要能够访问到根目录
*/
const defFolders: Folder[] = [
{
name: "root",
path: "./",
},
];

const folders = [...defFolders, ...getFolders()];

const codeWorkspaceContent = {
folders,
};

const defCodeWorkspaceFilename = <const>"vscode";

/**
* 生成 vscode.code-workspace 文件
*/
function generateCodeWorkspace(filename: string = defCodeWorkspaceFilename) {
const postfix = <const>".code-workspace";
const fullName = <const>`${filename}${postfix}`;

// TODO: 待优化 这里的路径读取还是不够智能 有写死的情况
const codeWorkspacePath = join(__dirname, "..", fullName);
fs.writeFileSync(codeWorkspacePath, JSON.stringify(codeWorkspaceContent, null, 2));
}

// 我们的工作区名称为 vercel-monorepo-test
generateCodeWorkspace("vercel-monorepo-test");
30 changes: 30 additions & 0 deletions scripts/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"compilerOptions": {
"target": "ES2022",
"lib": [
"ES2023"
],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
// 对应的文件 不经过vite
// "moduleResolution": "bundler",
"moduleResolution": "Node",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"types": [
"node"
],
"esModuleInterop": true
},
"include": [
"./generate-vscode.code-workspace-by-pnpm-workspace.yaml.ts"
]
}
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"exclude": [
"**/dist",
"**/node_modules"
"**/node_modules",
"./scripts",
],
"compilerOptions": {
"outDir": "**/dist",
Expand All @@ -12,5 +13,5 @@
{
"path": "./tsconfig.path.json"
}
]
],
}
15 changes: 15 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@
"dependsOn": [
"//#changeset:publish"
]
},
"//#code-workspace:del": {
"cache": false
},
"//#code-workspace:create": {
"cache": false,
"dependsOn": [
"//#code-workspace:del"
]
},
"//#do-create-code-workspace": {
"cache": false,
"dependsOn": [
"//#code-workspace:create"
]
}
}
}
6 changes: 6 additions & 0 deletions utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @ruan-cat/utils 更新日志

## 1.2.0

### Minor Changes

- 提供了针对 pnpm 工作区文件的类型声明。

## 1.1.1

### Patch Changes
Expand Down
Loading

0 comments on commit 53b61b9

Please sign in to comment.