Multi-terminal multiplexed applet code conversion method, device and computer program product
By building file compilation tools that are compatible with different platforms, and automatically compiling the software files of the applet, the problem of poor compatibility between different platforms is solved, and efficient cross-end conversion and improved operating performance is achieved.
Patent Information
- Application Number
- CN202411561984.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-05
- Publication Date
- 2025-03-04
- Estimated Expiration
- 2044-11-05
AI Technical Summary
The poor compatibility of existing applets between different platforms leads to the need for manual code adaptation, which increases the workload and cost, and also has low operating performance.
By building file compilation tools that are compatible with different platforms, automatically compile files in the software project package, generate converted software files compatible with the platform to be deployed, and run them directly on the platform, avoiding runtime code compilation.
It improves the cross-end conversion efficiency of mini programs, reduces workload and cost, and improves operating performance, allowing mini programs to run efficiently on different platforms.
Smart Images

Figure CN119065679B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of data processing technology, and specifically relates to a multi-terminal multiplexed small program code conversion method, device and computer program product. Background Art
[0002] With the development of information technology, most apps have launched mini programs. Mini programs are mobile applications that can be used without downloading and installing. Users only need to scan the QR code or search for them to use them immediately. Due to their advantages such as no need to download and install, no need to uninstall, and no taking up mobile phone storage space, mini programs have been widely used.
[0003] At present, third-party merchants can develop mini-programs based on corresponding development specifications and use corresponding languages, so that they can complete the deployment of mini-programs on different platforms to facilitate user use and increase the customer flow of third-party merchants; however, most of the current mini-programs have compatibility issues, that is, they cannot be run directly on different platforms (such as WeChat mini-programs cannot be run on Baidu platform or Douyin platform). Therefore, when applying cross-end applications, the mini-programs need to be converted across ends.
[0004] In actual use, there are cross-terminal conversion solutions for small programs such as uni-app and taro. However, the above-mentioned existing technologies have the following shortcomings: (1) The versatility is not strong. For different platforms, additional program adaptation needs to be done for different platforms respectively, that is, it is necessary to manually re-develop and modify the code according to different platforms to adapt to different platforms. This not only has a large workload and high cost, but also reduces the efficiency of cross-terminal conversion; (2) The above-mentioned technologies only compile the code when running on the platform, which will cause the memory usage to be too large during runtime, thereby reducing the running performance. Based on this, how to provide a small program code conversion method with low cost, high efficiency and strong running performance has become a problem that needs to be solved urgently. Summary of the invention
[0005] The purpose of the present invention is to provide a multi-terminal multiplexed mini-program code conversion method, device and computer program product to solve the problems of large workload, high cost, low cross-terminal conversion efficiency and low operating performance existing in the prior art.
[0006] In order to achieve the above object, the present invention adopts the following technical solutions:
[0007] In a first aspect, a method for converting codes of a mini-program for multi-terminal multiplexing is provided, comprising:
[0008] Obtaining a target software project package and determining a platform to be deployed for the target software project package;
[0009] Parsing the target software project package to obtain all software files in the target software project package;
[0010] Determine the file compilation tool of each software file according to the file type of each software file, and perform code compilation processing on the software code in each software file based on the platform to be deployed and the file compilation tool of each software file, so as to obtain each converted software file compatible with the platform to be deployed after the code compilation processing, wherein any file compilation tool stores software compilation codes corresponding to different platforms;
[0011] Based on each converted software file, a converted target software project package is generated, so that the converted target software project package can be directly run on the platform to be deployed, so as to complete the reuse of the target software project package on the platform to be deployed.
[0012] Based on the above disclosed content, after acquiring the target software project package and determining its corresponding platform to be deployed, the present invention first parses the target software project package to obtain all software files in the target software project package; then, according to the file type of each software file, the file compilation tool corresponding to each software file is matched; wherein any file compilation tool stores software compilation codes corresponding to different platforms; in this way, the code in each software file can be compiled with the help of the platform to be deployed and the software compilation codes in the aforementioned file compilation tools, thereby obtaining each converted software file compatible with the platform to be deployed; finally, the converted target software project package can be generated based on each converted software file, thereby realizing the direct operation of the software project package on the platform to be deployed.
[0013] Through the above design, the present invention realizes the automatic compilation of files in the software project package by constructing a file compilation tool compatible with different platforms; in this way, it is compatible with code conversion when deployed to different platforms, without the need for manual re-development and modification of the code according to different platforms, which not only improves the cross-end conversion efficiency, but also reduces the cost and workload; at the same time, the present invention uses the compiled files to generate the converted software project package, and deploys it on the platform for operation, rather than compiling the code at runtime; thereby, the performance problem of the mini program when running on multiple terminals is solved; based on this, the present invention provides a mini program code conversion method with low cost, high efficiency and strong operating performance, which provides key technical support for the cross-end application of the mini program, and is therefore very suitable for large-scale application and promotion.
[0014] In a possible design, the software files in the target software project package include: a style file, wherein the file compilation tool corresponding to the style file includes a Less loader and a cascading style sheet loader, the cascading style sheet loader stores style compilation codes corresponding to different platforms, and each style compilation code serves as a software compilation code stored in the file compilation tool corresponding to the style file;
[0015] Correspondingly, based on the to-be-deployed platform and the file compilation tool of each software file, the software code in each software file is compiled, which includes:
[0016] For the style file, calling the Less loader to compile the style file into a cascading style sheet file;
[0017] Determine, from the cascading style sheet loader, the style compilation code corresponding to the platform to be deployed as the first target code;
[0018] The cascading style sheet loader is called and the first target code is run, so as to perform style compilation on the cascading style sheet file by running the first target code, so as to obtain a converted style file after the style compilation.
[0019] In one possible design, the cascading style sheet loader is constructed as follows;
[0020] Calling the postcss parsing tool to parse the cascading style sheet file to obtain style parsing content;
[0021] Generate style compilation codes corresponding to different platforms according to the style parsing content, and determine loader configuration information based on each generated style compilation code;
[0022] The webpack tool is called, and the loader configuration information is used to generate the cascading style sheet loader.
[0023] In a possible design, the software files in the target software project package include: JavaScript files, wherein the file compilation tool corresponding to the JavaScript files includes a code conversion tool and an API loader, the API loader stores API replacement codes corresponding to different platforms, and each API replacement code serves as a software compilation code stored in the file compilation tool corresponding to the JavaScript files;
[0024] Correspondingly, based on the to-be-deployed platform and the file compilation tool of each software file, the software code in each software file is compiled, which includes:
[0025] For the JavaScript file, calling the code conversion tool to convert the JavaScript code in the JavaScript file into software code compatible with the platform to be deployed, so as to obtain a pre-converted JavaScript file after conversion;
[0026] parse the pre-converted JavaScript file using an AST algorithm to obtain API information in the pre-converted JavaScript file, and use the obtained API information as target information;
[0027] Determine, from the API loader, an API replacement code corresponding to the platform to be deployed as a second target code;
[0028] The API loader is called and the second target code is run, so that the target information is replaced with the API information corresponding to the platform to be deployed by running the second target code, so as to obtain a converted JavaScript file after the replacement.
[0029] In a possible design, the software files in the target software project package include: WXML files, wherein the file compilation tool corresponding to the WXML file includes an htmlparser2 parser, the htmlparser2 parser stores attribute conversion codes corresponding to different platforms, and each attribute conversion code serves as a software compilation code stored in the file compilation tool corresponding to the WXML file;
[0030] Correspondingly, based on the to-be-deployed platform and the file compilation tool of each software file, the software code in each software file is compiled, which includes:
[0031] For the WXML file, calling the htmlparser2 parser to parse the WXML file to obtain the original platform attribute information of the WXML file;
[0032] Determine the attribute conversion code corresponding to the platform to be deployed from the htmlparser2 parser;
[0033] The htmlparser2 parser is called and the determined attribute conversion code is run to replace the original platform attribute information in the WXML file with the attribute information of the platform to be deployed by running the determined attribute conversion code, so as to obtain a converted WXML file after the replacement.
[0034] In a possible design, the software files in the target software project package further include: a json file, wherein the file compilation tool corresponding to the json file includes an AST modification tool, the AST modification tool stores modification codes corresponding to different platforms, and each modification code serves as a software compilation code stored in the file compilation tool corresponding to the json file;
[0035] Correspondingly, based on the to-be-deployed platform and the file compilation tool of each software file, the software code in each software file is compiled, which includes:
[0036] For the json file, call the AST modification tool to parse the json file to obtain an abstract syntax tree corresponding to the json file, wherein the abstract syntax tree includes a plurality of nodes, and each node is used to represent a code composition structure of the json code in the json file;
[0037] Determine a specified code in the AST modification tool, and based on the specified code, determine a node to be modified from the abstract syntax tree, wherein the specified code is a modification code in the AST modification tool corresponding to the platform to be deployed;
[0038] The node to be modified is subjected to node conversion processing to convert the node to be modified into a node compatible with the platform to be deployed, so as to obtain a converted json file after the conversion processing.
[0039] In a possible design, the platform to be deployed for the target software project package is determined, including:
[0040] Get the script project using the command line;
[0041] Compiling the script project using a command line using a node startup item, so as to determine a to-be-deployed platform of the target software project package by compiling the script project using a command line;
[0042] The step of generating a converted target software project package based on each converted software file includes:
[0043] Compile each converted software file into the dist directory, so as to obtain the converted target software project package after compiling into the dist directory.
[0044] In a second aspect, a multi-terminal multiplexed applet code conversion device is provided, comprising:
[0045] An acquisition unit, used to acquire a target software project package and determine a platform to be deployed on the target software project package;
[0046] A parsing unit, used for parsing the target software project package to obtain all software files in the target software project package;
[0047] A file compilation unit is used to determine a file compilation tool for each software file according to the file type of each software file, and to perform code compilation processing on the software code in each software file based on the platform to be deployed and the file compilation tool of each software file, so as to obtain each converted software file compatible with the platform to be deployed after the code compilation processing, wherein any file compilation tool stores software compilation codes corresponding to different platforms;
[0048] The file compilation unit is also used to generate a converted target software project package based on each converted software file, so as to directly run the converted target software project package on the platform to be deployed, so as to complete the reuse of the target software project package on the platform to be deployed.
[0049] According to a third aspect, another device for converting multi-terminal multiplexed mini-program codes is provided. Taking the device as an electronic device as an example, the device comprises a memory, a processor and a transceiver which are communicatively connected in sequence, wherein the memory is used to store computer programs, the transceiver is used to send and receive messages, and the processor is used to read the computer program and execute the multi-terminal multiplexed mini-program code conversion method as described in the first aspect or any possible design of the first aspect.
[0050] In a fourth aspect, a storage medium is provided, on which instructions are stored. When the instructions are executed on a computer, the multi-terminal multiplexed mini-program code conversion method as described in the first aspect or any possible design of the first aspect is executed.
[0051] In a fifth aspect, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute the multi-terminal multiplexed mini-program code conversion method as described in the first aspect or any possible design of the first aspect.
[0052] Beneficial effects:
[0053] (1) The present invention realizes automatic compilation of files in a software project package by constructing a file compilation tool compatible with different platforms. In this way, code conversion when deployed to different platforms is compatible without the need for manual redevelopment and modification of the code based on different platforms, which not only improves the efficiency of cross-terminal conversion but also reduces costs and workload. At the same time, the present invention uses the compiled files to generate the converted software project package and deploys it on the platform for operation, rather than compiling the code at runtime. Thus, the performance problem of the mini program when running on multiple terminals is solved. Based on this, the present invention provides a mini program code conversion method with low cost, high efficiency and strong operating performance, which provides key technical support for the cross-terminal application of the mini program and is therefore very suitable for large-scale application and promotion. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 A schematic diagram of the steps of a method for converting codes of a mini-program for multi-terminal multiplexing provided by an embodiment of the present invention;
[0055] Figure 2 The running interface after using the command line for the compiled script project provided by the embodiment of the present invention;
[0056] Figure 3 A schematic diagram of all software files in a target software project package provided by an embodiment of the present invention;
[0057] Figure 4 A schematic diagram of the structure of a multi-terminal multiplexed applet code conversion device provided by an embodiment of the present invention;
[0058] Figure 5 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0059] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the present invention will be briefly introduced below in combination with the drawings and the description of the embodiments or the prior art. Obviously, the following description of the structure of the drawings is only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. It should be noted that the description of these embodiments is used to help understand the present invention, but does not constitute a limitation of the present invention.
[0060] It should be understood that although the terms first, second, etc. may be used herein to describe various units, these units should not be limited by these terms. These terms are only used to distinguish one unit from another unit. For example, a first unit can be referred to as a second unit, and similarly, a second unit can be referred to as a first unit without departing from the scope of the exemplary embodiments of the present invention.
[0061] It should be understood that the term "and / or" that may appear in this article is merely a description of the association relationship between associated objects, indicating that three relationships may exist. For example, A and / or B can represent three situations: A exists alone, B exists alone, and A and B exist at the same time. The term " / and" that may appear in this article describes another type of association object relationship, indicating that two relationships may exist. For example, A / and B can represent two situations: A exists alone, and A and B exist alone. In addition, the character " / " that may appear in this article generally indicates that the previous and next associated objects are in an "or" relationship.
[0062] Example:
[0063] See also Figure 1 As shown, the multi-terminal reused mini-program code conversion method provided in this embodiment realizes the automatic compilation of files in the software project package by constructing a file compilation tool compatible with different platforms; thus, compared with the traditional technology, it has strong versatility and does not need to manually re-modify and develop the code for different platforms. Therefore, it not only improves the cross-terminal conversion efficiency of the mini-program, but also reduces the workload and cost; at the same time, the converted software project package obtained by the present method is a compiled software package, which can be directly run on the platform to be deployed; based on this, compared with the traditional technology of compiling at runtime, the present method reduces the occupancy of the running memory and can improve the running performance; thus, the present method provides key technical support for the cross-terminal application of the mini-program, and is very suitable for large-scale application and promotion; among them, for example, the present method can be but not limited to running on the software development end side, optionally, the software development end can be but not limited to a personal computer, it can be understood that the aforementioned execution subject does not constitute a limitation on the embodiments of the present application, and accordingly, the running steps of the present method can be but not limited to the following steps S1 to S4.
[0064] S1. Obtain a target software project package and determine a platform to be deployed for the target software project package. In this embodiment, the target software project package may be uploaded to a software development end in advance. At the same time, inquire (an open source library of the Rust programming language) may be used to select a project to obtain the target software project package.
[0065] Meanwhile, the platform to be deployed of the target software project package may be determined by, for example but not limited to, the following method.
[0066] S11. Obtain a command line for the script project. In this embodiment, the software development end obtains a command line for the script project when responding to human-computer interaction. The command line for the script project includes a platform to be selected (i.e., the platform to be deployed, such as Baidu, TikTok, or other platforms). Therefore, the command line for the script project can be compiled to determine the aforementioned platform to be deployed. Optionally, the compilation process of the aforementioned command is shown in the following step S12.
[0067] S12. Compile the script project using the node startup item using the command line, and determine the platform to be deployed for the target software project package by compiling the script project using the command line; in the specific implementation, the node startup item is used to compile the command, which is a common technology for project startup in software development, and its principle is not repeated; at the same time, after compiling the aforementioned script project using the command line, the corresponding running interface can be seen Figure 2 As shown, from Figure 2 It can be seen that the operating mode, operating environment and corresponding compilation platform (i.e., the platform to be deployed) of the target software project package can be obtained.
[0068] In this way, after obtaining the target software project package and the corresponding platform to be deployed based on the aforementioned step S1 and its sub-steps, the target software project package can be compiled to convert it into a project package compatible with the aforementioned platform to be deployed, thereby realizing the reuse of the target software project package on the aforementioned platform to be deployed; wherein, in this embodiment, the target software project package is first parsed to obtain the corresponding software file; and then, the software file is compiled to obtain a project package compatible with the aforementioned platform to be deployed; optionally, the parsing process of the target software project package can be but is not limited to as shown in the following step S2.
[0069] S2. Parse the target software project package to obtain all software files in the target software project package; in specific implementation, for example, but not limited to, call Node (which is a server-side, using a JavaScript runtime environment based on the Chrome V8 engine) to parse the target software project package, thereby obtaining all configurable software files; wherein, for example, all software files obtained by the analysis may include, but not limited to: style files, JavaScript files, WXML files, and json files, etc.; further, the schematic diagram of the software files obtained by the above analysis can be seen in Figure 3 As shown; of course, Figure 3 This is only an indication and not an exhaustive list.
[0070] After all the software files in the aforementioned target software project package are obtained based on step S2, the software codes in each software file can be compiled, thereby converting each software file into a file compatible with the platform to be deployed; wherein, the compilation process of each software file can be but is not limited to as shown in the following step S3.
[0071] S3. According to the file type of each software file, the file compilation tool of each software file is determined, and based on the platform to be deployed and the file compilation tool of each software file, the software code in each software file is compiled, so as to obtain each converted software file compatible with the platform to be deployed after the code compilation, wherein any file compilation tool stores software compilation codes corresponding to different platforms; in the specific implementation, it has been explained above that the parsed files include style files, JavaScript files, WXML files and json files, so the corresponding file types are style file types, js file types, WXML file types and json file types; based on this, a tool library is set in the example software development end, and the file compilation tools corresponding to different file types are stored in the tool library; in this way, after obtaining the file type of each software file, tool matching can be performed from the aforementioned tool library to obtain the corresponding file compilation tool.
[0072] Furthermore, the file compilation tools corresponding to the aforementioned software files are given below:
[0073] In this embodiment, the file compilation tool corresponding to the style file may include, but is not limited to: Less loader (i.e., Less loader) and cascading style sheet loader (i.e., css loader), wherein the cascading style sheet loader stores style compilation codes corresponding to different platforms, and each style compilation code serves as a software compilation code stored in the file compilation tool corresponding to the style file; at the same time, the reason for setting the compiler of the style file to Less loader and cascading style sheet loader is that less loader can only process part of the nested logic, and the conditional logic of the style file cannot be implemented. Therefore, this embodiment constructs a cascading style sheet loader to implement the compilation of conditional logic.
[0074] Among them, the construction method of the cascading style sheet loader is as follows: (1) calling the postcss parsing tool (a cssast code tool) to parse the cascading style sheet file to obtain the style parsing content (that is, the running interface style set in the target software project package); (2) generating style compilation codes corresponding to different platforms according to the style parsing content, and determining the loader configuration information based on the generated style compilation codes; in this embodiment, the style compilation framework codes corresponding to different platforms (such as the style compilation framework codes corresponding to Baidu, Douyin, and Kuaishou) can be set in advance in the software development end; then, the aforementioned style parsing content is filled into each style compilation framework code, and the style compilation codes corresponding to different platforms can be obtained; after obtaining the style compilation codes corresponding to different platforms, the corresponding loader configuration information can be generated based on this (that is, the obtained style compilation code is directly used as the configuration information); finally, the css loader can be constructed based on the aforementioned configuration information, as shown in the subsequent step (3); (3) calling the webpack tool (which is a code compilation tool with an entry, an exit, and a loader and plug-ins), and uses the loader configuration information to generate the cascading style sheet loader; in this embodiment, the cascading style sheet loader can be generated by directly introducing the aforementioned loader configuration information into the configuration file corresponding to the webpack tool.
[0075] Similarly, the file compilation tool corresponding to the JavaScript file in the example may include but is not limited to: a code conversion tool and an API loader, wherein the API loader stores API replacement codes corresponding to different platforms, and each API replacement code serves as a software compilation code stored in the file compilation tool corresponding to the JavaScript file; in this embodiment, the example code conversion tool may include but is not limited to babel-loader (a tool for converting JavaScript code into code compatible with different browsers and platforms).
[0076] Further, for example, the file compilation tool corresponding to the WXML file may include but is not limited to: htmlparser2 parser, wherein the htmlparser2 parser stores attribute conversion codes corresponding to different platforms, and each attribute conversion code serves as a software compilation code stored in the file compilation tool corresponding to the WXML file; in this embodiment, the htmlparser2 parser is an open source library created by Dominik Hranitzky, and its goal is to provide an efficient and easy-to-use API to parse HTML and XML documents.
[0077] In this embodiment, the API replacement code and attribute conversion code corresponding to different platforms can be set in advance in the software development end; then, the same construction method of the aforementioned cascading style sheet loader is used to construct the API loader; of course, the process will not be repeated any more.
[0078] In addition, the file compilation tool corresponding to the json file may include but is not limited to: an AST modification tool, wherein the AST modification tool stores modification codes corresponding to different platforms, and each modification code serves as a software compilation code stored in the file compilation tool corresponding to the json file; in this embodiment, the AST modification tool is @humanwhocodes / momoa (which is an ast parsing and modification tool for json files), which is a commonly used tool for parsing and modifying json files; at the same time, the aforementioned modification code is also pre-stored in the AST modification tool, and can be called when used.
[0079] Thus, after the file compilation tools corresponding to the aforementioned software files are determined, the compilation of the software files can be performed, and the process is shown in the following steps S301 to S313.
[0080] Among them, for the style file, for example, but not limited to, the following steps S301 to S303 are used to convert it into a file compatible with the platform to be deployed.
[0081] S301. For the style file, call the Less loader to compile the style file into a cascading style sheet file; in this embodiment, the Less loader, i.e., the Less loader is a loader for Webpack, which is a tool for compiling Less files (i.e., style files) into CSS (Cascading Style Sheets). Therefore, when using it, directly call the loader to complete the conversion of the style file to the cascading style sheet file.
[0082] After the cascading style sheet file is obtained, the cascading style sheet loader may be used to implement the compilation of the cascading style sheet file, and the process may be but is not limited to the following steps S302 and S303.
[0083] S302. Determine the style compilation code corresponding to the platform to be deployed from the cascading style sheet loader as the first target code; in this embodiment, assuming that the platform to be deployed is WeChat, then determine the style compilation code corresponding to WeChat, and based on this, compile the conditional logic code in the cascading style sheet file (that is, the code corresponding to the running interface), and the compilation process can be but is not limited to the following step S303.
[0084] S303. Call the cascading style sheet loader and run the first target code to perform style compilation on the cascading style sheet file by running the first target code, so as to obtain a converted style file after the style compilation.
[0085] Thus, based on the aforementioned steps S301 to S303, the compilation of the style file can be completed to obtain a converted style file compatible with the platform to be deployed; then, the JavaScript file can be compiled, and the process can be but not limited to as shown in the following steps S304 to S307.
[0086] S304. For the JavaScript file, call the code conversion tool to convert the JavaScript code in the JavaScript file into software code compatible with the platform to be deployed, so as to obtain a pre-converted JavaScript file after the conversion; in this embodiment, it has been explained above that the code conversion tool adopts babel-loader, so babel-loader can be directly called to convert the software code in the JavaScript file into software code compatible with the platform to be deployed, so as to obtain a pre-converted JavaScript file; then, the API information in the pre-converted JavaScript file can be replaced, and the process is shown in the following steps S305 to S307.
[0087] S305. Utilize the AST algorithm to parse the pre-converted JavaScript file and obtain the API information in the pre-converted JavaScript file, and use the obtained API information as the target information. In specific implementation, the AST (Abstract Syntax Tree) algorithm represents the abstract syntax structure of the source code in a tree form, which decomposes the code into nodes in the tree, each node representing a structure in the code (i.e., a code composition structure), such as a variable declaration, a literal, an expression, etc. Therefore, based on the aforementioned AST algorithm, the API information on the original platform in the target software project package can be obtained. Then, the API loader can be used to replace the API information, so that the converted JavaScript file supports the API interface of the platform to be deployed. The API information replacement process can be, but is not limited to, as shown in the following steps S306 and S307.
[0088] S307. Determine the API replacement code corresponding to the platform to be deployed from the API loader as the second target code; in this embodiment, the corresponding API replacement code can be determined according to the type of the platform to be deployed (such as Baidu, Douyin or Kuaishou); then, based on this, the API information determined in the aforementioned step S305 can be replaced, as shown in the following step S308.
[0089] S308. Call the API loader and run the second target code to replace the target information with the API information corresponding to the platform to be deployed by running the second target code, so as to obtain the converted JavaScript file after the replacement; in this embodiment, the aforementioned step S308 is explained by an example, wherein, if the original platform of the target software project package is WeChat (i.e., it runs on WeChat), its corresponding API information is wx.showLoading; and assuming that the platform to be deployed is Baidu, then the API replacement code corresponding to Baidu is used to replace wx.showLoading with swan.showLoading to achieve API adaptation of the Baidu platform; of course, when the platform to be deployed is other platforms, the API information replacement process is the same as the aforementioned example, and will not be repeated here.
[0090] In this way, through the aforementioned steps S304 to S307, the file compilation of the JavaScript file can be completed to obtain a converted JavaScript file that is compatible with the platform to be deployed.
[0091] Then, the WXML file may be compiled, and the process may be but not limited to the following steps S308 to S310 .
[0092] S308. For the WXML file, call the htmlparser2 parser to parse the WXML file to obtain the original platform attribute information of the WXML file; in this embodiment, an example is used to illustrate this step. Assuming that the original operating platform of the target software project package is WeChat, the original platform attribute information is the attribute information corresponding to WeChat, such as wx:if; of course, the aforementioned platform attribute information is the platform-specific attributes written when the software runs on the platform; therefore, when in use, the aforementioned WXML file can be obtained by calling the htmlparser2 parser to parse the aforementioned WXML file; of course, the platform attribute information corresponding to different original operating platforms is different, which will not be repeated here.
[0093] After the original platform attribute information is obtained, the attribute conversion may be performed, and the process may be, but is not limited to, as shown in the following steps S309 and S310.
[0094] S309. Determine the attribute conversion code corresponding to the platform to be deployed from the htmlparser2 parser; in this embodiment, after determining the attribute conversion code corresponding to the platform to be deployed, attribute conversion can be performed based on this code, and the process is shown in the following step S310.
[0095] S310. Calling the htmlparser2 parser and running the determined attribute conversion code to replace the original platform attribute information in the WXML file with the attribute information of the platform to be deployed by running the determined attribute conversion code, so as to obtain a converted WXML file after the replacement.
[0096] In the specific implementation, the aforementioned step S310 is explained by an example, wherein, assuming that the platform to be deployed is Baidu, and the original operating platform is WeChat, then the attribute conversion code corresponding to WeChat is used to convert wx:if into s-if; of course, when the platform to be deployed is other platforms, the conversion process is the same as the aforementioned example, and will not be repeated here.
[0097] After the compilation of the WXML file is completed, the compilation of the json file may be performed, and the process may be but not limited to the following steps S311 to S313.
[0098] S311. For the json file, call the AST modification tool to parse the json file to obtain an abstract syntax tree corresponding to the json file, wherein the abstract syntax tree contains multiple nodes, and each node is used to represent a code composition structure of the json code in the json file; in this embodiment, it has been explained above that the AST modification tool is an ast parsing and modification tool for json files, therefore, it is equivalent to parsing the json file into an abstract syntax tree, and a node in the abstract syntax tree represents a variable, literal, expression, etc.; based on this, the variables, literals and expressions that need to be modified can be determined based on the abstract syntax tree, so as to subsequently modify the aforementioned variables, independent variables and expressions; optionally, the modification process of the nodes in the aforementioned abstract syntax tree can be but is not limited to the following steps S312 to S313.
[0099] S312. Determine the designated code in the AST modification tool, and based on the designated code, determine the node to be modified from the abstract syntax tree, wherein the designated code is the modification code in the AST modification tool corresponding to the platform to be deployed; in specific application, for example, the role of each modification code in the AST modification tool is to send the abstract syntax tree corresponding to the json file to the detection end, so that the user corresponding to the detection end can determine the node to be modified based on the abstract syntax tree, and convert the node to be modified to obtain the converted node; finally, upload the node to be modified and the converted node to the software development end, and at this time, the software development end can determine the node to be modified and the converted node when responding to the data interaction operation.
[0100] In this way, after obtaining the node to be modified and the converted node, the node replacement can be performed, and the process can be but not limited to the following step S313.
[0101] S313. Perform node conversion processing on the node to be modified to convert the node to be modified into a node compatible with the platform to be deployed, so as to obtain a converted json file after the conversion processing; in the present embodiment, it is equivalent to directly replacing the node to be modified with the converted node, so as to obtain an updated abstract syntax tree after the replacement; finally, according to the updated abstract syntax tree, a converted json file compatible with the platform to be deployed can be obtained.
[0102] In addition, in this embodiment, examples can be but are not limited to integrating the aforementioned file compilation tools into the webpack code packaging tool, and then, when in use, the compilation of different software files is achieved by calling the webpack code packaging tool, thereby obtaining converted files that are compatible with the platform to be deployed.
[0103] Therefore, through the aforementioned steps S301 to S313, this embodiment realizes the automatic compilation of files in the software project package by constructing a file compilation tool compatible with different platforms, so as to obtain various converted software files compatible with the platform to be deployed; then, a converted target software project package can be generated based on each converted software file; wherein, the generation process of the converted target software project package can be but is not limited to as shown in the following step S4.
[0104] S4. Generate a converted target software project package based on each converted software file, so that the converted target software project package can be directly run on the platform to be deployed, so as to complete the reuse of the target software project package on the platform to be deployed; in specific application, for example, each converted software file is compiled into a dist directory (i.e., a release directory), so as to obtain the converted target software project package after compiling into the dist directory; in this way, the converted target software project package can be directly run on the platform to be deployed.
[0105] Therefore, through the multi-terminal multiplexed mini-program code conversion method described in detail in the aforementioned steps S1 to S4, the present invention realizes the automatic compilation of files in the software project package by constructing a file compilation tool compatible with different platforms; thus, compared with traditional technologies, it has strong versatility and does not require manual code re-modification and development for different platforms. Therefore, it not only improves the cross-terminal conversion efficiency of mini-programs, but also reduces workload and cost; at the same time, the converted software project package obtained by the present invention is a compiled software package, which can be directly run on the platform to be deployed; based on this, compared with traditional technologies that compile at runtime, the present invention reduces the amount of running memory occupied and can improve running performance; thus, the present invention provides key technical support for the cross-terminal application of mini-programs, and is very suitable for large-scale application and promotion.
[0106] like Figure 4 As shown, the second aspect of this embodiment provides a hardware device for implementing the multi-terminal multiplexing applet code conversion method described in the first aspect of the embodiment, including:
[0107] The acquisition unit is used to acquire a target software project package and determine a platform to be deployed for the target software project package.
[0108] The parsing unit is used to parse the target software project package to obtain all software files in the target software project package.
[0109] The file compilation unit is used to determine the file compilation tool of each software file according to the file type of each software file, and based on the platform to be deployed and the file compilation tool of each software file, perform code compilation processing on the software code in each software file, so as to obtain each converted software file compatible with the platform to be deployed after the code compilation processing, wherein any file compilation tool stores software compilation codes corresponding to different platforms.
[0110] The file compilation unit is also used to generate a converted target software project package based on each converted software file, so as to directly run the converted target software project package on the platform to be deployed, so as to complete the reuse of the target software project package on the platform to be deployed.
[0111] The working process, working details and technical effects of the device provided in this embodiment can be found in the first aspect of the embodiment and will not be described in detail here.
[0112] like Figure 5 As shown, the third aspect of this embodiment provides another multi-terminal multiplexed mini-program code conversion device, taking the device as an electronic device as an example, comprising: a memory, a processor and a transceiver that are communicatively connected in sequence, wherein the memory is used to store computer programs, the transceiver is used to send and receive messages, and the processor is used to read the computer program, and execute the multi-terminal multiplexed mini-program code conversion method as described in the first aspect of the embodiment.
[0113] For example, the memory may include, but is not limited to, random access memory (RAM), read only memory (ROM), flash memory, first input first output (FIFO) and / or first in last out (FILO), etc. Specifically, the processor may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). At the same time, the processor may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state.
[0114] In some embodiments, the processor may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. For example, the processor may not be limited to a microprocessor of the STM32F105 series, a reduced instruction set computer (RISC) microprocessor, an X86 architecture processor, or a processor with an integrated embedded neural network processing unit (NPU); the transceiver may be, but is not limited to, a wireless fidelity (WIFI) wireless transceiver, a Bluetooth wireless transceiver, a General Packet Radio Service (GPRS) wireless transceiver, a ZigBee protocol (a low-power LAN protocol based on the IEEE802.15.4 standard, ZigBee) wireless transceiver, a 3G transceiver, a 4G transceiver, and / or a 5G transceiver. In addition, the device may also include, but is not limited to, a power module, a display screen, and other necessary components.
[0115] The working process, working details and technical effects of the electronic device provided in this embodiment can be found in the first aspect of the embodiment and will not be described in detail here.
[0116] The fourth aspect of this embodiment provides a storage medium that stores instructions for the multi-terminal multiplexing mini-program code conversion method described in the first aspect of the embodiment, that is, the storage medium stores instructions, and when the instructions are run on a computer, the multi-terminal multiplexing mini-program code conversion method described in the first aspect of the embodiment is executed.
[0117] The storage medium refers to a carrier for storing data, which may include but is not limited to a floppy disk, a CD, a hard disk, a flash memory, a USB flash drive and / or a memory stick, and the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.
[0118] The working process, working details and technical effects of the storage medium provided in this embodiment can be found in the first aspect of the embodiment and will not be described in detail here.
[0119] The fifth aspect of this embodiment provides a computer program product containing instructions, which, when executed on a computer, enables the computer to execute the multi-terminal multiplexed mini-program code conversion method as described in the first aspect of the embodiment, wherein the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device.
[0120] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for converting code of a small program for multi-terminal multiplexing, characterized in that: include: Obtaining a target software project package and determining a platform to be deployed for the target software project package; Parsing the target software project package to obtain all software files in the target software project package; Determine the file compilation tool of each software file according to the file type of each software file, and perform code compilation processing on the software code in each software file based on the platform to be deployed and the file compilation tool of each software file, so as to obtain each converted software file compatible with the platform to be deployed after the code compilation processing, wherein any file compilation tool stores software compilation codes corresponding to different platforms; Based on each converted software file, a converted target software project package is generated, so that the converted target software project package can be directly run on the platform to be deployed, so as to complete the reuse of the target software project package on the platform to be deployed; The software files in the target software project package include: style files, wherein the file compilation tools corresponding to the style files include a Less loader and a cascading style sheet loader, the cascading style sheet loader stores style compilation codes corresponding to different platforms, and each style compilation code serves as a software compilation code stored in the file compilation tool corresponding to the style file; Correspondingly, based on the to-be-deployed platform and the file compilation tool of each software file, the software code in each software file is compiled, which includes: For the style file, calling the Less loader to compile the style file into a cascading style sheet file; Determine, from the cascading style sheet loader, the style compilation code corresponding to the platform to be deployed as the first target code; Calling the cascading style sheet loader and running the first target code to perform style compilation on the cascading style sheet file by running the first target code, so as to obtain a converted style file after the style compilation; The software files in the target software project package include: JavaScript files, wherein the file compilation tool corresponding to the JavaScript files includes a code conversion tool and an API loader, the API loader stores API replacement codes corresponding to different platforms, and each API replacement code serves as a software compilation code stored in the file compilation tool corresponding to the JavaScript files; Correspondingly, based on the to-be-deployed platform and the file compilation tool of each software file, the software code in each software file is compiled, which includes: For the JavaScript file, calling the code conversion tool to convert the JavaScript code in the JavaScript file into software code compatible with the platform to be deployed, so as to obtain a pre-converted JavaScript file after conversion; parse the pre-converted JavaScript file using an AST algorithm to obtain API information in the pre-converted JavaScript file, and use the obtained API information as target information; Determine, from the API loader, an API replacement code corresponding to the platform to be deployed as a second target code; Calling an API loader and running the second target code, so as to replace the target information with the API information corresponding to the platform to be deployed by running the second target code, so as to obtain a converted JavaScript file after the replacement; The software files in the target software project package include: WXML files, wherein the file compilation tool corresponding to the WXML file includes an htmlparser2 parser, the htmlparser2 parser stores attribute conversion codes corresponding to different platforms, and each attribute conversion code serves as a software compilation code stored in the file compilation tool corresponding to the WXML file; Correspondingly, based on the to-be-deployed platform and the file compilation tool of each software file, the software code in each software file is compiled, which includes: For the WXML file, calling the htmlparser2 parser to parse the WXML file to obtain the original platform attribute information of the WXML file; Determine the attribute conversion code corresponding to the platform to be deployed from the htmlparser2 parser; Calling the htmlparser2 parser and running the determined attribute conversion code, so as to replace the original platform attribute information in the WXML file with the attribute information of the platform to be deployed by running the determined attribute conversion code, so as to obtain a converted WXML file after the replacement; The software files in the target software project package also include: a json file, wherein the file compilation tool corresponding to the json file includes an AST modification tool, the AST modification tool stores modification codes corresponding to different platforms, and each modification code serves as a software compilation code stored in the file compilation tool corresponding to the json file; Correspondingly, based on the to-be-deployed platform and the file compilation tool of each software file, the software code in each software file is compiled, which includes: For the json file, call the AST modification tool to parse the json file to obtain an abstract syntax tree corresponding to the json file, wherein the abstract syntax tree includes a plurality of nodes, and each node is used to represent a code composition structure of the json code in the json file; Determine a specified code in the AST modification tool, and based on the specified code, determine a node to be modified from the abstract syntax tree, wherein the specified code is a modification code in the AST modification tool corresponding to the platform to be deployed; The node to be modified is subjected to node conversion processing to convert the node to be modified into a node compatible with the platform to be deployed, so as to obtain a converted json file after the conversion processing.
2. A method for converting code of a multi-terminal multiplexed applet according to claim 1, characterized in that: The cascading style sheet loader is constructed as follows; Calling the postcss parsing tool to parse the cascading style sheet file to obtain style parsing content; Generate style compilation codes corresponding to different platforms according to the style parsing content, and determine loader configuration information based on each generated style compilation code; The webpack tool is called, and the loader configuration information is used to generate the cascading style sheet loader.
3. The method for converting code of a multi-terminal multiplexed applet according to claim 1, characterized in that: Determine the platform on which the target software project package will be deployed, including: Get the script project using the command line; Compiling the script project using a command line using a node startup item, so as to determine a to-be-deployed platform of the target software project package by compiling the script project using a command line; The step of generating a converted target software project package based on each converted software file includes: Compile each converted software file into the dist directory, so as to obtain the converted target software project package after compiling into the dist directory.
4. A multi-terminal multiplexing applet code conversion device, characterized in that: A method for converting a small program code for multi-terminal multiplexing according to any one of claims 1 to 3, wherein the device comprises: An acquisition unit, used to acquire a target software project package and determine a platform to be deployed on the target software project package; A parsing unit, used for parsing the target software project package to obtain all software files in the target software project package; A file compilation unit is used to determine a file compilation tool for each software file according to the file type of each software file, and to perform code compilation processing on the software code in each software file based on the platform to be deployed and the file compilation tool of each software file, so as to obtain each converted software file compatible with the platform to be deployed after the code compilation processing, wherein any file compilation tool stores software compilation codes corresponding to different platforms; The file compilation unit is also used to generate a converted target software project package based on each converted software file, so as to directly run the converted target software project package on the platform to be deployed, so as to complete the reuse of the target software project package on the platform to be deployed.
5. A multi-terminal multiplexing applet code conversion device, characterized in that: include: A memory, a processor and a transceiver which are sequentially connected in communication, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program, and execute the multi-terminal multiplexed mini-program code conversion method as described in any one of claims 1 to 3.
6. A computer program product comprising instructions, characterized in that When the instructions are executed on a computer, the computer is caused to execute the multi-terminal multiplexed mini-program code conversion method as described in any one of claims 1 to 3.
Citation Information
Patent Citations
A small program code conversion system and conversion method based on multiple platforms
CN109710260A
Small program conversion method and device,equipment and storage medium
CN111610978A