A project code processing method and device
By receiving module processing commands and template parameters in configuration files, and replacing placeholders in code template files, the problem of being unable to delete module codes and limited incremental file modification functions in the existing technology is solved, and automated module code is realized. Manage and efficiently modify files to adapt to various code engineering structures.
Patent Information
- Application Number
- CN201911229763.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-12-04
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2039-12-04
AI Technical Summary
Existing command-line scaffolding tools cannot delete existing module codes, and their incremental modification capabilities to files are limited, making it difficult for users to extend module commands.
Provide a project code processing method and device, by receiving module processing commands, selecting the module template type and corresponding template type parameters from the configuration file, generating template parameters, reading the code template file, replacing placeholders, and executing module processing Command supports adding and deleting module code and making incremental or decremental modifications in files.
It realizes automatic and rapid addition or deletion of module codes, improves work efficiency, supports users to expand module types by themselves, and reduces learning difficulty and development costs.
Smart Images

Figure CN112905164B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a project code processing method and device. Background Art
[0002] In the early stages of a project, command line scaffolding tools (CLI tools) are usually used to automatically generate the initial code for the project, which can provide developers with automatic creation commands, reducing a lot of workload and error rate.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0004] In existing code projects, command-line scaffolding tools can only automatically add new module codes, but do not support deleting existing module codes. Moreover, the functions of incrementally modifying existing files are very limited, and only support modifying specific parts of certain code files. In addition, it is also very difficult for users to expand the module adding command by themselves. Summary of the invention
[0005] In view of this, an embodiment of the present invention provides a project code processing method and device, which can solve the problem that the existing command line scaffolding tool cannot delete the existing module code and has limited incremental modification function for files.
[0006] To achieve the above-mentioned purpose, according to one aspect of an embodiment of the present invention, a project code processing method is provided, including receiving a module processing command, selecting a module template type and corresponding template type parameters from a configuration file to generate template parameters; reading a code template file in a subdirectory of a corresponding module template type from a code template file directory, replacing a preset placeholder in the code template file name with the passed-in template parameters; and executing the module processing command based on the extension type of the code template file.
[0007] Optionally, receiving a module processing command, selecting a module template type and corresponding template type parameters from a configuration file to generate template parameters, including:
[0008] Receive a module adding processing command, read a module template type list from a configuration file to select a template type, and set a module name; merge the module name with a corresponding template type parameter in the configuration file to generate a template parameter;
[0009] Alternatively, a module deletion processing command is received, and a module list is read from a configuration file to select a module name; the module name is merged with a corresponding template type parameter in the configuration file to generate a template parameter; wherein the module list includes a mapping relationship between a module template type and a module name.
[0010] Optionally, based on the extension type of the code template file, a module processing command is executed, including:
[0011] The extension of the detection code template file is the preset first type;
[0012] If the module processing command is to add a module processing command, the template engine is used to replace the template parameters with all preset placeholders in the code template file, and then the extension is removed and the code template file is copied; according to the template file directory structure in the code template file directory, the code template file is stored in a corresponding position;
[0013] If the module processing command is a module deletion processing command, the code template file name with the extension removed is obtained, so as to delete the code template file at the corresponding position based on the template file directory structure in the code template file directory.
[0014] Optionally, based on the extension type of the code template file, a module processing command is executed, including:
[0015] The extension of the detection code template file is the preset second type;
[0016] If the module processing command is an add module processing command, the code template file is copied; according to the template file directory structure in the code template file directory, the code template file is stored in a corresponding position;
[0017] If the module processing command is a delete module processing command, the code template file at the corresponding position is deleted based on the template file directory structure in the code template file directory.
[0018] Optionally, based on the extension type of the code template file, a module processing command is executed, including:
[0019] The extension of the detection code template file is the preset third type;
[0020] If the module processing command is to add a module processing command, multiple corresponding block code templates are parsed according to the block structure in the code template file, and the template engine is used to replace the preset placeholders in each block code template with the template parameters to obtain the rendered block code template; according to the code template file directory structure, the corresponding existing files are searched in the existing code project to replace the corresponding comment placeholders in the existing files with the rendered block code templates, and a comment placeholder is generated after the replaced comment placeholder;
[0021] If the module processing command is a delete module processing command, multiple corresponding block code templates are parsed according to the block structure in the code template file, and the template engine is used to replace the preset placeholders in each block code template with the template parameters to obtain the rendered block code template; according to the code template file directory structure, the corresponding existing files are searched in the existing code project to locate the corresponding positions in the existing files based on the rendered block code templates, and then replaced with empty strings.
[0022] Optionally, the incoming template parameter replaces a preset placeholder in the code template file name, including:
[0023] Detect whether the code template file name includes a preset branch reading identifier;
[0024] If so, a subdirectory of the directory where the code template file is located is selected according to the module template type, and then the template parameters are passed in to replace the preset placeholder in the code template file name included in the subdirectory;
[0025] If not, directly pass in the template parameters to replace the preset placeholders in the code template file name.
[0026] Optionally, the incoming template parameter replaces a preset placeholder in the code template file name, including:
[0027] Pass in template parameters and use the template engine to replace the preset placeholders in the code template file name.
[0028] In addition, according to one aspect of an embodiment of the present invention, a project code processing device is provided, including a receiving module, used to receive a module processing command, select a module template type and corresponding template type parameters from a configuration file to generate template parameters; read a code template file in a subdirectory of a corresponding module template type from a code template file directory, and replace a preset placeholder in the code template file name with the passed-in template parameters; and an execution module, used to execute the module processing command based on the extension type of the code template file.
[0029] According to another aspect of an embodiment of the present invention, there is further provided an electronic device, including:
[0030] one or more processors;
[0031] a storage device for storing one or more programs,
[0032] When the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any of the above computing embodiments.
[0033] According to another aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, any of the above-mentioned methods based on the computing embodiment is implemented.
[0034] An embodiment of the above invention has the following advantages or beneficial effects: the present invention receives a module processing command, selects a module template type and a corresponding template type parameter from a configuration file, and generates a template parameter; reads a code template file in a subdirectory of a corresponding module template type from a code template file directory, and replaces a preset placeholder in the code template file name with the incoming template parameter; and executes the module processing command based on the extension type of the code template file. Thus, the present invention provides two CLI commands, namely, add and delete, to realize automatic and rapid addition of template initialization code or deletion of existing module code, and greatly improves work efficiency.
[0035] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0037] Figure 1 Schematic diagram of the main process of the project code processing method according to the first embodiment of the present invention
[0038] Figure 2 is a schematic diagram of a framework of a project code processing method according to an embodiment of the present invention;
[0039] Figure 3 is a schematic diagram of the main flow of the project code processing method according to the second embodiment of the present invention;
[0040] Figure 4 is a schematic diagram of the main flow of the project code processing method according to the third embodiment of the present invention;
[0041] Figure 5 is a schematic diagram of main modules of a project code processing device according to an embodiment of the present invention;
[0042] Figure 6 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0043] Figure 7 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0044] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0045] Figure 1 : is a schematic diagram of the main process of the project code processing method according to the first embodiment of the present invention. The project code processing method may include:
[0046] Step S101, receiving a module processing command, selecting a module template type and corresponding template type parameters from a configuration file to generate template parameters.
[0047] As an embodiment of the present invention, Figure 2 As shown, it is a framework diagram of the project code processing method according to an embodiment of the present invention, including an existing code project, an add module command and a delete module command. Among them, the existing code project includes a CLI configuration file (such as a cli.config.js configuration file) and a code template file directory (such as a templates directory). Of course, the existing code project also includes conventional codes required for project development. The add module command is divided into creating a module file and incrementally modifying an existing file, and the delete module command is divided into deleting a module file and decrementally modifying an existing file.
[0048] For example: To add a module command, use Node.js to create a global command named cli, and then create a sub-command named cli add to add a module.
[0049] The module deletion command uses Node.js to create a global command named cli, and then creates a module deletion sub-command named: cli delete.
[0050] In a further embodiment, the CLI configuration file can generally be written in js or xml format. The CLI configuration file may include: the templates field (i.e., a list of template types) is an object structure, in which the component subfield (i.e., an array structure, used to store information such as different template types required when executing the add module command) is the module type parameter input when executing the add module command, the purpose of which is to distinguish which type of new module is added. In addition, when presetting multiple module types, multiple templates subfields can also be defined, such as page, etc. The CLI configuration file can also include a files field (i.e., a list of existing modules, which is used to save existing module information for reading and use when deleting command operations): the structure is similar to templates and is also an object structure, and the component subfield is also similar to the component subfield in the above-mentioned templates field, which is an array structure. Multiple files subfields can also be defined, such as page, etc.
[0051] In another further embodiment, the first level directory of the code template file directory is the module type parameter input when executing the add module command, and the storage location of each file under the first level directory completely corresponds to each file structure in the existing code project. Among them, the file type includes the first type, the second type and the third type.
[0052] The first type is a file with an .hbs extension, which can be a template file rendered by a template engine (for example, using the Handlebars template engine, whose default placeholder is "{{xxx}}", but the present invention is not limited to the use of a certain template engine, such as EJS or a simple template engine implemented by itself.), and after rendering, the .hbs extension will be removed to generate a corresponding file.
[0053] The second type is a file with a .t.hbs extension. This type of file needs to be parsed into blocks to obtain a block template. After rendering, local codes will be added or deleted in the corresponding file after removing the .t.hbs extension.
[0054] The third type is the remaining files, all of which are regular files.
[0055] In some embodiments, if the received command is to add a module processing command, a module template type list is read from a configuration file (e.g., a CLI configuration file) to select a template type and set a module name. The module name is merged with the corresponding template type parameter in the configuration file to generate a template parameter.
[0056] If the received command is to delete a module, a module list is read from the configuration file to select a module name, and the module name is combined with a corresponding template type parameter in the configuration file to generate a template parameter, wherein the module list includes a mapping relationship between a module template type and a module name.
[0057] Step S102, reading the code template file in the corresponding module template type subdirectory from the code template file directory, and replacing the preset placeholder in the code template file name with the incoming template parameters.
[0058] The placeholder mentioned above, taking the handlebars template engine as an example, refers to {{abc}} in the template file content or template file name, that is, the placeholder can only exist in the template file, which is an existing concept. Each template engine has built-in support for replacing placeholders. For different template engines, the default supported placeholders are different. For example, EJS, its placeholder is <%abc%>.
[0059] In some embodiments, when the template parameters are passed in to replace the preset placeholders in the code template file name, it can be detected whether the code template file name includes a preset branch read identifier. If the preset branch read identifier is included, a subdirectory of the directory where the code template file is located is selected according to the module template type, and then the template parameters are passed in to replace the preset placeholders in the code template file name included in the subdirectory. If the preset branch read identifier is not included, the template parameters are directly passed in to replace the preset placeholders in the code template file name.
[0060] As a preferred embodiment, template parameters are passed in and the template engine is used to replace the preset placeholders in the code template file name.
[0061] Step S103, executing the module processing command based on the extension type of the code template file.
[0062] In some embodiments, when the extension of the code template file is detected to be a preset first type:
[0063] If the module processing command is to add a module processing command, the template engine is used to replace the template parameters with all preset placeholders in the code template file, and then the extension is removed and the code template file is copied; according to the template file directory structure in the code template file directory, the code template file is stored in the corresponding location. At this point, the creation of the module file is completed. For example: the template parameter is {a:100,b:200}, and the template file content is {{a}}+{{b}}=300. When using the template engine to replace, the template parameter needs to be passed in, and only one replacement is required. The result after replacement is: 100+200=300.
[0064] If the module processing command is a delete module processing command, the code template file name without the extension is obtained to delete the code template file at the corresponding position based on the template file directory structure in the code template file directory. At this point, the module file is deleted.
[0065] In some other embodiments, when the extension of the code template file is detected to be of a preset second type:
[0066] If the module processing command is to add a module processing command, the code template file is copied; according to the template file directory structure in the code template file directory, the code template file is stored in a corresponding position. At this point, the creation of the module file is completed.
[0067] If the module processing command is a delete module processing command, the code template file at the corresponding position is deleted based on the template file directory structure in the code template file directory. At this point, the module file is deleted.
[0068] In some other embodiments, when the extension of the code template file is detected to be a preset third type:
[0069] If the module processing command is to add a module processing command, multiple corresponding block code template files are parsed according to the block structure in the code template file, and the template engine is used to replace the preset placeholders in each block code template with the template parameters to obtain the rendered block code template; according to the code template file directory structure, the corresponding existing files are searched in the existing code project to replace the corresponding comment placeholders in the existing file with the rendered block code templates, and a comment placeholder is generated after the replaced comment placeholder. At this point, the incremental modification of the existing file is completed.
[0070] If the module processing command is a delete module processing command, multiple corresponding block code template files are parsed according to the block structure in the code template file, and the template engine is used to replace the preset placeholders in each block code template with the template parameters to obtain the rendered block code template; according to the code template file directory structure, the corresponding existing files are searched in the existing code project to locate the corresponding position in the existing file based on the rendered block code template, and then replaced with an empty string. At this point, the reduction modification of the existing file is completed.
[0071] The comment placeholder is predefined and used to insert new content into the existing code file, while it is a comment itself and does not affect the function of the existing code. For example, in js (javascript) code, the format can be " / / {placeholder} / / ", where placeholder is the name of the comment placeholder. In css code, the format can be " / *{placeholder}* / ".
[0072] Therefore, the project code processing method described in the present invention not only supports adding module codes, but also supports deleting module codes. That is, two CLI commands of adding or deleting are provided to realize automatic and rapid addition of template initial codes or deletion of existing module codes, thereby improving work efficiency. At the same time, in addition to supporting incremental modification, decremental modification is also supported for existing files. When modifying existing files by increment (decrement), several comment placeholders can also be customized and placed at any position. In addition, there are no restrictions on the programming language of existing code files, and it supports adding or deleting codes at any position in any code language file. The scalability is very strong and it is adaptable to existing code projects with any file structure. In addition, it supports users to expand and add or delete new types of modules by themselves, and the difficulty of learning and the development cost are very low. Users only need to master very simple concepts to start personalized extension functions by themselves.
[0073] Figure 3 2 is a schematic diagram of the main flow of a project code processing method according to a second embodiment of the present invention. Based on receiving a module adding processing command, the project code processing method may include:
[0074] Step S301, receiving a module adding processing command.
[0075] For example: receiving the cli add component command, where the component parameter is called the module type.
[0076] Step S302, read the module template type list from the configuration file to select the template type and set the module name.
[0077] For example: read the module template type list from the cli.config.js file, select the template type to be created, and enter the module name. The module name is saved in the componentName variable (i.e. the naming method is "module type + Name").
[0078] Step S303: merge the module name with the corresponding template type parameter in the configuration file to generate template parameters.
[0079] Step S304, reading the code template file in the corresponding module template type subdirectory from the code template file directory.
[0080] Step S305, detecting whether the code template file name includes a preset branch read identifier, if so, proceeding to step S306 and then to step S307, otherwise, directly proceeding to step S307.
[0081] For example: the directory name of templates / component / src / [components] / contains "[]", which means that its subdirectories or files will be read in branches according to the template type. Step S306, select a subdirectory of the directory where the code template file is located according to the module template type, and then pass in the template parameters to replace the preset placeholder in the code template file name included in the subdirectory.
[0082] In the embodiment, the corresponding subdirectory (e.g., {{ComponentName}}-Input subdirectory) is selected according to the previously input template type (e.g., Input template type). This subdirectory name needs to be named with "-template type" at the end, so that more common template files (such as main.js.t.hbs in the example) can be reused, which is easier to maintain when the number of template files is large.
[0083] Step S307, input template parameters and use the template engine to replace the preset placeholders in the code template file name.
[0084] For example: Use the Handlebars template engine to replace the preset placeholders in the code template file name. It should be noted that in special cases: if the "-template type" suffix is included, the "-template type" needs to be removed. If "[]" is included, the "[]" is also removed. For example: src / [components] / {{ComponentName}}-Input is replaced with src / components / Test1.
[0085] Step S308, determine the extension type of the code template file, if it is the preset first type, proceed to step S309, if it is the preset second type, proceed to step S310, if it is the preset third type, proceed to step S311.
[0086] Step S309, using the template engine to replace the template parameters with all preset placeholders in the code template file, then remove the extension and copy the code template file; according to the template file directory structure in the code template file directory, store the code template file to the corresponding location.
[0087] Step S310, copying the code template file; storing the code template file to a corresponding location according to the template file directory structure in the code template file directory.
[0088] Step S311, parse out multiple corresponding block code templates according to the block structure in the code template file, and use the template engine to replace the preset placeholders in each block code template with the template parameters to obtain the rendered block code templates; according to the code template file directory structure, search for the corresponding existing files in the existing code project to replace the corresponding comment placeholders in the existing files with the rendered block code templates, and generate a comment placeholder after the replaced comment placeholder.
[0089] For example, the templates / component / src / main.js.t.hbs file is structured with multiple <#template> tags, called block templates. Each block template tag includes a name attribute, called the block template name.
[0090] Figure 4 is a schematic diagram of the main flow of a project code processing method according to a third embodiment of the present invention. Based on receiving a deletion module processing command, the project code processing method may include:
[0091] Step S401, receiving a deletion module processing command.
[0092] For example: Enter the cli delete component command, where the component parameter refers to the module type.
[0093] Step S402, reading a module list from a configuration file to select a module name.
[0094] Step S403: merge the module name with the corresponding template type parameter in the configuration file to generate template parameters.
[0095] Wherein, the module list includes a mapping relationship between module template types and module names.
[0096] Step S404, reading the code template file in the corresponding module template type subdirectory from the code template file directory.
[0097] Step S405, detecting whether the code template file name includes a preset branch read identifier, if so, proceeding to step S406 and then to step S407, otherwise, directly proceeding to step S407.
[0098] Step S406, selecting a subdirectory of the directory where the code template file is located according to the module template type, and then inputting template parameters to replace the preset placeholder in the code template file name included in the subdirectory.
[0099] Step S407, input template parameters and use the template engine to replace the preset placeholders in the code template file name.
[0100] Step S408, determine the extension type of the code template file, if it is the preset first type, proceed to step S409 and then step S410, if it is the preset second type, directly proceed to step S410, if it is the preset third type, proceed to step S411.
[0101] Step S409, obtaining the code template file name with the extension removed.
[0102] Step S410, based on the template file directory structure in the code template file directory, delete the code template file at the corresponding position.
[0103] Step S411, parse out multiple corresponding block code templates according to the block structure in the code template file, and use the template engine to replace the preset placeholders in each block code template with the template parameters to obtain the rendered block code template; according to the code template file directory structure, search for the corresponding existing files in the existing code project to locate the corresponding positions in the existing files based on the rendered block code template, and then replace them with empty strings.
[0104] Figure 5 is a schematic diagram of the main modules of the project code processing device according to the first embodiment of the present invention, such as Figure 5 As shown, the project code processing device 500 includes a receiving module 501 and an execution module 502. The receiving module 501 receives a module processing command, selects a module template type and a corresponding template type parameter from a configuration file, and generates a template parameter. From the code template file directory, the code template file in the corresponding module template type subdirectory is read, and the preset placeholder in the code template file name is replaced with the incoming template parameter. The execution module 502 executes the module processing command based on the extension type of the code template file.
[0105] In a further embodiment, when the receiving module 501 receives the module processing command and selects the module template type and the corresponding template type parameters from the configuration file to generate the template parameters, the following steps may be included:
[0106] Receive the module adding processing command, read the module template type list from the configuration file to select the template type, set the module name; merge the module name with the corresponding template type parameters in the configuration file to generate template parameters.
[0107] Alternatively, a module deletion processing command is received, and a module list is read from a configuration file to select a module name; the module name is merged with a corresponding template type parameter in the configuration file to generate a template parameter; wherein the module list includes a mapping relationship between a module template type and a module name.
[0108] As another embodiment, when the execution module 502 executes the module processing command based on the extension type of the code template file, it can detect that the extension of the code template file is a preset first type. If the module processing command is to add a module processing command, the template engine is used to replace the template parameters with all preset placeholders in the code template file, and then the extension is removed and the code template file is copied; according to the template file directory structure in the code template file directory, the code template file is stored in the corresponding position. If the module processing command is to delete the module processing command, the code template file name with the extension removed is obtained to delete the code template file in the corresponding position based on the template file directory structure in the code template file directory.
[0109] As another embodiment, when the execution module 502 executes the module processing command based on the extension type of the code template file, it can detect that the extension of the code template file is a preset second type. If the module processing command is an add module processing command, the code template file is copied; according to the template file directory structure in the code template file directory, the code template file is stored in the corresponding position. If the module processing command is a delete module processing command, the code template file at the corresponding position is deleted based on the template file directory structure in the code template file directory.
[0110] As another embodiment, when the execution module 502 executes the module processing command based on the extension type of the code template file, it can detect that the extension of the code template file is a preset third type. If the module processing command is to add a module processing command, multiple corresponding block code template files are parsed according to the block structure in the code template file, and the template engine is used to replace the preset placeholders in each block code template with the template parameters to obtain the rendered block code template; according to the directory structure of the code template file, the corresponding existing files are searched in the existing code project to replace the corresponding comment placeholders in the existing file with the rendered block code template, and a comment placeholder is generated behind the replaced comment placeholder; if the module processing command is to delete the module processing command, multiple corresponding block code template files are parsed according to the block structure in the code template file, and the template engine is used to replace the preset placeholders in each block code template with the template parameters to obtain the rendered block code template; according to the directory structure of the code template file, the corresponding existing files are searched in the existing code project to locate the corresponding position in the existing file based on the rendered block code template, and then replace it with an empty string.
[0111] It is also worth noting that the template parameters passed into the receiving module 501 replace the preset placeholders in the code template file name, including:
[0112] Detect whether the code template file name includes a preset branch reading identifier;
[0113] If so, a subdirectory of the directory where the code template file is located is selected according to the module template type, and then the template parameters are passed in to replace the preset placeholders in the code template file name included in the subdirectory.
[0114] If not, directly pass in the template parameters to replace the preset placeholders in the code template file name.
[0115] In some embodiments of the present invention, the receiving module 501 passes in template parameters and uses the template engine to replace the preset placeholders in the code template file name.
[0116] It should be noted that the project code processing method and the project code processing device of the present invention have a corresponding relationship in terms of specific implementation contents, so the repeated contents will not be described again.
[0117] Figure 6 An exemplary system architecture 600 is shown to which the project code processing method or project code processing apparatus according to the embodiment of the present invention can be applied.
[0118] like Figure 6 As shown, system architecture 600 may include terminal devices 601, 602, 603, network 604 and server 605. Network 604 is used to provide a medium for communication links between terminal devices 601, 602, 603 and server 605. Network 604 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0119] Users can use terminal devices 601, 602, and 603 to interact with server 605 through network 604 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 601, 602, and 603, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).
[0120] The terminal devices 601 , 602 , and 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc.
[0121] The server 605 may be a server that provides various services, such as a backend management server (only an example) that provides support for shopping websites browsed by users using the terminal devices 601, 602, and 603. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information, product information - only an example) to the terminal device.
[0122] It should be noted that the project code processing method provided in the embodiment of the present invention is generally executed by the server 605 , and accordingly, the project code processing device is generally disposed in the server 605 .
[0123] It should be understood that Figure 6 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0124] Reference below Figure 7 , which shows a schematic diagram of the structure of a computer system 700 of a terminal device suitable for implementing an embodiment of the present invention. Figure 7 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0125] like Figure 7 As shown, the computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage part 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the system 700 are also stored. The CPU 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0126] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, etc.; an output section 707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, a modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed, so that a computer program read therefrom is installed into the storage section 708 as needed.
[0127] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 709, and / or installed from the removable medium 711. When the computer program is executed by the central processing unit (CPU) 701, the above-mentioned functions defined in the system of the present invention are executed.
[0128] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0129] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0130] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes a receiving module and an execution module. The names of these modules do not, in some cases, constitute limitations on the modules themselves.
[0131] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: receiving a module processing command, selecting a module template type and corresponding template type parameters from a configuration file to generate template parameters; reading a code template file in a corresponding module template type subdirectory from a code template file directory, replacing a preset placeholder in the code template file name with the incoming template parameters; and executing the module processing command based on the extension type of the code template file.
[0132] According to the technical solution of the embodiment of the present invention, it is possible to solve the problem that the existing command line scaffolding tool cannot delete the existing module code and has limited function of incremental modification of files.
[0133] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A project code processing method, characterized in that: include: Receiving a module processing command, selecting a module template type and corresponding template type parameters from a configuration file to generate template parameters, including: receiving an add module processing command, reading a module template type list from a configuration file to select a template type, and setting a module name; merging the module name with the corresponding template type parameters in the configuration file to generate template parameters; or, receiving a delete module processing command, reading a module list from a configuration file to select a module name; merging the module name with the corresponding template type parameters in the configuration file to generate template parameters; wherein the module list includes a mapping relationship between module template types and module names; From the code template file directory, read the code template file in the corresponding module template type subdirectory, and replace the preset placeholder in the code template file name with the passed template parameters; Based on the extension type of the code template file, the module processing command is executed.
2. The method according to claim 1, characterized in that Based on the extension type of the code template file, the module processing commands are executed, including: The extension of the detection code template file is the preset first type; If the module processing command is to add a module processing command, the template engine is used to replace the template parameters with all preset placeholders in the code template file, and then the extension is removed and the code template file is copied; according to the template file directory structure in the code template file directory, the code template file is stored in a corresponding position; If the module processing command is a module deletion processing command, the code template file name with the extension removed is obtained, so as to delete the code template file at the corresponding position based on the template file directory structure in the code template file directory.
3. The method according to claim 1, characterized in that Based on the extension type of the code template file, the module processing commands are executed, including: The extension of the detection code template file is the preset second type; If the module processing command is an add module processing command, the code template file is copied; according to the template file directory structure in the code template file directory, the code template file is stored in a corresponding position; If the module processing command is a delete module processing command, the code template file at the corresponding position is deleted based on the template file directory structure in the code template file directory.
4. The method according to claim 1, characterized in that: Based on the extension type of the code template file, the module processing commands are executed, including: The extension of the detection code template file is the preset third type; If the module processing command is to add a module processing command, multiple corresponding block code templates are parsed according to the block structure in the code template file, and the template engine is used to replace the preset placeholders in each block code template with the template parameters to obtain the rendered block code template; according to the code template file directory structure, the corresponding existing files are searched in the existing code project to replace the corresponding comment placeholders in the existing files with the rendered block code templates, and a comment placeholder is generated after the replaced comment placeholder; If the module processing command is a delete module processing command, multiple corresponding block code templates are parsed according to the block structure in the code template file, and the template engine is used to replace the preset placeholders in each block code template with the template parameters to obtain the rendered block code template; according to the code template file directory structure, the corresponding existing files are searched in the existing code project to locate the corresponding positions in the existing files based on the rendered block code templates, and then replaced with empty strings.
5. The method according to claim 1, characterized in that The input template parameters replace the preset placeholders in the code template file name, including: Detect whether the code template file name includes a preset branch reading identifier; If so, a subdirectory of the directory where the code template file is located is selected according to the module template type, and then the template parameters are passed in to replace the preset placeholder in the code template file name included in the subdirectory; If not, directly pass in the template parameters to replace the preset placeholders in the code template file name.
6. The method according to any one of claims 1 to 5, characterized in that: The input template parameters replace the preset placeholders in the code template file name, including: Pass in template parameters and use the template engine to replace the preset placeholders in the code template file name.
7. A project code processing device, characterized in that: include: A receiving module is used to receive a module processing command, select a module template type and corresponding template type parameters from a configuration file to generate template parameters, including: receiving an add module processing command, reading a module template type list from a configuration file to select a template type, and setting a module name; merging the module name with the corresponding template type parameters in the configuration file to generate template parameters; or, receiving a delete module processing command, reading a module list from a configuration file to select a module name; merging the module name with the corresponding template type parameters in the configuration file to generate template parameters; wherein the module list includes a mapping relationship between a module template type and a module name; reading a code template file in a subdirectory of a corresponding module template type from a code template file directory, and replacing a preset placeholder in the code template file name with the incoming template parameters; The execution module is used to execute module processing commands based on the extension type of the code template file.
8. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6.
9. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
System and method for extended structure command line
CN108228161A
Implementation method and device for generating examination report based on parameters, and method for generating examination report by using method and device
CN110309498A
