Преглед на файлове

feat: Support multiple application launch scripts

vben преди 9 месеца
родител
ревизия
a26630b6e0

+ 1 - 1
.npmrc

@@ -1,4 +1,4 @@
-# registry = "https://registry.npmmirror.com"
+registry = "https://registry.npmmirror.com"
 public-hoist-pattern[]=husky
 public-hoist-pattern[]=eslint
 public-hoist-pattern[]=prettier

+ 3 - 0
apps/web-antd/src/preferences.ts

@@ -6,4 +6,7 @@ import { defineOverridesPreferences } from '@vben/preferences';
  */
 export const overridesPreferences = defineOverridesPreferences({
   // overrides
+  app: {
+    name: import.meta.env.VITE_APP_TITLE,
+  },
 });

+ 3 - 0
apps/web-naive/src/preferences.ts

@@ -6,4 +6,7 @@ import { defineOverridesPreferences } from '@vben/preferences';
  */
 export const overridesPreferences = defineOverridesPreferences({
   // overrides
+  app: {
+    name: import.meta.env.VITE_APP_TITLE,
+  },
 });

+ 3 - 1
package.json

@@ -37,7 +37,7 @@
     "check:type": "turbo run typecheck",
     "clean": "vsh clean",
     "commit": "czg",
-    "dev": "cross-env turbo run dev",
+    "dev": "turbo-run dev",
     "dev:antd": "pnpm -F @vben/web-antd",
     "dev:naive": "pnpm -F @vben/web-naive",
     "dev:docs": "pnpm -F @vben/website run docs:dev",
@@ -49,6 +49,7 @@
     "publint": "vsh publint",
     "reinstall": "pnpm clean --del-lock && pnpm bootstrap",
     "test:unit": "vitest",
+    "turbo-run": "turbo-run",
     "update:deps": " pnpm update --latest --recursive",
     "version": "pnpm exec changeset version && pnpm install --no-frozen-lockfile"
   },
@@ -65,6 +66,7 @@
     "@vben/stylelint-config": "workspace:*",
     "@vben/tailwind-config": "workspace:*",
     "@vben/tsconfig": "workspace:*",
+    "@vben/turbo-run": "workspace:*",
     "@vben/vite-config": "workspace:*",
     "@vben/vsh": "workspace:*",
     "@vue/test-utils": "^2.4.6",

+ 1 - 1
packages/@core/preferences/src/config.ts

@@ -18,7 +18,7 @@ const defaultPreferences: Preferences = {
     layout: 'sidebar-nav',
     locale: 'zh-CN',
     loginExpiredMode: 'modal',
-    name: 'Vben Admin Naive',
+    name: 'Vben Admin',
     watermark: false,
   },
   breadcrumb: {

+ 4 - 4
packages/@core/preferences/src/constants.ts

@@ -8,10 +8,10 @@ interface BuiltinThemePreset {
 }
 
 const BUILT_IN_THEME_PRESETS: BuiltinThemePreset[] = [
-  // {
-  //   color: 'hsl(231 98% 65%)',
-  //   type: 'default',
-  // },
+  {
+    color: 'hsl(231 98% 65%)',
+    type: 'default',
+  },
   {
     color: 'hsl(245 82% 67%)',
     type: 'violet',

+ 4 - 8
packages/@core/preferences/src/update-css-variables.ts

@@ -5,7 +5,7 @@ import {
   generatorColorVariables,
 } from '@vben-core/shared';
 
-import { BUILT_IN_THEME_PRESETS, type BuiltinThemePreset } from './constants';
+import { BUILT_IN_THEME_PRESETS } from './constants';
 
 /**
  * 更新主题的 CSS 变量以及其他 CSS 变量
@@ -37,13 +37,9 @@ function updateCSSVariables(preferences: Preferences) {
   }
 
   // 获取当前的内置主题
-  const currentBuiltType = [
-    {
-      color: preferences.theme.colorPrimary,
-      type: 'default',
-    } as BuiltinThemePreset,
-    ...BUILT_IN_THEME_PRESETS,
-  ].find((item) => item.type === builtinType);
+  const currentBuiltType = [...BUILT_IN_THEME_PRESETS].find(
+    (item) => item.type === builtinType,
+  );
 
   let builtinTypeColorPrimary: string | undefined = '';
 

+ 0 - 4
packages/effects/layouts/src/widgets/preferences/blocks/theme/builtin.vue

@@ -27,10 +27,6 @@ const inputValue = computed(() => {
 
 const builtinThemePresets = computed(() => {
   return [
-    {
-      color: 'hsl(231 98% 65%)',
-      type: 'default',
-    },
     // {
     //   color: 'hsl(231 98% 65%)',
     //   type: 'default',

+ 40 - 3
pnpm-lock.yaml

@@ -49,6 +49,9 @@ importers:
       '@vben/tsconfig':
         specifier: workspace:*
         version: link:internal/tsconfig
+      '@vben/turbo-run':
+        specifier: workspace:*
+        version: link:scripts/turbo-run
       '@vben/vite-config':
         specifier: workspace:*
         version: link:internal/vite-config
@@ -978,6 +981,18 @@ importers:
         specifier: ^4.4.0
         version: 4.4.0(vue@3.4.34(typescript@5.5.4))
 
+  scripts/turbo-run:
+    dependencies:
+      '@clack/prompts':
+        specifier: ^0.7.0
+        version: 0.7.0
+      '@vben/node-utils':
+        specifier: workspace:*
+        version: link:../../internal/node-utils
+      cac:
+        specifier: ^6.7.14
+        version: 6.7.14
+
   scripts/vsh:
     dependencies:
       '@vben/node-utils':
@@ -995,9 +1010,6 @@ importers:
       publint:
         specifier: ^0.2.9
         version: 0.2.9
-      zx:
-        specifier: ^8.1.4
-        version: 8.1.4
 
   website:
     dependencies:
@@ -1895,6 +1907,14 @@ packages:
   '@changesets/write@0.3.1':
     resolution: {integrity: sha512-SyGtMXzH3qFqlHKcvFY2eX+6b0NGiFcNav8AFsYwy5l8hejOeoeTDemu5Yjmke2V5jpzY+pBvM0vCCQ3gdZpfw==}
 
+  '@clack/core@0.3.4':
+    resolution: {integrity: sha512-H4hxZDXgHtWTwV3RAVenqcC4VbJZNegbBjlPvzOzCouXtS2y3sDvlO3IsbrPNWuLWPPlYVYPghQdSF64683Ldw==}
+
+  '@clack/prompts@0.7.0':
+    resolution: {integrity: sha512-0MhX9/B4iL6Re04jPrttDm+BsP8y6mS7byuv0BvXgdXhbV5PdlsHt55dvNsuBCPZ7xq1oTAOOuotR9NFbQyMSA==}
+    bundledDependencies:
+      - is-unicode-supported
+
   '@cloudflare/kv-asset-handler@0.3.4':
     resolution: {integrity: sha512-YLPHc8yASwjNkmcDMQMY35yiWjoKAKnhUbPRszBRS0YgH+IXtsMp61j+yTcnCE3oO2DgP0U3iejLC8FTtKDC8Q==}
     engines: {node: '>=16.13'}
@@ -3169,6 +3189,7 @@ 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
 
@@ -8241,6 +8262,9 @@ packages:
     resolution: {integrity: sha512-94Bdh3cC2PKrbgSOUqTiGPWVZeSiXfKOVZNJniWoqrWrRkB1CJzBU3NEbiTsPcYy1lDsANA/THzS+9WBiy5nfQ==}
     engines: {node: '>= 10'}
 
+  sisteransi@1.0.5:
+    resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==}
+
   slash@3.0.0:
     resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==}
     engines: {node: '>=8'}
@@ -10704,6 +10728,17 @@ snapshots:
       human-id: 1.0.2
       prettier: 2.8.8
 
+  '@clack/core@0.3.4':
+    dependencies:
+      picocolors: 1.0.1
+      sisteransi: 1.0.5
+
+  '@clack/prompts@0.7.0':
+    dependencies:
+      '@clack/core': 0.3.4
+      picocolors: 1.0.1
+      sisteransi: 1.0.5
+
   '@cloudflare/kv-asset-handler@0.3.4':
     dependencies:
       mime: 3.0.0
@@ -17426,6 +17461,8 @@ snapshots:
       mrmime: 2.0.0
       totalist: 3.0.1
 
+  sisteransi@1.0.5: {}
+
   slash@3.0.0: {}
 
   slash@4.0.0: {}

+ 3 - 0
scripts/turbo-run/README.md

@@ -0,0 +1,3 @@
+# @vben/vsh
+
+shell 脚本工具集合

+ 3 - 0
scripts/turbo-run/bin/turbo-run.mjs

@@ -0,0 +1,3 @@
+#!/usr/bin/env node
+
+import('../dist/index.mjs');

+ 7 - 0
scripts/turbo-run/build.config.ts

@@ -0,0 +1,7 @@
+import { defineBuildConfig } from 'unbuild';
+
+export default defineBuildConfig({
+  clean: true,
+  declaration: true,
+  entries: ['src/index'],
+});

+ 29 - 0
scripts/turbo-run/package.json

@@ -0,0 +1,29 @@
+{
+  "name": "@vben/turbo-run",
+  "version": "5.0.0",
+  "private": true,
+  "license": "MIT",
+  "type": "module",
+  "scripts": {
+    "stub": "pnpm unbuild --stub"
+  },
+  "files": [
+    "dist"
+  ],
+  "bin": {
+    "turbo-run": "./bin/turbo-run.mjs"
+  },
+  "main": "./dist/index.mjs",
+  "module": "./dist/index.mjs",
+  "exports": {
+    ".": {
+      "default": "./dist/index.mjs"
+    },
+    "./package.json": "./package.json"
+  },
+  "dependencies": {
+    "@clack/prompts": "^0.7.0",
+    "@vben/node-utils": "workspace:*",
+    "cac": "^6.7.14"
+  }
+}

+ 29 - 0
scripts/turbo-run/src/index.ts

@@ -0,0 +1,29 @@
+import { colors, consola } from '@vben/node-utils';
+
+import { cac } from 'cac';
+
+import { run } from './run';
+
+try {
+  const turboRun = cac('turbo-run');
+
+  turboRun
+    .command('[script]')
+    .usage(`Run turbo interactively.`)
+    .action(async (command: string) => {
+      run({ command });
+    });
+
+  // Invalid command
+  turboRun.on('command:*', () => {
+    consola.error(colors.red('Invalid command!'));
+    process.exit(1);
+  });
+
+  turboRun.usage('turbo-run');
+  turboRun.help();
+  turboRun.parse();
+} catch (error) {
+  consola.error(error);
+  process.exit(1);
+}

+ 63 - 0
scripts/turbo-run/src/run.ts

@@ -0,0 +1,63 @@
+import type { Package } from '@vben/node-utils';
+
+import { join } from 'node:path';
+
+import { $, fs, getPackages } from '@vben/node-utils';
+
+import { cancel, isCancel, multiselect } from '@clack/prompts';
+
+interface RunOptions {
+  command?: string;
+}
+
+export async function run(options: RunOptions) {
+  const { command } = options;
+  const { packages } = await getPackages();
+  const appPkgs = await findApps(process.cwd(), packages);
+
+  const selectApps = await multiselect<any, string>({
+    message: `Select the app you need to run [${command}]:`,
+    options: appPkgs.map((item) => ({ label: item, value: item })),
+    required: true,
+  });
+
+  if (isCancel(selectApps)) {
+    cancel('👋 Has cancelled');
+    process.exit(0);
+  }
+
+  if (selectApps.length === 1) {
+    $.verbose = true;
+    // 让控制台显示颜色
+    process.env.FORCE_COLOR = '1';
+    await $`pnpm --filter=${selectApps[0]} run ${command} `;
+    return;
+  }
+  const filters = [];
+  for (const app of selectApps) {
+    filters.push(`--filter=${app}`);
+  }
+  $.verbose = true;
+  // 让控制台显示颜色
+  process.env.FORCE_COLOR = '1';
+  await $`turbo run ${command} ${filters}`;
+}
+
+/**
+ * 过滤app包
+ * @param root
+ * @param packages
+ */
+async function findApps(root: string, packages: Package[]) {
+  // apps内的
+  const appPackages = packages
+    .filter((pkg) => {
+      const viteConfigExists = fs.existsSync(join(pkg.dir, 'vite.config.mts'));
+      return pkg.dir.startsWith(join(root, 'apps')) && viteConfigExists;
+    })
+    .map((pkg) => {
+      return pkg.packageJson.name;
+    });
+
+  return appPackages;
+}

+ 6 - 0
scripts/turbo-run/tsconfig.json

@@ -0,0 +1,6 @@
+{
+  "$schema": "https://json.schemastore.org/tsconfig",
+  "extends": "@vben/tsconfig/node.json",
+  "include": ["src"],
+  "exclude": ["node_modules"]
+}

+ 1 - 2
scripts/vsh/package.json

@@ -26,7 +26,6 @@
     "cac": "^6.7.14",
     "circular-dependency-scanner": "^2.2.2",
     "depcheck": "^1.4.7",
-    "publint": "^0.2.9",
-    "zx": "^8.1.4"
+    "publint": "^0.2.9"
   }
 }

+ 4 - 0
vben-admin.code-workspace

@@ -144,6 +144,10 @@
       "name": "@vben/utils",
       "path": "packages/utils",
     },
+    {
+      "name": "@vben/turbo-run",
+      "path": "scripts/turbo-run",
+    },
     {
       "name": "@vben/vsh",
       "path": "scripts/vsh",