Code processing methods, apparatus, computer equipment and storage media
By generating virtual modules associated with the main body and page modules and constructing a dependency graph, the problem of poor project construction effect in existing technologies for mini-programs is solved, and efficient code processing and construction effect are achieved.
Patent Information
- Application Number
- CN202110909269.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-09
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2041-08-09
AI Technical Summary
In existing technologies, the automated building of mini-program projects using the gulp tool cannot analyze the code dependencies in the source code, resulting in poor build performance.
By generating virtual modules associated with the main modules of the main type and page type, a dependency graph is constructed, and the main and page build artifacts are output based on the dependency graph, fully considering the code dependencies between the modules.
It improves the efficiency and effectiveness of building mini-program projects, and enables efficient processing of source code with the help of build tools.
Smart Images

Figure CN115904334B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a code processing method, apparatus, computer device, and storage medium. Background Technology
[0002] A mini program is a quick application that runs by attaching to a host program.
[0003] In related technologies, when building a mini-program project, the gulp tool is often used to directly compile the mini-program source code to achieve automated building of the mini-program project.
[0004] However, among the aforementioned technologies, the automated building process of mini-program projects using the gulp tool cannot analyze the code dependencies in the source code, resulting in poor building performance for mini-program projects. Summary of the Invention
[0005] This application provides a code processing method, apparatus, computer device, and storage medium, which can analyze code dependencies in source code to improve the building effect of mini-program projects. The technical solution is as follows:
[0006] On the one hand, a code processing method is provided, the method comprising:
[0007] Obtain at least two types of main modules, where each main module corresponds to a program main file in the source code;
[0008] Generate a first virtual module associated with the subject modules of the at least two subject types;
[0009] A dependency graph is constructed using the first virtual module as the input starting point; the dependency graph contains the reference relationships between the first virtual module and the subject modules of the at least two subject types.
[0010] Based on the dependency graph, output at least two main body construction products corresponding to the source code, and the at least two main body construction products correspond one-to-one with the at least two main body types; the main body construction products contain main body modules of the corresponding main body types.
[0011] On the other hand, a code processing apparatus is provided, the apparatus comprising:
[0012] The first acquisition module is used to acquire at least two types of main modules, wherein the main modules correspond to the program main files in the source code;
[0013] A first generation module is used to generate a first virtual module associated with the subject modules of the at least two subject types;
[0014] A dependency graph construction module is used to construct a dependency graph starting from the first virtual module; the dependency graph contains reference relationships between the first virtual module and the subject modules of the at least two subject types;
[0015] The main body build artifact output module is used to output at least two main body build artifacts corresponding to the source code based on the dependency graph. The at least two main body build artifacts correspond one-to-one with the at least two main body types. The main body build artifacts contain main body modules of the corresponding main body types.
[0016] In one possible implementation, the device further includes:
[0017] The second acquisition module is used to acquire page modules of at least two page types, wherein the page modules correspond to program page files in the source code;
[0018] The second generation module is used to generate a second virtual module associated with the page modules of the at least two page types;
[0019] The dependency graph construction module is used to construct the dependency graph based on the first virtual module and the second virtual module, with the first virtual module as the input starting point. The dependency graph includes the reference relationship between the first virtual module and the main modules of the at least two main types, and the reference relationship between the third virtual module and the page modules of the at least two page types.
[0020] In one possible implementation, the device further includes:
[0021] The combination acquisition module is used to segment the dependency graph based on module type to obtain two module combinations; the two module combinations include a first module combination corresponding to the main modules of at least two main types, and a second module combination corresponding to the page modules of at least two page types;
[0022] The main body build product output module is used to output at least two main body build products corresponding to the source code based on the combination of the first modules.
[0023] In one possible implementation, the device further includes:
[0024] The page build product output module is used to output at least two page build products corresponding to the source code based on the combination of the second module; the at least two page build products correspond one-to-one with the at least two page types; the page build products contain page modules of the corresponding page types.
[0025] In one possible implementation, the first generation module is used to call the first loader to associate the program body files in the body modules of the at least two body types to generate the first virtual module.
[0026] In one possible implementation, the second generation module is used to call the second loader to associate the program page files in the page modules of the at least two page types and generate the second virtual module.
[0027] In one possible implementation, a target subject module is included in the subject module corresponding to at least two subject types, the target subject module being a subject module having a target subject type; the apparatus further includes:
[0028] The third generation module is used to call the third loader to perform compilation format conversion on the source code files in the target main module and generate a third virtual module; the compilation format conversion refers to converting the first compilation format to the second compilation format.
[0029] The dependency graph construction module is used to establish the reference relationship between the third virtual module and the first virtual module, and the reference relationship between the third virtual module and the second virtual module, so as to construct the dependency graph;
[0030] The first compilation format includes a dependency declaration format, and the second compilation format includes a reference format.
[0031] In one possible implementation, in response to a page module containing a target page module of at least two page types, the apparatus further includes:
[0032] The fourth generation module is used to call the fourth loader to perform compilation format conversion on the target page module and generate the fourth virtual module; the compilation format conversion refers to converting the first compilation format into the second compilation format;
[0033] The dependency graph construction module is used to establish the reference relationship between the fourth virtual module and the second virtual module in order to construct the dependency graph;
[0034] The first compilation format includes a dependency declaration format, and the second compilation format includes a reference format.
[0035] In one possible implementation, in response to the source file being a code file compiled based on a first type of compiled language, the first generation module includes:
[0036] The first conversion submodule is used to call the first loader to convert the program body files in at least two body types of body modules into body conversion files; the body conversion files are code files compiled based on the second type of compilation language.
[0037] The first generation submodule is used to call the first loader to associate the subject transformation files in the subject modules of at least two subject types and generate the first virtual module.
[0038] In one possible implementation, in response to the source file being a code file compiled based on a first type of compiled language, the second generation module includes:
[0039] The second conversion submodule is used to call the second loader to convert program page files in page modules of at least two page types into page conversion files; the page conversion files are code files compiled based on the second type of compilation language.
[0040] The second generation submodule is used to call the second loader to associate the page conversion files in at least two types of page modules and generate the third virtual module.
[0041] In one possible implementation, the first type of compiled language is a non-mini-program compiled language, and the second type of compiled language is a mini-program compiled language.
[0042] In one possible implementation, the at least two main build artifacts include build artifacts with compilation formats of js, json and wxss, respectively;
[0043] The at least two page build artifacts include build artifacts in compiled formats of js, json, wxss and wxml respectively.
[0044] On the other hand, a computer device is provided, the computer device including a processor and a memory, the memory storing at least one computer program, the at least one computer program being loaded and executed by the processor to implement the code processing methods provided in the various alternative implementations described above.
[0045] On the other hand, a computer-readable storage medium is provided, wherein at least one computer program is stored in the storage medium, the computer program being loaded and executed by a processor to implement the code processing methods provided in the various alternative implementations described above.
[0046] On the other hand, a computer program product or computer program is provided, 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 code processing methods provided in the various optional implementations described above.
[0047] The technical solution provided in this application may include the following beneficial effects:
[0048] The code processing method provided in this application generates a first type of virtual module associated with various types of main files, and uses the first type of virtual module as the input starting point to construct a dependency graph based on the reference relationship between the modules. Based on the dependency graph, it obtains and outputs at least two main construction artifacts corresponding to the source code. This allows the use of construction tools to improve the processing efficiency of the source code during the processing process. At the same time, since the code dependencies between the modules are fully considered during the architecture process, the construction effect of the project corresponding to the source code is improved.
[0049] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description
[0050] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0051] Figure 1 A schematic diagram of the structure of a code processing system illustrated in an exemplary embodiment of this application is shown;
[0052] Figure 2 A flowchart illustrating a code processing method provided in an exemplary embodiment of this application is shown;
[0053] Figure 3 This illustration shows a schematic diagram illustrating the execution effect of mpflow help in an exemplary embodiment of this application;
[0054] Figure 4 This illustration shows the execution effect of the mpflow create command as illustrated in an exemplary embodiment of this application;
[0055] Figure 5 A flowchart illustrating a code processing method provided in an exemplary embodiment of this application is shown;
[0056] Figure 6 This application shows a schematic diagram illustrating the function of the app-loader in an exemplary embodiment.
[0057] Figure 7 This illustration shows a schematic diagram of the compilation format conversion of the source code file in app.json, as shown in an exemplary embodiment of this application;
[0058] Figure 8 A schematic diagram of a dependency graph provided in an exemplary embodiment of this application is shown;
[0059] Figure 9 A schematic diagram illustrating the output entity construction product of an exemplary embodiment of this application is shown;
[0060] Figure 10 A schematic diagram illustrating the mpflow path processing flow of an exemplary embodiment of this application is shown;
[0061] Figure 11 This is a block diagram of a code processing apparatus provided in an exemplary embodiment of this application;
[0062] Figure 12 This is a structural block diagram of a computer device according to an exemplary embodiment;
[0063] Figure 13 This is a structural block diagram of a computer device according to an exemplary embodiment. Detailed Implementation
[0064] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0065] It should be understood that "multiple" as used in this article refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.
[0066] This application proposes a code processing method that can analyze code dependencies in the source code to improve the building effect of mini-program projects. Figure 1 A schematic diagram of the structure of a code processing system illustrated in an exemplary embodiment of this application is shown, such as... Figure 1 As shown, the system may include a server 110 and a terminal 120.
[0067] The aforementioned server 110 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. In this embodiment, the server 110 can be used to receive source code and process it.
[0068] The aforementioned terminal 120 can be a terminal device with code compilation capabilities. For example, terminal 120 can be a smartphone, tablet computer, e-book reader, smart glasses, smartwatch, smart TV, MP3 player (Moving Picture Experts Group Audio Layer III), MP4 player (Moving Picture Experts Group Audio Layer IV), laptop computer, desktop computer, etc. In this embodiment, terminal 120 can be used to provide source code, that is, after the user completes the compilation of the source code through terminal 120, the source code is uploaded to server 110 so that server 110 can complete the construction of the source code; or, terminal 120 can also have code construction capabilities, and after the user completes the compilation of the source code, it can directly construct the source code. This application does not limit this.
[0069] Optionally, the system described above includes one or more servers 110 and multiple terminals 120. This application embodiment does not limit the number of servers 110 and terminals 120.
[0070] The terminal and server are connected via a communication network. Optionally, the communication network can be a wired network or a wireless network.
[0071] Optionally, the aforementioned wireless or wired networks use standard communication technologies and / or protocols. The network is typically the Internet, but can also be any network, including but not limited to Local Area Networks (LANs), Metropolitan Area Networks (MANs), Wide Area Networks (WANs), mobile, wired or wireless networks, private networks, or any combination of virtual private networks. In some embodiments, technologies and / or formats including Hyper Text Markup Language (HTML), Extensible Markup Language (XML), etc., are used to represent data exchanged over the network. Furthermore, conventional encryption technologies such as Secure Socket Layer (SSL), Transport Layer Security (TLS), Virtual Private Networks (VPNs), and Internet Protocol Security (IPsec) can be used to encrypt all or some links. In other embodiments, customized and / or dedicated data communication technologies can be used to replace or supplement the aforementioned data communication technologies. This application does not impose any limitations.
[0072] Figure 2 A flowchart illustrating a code processing method provided in an exemplary embodiment of this application is shown. This code processing method can be executed by a computer device, and the terminal can be implemented as follows: Figure 1 The terminal or server shown, such as Figure 2 As shown, this code processing method may include the following steps:
[0073] Step 210: Obtain at least two types of main body modules, which correspond to the main program files in the source code.
[0074] In this embodiment of the application, the source code may be a user-compiled code file; further, the source code may be a code file used to build a mini-program; the source code may contain the main program file.
[0075] In the embodiments of the application, any one of the at least two subject type subject modules can correspond to a program subject file of at least one subject code type in the source code. For example, a subject module of subject type js can correspond to a program subject file of subject code type js, and / or a program subject file of subject type ts.
[0076] Step 220: Generate a first virtual module associated with a subject module of at least two subject types.
[0077] Step 230: Using the first virtual module as the starting point, construct a dependency graph; the dependency graph contains the reference relationships between the first virtual module and subject modules of at least two subject types.
[0078] In this embodiment of the application, the dependency graph may include a first virtual module, at least two types of subject modules, and an element used to represent the reference relationship between the first virtual module and the at least two types of subject modules. Schematic, the element may be implemented as a directional arrow.
[0079] Step 240: Output at least two subject construction artifacts corresponding to the source code based on the dependency graph. The at least two subject construction artifacts correspond one-to-one with at least two subject types. The subject construction artifacts contain subject modules of the corresponding subject types.
[0080] Indicatively, a subject build product contains all subject modules in at least two subject modules that correspond to the subject type of the subject build product. In other words, the subject build product is a set of subject modules with the same subject type in at least two subject modules.
[0081] The main body's build artifact can be implemented as a program file.
[0082] In summary, the code processing method provided in this application generates a first type of virtual module associated with various types of main files, and uses the first type of virtual module as the input starting point to construct a dependency graph based on the reference relationships between the modules. Based on the dependency graph, it obtains and outputs at least two main construction artifacts corresponding to the source code. This allows the use of construction tools to improve the processing efficiency of the source code during the processing process. At the same time, since the code dependencies between the modules are fully considered during the architecture process, the construction effect of the project corresponding to the source code is improved.
[0083] During the process of building the mini-program code, a build tool can be used to automate the construction of the mini-program source code. The code processing method provided in this embodiment can be implemented by a build tool, which can be called mpflow. Before mpflow obtains and outputs the build artifacts of the source code through the mini-program development tool, it is necessary to install, configure, and start mpflow on the computer device. Schematic, this process can be implemented as follows:
[0084] 1. Install the mpflow command line;
[0085] Computer devices can install @mpflow / cli globally using package management tools, for example: npm install @mpflow / cli -g or yarn global add @mpflow / cli.
[0086] After installation, an mpflow command is also registered globally. Users can use mpflow-help to confirm the installation results. Figure 3 This illustration shows a schematic diagram of the execution effect of mpflow help as shown in an exemplary embodiment of this application, such as... Figure 3 As shown, executing `mpflow help` displays various auxiliary commands in mpflow, including `mpflowcreate`. <appname>The command is used to create mini-programs; mpflow add <pluginname>The command is used to download and install plugins; mpflow generate <pluginname>The `mpflow build` command is used to trigger the plugin's generator; the `mpflow dev` command is used to build the mini-program; the `mpflow inspect` command is used to develop the mini-program; and the `mpflow inspect` command is used to inspect the mpflow build configuration.
[0087] 2. Create an mpflow project;
[0088] The mpflow create command can be used to quickly create an mpflow project. During the creation process, you need to enter the mini-program appid, and then set whether to install plugins, such as TypeScript plugins, CSS plugins, testing plugins, etc., according to the project needs. This will provide extended capabilities on the basis of the native mini-program, allowing mini-program developers to use Babel, TypeScript, Less, unit testing, e2e testing and other capabilities in addition to using the native mini-program functions. Figure 4 This illustration shows the execution effect of the mpflow create command as shown in an exemplary embodiment of this application. Figure 4 As shown, the mpflowcreate command can quickly create an mpflow project, which corresponds to multiple optional plugins. The application status of each plugin in the project can be set, i.e., whether to install or not.
[0089] 3. Start development;
[0090] The mpflow dev-open command can be used to enable local file monitoring and automatically launch the mini-program development tool.
[0091] 4. Generate build artifacts;
[0092] The mpfow build command can be used to build production-mode code from source code, where the code will be compressed and optimized.
[0093] Figure 5 This application illustrates a flowchart of a code processing method provided in an exemplary embodiment. This method can be executed by a computer device, which can be implemented as a terminal or server with mpflow installed. Figure 1 The terminal or server shown is, for example Figure 5 As shown, this code processing method may include the following steps:
[0094] Step 510: Obtain at least two types of main body modules, which correspond to the main program files in the source code.
[0095] In this embodiment, the source code may include both main program files and page program files. The source code of the mini-program includes an app (main) part describing the overall program and multiple page (page) parts describing their respective pages. The main part of a mini-program may consist of at least two main files. Schematic, the at least two main files may include an app.js file (used to explain the mini-program logic), an app.json file (used to explain the mini-program's common configuration), and an app.wxss file (used to explain the mini-program's common style sheet). The page part of a mini-program may consist of at least two page files. Schematic, the at least two page files may include a js file (used to explain the page logic), a wxml file (used to explain the page structure), a json file (used to explain the page configuration), and a wxss file (used to explain the page style sheet).
[0096] Step 520: Generate a first virtual module associated with a subject module of at least two subject types.
[0097] In this embodiment of the application, mpflow may include at least one loader. The loader is used to preprocess the imported module (file) and to convert a piece of code into another piece of code of the required type. Different types of loaders can be set based on different code conversion requirements.
[0098] Computer devices can invoke the first loader in mpflow to associate the program body files in body modules of at least two body types and generate a first virtual module; this first loader can be implemented as app-loader. Figure 6 This application shows a schematic diagram illustrating the function of an app-loader in an exemplary embodiment, as follows: Figure 6 As shown, the main program files in the app.js module, the app.json module, and the app.wxss module are input into app-loader to obtain the first virtual module 610 output by app-loader, namely app-loader!app.js module. The first virtual module 610 has reference relationships with app.js module 620, app.json module 630, and app.wxss module 640, respectively.
[0099] In this embodiment of the application, the source code can be a code file compiled based on a first type of compilation language, or the source code file can be a code file compiled based on a second type of compilation language, wherein the second type of compilation language is the compilation language corresponding to the build artifacts output by mpflow; illustratively, the first type of compilation language is a non-mini-program compilation language, and the second type of compilation language is a mini-program compilation language.
[0100] In response to the fact that the source code is a code file compiled based on a first-type compiled language, when generating the first virtual module, the computer device can call the first loader to convert the program body file in the body module of at least two body types into a body transformation file; the body transformation file is a code file compiled based on a second-type compiled language;
[0101] The first loader is invoked to associate the main conversion files in the main modules of at least two main types, and a first virtual module is generated.
[0102] In other words, after the first loader converts the code files in the main module that are compiled based on the first type of compilation language into code files that are compiled based on the second type of compilation language, the first virtual module is generated based on the main modules of at least two main types corresponding to the converted code files compiled in the second type of compilation language. For example, ts type code files can be converted into js type code files, less type and cess type code files can be converted into wxss type code files, and so on.
[0103] Step 530: Obtain page modules of at least two page types, which correspond to program page files in the source code.
[0104] Step 540: Generate a second virtual module associated with page modules of at least two page types.
[0105] A computer device can invoke a second loader in mpflow to associate program page files in page modules of at least two page types, generating a second virtual module. This second loader can be implemented as a page-loader, which can input program page files from the page.js module, page.json module, page.wxml module, and page.wxss module into the page-loader, obtaining the second virtual module page-loader! page.js output by the page-loader. This second virtual module has reference relationships with the page.js, page.json, page.wxml, and page.wxss modules, respectively. For example, this second loader associates program page files in the pages / index / index.js, pages / index / index.json, pages / index / index.wxml, and pages / index / index.wxss modules, generating the second virtual module page-loader! / pages / index / index.
[0106] In response to the source file being a code file compiled based on a first-type compiler language, when generating the second virtual module, the computer device can invoke a second loader to convert program page files in page modules of at least two page types into page conversion files; these page conversion files are code files compiled based on a second-type compiler language.
[0107] The second loader is invoked to associate page transformation files in at least two types of page modules and generate a third virtual module.
[0108] Step 550: Using the first virtual module as the input starting point, construct a dependency graph based on the first virtual module and the second virtual module; the dependency graph includes the reference relationships between the first virtual module and at least two types of subject modules, and the reference relationships between the third virtual module and at least two types of page modules.
[0109] In this embodiment of the application, in response to the fact that the subject module of at least two subject types includes a target subject module, the target subject module is a subject module with a target subject type; the computer device can call a third loader to perform compilation format conversion on the source code file in the target subject module to generate a third virtual module; the compilation format conversion refers to converting the first compilation format into the second compilation format.
[0110] Since file references in a mini-program project are stored in JSON files (e.g., the app file references page files in the app.json file), and mini-program projects lack require / import statements, they cannot be read by mplow. Therefore, the code in the JSON file needs to be compiled and converted so that mplow can read and process it. Thus, the target module can be the app.json module. Figure 7 This illustration shows a schematic diagram of the compilation format conversion of the source code file in app.json, as shown in an exemplary embodiment of this application. Figure 7 As shown, the source code files in the app.json module are compiled based on the first compilation format, i.e., the dependency declaration format. Based on the third loader, i.e., app-json-loader in mplow, the first compilation format is converted into the second compilation format, i.e., the reference format, to obtain the third virtual module 710. This third virtual module is represented as: app-json-loader! app.json.
[0111] After obtaining the third virtual module, the computer device constructs a dependency graph starting from the first virtual module by establishing reference relationships between the third virtual module and the first virtual module, as well as between the third virtual module and the second virtual module.
[0112] In this embodiment of the application, in response to the fact that a target page module is included in a page module of at least two page types, the computer device can call a fourth loader to perform compilation format conversion on the target page module and generate a fourth virtual module; compilation format conversion refers to converting the first compilation format into the second compilation format.
[0113] The target page module can be the page.json module, and the fourth loader can be page-json-loader in mpflow. The fourth loader converts the source code in the page.json module from dependency declaration format to reference format, enabling mpflow to read the code content and generate a fourth virtual module. For example, when the page.json module is pages / index / index.json, the fourth virtual module can be represented as: page-json-loader! pages / iindex / index.json.
[0114] After obtaining the fourth virtual module, the computer device can construct the reference relationship between the fourth virtual module and the second virtual module to generate the dependency graph.
[0115] Step 560: Output at least two subject construction artifacts corresponding to the source code based on the dependency graph. The at least two subject construction artifacts correspond one-to-one with at least two subject types. The subject construction artifacts contain subject modules of the corresponding subject types.
[0116] In one possible implementation, the dependency graph can be segmented based on module type to obtain two module combinations; the two module combinations include a first module combination corresponding to main modules of at least two main types, and a second module combination corresponding to page modules of at least two page types.
[0117] Figure 8 A schematic diagram of a dependency graph provided in an exemplary embodiment of this application is shown, such as... Figure 8 As shown, the dependency graph includes a first virtual module 810, a second virtual module 820, a third virtual module 830, and a fourth virtual module 840. It also includes main modules and / or page modules that reference each virtual module, as well as identifiers to show the reference relationships between modules, i.e., directional arrows in the diagram. Based on the type of each module, the dependency graph can be divided into two module combinations. For example, module combinations can be based on different loader processing types, such as app-loader and page-loader. The number of module combinations in each combination can be different. For example, a mini-program contains one main part and multiple page parts; therefore, the first module combination can have one element, and the second module combination can have multiple elements. Figure 8 The following example illustrates the dependency graph, which contains a first module combination 850 and a second module combination 860. However, there is no limit to the number of first and second module combinations. For illustration purposes, the first module combination can be called a Chunk App, and the second module combination can be called a Chunk Index.
[0118] When outputting at least two main body build artifacts corresponding to the source code, the output of at least two main body build artifacts corresponding to the source code can be based on the first module combination.
[0119] In this embodiment of the application, at least two page build artifacts corresponding to the source code can also be output. This process can be implemented as follows:
[0120] Based on the second module combination, output at least two page build artifacts corresponding to the source code; the at least two page build artifacts correspond one-to-one with at least two page types; the page build artifacts contain page modules of the corresponding page types.
[0121] Taking the combination of the first module as an example, outputting at least two main building artifacts corresponding to the source code, Figure 9 A schematic diagram illustrating the output entity construction product of an exemplary embodiment of this application is shown, such as... Figure 9 As shown, each subject type corresponds to a subject build artifact. Specifically, the subject module with subject type js outputs app.js subject build artifact 910, the subject module with subject type json outputs app.json subject build artifact 920, and the subject module with subject type wxss outputs app.wxss subject build artifact 930. When outputting app.js subject build artifact 910 for the subject module with subject type js, an app.js subject build artifact containing reference relationships can be generated based on the first and third virtual modules generated during dependency analysis, so as to facilitate the subsequent application of subject build artifacts.
[0122] In the embodiments of this application, at least two main build artifacts include build artifacts with compilation formats of js, json and wxss respectively;
[0123] At least two page build artifacts include build artifacts in compiled formats of js, json, wxss, and wxml, respectively.
[0124] In summary, the code processing method provided in this application generates a first type of virtual module associated with various types of main files, and uses this first type of virtual module as the input starting point to construct a dependency graph based on the reference relationships between the modules. Based on this dependency graph, it obtains and outputs at least two main construction artifacts corresponding to the source code. This allows for the automatic construction of mini-program projects with the help of construction tools during the source code processing process, improving the efficiency of source code processing. At the same time, since the code dependencies between the modules are fully considered during the construction process, the construction effect of the project corresponding to the source code is improved.
[0125] When executing the code processing method provided in this application, the path processing logic needs to be configured, including module lookup, loader lookup, resource lookup, and resource output. mpflow includes a path processing module. Taking the processing of the source files of a mini-program as an example, the path processing module is obtained by modifying the internal process based on the mini-program's path processing logic, so that the path parsing of the path processing module conforms to the mini-program's path logic. For illustration, the internal process can be modified through plugins. The mini-program path logic includes: the root path of the mini-program is the working path; the directory can be specified in package.json via the miniprogram field, where package.json is a file in the root directory of the mini-program project, defining the various modules required by the project, as well as the project's configuration information, such as name, project, license, and other metadata; by default, the miniprogran_dist directory of the npm package manager (Node Package Manager) is read; modules outside the path where the app is located need to be output to the miniprogran_npm directory.
[0126] Paths are categorized into: absolute paths, relative paths, and module paths.
[0127] Figure 10 The illustration shows a schematic diagram of the mpflow path processing flow as shown in an exemplary embodiment of this application, such as... Figure 10 As shown, the path resolution module in mpflow, within the overall mpflow processing flow, includes the following resolve process:
[0128] S1001 triggers the resolve event.
[0129] S1002, check if there is a replacement name in the file path. If there is, proceed to S1003; otherwise, proceed to S1004.
[0130] S1003, replace the file path with the replacement name, then execute S1004.
[0131] S1004, determine whether the target path is a module path; if so, proceed to step S1005, otherwise, proceed to step S1010.
[0132] For file paths that have not undergone name replacement, the target path is the file path itself; for file paths that have undergone name replacement, the target path is the path obtained after the replacement.
[0133] S1005, search for node_modules in the module path.
[0134] Check if a file or folder exists in the path relative to the current module. If it is a file, load it directly; if it is a folder, continue searching.
[0135] S1006, look for fs / package.json in node_modules.
[0136] S1007, find the miniprogram file path in package.json.
[0137] S1008, find the main path in package.json.
[0138] If no corresponding path or file is found in any step from S1006 to S1008, return to the parent directory to search again; if the target path is still not found after repeating the above query process a specified number of times, it means that the target path cannot be found based on the module path, and then execute S1009.
[0139] If the target path is found based on S1005 to S1008, then return to step S1002.
[0140] S1009, treat the target path as a relative path.
[0141] S1010: Determine if the target path is the root path. If yes, execute S1011; otherwise, execute S1012.
[0142] S1011, add the root path of the mini program, and after converting it into a mini program workspace, execute S1012.
[0143] S1012, determine whether the target path is a relative path. If yes, execute S1013; otherwise, execute the parsing process.
[0144] S1013, after converting the target path to an absolute path, execute the parsing process.
[0145] Figure 11 This is a block diagram of a code processing apparatus provided in an exemplary embodiment of this application, such as... Figure 11 As shown, the device includes:
[0146] The first acquisition module 1110 is used to acquire at least two types of main modules, wherein the main modules correspond to the program main files in the source code;
[0147] The first generation module 1120 is used to generate a first virtual module associated with the subject modules of the at least two subject types;
[0148] The dependency graph construction module 1130 is used to construct a dependency graph with the first virtual module as the input starting point; the dependency graph contains the reference relationship between the first virtual module and the main modules of the at least two main types;
[0149] The main body construction product output module 1140 is used to output at least two main body construction products corresponding to the source code based on the dependency graph. The at least two main body construction products correspond one-to-one with the at least two main body types. The main body construction products contain main body modules of the corresponding main body types.
[0150] In one possible implementation, the device further includes:
[0151] The second acquisition module is used to acquire page modules of at least two page types, wherein the page modules correspond to program page files in the source code;
[0152] The second generation module is used to generate a second virtual module associated with the page modules of the at least two page types;
[0153] The dependency graph construction module 1130 is used to construct the dependency graph based on the first virtual module and the second virtual module, with the first virtual module as the input starting point. The dependency graph includes the reference relationship between the first virtual module and the main modules of the at least two main types, and the reference relationship between the third virtual module and the page modules of the at least two page types.
[0154] In one possible implementation, the device further includes:
[0155] The combination acquisition module is used to segment the dependency graph based on module type to obtain two module combinations; the two module combinations include a first module combination corresponding to the main modules of at least two main types, and a second module combination corresponding to the page modules of at least two page types;
[0156] The main body build product output module 1140 is used to output at least two main body build products corresponding to the source code based on the first module combination.
[0157] In one possible implementation, the device further includes:
[0158] The page build product output module is used to output at least two page build products corresponding to the source code based on the combination of the second module; the at least two page build products correspond one-to-one with the at least two page types; the page build products contain page modules of the corresponding page types.
[0159] In one possible implementation, the first generation module 1120 is used to call the first loader to associate the program body files in the body modules of the at least two body types to generate the first virtual module.
[0160] In one possible implementation, the second generation module is used to call the second loader to associate the program page files in the page modules of the at least two page types and generate the second virtual module.
[0161] In one possible implementation, a target subject module is included in the subject module corresponding to at least two subject types, the target subject module being a subject module having a target subject type; the apparatus further includes:
[0162] The third generation module is used to call the third loader to perform compilation format conversion on the source code files in the target main module and generate a third virtual module; the compilation format conversion refers to converting the first compilation format to the second compilation format.
[0163] The dependency graph construction module 1130 is used to establish the reference relationship between the third virtual module and the first virtual module, and the reference relationship between the third virtual module and the second virtual module, so as to construct the dependency graph;
[0164] The first compilation format includes a dependency declaration format, and the second compilation format includes a reference format.
[0165] In one possible implementation, in response to a page module containing a target page module of at least two page types, the apparatus further includes:
[0166] The fourth generation module is used to call the fourth loader to perform compilation format conversion on the target page module and generate the fourth virtual module; the compilation format conversion refers to converting the first compilation format into the second compilation format;
[0167] The dependency graph construction module 1130 is used to establish the reference relationship between the fourth virtual module and the second virtual module to construct the dependency graph;
[0168] The first compilation format includes a dependency declaration format, and the second compilation format includes a reference format.
[0169] In one possible implementation, in response to the source file being a code file compiled based on a first type of compiled language, the first generation module 1120 includes:
[0170] The first conversion submodule is used to call the first loader to convert the program body files in at least two body types of body modules into body conversion files; the body conversion files are code files compiled based on the second type of compilation language.
[0171] The first generation submodule is used to call the first loader to associate the subject transformation files in the subject modules of at least two subject types and generate the first virtual module.
[0172] In one possible implementation, in response to the source file being a code file compiled based on a first type of compiled language, the second generation module includes:
[0173] The second conversion submodule is used to call the second loader to convert program page files in page modules of at least two page types into page conversion files; the page conversion files are code files compiled based on the second type of compilation language.
[0174] The second generation submodule is used to call the second loader to associate the page conversion files in at least two types of page modules and generate the third virtual module.
[0175] In one possible implementation, the first type of compiled language is a non-mini-program compiled language, and the second type of compiled language is a mini-program compiled language.
[0176] In one possible implementation, the at least two main build artifacts include build artifacts with compilation formats of js, json and wxss, respectively;
[0177] The at least two page build artifacts include build artifacts in compiled formats of js, json, wxss and wxml respectively.
[0178] In summary, the code processing apparatus provided in this application generates a first type of virtual module associated with various types of main files, and uses this first type of virtual module as the input starting point to construct a dependency graph based on the reference relationships between the modules. Based on this dependency graph, it obtains and outputs at least two main construction artifacts corresponding to the source code. This allows for automated construction of mini-program projects with the help of construction tools during the source code processing process, improving the efficiency of source code processing. At the same time, since the code dependencies between the modules are fully considered during the architecture process, the construction effect of the project corresponding to the source code is improved.
[0179] Figure 12 This is a structural block diagram of a computer device 1200 according to an exemplary embodiment. The computer device 1200 may be a terminal in the embodiments of this application.
[0180] Typically, computer device 1200 includes a processor 1201 and a memory 1202.
[0181] Processor 1201 may include one or more processing cores, such as a quad-core processor, an octa-core processor, etc. Processor 1201 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). Processor 1201 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, processor 1201 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, processor 1201 may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.
[0182] The memory 1202 may include one or more computer-readable storage media, which may be non-transitory. The memory 1202 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In some embodiments, the non-transitory computer-readable storage media in the memory 1202 are used to store at least one instruction, which is executed by the processor 1201 to implement the method provided in the method embodiments of this application.
[0183] In some embodiments, the computer device 1200 may optionally include a peripheral device interface 1203 and at least one peripheral device. The processor 1201, memory 1202, and peripheral device interface 1203 can be connected via a bus or signal line. Each peripheral device can be connected to the peripheral device interface 1203 via a bus, signal line, or circuit board. Specifically, the peripheral device includes at least one of the following: a radio frequency circuit 1204, a display screen 1205, a camera assembly 1206, an audio circuit 1207, a positioning assembly 1208, and a power supply 1209.
[0184] In some embodiments, the computer device 1200 further includes one or more sensors 1210. The one or more sensors 1210 include, but are not limited to: an accelerometer 1211, a gyroscope 1212, a pressure sensor 1213, a fingerprint sensor 1214, an optical sensor 1215, and a proximity sensor 1216.
[0185] Those skilled in the art will understand that Figure 12 The structure shown does not constitute a limitation on the computer device 1200 and may include more or fewer components than shown, or combine certain components, or use different component arrangements.
[0186] Figure 13 This is a structural block diagram of a computer device 1300 according to an exemplary embodiment. This computer device can be implemented as the server described in the above-described scheme of this application.
[0187] The computer device 1300 includes a central processing unit (CPU) 1301, a system memory 1304 including random access memory (RAM) 1302 and read-only memory (ROM) 1303, and a system bus 1305 connecting the system memory 1304 and the CPU 1301. The computer device 1300 also includes a basic input / output system (I / O system) 1306 to facilitate information transfer between various components within the computer, and a mass storage device 1307 for storing the operating system 1313, application programs 1314, and other program modules 1315.
[0188] The basic input / output system 1306 includes a display 1308 for displaying information and an input device 1309 for user input, such as a mouse or keyboard. Both the display 1308 and the input device 1309 are connected to the central processing unit 1301 via an input / output controller 1310 connected to the system bus 1305. The basic input / output system 1306 may also include the input / output controller 1310 for receiving and processing input from multiple other devices such as a keyboard, mouse, or electronic stylus. Similarly, the input / output controller 1310 also provides output to a display screen, printer, or other types of output devices.
[0189] The mass storage device 1307 is connected to the central processing unit 1301 via a mass storage controller (not shown) connected to the system bus 1305. The mass storage device 1307 and its associated computer-readable media provide non-volatile storage for the computer device 1300. That is, the mass storage device 1307 may include computer-readable media (not shown) such as a hard disk or a compact disc read-only memory (CD-ROM) drive.
[0190] Without loss of generality, the computer-readable medium may include computer storage media and communication media. Computer storage media include volatile and non-volatile, removable and non-removable media implemented using any method or technology for storing information such as computer-readable instructions, data structures, program modules, or other data. Computer storage media include RAM, ROM, erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other solid-state storage technologies, CD-ROM, digital versatile disc (DVD) or other optical storage, magnetic tape cassettes, magnetic tape, disk storage, or other magnetic storage devices. Of course, those skilled in the art will recognize that the computer storage media are not limited to the above-mentioned types. The system memory 1304 and mass storage device 1307 described above can be collectively referred to as memory.
[0191] According to various embodiments of this disclosure, the computer device 1300 can also be connected to a remote computer on a network, such as the Internet. That is, the computer device 1300 can be connected to a network 1312 via a network interface unit 1311 connected to the system bus 1305, or it can use the network interface unit 1311 to connect to other types of networks or remote computer systems (not shown).
[0192] The memory further includes at least one instruction, at least one program, code set, or instruction set, which are stored in the memory. The central processing unit 1301 executes the at least one instruction, at least one program, code set, or instruction set to implement all or part of the steps in the code processing methods shown in the above embodiments.
[0193] In one exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory including at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, at least one program, code set, or instruction set can be executed by a processor to perform the above-described task. Figure 2 or Figure 5 All or part of the steps of the method shown in any embodiment. For example, the non-transitory computer-readable storage medium may be ROM, RAM, CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc.
[0194] In one exemplary embodiment, a computer program product or computer program is also provided, comprising 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 aforementioned actions. Figure 2 or Figure 5 All or part of the steps of the method shown in any embodiment.
[0195] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.
[0196] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.< / pluginname> < / pluginname> < / appname>
Claims
1. A code processing method, characterized in that, The method includes: Obtain at least two types of main modules, where each main module corresponds to a program main file in the source code; Generate a first virtual module associated with the subject modules of the at least two subject types; Obtain page modules of at least two page types, wherein the page modules correspond to program page files in the source code; Generate a second virtual module associated with the page modules of the at least two page types; Starting from the first virtual module, a dependency graph is constructed based on the first virtual module and the second virtual module. The dependency graph includes the reference relationship between the first virtual module and the main modules of the at least two main types, and the reference relationship between the second virtual module and the page modules of the at least two page types. Based on the dependency graph, output at least two main body construction products corresponding to the source code, and the at least two main body construction products correspond one-to-one with the at least two main body types; the main body construction products contain main body modules of the corresponding main body types.
2. The method according to claim 1, characterized in that, The method further includes: The dependency graph is segmented based on module type to obtain two module combinations; the two module combinations include a first module combination corresponding to the main modules of at least two main types, and a second module combination corresponding to the page modules of at least two page types. The step of outputting at least two main build artifacts corresponding to the source code based on the dependency graph includes: Based on the first module combination, at least two main building artifacts corresponding to the source code are output.
3. The method according to claim 2, characterized in that, The method further includes: Based on the second module combination, at least two page construction products corresponding to the source code are output; the at least two page construction products correspond one-to-one with the at least two page types; the page construction products contain page modules of the corresponding page types.
4. The method according to claim 1, characterized in that, The generation of a first virtual module associated with the subject modules of the at least two subject types includes: The first loader is invoked to associate the program main files in the main modules of the at least two main types to generate the first virtual module.
5. The method according to claim 1, characterized in that, The generation of the second virtual module associated with the page modules of the at least two page types includes: The second loader is invoked to associate the program page files in the page modules of the at least two page types, thereby generating the second virtual module.
6. The method according to claim 1, characterized in that, In response to a target subject module being included in a subject module of at least two subject types, wherein the target subject module is a subject module having a target subject type; the construction of the dependency graph, starting from the first virtual module and based on the first virtual module and the second virtual module, includes: A third loader is invoked to perform compilation format conversion on the source code files in the target main module, generating a third virtual module; the compilation format conversion refers to converting the first compilation format to the second compilation format. Establish the reference relationship between the third virtual module and the first virtual module, and the reference relationship between the third virtual module and the second virtual module, to construct the dependency graph; The first compilation format includes a dependency declaration format, and the second compilation format includes a reference format.
7. The method according to claim 1, characterized in that, In response to a page module containing a target page module in at least two page types, the construction of the dependency graph, starting from the first virtual module and based on the first virtual module and the second virtual module, includes: The fourth loader is invoked to perform compilation format conversion on the target page module, generating a fourth virtual module; the compilation format conversion refers to converting the first compilation format to the second compilation format. Establish a reference relationship between the fourth virtual module and the second virtual module to construct the dependency graph; The first compilation format includes a dependency declaration format, and the second compilation format includes a reference format.
8. The method according to claim 4, characterized in that, In response to the source code being a code file compiled based on a first type of compiled language, the invocation of the first loader to associate the program body files in the body modules of the at least two body types and generate the first virtual module includes: The first loader is invoked to convert the program body files in the body modules of at least two body types into body conversion files; the body conversion files are code files compiled based on the second type of compilation language. The first loader is invoked to associate the subject transformation files in the subject modules of at least two subject types, thereby generating the first virtual module.
9. The method according to claim 5, characterized in that, In response to the source code being a code file compiled based on a first type of compiled language, the invocation of the second loader, associating the program page files in the page modules of the at least two page types, and generating the second virtual module, includes: The second loader is invoked to convert program page files in page modules of at least two page types into page conversion files; the page conversion files are code files compiled based on a second type of compilation language. The second loader is invoked to associate the page conversion files in at least two types of page modules and generate the second virtual module.
10. The method according to claim 8 or 9, characterized in that, The first type of compiled language is a non-mini-program compiled language, and the second type of compiled language is a mini-program compiled language.
11. The method according to claim 3, characterized in that, The at least two main build artifacts include build artifacts with compilation formats of js, json and wxss respectively; The at least two page build artifacts include build artifacts in compiled formats of js, json, wxss and wxml respectively.
12. A code processing device, characterized in that, The device includes: The first acquisition module is used to acquire at least two types of main modules, wherein the main modules correspond to the program main files in the source code; A first generation module is used to generate a first virtual module associated with the subject modules of the at least two subject types; The second acquisition module is used to acquire page modules of at least two page types, wherein the page modules correspond to program page files in the source code; The second generation module is used to generate a second virtual module associated with the page modules of the at least two page types; A dependency graph construction module is used to construct a dependency graph based on the first virtual module and the second virtual module, with the first virtual module as the input starting point. The dependency graph includes the reference relationship between the first virtual module and the main modules of the at least two main types, and the reference relationship between the second virtual module and the page modules of the at least two page types. The main body build product output module is used to output at least two main body build products corresponding to the source code based on the dependency graph. The at least two main body build products correspond one-to-one with the at least two main body types. The main body build products contain main body modules of the corresponding main body types.
13. A computer device, characterized in that, The computer device includes a processor and a memory, the memory storing at least one computer program, which is loaded and executed by the processor to implement the code processing method as described in any one of claims 1 to 11.
14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one computer program, which is loaded and executed by a processor to implement the code processing method as described in any one of claims 1 to 11.
Citation Information
Patent Citations
Employing Dependency Graph in Software Build Projects
US20160253625A1
Application development method, tool, and device, and storage medium
US20190310835A1