微信云开发插件
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
export const build_dist = "build/wechatgame";
|
||||
export const cloud_func_dir = "cloud_functions";
|
||||
60
extensions/WeChat MiniGame Cloud Template/source/main.ts
Normal file
60
extensions/WeChat MiniGame Cloud Template/source/main.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
// @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() { }
|
||||
@@ -0,0 +1,62 @@
|
||||
import { readFileSync } from 'fs-extra';
|
||||
import { join } from 'path';
|
||||
import { createApp, App } from 'vue';
|
||||
const panelDataMap = new WeakMap<any, App>();
|
||||
/**
|
||||
* @zh 如果希望兼容 3.3 之前的版本可以使用下方的代码
|
||||
* @en You can add the code below if you want compatibility with versions prior to 3.3
|
||||
*/
|
||||
// Editor.Panel.define = Editor.Panel.define || function(options: any) { return options }
|
||||
module.exports = Editor.Panel.define({
|
||||
listeners: {
|
||||
show() { console.log('show'); },
|
||||
hide() { console.log('hide'); },
|
||||
},
|
||||
template: readFileSync(join(__dirname, '../../../static/template/default/index.html'), 'utf-8'),
|
||||
style: readFileSync(join(__dirname, '../../../static/style/default/index.css'), 'utf-8'),
|
||||
$: {
|
||||
app: '#app',
|
||||
text: '#text',
|
||||
},
|
||||
methods: {
|
||||
hello() {
|
||||
if (this.$.text) {
|
||||
this.$.text.innerHTML = 'hello';
|
||||
console.log('[cocos-panel-html.default]: hello');
|
||||
}
|
||||
},
|
||||
},
|
||||
ready() {
|
||||
if (this.$.text) {
|
||||
this.$.text.innerHTML = 'Hello Cocos.';
|
||||
}
|
||||
if (this.$.app) {
|
||||
const app = createApp({});
|
||||
app.config.compilerOptions.isCustomElement = (tag) => tag.startsWith('ui-');
|
||||
app.component('MyCounter', {
|
||||
template: readFileSync(join(__dirname, '../../../static/template/vue/counter.html'), 'utf-8'),
|
||||
data() {
|
||||
return {
|
||||
counter: 0,
|
||||
};
|
||||
}, methods: {
|
||||
addition() {
|
||||
this.counter += 1;
|
||||
},
|
||||
subtraction() {
|
||||
this.counter -= 1;
|
||||
},
|
||||
},
|
||||
});
|
||||
app.mount(this.$.app);
|
||||
panelDataMap.set(this, app);
|
||||
}
|
||||
},
|
||||
beforeClose() { },
|
||||
close() {
|
||||
const app = panelDataMap.get(this);
|
||||
if (app) {
|
||||
app.unmount();
|
||||
}
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user