Project and resources

October 22, 2022

Project and resources

When our code becomes more and more complex, we may need to write multiple js files, and the files call each other; some js files may also need to read resource files such as pictures and music. A project is a folder used to organize multiple files. The project folder contains a project.json file that describes the configuration of the project. This configuration file allows you to package without refilling the packaging information every time.

Through the menu in the lower right corner of the file management interface of CloudControl Pro, select the project to create a new project. You can choose a different project template or a custom template when creating it, and just choose an empty project when you use it for the first time.

After creating a new project, a folder with the project name will be automatically created, under which you can see at least two files:

  • main.js: The main entry file of the project, which will be executed when the project is run
  • project.json: project configuration file, configuration project name, package name, packaging configuration, etc.

In the project, all the resource files and module files we use must be placed in the project folder and referenced with relative paths, so that they can be packaged into the apk and run correctly when packaging.

For example, we wrote a module file sum.js:

// sum.js
function sum(n) {
     let result = 0;
     for (let i = 0; i < n; i++) {
         result += i;
     }
     return result;
}

module.exports = sum;

Then in main.js, you need to use a relative path reference:

// main.js
let sum = require('./sum.js');
console.log(sum(100));

Similarly, resource files such as images also need to use relative path references. For example, our project folder has the following files:

main.js
sum.js
apple.png
project.json

When reading apple images, you need to use relative paths, such as let apple = $images.read('./apple.png').

Project management and packaging

Open the folder of the project, and you can see a compass icon on the upper toolbar:

Project Management

After clicking, the pop-up menu can edit the project, package the project, publish the project, etc. The packaging of the project is basically the same as the packaging in the previous section, and will not be elaborated here; publishing the project will upload the project to the store. After the review is passed, everyone can download the project.

Last update:
Contributors: Bruce