A node application for exporting playable ads
npm install playable-adapter-coreSupport exporting playable ads for the cocos plugin and node.js




- Support some popular platform
- Support exporting a single html for target platform
- Remove XMLHttpRequest from single html passing the platform test
- Add TinyPng to compress
| >= 2.4.6 | >= 3.8.x |
| -------- | -------- |
| ✅ | ✅ |
| | AppLovin | Facebook | Google | IronSource | Liftoff | Mintegral | Moloco | Pangle | Rubeex | Tiktok | Unity |
| ------------ | -------- | -------- | ------ | ---------- | ------- | --------- | ------ | ------ | ------ | ------ | ----- |
| >= 2.4.6 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| >= 3.8.x | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Using npm:
``bash`
$ npm install playable-adapter-core
Using yarn:
`bash`
$ yarn add playable-adapter-core
Using pnpm:
`bash`
$ pnpm install playable-adapter-core
`typescript
import { TPlatform, exec2xAdapter } from "playable-adapter-core";
const main = async () => {
const config = {
buildFolderPath: "/your/build/folder/path",
adapterRC: {
buildPlatform: "web-mobile",
exportChannels: "Facebook",
injectOptions: {
Facebook: {},
},
orientation: "auto",
enableSplash: true,
skipBuild: true,
tinify: true,
tinifyApiKey: "your tinify api key",
},
};
// required
const version = "2"; // '2' | '3'
version === "2" ? await exec2xAdapter(config) : await exec3xAdapter(config);
};
main();
`
`bash`
npm install safeify
`typescript
import { Api, useContext } from "@midwayjs/hooks";
import { Context } from "@midwayjs/koa";
import { TPlatform, exec2xAdapter, exec3xAdapter } from "playable-adapter-core";
import { Safeify } from "safeify";
export const uploadBuildPkg = Api(Upload(), async () => {
const ctx = useContext
// 调用接口
const files = useFiles();
const fields = useFields() as UploadFields;
const buildPkgKey = Object.keys(files).pop();
const buildPkg = <
{
data: string;
fieldName: string;
filename: string;
mimeType: string;
_ext: string;
}
>files[buildPkgKey].pop();
const buildChannels = JSON.parse(fields.channels ?? "[]") as TChannel[];
const tinify = JSON.parse(fields.tinify ?? "false") as boolean;
const tinifyApiKey = fields.tinifyApiKey ?? "";
const injectOptions = JSON.parse(fields.injectOptions ?? "{}") as {
[key in TChannel]: TChannelRC;
};
const webOrientation = fields.webOrientation ?? "auto";
const version = fields.version ?? "2";
const zipFilePath = buildPkg.data;
const zipExt = buildPkg._ext;
const filename = buildPkg.filename.replaceAll(buildPkg._ext, "") as TPlatform;
const unzipDir = join(
dirname(buildPkg.data),
basename(zipFilePath).replace(zipExt, "")
);
const config = {
buildFolderPath: unzipDir,
adapterBuildConfig: {
buildPlatform: filename,
exportChannels: buildChannels,
injectOptions,
orientation: webOrientation,
skipBuild: true,
tinify,
tinifyApiKey,
},
};
// 创建 safeify 实例
const safeVm = new Safeify({
timeout: 3000,
asyncTimeout: 120000,
unrestricted: true,
});
await safeVm.run(
version === '2'
? await exec2xAdapter(config)
: await exec3xAdapter(config)
,
{
version,
exec2xAdapter,
exec3xAdapter,
config,
}
);
return true;
});
`
support dynamic import from cocos source code, just like:
`typescript
// source code
window.advChannels = "{{__adv_channels_adapter__}}"; // 防止rollup打包进行tree-shaking省略掉该代码(dead code),占位符变量可挂载在全局
// 在Facebook渠道下代码会被替换为
window.advChannels = "Facebook";
`
export package from target platforms
`typescript`
const exportChannels: TChannel[] = ["Facebook", "Google"];
Replace Cocos Splash. (How to remove or change splash ?)
`typescript`
let config = {
enableSplash: false,
};
inject script in building html
`typescript
type TChannel =
| "AppLovin"
| "Facebook"
| "Google"
| "IronSource"
| "Liftoff"
| "Mintegral"
| "Moloco"
| "Pangle"
| "Rubeex"
| "Tiktok"
| "Unity";
const injectOptions: {
[key in TChannel]: {
head: string; // To append to the end of the