Skip to content
Prev Previous commit
Next Next commit
1
  • Loading branch information
Yueby committed Nov 13, 2024
commit 0df222991fe47d11cf0747ecb68e48a9e2652d67
16 changes: 8 additions & 8 deletions packages/playable-adapter-core/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { TPlayableConfig } from '@/typings'
import { TPlayableConfig } from '@/typings';

// game config
export const PLAYABLE_DEFAULT_CONFIG: TPlayableConfig = {
playable_orientation: 0,
playable_languages: ["ja", "zh", "ar", "es", "en", "ko", "pt", "ru", "vi"]
}
};

export const REPLACE_SYMBOL = '{{__adv_channels_adapter__}}'
export const ADAPTER_FETCH = 'adapterFetch'
export const REPLACE_SYMBOL = '{{__adv_channels_adapter__}}';
export const ADAPTER_FETCH = 'adapterFetch';
// every channel's adapter zip file size limit
export const MAX_ZIP_SIZE = 2 * 1024 * 1024
export const MAX_ZIP_SIZE = 2 * 1024 * 1024;

export const TO_STRING_EXTNAME = [
'.txt',
Expand All @@ -25,12 +25,12 @@ export const TO_STRING_EXTNAME = [
'.fnt',
'.js',
".zip"
]
];

export const TO_SKIP_EXTNAME = [
'.ico',
'.html',
'.css',
]
];

export const TRANSPARENT_GIF = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
export const TRANSPARENT_GIF = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
8 changes: 4 additions & 4 deletions packages/playable-adapter-core/src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ export const exec2xAdapter = async (options: TOptions, config?: { mode: TMode; }

const { orientation = 'auto' } = getAdapterRCJson() || {};
const { mode = 'parallel' } = config ?? { mode: 'parallel' };

console.info('[打包] 开始生成渠道包');
await gen2xChannelsPkg({
orientation,
resMapper,
compDiff
}, mode);
console.info('[打包] 渠道包生成完成');

unmountGlobalVars();
console.info('[构建] 构建完成');
};
Expand All @@ -67,14 +67,14 @@ export const exec3xAdapter = async (options: TOptions, config?: { mode: TMode; }

const { orientation = 'auto' } = getAdapterRCJson() || {};
const { mode = 'parallel' } = config ?? { mode: 'parallel' };

console.info('【生成渠道包】');
await gen3xChannelsPkg({
orientation,
resMapper,
compDiff
}, mode);
console.info('渠道包生成完成');

unmountGlobalVars();
};
12 changes: 6 additions & 6 deletions packages/playable-adapter-core/src/utils/file-system/project.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import path from "path"
import { getGlobalProjectBuildPath } from "@/global"
import path from "path";
import { getGlobalProjectBuildPath } from "@/global";

export const get2xSingleFilePath = () => {
return path.join(getGlobalProjectBuildPath(), '/single-file-2x.html')
}
return path.join(getGlobalProjectBuildPath(), '/single-file-2x.html');
};

export const get3xSingleFilePath = () => {
return path.join(getGlobalProjectBuildPath(), '/single-file-3x.html')
}
return path.join(getGlobalProjectBuildPath(), '/single-file-3x.html');
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const readAdapterRCFile = (): TAdapterRC | null => {
const adapterRCJsonPath = `${projectRootPath}${ADAPTER_RC_PATH}`;
if (existsSync(adapterRCJsonPath)) {
let config = <TAdapterRC>JSON.parse(readToPath(adapterRCJsonPath));

if (config.injectOptions) {
for (const channel in config.injectOptions) {
if (config.injectOptions.hasOwnProperty(channel)) {
Expand Down Expand Up @@ -68,7 +68,7 @@ export const getRCSkipBuild = (): boolean => {
return adapterRCJson.skipBuild ?? false;
};

export const getRCTinify = (): { tinify: boolean; tinifyApiKey: string } => {
export const getRCTinify = (): { tinify: boolean; tinifyApiKey: string; } => {
const adapterRCJson = getAdapterRCJson();
if (!adapterRCJson) {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { readFileSync } from 'fs'
import { readFileSync } from 'fs';

export const getRealPath = (pathStr: string) => {
let realPath = pathStr
let realPath = pathStr;
// 适配window路径
if (realPath.indexOf('\\') !== -1) {
realPath = realPath.replace(/\\/g, '/')
realPath = realPath.replace(/\\/g, '/');
}

return realPath
}
return realPath;
};

export const readToPath = (filepath: string, encoding?: BufferEncoding) => {
const fileBuffer = readFileSync(filepath)
return fileBuffer.toString(encoding)
}
const fileBuffer = readFileSync(filepath);
return fileBuffer.toString(encoding);
};
34 changes: 17 additions & 17 deletions packages/playable-ads-adapter/src/extensions/worker/2x.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
import { parentPort, workerData } from 'worker_threads'
import { exec2xAdapter } from 'playable-adapter-core'
import { parentPort, workerData } from 'worker_threads';
import { exec2xAdapter } from 'playable-adapter-core';

// 重写console的log和info方法,使其在主线程中打印
const overrideConsole = () => {
const { log, info } = console
const { log, info } = console;
console.log = (...args: any[]) => {
parentPort?.postMessage({
event: 'adapter:log',
msg: args.join(' ')
})
log(...args)
}
});
log(...args);
};
console.info = (...args: any[]) => {
parentPort?.postMessage({
event: 'adapter:log',
msg: args.join(' ')
})
info(...args)
}
}
});
info(...args);
};
};

const task = async () => {
try {
// 重写console的log和info方法,使其在主线程中打印
overrideConsole()
overrideConsole();

const { buildFolderPath, adapterBuildConfig } = workerData
const { buildFolderPath, adapterBuildConfig } = workerData;
await exec2xAdapter({
buildFolderPath,
adapterBuildConfig,
}, {
mode: 'serial'
})
});

parentPort?.postMessage({
finished: true,
msg: 'success',
event: 'adapter:finished'
})
});
} catch (error) {
parentPort?.postMessage({
finished: false,
msg: error,
event: 'adapter:finished'
})
});
}
}
task()
};
task();