61 lines
2.2 KiB
TypeScript
61 lines
2.2 KiB
TypeScript
// @ts-ignore
|
||
import packageJSON from '../package.json';
|
||
import path from "path";
|
||
import fse from "fs-extra";
|
||
import { build_dist, cloud_func_dir } from './const';
|
||
|
||
/**
|
||
* @en Registration method for the main process of Extension
|
||
* @zh 为扩展的主进程的注册方法
|
||
*/
|
||
export const methods: { [key: string]: (...any: any) => any } = {
|
||
/**
|
||
* @en A method that can be triggered by message
|
||
* @zh 通过 message 触发的方法
|
||
*/
|
||
// openPanel() {
|
||
// Editor.Panel.open(packageJSON.name);
|
||
// },
|
||
createTemplate(){
|
||
let cloudName = "cocos_cloud";
|
||
let cloudDir = path.join("build-templates/wechatgame", cloud_func_dir);
|
||
let cloudInputDir = path.join(__dirname, "../template/", cloudName);
|
||
let cloudOutputDir = path.join(Editor.Project.path, cloudDir, cloudName);
|
||
|
||
fse.ensureDirSync(cloudOutputDir);
|
||
fse.copy(cloudInputDir, cloudOutputDir);
|
||
|
||
let clientName = "wx_clound_client_api";
|
||
let clientDir = "assets/Scripts";
|
||
let clientInputDir = path.join(__dirname, "../template", clientName);
|
||
let clientOutputDir = path.join(Editor.Project.path, clientDir, clientName);
|
||
|
||
fse.ensureDirSync(clientOutputDir);
|
||
fse.copy(clientInputDir, clientOutputDir);
|
||
|
||
Editor.Dialog.info(`创建云函数模版成功!请查看\n云函数:${cloudDir}\n客户端API:${clientDir}/${clientName}`, { buttons :["确定"]})
|
||
},
|
||
|
||
activeCloud(){
|
||
let projectConfigPath = path.join(Editor.Project.path, build_dist, 'project.config.json');
|
||
let script = fse.readFileSync(projectConfigPath, 'utf8');
|
||
let projectConfigObj = JSON.parse(script);
|
||
projectConfigObj["cloudfunctionRoot"] = cloud_func_dir;
|
||
script = JSON.stringify(projectConfigObj, null, '\t');
|
||
fse.writeFileSync(projectConfigPath, script);
|
||
Editor.Dialog.info("配置云函数目录成功!", { buttons: ["确定"] });
|
||
}
|
||
};
|
||
|
||
/**
|
||
* @en Method Triggered on Extension Startup
|
||
* @zh 扩展启动时触发的方法
|
||
*/
|
||
export function load() { }
|
||
|
||
/**
|
||
* @en Method triggered when uninstalling the extension
|
||
* @zh 卸载扩展时触发的方法
|
||
*/
|
||
export function unload() { }
|