Skip to content

Commit

Permalink
optimize: paths
Browse files Browse the repository at this point in the history
  • Loading branch information
snowtafir committed Oct 7, 2024
1 parent 87303a5 commit d21a9d8
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# 2.0.4
* 增加splitHeight配置项,其他优化
* 优化B站风控相关,新增bili_tiket参数
* fix Repeated Instantiation Puppeteer
* 优化获取B站登录ck
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yz-yuki-plugin",
"version": "2.0.4-7",
"version": "2.0.4-8",
"description": "优纪插件,yunzaijs 关于 微博推送、B站推送 等功能的拓展插件",
"author": "snowtafir",
"type": "module",
Expand Down
11 changes: 6 additions & 5 deletions src/components/dynamic/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// up账户组件
import React from 'react';
import LogoText from '@/components/dynamic/LogoText';
import { _paths } from '@/utils/paths';
import path from 'path';
import { _paths, createRequire } from '@/utils/paths';

const Bilibililogo: string = path.join(_paths.pluginResources, 'img/icon/dynamic/bilibili.svg')
const Weibilogo: string = path.join(_paths.pluginResources, 'img/icon/dynamic/weibo.svg')
const AccountCss: string = path.join(_paths.pluginResources, 'css/dynamic/Account.css')
const require = createRequire(import.meta.url);

const Bilibililogo: string = require('./../../../resources/img/icon/dynamic/bilibili.svg')
const Weibilogo: string = require('./../../../resources/img/icon/dynamic/weibo.svg')
const AccountCss: string = require('./../../../resources/css/dynamic/Account.css')

type AccountProps = {
data: {
Expand Down
11 changes: 6 additions & 5 deletions src/components/dynamic/Content.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// DynamicContent.tsx
import React from 'react';
import { _paths } from '@/utils/paths';
import path from 'path';
import { _paths, createRequire } from '@/utils/paths';

const ContentBoxGrid4Css: string = path.join(_paths.pluginResources, 'css/dynamic/Content.box.grid.4.css')
const ContentBoxGrid9Css: string = path.join(_paths.pluginResources, 'css/dynamic/Content.box.grid.9.css')
const ContentCss: string = path.join(_paths.pluginResources, 'css/dynamic/Content.css')
const require = createRequire(import.meta.url);

const ContentBoxGrid4Css: string = require('./../../resources/css/dynamic/Content.box.grid.4.css')
const ContentBoxGrid9Css: string = require('./../../resources/css/dynamic/Content.box.grid.9.css')
const ContentCss: string = require('./../../resources/css/dynamic/Content.css')

type ContentProps = {
data: {
Expand Down
10 changes: 6 additions & 4 deletions src/components/dynamic/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
import React from 'react';
import { BOT_NAME, ConfigController } from 'yunzai';
import Config from '@/utils/config';
import { _paths } from '@/utils/paths';
import path from 'path';
import { _paths, createRequire } from '@/utils/paths';

const require = createRequire(import.meta.url);

const botVersion = ConfigController.package?.version;
const yukiPluginVersion = Config.getPackageJsonKey('version', path.join(_paths.pluginPath, 'package.json'));

const bilibililogo: string = path.join(_paths.pluginResources, 'img/icon/dynamic/bilibili.svg')
const weibilogo: string = path.join(_paths.pluginResources, 'img/icon/dynamic/weibo.svg')
const FooterCss: string = path.join(_paths.pluginResources, 'css/dynamic/Footer.css')
const bilibililogo: string = require('./../../../resources/img/icon/dynamic/bilibili.svg')
const weibilogo: string = require('./../../../resources/img/icon/dynamic/weibo.svg')
const FooterCss: string = require('./../../../resources/css/dynamic/Footer.css')

type FooterProps = {
data: {
Expand Down
7 changes: 4 additions & 3 deletions src/components/dynamic/ForwardContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import React from 'react';
import Account from '@/components/dynamic/Account';
import Content from '@/components/dynamic/Content';
import { _paths } from '@/utils/paths';
import path from 'path';
import { _paths, createRequire } from '@/utils/paths';

const ForwardContentCss: string = path.join(_paths.pluginResources, 'css/dynamic/ForwardContent.css');
const require = createRequire(import.meta.url);

const ForwardContentCss: string = require('./../../../resources/css/dynamic/ForwardContent.css');

type ForwardContentProps = {
data?: any;
Expand Down
7 changes: 4 additions & 3 deletions src/components/dynamic/LogoText.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// LogoText
// Logo 文本组件
import React from 'react';
import { _paths } from '@/utils/paths';
import path from 'path';
import { _paths, createRequire } from '@/utils/paths';

const LogoTextCss: string = path.join(_paths.pluginResources, 'css/dynamic/LogoText.css')
const require = createRequire(import.meta.url);

const LogoTextCss: string = require('./../../../resources/css/dynamic/LogoText.css')

type LogoTextProps = {
data: {
Expand Down
7 changes: 4 additions & 3 deletions src/components/dynamic/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import Account from '@/components/dynamic/Account';
import Content from '@/components/dynamic/Content';
import ForwardContent from '@/components/dynamic/ForwardContent';
import Footer from '@/components/dynamic/Footer';
import { _paths } from '@/utils/paths';
import path from 'path';
import { _paths, createRequire } from '@/utils/paths';

const MainPageCss: string = path.join(_paths.pluginResources, 'css/dynamic/MainPage.css')
const require = createRequire(import.meta.url);

const MainPageCss: string = require('./../../resources/css/dynamic/MainPage.css')

export type MainProps = {
data: {
Expand Down
8 changes: 5 additions & 3 deletions src/components/help/Help.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
import React from 'react';
import { BOT_NAME, ConfigController } from 'yunzai';
import Config from '@/utils/config';
import { _paths } from '@/utils/paths';
import path from 'path';
import { _paths, createRequire } from '@/utils/paths';

const require = createRequire(import.meta.url);

const botVersion = ConfigController.package?.version;
const yukiPluginVersion = Config.getPackageJsonKey('version', path.join(_paths.pluginPath, 'package.json'));

const HelpCss: string = path.join(_paths.pluginResources, 'css/help/help.css')
const iconPath = (iconName: string) => path.join(_paths.pluginResources, `img/icon/puplic/${iconName}.png`)
const HelpCss: string = require('./../../../resources/css/help/help.css')
const iconPath = (iconName: string) => require(`./../../../resources/img/icon/puplic/${iconName}.png`)

export type HelpPageProps = {
data: {
Expand Down
7 changes: 4 additions & 3 deletions src/components/loginQrcode/Page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// QrcodeLoginPage.tsx
import React from 'react';
import { _paths } from '@/utils/paths';
import path from 'path';
import { _paths, createRequire } from '@/utils/paths';

const LoginQrcodeCss: string = path.join(_paths.pluginResources, 'css/loginQrcode/Page.css')
const require = createRequire(import.meta.url);

const LoginQrcodeCss: string = require('./../../../resources/css/loginQrcode/Page.css')

export type LoginProps = {
data: {
Expand Down
6 changes: 4 additions & 2 deletions src/components/version/Version.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react';
import { BOT_NAME, ConfigController } from 'yunzai';
import Config from '../../utils/config';
import { _paths } from '@/utils/paths';
import path from 'path';
import { _paths, createRequire } from '@/utils/paths';

const require = createRequire(import.meta.url);

const botVersion = ConfigController.package?.version;
const yukiPluginVersion = Config.getPackageJsonKey('version', path.join(_paths.pluginPath, 'package.json'));

const VersionCss: string = path.join(_paths.pluginResources, 'css/version/version.css')
const VersionCss: string = require('./../../../resources/css/version/version.css')

export type VersionProps = {
data: {
Expand Down
24 changes: 23 additions & 1 deletion src/utils/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,26 @@ export const _paths = {
pluginPath, // yuki-plugin根目录
pluginResources: join(pluginPath, 'resources'), // yuki-plugin资源目录
pluginName, // 插件所在文件夹名称
}
}

/**
* 使用import.meta.url得到require
* @param basePath
* @returns
* 这并不是
* ***
* import { createRequire } from "module"
* ***
* 原型为
* new URL(path, import.meta.url).href
*/
export const createRequire = (basePath: string) => {
return (path: string) => {
if (process.platform === 'linux' || process.platform === 'android' || process.platform === 'darwin') {
return new URL(path, basePath).href.replace(/^file:\/\//, '');
}
else {
return new URL(path, basePath).href.replace(/^file:\/\/\//, ''); // windows
}
};
};

0 comments on commit d21a9d8

Please sign in to comment.