Code automatic generation method and device based on command line, equipment and storage medium
Through the automatic code generation method based on command line, the problems of high development threshold and strong coupling of code files in low-code platforms are solved, efficient and flexible list page development is achieved, and development efficiency and code adaptability are improved.
Patent Information
- Application Number
- CN202411137550.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-19
- Publication Date
- 2024-12-10
AI Technical Summary
In low-code platforms, when developing list pages and details pages, reference documents are required to successfully generate components, resulting in high development thresholds and inability to make minor adjustments. The generated code files are strongly coupled with the project environment and cannot be shared between different projects .
Through the automatic code generation method based on the command line, the input data is obtained automatically configure the project configuration file, the interface document data is obtained, and the target code file is generated using preset services to realize the automatic generation of list pages, which has good expansion and independence.
It lowers the development threshold, improves development efficiency, allows for continued encoding on local files, and is not limited to the low-code platform, achieving flexible adaptability and commonality of the code.
Smart Images

Figure CN119105744A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a command line-based automatic code generation method, device, equipment and storage medium. Background Art
[0002] In the daily development process of the front-end management system, the more common development task is the development of list pages and detail pages with simple add, delete, modify and query functions. There is a lot of repetitive work in the above development process. In order to improve the development efficiency of list pages and detail pages in the front-end management system, low-code technology is introduced.
[0003] In the current low-code platform, the low-code components are first compiled and then generated through configuration files and template engines. In the existing component management process, when a component needs to be changed, the configuration file needs to be modified to update the low-code component. The above implementation process has the following defects:
[0004] 1) When developing components, you must carefully refer to the documentation to successfully generate the components, and the development threshold is high;
[0005] 2) It can only support the interaction modes that have been developed in the generator and cannot make subtle adjustments;
[0006] 3) The work of developing components can only be based on a unified generator project, which is not conducive to parallel development.
[0007] That is, in the face of complex page interactions, after the code file is generated, you still need to modify the code yourself, and it cannot be used out of the box. Moreover, the directory of the code file generated in the low-code platform is strongly coupled with the code directory of the project environment. Code files cannot be shared between different projects, but the code files of the previous project need to be manually adjusted to adapt to the new project. Summary of the invention
[0008] The embodiments of the present invention provide a command line-based automatic code generation method, device, equipment and storage medium, which aims to solve the problem that in the prior art, when developing list pages and detail pages in a low-code platform, the low-code components are first compiled, and the components are generated through configuration files and template engines. The above component development process requires reference to documents before the components can be successfully generated, which has a high development threshold and leads to low development efficiency.
[0009] In a first aspect, an embodiment of the present invention provides a method for automatically generating code based on a command line, which includes:
[0010] Acquire input data, and automatically configure the initial project configuration file according to the input data to obtain the project configuration file; wherein the input data at least includes an interface document address;
[0011] Acquire a target application program interface corresponding to the interface document address, and acquire data required for the list page from the corresponding interface document platform based on the target application program interface;
[0012] Based on the command line in the preset service, the project configuration file, the data required for the list page and the preset code template, generate a target code file corresponding to the data required for the list page; wherein the preset service is used to run the command line to generate the code file accordingly;
[0013] A target list page is generated based on the target code file.
[0014] In a second aspect, an embodiment of the present invention further provides a command line-based automatic code generation device, which includes:
[0015] A project configuration file acquisition unit, used to acquire input data, and automatically configure the initial project configuration file according to the input data to obtain the project configuration file; wherein the input data at least includes an interface document address;
[0016] A list page data acquisition unit, used to acquire a target application program interface corresponding to the interface document address, and acquire data required for the list page from a corresponding interface document platform based on the target application program interface;
[0017] A target code file generating unit, configured to generate a target code file corresponding to the data required by the list page based on a command line in a preset service, the project configuration file, the data required by the list page, and a preset code template; wherein the preset service is configured to run a command line to generate a corresponding code file;
[0018] The target list page generating unit is used to generate a target list page based on the target code file.
[0019] In a third aspect, an embodiment of the present invention further provides a computer device, which includes a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the method described in the first aspect is implemented.
[0020] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the method described in the first aspect above can be implemented.
[0021] The embodiments of the present invention provide a command line-based automatic code generation method, apparatus, device and storage medium, the method comprising: obtaining input data, and automatically configuring an initial project configuration file according to the input data to obtain a project configuration file; obtaining a target application interface corresponding to the interface document address, and obtaining the data required for the list page from the corresponding interface document platform based on the target application interface; generating a target code file corresponding to the data required for the list page based on the command line in the preset service, the project configuration file, the data required for the list page and a preset code template; generating a target list page based on the target code file. The embodiments of the present invention can generate pages through command lines, which not only has good scalability, but also allows coding to continue directly on local files without being limited by low-code platforms. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying any creative work.
[0023] Figure 1 A schematic diagram of an application scenario of the command line-based automatic code generation method provided by an embodiment of the present invention;
[0024] Figure 2 A schematic diagram of a flow chart of a command line based automatic code generation method provided by an embodiment of the present invention;
[0025] Figure 3 A schematic diagram of a sub-flow diagram of a command line-based automatic code generation method provided by an embodiment of the present invention;
[0026] Figure 4 A schematic block diagram of a command line based code automatic generation device provided by an embodiment of the present invention;
[0027] Figure 5 A schematic block diagram of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0028] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0029] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.
[0030] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0031] It should be further understood that the term "and / or" used in the present description and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0032] Please also refer to Figure 1 and Figure 2 ,in Figure 1 Schematic diagram of a scenario of a command line-based automatic code generation method according to an embodiment of the present invention. Figure 2 FIG. 1 is a flow chart of a method for automatically generating code based on a command line provided by an embodiment of the present invention. Figure 1 As shown, the command line-based automatic code generation method provided in the embodiment of the present invention is applied to a server 10 , and the server 10 is communicatively connected to a user terminal 20 .
[0033] like Figure 2 As shown, the method includes the following steps S110-S140.
[0034] S110 , obtaining input data, and automatically configuring the initial project configuration file according to the input data to obtain a project configuration file.
[0035] Wherein, the input data at least includes the interface document address.
[0036] In the present embodiment, the technical solution is described with the server as the execution subject. After the user terminal establishes a communication connection with the server, if the user interface of the system is automatically generated by the code corresponding to the server, it is displayed on the user terminal. At this time, the user operates the user terminal to send input data to the server in a variety of data formats, for example, the input data of JS file format (i.e., the file format of JavaScript code), TXT file format (i.e., text file format), JSON file format (i.e., JS object notation file format) can be sent to the server, and at least the interface document address is set in the input data, and the file name and file path can also be set. Of course, the input data is not limited to only including the data in the above examples, but also can include other data of more dimensions, which will not be listed in detail here.
[0037] After the input data is obtained by the server, the initial project configuration file is first obtained in the automatic code generation system, and then the content included in the input data is automatically filled into the initial project configuration file for automatic configuration, thereby obtaining the project configuration file. Among them, the initial project file is the initial project configuration file related to the user's project to be developed. It is a file that has been configured in the initial stage of the project to be developed. It corresponds to the needs of the project to be developed and can flexibly adapt to the needs of different projects.
[0038] In one embodiment, the input data also includes table lists, enumeration values, and search forms; Figure 3 As shown, step S110 includes:
[0039] S111, obtaining the API list subfile, the table list subfile, the enumeration value subfile and the search form subfile in the initial project configuration file;
[0040] S112. Fill the file name, the file path and the interface document address into the api list sub-file, fill the table list into the table list sub-file, fill the enumeration value into the enumeration value sub-file, fill the search form into the search form sub-file, and obtain the project configuration file.
[0041] In this embodiment, if the data included in the input data and the initial project configuration file are both in JS file format, the initial project configuration file is recorded as dataConfig.js file. The subfiles that need to be automatically configured based on the input data in the initial project configuration file include URL address subfile (recorded as url subfile), route name subfile (recorded as routerTitle subfile), route path subfile (recorded as routePath subfile), api list subfile (recorded as apiList subfile), table list subfile (recorded as tableList subfile), enumeration value subfile (recorded as optionList subfile) and search form subfile (recorded as form subfile).
[0042] Among them, in the url sub-file, the third-level directory needs to be automatically entered based on the file location of the initial project configuration file (for example, "url:taskCenter / dailyTask / dailyTaskList"), and the index.vue file (that is, a single-file component, which includes templates, scripts, styles and other information) will be generated under the first preset path such as src / ${url}.
[0043] In the routerTitle sub-file, you can directly fill it based on the route name (for example, the route name is "dailyTaskList"), and in the routePath sub-file, you can directly fill it based on the route path (for example, the route path is "Daily Tasks").
[0044] The apiList sub-file is filled with the file name, file path, and interface document address in the input data. For example, the filled apiList sub-file is as follows:
[0045] apiList:[{
[0046] apiName:"getTestList1", / / Method name referenced by the interface
[0047] apiUrl:" / privileged / service / brand / promotion / pageList", / / Interface path
[0048] apiDescription: "Test api3", / / Interface comments
[0049] docLink:"https: / / apidoc.oa.fenqile.com" / / Interface document link
[0050] }]
[0051] That is, the input data may also include interface comments, and the populated apiList sub-file may also include the interface comments.
[0052] In the tableList subfile, it is mainly necessary to enter table data (i.e., tableData), attribute name status, display name status, and conversion identification value. In one embodiment, the process of filling the table list into the table list subfile includes:
[0053] Get the table component column attribute name and the table component column display name to form table data;
[0054] Acquire the attribute name status, display name status and conversion identification value; wherein the conversion identification value is an identification value used to determine whether the field value in the table data needs to be converted to enumeration data;
[0055] The table data, the attribute name status, the display name status and the conversion identification value are combined into the table list and filled into the table list sub-file.
[0056] In this embodiment, the prop attribute of el-table-column (i.e., the table component column attribute name, el-table represents the table component, el-table-column represents a column of the table component, the prop attribute is used to specify the attribute name of the column bound data list, and the label attribute of el-table-column (i.e., the table component column display name) are first obtained, so that the table component column attribute name and the table component column display name are used to form the table data. Then, the attribute name status, display name status and conversion identification value are obtained (its value is true or false, when the value is true, it means that all field values in the table data need to be converted to enumeration data, and when the value is false, it means that all field values in the table data do not need to be converted to enumeration data); finally, the table data, the attribute name status, the display name status and the conversion identification value are combined into the table list and filled into the table list sub-file to complete the update of the table list sub-file.
[0057] For example, the table list subfile that completes data filling is as follows:
[0058] tableData:[{
[0059] prop:"followers", / / prop attribute of el-table-column
[0060] label:"Test followers" / / label attribute of el-table-column
[0061] },{
[0062] prop:"status",
[0063] label:"test status",
[0064] isNeedTransform:true / / Determine whether enumeration data conversion is required in the table data, which needs to be used together with the subsequent optionList
[0065] }]
[0066] Among them, prop:"status" indicates the property name status, label:"test status" indicates the display name status, and isNeedTransform:true indicates the conversion identification value.
[0067] In the optionList subfile, multiple enumeration values need to be entered, and each enumeration value has an enumeration value type and an enumeration value mapping value. In one embodiment, the enumeration value is filled into the enumeration value subfile, including:
[0068] Obtain several enumeration values and the enumeration value type and enumeration value mapping value corresponding to each enumeration value, and fill them into the enumeration value subfile.
[0069] In this embodiment, for example, one of the enumeration values of the optionList sub-file is as follows:
[0070] {
[0071] value:0, / / enumeration value
[0072] type:'number', / / enumeration value type
[0073] label:'Initialize 1234' / / enumeration value mapping value
[0074] }
[0075] In the above example, it represents an enumeration value with a value of 0, its enumeration value type is number, and the enumeration value mapping value is initialized to 1234.
[0076] In the form sub-file, multiple search sub-forms need to be entered, and each search sub-form includes the attribute name of the search form component, the display name of the search form component, and the form component type of the search form component. In one embodiment, the step of filling the search form into the search form sub-file includes:
[0077] A plurality of search subforms and the attribute name, display name and form component type corresponding to each search subform are obtained, and filled into the search form subfile.
[0078] In this embodiment, for example, one of the search subforms in the form subfile is as follows:
[0079] {
[0080] prop:"dailyReceiveActivityId", / / prop attribute of el-form-item
[0081] label:"Test activity ID", / / label attribute of el-form-item
[0082] type:"input" / / The form component type in el-form-item, and the form component type is selected from input|select|date
[0083] }
[0084] In the above example, it means that the attribute name of the search subform is dailyReceiveActivityId, the display name is the test activity ID, and the form component type is input (ie, input).
[0085] Once the file name, the file path and the interface document address are filled into the api list sub-file, the table list is filled into the table list sub-file, the enumeration value is filled into the enumeration value sub-file, and the search form is filled into the search form sub-file, the project configuration file can be quickly obtained.
[0086] S120: Acquire a target application program interface corresponding to the interface document address, and acquire data required for the list page from a corresponding interface document platform based on the target application program interface.
[0087] In this embodiment, after the acquisition of the project configuration file is completed, the target application interface and the corresponding interface document platform can be determined based on the interface document address included in the api list subfile (such as / privileged / service / brand / promotion / pageList), and then the server obtains the data required for the list page from the corresponding interface document platform based on the target application interface. Among them, the data required for the list page includes a mapping relationship of list attributes, which can be used as the core data for generating the target list page. Moreover, the data structure corresponding to the data required for the list page is helpful to dynamically generate code that adapts to actual business needs (that is, the process of generating code can dynamically adapt to changes in the interface and can cope with changing business needs). Of course, at this time, the data required for the list page cannot be directly used for visual display, and it still needs to be processed by automatic code generation.
[0088] S130: Generate a target code file corresponding to the data required for the list page based on a command line in a preset service, the project configuration file, the data required for the list page, and a preset code template.
[0089] In this embodiment, the preset service can be a Node service, and a scaffolding task (such as plop.js) can also be created in the Node service, and then a command line can be run in the scaffolding task (such as the command line corresponding to the Node service is a Node command) to generate a target code file corresponding to the data required for the list page based on the project configuration file, the data required for the list page and the preset code template. Moreover, the target code file is generated and saved in the directory corresponding to the project configuration file. It can be seen that based on the above method, code generation is realized through the command line, so that developers can complete the basic structure of complex pages through simple commands.
[0090] In one embodiment, before step S130, the method further includes:
[0091] Create initial scaffolding tasks;
[0092] In the initial scaffolding task, generator parameters are created accordingly, and modules, list pages and detail pages are generated accordingly based on the generator parameters to complete the creation of the preset service.
[0093] In this embodiment, when creating a preset service based on a scaffolding task, an initial scaffolding task with a parameter of an empty value is first created (such as based on the instruction npminstallplop-save-g), and then a generator parameter is created in the initial scaffolding task (such as based on the instruction npm run plop generator--param[VALUE] to create a generator (addModule, addChildModule, list, view)), and based on the generator parameter, a module is generated (such as based on the instruction npm run plop addModule "taskCenter" "taskCenter" "task center"), a list page (such as based on the instruction npm runplop list) and a details page (such as based on the instruction npm runplop view) to complete the creation of the preset service. It can be seen that after creating the preset service configured by the scaffolding task, the code file can be directly generated by using the command line and the configuration file to improve the development efficiency of the page.
[0094] In one embodiment, before step S130, the method further includes:
[0095] Creating an initial request file, and storing the api list sub-file in the initial request file to obtain a current request file;
[0096] Generate a single file component and a copy of the current requested file at a corresponding first preset path based on the url subfile in the project configuration file;
[0097] adding the current request file, the single file component and the current request file copy to the project configuration file to update the project configuration file;
[0098] After step S130, the method further includes:
[0099] The target code file is stored in the path file corresponding to the routePath subfile in the project configuration file.
[0100] In this embodiment, specifically, the initial request file common / request.js is first created, and then the file name, the file path and the interface document address in the api list subfile are saved in the common / request.js file, thereby obtaining the current request file.
[0101] Then, based on the url sub-file in the project configuration file, a single file component (i.e., index.vue file) is generated under the corresponding first preset path, and a copy of the current request file is generated at the same time (which can be understood as having the same data as the current request file and copied from the current request file). The obtained current request file, the single file component, and the copy of the current request file are correspondingly added to the project configuration file to update the project configuration file.
[0102] Finally, running a command line (such as npm runplop view) can generate a target code file corresponding to the data required by the list page based on the project configuration file, the data required by the list page, and the preset code template, and store the target code file in the path file corresponding to the routePath subfile in the project configuration file. It can be seen that the above code generation and saving actions are all automatic, without manual operation.
[0103] S140: Generate a target list page based on the target code file.
[0104] In this embodiment, after the target code file is generated in the preset service based on the command line, project configuration file, data required for the list page and code template, since the target code file is generated and saved in the directory corresponding to the project configuration file, the target list page can be generated based on the target code file from the directory, thereby realizing automatic generation of the page.
[0105] It can be seen that the implementation example of the method can generate pages through the command line, which not only has good scalability, but also can continue encoding directly on local files without being restricted by the low-code platform.
[0106] Figure 4 is a schematic block diagram of a command line based code automatic generation device provided by an embodiment of the present invention. Figure 4 As shown, corresponding to the above command line-based automatic code generation method, the present invention also provides a command line-based automatic code generation device 100. The command line-based automatic code generation device includes: a project configuration file acquisition unit 110, a list page data acquisition unit 120, a target code file generation unit 130 and a target list page generation unit 140.
[0107] The project configuration file acquisition unit 110 is used to acquire input data and automatically configure the initial project configuration file according to the input data to obtain the project configuration file.
[0108] Wherein, the input data at least includes the interface document address.
[0109] In the present embodiment, the technical solution is described with the server as the execution subject. After the user terminal establishes a communication connection with the server, if the user interface of the system is automatically generated by the code corresponding to the server, it is displayed on the user terminal. At this time, the user operates the user terminal to send input data to the server in a variety of data formats, for example, the input data of JS file format (i.e., the file format of JavaScript code), TXT file format (i.e., text file format), JSON file format (i.e., JS object notation file format) can be sent to the server, and at least the interface document address is set in the input data, and the file name and file path can also be set. Of course, the input data is not limited to only including the data in the above examples, but also can include other data of more dimensions, which will not be listed in detail here.
[0110] After the input data is obtained by the server, the initial project configuration file is first obtained in the automatic code generation system, and then the content included in the input data is automatically filled into the initial project configuration file for automatic configuration, thereby obtaining the project configuration file. Among them, the initial project file is the initial project configuration file related to the user's project to be developed. It is a file that has been configured in the initial stage of the project to be developed. It corresponds to the needs of the project to be developed and can flexibly adapt to the needs of different projects.
[0111] In one embodiment, the input data further includes a table list, an enumeration value, and a search form; the project configuration file acquisition unit 110 is used to:
[0112] Obtain the API list sub-file, the table list sub-file, the enumeration value sub-file and the search form sub-file in the initial project configuration file;
[0113] Fill the file name, the file path and the interface document address into the api list subfile, fill the table list into the table list subfile, fill the enumeration value into the enumeration value subfile, fill the search form into the search form subfile, and obtain the project configuration file.
[0114] In this embodiment, if the data included in the input data and the initial project configuration file are both in JS file format, the initial project configuration file is recorded as dataConfig.js file. The subfiles that need to be automatically configured based on the input data in the initial project configuration file include URL address subfile (recorded as url subfile), route name subfile (recorded as routerTitle subfile), route path subfile (recorded as routePath subfile), api list subfile (recorded as apiList subfile), table list subfile (recorded as tableList subfile), enumeration value subfile (recorded as optionList subfile) and search form subfile (recorded as form subfile).
[0115] Among them, in the url sub-file, the third-level directory needs to be automatically entered based on the file location of the initial project configuration file (for example, "url:taskCenter / dailyTask / dailyTaskList"), and the index.vue file (that is, a single-file component, which includes templates, scripts, styles and other information) will be generated under the first preset path such as src / ${url}.
[0116] In the routerTitle sub-file, you can directly fill it based on the route name (for example, the route name is "dailyTaskList"), and in the routePath sub-file, you can directly fill it based on the route path (for example, the route path is "Daily Tasks").
[0117] The apiList sub-file is filled with the file name, file path, and interface document address in the input data. For example, the filled apiList sub-file is as follows:
[0118] apiList:[{
[0119] apiName:"getTestList1", / / Method name referenced by the interface
[0120] apiUrl:" / privileged / service / brand / promotion / pageList", / / Interface path
[0121] apiDescription: "Test api3", / / Interface comments
[0122] docLink:"https: / / apidoc.oa.fenqile.com" / / Interface document link
[0123] }]
[0124] That is, the input data may also include interface comments, and the populated apiList sub-file may also include the interface comments.
[0125] In the tableList subfile, it is mainly necessary to enter table data (i.e., tableData), attribute name status, display name status, and conversion identification value. In one embodiment, the process of filling the table list into the table list subfile includes:
[0126] Get the table component column attribute name and the table component column display name to form table data;
[0127] Acquire the attribute name status, display name status and conversion identification value; wherein the conversion identification value is an identification value used to determine whether the field value in the table data needs to be converted to enumeration data;
[0128] The table data, the attribute name status, the display name status and the conversion identification value are combined into the table list and filled into the table list sub-file.
[0129] In this embodiment, the prop attribute of el-table-column (i.e., the table component column attribute name, el-table represents the table component, el-table-column represents a column of the table component, the prop attribute is used to specify the attribute name of the column bound data list, and the label attribute of el-table-column (i.e., the table component column display name) are first obtained, so that the table component column attribute name and the table component column display name are used to form the table data. Then, the attribute name status, display name status and conversion identification value are obtained (its value is true or false, when the value is true, it means that all field values in the table data need to be converted to enumeration data, and when the value is false, it means that all field values in the table data do not need to be converted to enumeration data); finally, the table data, the attribute name status, the display name status and the conversion identification value are combined into the table list and filled into the table list sub-file to complete the update of the table list sub-file.
[0130] For example, the table list subfile that completes data filling is as follows:
[0131] tableData:[{
[0132] prop:"followers", / / prop attribute of el-table-column
[0133] label:"Test followers" / / label attribute of el-table-column
[0134] },{
[0135] prop:"status",
[0136] label:"test status",
[0137] isNeedTransform:true / / Determine whether enumeration data conversion is required in the table data, which needs to be used together with the subsequent optionList
[0138] }]
[0139] Among them, prop:"status" indicates the property name status, label:"test status" indicates the display name status, and isNeedTransform:true indicates the conversion identification value.
[0140] In the optionList subfile, multiple enumeration values need to be entered, and each enumeration value has an enumeration value type and an enumeration value mapping value. In one embodiment, the enumeration value is filled into the enumeration value subfile, including:
[0141] Obtain several enumeration values and the enumeration value type and enumeration value mapping value corresponding to each enumeration value, and fill them into the enumeration value subfile.
[0142] In this embodiment, for example, one of the enumeration values of the optionList sub-file is as follows:
[0143] {
[0144] value:0, / / enumeration value
[0145] type:'number', / / enumeration value type
[0146] label:'Initialize 1234' / / enumeration value mapping value
[0147] }
[0148] In the above example, it represents an enumeration value with a value of 0, its enumeration value type is number, and the enumeration value mapping value is initialized to 1234.
[0149] In the form sub-file, multiple search sub-forms need to be entered, and each search sub-form includes the attribute name of the search form component, the display name of the search form component, and the form component type of the search form component. In one embodiment, the step of filling the search form into the search form sub-file includes:
[0150] A plurality of search subforms and the attribute name, display name and form component type corresponding to each search subform are obtained, and filled into the search form subfile.
[0151] In this embodiment, for example, one of the search subforms in the form subfile is as follows:
[0152] {
[0153] prop:"dailyReceiveActivityId", / / prop attribute of el-form-item
[0154] label:"Test activity ID", / / label attribute of el-form-item
[0155] type:"input" / / The form component type in el-form-item, and the form component type is selected from input|select|date
[0156] }
[0157] In the above example, it means that the attribute name of the search subform is dailyReceiveActivityId, the display name is the test activity ID, and the form component type is input (ie, input).
[0158] Once the file name, the file path and the interface document address are filled into the api list sub-file, the table list is filled into the table list sub-file, the enumeration value is filled into the enumeration value sub-file, and the search form is filled into the search form sub-file, the project configuration file can be quickly obtained.
[0159] The list page data acquisition unit 120 is used to acquire a target application program interface corresponding to the interface document address, and acquire the data required for the list page from the corresponding interface document platform based on the target application program interface.
[0160] In this embodiment, after the acquisition of the project configuration file is completed, the target application interface and the corresponding interface document platform can be determined based on the interface document address included in the api list subfile (such as / privileged / service / brand / promotion / pageList), and then the server obtains the data required for the list page from the corresponding interface document platform based on the target application interface. Among them, the data required for the list page includes a mapping relationship of list attributes, which can be used as the core data for generating the target list page. Moreover, the data structure corresponding to the data required for the list page is helpful to dynamically generate code that adapts to actual business needs (that is, the process of generating code can dynamically adapt to changes in the interface and can cope with changing business needs). Of course, at this time, the data required for the list page cannot be directly used for visual display, and it still needs to be processed by automatic code generation.
[0161] The target code file generating unit 130 is used to generate a target code file corresponding to the data required by the list page based on the command line in the preset service, the project configuration file, the data required by the list page and the preset code template.
[0162] In this embodiment, the preset service can be a Node service, and a scaffolding task (such as plop.js) can also be created in the Node service, and then a command line can be run in the scaffolding task (such as the command line corresponding to the Node service is a Node command) to generate a target code file corresponding to the data required for the list page based on the project configuration file, the data required for the list page and the preset code template. Moreover, the target code file is generated and saved in the directory corresponding to the project configuration file. It can be seen that based on the above method, code generation is realized through the command line, so that developers can complete the basic structure of complex pages through simple commands.
[0163] In one embodiment, the command line-based automatic code generation device 100 further includes:
[0164] Task creation unit, used to create initial scaffolding tasks;
[0165] The preset service creation unit is used to create generator parameters in the initial scaffolding task, and to generate modules, list pages and detail pages based on the generator parameters to complete the creation of the preset service.
[0166] In this embodiment, when creating a preset service based on a scaffolding task, an initial scaffolding task with a parameter of an empty value is first created (such as based on the instruction npminstallplop-save-g), and then a generator parameter is created in the initial scaffolding task (such as based on the instruction npm run plop generator--param[VALUE] to create a generator (addModule, addChildModule, list, view)), and based on the generator parameter, a module is generated (such as based on the instruction npm run plop addModule "taskCenter" "taskCenter" "task center"), a list page (such as based on the instruction npm runplop list) and a details page (such as based on the instruction npm runplop view) to complete the creation of the preset service. It can be seen that after creating the preset service configured by the scaffolding task, the code file can be directly generated by using the command line and the configuration file to improve the development efficiency of the page.
[0167] In one embodiment, the command line-based automatic code generation device 100 further includes:
[0168] A current request file acquisition unit, used for creating an initial request file and storing the API list sub-file in the initial request file to obtain a current request file;
[0169] A component file generating unit, configured to generate a single file component and a copy of the current requested file in a corresponding first preset path based on the url subfile in the project configuration file;
[0170] adding the current request file, the single file component and the current request file copy to the project configuration file to update the project configuration file;
[0171] The command line-based automatic code generation device 100 also includes:
[0172] The target code file storage unit is used to store the target code file in the path file corresponding to the routePath sub-file in the project configuration file.
[0173] In this embodiment, specifically, the initial request file common / request.js is first created, and then the file name, the file path and the interface document address in the api list subfile are saved in the common / request.js file, thereby obtaining the current request file.
[0174] Then, based on the url sub-file in the project configuration file, a single file component (i.e., index.vue file) is generated under the corresponding first preset path, and a copy of the current request file is generated at the same time (which can be understood as having the same data as the current request file and copied from the current request file). The obtained current request file, the single file component, and the copy of the current request file are correspondingly added to the project configuration file to update the project configuration file.
[0175] Finally, running a command line (such as npm runplop view) can generate a target code file corresponding to the data required by the list page based on the project configuration file, the data required by the list page, and the preset code template, and store the target code file in the path file corresponding to the routePath subfile in the project configuration file. It can be seen that the above code generation and saving actions are all automatic, without manual operation.
[0176] The target list page generating unit 140 is configured to generate a target list page based on the target code file.
[0177] In this embodiment, after the target code file is generated in the preset service based on the command line, project configuration file, data required for the list page and code template, since the target code file is generated and saved in the directory corresponding to the project configuration file, the target list page can be generated based on the target code file from the directory, thereby realizing automatic generation of the page.
[0178] It can be seen that the implementation example of the device can generate pages through the command line, which not only has good scalability, but also can continue encoding directly on local files without being restricted by the low-code platform.
[0179] The above command line based automatic code generation device can be implemented in the form of a computer program. The computer program can be used in Figure 5 Runs on the computer device shown.
[0180] See also Figure 5 , Figure 5 The schematic block diagram of a computer device provided by an embodiment of the present invention is shown in FIG. The computer device integrates any command line-based automatic code generation device provided by an embodiment of the present invention.
[0181] See also Figure 5 The computer device 400 includes a processor 402 , a memory and a network interface 405 connected via a system bus 401 , wherein the memory may include a storage medium 403 and an internal memory 404 .
[0182] The storage medium 403 can store an operating system 4031 and a computer program 4032. The computer program 4032 includes program instructions, and when the program instructions are executed, the processor 402 can execute the above command line-based automatic code generation method.
[0183] The processor 402 is used to provide computing and control capabilities to support the operation of the entire computer device.
[0184] The internal memory 404 provides an environment for the operation of the computer program 4032 in the storage medium 403. When the computer program 4032 is executed by the processor 402, the processor 402 can execute the above-mentioned command line-based automatic code generation method.
[0185] The network interface 405 is used to communicate with other devices over the network. Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present invention, and does not constitute a limitation on the computer device to which the solution of the present invention is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0186] The processor 402 is used to run the computer program 4032 stored in the memory to implement the above-mentioned command line-based automatic code generation method.
[0187] It should be understood that in the embodiment of the present invention, the processor 402 may be a central processing unit (CPU), and the processor 402 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0188] It can be understood by those skilled in the art that all or part of the processes in the method for implementing the above embodiment can be completed by instructing the relevant hardware through a computer program. The computer program includes program instructions, and the computer program can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiment of the above method.
[0189] Therefore, the present invention also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions. When the program instructions are executed by a processor, the processor executes the above-mentioned command line-based automatic code generation method.
[0190] The computer-readable storage medium may be a USB flash drive, a mobile hard disk, a read-only memory (ROM), a magnetic disk, or an optical disk, etc., which are computer-readable storage media that can store program codes.
[0191] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0192] In the several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of each unit is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.
[0193] The steps in the method of the embodiment of the present invention can be adjusted in order, combined and deleted according to actual needs. The units in the device of the embodiment of the present invention can be combined, divided and deleted according to actual needs. In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0194] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, terminal, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention.
[0195] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A command line based automatic code generation method, characterized in that: include: Acquire input data, and automatically configure the initial project configuration file according to the input data to obtain a project configuration file; wherein the input data at least includes an interface document address; Obtaining a target application program interface corresponding to the interface document address, and obtaining data required for the list page from the corresponding interface document platform based on the target application program interface; Generate a target code file corresponding to the data required by the list page based on a command line in a preset service, the project configuration file, the data required by the list page, and a preset code template; wherein the preset service is used to run the command line to generate the corresponding code file; A target list page is generated based on the target code file.
2. The method according to claim 1, characterized in that The input data also includes table lists, enumeration values and search forms; The automatic configuration of the initial project configuration file according to the input data to obtain the project configuration file includes: Obtain the API list sub-file, table list sub-file, enumeration value sub-file, and search form sub-file in the initial project configuration file; Fill the file name, the file path and the interface document address into the api list sub-file, fill the table list into the table list sub-file, fill the enumeration value into the enumeration value sub-file, fill the search form into the search form sub-file, and obtain the project configuration file.
3. The method according to claim 2, characterized in that Filling the table list into the table list subfile includes: Get the table component column attribute name and table component column display name to form table data; Acquire the attribute name status, display name status and conversion identification value; wherein the conversion identification value is an identification value used to determine whether the field value in the table data needs to be converted to enumeration data; The table data, the attribute name status, the display name status and the conversion identification value are combined into the table list and filled into the table list sub-file.
4. The method according to claim 2, characterized in that Filling the enumeration value into the enumeration value subfile includes: Obtain a number of enumeration values and the enumeration value type and enumeration value mapping value corresponding to each enumeration value, and fill them into the enumeration value sub-file.
5. The method according to claim 2, characterized in that Filling the search form into the search form sub-file includes: A plurality of search subforms and the attribute name, display name and form component type corresponding to each search subform are obtained and filled into the search form subfile.
6. The method according to claim 2, characterized in that Before the step of generating a target code file corresponding to the data required for the list page based on the command line in the preset service, the project configuration file, the data required for the list page, and the preset code template, the method further includes: Create initial scaffolding tasks; In the initial scaffolding task, generator parameters are created accordingly, and modules, list pages and details pages are generated accordingly based on the generator parameters to complete the creation of the preset service.
7. The method according to claim 2, characterized in that Before the step of generating a target code file corresponding to the data required for the list page based on the command line in the preset service, the project configuration file, the data required for the list page, and the preset code template, the method further includes: Creating an initial request file, and storing the API list sub-file in the initial request file to obtain a current request file; Generate a single file component and a copy of the current requested file under a corresponding first preset path based on the url subfile in the project configuration file; adding the current request file, the single-file component, and the current request file copy to the project configuration file to update the project configuration file; After the step of generating a target code file corresponding to the data required for the list page based on the command line in the preset service, the project configuration file, the data required for the list page, and the preset code template, the method further includes: The target code file is stored in the path file corresponding to the routePath sub-file in the project configuration file.
8. A code automatic generation device based on command line, characterized in that: include: A project configuration file acquisition unit, configured to acquire input data and automatically configure the initial project configuration file according to the input data to obtain a project configuration file; wherein the input data at least includes an interface document address; A list page data acquisition unit, configured to acquire a target application program interface corresponding to the interface document address, and acquire data required for the list page from the corresponding interface document platform based on the target application program interface; An object code file generating unit, configured to generate an object code file corresponding to the data required by the list page based on a command line in a preset service, the project configuration file, the data required by the list page, and a preset code template; The target list page generating unit is configured to generate a target list page based on the target code file.
9. A computer device, characterized in that: The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the command line-based automatic code generation method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions. When the program instructions are executed by a processor, the command line-based automatic code generation method according to any one of claims 1 to 7 can be implemented.
Citation Information
Cited By
Method and device for automatically generating command line code
CN119829033A
