vite-plugin-millennium-skin 1.0.8 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ a{color:red}
@@ -0,0 +1 @@
1
+ :root{--aaa: rgb(255, 255, 255, 0)}
@@ -0,0 +1 @@
1
+ const e={native:{major:1,minor:0,patch:9,beta:3},new:{major:1,minor:0,patch:9,beta:3,preview:1},nativeString:"1.0.9-beta.3",newString:"1.0.9-beta.3.preview.1"},n=window.opener.SP_REACT.createElement;n("div");console.log(e);
package/dist/skin.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "Transparent Steam",
3
+ "description": "description",
4
+ "author": "bvii",
5
+ "header_image": "",
6
+ "splash_image": "",
7
+ "github": {
8
+ "owner": "bviibvii",
9
+ "repo_name": "steam"
10
+ },
11
+ "RootColors": "assets/css/color.css",
12
+ "Patches": [
13
+ {
14
+ "MatchRegexString": "^Steam$",
15
+ "TargetJs": "assets/js/a.js",
16
+ "TargetCss": "assets/css/a.css"
17
+ }
18
+ ],
19
+ "srcCss": "lib",
20
+ "srcJs": "lib",
21
+ "version": "1.0.9-beta.3.preview.1"
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-millennium-skin",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "main": "./dist/index.js",
5
5
  "type": "module",
6
6
  "directories": {
@@ -9,7 +9,10 @@
9
9
  "types": "dist/index.d.ts",
10
10
  "scripts": {
11
11
  "lint": "eslint . --ext .ts",
12
- "build": "tsc --noEmit && vite build"
12
+ "build": "tsc --noEmit && vite build",
13
+ "build:beta": "tsc --noEmit && cross-env RELEASE=beta vite build",
14
+ "build:preview": "tsc --noEmit && cross-env RELEASE=preview vite build",
15
+ "ci": "npm publish"
13
16
  },
14
17
  "repository": {
15
18
  "type": "git",
@@ -53,6 +56,8 @@
53
56
  "@typescript-eslint/eslint-plugin": "^8.50.1",
54
57
  "babel-plugin-transform-typescript": "^7.0.0-alpha.19",
55
58
  "chalk": "^5.6.2",
59
+ "inquirer": "^13.1.0",
60
+ "simple-git": "^3.30.0",
56
61
  "vite-plugin-dts": "^4.5.4"
57
62
  }
58
63
  }
package/src/ts/git.ts ADDED
@@ -0,0 +1,58 @@
1
+ import inquirer from "inquirer";
2
+ import simpleGit from "simple-git";
3
+ import { info, error } from "./index";
4
+
5
+ const git = simpleGit();
6
+
7
+ export async function gitCommit(needCommitMessage: boolean = false) {
8
+ if (needCommitMessage) {
9
+ const answers = await inquirer.prompt([
10
+ {
11
+ type: "select",
12
+ name: "type",
13
+ message: "选择提交类型:",
14
+ choices: [
15
+ "feat",
16
+ "fix",
17
+ "docs",
18
+ "style",
19
+ "refactor",
20
+ "test",
21
+ "chore",
22
+ ],
23
+ default: "chore",
24
+ },
25
+ {
26
+ type: "input",
27
+ name: "message",
28
+ message: "输入提交信息:",
29
+ },
30
+ {
31
+ type: "confirm",
32
+ name: "confirm",
33
+ message: "确认提交?",
34
+ default: true,
35
+ },
36
+ ]);
37
+
38
+ if (!answers.confirm) {
39
+ info("❌ 已取消提交");
40
+ return;
41
+ }
42
+ try {
43
+ await git.add(".");
44
+ await git.commit(`${answers.type}: ${answers.message}`);
45
+ info("✓ git提交成功");
46
+ } catch (e) {
47
+ error(`❌ git提交失败: ${(e as Error).message}`);
48
+ }
49
+ } else {
50
+ try {
51
+ await git.add(".");
52
+ await git.commit("chore: auto commit by MillenniumSkin");
53
+ info("✓ git提交成功");
54
+ } catch (e) {
55
+ error(`❌ git提交失败: ${(e as Error).message}`);
56
+ }
57
+ }
58
+ }
package/src/ts/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Plugin, ResolvedConfig, Logger, LogOptions } from "vite";
2
2
  import type { Statement, MemberExpression, Identifier } from "@babel/types";
3
+ import type { autoCommitLevel, versionConfig } from "./versionConfig";
3
4
  import type { NodePath } from "@babel/traverse";
4
5
  import t from "@babel/types";
5
6
  import { parse } from "@babel/parser";
@@ -12,11 +13,13 @@ import { loadConfigFromFile } from "vite";
12
13
  import chalk from "chalk";
13
14
  import defaultPatches from "./defaultPatches";
14
15
  import aliasModules, { __DIRECT__, __RUNTIME__ } from "./aliasModules";
15
- import { __AUTO__, __PACKAGE__ } from "./versionConfig";
16
+ import { __DEFAULT__ } from "./versionConfig";
17
+ import { gitCommit } from "./git";
16
18
 
17
19
  export * from "./aliasModules";
18
20
  export * from "./defaultMatch";
19
21
  export * from "./versionConfig";
22
+ export * from "./versionConfig";
20
23
 
21
24
  export type SkinConfig = {
22
25
  name: string;
@@ -100,11 +103,6 @@ export type versionObject = {
100
103
  snapshot?: number;
101
104
  };
102
105
 
103
- export enum versionConfig {
104
- auto,
105
- package,
106
- }
107
-
108
106
  const traver = (traverse as any).default as typeof traverse;
109
107
  const SEMANTIC_VERSIONING_REGEXP =
110
108
  /(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<preRelease>(?:[a-zA-Z1-9][a-zA-Z\d]*|0\d*[a-zA-Z][a-zA-Z\d]*|0)(?:\.(?:[a-zA-Z1-9][a-zA-Z\d]*|0\d*[a-zA-Z][a-zA-Z\d]*|0))*))?(?:\+(?<metadata>(?:[a-zA-Z\d-]*)(?:\.(?:[a-zA-Z\d-]*))*))?/;
@@ -118,10 +116,25 @@ export default function millenniumSkin(): Plugin {
118
116
  let skinConfig: SkinConfig;
119
117
  let skinConfigResult: SkinConfigResult;
120
118
  let viteConfig: ResolvedConfig;
119
+ let versions: bumpResult | undefined;
120
+ const virtualModuleId = "virtual:millennium-skin";
121
+ const resolvedVirtualModuleId = "\0" + virtualModuleId;
121
122
  return {
122
123
  name: "vite-plugin-millennium-skin",
123
124
  enforce: "pre",
124
125
 
126
+ resolveId(source) {
127
+ if (source === virtualModuleId) {
128
+ return resolvedVirtualModuleId;
129
+ }
130
+ },
131
+
132
+ load(id) {
133
+ if (id === resolvedVirtualModuleId) {
134
+ return `export const version = ${versions ? JSON.stringify(versions) : "undefined"};`;
135
+ }
136
+ },
137
+
125
138
  async config(config) {
126
139
  const res = await loadConfigFromFile(
127
140
  { command: "build", mode: "profuction" },
@@ -180,9 +193,44 @@ export default function millenniumSkin(): Plugin {
180
193
  };
181
194
  },
182
195
 
183
- configResolved(config) {
196
+ async configResolved(config) {
184
197
  viteConfig = config;
185
198
  logger = config.logger;
199
+
200
+ const root = viteConfig.root;
201
+ const pkgPath = join(root, "package.json");
202
+ if (skinConfig.version === undefined)
203
+ skinConfig.version = __DEFAULT__;
204
+ // 版本自动管理
205
+ try {
206
+ const pkg = JSON.parse(
207
+ await fsp.readFile(pkgPath, {
208
+ flag: "r",
209
+ encoding: "utf-8",
210
+ }),
211
+ );
212
+
213
+ if (skinConfig.version.type === "auto") {
214
+ versions = await bump_version(
215
+ pkg.version,
216
+ process.env.RELEASE as any,
217
+ );
218
+ if (versions) {
219
+ const newVersion = versions.newString;
220
+ pkg.version = newVersion;
221
+ await fsp.writeFile(
222
+ pkgPath,
223
+ JSON.stringify(pkg, null, 4),
224
+ );
225
+ info(`${versions.nativeString} -> ${newVersion}`);
226
+ }
227
+ } else if (skinConfig.version.type === "package") {
228
+ versions = await bump_version(pkg.version);
229
+ }
230
+ } catch (e) {
231
+ warn(`can't use package.json: ${e}`);
232
+ versions = await bump_version("0.0.0");
233
+ }
186
234
  },
187
235
 
188
236
  generateBundle(_, bundles) {
@@ -224,9 +272,8 @@ export default function millenniumSkin(): Plugin {
224
272
 
225
273
  const compileLib = bundle.fileName;
226
274
  if (type === "chunk") {
227
- const compileParsed = path.parse(
228
- bundle.facadeModuleId as string,
229
- );
275
+ if (!bundle.facadeModuleId) return;
276
+ const compileParsed = path.parse(bundle.facadeModuleId);
230
277
  const compilePath = join(
231
278
  compileParsed.dir,
232
279
  compileParsed.name,
@@ -264,47 +311,12 @@ export default function millenniumSkin(): Plugin {
264
311
  skinConfigResult = {
265
312
  ...skinConfig,
266
313
  Patches: patches,
267
- version: "",
314
+ version: versions?.newString ?? "0.0.0",
268
315
  };
269
316
  },
270
317
 
271
318
  async writeBundle() {
272
319
  const root = viteConfig.root;
273
- const pkgPath = join(root, "package.json");
274
- // 版本自动管理
275
- try {
276
- const pkg = JSON.parse(
277
- await fsp.readFile(pkgPath, {
278
- flag: "r",
279
- encoding: "utf-8",
280
- }),
281
- );
282
- if (
283
- skinConfig.version === __AUTO__ ||
284
- skinConfig.version === undefined
285
- ) {
286
- const versions = await bump_version(
287
- pkg.version,
288
- process.env.RELEASE as any,
289
- );
290
- if (versions) {
291
- const newVersion = versionObjToString(versions.new);
292
- skinConfigResult.version = newVersion;
293
- pkg.version = newVersion;
294
- await fsp.writeFile(
295
- pkgPath,
296
- JSON.stringify(pkg, null, 4),
297
- );
298
- info(
299
- `${versionObjToString(versions.native)} -> ${newVersion}`,
300
- );
301
- }
302
- } else if (skinConfig.version === __PACKAGE__) {
303
- skinConfigResult.version = pkg.version;
304
- }
305
- } catch (e) {
306
- warn(`can't use package.json: ${e}`);
307
- }
308
320
 
309
321
  // 写入skin.json
310
322
  try {
@@ -394,6 +406,25 @@ export default function millenniumSkin(): Plugin {
394
406
  const result = generate(ast);
395
407
  return { code: result.code };
396
408
  },
409
+
410
+ async closeBundle(error?: Error) {
411
+ if (error) {
412
+ console.error("打包失败:", error);
413
+ return;
414
+ }
415
+ if (skinConfig.version?.git !== undefined) {
416
+ const tag = process.env.RELEASE as
417
+ | keyof versionConfig["git"]
418
+ | undefined;
419
+ if (tag && skinConfig.version.git[tag]) {
420
+ const gitConfig = skinConfig.version.git[
421
+ tag
422
+ ] as autoCommitLevel;
423
+ if (gitConfig.autoCommit)
424
+ await gitCommit(gitConfig.needCommitMessage);
425
+ }
426
+ }
427
+ },
397
428
  };
398
429
  }
399
430
 
@@ -460,7 +491,16 @@ function createNestedMemberExpression(globalObj: string[]): t.MemberExpression {
460
491
  return node as t.MemberExpression;
461
492
  }
462
493
 
463
- async function bump_version(nativeVersion: string, tag: bump_tag = "snapshot") {
494
+ type bumpResult = {
495
+ native: versionObject;
496
+ new: versionObject;
497
+ nativeString: string;
498
+ newString: string;
499
+ };
500
+ async function bump_version(
501
+ nativeVersion: string,
502
+ tag: bump_tag = null,
503
+ ): Promise<bumpResult | undefined> {
464
504
  try {
465
505
  const match = SEMANTIC_VERSIONING_REGEXP.exec(nativeVersion);
466
506
 
@@ -547,6 +587,8 @@ async function bump_version(nativeVersion: string, tag: bump_tag = "snapshot") {
547
587
  return {
548
588
  native: nativeVersionObj,
549
589
  new: version,
590
+ nativeString: nativeVersion,
591
+ newString: versionObjToString(version),
550
592
  };
551
593
  } catch (e) {
552
594
  warn(`can't bump version: ${e}`);
@@ -575,13 +617,19 @@ function versionObjToString(version: versionObject) {
575
617
  return versionString;
576
618
  }
577
619
 
578
- function warn(msg: string, options?: LogOptions) {
620
+ export function warn(msg: string, options?: LogOptions) {
579
621
  if (logger) logger.warn(chalk.yellow(`[MillenniumSkin] ${msg}`), options);
580
622
  else console.warn(chalk.yellow(`[MillenniumSkin] ${msg}`));
581
623
  }
582
624
 
583
- function info(msg: string, options?: LogOptions) {
625
+ export function info(msg: string, options?: LogOptions) {
584
626
  if (logger)
585
627
  logger.info(chalk.greenBright(`[MillenniumSkin] ${msg}`), options);
586
628
  else console.log(chalk.greenBright(`[MillenniumSkin] ${msg}`));
587
629
  }
630
+
631
+ export function error(msg: string, options?: LogOptions) {
632
+ if (logger)
633
+ logger.error(chalk.redBright(`[MillenniumSkin] ${msg}`), options);
634
+ else console.error(chalk.redBright(`[MillenniumSkin] ${msg}`));
635
+ }
@@ -1,2 +1,55 @@
1
- export const __AUTO__ = 0;
2
- export const __PACKAGE__ = 1;
1
+ export const __AUTO__: versionConfig = {
2
+ type: "auto",
3
+ git: {
4
+ major: { autoCommit: false },
5
+ minor: { autoCommit: false },
6
+ patch: { autoCommit: false },
7
+ rc: { autoCommit: true, needCommitMessage: true },
8
+ gamma: { autoCommit: true, needCommitMessage: true },
9
+ beta: { autoCommit: true, needCommitMessage: true },
10
+ preview: { autoCommit: true, needCommitMessage: false },
11
+ alpha: { autoCommit: true, needCommitMessage: false },
12
+ snapshot: { autoCommit: true, needCommitMessage: false },
13
+ },
14
+ };
15
+
16
+ export const __PACKAGE__: versionConfig = {
17
+ type: "auto",
18
+ git: {
19
+ major: { autoCommit: false },
20
+ minor: { autoCommit: false },
21
+ patch: { autoCommit: false },
22
+ rc: { autoCommit: false },
23
+ gamma: { autoCommit: false },
24
+ beta: { autoCommit: false },
25
+ preview: { autoCommit: false },
26
+ alpha: { autoCommit: false },
27
+ snapshot: { autoCommit: false },
28
+ },
29
+ };
30
+
31
+ export const __DEFAULT__: versionConfig = __AUTO__;
32
+
33
+ export type autoCommitLevel =
34
+ | {
35
+ autoCommit: false;
36
+ }
37
+ | {
38
+ autoCommit: true;
39
+ needCommitMessage: boolean;
40
+ };
41
+
42
+ export type versionConfig = {
43
+ type: "auto" | "package";
44
+ git?: {
45
+ major: autoCommitLevel;
46
+ minor: autoCommitLevel;
47
+ patch: autoCommitLevel;
48
+ rc: autoCommitLevel;
49
+ gamma: autoCommitLevel;
50
+ beta: autoCommitLevel;
51
+ preview: autoCommitLevel;
52
+ alpha: autoCommitLevel;
53
+ snapshot: autoCommitLevel;
54
+ };
55
+ };
@@ -0,0 +1,3 @@
1
+ declare module "virtual:millennium-skin" {
2
+ export const version: bumpResult | undefined;
3
+ }
package/vite.config.ts CHANGED
@@ -51,4 +51,4 @@ const rt: any = {
51
51
  plugins: [aaa()],
52
52
  };
53
53
 
54
- export default defineConfig(rg);
54
+ export default defineConfig(rt);
@@ -1,8 +0,0 @@
1
- export declare const __DIRECT__ = 0;
2
- export declare const __RUNTIME__ = 1;
3
- declare const _default: {
4
- method: number;
5
- module: RegExp;
6
- links: string[];
7
- }[];
8
- export default _default;
@@ -1,9 +0,0 @@
1
- export declare const Root: RegExp;
2
- export declare const LibraryRoot: RegExp;
3
- export declare const MenuView: RegExp;
4
- export declare const MenuSteam: RegExp;
5
- export declare const MenuFriends: RegExp;
6
- export declare const MenuGames: RegExp;
7
- export declare const MenuHelp: RegExp;
8
- export declare const MenuNotifications: RegExp;
9
- export declare const MenuAccount: RegExp;
@@ -1,6 +0,0 @@
1
- declare const _default: {
2
- Match: string;
3
- TargetCss: string;
4
- TargetJs: string;
5
- }[];
6
- export default _default;
package/dist/index.d.ts DELETED
@@ -1,73 +0,0 @@
1
- import { Plugin } from 'vite';
2
- export * from './aliasModules';
3
- export * from './defaultMatch';
4
- export * from './versionConfig';
5
- export type SkinConfig = {
6
- name: string;
7
- description: string;
8
- author: string;
9
- version?: versionConfig;
10
- tags?: string[];
11
- header_image: string;
12
- splash_image: string;
13
- github: {
14
- owner: string;
15
- repo_name: string;
16
- };
17
- discord_support?: {
18
- inviteCodeExcludingLink?: string;
19
- };
20
- "Steam-WebKit"?: string;
21
- UseDefaultPatches?: boolean;
22
- RootColors?: string;
23
- Patches?: Patch[];
24
- srcJs: string;
25
- srcCss: string;
26
- };
27
- export type SkinConfigResult = {
28
- name: string;
29
- description: string;
30
- author: string;
31
- version: string;
32
- header_image: string;
33
- splash_image: string;
34
- github: {
35
- owner: string;
36
- repo_name: string;
37
- };
38
- RootColors?: string;
39
- Patches: PatchResult[];
40
- };
41
- export type Patch = {
42
- Match: string | RegExp;
43
- TargetCss?: string;
44
- TargetJs?: string;
45
- };
46
- export type PatchResult = {
47
- MatchRegexString: string;
48
- TargetCss?: string;
49
- TargetJs?: string;
50
- };
51
- export type namedExports = namedExport[];
52
- export type namedExport = {
53
- exportLocal: string;
54
- links: string[];
55
- };
56
- export type bump_tag = null | undefined | "major" | "minor" | "patch" | "rc" | "gamma" | "beta" | "preview" | "alpha" | "snapshot";
57
- export type versionObject = {
58
- major: number;
59
- minor: number;
60
- patch: number;
61
- rc?: number;
62
- gamma?: number;
63
- beta?: number;
64
- preview?: number;
65
- alpha?: number;
66
- snapshot?: number;
67
- };
68
- export declare enum versionConfig {
69
- auto = 0,
70
- package = 1
71
- }
72
- export default function millenniumSkin(): Plugin;
73
- export declare function defineConfig(SkinConfig: SkinConfig): SkinConfig;
package/dist/index.js DELETED
@@ -1,458 +0,0 @@
1
- import c from "@babel/types";
2
- import { parse as A } from "@babel/parser";
3
- import x from "@babel/traverse";
4
- import { generate as P } from "@babel/generator";
5
- import b, { join as m } from "path/posix";
6
- import { existsSync as I } from "fs";
7
- import k from "fs/promises";
8
- import { loadConfigFromFile as F } from "vite";
9
- import v from "chalk";
10
- const N = [
11
- {
12
- Match: "https://.*.steampowered.com",
13
- TargetCss: "webkit.css",
14
- TargetJs: "webkit.js"
15
- },
16
- {
17
- Match: "https://steamcommunity.com",
18
- TargetCss: "webkit.css",
19
- TargetJs: "webkit.js"
20
- },
21
- {
22
- Match: "^Steam$",
23
- TargetCss: "libraryroot.custom.css",
24
- TargetJs: "libraryroot.custom.js"
25
- },
26
- {
27
- Match: "^OverlayBrowser_Browser$",
28
- TargetCss: "libraryroot.custom.css",
29
- TargetJs: "libraryroot.custom.js"
30
- },
31
- {
32
- Match: "^SP Overlay:",
33
- TargetCss: "libraryroot.custom.css",
34
- TargetJs: "libraryroot.custom.js"
35
- },
36
- {
37
- Match: "Supernav$",
38
- TargetCss: "libraryroot.custom.css",
39
- TargetJs: "libraryroot.custom.js"
40
- },
41
- {
42
- Match: "^notificationtoasts_",
43
- TargetCss: "notifications.custom.css",
44
- TargetJs: "notifications.custom.js"
45
- },
46
- {
47
- Match: "^SteamBrowser_Find$",
48
- TargetCss: "libraryroot.custom.css",
49
- TargetJs: "libraryroot.custom.js"
50
- },
51
- {
52
- Match: "^OverlayTab\\d+_Find$",
53
- TargetCss: "libraryroot.custom.css",
54
- TargetJs: "libraryroot.custom.js"
55
- },
56
- {
57
- Match: "^Steam Big Picture Mode$",
58
- TargetCss: "bigpicture.custom.css",
59
- TargetJs: "bigpicture.custom.js"
60
- },
61
- {
62
- Match: "^QuickAccess_",
63
- TargetCss: "bigpicture.custom.css",
64
- TargetJs: "bigpicture.custom.js"
65
- },
66
- {
67
- Match: "^MainMenu_",
68
- TargetCss: "bigpicture.custom.css",
69
- TargetJs: "bigpicture.custom.js"
70
- },
71
- {
72
- Match: ".friendsui-container",
73
- TargetCss: "friends.custom.css",
74
- TargetJs: "friends.custom.js"
75
- },
76
- {
77
- Match: "Menu$",
78
- TargetCss: "libraryroot.custom.css",
79
- TargetJs: "libraryroot.custom.js"
80
- },
81
- {
82
- Match: ".ModalDialogPopup",
83
- TargetCss: "libraryroot.custom.css",
84
- TargetJs: "libraryroot.custom.js"
85
- },
86
- {
87
- Match: ".FullModalOverlay",
88
- TargetCss: "libraryroot.custom.css",
89
- TargetJs: "libraryroot.custom.js"
90
- }
91
- ], $ = 0, O = 1, z = [
92
- {
93
- method: $,
94
- module: /^react$/g,
95
- links: ["window", "opener", "SP_REACT"]
96
- },
97
- {
98
- method: $,
99
- module: /^react-dom$/g,
100
- links: ["window", "opener", "SP_REACTDOM"]
101
- }
102
- ], Z = 0, B = 1, ae = /^SharedJSContext$/, ne = /^Steam$/, ie = /^View Root Menu$/, ce = /^Steam Root Menu$/, le = /^Friends Root Menu$/, ue = /^Games Root Menu$/, me = /^Help Root Menu$/, pe = /^Notifications Menu$/, ge = /^Account Menu$/;
103
- var D = /* @__PURE__ */ ((s) => (s[s.auto = 0] = "auto", s[s.package = 1] = "package", s))(D || {});
104
- const G = x.default, L = /(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<preRelease>(?:[a-zA-Z1-9][a-zA-Z\d]*|0\d*[a-zA-Z][a-zA-Z\d]*|0)(?:\.(?:[a-zA-Z1-9][a-zA-Z\d]*|0\d*[a-zA-Z][a-zA-Z\d]*|0))*))?(?:\+(?<metadata>(?:[a-zA-Z\d-]*)(?:\.(?:[a-zA-Z\d-]*))*))?/, V = /(?:\.)?(?<tag>[a-zA-Z]+)\.(?<number>(?:[1-9]\d*|0\d*|0))/g;
105
- let w;
106
- function de() {
107
- const s = [], o = [];
108
- let t, e, n;
109
- return {
110
- name: "vite-plugin-millennium-skin",
111
- enforce: "pre",
112
- async config(i) {
113
- if (t = (await F(
114
- { command: "build", mode: "profuction" },
115
- "skin.config.ts",
116
- i.root
117
- ))?.config, t.Patches === void 0) {
118
- if (!t.UseDefaultPatches)
119
- throw new Error("haven't any patch in skin.config.ts");
120
- t.Patches = N;
121
- }
122
- return t.Patches.forEach((a) => {
123
- a.TargetJs && s.push(m(t.srcJs, a.TargetJs)), a.TargetCss && o.push(
124
- J(m(t.srcCss, a.TargetCss))
125
- );
126
- }), t.RootColors !== void 0 && o.push(
127
- J(
128
- m(t.srcCss, t.RootColors)
129
- )
130
- ), {
131
- build: {
132
- rollupOptions: {
133
- input: [...s, ...o],
134
- output: {
135
- entryFileNames: "assets/js/[name].js",
136
- assetFileNames: (a) => {
137
- const u = a.names[0], r = b.parse(u);
138
- return r.ext === ".css" ? `assets/css/${u}` : /\.(png|jpg|jpeg|gif|svg|webp|bmp|heic)/i.test(
139
- r.ext
140
- ) ? `assets/images/${u}` : `assets/css/${u}`;
141
- }
142
- }
143
- },
144
- assetsInlineLimit: 0,
145
- cssCodeSplit: !0
146
- }
147
- };
148
- },
149
- configResolved(i) {
150
- n = i, w = i.logger;
151
- },
152
- generateBundle(i, p) {
153
- if (t.Patches === void 0)
154
- throw new Error("haven't any patch in building");
155
- const a = n.root, u = structuredClone(
156
- t.Patches
157
- ).map((r) => {
158
- if (r.Match instanceof RegExp && (r.Match = r.Match.source), r.TargetJs) {
159
- const g = b.parse(r.TargetJs);
160
- r.TargetJs = m(
161
- a,
162
- t.srcJs,
163
- g.dir,
164
- g.name
165
- );
166
- }
167
- if (r.TargetCss) {
168
- const g = b.parse(r.TargetCss);
169
- r.TargetCss = m(
170
- a,
171
- t.srcCss,
172
- g.dir,
173
- g.name
174
- );
175
- }
176
- return {
177
- MatchRegexString: r.Match,
178
- TargetJs: r.TargetJs,
179
- TargetCss: r.TargetCss
180
- };
181
- });
182
- Object.entries(p).forEach(([, r]) => {
183
- const { type: g } = r, h = r.fileName;
184
- if (g === "chunk") {
185
- const l = b.parse(
186
- r.facadeModuleId
187
- ), f = m(
188
- l.dir,
189
- l.name
190
- );
191
- u.forEach((d) => {
192
- f === d.TargetJs && (d.TargetJs = h);
193
- });
194
- } else {
195
- const l = b.parse(
196
- m(a, r.originalFileNames[0])
197
- ), f = m(
198
- l.dir,
199
- l.name
200
- );
201
- u.forEach((d) => {
202
- f === d.TargetCss && (d.TargetCss = h);
203
- }), t.RootColors && f === m(
204
- n.root,
205
- t.srcCss,
206
- t.RootColors
207
- ) && (t.RootColors = h);
208
- return;
209
- }
210
- }), e = {
211
- ...t,
212
- Patches: u,
213
- version: ""
214
- };
215
- },
216
- async writeBundle() {
217
- const i = n.root, p = m(i, "package.json");
218
- try {
219
- const a = JSON.parse(
220
- await k.readFile(p, {
221
- flag: "r",
222
- encoding: "utf-8"
223
- })
224
- );
225
- if (t.version === Z || t.version === void 0) {
226
- const u = await W(
227
- a.version,
228
- process.env.RELEASE
229
- );
230
- if (u) {
231
- const r = _(u.new);
232
- e.version = r, a.version = r, await k.writeFile(
233
- p,
234
- JSON.stringify(a, null, 4)
235
- ), X(
236
- `${_(u.native)} -> ${r}`
237
- );
238
- }
239
- } else t.version === B && (e.version = a.version);
240
- } catch (a) {
241
- j(`can't use package.json: ${a}`);
242
- }
243
- try {
244
- await k.writeFile(
245
- m(i, n.build.outDir, "skin.json"),
246
- JSON.stringify(e, null, 4)
247
- );
248
- } catch (a) {
249
- throw new Error(`can't write skin.json: ${a}`);
250
- }
251
- },
252
- transform(i, p) {
253
- if (!/.+\.(js|ts|tsx)$/g.test(p)) return;
254
- const a = A(i, {
255
- sourceType: "module",
256
- plugins: ["typescript", "jsx"]
257
- });
258
- return G(a, {
259
- Program(r) {
260
- const g = r.node.body, h = {};
261
- for (let l = g.length - 1; l >= 0; l--) {
262
- let f = g[l];
263
- if (!c.isImportDeclaration(f)) continue;
264
- const d = f.source.value, M = [];
265
- for (const T of z) {
266
- if (!T.module.test(d)) continue;
267
- const { method: R } = T;
268
- for (const C of f.specifiers) {
269
- const E = C.local.name;
270
- let y;
271
- switch (C.type === "ImportDefaultSpecifier" ? y = T.links : y = [
272
- ...T.links,
273
- C.imported.name
274
- ], R) {
275
- case O:
276
- h[E] = T.links;
277
- break;
278
- case $:
279
- M.push(
280
- U(
281
- E,
282
- y
283
- )
284
- );
285
- break;
286
- }
287
- }
288
- }
289
- M.length && g.splice(l, 1, ...M);
290
- }
291
- Object.entries(h).forEach(
292
- ([l, f]) => {
293
- const d = r.scope.getBinding(l);
294
- d !== void 0 && (d.referencePaths.forEach((M) => {
295
- H(M, l, f);
296
- }), d.scope.removeOwnBinding(l));
297
- }
298
- );
299
- }
300
- }), { code: P(a).code };
301
- }
302
- };
303
- }
304
- function fe(s) {
305
- return s;
306
- }
307
- function U(s, o) {
308
- let t = c.identifier(o[0]);
309
- for (let n = 1; n < o.length; n++)
310
- t = c.memberExpression(t, c.identifier(o[n]));
311
- const e = c.variableDeclarator(
312
- c.identifier(s),
313
- t
314
- );
315
- return c.variableDeclaration("const", [e]);
316
- }
317
- function J(s) {
318
- if (b.parse(s).ext !== "") return s;
319
- for (const t of ["scss", "sass", "css"]) {
320
- const e = `${s}.${t}`;
321
- if (I(m(process.cwd(), e)))
322
- return e;
323
- }
324
- throw new Error(`can't find css module: ${s}`);
325
- }
326
- function H(s, o, t) {
327
- const e = s.parent;
328
- if (c.isMemberExpression(e) && e.object === s.node) {
329
- const n = e.property;
330
- if (c.isIdentifier(n)) {
331
- const i = S(t);
332
- if (!s.parentPath) return;
333
- s.parentPath.replaceWith(
334
- c.memberExpression(i, c.identifier(n.name))
335
- );
336
- }
337
- return;
338
- }
339
- if (s.isIdentifier()) {
340
- const n = S(t);
341
- s.replaceWith(
342
- c.memberExpression(n, c.identifier(o))
343
- );
344
- }
345
- }
346
- function S(s) {
347
- if (s.length === 0)
348
- throw new Error("globalObj must not be empty");
349
- let o = c.identifier(s[0]);
350
- for (let t = 1; t < s.length; t++)
351
- o = c.memberExpression(o, c.identifier(s[t]));
352
- return o;
353
- }
354
- async function W(s, o = "snapshot") {
355
- try {
356
- const t = L.exec(s);
357
- if (!t?.groups) {
358
- j(`can't understand version: ${s}`);
359
- return;
360
- }
361
- let e = {
362
- major: parseInt(t.groups.major),
363
- minor: parseInt(t.groups.minor),
364
- patch: parseInt(t.groups.patch)
365
- };
366
- t.groups.preRelease && [
367
- ...t.groups.preRelease.matchAll(V)
368
- ].forEach((p) => {
369
- p.groups && (e[p.groups.tag] = parseInt(p.groups.number));
370
- });
371
- const n = { ...e };
372
- switch (o) {
373
- case null:
374
- break;
375
- case void 0:
376
- break;
377
- case "major":
378
- e = {
379
- major: e.major + 1,
380
- minor: 0,
381
- patch: 0
382
- };
383
- break;
384
- case "minor":
385
- e = {
386
- major: e.major,
387
- minor: e.minor + 1,
388
- patch: 0
389
- };
390
- break;
391
- case "patch":
392
- e = {
393
- major: e.major,
394
- minor: e.minor,
395
- patch: e.patch + 1
396
- };
397
- break;
398
- case "rc":
399
- e.rc = (e.rc ?? 0) + 1, delete e.gamma, delete e.beta, delete e.preview, delete e.alpha, delete e.snapshot;
400
- break;
401
- case "gamma":
402
- e.gamma = (e.gamma ?? 0) + 1, delete e.beta, delete e.preview, delete e.alpha, delete e.snapshot;
403
- break;
404
- case "beta":
405
- e.beta = (e.beta ?? 0) + 1, delete e.preview, delete e.alpha, delete e.snapshot;
406
- break;
407
- case "preview":
408
- e.preview = (e.preview ?? 0) + 1, delete e.alpha, delete e.snapshot;
409
- break;
410
- case "alpha":
411
- e.alpha = (e.alpha ?? 0) + 1, delete e.snapshot;
412
- break;
413
- case "snapshot":
414
- e.snapshot = (e.snapshot ?? 0) + 1;
415
- break;
416
- }
417
- return {
418
- native: n,
419
- new: e
420
- };
421
- } catch (t) {
422
- j(`can't bump version: ${t}`);
423
- }
424
- }
425
- function _(s) {
426
- let o = `${s.major}.${s.minor}.${s.patch}`;
427
- const t = ["rc", "gamma", "beta", "preview", "alpha", "snapshot"];
428
- let e = !1;
429
- for (const n of t) {
430
- const i = s[n];
431
- i != null && (e ? o += `.${n}.${i}` : (o += `-${n}.${i}`, e = !0));
432
- }
433
- return o;
434
- }
435
- function j(s, o) {
436
- w ? w.warn(v.yellow(`[MillenniumSkin] ${s}`), o) : console.warn(v.yellow(`[MillenniumSkin] ${s}`));
437
- }
438
- function X(s, o) {
439
- w ? w.info(v.greenBright(`[MillenniumSkin] ${s}`), o) : console.log(v.greenBright(`[MillenniumSkin] ${s}`));
440
- }
441
- export {
442
- ne as LibraryRoot,
443
- ge as MenuAccount,
444
- le as MenuFriends,
445
- ue as MenuGames,
446
- me as MenuHelp,
447
- pe as MenuNotifications,
448
- ce as MenuSteam,
449
- ie as MenuView,
450
- ae as Root,
451
- Z as __AUTO__,
452
- $ as __DIRECT__,
453
- B as __PACKAGE__,
454
- O as __RUNTIME__,
455
- de as default,
456
- fe as defineConfig,
457
- D as versionConfig
458
- };
@@ -1,2 +0,0 @@
1
- export declare const __AUTO__ = 0;
2
- export declare const __PACKAGE__ = 1;