A method and related apparatus for generating mini-programs
Patent Information
- Application Number
- CN202011146753.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-23
- Publication Date
- 2026-09-01
- Estimated Expiration
- 2040-10-23
AI Technical Summary
目前在开发小程序时,是将单一小程序作为一个项目进行开发,方式单一
Smart Images

Figure CN112148389B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computers, and in particular to a method for generating a mini-program, a device for generating a mini-program, an electronic device, and a computer-readable storage medium. Background Technology
[0002] Mini-programs, as applications that can be used without downloading or installation, realize the dream of "applications at your fingertips." Users can open the application simply by scanning a QR code or searching. They also embody the "use and go" concept, eliminating concerns about insufficient memory on the user's device due to installing too many applications. Mini-programs make applications ubiquitous and readily available, yet require no installation or uninstallation. Currently, mini-program development treats a single mini-program as a project, resulting in a simplistic approach. Summary of the Invention
[0003] This application provides a method and related apparatus for generating mini-programs. It can merge multiple mini-programs into a single mini-program, increasing the diversity of mini-program generation methods and improving generation efficiency.
[0004] On one hand, embodiments of this application provide a method for generating a mini-program, the method comprising:
[0005] When the source code packages of at least two mini-programs are obtained, the source code packages of each of the at least two mini-programs are compiled respectively to obtain the target compiled code packages of each mini-program;
[0006] A main mini-program and a sub-mini-program are determined from the at least two mini-programs, wherein the sub-mini-program is a mini-program other than the main mini-program among the at least two mini-programs;
[0007] The target compiled code packages of each of the sub-mini-programs are merged with the target compiled code package of the main mini-program to obtain the merged code package;
[0008] The target mini-program is generated based on the merged code package.
[0009] On one hand, embodiments of this application provide a mini-program generation device, the device comprising:
[0010] The processing unit is configured to, when the source code packages of at least two mini-programs are obtained, compile the source code packages of each of the at least two mini-programs respectively to obtain the target compiled code packages of each mini-program;
[0011] A determining unit is configured to determine a main mini-program and a sub-mini-program from the at least two mini-programs, wherein the sub-mini-program is a mini-program other than the main mini-program among the at least two mini-programs;
[0012] The processing unit is also used to merge the target compiled code packages of each of the sub-mini-programs with the target compiled code package of the main mini-program to obtain a merged code package;
[0013] The generation unit is used to generate the target mini-program based on the merged code package.
[0014] In one possible example, regarding the step of compiling the source code packages of each of the at least two mini-programs to obtain the target compiled code packages of each mini-program, the processing unit is specifically configured to: compile the source code packages of each of the at least two mini-programs according to a first compilation method to obtain the first compiled code packages of each mini-program; process the first compiled code packages of each mini-program according to a preset processing method to obtain the second compiled code packages corresponding to each mini-program, and use the second compiled code packages corresponding to each mini-program as the target compiled code packages of each mini-program.
[0015] In one possible example, the initial compiled code package includes an initial code file directory, which includes at least one code file. Regarding the step of compiling the source code packages of each of the at least two miniprograms according to the first compilation method to obtain the first compiled code package of each miniprogram, the processing unit is specifically configured to: clear the initial code file directory in the initial compiled code package corresponding to each miniprogram; compile the source code packages of each of the at least two miniprograms to obtain the currently compiled code file directory corresponding to each miniprogram; and write the currently compiled code file directory into the correspondingly cleared initial compiled code package to obtain the first compiled code package of each miniprogram.
[0016] In one possible example, regarding the step of processing the first compiled code package of each mini-program according to a preset processing method to obtain the second compiled code package corresponding to each mini-program, the processing unit is specifically configured to: determine invalid code in the first compiled code package of each mini-program, and remove the invalid code from the first compiled code package of each mini-program respectively, to obtain the compiled code package of each mini-program after removing invalid code; compile the compiled code package of each mini-program after removing invalid code according to a second compilation method, to obtain the compiled code package of each mini-program compiled according to the second compilation method; and compress the compiled code package of each mini-program compiled according to the second method to obtain the second compiled code package corresponding to each mini-program.
[0017] In one possible example, before merging the target compiled code packages of each of the sub-mini-programs with the target compiled code package of the main mini-program, the processing unit is further configured to: determine the configuration files of the target file types included in the target compiled code packages of each sub-mini-program; determine whether the target compiled code package of the sub-mini-program to be processed is a code package of a preset type based on the file content of the configuration files of the target file types, wherein the sub-mini-program to be processed is any one of the at least two sub-mini-programs; if it is not a code package of a preset type, then perform the step of merging the target compiled code packages of each of the sub-mini-programs with the target compiled code package of the main mini-program.
[0018] In one possible example, the processing unit is further configured to: if it is a code package of a preset type, extract the entry file of the sub-mini-program to be processed from the target compiled code package of the sub-mini-program to be processed; inject the entry file of the sub-mini-program to be processed into the entry file included in the target compiled code package of the main mini-program, and perform the step of merging the target compiled code packages of each sub-mini-program with the target compiled code package of the main mini-program.
[0019] In one possible example, the target compiled code package includes a code file directory, which includes at least one code file; in the process of merging the target compiled code packages of each of the sub-mini-programs with the target compiled code package of the main mini-program, the processing unit is specifically used to: inject the code file directory included in the target compiled code package of the sub-mini-program to be processed into the code file directory included in the target compiled code package of the main mini-program.
[0020] In one possible example, after injecting the code file directory included in the target compiled code package of the sub-mini-program to be processed into the code file directory included in the target compiled code package of the main mini-program, the method further includes: adding the page path of the sub-mini-program to the global configuration file included in the target compiled code package of the main mini-program to obtain the merged code package.
[0021] On one hand, embodiments of this application provide an electronic device, including a processor, a memory, a communication interface, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the processor, and the programs include instructions for performing the steps in the method described above.
[0022] Accordingly, this application provides a chip that includes a processor and a data interface. The processor reads instructions stored in the memory through the data interface and executes the method as described in the above method example and any possible implementation of the method.
[0023] Accordingly, embodiments of this application provide a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program for electronic data interchange, wherein the computer program causes a computer to perform some or all of the steps described in the above method.
[0024] Accordingly, embodiments of this application also provide a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the described method.
[0025] In this embodiment, the source code packages of the main mini-program and the sub-mini-programs are compiled separately to obtain a target compiled code package. Then, the target compiled code packages of each sub-mini-program are merged with the target compiled code package of the main mini-program to obtain a merged code package; the target mini-program is then generated based on the merged code package. Even if the development frameworks of the source code of each mini-program are different, they can be compiled separately, and the compiled target compiled code packages can be merged. The target mini-program is then generated based on the merged code package. This allows multiple mini-programs to be merged into one, increasing the diversity of mini-program generation methods and improving mini-program generation efficiency. Attached Figure Description
[0026] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0027] Figure 1 This is a schematic diagram illustrating the generation process of a mini-program according to an embodiment of this application;
[0028] Figure 2A This is a flowchart illustrating a method for generating a mini-program provided in an embodiment of this application;
[0029] Figure 2B This is a schematic diagram of a target mini-program provided in an embodiment of this application;
[0030] Figure 3 This is a flowchart illustrating another method for generating a mini-program provided in an embodiment of this application;
[0031] Figure 4This is a flowchart illustrating another method for generating a mini-program provided in this application embodiment;
[0032] Figure 5 This is a schematic diagram of the functional units of a mini-program generation device provided in an embodiment of this application;
[0033] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0034] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0035] The terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or apparatuses.
[0036] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0037] Currently, when developing mini-programs, each mini-program is developed as a single project. Subsequent use and management also revolve around this single mini-program. Therefore, users need to switch between different mini-programs, and cannot browse multiple mini-programs simultaneously, leading to inconvenience in both usage and management.
[0038] To address the aforementioned issues, this application provides a method for generating mini-programs, applicable to electronic devices. A detailed description follows with reference to the accompanying drawings.
[0039] First, please refer to Figure 1 , Figure 1The process of generating the target mini-program is shown, which involves the main mini-program, sub-mini-programs, and the target mini-program.
[0040] The main mini-program, sub-mini-program, and target mini-program can be WeChat mini-programs or other application mini-programs, applied to electronic devices. There can be one or more main mini-programs and sub-mini-programs.
[0041] Both the main mini-program and the sub-mini-program contain source code. Compiling the source code of the main mini-program and the source code of the sub-mini-program separately yields the compiled code of the main mini-program and the compiled code of the sub-mini-program, respectively. Combining the compiled code of the main mini-program and the compiled code of the sub-mini-program into a single package yields the combined code. The target mini-program can then be generated from the combined code.
[0042] The aforementioned electronic devices may include, for example, distributed storage servers, traditional servers, large-scale storage systems, desktop computers, laptops, tablets, PDAs, smartphones, portable digital players, smartwatches, and smart bracelets. The aforementioned terminals include, but are not limited to, devices with communication functions, smartphones, tablets, laptops, desktop computers, portable digital players, smart bracelets, and smartwatches.
[0043] The technical solutions of this application embodiment can be based on Figure 1 The following is a schematic diagram or deformation diagram illustrating the generation process of the target mini-program, which is used for specific implementation.
[0044] See Figure 2A , Figure 2A This is a flowchart illustrating a method for generating a mini-program according to an embodiment of this application. The method can be executed by a mini-program generation device and may include, but is not limited to, the following steps:
[0045] 201. When the source code packages of at least two mini-programs are obtained, the source code packages of each of the at least two mini-programs are compiled respectively to obtain the target compiled code packages of each mini-program.
[0046] Specifically, since each of the at least two mini-programs mentioned above can be developed as an independent project, each mini-program has a corresponding source code package. A source code package is a file package containing source code (also called source program), which refers to a series of human-readable computer language instructions. In modern programming languages, source code can appear in the form of books or tapes, but the most common format is a text file, the typical format of which is used to compile computer programs.
[0047] Furthermore, the mini-program generation device compiles the source code packages of each of the at least two mini-programs mentioned above to obtain the target compiled code packages of each mini-program. The target compiled code package includes target compiled code, which translates human-readable text (source code) into binary instructions that can be executed by a computer.
[0048] In addition, the source code packages of each of the aforementioned at least two mini-programs include instruction options as shown in Table 1. The table contains the parameter name for each instruction option, the meaning of the parameter name, its default value, and whether it is required. "Required" means that if a parameter name has a corresponding default value, it is not required; otherwise, it is required. "Required" means that if no default value exists, the value corresponding to that parameter name must be uploaded again.
[0049]
[0050]
[0051] Table 1
[0052] 202. Determine a main mini-program and a sub-mini-program from the at least two mini-programs, wherein the sub-mini-program is a mini-program other than the main mini-program among the at least two mini-programs.
[0053] Specifically, determining the main mini-program and sub-mini-programs from at least two mini-programs can be done randomly or according to certain logic by the mini-program generation device; alternatively, it can be a main mini-program determination instruction received by the mini-program generation device, which instructs that any one or more mini-programs be selected as the main mini-program and sub-mini-programs from at least two mini-programs. The instruction can also specify which mini-program(s) will be the main mini-program, and the sub-mini-programs will be selected from the at least two mini-programs excluding the main mini-program.
[0054] 203. Merge the target compiled code packages of each sub-mini-program with the target compiled code package of the main mini-program to obtain the merged code package.
[0055] Specifically, the mini-program generation device compiles the source code packages of each of at least two mini-programs separately, obtaining the target compiled code packages of each mini-program. Then, it merges the compiled code packages of each sub-mini-program with the compiled code package of the main mini-program to obtain a merged code package. The merging process is performed according to a preset method, and the merged code package includes the target compiled code packages of both the main mini-program and the sub-mini-programs.
[0056] 204. Generate the target mini-program based on the merged code package.
[0057] Specifically, it can be understood that the merged code package contains the target compiled code packages of the main mini-program and the sub-mini-program. Therefore, the target mini-program generated based on the merged code package includes the pages and functions of the main mini-program as well as the pages and functions of the sub-mini-program.
[0058] For example, consider a mobile phone recharge mini-program as the main mini-program and an online service hall project mini-program as a sub-mini-program. The mobile phone recharge mini-program can be a native mini-program without any framework, or a mini-program developed based on frameworks such as wepy1 or wepy2, kbone, or taro. The online service hall project mini-program can be developed based on the kbone framework; a single source code can be used to build and generate code for both H5 web pages and the mini-program itself. Even if the two mini-programs use different development frameworks, the target compilation code packages corresponding to their source code can be merged to generate the target mini-program. The target mini-program's pages can be as follows: Figure 2B As shown, Figure 2B The left-hand page is the homepage of the mobile phone recharge mini-program. Figure 2B The right-hand page is the homepage of the online service hall. The target mini-program's pages can also be arranged sequentially, meaning the pages of the sub-mini-program before merging and the main mini-program after merging into the target mini-program are arranged in that order. It's not simply a matter of... Figure 2B The left and right sections are shown in the diagram. The generated target app supports running on multiple systems, such as personal terminals (PCs) or Apple laptops (MacBooks, Macs) for local access, and also supports BSD-based Mac operating systems and Linux-based Linux operating systems for continuous integration (CI).
[0059] As can be seen, the source code packages of the main mini-program and the sub-mini-programs are compiled separately to obtain the target compiled code package. Then, the target compiled code packages of each sub-mini-program are merged with the target compiled code package of the main mini-program to obtain a merged code package; the target mini-program is then generated based on the merged code package. Even if the development frameworks of the source code of each mini-program are different, they can be compiled separately, and the compiled target compiled code packages can be merged. The target mini-program is then generated based on the merged code package. This improves the functionality and management convenience of the generated target mini-program and avoids the waste of resources caused by redeveloping the mini-program.
[0060] With the above Figure 2A The embodiments shown are consistent; please refer to [link / reference]. Figure 3 , Figure 3 This is a flowchart illustrating another method for generating a mini-program provided in this application embodiment. This method is applied to a mini-program generation device and may include, but is not limited to, the following steps:
[0061] 301. When the source code packages of at least two mini-programs are obtained, the source code packages of each of the at least two mini-programs are compiled according to the first compilation method to obtain the first compiled code package of each mini-program.
[0062] Specifically, when the mini-program generation device obtains the source code packages of at least two mini-programs, it can compile the source code packages of each of the at least two mini-programs according to the first compilation method to obtain the first compiled code package of each mini-program. This can be understood as the first compiled code package being obtained after the initial compilation, that is, after compilation according to the first compilation method.
[0063] Optionally, the initial compiled code package includes an initial code file directory, which includes at least one code file; the step of compiling the source code packages of each of the at least two mini-programs according to the first compilation method to obtain the first compiled code package of each mini-program includes: clearing the initial code file directory in the initial compiled code package corresponding to each mini-program; compiling the source code packages of each of the at least two mini-programs to obtain the currently compiled code file directory corresponding to each mini-program; and writing the currently compiled code file directory into the correspondingly cleared initial compiled code package to obtain the first compiled code package of each mini-program.
[0064] Specifically, the compiled code package obtained from the mini-program's source code includes a code file directory, whether it's the initial compiled code package or the target compiled code package. The initial compiled code package includes the initial code file directory, while the target compiled code package includes the currently compiled code file directory. The code file directory includes at least one code file, such as a JSON configuration file with the .json extension; a WXML template file with the .wxml extension, which can be considered a concise HTML page, differing only slightly in its file extension and some tags; a WXSS stylesheet file with the .wxss extension; or a JS script file with the .js extension, etc.
[0065] When the mini-program generation device compiles the source code packages of each of the at least two mini-programs according to the first compilation method, it can clear the initial code file directory in the initial compiled code package corresponding to each mini-program. The initial code file directory can be understood as the directory of code files contained in the compiled code package obtained after the previous compilation based on the source code package. Clearing it prevents the previously compiled code file directory (i.e., the initial code file directory) from interfering with the currently compiled code file directory. Then, the source code packages of each of the at least two mini-programs are compiled again to obtain the currently compiled code directory corresponding to each mini-program. The currently compiled code file directory is then written into the correspondingly cleared initial compiled code package to obtain the first compiled code package of each mini-program.
[0066] As can be seen, when the mini-program generation device compiles the source code packages of each of the at least two mini-programs according to the first compilation method, it first clears the initial code file directory in the initial compiled code package corresponding to each mini-program; then it compiles the source code packages of each of the at least two mini-programs respectively, obtaining the currently compiled code file directory corresponding to each mini-program; and then it writes the currently compiled code file directory into the correspondingly cleared initial compiled code package to obtain the first compiled code package of each mini-program. This effectively avoids interference from the initially existing code file directory on the currently compiled code file directory, improves the accuracy of the currently compiled code file directory, and further ensures the cleanliness of the first compiled code package.
[0067] Optionally, clearing the initial code file directory in the initial compiled code package corresponding to each mini-program includes: detecting the version of the initial compiled code package of the main mini-program; if the version of the initial compiled code package of the main mini-program is lower than a preset version, then clearing the initial compiled code package of the main mini-program and the initial compiled code package of the sub-mini-program respectively. The preset version is a version that can run on various versions of the application. The version of the initial compiled code package of the main mini-program is lower than the preset version, that is, the initial compiled code package of the main mini-program does not meet the requirements for running on various versions of the application, so it needs to be cleared.
[0068] 302. Process the first compiled code package of each mini-program according to the preset processing method to obtain the second compiled code package corresponding to each mini-program, and use the second compiled code package corresponding to each mini-program as the target compiled code package of each mini-program.
[0069] Specifically, the mini-program generation device compiles the source code packages of each of the at least two mini-programs according to the first compilation method, obtaining the first compiled code packages of each mini-program. Then, it processes these first compiled code packages according to a preset processing method to obtain the second compiled code packages corresponding to each mini-program, and uses these second compiled code packages as the target compiled code packages for each mini-program. The preset processing method may include removing invalid code from the first compiled code packages, Babel compilation, and UglifyJS code compression. The second compiled code packages are more streamlined than the first compiled code packages and can support more versions of applications running on them.
[0070] 303. Determine a main mini-program and a sub-mini-program from the at least two mini-programs, wherein the sub-mini-program is a mini-program other than the main mini-program among the at least two mini-programs;
[0071] 304. Merge the target compiled code packages of each of the sub-mini-programs with the target compiled code package of the main mini-program to obtain a merged code package;
[0072] 305. Generate the target mini-program based on the merged code package.
[0073] Steps 303-305 are the same as steps 202-204 above, and will not be repeated here.
[0074] As can be seen, the source code packages of each of the at least two mini-programs are compiled separately according to the first compilation method to obtain the first compiled code package of each mini-program. Then, the first compiled code packages of each mini-program are processed according to a preset processing method to obtain the second compiled code package corresponding to each mini-program, and the second compiled code package corresponding to each mini-program is used as the target compiled code package of each mini-program. Next, the target compiled code packages of each sub-mini-program are merged with the target compiled code package of the main mini-program to obtain a merged code package; the target mini-program is generated based on the merged code package. Even if the development frameworks of the source code of each mini-program are different, they can be compiled separately, and then the compiled target compiled code packages are merged. Finally, the target mini-program is generated based on the merged code package. This improves the functionality and management convenience of the generated target mini-program and avoids the waste of resources caused by redeveloping mini-programs.
[0075] In one possible example, processing the first compiled code package of each mini-program according to a preset processing method to obtain the second compiled code package corresponding to each mini-program includes: determining invalid code in the first compiled code package of each mini-program, and removing the invalid code from the first compiled code package of each mini-program to obtain the compiled code package of each mini-program after removing invalid code; compiling the compiled code package of each mini-program after removing invalid code according to a second compilation method to obtain the compiled code package of each mini-program compiled according to the second compilation method; and compressing the compiled code package of each mini-program compiled according to the second method to obtain the second compiled code package corresponding to each mini-program.
[0076] Specifically, the first compiled code package of each mini-program is processed according to a preset processing method to obtain a second compiled code package corresponding to each mini-program. This includes: identifying invalid code in the first compiled code package of each mini-program and removing the invalid code from the first compiled code package of each mini-program to obtain a compiled code package of each mini-program after removing invalid code. The compiled code package of each mini-program after removing invalid code is compiled according to a second compilation method to obtain a compiled code package of each mini-program compiled according to the second compilation method. The second compilation method can be Babel compilation. Babel compilation can convert the compiled code package after removing invalid code into a language that can be recognized by various versions of browsers or APP versions, that is, it can run in different versions of browsers or different versions of applications (APP).
[0077] Furthermore, the mini-program generation device compresses the compiled code packages of each mini-program after the second compilation method, obtaining a second compiled code package corresponding to each mini-program. The compression process can be performed using the Uglifyjs code compression tool to compress the compiled code packages of each mini-program after the second compilation method, resulting in a more concise second compiled code package.
[0078] As can be seen, when processing the first compiled code package of each mini-program according to the preset processing method, invalid code in the first compiled code package can be cleared first, and then compiled according to the second compilation method. Further compression processing can also be performed. This makes the second compiled code package corresponding to each mini-program more concise than the first compiled code package. Furthermore, the second compiled code package can be used with more versions at runtime, improving its applicability.
[0079] In one possible example, before merging the target compiled code packages of each of the sub-mini-programs with the target compiled code package of the main mini-program, the method further includes: determining the configuration files of the target file types included in the target compiled code packages of each sub-mini-program; determining, based on the file content of the configuration files of the target file types, whether the target compiled code package of the sub-mini-program to be processed is a code package of a preset type, wherein the sub-mini-program to be processed is any one of the at least two sub-mini-programs; if it is not a code package of a preset type, then performing the step of merging the target compiled code packages of each of the sub-mini-programs with the target compiled code package of the main mini-program.
[0080] Specifically, before merging the target compiled code packages of each sub-mini-program with the target compiled code package of the main mini-program, the mini-program generation device can first determine the configuration files of the target file types included in the target compiled code packages of each sub-mini-program. The configuration files of the target file types are the configuration files corresponding to the development framework. It can be understood that different development frameworks correspond to different configuration files of the target file types, resulting in different compiled code packages. Therefore, the device can determine whether the target compiled code package of the sub-mini-program to be processed is a preset type of code package based on the file content of the target file type configuration file. A preset type of code package is a code package corresponding to a specific development framework, such as the wepy1 framework or the wepy2 framework. Sub-mini-programs based on a specific development framework will put common code in the app.js file of the target compiled code package, so it is necessary to extract the entry file of the sub-mini-program to be processed from its target compiled code package. The entry file can be understood as the app.js file. Then, the entry file of the sub-mini-program to be processed is injected into the entry file included in the target compiled code package of the main mini-program to avoid timing errors during code execution. Among them, the sub-mini-program to be processed is any one of at least two sub-mini-programs.
[0081] Furthermore, if the target compiled code package of the sub-mini-program to be processed is not a predefined type of code package, it means that the sub-mini-program to be processed is not developed based on a specific development framework. That is, the common code of the target compiled code package of the sub-mini-program to be processed is exposed and not stored in the app.js file. Therefore, it is not necessary to separately extract the entry file (app.js file) of the sub-mini-program to be processed and inject it into the entry file included in the target compiled code package of the main mini-program. Instead, the step of merging the target compiled code packages of each sub-mini-program with the target compiled code package of the main mini-program is directly executed.
[0082] As can be seen, before merging the target compiled code packages of each sub-mini-program with the target compiled code package of the main mini-program, the mini-program generation device first determines whether the target compiled code package of each sub-mini-program to be processed is a code package of a preset type based on the contents of the configuration file of the target file type. If the code package is not of the preset type, the step of merging the target compiled code packages of each sub-mini-program with the target compiled code package of the main mini-program is executed. By making the pre-determination, timing errors in the runtime of the merged code package are avoided when the target compiled code package is of the preset type.
[0083] In one possible example, the method further includes: if it is a code package of a preset type, extracting the entry file of the sub-mini-program to be processed from the target compiled code package of the sub-mini-program to be processed; injecting the entry file of the sub-mini-program to be processed into the entry file included in the target compiled code package of the main mini-program, and performing the step of merging the target compiled code packages of each sub-mini-program with the target compiled code package of the main mini-program.
[0084] Specifically, the mini-program generation device determines whether the target compiled code package of the sub-mini-program to be processed is a preset type code package based on the file content of the configuration file of the target file type. A preset type code package is a code package based on a specific development framework, such as the wepy1 or wepy2 framework. Sub-mini-programs based on a specific development framework will put their common code in the app.js file of the target compiled code package. If it is a preset type code package, that is, when it is determined that the sub-mini-program to be processed is based on a specific development framework, the entry file of the sub-mini-program to be processed needs to be extracted from its target compiled code package. The entry file can be understood as the app.js file. This entry file is then injected into the entry file included in the target compiled code package of the main mini-program to avoid timing errors during code execution. Then, the step of merging the target compiled code packages of each sub-mini-program with the target compiled code package of the main mini-program is performed. Here, the sub-mini-program to be processed can be any one of at least two sub-mini-programs.
[0085] As can be seen, the mini-program generation device determines, based on the file content of the configuration file of the target file type, that the target compiled code package of the sub-mini-program to be processed is a code package of a preset type. Then, it extracts the entry file of the sub-mini-program to be processed from the target compiled code package of the sub-mini-program; injects the entry file of the sub-mini-program to be processed into the entry file included in the target compiled code package of the main mini-program; and executes the step of merging the target compiled code packages of each sub-mini-program with the target compiled code package of the main mini-program. This effectively reduces timing errors during the runtime of the merged code package.
[0086] In one possible example, the target compiled code package includes a code file directory, which contains at least one code file; the process of merging the target compiled code packages of each of the sub-mini-programs with the target compiled code package of the main mini-program includes: injecting the code file directory included in the target compiled code package of the sub-mini-program to be processed into the code file directory included in the target compiled code package of the main mini-program.
[0087] Specifically, the target compiled code package includes a code file directory, which contains at least one code file. The code file directory included in the target compiled code package of the sub-mini-program to be processed can be the code file directory corresponding to the page of the sub-mini-program to be processed. Injecting the code file directory into the code file directory included in the target compiled code package of the main mini-program can be done by creating a new folder under the code file directory corresponding to the homepage of the main mini-program, and then injecting the code file directory of the sub-mini-program to be processed into this new folder. This adds the original first-level directory code files of the main mini-program to the sub-mini-program's code file directory.
[0088] As can be seen, when the mini-program generation device merges the target compiled code packages of each sub-mini-program with the target compiled code package of the main mini-program, it injects the code file directories included in the target compiled code package of the sub-mini-program into the code file directories included in the target compiled code package of the main mini-program. This effectively merges the pages of the sub-mini-programs into the pages of the main mini-program, so that the generated target mini-program contains both the pages of the sub-mini-programs and the pages of the main mini-program, thus improving the functionality of the target mini-program.
[0089] In one possible example, after injecting the code file directory included in the target compiled code package of the sub-mini-program to be processed into the code file directory included in the target compiled code package of the main mini-program, the method further includes: adding the page path of the sub-mini-program to the global configuration file included in the target compiled code package of the main mini-program to obtain the merged code package.
[0090] Specifically, after the mini-program generation device injects the code file directory included in the target compiled code package of the sub-mini-program into the code file directory included in the target compiled code package of the main mini-program, it can also merge the target compiled code packages of each sub-mini-program with the target compiled code package of the main mini-program. This can further include adding the page path of the sub-mini-program to the global configuration file included in the target compiled code package of the main mini-program to obtain the merged code package. The global configuration file included in the target compiled code package of the main mini-program can be an app.json configuration file. It serves as the global configuration of the main mini-program, including settings such as the list of configured page paths, global default window appearance, network timeout, bottom tab bar, and mini-program interface permission settings.
[0091] Therefore, injecting the code file directory included in the target compiled code package of the sub-mini-program into the code file directory included in the target compiled code package of the main mini-program can be understood as injecting the page code files corresponding to the sub-mini-program into the folder corresponding to the page code files of the main mini-program. To ensure that the generated target mini-program can correctly open the pages that originally belonged to the sub-mini-program, the page paths of the sub-mini-program need to be added to the global configuration file included in the target compiled code package of the main mini-program, forming a new list of page paths. The page path list specifies which pages make up the target mini-program, with each item corresponding to the path of a page. The first item in the page path list represents the homepage of the target mini-program, which is the homepage of the original main mini-program.
[0092] As can be seen, after the mini-program generation device injects the code file directory included in the target compiled code package of the sub-mini-program into the code file directory included in the target compiled code package of the main mini-program, it adds the page path of the sub-mini-program to the global configuration file included in the target compiled code package of the main mini-program, thus obtaining the merged code package. This allows the target mini-program generated from the merged code package to display all pages normally.
[0093] Please refer to the embodiments of this application below, which are consistent with the above. Figure 2A , Figure 3 The embodiments shown are consistent; please refer to [link / reference]. Figure 4 , Figure 4 This is a flowchart illustrating another method for generating a mini-program provided in this application embodiment. This method is applied to a mini-program generation device and may include, but is not limited to, the following steps:
[0094] 401. Continuous integration deployment is complete; execute relevant commands via command line. Continuous integration deployment includes: Since the client provided by the mini-program generation device is a command-line tool based on Node.js (JavaScript runtime environment), the user needs to install the client after installing the Node.js environment on the initiating party. Then, the installed client tool can be run by executing the corresponding commands through the bash (command processor) plugin of the continuous integration platform. Afterwards, the mini-program generation device begins to run relevant commands based on the source code of the main mini-program and sub-mini-programs to build the target compiled code packages for each mini-program.
[0095] 402. Constructing the target compiled code package for each mini-program includes clearing the initial compiled code package of the main mini-program and the initial compiled code package of the sub-mini-program.
[0096] 403. Executing the build command also includes generating the target compiled code package for the main mini-program and the target compiled code package for the sub-mini-program.
[0097] 404. Remove invalid code from the target compiled code package of the main mini-program and the target compiled code package of the sub-mini-program respectively.
[0098] 405. The target compilation method generates the target compiled code packages for the main mini-program and the sub-mini-program after removing invalid code. The target compilation method can utilize Babel (a compilation tool) to compile the JS code.
[0099] 406. After compressing the target compiled code packages of the main app and sub-apps, remove invalid artifact code from the current directory. Compression can be performed using Uglifyjs (a code compression tool).
[0100] 407. Extract the page code directory from the target compiled code package of the sub-mini-program and the homepage code from the target compiled code package of the main mini-program.
[0101] 408. Determine whether the sub-mini-program uses a specific development framework based on its target compiled code package. If not, extract the sub-mini-program's entry file from its target compiled code package and inject it into the main mini-program's target compiled code package's entry file. The specific development framework can be wepy1 or wepy2. Because wepy1 or wepy2 frameworks place the sub-mini-program's common code in its entry file (app.js), it needs to be injected into the main mini-program's entry page; otherwise, a timing error will occur when the combined code is executed.
[0102] 409. If so, inject the page code directory of the sub-mini-program into the page code directory of the main mini-program and copy the current build artifact directory to the target directory.
[0103] 410. Add the page path of the sub-mini-program to the global configuration file included in the target compilation code package of the main mini-program to obtain the merged code package.
[0104] Optionally, it may also include 411, which generates the target mini-program based on the merged code package.
[0105] Please see again Figure 5 This is a functional unit diagram of a mini-program generation device 500 according to an embodiment of the present invention. The mini-program generation device 500 in this application embodiment can be a built-in device of an electronic device or an external device of an electronic device.
[0106] In one implementation of the device according to an embodiment of the present invention, the mini-program generation device includes:
[0107] The processing unit 510 is configured to, when the source code packages of at least two mini-programs are obtained, compile the source code packages of each of the at least two mini-programs respectively to obtain the target compiled code packages of each mini-program;
[0108] The determining unit 520 is used to determine a main mini-program and a sub-mini-program from the at least two mini-programs, wherein the sub-mini-program is a mini-program other than the main mini-program among the at least two mini-programs;
[0109] The processing unit 510 is further configured to merge the target compiled code packages of each of the sub-mini-programs with the target compiled code package of the main mini-program to obtain a merged code package;
[0110] The generation unit 530 is used to generate a target mini-program based on the merged code package.
[0111] In one possible example, regarding the step of compiling the source code packages of each of the at least two mini-programs to obtain the target compiled code packages of each mini-program, the processing unit 510 is specifically configured to: compile the source code packages of each of the at least two mini-programs according to a first compilation method to obtain the first compiled code packages of each mini-program; process the first compiled code packages of each mini-program according to a preset processing method to obtain the second compiled code packages corresponding to each mini-program, and use the second compiled code packages corresponding to each mini-program as the target compiled code packages of each mini-program.
[0112] In one possible example, the initial compiled code package includes an initial code file directory, which includes at least one code file. Regarding the step of compiling the source code packages of each of the at least two miniprograms according to the first compilation method to obtain the first compiled code package of each miniprogram, the processing unit 510 is specifically configured to: clear the initial code file directory in the initial compiled code package corresponding to each miniprogram; compile the source code packages of each of the at least two miniprograms to obtain the currently compiled code file directory corresponding to each miniprogram; and write the currently compiled code file directory into the correspondingly cleared initial compiled code package to obtain the first compiled code package of each miniprogram.
[0113] In one possible example, regarding the process of processing the first compiled code package of each mini-program according to a preset processing method to obtain the second compiled code package corresponding to each mini-program, the processing unit 510 is specifically configured to: determine invalid code in the first compiled code package of each mini-program, and remove the invalid code in the first compiled code package of each mini-program respectively, to obtain the compiled code package of each mini-program after removing invalid code; compress the compiled code package of each mini-program after removing invalid code according to a second compilation method, to obtain the compiled code package of each mini-program after being compiled according to the second compilation method; and compress the compiled code package of each mini-program after being compiled according to the second method to obtain the second compiled code package corresponding to each mini-program.
[0114] In one possible example, before merging the target compiled code packages of each of the sub-mini-programs with the target compiled code package of the main mini-program, the processing unit 510 is further configured to: determine the configuration files of the target file types included in the target compiled code packages of each sub-mini-program; determine whether the target compiled code package of the sub-mini-program to be processed is a code package of a preset type according to the file content of the configuration file of the target file type, wherein the sub-mini-program to be processed is any one of the at least two sub-mini-programs; if it is not a code package of a preset type, then perform the step of merging the target compiled code packages of each of the sub-mini-programs with the target compiled code package of the main mini-program.
[0115] In one possible example, the processing unit 510 is further configured to: if it is a code package of a preset type, extract the entry file of the sub-mini-program to be processed from the target compiled code package of the sub-mini-program to be processed; inject the entry file of the sub-mini-program to be processed into the entry file included in the target compiled code package of the main mini-program, and perform the step of merging the target compiled code packages of each sub-mini-program with the target compiled code package of the main mini-program.
[0116] In one possible example, the target compiled code package includes a code file directory, which includes at least one code file; in the process of merging the target compiled code packages of each of the sub-mini-programs with the target compiled code package of the main mini-program, the processing unit 510 is specifically used to: inject the code file directory included in the target compiled code package of the sub-mini-program to be processed into the code file directory included in the target compiled code package of the main mini-program.
[0117] In one possible example, after injecting the code file directory included in the target compiled code package of the sub-mini-program to be processed into the code file directory included in the target compiled code package of the main mini-program, the processing unit 510 is further configured to: add the page path of the sub-mini-program to the global configuration file included in the target compiled code package of the main mini-program to obtain the merged code package.
[0118] In some embodiments, the mini-program generation device may further include an input / output interface, a communication interface, a power supply, and a communication bus.
[0119] This application embodiment can divide the mini-program generation device into functional units according to the above method example. For example, each function can be divided into separate functional units, or two or more functions can be integrated into one processing unit. The integrated unit can be implemented in hardware or as a software functional unit. It should be noted that the unit division in this application embodiment is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods.
[0120] Please see again Figure 6 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. The electronic device includes a power supply module and other structures, and includes a processor 601, a storage device 602, and a communication interface 603. The processor 601, the storage device 602, and the communication interface 603 can exchange data.
[0121] The storage device 602 may include volatile memory, such as random-access memory (RAM); the storage device 602 may also include non-volatile memory, such as flash memory, solid-state drive (SSD), etc.; the storage device 602 may also include combinations of the above types of memory. The communication interface 603 is an interface for data interaction between internal devices of the electronic device, such as between the storage device 602 and the processor 601.
[0122] The processor 601 may be a central processing unit (CPU). In one embodiment, the processor 601 may also be a graphics processing unit (GPU). The processor 601 may also be a combination of a CPU and a GPU. In one embodiment, the storage device 602 is used to store program instructions. The processor 601 can invoke the program instructions to perform the following steps:
[0123] When the source code packages of at least two mini-programs are obtained, the source code packages of each of the at least two mini-programs are compiled respectively to obtain the target compiled code packages of each mini-program;
[0124] A main mini-program and a sub-mini-program are determined from the at least two mini-programs, wherein the sub-mini-program is a mini-program other than the main mini-program among the at least two mini-programs;
[0125] The target compiled code packages of each of the sub-mini-programs are merged with the target compiled code package of the main mini-program to obtain the merged code package;
[0126] The target mini-program is generated based on the merged code package.
[0127] In one possible example, regarding the step of compiling the source code packages of each of the at least two miniprograms to obtain the target compiled code packages of each miniprogram, the processor 601 is specifically configured to: compile the source code packages of each of the at least two miniprograms according to a first compilation method to obtain a first compiled code package of each miniprogram; process the first compiled code packages of each miniprogram according to a preset processing method to obtain a second compiled code package corresponding to each miniprogram, and use the second compiled code package corresponding to each miniprogram as the target compiled code package of each miniprogram.
[0128] In one possible example, the initial compiled code package includes an initial code file directory, which includes at least one code file. Regarding the step of compiling the source code packages of each of the at least two miniprograms according to the first compilation method to obtain the first compiled code package of each miniprogram, the processor 601 is specifically configured to: clear the initial code file directory in the initial compiled code package corresponding to each miniprogram; compile the source code packages of each of the at least two miniprograms to obtain the currently compiled code file directory corresponding to each miniprogram; and write the currently compiled code file directory into the correspondingly cleared initial compiled code package to obtain the first compiled code package of each miniprogram.
[0129] In one possible example, regarding the step of processing the first compiled code package of each mini-program according to a preset processing method to obtain the second compiled code package corresponding to each mini-program, the processor 601 is specifically configured to: determine invalid code in the first compiled code package of each mini-program, and remove the invalid code from the first compiled code package of each mini-program respectively, to obtain the compiled code package of each mini-program after removing invalid code; compress the compiled code package of each mini-program after removing invalid code according to a second compilation method, to obtain the compiled code package of each mini-program after being compiled according to the second compilation method; and compress the compiled code package of each mini-program after being compiled according to the second method to obtain the second compiled code package corresponding to each mini-program.
[0130] In one possible example, before merging the target compiled code packages of each of the sub-mini-programs with the target compiled code package of the main mini-program, the processor 601 is further configured to: determine the configuration files of the target file types included in the target compiled code packages of each sub-mini-program; determine whether the target compiled code package of the sub-mini-program to be processed is a code package of a preset type according to the file content of the configuration files of the target file types, wherein the sub-mini-program to be processed is any one of the at least two sub-mini-programs; if it is not a code package of a preset type, then perform the step of merging the target compiled code packages of each of the sub-mini-programs with the target compiled code package of the main mini-program.
[0131] In one possible example, the processor 601 is further configured to: if it is a code package of a preset type, extract the entry file of the sub-mini-program to be processed from the target compiled code package of the sub-mini-program to be processed; inject the entry file of the sub-mini-program to be processed into the entry file included in the target compiled code package of the main mini-program, and perform the step of merging the target compiled code packages of each sub-mini-program with the target compiled code package of the main mini-program.
[0132] In one possible example, the target compiled code package includes a code file directory, which includes at least one code file; in the process of merging the target compiled code packages of each of the sub-mini-programs with the target compiled code package of the main mini-program, the processor 601 is specifically used to: inject the code file directory included in the target compiled code package of the sub-mini-program to be processed into the code file directory included in the target compiled code package of the main mini-program.
[0133] In one possible example, after injecting the code file directory included in the target compiled code package of the sub-mini-program to be processed into the code file directory included in the target compiled code package of the main mini-program, the processor 601 is further configured to: add the page path of the sub-mini-program to the global configuration file included in the target compiled code package of the main mini-program to obtain the merged code package.
[0134] In specific implementations, the processor 601, storage device 602, and communication interface 603 described in this embodiment of the invention can execute this embodiment of the invention. Figure 2A , Figure 3 or Figure 4 The implementation methods described in the relevant embodiments of the provided mini-program generation method will not be repeated here.
[0135] This application also provides a computer storage medium storing a computer program for electronic data interchange, which causes a computer to perform some or all of the steps of any of the methods described in the above method embodiments.
[0136] This application also provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform some or all of the steps of any of the methods described in the above method embodiments.
[0137] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0138] The above-disclosed embodiments are merely some examples of the present invention and should not be construed as limiting the scope of the invention. Those skilled in the art will understand that implementing all or part of the above-described embodiments and making equivalent changes in accordance with the claims of the present invention are still within the scope of the invention.
Claims
1. A method for generating a mini-program, characterized in that, The method includes: When the source code packages of at least two mini-programs are obtained, the source code packages of each of the at least two mini-programs are compiled respectively to obtain the target compiled code package of each mini-program. The target compiled code package includes a code file directory, and the code file directory includes at least one code file. Receive a main mini-program determination instruction, determine the mini-program indicated by the main mini-program determination instruction as the main mini-program among the at least two mini-programs, and determine the mini-programs other than the main mini-program among the at least two mini-programs as sub-mini-programs; The configuration files of the target file types included in the target compiled code packages of each sub-mini-program are determined respectively; based on the file content of the configuration files of the target file types, it is determined whether the target compiled code package of the sub-mini-program to be processed is a code package of a preset type, wherein the sub-mini-program to be processed is any one of the at least two sub-mini-programs; if it is a code package of a preset type, the entry file of the sub-mini-program to be processed is extracted from the compiled code package of the sub-mini-program to be processed; the entry file of the sub-mini-program to be processed is injected into the entry file included in the target compiled code package of the main mini-program; A new folder is added under the code file directory corresponding to the homepage of the main mini-program. The code file directory included in the target compiled code package of the sub-mini-program to be processed is injected into the new folder. The page path of the sub-mini-program is added to the global configuration file included in the target compiled code package of the main mini-program to obtain the merged code package. A target mini-program is generated based on the merged code package. The target mini-program's pages include a merged page, which is formed by merging the pages of the main mini-program and the sub-mini-program. The pages of the main mini-program and the sub-mini-program are merged in a left-right or front-back direction.
2. The method according to claim 1, characterized in that, The step of compiling the source code packages of each of the at least two mini-programs to obtain the target compiled code packages of each mini-program includes: The source code packages of each of the at least two mini-programs are compiled according to the first compilation method to obtain the first compiled code package of each mini-program; The first compiled code package of each mini-program is processed according to a preset processing method to obtain the second compiled code package corresponding to each mini-program, and the second compiled code package corresponding to each mini-program is used as the target compiled code package of each mini-program.
3. The method according to claim 2, characterized in that, The initial compiled code package includes an initial code file directory, which contains at least one code file; The step of compiling the source code packages of each of the at least two mini-programs according to the first compilation method to obtain the first compiled code package of each mini-program includes: Clear the initial code file directory in the initial compilation code package corresponding to each mini-program; Compile the source code packages of each of the at least two mini-programs respectively to obtain the current compiled code file directory corresponding to each mini-program; Write the currently compiled code file directory into the corresponding cleared initial compiled code package to obtain the first compiled code package of each mini-program.
4. The method according to claim 2 or 3, characterized in that, The step of processing the first compiled code package of each mini-program according to a preset processing method to obtain the second compiled code package corresponding to each mini-program includes: Identify invalid code in the first compiled code package of each mini-program, and remove the invalid code from the first compiled code package of each mini-program to obtain the compiled code package of each mini-program after removing invalid code; Compile the compiled code packages of each mini-program after removing invalid code according to the second compilation method to obtain the compiled code packages of each mini-program compiled according to the second compilation method; The compiled code packages of each mini-program after being compiled in the second method are compressed to obtain the second compiled code package corresponding to each mini-program.
5. The method according to claim 1, characterized in that, The method further includes: If the code package is not of a preset type, then the step of merging the target compiled code packages of each of the sub-mini-programs with the target compiled code package of the main mini-program is performed.
6. A mini-program generation device, characterized in that, The device includes: The processing unit is configured to, when the source code packages of at least two mini-programs are obtained, compile the source code packages of each of the at least two mini-programs respectively to obtain the target compiled code package of each mini-program. The target compiled code package includes a code file directory, and the code file directory includes at least one code file. The determining unit is configured to receive a main mini-program determining instruction, determine the mini-program indicated by the main mini-program determining instruction as the main mini-program among the at least two mini-programs, and determine the mini-programs other than the main mini-program among the at least two mini-programs as sub-mini-programs; The processing unit is further configured to: determine the configuration files of the target file types included in the target compiled code packages of each sub-program; determine whether the target compiled code package of the sub-program to be processed is a code package of a preset type based on the file content of the configuration files of the target file types, wherein the sub-program to be processed is any one of the at least two sub-programs; if it is a code package of a preset type, extract the entry file of the sub-program to be processed from the compiled code package of the sub-program to be processed; and inject the entry file of the sub-program to be processed into the entry file included in the target compiled code package of the main program; The processing unit is further configured to add a new folder in the code file directory corresponding to the homepage of the main mini-program, inject the code file directory included in the target compiled code package of the sub-mini-program to be processed into the new folder, add the page path of the sub-mini-program to the global configuration file included in the target compiled code package of the main mini-program, and obtain the merged code package; The generation unit is used to generate a target mini-program based on the merged code package. The target mini-program includes a merged page, which is formed by merging the pages of the main mini-program and the sub-mini-program. The pages of the main mini-program and the sub-mini-program are merged in a left-right or front-back direction.
7. An electronic device, characterized in that, The device includes a processor, a storage device, a communication interface, and one or more programs, which are stored in the memory and configured to be executed by the processor according to any one of claims 1-5.
8. A computer-readable storage medium, characterized in that, A computer program for storing electronic data interchange is provided, wherein the computer program causes a computer to perform the method as described in any one of claims 1-5.
9. A computer program product, characterized in that, The computer program product includes computer instructions stored in a computer-readable storage medium, a processor of a computer device reading the computer instructions from the computer-readable storage medium, and the processor executing the computer instructions to cause the computer device to perform the method as described in any one of claims 1-5.
Citation Information
Patent Citations
Program compiling and package combination method and device, electronic equipment and storage medium
CN111176653A