When building from the command line, the scene script of the editor extension called by using the build hook does not work

Hi Cocos Team。
I need help with the following.

I found a bug-like behavior in the behavior of an editor extension.
The editor extension that I created exposes the message acceptance and echoes the received value.

The operation check showed that 3 did not work.

  1. check if the editor extension works from CocosCreator’s Editor.
  2. Build from the build panel and call the editor extension in the hook of the build template.
  3. build from the command line and call the editor extension with the hook in the build template.

When I build from the build panel, the echo contents are displayed in the Console.
However, when building from the command line, the echo contents are not displayed on the terminal.

In the case of building from the command line, I was able to confirm that everything from the build template to the editor extension browser.js was working properly.
However, when calling scene.js from browser.js from browser.js does not work properly and is not echoed.

I think that building from the command line will start CocosCreator headless, so the script for scene will not work properly.

The following are the commands for building.

/Applications/CocosCreator/Creator/3.3.1/CocosCreator.app/Contents/MacOS/CocosCreator --project [project path] --build "configPath=[build-config.json];"

・Specify the path to the project in [project path].
・Specify the settings exported from the build panel in [build-config.json].


The following are the details of the editor extension used for testing and the build template.

The editor extension was created using the following procedure.
・Go to [Extension] > [Create Extension] and create a template for an editor extension that belongs to ‘project’.
・Add scene.js.
・Modify package.json to embed scene.js and set a public message.

The following is the configuration of the contributions section in package.json.

"contributions": {
    "menu": [
        {
            "path": "Test",
            "label": "Echo test",
            "message": "open"
        }
    ],
    "messages": {
        "open": {
            "methods": [
            "fromMenu"
            ]
        },
        "fromMessage": {
            "public": true,
            "description": "Echo test.",
            "doc": "",
            "methods": [
            "fromMessage"
            ]
        }
    },
    "scene": {
        "script": "./scene.js"
    }
}

The following is the contents of browser.js.

const packageJSON = require('./package.json');

exports.methods={
    async fromMenu() {
        const result = await Editor.Message.request('scene', 'execute-scene-script', {
            name: packageJSON.name,
            method: `echo`,
            args: [`fromMenu`,]
        });
        console.log(`******** Echo : ${result} ********`);
    },

    async fromMessage(value) {
        const result = await Editor.Message.request('scene', 'execute-scene-script', {
            name: packageJSON.name,
            method: `echo`,
            args: [value,]
        });
        return result;
    },
};

The following is the content of scene.js.

'use strict';

exports.methods = {

    async echo(arg) {
        const sleep = new Promise(resolve => {
            const timeoutID = setTimeout(() => {
                clearTimeout(timeoutID);
                resolve(arg);
            }, 1000);
        });

        const result =  await sleep;
        return result;
    },
};

Details of Operation

  1. browser.js receives a message and passes the value to scene.js.
  2. scene.js echoes the message and returns the value to browser.js.
  3. browser.js returns the value returned from scene.js as the return value of the message.

The builder plate was created by the following procedure.
・Add it by [Project] > [Generate Builder Extention].
・Rewrite onBeforeBuild in hooks.ts.

Rewrite onBeforeBuild in hooks.ts as follows.

export async function onBeforeBuild(options: ITaskOptions) {
    const result = await Editor.Message.request('simple-1638839972442', 'fromMessage', [`fromMessage`]);
    console.log(`******** Echo : ${result} ********`);
}

Finally, we need a Scene to build, so add an empty scene under assets.

I will ask engineering to have a look.

thanks you slackmoehrle.

I forgot to mention that the environment is as follows.
OS : MacOS 10.15.7
CocosCreator : 3.3.1

You need to register the data to the scene plugin in pacakge.json

.
NewProject_21.zip (634.7 KB)

Thanks koei.
I’ll DL the project right away and see how it works.

I checked my code, and scene.js was already written in the package.json I posted in the first place.

Hi koei.

I didn’t know that you could upload files from me.
I uploaded a validation project that I created here.
EchoProject.zip (105.0 KB)

The node_modules in cocos-build-template have been removed.
Please npm install it.

If you build this project from the command line and check the contents of Echo, you will see the following.

2021-12-27 11:32-log: ******** Echo : null ********

Using the scene script is called in the scene rendering process.
Command line builds do not start the scene rendering process.

Hi Koei.
Are there any plans to make scene scripts work with command line builds in the future?

For the time being, there are no plans related to this area.

Thank you Koei.
I hope to deal with this someday.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.