vite-plugin-millennium-skin 1.0.9 → 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.9",
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) {
@@ -225,9 +273,7 @@ export default function millenniumSkin(): Plugin {
225
273
  const compileLib = bundle.fileName;
226
274
  if (type === "chunk") {
227
275
  if (!bundle.facadeModuleId) return;
228
- const compileParsed = path.parse(
229
- bundle.facadeModuleId as string,
230
- );
276
+ const compileParsed = path.parse(bundle.facadeModuleId);
231
277
  const compilePath = join(
232
278
  compileParsed.dir,
233
279
  compileParsed.name,
@@ -265,47 +311,12 @@ export default function millenniumSkin(): Plugin {
265
311
  skinConfigResult = {
266
312
  ...skinConfig,
267
313
  Patches: patches,
268
- version: "",
314
+ version: versions?.newString ?? "0.0.0",
269
315
  };
270
316
  },
271
317
 
272
318
  async writeBundle() {
273
319
  const root = viteConfig.root;
274
- const pkgPath = join(root, "package.json");
275
- // 版本自动管理
276
- try {
277
- const pkg = JSON.parse(
278
- await fsp.readFile(pkgPath, {
279
- flag: "r",
280
- encoding: "utf-8",
281
- }),
282
- );
283
- if (
284
- skinConfig.version === __AUTO__ ||
285
- skinConfig.version === undefined
286
- ) {
287
- const versions = await bump_version(
288
- pkg.version,
289
- process.env.RELEASE as any,
290
- );
291
- if (versions) {
292
- const newVersion = versionObjToString(versions.new);
293
- skinConfigResult.version = newVersion;
294
- pkg.version = newVersion;
295
- await fsp.writeFile(
296
- pkgPath,
297
- JSON.stringify(pkg, null, 4),
298
- );
299
- info(
300
- `${versionObjToString(versions.native)} -> ${newVersion}`,
301
- );
302
- }
303
- } else if (skinConfig.version === __PACKAGE__) {
304
- skinConfigResult.version = pkg.version;
305
- }
306
- } catch (e) {
307
- warn(`can't use package.json: ${e}`);
308
- }
309
320
 
310
321
  // 写入skin.json
311
322
  try {
@@ -395,6 +406,25 @@ export default function millenniumSkin(): Plugin {
395
406
  const result = generate(ast);
396
407
  return { code: result.code };
397
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
+ },
398
428
  };
399
429
  }
400
430
 
@@ -461,7 +491,16 @@ function createNestedMemberExpression(globalObj: string[]): t.MemberExpression {
461
491
  return node as t.MemberExpression;
462
492
  }
463
493
 
464
- 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> {
465
504
  try {
466
505
  const match = SEMANTIC_VERSIONING_REGEXP.exec(nativeVersion);
467
506
 
@@ -548,6 +587,8 @@ async function bump_version(nativeVersion: string, tag: bump_tag = "snapshot") {
548
587
  return {
549
588
  native: nativeVersionObj,
550
589
  new: version,
590
+ nativeString: nativeVersion,
591
+ newString: versionObjToString(version),
551
592
  };
552
593
  } catch (e) {
553
594
  warn(`can't bump version: ${e}`);
@@ -576,13 +617,19 @@ function versionObjToString(version: versionObject) {
576
617
  return versionString;
577
618
  }
578
619
 
579
- function warn(msg: string, options?: LogOptions) {
620
+ export function warn(msg: string, options?: LogOptions) {
580
621
  if (logger) logger.warn(chalk.yellow(`[MillenniumSkin] ${msg}`), options);
581
622
  else console.warn(chalk.yellow(`[MillenniumSkin] ${msg}`));
582
623
  }
583
624
 
584
- function info(msg: string, options?: LogOptions) {
625
+ export function info(msg: string, options?: LogOptions) {
585
626
  if (logger)
586
627
  logger.info(chalk.greenBright(`[MillenniumSkin] ${msg}`), options);
587
628
  else console.log(chalk.greenBright(`[MillenniumSkin] ${msg}`));
588
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,459 +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
- if (!r.facadeModuleId) return;
186
- const l = b.parse(
187
- r.facadeModuleId
188
- ), f = m(
189
- l.dir,
190
- l.name
191
- );
192
- u.forEach((d) => {
193
- f === d.TargetJs && (d.TargetJs = h);
194
- });
195
- } else {
196
- const l = b.parse(
197
- m(a, r.originalFileNames[0])
198
- ), f = m(
199
- l.dir,
200
- l.name
201
- );
202
- u.forEach((d) => {
203
- f === d.TargetCss && (d.TargetCss = h);
204
- }), t.RootColors && f === m(
205
- n.root,
206
- t.srcCss,
207
- t.RootColors
208
- ) && (t.RootColors = h);
209
- return;
210
- }
211
- }), e = {
212
- ...t,
213
- Patches: u,
214
- version: ""
215
- };
216
- },
217
- async writeBundle() {
218
- const i = n.root, p = m(i, "package.json");
219
- try {
220
- const a = JSON.parse(
221
- await k.readFile(p, {
222
- flag: "r",
223
- encoding: "utf-8"
224
- })
225
- );
226
- if (t.version === Z || t.version === void 0) {
227
- const u = await W(
228
- a.version,
229
- process.env.RELEASE
230
- );
231
- if (u) {
232
- const r = _(u.new);
233
- e.version = r, a.version = r, await k.writeFile(
234
- p,
235
- JSON.stringify(a, null, 4)
236
- ), X(
237
- `${_(u.native)} -> ${r}`
238
- );
239
- }
240
- } else t.version === B && (e.version = a.version);
241
- } catch (a) {
242
- j(`can't use package.json: ${a}`);
243
- }
244
- try {
245
- await k.writeFile(
246
- m(i, n.build.outDir, "skin.json"),
247
- JSON.stringify(e, null, 4)
248
- );
249
- } catch (a) {
250
- throw new Error(`can't write skin.json: ${a}`);
251
- }
252
- },
253
- transform(i, p) {
254
- if (!/.+\.(js|ts|tsx)$/g.test(p)) return;
255
- const a = A(i, {
256
- sourceType: "module",
257
- plugins: ["typescript", "jsx"]
258
- });
259
- return G(a, {
260
- Program(r) {
261
- const g = r.node.body, h = {};
262
- for (let l = g.length - 1; l >= 0; l--) {
263
- let f = g[l];
264
- if (!c.isImportDeclaration(f)) continue;
265
- const d = f.source.value, M = [];
266
- for (const T of z) {
267
- if (!T.module.test(d)) continue;
268
- const { method: R } = T;
269
- for (const C of f.specifiers) {
270
- const E = C.local.name;
271
- let y;
272
- switch (C.type === "ImportDefaultSpecifier" ? y = T.links : y = [
273
- ...T.links,
274
- C.imported.name
275
- ], R) {
276
- case O:
277
- h[E] = T.links;
278
- break;
279
- case $:
280
- M.push(
281
- U(
282
- E,
283
- y
284
- )
285
- );
286
- break;
287
- }
288
- }
289
- }
290
- M.length && g.splice(l, 1, ...M);
291
- }
292
- Object.entries(h).forEach(
293
- ([l, f]) => {
294
- const d = r.scope.getBinding(l);
295
- d !== void 0 && (d.referencePaths.forEach((M) => {
296
- H(M, l, f);
297
- }), d.scope.removeOwnBinding(l));
298
- }
299
- );
300
- }
301
- }), { code: P(a).code };
302
- }
303
- };
304
- }
305
- function fe(s) {
306
- return s;
307
- }
308
- function U(s, o) {
309
- let t = c.identifier(o[0]);
310
- for (let n = 1; n < o.length; n++)
311
- t = c.memberExpression(t, c.identifier(o[n]));
312
- const e = c.variableDeclarator(
313
- c.identifier(s),
314
- t
315
- );
316
- return c.variableDeclaration("const", [e]);
317
- }
318
- function J(s) {
319
- if (b.parse(s).ext !== "") return s;
320
- for (const t of ["scss", "sass", "css"]) {
321
- const e = `${s}.${t}`;
322
- if (I(m(process.cwd(), e)))
323
- return e;
324
- }
325
- throw new Error(`can't find css module: ${s}`);
326
- }
327
- function H(s, o, t) {
328
- const e = s.parent;
329
- if (c.isMemberExpression(e) && e.object === s.node) {
330
- const n = e.property;
331
- if (c.isIdentifier(n)) {
332
- const i = S(t);
333
- if (!s.parentPath) return;
334
- s.parentPath.replaceWith(
335
- c.memberExpression(i, c.identifier(n.name))
336
- );
337
- }
338
- return;
339
- }
340
- if (s.isIdentifier()) {
341
- const n = S(t);
342
- s.replaceWith(
343
- c.memberExpression(n, c.identifier(o))
344
- );
345
- }
346
- }
347
- function S(s) {
348
- if (s.length === 0)
349
- throw new Error("globalObj must not be empty");
350
- let o = c.identifier(s[0]);
351
- for (let t = 1; t < s.length; t++)
352
- o = c.memberExpression(o, c.identifier(s[t]));
353
- return o;
354
- }
355
- async function W(s, o = "snapshot") {
356
- try {
357
- const t = L.exec(s);
358
- if (!t?.groups) {
359
- j(`can't understand version: ${s}`);
360
- return;
361
- }
362
- let e = {
363
- major: parseInt(t.groups.major),
364
- minor: parseInt(t.groups.minor),
365
- patch: parseInt(t.groups.patch)
366
- };
367
- t.groups.preRelease && [
368
- ...t.groups.preRelease.matchAll(V)
369
- ].forEach((p) => {
370
- p.groups && (e[p.groups.tag] = parseInt(p.groups.number));
371
- });
372
- const n = { ...e };
373
- switch (o) {
374
- case null:
375
- break;
376
- case void 0:
377
- break;
378
- case "major":
379
- e = {
380
- major: e.major + 1,
381
- minor: 0,
382
- patch: 0
383
- };
384
- break;
385
- case "minor":
386
- e = {
387
- major: e.major,
388
- minor: e.minor + 1,
389
- patch: 0
390
- };
391
- break;
392
- case "patch":
393
- e = {
394
- major: e.major,
395
- minor: e.minor,
396
- patch: e.patch + 1
397
- };
398
- break;
399
- case "rc":
400
- e.rc = (e.rc ?? 0) + 1, delete e.gamma, delete e.beta, delete e.preview, delete e.alpha, delete e.snapshot;
401
- break;
402
- case "gamma":
403
- e.gamma = (e.gamma ?? 0) + 1, delete e.beta, delete e.preview, delete e.alpha, delete e.snapshot;
404
- break;
405
- case "beta":
406
- e.beta = (e.beta ?? 0) + 1, delete e.preview, delete e.alpha, delete e.snapshot;
407
- break;
408
- case "preview":
409
- e.preview = (e.preview ?? 0) + 1, delete e.alpha, delete e.snapshot;
410
- break;
411
- case "alpha":
412
- e.alpha = (e.alpha ?? 0) + 1, delete e.snapshot;
413
- break;
414
- case "snapshot":
415
- e.snapshot = (e.snapshot ?? 0) + 1;
416
- break;
417
- }
418
- return {
419
- native: n,
420
- new: e
421
- };
422
- } catch (t) {
423
- j(`can't bump version: ${t}`);
424
- }
425
- }
426
- function _(s) {
427
- let o = `${s.major}.${s.minor}.${s.patch}`;
428
- const t = ["rc", "gamma", "beta", "preview", "alpha", "snapshot"];
429
- let e = !1;
430
- for (const n of t) {
431
- const i = s[n];
432
- i != null && (e ? o += `.${n}.${i}` : (o += `-${n}.${i}`, e = !0));
433
- }
434
- return o;
435
- }
436
- function j(s, o) {
437
- w ? w.warn(v.yellow(`[MillenniumSkin] ${s}`), o) : console.warn(v.yellow(`[MillenniumSkin] ${s}`));
438
- }
439
- function X(s, o) {
440
- w ? w.info(v.greenBright(`[MillenniumSkin] ${s}`), o) : console.log(v.greenBright(`[MillenniumSkin] ${s}`));
441
- }
442
- export {
443
- ne as LibraryRoot,
444
- ge as MenuAccount,
445
- le as MenuFriends,
446
- ue as MenuGames,
447
- me as MenuHelp,
448
- pe as MenuNotifications,
449
- ce as MenuSteam,
450
- ie as MenuView,
451
- ae as Root,
452
- Z as __AUTO__,
453
- $ as __DIRECT__,
454
- B as __PACKAGE__,
455
- O as __RUNTIME__,
456
- de as default,
457
- fe as defineConfig,
458
- D as versionConfig
459
- };
@@ -1,2 +0,0 @@
1
- export declare const __AUTO__ = 0;
2
- export declare const __PACKAGE__ = 1;