Cross-platform application packaging method, system and equipment based on environment variables and medium

Through a cross-platform application packaging method based on environment variables, target configuration parameters are dynamically generated, which solves the problem of insufficient packaging and configuration management of multi-version applications in the existing technology, realizes efficient and flexible multi-version management and packaging, and improves development and maintenance efficiency.

CN120670018APending Publication Date: 2025-09-19SWIFTPASS TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510532524.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-25
Publication Date
2025-09-19

AI Technical Summary

Technical Problem

Existing cross-platform development frameworks are inadequate in handling the packaging and configuration management of multi-version applications, forcing developers to manually maintain multiple code bases. Existing tools do not support passing parameters during packaging, resulting in bloated application packages and increased storage and loading overhead.

Method used

Through a cross-platform application packaging method based on environment variables, target configuration parameters are dynamically generated, including parsing build instructions, loading page configuration files and platform-specific configuration templates, generating environment variables containing device compatibility parameters, optimizing parameter information using code optimization algorithms, and outputting the target platform application installation package.

Benefits of technology

It realizes the automated management of multi-version environments, supports customized configurations of different clients, avoids manual maintenance of multiple code bases, improves development and maintenance efficiency, and is particularly suitable for the packaging and construction of multi-version Hongmeng App.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120670018A_ABST
    Figure CN120670018A_ABST
Patent Text Reader

Abstract

The invention relates to a cross-platform application packaging method based on an environment variable, and the method comprises the steps: obtaining a construction instruction inputted by a user, analyzing the construction instruction, extracting a platform type parameter and a version identification parameter, and generating a basic environment variable comprising a compiling mode; loading a page configuration file of a corresponding version according to the version identification parameter, and generating a version environment variable comprising page configuration information; calling a platform exclusive configuration template based on the platform type parameter, and generating a platform environment variable containing an equipment compatibility parameter; generating a target configuration parameter based on the basic environment variable, the version environment variable and the platform environment variable; the target configuration parameter comprises parameter information required for generating / packaging an application; and outputting a target platform application installation package according to the target configuration parameter.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of software development technology, and in particular to a cross-platform application packaging method, system, device and medium based on environment variables. Background Art

[0002] Currently, cross-platform application development has become mainstream, allowing developers to adapt to multiple platforms, such as H5, mini-programs, and Hongmeng, with a single set of code. However, existing cross-platform development frameworks still have many shortcomings when it comes to handling the packaging and configuration management of multiple versions of applications. For example, existing tools such as Dcloud's Hbuilder tool, while capable of cross-platform packaging, do not support passing parameters during packaging. This limitation means that when there are multiple versions, developers need to manually change the parameters of each version one by one, which brings maintenance difficulties.

[0003] In the existing technology, patent number: 202110407100.6, different versions of file resources are packaged into the app to achieve version switching. Although this solution allows C-end users to switch between different versions in real time, it will lead to bloated application packages and increase storage and loading costs. Summary of the Invention

[0004] The present application provides a cross-platform application packaging method, system and storage medium based on environment variables to address the deficiencies in the existing technology and achieve efficient and flexible multi-version management and packaging.

[0005] In a first aspect, the present application provides a cross-platform application packaging method based on environment variables, the method comprising:

[0006] Obtaining the build instructions input by the user, parsing the build instructions to extract the platform type parameter and the version identification parameter, and generating basic environment variables including the compilation mode;

[0007] Load the page configuration file of the corresponding version according to the version identification parameter, and generate a version environment variable including page configuration information;

[0008] Invoking a platform-specific configuration template based on the platform type parameter to generate a platform environment variable containing device compatibility parameters;

[0009] Generate target configuration parameters based on the basic environment variables, the version environment variables, and the platform environment variables; the target configuration parameters include parameter information required for generating / packaging the application;

[0010] Output the target platform application installation package according to the target configuration parameters; wherein, the target platform application includes at least one of Hongmeng native application, WeChat applet, H5 web application, iOS application and Android application.

[0011] In some embodiments, the parsing of the build instructions to extract the platform type parameter and the version identification parameter, and generating basic environment variables including the compilation mode, includes:

[0012] Parsing the version identifier of the build instruction to extract the platform type parameter and the version identifier parameter;

[0013] Locating a preset metadata configuration node based on the platform type parameter and the version identification parameter; the metadata configuration node includes a development operation node and a production operation node;

[0014] Based on the metadata configuration node, call a pre-configured script file;

[0015] The basic environment variables are generated based on the called script file.

[0016] In some embodiments, the step of loading a page configuration file of a corresponding version according to the version identification parameter and generating a version environment variable including effective configuration information includes:

[0017] Matching pre-stored page configuration files based on version identification parameters;

[0018] Verify the legitimacy of the matching page configuration files by configuring validation rules;

[0019] The version environment variable is generated based on the verified page configuration file.

[0020] In some embodiments, calling a platform-specific configuration template based on the platform type parameter to generate a platform environment variable containing device compatibility parameters includes:

[0021] Loading a platform basic template file, and integrating the basic template file with the page configuration file;

[0022] The device information parameter is acquired according to the platform type parameter to generate the platform environment variable.

[0023] In some embodiments, generating target configuration parameters based on the basic environment variables, the version environment variables, and the platform environment variables includes:

[0024] Dynamically setting a dependency optimization strategy for a build tool according to the compilation mode in the basic environment variable;

[0025] Update the inclusion rules of the page configuration file based on the page configuration information in the version environment variable;

[0026] The device compatibility parameters in the platform environment variables and the inclusion rules are written into a running configuration file to obtain the target configuration parameters.

[0027] In some embodiments, outputting the target platform application installation package according to the target configuration parameters includes:

[0028] Perform dependency analysis based on the version environment variable including the effective configuration information, and optimize parameter information in the target configuration information using a code optimization algorithm;

[0029] Output the target platform application installation package according to the optimized target configuration parameters.

[0030] In some embodiments, optimizing the parameter information in the target configuration information by using a code optimization algorithm includes:

[0031] Calculate the retention score of the code module corresponding to each parameter information in the target configuration information using the following formula through the code optimization algorithm;

[0032]

[0033] Among them, W m The retention score of the mth parameter information in the calculated target configuration information, α is the weight coefficient used to control the influence of the effective configuration information on the retention score, w r To configure the priority weight of r to take effect, R m is the set of referenced effective configuration information, β is the weight coefficient used to control the influence of historical usage frequency on the retention score, f m The number of times the mth parameter information has been retained in the past preset number of constructions;

[0034] Determine whether the retention score is greater than a preset threshold; if not, delete the code module corresponding to the retention score.

[0035] In a second aspect, the present application provides a cross-platform application packaging system based on environment variables, the system comprising:

[0036] An environment configuration module is used to obtain the build instructions input by the user, parse the build instructions to extract the platform type parameters and version identification parameters, and generate basic environment variables including the compilation mode;

[0037] A version identification module is used to load a page configuration file of a corresponding version according to the version identification parameter and generate a version environment variable including page configuration information;

[0038] A platform adaptation module, configured to call a platform-specific configuration template based on the platform type parameters and generate platform environment variables containing device compatibility parameters;

[0039] A parameter generation module, configured to generate target configuration parameters based on the basic environment variables, the version environment variables, and the platform environment variables; the target configuration parameters include parameter information required for generating / packaging an application;

[0040] An output module is used to output a target platform application installation package according to the target configuration parameters; wherein the target platform application includes at least one of Hongmeng native applications, WeChat applets, H5 web applications, iOS applications and Android applications.

[0041] In a third aspect, an electronic device is provided, comprising a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other via the communication bus;

[0042] Memory for storing computer programs;

[0043] The processor is used to implement the steps of the cross-platform application packaging method based on environment variables described in any embodiment of the first aspect when executing the program stored in the memory.

[0044] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the cross-platform application packaging method based on environment variables as described in any embodiment of the first aspect are implemented.

[0045] Compared with the prior art, the above-mentioned technical solution provided by the embodiment of the present application has the following advantages: it innovatively constructs a dynamic environment variable switching mechanism, and achieves the following key technological breakthroughs on the basis of maintaining the advantages of cross-platform development: (1) Automated management of multi-version environments, realizing intelligent switching of development / testing / production environments through scripting tools, supporting customized configurations of different clients (such as brand logos, functional module combinations, etc.), and avoiding the repetitive work of manually maintaining multiple sets of code bases in traditional development; (2) Dynamic injection of compilation parameters, such as API addresses, version numbers, appids and other key parameters are abstracted as configurable variables, and cooperate with CI / CD systems to realize centralized management and automatic injection of independent configurations of each version; (3) Support for multi-version Hongmeng App packaging and construction, generating different versions of configuration files through scripts, and then packaging them through packaging tools, which can solve the problem that packaging tools do not support parameter passing during Hongmeng App packaging and construction.

[0046] The technical solution of the present invention enables the development team to significantly improve the efficiency of multi-version development and maintenance while maintaining the core advantages of the cross-platform framework. It is particularly suitable for complex scenarios where multiple customized product lines are maintained simultaneously based on a standardized product. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0048] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0049] Figure 1 A schematic diagram of a process flow of a cross-platform application packaging method based on environment variables provided in an embodiment of the present application;

[0050] Figure 2 A flow chart of a method for optimizing target configuration parameters provided in an embodiment of the present application;

[0051] Figure 3 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application;

[0052] Figure 4 Flowchart of the packaging system execution provided in the embodiment of the present application;

[0053] Figure 5 A schematic diagram illustrating an example of a command entered by a developer in a console according to an embodiment of the present application;

[0054] Figure 6 A schematic diagram of the core directory structure of the system provided in an embodiment of the present application;

[0055] Figure 7 Schematic diagram of key script commands and metadata of the package.json file provided in an embodiment of the present application;

[0056] Figure 8 A schematic diagram illustrating how the script file provided in the embodiment of the present application reads the metadata of the package.json file;

[0057] Figure 9 A schematic diagram of the contents of the vite.config.ts configuration file provided in an embodiment of the present application;

[0058] Figure 10A schematic diagram of the contents of the config.ts business file provided in an embodiment of the present application. DETAILED DESCRIPTION

[0059] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0060] Figure 1 A flow chart of a cross-platform application packaging method based on environment variables provided in an embodiment of the present application. In some embodiments, Figure 1 The process shown can be executed by an electronic device, and the process may include the following operations:

[0061] Step 101: Obtain a build instruction input by a user, parse the build instruction to extract a platform type parameter and a version identification parameter, and generate basic environment variables including a compilation mode.

[0062] User-entered build instructions refer to the commands or parameters entered by developers in the console, which instruct the build tool to start packaging or development operations. Build instructions include information such as platform type, version identifier, and environment settings.

[0063] The platform type parameter indicates the platform for which the application to be generated is built, such as Android, iOS, H5, WeChat applet, Hongmeng, etc.

[0064] The version identification parameter indicates the specific version number used by the built application, so that configuration files can be loaded and environment variables can be generated according to different versions.

[0065] In some embodiments, after a user enters a command in the console, the build tool parses the command content. It parses the platform type parameter (e.g., Android, iOS, etc.) and the version identifier parameter (e.g., 1.0.0) and stores them in corresponding variables. Based on the parsed information, it generates basic environment variables including the compilation mode (e.g., development mode or production mode).

[0066] In some embodiments, parsing the build instruction to extract a platform type parameter and a version identification parameter, and generating basic environment variables including a compilation mode may include the following operations.

[0067] S10, parsing the version identifier of the build instruction, and extracting the platform type parameter and the version identifier parameter.

[0068] The parsing method can be through a construction tool or other methods, for example, through a machine learning model. This embodiment does not limit the specific parsing method.

[0069] S11: Locate a preset metadata configuration node based on the platform type parameter and the version identification parameter.

[0070] A metadata configuration node is a file or data structure that stores configuration information for a specific platform and version. This includes information about the app's functional modules, page layout, dependencies, and more.

[0071] In some embodiments, the corresponding metadata configuration node can be searched based on the parameters obtained by parsing.

[0072] S12: Based on the metadata configuration node, call a pre-configured script file.

[0073] Script files are script programs used to perform specific tasks, such as setting environment variables, selecting compilation modes, and injecting packaging parameters.

[0074] In some embodiments, the node can be configured based on the loaded metadata to find a script file that matches the platform and version.

[0075] S13, generating the basic environment variables based on the called script file.

[0076] Basic environment variables are variables that contain basic configuration information related to the build, including compilation mode (such as development mode, production mode), platform type, version information, etc.

[0077] When the script file is executed, the required basic environment variables can be generated based on the platform and version configuration.

[0078] Step 102: Load the page configuration file of the corresponding version according to the version identification parameter, and generate a version environment variable including page configuration information.

[0079] Page configuration files are customized for different versions of an app and can include specific settings such as page layout, functional modules, and styles. For example, the configuration file for version 1.0.0 might include specific theme colors, functional modules, page layout, etc. Version 1.1.0 might adjust some UI design or features.

[0080] Version environment variables are generated based on different versions of configuration files and are used to configure version-related parameters such as page display and functional modules.

[0081] In some embodiments, the corresponding version of the configuration file (such as s.json) can be searched based on the parsed version identification parameter, the page configuration information in the configuration file can be loaded, and the corresponding version environment variable can be generated.

[0082] In some embodiments, the step of loading the page configuration file of the corresponding version according to the version identification parameter and generating the version environment variable including the effective configuration information may include the following operations.

[0083] S20, matching a pre-stored page configuration file according to the version identification parameter;

[0084] The page configuration file contains the configuration of page layout, function modules, styles, and other interface components related to a specific version. For example, bankA.pages.json may contain all the configurations related to the pages of Bank A's application, such as the page URL, page name, required function modules, etc.

[0085] In some embodiments, a pre-stored page configuration file may be searched based on the input version identification parameter.

[0086] S21, verify the legitimacy of the matching page configuration file by configuring verification rules;

[0087] Configuration validation rules are a set of rules used to check the legitimacy of page configuration files, including field validation, data type checking, and required field verification. By configuring validation rules, you can ensure that the content of the configuration file conforms to the expected format and standards.

[0088] In some embodiments, the loaded page configuration file may be read and verified according to predefined configuration validation rules, for example, checking whether the pageName field is a string, whether the isEnabled field is a Boolean value, and so on.

[0089] If the configuration file passes all verifications, the subsequent operations will continue; if the verification fails, an error will be reported and processing will stop.

[0090] S22, generating the version environment variable based on the verified page configuration file;

[0091] In some embodiments, required page and function information can be extracted based on a verified page configuration file. For example, bankA.pages.2.0.0.json contains enabled pages and function modules, and this information is converted into version environment variables.

[0092] Step 103: Calling a platform-specific configuration template based on the platform type parameter to generate a platform environment variable containing device compatibility parameters.

[0093] A platform-specific configuration template refers to a configuration template specific to each platform, which contains information such as platform-related device compatibility parameters and platform-agreed configuration items.

[0094] Device compatibility parameters refer to configuration items related to specific platform devices, such as the minimum supported operating system version, supported device models, device display resolution, etc.

[0095] In some embodiments, configuration items related to device compatibility can be obtained from a dedicated configuration template based on platform type parameters (such as Android, iOS, etc.); and platform environment variables containing device compatibility parameters can be generated.

[0096] In some embodiments, calling a platform-specific configuration template based on the platform type parameter to generate platform environment variables containing device compatibility parameters includes: loading a platform basic template file, fusing the basic template file with the page configuration file; and obtaining device information parameters according to the platform type parameter to generate the platform environment variables.

[0097] A platform-based template file is a file that contains platform-specific configurations. It defines the basic environment for a specific platform, such as the default screen resolution, layout, and framework settings. Different platforms (such as Android, iOS, and HarmonyOS) have different template files to ensure that applications can adapt to different platforms.

[0098] In some embodiments, a corresponding basic template file can be loaded according to the platform type parameter, and the loaded basic template file can be merged with the page configuration file. The specific operation can be to merge the platform-specific settings (such as default resolution) in the basic template with the page and function configuration in the page configuration file to generate a complete configuration file for subsequent use. It should be noted that in addition to the device resolution parameter, the device information parameter can also be other hardware parameters or software parameters such as the device's operating system.

[0099] Device resolution adaptation parameters refer to the resolution and display settings that need to be adjusted to ensure that the application displays correctly on different devices. Device resolution adaptation parameters include dynamic adjustments based on the device's screen size, resolution, and other characteristics.

[0100] In some embodiments, the resolution adaptation parameters of the device may be determined according to the platform type parameters (eg, Android), and the device resolution adaptation parameters may be added to the current environment variables to generate the final platform environment variables.

[0101] In this embodiment, the basic template file and the page configuration file are loaded and merged according to the platform type parameters, and the device resolution is adapted to generate environment variables containing platform-specific configurations. This method ensures that cross-platform applications can flexibly adapt to different devices and platforms, automatically manages the configurations of different platforms, reduces the complexity and error probability of manual configuration, and effectively improves the efficiency of cross-platform application development. It should be noted that

[0102] Step 104: Generate target configuration parameters based on the basic environment variables, the version environment variables, and the platform environment variables.

[0103] The target configuration parameters include parameter information required to generate / package an application.

[0104] The target configuration parameters are used to generate the final configuration of the target platform application installation package, including all necessary compilation, packaging, version, platform compatibility and other information.

[0105] In some embodiments, the basic environment variables, version environment variables and platform environment variables may be combined to generate target configuration parameters, or further processing may be performed on the basis of the basic environment variables, version environment variables and platform environment variables to generate target configuration parameters.

[0106] For example, you can generate target configuration parameters by the following operations.

[0107] S30: Dynamically set the dependency optimization strategy of the build tool according to the compilation mode in the basic environment variable.

[0108] Compilation modes refer to different configurations used during the application build process, such as production mode and packaging mode.

[0109] In some embodiments, the compilation mode information in the basic environment variables can be read, and the dependency optimization strategy of the build tool can be set according to the mode.

[0110] Dependency optimization strategies are methods used to optimize target configuration parameters.

[0111] S31, updating the inclusion rules of the page configuration file based on the page configuration information in the version environment variable;

[0112] Inclusion rules determine which pages and functional modules should be included in the final application package when building an application. Inclusion rules can be dynamically updated through page configuration in the version environment variable.

[0113] In some embodiments, a list of pages that need to be included can be obtained based on the page configuration information in the version environment variable, and the inclusion rules of the page configuration file can be updated to ensure that only the required pages are included in the final build, and other pages will be excluded. The updated inclusion rules will be written into the page configuration file as part of the build process.

[0114] S32, writing the device compatibility parameter in the platform environment variable and the inclusion rule into a running configuration file to obtain the target configuration parameter;

[0115] The runtime configuration file is used to store the final configuration information to ensure that the application can run properly on different platforms and versions. The runtime configuration file includes information such as platform environment, page configuration, and device compatibility.

[0116] In some embodiments, device compatibility parameters in the platform environment variables can be read and merged with the updated page inclusion rules. For example, the resolution settings and page inclusion rules in the platform environment are combined and the merged information is written into the running configuration file to form the target configuration parameters.

[0117] In this example, based on basic, version, and platform environment variables, the build tool's dependency optimization strategy is dynamically set, the page configuration file's inclusion rules are updated, and the target configuration parameters are ultimately generated. This process ensures flexible configuration switching in cross-platform application development and automated management based on platform, version, and device requirements, improving development efficiency and reducing the workload of manual configuration maintenance.

[0118] Step 105: Output the target platform application installation package according to the target configuration parameters.

[0119] Among them, the target platform application includes at least one of Hongmeng native application, WeChat applet, H5 web application, iOS application and Android application.

[0120] The target platform application installation package is the final application file generated by the packaging tool according to the target configuration parameters, and is used for installation and operation on the target platform.

[0121] In some embodiments, a packaging tool may be called to perform a packaging operation based on the generated target configuration parameters to output an application installation package for the target platform.

[0122] Figure 2 Schematic diagram of the process of optimizing target configuration parameters provided by the embodiment of the present application. In some embodiments, Figure 2 The operations shown can be performed by electronic devices, such as Figure 2 As shown, the process may include the following operations:

[0123] Step 201 : performing dependency analysis based on the version environment variable including the effective configuration information, and optimizing parameter information in the target configuration information by using a code optimization algorithm.

[0124] Dependency analysis involves identifying and analyzing the dependencies between modules or components of an application when building it. This ensures that all necessary dependencies are correctly referenced and eliminates unnecessary dependencies, optimizing application performance and reducing redundancy.

[0125] In some embodiments, the functional modules required for the current version can be obtained based on the configuration information in the version environment variables, the dependencies between the functional modules can be analyzed, and it can be determined which modules need to be built together and which can be excluded. Based on the results of the dependency analysis, the build plan can be adjusted to exclude unnecessary dependencies and optimize the build process.

[0126] Code optimization algorithms are technologies used to improve program performance, with the goal of increasing code execution efficiency, reducing resource consumption, and reducing redundant code.

[0127] The code optimization algorithm optimizes the parameters of each functional module in the target configuration information. This can reduce redundancy by merging dependencies and compressing the modules and parameters in the target configuration information to reduce the size of the final application package. The optimized configuration information will be used in subsequent packaging steps to ensure that the built application runs more efficiently on the target platform.

[0128] Step 202: Output the target platform application installation package according to the optimized target configuration parameters.

[0129] An application installation package is a compressed file used to install an application on a target platform, including all the application's code, resources, configuration files, and other content.

[0130] In some embodiments, a corresponding installation package can be generated based on the optimized target configuration parameters, and the correct build tools and format (such as generating an .apk file) can be selected according to the platform type. Finally, the application installation package of the target platform is output for distribution and installation by users or developers.

[0131] In some embodiments, optimizing the parameter information in the target configuration information by using a code optimization algorithm includes:

[0132] Calculate the retention score of the code module corresponding to each parameter information in the target configuration information using the following formula (1) through the code optimization algorithm;

[0133]

[0134] Among them, Wm The retention score of the mth parameter information in the calculated target configuration information, α is the weight coefficient used to control the influence of the effective configuration information on the retention score, w r To configure the priority weight of r to take effect, R m is the set of referenced effective configuration information, β is the weight coefficient used to control the influence of historical usage frequency on the retention score, f m The number of times the mth parameter information has been retained in the past preset number of constructions;

[0135] Determine whether the retention score is greater than a preset threshold; if not, delete the code module corresponding to the retention score.

[0136] The preset threshold can be set based on experience. When the retention score is not greater than the preset threshold, in addition to deleting the code module corresponding to the retention score, the code module can also be merged with code modules corresponding to other functional modules.

[0137] In this example, dependency analysis and code optimization algorithms are used to optimize target configuration parameters, ultimately generating an application installation package suitable for the target platform based on these optimized parameters. This approach ensures efficient cross-platform application development, avoids redundant code, optimizes application performance, and enables customized packaging for different versions and platforms.

[0138] The following is an exemplary complete embodiment provided in this application. It should be understood that the following embodiment is for illustrative purposes only and is not intended to limit the scope of the technical solutions provided by the above embodiments.

[0139] For B-side users, such as banks, the content required by each bank is determined during development, and dynamic switching to other bank versions on the page is not allowed. Therefore, the solution provided in this application does not target real-time user switching. Based on the different needs of each bank, only the required version files are packaged. This significantly reduces the code package size compared to existing real-time switching solutions.

[0140] Figure 4 Provides the main flow chart of the entire packaging system execution, Figure 4 The first "console command" can be referred to Figure 5 For example.

[0141] After the developer enters a command in the console, he can first call the corresponding script file in the / script directory according to whether to perform development operations (the command contains the keyword dev) or production packaging operations (the command contains the keyword build). At this time, the corresponding environment variable object ENV-1 (alias) will be generated for subsequent operations.

[0142] Then in the version identification step, for example, if it is Bank A, you can go to the / config / pages directory (see Figure 6 ) Get the configuration items for the pages and related functions required by Bank A. The corresponding file is bankA.pages.json. After completing this step, the variable object ENV-2 (a pseudonym) is obtained for subsequent operations.

[0143] Then in the platform identification stage, for example, if the platform is HarmonyOS App, you can go to the / config / harmony.config.ts file to obtain HarmonyOS's exclusive configuration items (see Figure 6 Different platforms may have different ways of obtaining some environment variables (such as device information), and this step is responsible for smoothing out the differences. After completing this step, the variable object ENV-3 (a pseudonym) is obtained for subsequent operations.

[0144] When generating the configuration file, ENV-1, ENV-2, and ENV-3 obtained in the above steps will be combined to generate the final configuration parameters required for development / packaging and updated to the entity file.

[0145] The final startup / packaging phase will read the generated entity files and complete the final process of the entire system: starting the project for development or packaging the final App product.

[0146] The following is a detailed description of each step in the above main process.

[0147] (1) Identify the environment and related parameter injection

[0148] In this example, Vite is used as the front-end building tool. The project root directory usually contains a package.json file (see Figure 6 ), which is the core file of the Node.js project configuration and is used to define project metadata, dependency management, and build scripts (such as development server startup and production environment build).

[0149] from Figure 7 You can see that the "scripts" object inside the file defines two script commands, dev and build, which correspond to starting the development server and building the production environment respectively.

[0150] When a developer enters the following in the console: Figure 5When executing the command shown, if the keyword "dev" is included, the script configured under "script" in the package file will be executed; if the keyword "build" is included, the script configured under "build" will be executed. This is achieved by the script execution rules and the Node.js module parsing mechanism (the rules are pre-configured).

[0151] dev is used to start the development server and execute the script / dev.js file; build is used to build the production environment and execute the script / build.js file, so that the environment can be identified.

[0152] The metadata that needs to be injected in this step can be defined inside the package.json file. For example, Figure 7 Developers can create env-meta on demand.

[0153] Figure 8 This is an example of how to read env-meta during script execution. For example, if the developer enters "npm run dev bankA-h5" in the console, the following steps will be executed:

[0154] 1. Use the dev keyword to determine the execution of the scripts / dev.js script file;

[0155] 2. Get the keyword “bankA-h5” through “process.argv[2]” in the dev.js script file;

[0156] 3. Then package['env-meta'][compile] in the script file is actually equivalent to package['env-meta']['bankA-h5'] after assignment, so the metadata at the specified location is obtained for use in subsequent steps.

[0157] After executing here, the metadata injection is completed and can be used in subsequent steps.

[0158] (2) Identify the version

[0159] In the previous step (1), the data env-meta['bankA-h5'] has been injected into the memory. The version can be obtained from the field "bankCode" in it, which is bankA.

[0160] (3) Segmentation process-identification platform

[0161] In the previous step (2), the data env-meta['bankA-h5'] has been injected into the memory. Through the field "platform" in it, we can get that the platform is h5.

[0162] (4) Segmentation process - generating configuration files

[0163] Step (4) will generate three key configuration files, namely:

[0164] 1. vite.config.ts in the root directory is the core file for subsequent Vite compilation and packaging;

[0165] 2. pages.json in the src directory contains the pages that need to be packaged under the current platform + version;

[0166] 3. config.ts in the config directory is a configuration file that is strongly related to the business, such as theme color, interface API address, App name, etc.

[0167] (5)vite.config.ts

[0168] You can pre-configure the configuration file starting with "vite." ( Figure 6 ), the version and platform have been determined through the previous steps (1)-(4). At this time, update the content of vite.config.ts through the command of the fs file operation module built into node.js to point to the corresponding configuration file.

[0169] The updated vite.config.ts file content may be as follows Figure 9 As shown, it is dynamically generated by script / dev.js or script / build.js.

[0170] (6)pages.json

[0171] pages.json is the project's page routing file (page configuration file), which controls which pages are needed and their access addresses. As we already know the version and platform from the previous steps, we can now read the corresponding file in the config / pages directory, such as bankA.pages.json, and then rewrite pages.json using the commands of the node.js built-in fs file operation module.

[0172] (7)config.ts

[0173] config.ts is a configuration file used by specific business needs in the project. The most common ones include the API request address required by the current version and business configuration switch parameters. As we already know the version and platform from the previous steps, we can read the business configuration file of the corresponding version in the config directory (for example, bankA.config.ts) and then rewrite config.ts using the commands of the built-in fs file operation module of node.js.

[0174] The updated vite.config.ts file content can be as follows Figure 10 As shown. Subsequent specific business can read this file.

[0175] Based on the same inventive concept, the present application also provides a cross-platform application packaging system based on environment variables, the system comprising:

[0176] An environment configuration module is used to obtain the build instructions input by the user, parse the build instructions to extract the platform type parameters and version identification parameters, and generate basic environment variables including the compilation mode;

[0177] A version identification module is used to load a page configuration file of a corresponding version according to the version identification parameter and generate a version environment variable including page configuration information;

[0178] A platform adaptation module, configured to call a platform-specific configuration template based on the platform type parameters and generate platform environment variables containing device compatibility parameters;

[0179] A parameter generation module, configured to generate target configuration parameters based on the basic environment variables, the version environment variables, and the platform environment variables; the target configuration parameters include parameter information required for generating / packaging an application;

[0180] An output module is used to output a target platform application installation package according to the target configuration parameters; wherein the target platform application includes at least one of Hongmeng native applications, WeChat applets, H5 web applications, iOS applications and Android applications.

[0181] like Figure 3 As shown, an embodiment of the present application provides an electronic device, including a processor 111, a communication interface 112, a memory 113 and a communication bus 114, wherein the processor 111, the communication interface 112, and the memory 113 communicate with each other through the communication bus 114.

[0182] Memory 113, for storing computer programs;

[0183] In one embodiment of the present application, the processor 111 is configured to execute a program stored in the memory 113 to implement the method for cross-platform application packaging based on environment variables provided by any of the aforementioned method embodiments, including:

[0184] Obtaining the build instructions input by the user, parsing the build instructions to extract the platform type parameter and the version identification parameter, and generating basic environment variables including the compilation mode;

[0185] Load the page configuration file of the corresponding version according to the version identification parameter, and generate a version environment variable including page configuration information;

[0186] Invoking a platform-specific configuration template based on the platform type parameter to generate a platform environment variable containing device compatibility parameters;

[0187] Generate target configuration parameters based on the basic environment variables, the version environment variables, and the platform environment variables; the target configuration parameters include parameter information required for generating / packaging the application;

[0188] Output the target platform application installation package according to the target configuration parameters; wherein, the target platform application includes at least one of Hongmeng native application, WeChat applet, H5 web application, iOS application and Android application.

[0189] An embodiment of the present application also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the cross-platform application packaging method based on environment variables as provided in any of the aforementioned method embodiments are implemented.

[0190] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.

[0191] The foregoing description is intended only to provide specific embodiments of the present invention, which will enable those skilled in the art to understand and implement the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention is not intended to be limited to the embodiments shown herein, but is intended to be accorded the widest scope consistent with the principles and novel features claimed herein.

Claims

1. A cross-platform application packaging method based on environment variables, characterized in that: The method comprises: Obtaining the build instructions input by the user, parsing the build instructions to extract the platform type parameter and the version identification parameter, and generating basic environment variables including the compilation mode; Load the page configuration file of the corresponding version according to the version identification parameter, and generate a version environment variable including page configuration information; Invoking a platform-specific configuration template based on the platform type parameter to generate a platform environment variable containing device compatibility parameters; Generate target configuration parameters based on the basic environment variables, the version environment variables, and the platform environment variables; the target configuration parameters include parameter information required for generating / packaging the application; Output the target platform application installation package according to the target configuration parameters; wherein, the target platform application includes at least one of Hongmeng native application, WeChat applet, H5 web application, iOS application and Android application.

2. The method according to claim 1, characterized in that The parsing of the build instructions extracts platform type parameters and version identification parameters, and generates basic environment variables including compilation mode, including: Parsing the version identifier of the build instruction to extract the platform type parameter and the version identifier parameter; Locating a preset metadata configuration node based on the platform type parameter and the version identification parameter; the metadata configuration node includes a development operation node and a production operation node; Based on the metadata configuration node, call a pre-configured script file; The basic environment variables are generated based on the called script file.

3. The method according to claim 1, characterized in that The step of loading a page configuration file of a corresponding version according to the version identification parameter and generating a version environment variable including effective configuration information includes: Matching pre-stored page configuration files based on version identification parameters; Verify the legitimacy of the matching page configuration files by configuring validation rules; The version environment variable is generated based on the verified page configuration file.

4. The method according to claim 1, wherein The calling of a platform-specific configuration template based on the platform type parameter to generate a platform environment variable containing device compatibility parameters includes: Loading a platform basic template file, and integrating the basic template file with the page configuration file; The device information parameter is acquired according to the platform type parameter to generate the platform environment variable.

5. The method according to claim 1, wherein The generating target configuration parameters based on the basic environment variables, the version environment variables, and the platform environment variables includes: Dynamically setting a dependency optimization strategy for a build tool according to the compilation mode in the basic environment variable; Update the inclusion rules of the page configuration file based on the page configuration information in the version environment variable; The device compatibility parameters in the platform environment variables and the inclusion rules are written into a running configuration file to obtain the target configuration parameters.

6. The method according to claim 1, characterized in that Outputting the target platform application installation package according to the target configuration parameters includes: Perform dependency analysis based on the version environment variable including the effective configuration information, and optimize parameter information in the target configuration information using a code optimization algorithm; Output the target platform application installation package according to the optimized target configuration parameters.

7. The method according to claim 6, characterized in that Optimizing the parameter information in the target configuration information by using a code optimization algorithm includes: Calculate the retention score of the code module corresponding to each parameter information in the target configuration information using the following formula through the code optimization algorithm; Among them, W m The retention score of the mth parameter information in the calculated target configuration information, α is the weight coefficient used to control the influence of the effective configuration information on the retention score, w r To configure the priority weight of r to take effect, R m is the set of referenced effective configuration information, β is the weight coefficient used to control the influence of historical usage frequency on the retention score, f m The number of times the mth parameter information has been retained in the past preset number of constructions; Determine whether the retention score is greater than a preset threshold; if not, delete the code module corresponding to the retention score.

8. A cross-platform application packaging system based on environment variables, characterized in that: The system comprises: An environment configuration module is used to obtain the build instructions input by the user, parse the build instructions to extract the platform type parameters and version identification parameters, and generate basic environment variables including the compilation mode; A version identification module is used to load a page configuration file of a corresponding version according to the version identification parameter and generate a version environment variable including page configuration information; A platform adaptation module, configured to call a platform-specific configuration template based on the platform type parameters and generate platform environment variables containing device compatibility parameters; A parameter generation module, configured to generate target configuration parameters based on the basic environment variables, the version environment variables, and the platform environment variables; the target configuration parameters include parameter information required for generating / packaging an application; An output module is used to output a target platform application installation package according to the target configuration parameters; wherein the target platform application includes at least one of Hongmeng native applications, WeChat applets, H5 web applications, iOS applications and Android applications.

9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; Memory for storing computer programs; The processor is configured to implement the steps of the cross-platform application packaging method based on environment variables described in any one of claims 1 to 7 when executing the program stored in the memory.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the cross-platform application packaging method based on environment variables are implemented.

Citation Information

Patent Citations

  • Version switching method and device

    CN113101670A