Skip to content

Commit

Permalink
fix: aPPDevTool 获取 resourceDir 适配vue-cli、vite
Browse files Browse the repository at this point in the history
APPDevTool 获取 resourceDir 适配vue-cli、vite
  • Loading branch information
hewx815 committed Oct 26, 2023
1 parent 9b2341d commit 0fb40ae
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 9 deletions.
6 changes: 0 additions & 6 deletions for-vue2/src/packages/plugins/APPDevTool/TODO
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@

## BUG androidSdkPath 效验

## BUG javaPath 效验

## BUG resourceDir 效验

## XXX resourceDir 默认值 根据uniapp版本动态变化 ,

## BUG 自动下载 Build Tools

## BUG 自动下载 java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { resolve } from 'path';
import type { Argvs } from '../index.js';
import type { DeviceOptions } from './choiceDevice.js';

import { getConfig, initTemplate } from '../common/index.js';
import { getConfig, initTemplate, getResourcePath } from '../common/index.js';
import { err, checkPathExists } from '../utils.js';

import buildApk from './buildAPK.js';
Expand Down Expand Up @@ -53,7 +53,7 @@ export default async function androidServer(argvs: Argvs) {
}
}

const resourceDir = userConfig.resourceDir || resolve(process.cwd(), './dist/build/app-plus');
const resourceDir = getResourcePath(userConfig);

const abdPath = resolve(process.env.ANDROID_SDK_ROOT, './platform-tools');

Expand Down
33 changes: 33 additions & 0 deletions for-vue2/src/packages/plugins/APPDevTool/common/getResourcePath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { resolve } from 'path';
import { checkPathExists, err } from '../utils.js';
import type { Config } from '../config.js';

export default function getResourcePath(
userConfig: Config,
): string {
const CLI_DEV_RESOURCE_PATH = resolve(process.cwd(), './dist/dev/app-plus');
const VITE_DEV_RESOURCE_PATH = resolve(process.cwd(), './dist/dev/app');

const CLI_BUILD_RESOURCE_PATH = resolve(process.cwd(), './dist/build/app-plus');
const VITE_BUILD_RESOURCE_PATH = resolve(process.cwd(), './dist/build/app');

if (userConfig.resourceDir) {
return userConfig.resourceDir;
}

if (process.env.H_UNI_APPDEVTOOL_ENV === 'development') {
// vue-cli
if (checkPathExists(CLI_DEV_RESOURCE_PATH)) return CLI_DEV_RESOURCE_PATH;
// vite
if (checkPathExists(VITE_DEV_RESOURCE_PATH)) return VITE_DEV_RESOURCE_PATH;
}

if (process.env.H_UNI_APPDEVTOOL_ENV === 'production') {
// vue-cli
if (checkPathExists(CLI_BUILD_RESOURCE_PATH)) return CLI_BUILD_RESOURCE_PATH;
// vite
if (checkPathExists(VITE_BUILD_RESOURCE_PATH)) return VITE_BUILD_RESOURCE_PATH;
}

return err('未能正确获取 APP 资源目录') as string;
}
1 change: 1 addition & 0 deletions for-vue2/src/packages/plugins/APPDevTool/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as initTemplate } from './initTemplate.js';
export { default as help } from './help.js';
export { default as getConfig } from './getConfig.js';
export { default as getResourcePath } from './getResourcePath.js';
11 changes: 11 additions & 0 deletions for-vue2/src/packages/plugins/APPDevTool/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare global {
namespace NodeJS {
export interface ProcessEnv {
H_UNI_APPDEVTOOL_ENV: 'production' | 'development';

}
}

}

export { };
2 changes: 2 additions & 0 deletions for-vue2/src/packages/plugins/APPDevTool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface Argvs {
const argvs: Argvs = filterArgs(process.argv);

async function start() {
process.env.H_UNI_APPDEVTOOL_ENV = 'development';

if (argvs.dev) {
await androidServer(argvs);
await iosServer(argvs);
Expand Down
2 changes: 1 addition & 1 deletion for-vue2/src/packages/plugins/APPDevTool/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function log(message: unknown, type?: 'ios' | 'android') {
* @param message - 要记录的消息。
* @param where - 要记录的位置。
*/
export function err(message: unknown, e?: unknown, type?: 'ios' | 'android') {
export function err(message: unknown, e?: unknown, type?: 'ios' | 'android'): unknown {
const typeStr = type ? `[${type}]:` : '';
console.log(e);
let stack = '';
Expand Down

0 comments on commit 0fb40ae

Please sign in to comment.