Project File Structure
- AppScope/app.json5: global configuration of the atomic service.
- AppScope/ext.json: third-party platform configuration file of the atomic service.
- entry: HarmonyOS project module, which is ultimately built into a HAP file of the atomic service.
- entry/src/main/resources/rawfile/: resources generated after the ASCF main package is built. Do not place other content in this directory.
- ascf/ascf_src: ASCF source code.
- ascf/ascf_build: subpackages and compilation files of the atomic service generated during the compilation process of the ASCF source code. Do not place other content in this directory.
- For details about other files, see the atomic service project information.
ASCF Code Structure
The ASCF code is stored in the ascf/ascf_src directory. In this directory, code files are organized into a two-layer structure: app and page.
|— app.json
|— app.js
|— app.css
|— components
| |— cart.json
| |— cart.hxml
| |— cart.js
| |— cart.css
|— pages
| |— user.json
| |— user.hxml
| |— user.js
| |— user.css
- The app layer contains the application configuration in three files, which must be in the project root directory.
File | Mandatory | Description |
app.js | Yes | Logic of the application. |
app.json | Yes | Global configuration of the application. |
app.css | No | Global styles of the application. |
- The page layer contains the page configuration in four types of files in the same directory.
File | Mandatory | Description |
.hxml | Yes | Page structure. |
.js | Yes | Page implementation logic. |
.json | Yes | Page configuration. |
.css | No | Page styles. |
- HXML is similar to an HTML file. You can create it with the components provided by ASCF, following rules similar to those of HTML files.
[h2]File Storage
The files of an atomic service are stored in the following partitions:
- Cache: used to store cache files. For example, files downloaded by using fetch() are stored in this partition. Files in this partition may be deleted by the system when storage space is inadequate.
- Files: used to store small permanent files. Files in this partition are managed by the application.
- Temp: used to store temporary files mapped from external systems. For security purposes, temporary files are read-only and can be obtained only by using specific APIs like media.pickVideo. Access to temporary files is temporary. Upon restart, the application must use specific APIs to regain access to the temporary files. Moreover, application resources are processed in a special read-only partition.
[h2]URI
URIs identify application resources and files, and can be used to access application resources and files by using components or APIs.
Resource Type | URI | Read-Only | Example | Description |
Application resource | /path | Yes | /Common/header.png | Path to the rawfile folder of the installation package. |
Cache | internal://cache/path/ | No | internal://cache/fetch-123456.png | Sandbox directory of the atomic service, which cannot be accessed by users. |
Files | internal://files/path | No | internal://files/image/demo.png | Sandbox directory of the atomic service, which cannot be accessed by users. |
Temp | internal://tmp/path | Yes | internal://tmp/xxxxx/demo.png (file name) | Dynamically generated by the system. |
You can use the regular expression [^\\s\"'|*?<>\\\\]+ to specify the characters allowed in a URI. A URI cannot contain double periods (..). URIs support directories, which are separated by slashes (/). An internal URI indicates a file of an application. When specifying an internal URI, you do not need to specify the application ID. The same internal URI points to different files for different applications.
[h2]Resource and File Access Rules
An application resource can be specified by an absolute path (starting with a slash (/), for example, /Common/a.png) or a relative path (not starting with a slash (/), for example, a.png or ./Common/a.png).
Application resource files are classified into code files and resource files. Code files are files that contain code, such as .js, .css, and .hxml files. Other files are resource files, which can be used as data, like image and video files.
- To import a code file into another one, use the relative path of the code file to be imported, for example, ./Common/component.hxml.
- To reference a resource file (for example, an image file or a video file) in a code file, generally you can use the relative path of the resource file, for example, ./abc.png.
- When importing a code file to another and referencing a resource file in the imported code file, you can use a relative path to reference the resource file if the code files are in the same directory. If the code files are not in the same directory, you must use an absolute path because the imported code file is copied to the target file during compilation, which changes the directory structure.