Code migration method, device, equipment and medium for front-end framework upgrade
By identifying and parsing the target methods and parameters in JavaScript files, and combining the grammar rules of the target framework for grammar conversion, it solved the code maintenance efficiency and performance problems of early Vue front-end projects, realized automated code migration from the original framework to the target framework, and improved Improve development efficiency and code standardization.
Patent Information
- Application Number
- CN202410865934.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-01
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2044-07-01
AI Technical Summary
The early Vue front-end projects lacked standardized development methods, resulting in poor code maintenance efficiency and system security performance, and required framework upgrades to meet new technical requirements.
Provides a code migration method for front-end framework upgrades. By reading JavaScript files, identifying target methods and parameters, parsing input parameter objects, performing syntax conversion according to the syntax rules of the target framework, and generating code files under the target framework, the original Code migration from framework to target framework.
It realizes automated code migration, improves development efficiency, supports batch processing of different page files, and meets the code standardization and performance requirements of framework upgrades.
Smart Images

Figure CN118409793B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a code migration method, device, equipment and medium for front-end framework upgrade. Background Art
[0002] With the continuous development of web (World Wide Web) front-end framework technology and the continuous improvement of user experience requirements, project iteration has new requirements for the standardization of development code and development and maintenance efficiency.
[0003] For early Vue (a front-end framework for building user interfaces) front-end projects, since there is no standardized development method, developers have different encapsulations based on their own understandings, and still use the separate development mode of HTML (Hypertext Markup Language) and JS (JavaScript, a lightweight, interpreted or just-in-time compiled programming language with function priority) files instead of developing in Vue files. They also do not use packaging tools to package, compress and confuse the code, and do not meet the requirements of system security and performance. Therefore, it is necessary to upgrade the framework of such projects. Summary of the invention
[0004] The present application provides a code migration method, device, equipment and medium for front-end framework upgrade, which is used to solve the problem of how to better perform code migration when upgrading the front-end framework in the prior art.
[0005] In a first aspect, the present application provides a code migration method for front-end framework upgrade, comprising:
[0006] Read the JavaScript file in the folder of the current page and determine the type of the JavaScript file;
[0007] In response to the type of the JavaScript file being a page file, identifying a target method in the page file, and intercepting parameters of the target method;
[0008] Obtain the input parameter object of the parameter, and parse the input parameter object to obtain the template information and attribute information of the target object;
[0009] According to the grammatical rules of the target framework, the template information and the attribute information are grammatically converted to obtain a target file under the target framework.
[0010] In a second aspect, the present application provides a code migration device for front-end framework upgrade, comprising:
[0011] A reading module is used to read the JavaScript file in the folder of the current page and determine the type of the JavaScript file;
[0012] an identification module, for identifying a target method in the page file in response to the type of the JavaScript file being a page file, and intercepting parameters of the target method;
[0013] A parsing module, used to obtain an input parameter object of the parameter, and parse the input parameter object to obtain template information and attribute information of the target object;
[0014] The conversion module is used to perform syntax conversion on the template information and attribute information according to the syntax rules of the target framework to obtain the target file under the target framework.
[0015] In a third aspect, the present application also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, a code migration method for upgrading a front-end framework as described in any one of the embodiments of the present application is implemented.
[0016] In a fourth aspect, the present application also provides a computer-readable storage medium on which a computer program is stored, which, when executed by a processor, implements a code migration method for upgrading a front-end framework as described in any of the embodiments of the present application.
[0017] In a fifth aspect, the present application also provides a computer program product, including a computer program, which, when executed by a processor, implements a code migration method for upgrading a front-end framework as described in any one of the embodiments of the present application.
[0018] The code migration method, device, equipment and storage medium for front-end framework upgrade provided by the present application can obtain the parameters of the target method and its input object by identifying the js file in the page folder, and then further parse the input object to obtain the template information and attribute information of the target object, and finally perform syntax conversion on the template information and attribute information according to the grammatical rules of the target framework to obtain the target file under the target framework. Thus, the code under the original framework can be automatically generated into the code file under the target framework, and batch processing of different page files can be realized, which greatly improves the development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0020] Figure 1A flowchart of a code migration method for front-end framework upgrade provided in an embodiment of the present application;
[0021] Figure 2 A flowchart of a code migration method for front-end framework upgrade provided in an embodiment of the present application;
[0022] Figure 3 A schematic diagram of the structure of a code migration device for front-end framework upgrade provided in an embodiment of the present application;
[0023] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0024] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0025] The present application will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present application, rather than to limit the present application. It should also be noted that, for ease of description, only the parts related to the present application, rather than all structures, are shown in the accompanying drawings.
[0026] It should be noted that similar numbers and letters represent similar items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance. The acquisition, storage, use, and processing of data in the technical solution of this application comply with the relevant provisions of national laws and regulations.
[0027] Figure 1 Flowchart of the code migration method for front-end framework upgrade provided in the embodiment of the present application. This embodiment can be applied to the case where code migration is automatically implemented during the framework upgrade of an early vue front-end project. The method can be executed by a code migration device for front-end framework upgrade, which can be implemented in software and / or hardware, preferably configured in an electronic device, such as a computer device or a server. Figure 1 As shown, the method specifically includes:
[0028] S101, read the js file in the folder of the current page, and determine the type of the js file.
[0029] S102: In response to the type of the js file being a page file, identifying a target method in the page file, and intercepting parameters of the target method.
[0030] S103: Obtain an input parameter object, and obtain template information and attribute information of the target object according to the parsing of the input parameter object.
[0031] S104. According to the grammatical rules of the target framework, the template information and the attribute information are grammatically converted to obtain a target file under the target framework.
[0032] Specifically, each page or component in the front-end project to be migrated is written in a separate folder in the original framework. During code migration, the embodiment of the present application can obtain and process the files in the folder of each page in turn. First read the js file in the folder of each current page, and then determine the type of the js file. Among them, the js file can be a page file or a configuration file. The embodiment of the present application uses different logics to process page files and configuration files.
[0033] When it is determined that the js file is a page file, the target method in the page file is further identified, and the parameters of the target method are intercepted. For example, the target method in the page file can be identified by a pre-configured target function, and the parameters of the target method can be intercepted. Among them, the target method can be a key method in the pre-configured current code to be migrated, and the parameters of the target method can be in the form of a string. Therefore, the embodiment of the present application also needs to obtain the input parameter object of the parameter, for example, to obtain the input parameter object of the parameter through a js function / method. Then, according to the input parameter object, the template template information and attribute information of the target object can be further parsed from the content of the input parameter object, and the target object can be a vue object. Finally, according to the grammatical rules of the target framework, the template information and attribute information can be automatically converted to syntax, thereby obtaining the target file of the current page under the target framework. The code migration of the target project from the original framework to the target framework is completed by batch processing of all pages and components in the target project. Among them, the attribute information of the target object includes, for example, data attribute data, calculated attribute computed, completed creation hook function created, rendering completed hook function mounted, method attribute methods and observation attribute watch.
[0034] In one embodiment, when performing syntax conversion, the characteristic string can be matched in the code corresponding to the template information and the attribute information according to the syntax characteristics of the code in the original framework file in a regular matching manner, and then the matched string is syntax converted according to the syntax rules of the target framework to make it compatible under the target framework, thereby obtaining the new code under the target framework. After completing the code conversion, the obtained new code can be written into the migration project.
[0035] In one implementation, in addition to regular matching syntax conversion of feature string codes, some feature code blocks with syntax compatibility issues need to be adjusted in syntax as a whole (for example, there is a feature function call, the function input parameter is an anonymous callback function and the function body is defined at the same time, which constitutes a code block, and it is necessary to parse out a whole code block based on the function name and perform syntax compatibility processing). For code block nesting scenarios with such features (i.e., the input parameter callback function body also contains a call to this feature function), a recursive method is used to hierarchically parse the feature function call code blocks, and the local syntax is converted for compatibility and then spliced to obtain new code under the target framework.
[0036] In another embodiment, before obtaining the template information and attribute information of the target object according to the input parameter object, the method of the embodiment of the present application may further include: parsing the template path, js module import declaration information and variable declaration information of the target object according to the input parameter object. Specifically, it can be obtained by analyzing the code before the target method in the page file through a specific function. With these template paths, import declaration information and variable declaration information, it is possible to better prepare for the subsequent code migration.
[0037] Therefore, the technical solution of the embodiment of the present application, by identifying the js file in the page folder, obtains the parameters of the target method and its input object, and further parses the input object to obtain the template information and attribute information of the target object, and finally converts the template information and attribute information into syntax according to the grammatical rules of the target framework, obtains the target file under the target framework, and automatically generates the code file under the target framework from the code under the original framework, and realizes batch processing of different page files, which greatly improves the development efficiency. For example, for the early non-engineered vue2 project, the method of the embodiment of the present application can be used to upgrade it to vue3, and the html and js files are parsed and merged to automatically generate the corresponding code file under the vue3 framework.
[0038] Figure 2 Flow chart of the code migration method for front-end framework upgrade provided in the embodiment of the present application. Figure 2 As shown, the method comprises the following steps:
[0039] S201. Read the js file in the folder of the current page and determine the type of the js file.
[0040] S202: In response to the type of the js file being a page file, identifying a target method in the page file, and intercepting parameters of the target method.
[0041] S203: Obtain the input parameter object, and parse the input parameter object to obtain the template information and attribute information of the target object.
[0042] S204: According to the grammatical rules of the target framework, the template information and the attribute information are grammatically converted to obtain a target file under the target framework.
[0043] S205. In response to the type of the js file being a configuration file, parse the interface information and routing information in the configuration file.
[0044] S206: If the target file under the target framework already exists, the interface information and the routing information are respectively merged with the interface information and the routing information of the current page in the target file to update the target file.
[0045] Specifically, for the configuration file under the current page folder, the interface information and routing information therein can be parsed respectively. Then, it is determined whether the target file under the target framework already exists. If it already exists, the interface information and routing information are merged with the interface information and routing information of the current page in the target file respectively to update the target file. If it does not exist, a new file can be created and the interface information and routing information of the current page can be written.
[0046] In addition, a one-time manual migration can be performed on the multi-language configuration, public methods, custom components, custom instructions, etc. in the front-end project of the original framework, and they can be migrated to the target framework to complete the construction of the infrastructure of the front-end project in the target framework. The code migration and reconstruction of configuration files such as page files, components, routing configuration, interface request configuration, etc. can then be performed.
[0047] In one embodiment, in the method of the embodiment of the present application, in the process of traversing all page folders in the project to be migrated, the folders of each page can be recursively traversed and hierarchically parsed according to the nested relationship between the pages, thereby improving the efficiency of code migration and reducing errors caused by migration.
[0048] In another embodiment, the method of the embodiment of the present application may further include: in the process of traversing all page folders in the project to be migrated, if there is a second page that shares the same configuration file as the current page, determining whether there is currently a processing task for the configuration file corresponding to the second page; if so, placing the processing task of the configuration file corresponding to the current page into a queue to be executed, and after the processing task of the configuration file corresponding to the second page is completed, executing the processing task of the configuration file corresponding to the current page in the queue to be executed.
[0049] Specifically, in a front-end project, there may be a situation where different pages share the same configuration file. Therefore, this will be judged when performing code migration. If there is a second page that shares the same configuration file with the current page, it is determined whether there is a processing task for the configuration file corresponding to the second page; if so, the processing task of the configuration file corresponding to the current page is placed in the queue to be executed, and after the processing task of the configuration file corresponding to the second page is completed, the processing task of the configuration file corresponding to the current page in the queue to be executed is executed. That is, when executing the writing task of the configuration file of a certain page during the migration process, a read-write lock can be set for the configuration file. In this way, when other pages that share the configuration file are processed, the processing task for the configuration file will be temporarily placed in the queue to be executed, and when the writing task of the configuration file of the page is completed, the task in the queue to be executed will continue to be executed. In this way, the orderly progress of the code migration process can be ensured in the process of traversing each page folder. At the same time, the traversal, parsing operation and syntax conversion of the folder can also be executed by the main program, and the file reading and writing tasks can be executed by the asynchronous processing program, thereby improving the efficiency of code migration.
[0050] The technical solution of the embodiment of the present application adopts different logical processing methods for page files and configuration files, parses and merges HTML and JS files, automatically generates corresponding target Vue framework files, and automatically processes routing and interface configuration files, etc., which can greatly improve development efficiency.
[0051] Figure 3 This is a schematic diagram of the structure of the code migration device for front-end framework upgrade provided in the embodiment of the present application. Figure 3 As shown, the device 30 comprises:
[0052] The reading module 301 is used to read the JavaScript file in the folder of the current page and determine the type of the JavaScript file;
[0053] The identification module 302 is used for identifying a target method in the page file in response to the type of the JavaScript file being a page file, and intercepting parameters of the target method;
[0054] A parsing module 303 is used to obtain an input parameter object of the parameter, and parse the input parameter object to obtain template information and attribute information of the target object;
[0055] The conversion module 304 is used to perform syntax conversion on the template information and the attribute information according to the syntax rules of the target framework to obtain a target file under the target framework.
[0056] In some embodiments, the device further includes a configuration file processing module, specifically configured to:
[0057] In response to the type of the JavaScript file being a configuration file, parsing the interface information and routing information in the configuration file;
[0058] If the target file under the target framework already exists, the interface information and routing information are respectively merged with the interface information and routing information of the current page in the target file to update the target file.
[0059] In some embodiments, the device further includes a first processing module, specifically configured to:
[0060] In the process of traversing all page folders in the project to be migrated, the folders of each page are recursively traversed and hierarchically parsed according to the nested relationship between the pages.
[0061] In some embodiments, the device further includes a second processing module, specifically configured to:
[0062] In the process of traversing all page folders in the project to be migrated, if there is a second page that shares the same configuration file with the current page, determining whether there is currently a processing task for the configuration file corresponding to the second page;
[0063] If it exists, the processing task of the configuration file corresponding to the current page is put into a queue to be executed, and after the processing task of the configuration file corresponding to the second page is completed, the processing task of the configuration file corresponding to the current page in the queue to be executed is executed.
[0064] In some embodiments, the identification module 302 is specifically used to:
[0065] Through the pre-configured target function, the target method in the page file is identified, and the parameters of the target method are intercepted.
[0066] In some embodiments, the apparatus further comprises:
[0067] The declaration information acquisition module is used to parse the template path, JavaScript module introduction declaration information and variable declaration information of the target object according to the input parameter object before the parsing module 303 parses the input parameter object to obtain the template information and attribute information of the target object.
[0068] In some embodiments, the target object is a vue object.
[0069] The code migration device for front-end framework upgrade provided in the embodiment of the present application can be used to execute the technical solution of the code migration method for front-end framework upgrade in the above-mentioned embodiment. Its implementation principle and technical effect are similar and will not be repeated here.
[0070] It should be noted that it should be understood that the division of the various modules of the above device is only a division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated. And these modules can all be implemented in the form of software called by processing elements; they can also be all implemented in the form of hardware; some modules can also be implemented in the form of software called by processing elements, and some modules can be implemented in the form of hardware. For example, the analysis module 303 can be a separately established processing element, or it can be integrated in a chip of the above device. In addition, it can also be stored in the memory of the above device in the form of program code, and called and executed by a processing element of the above device. The function of the above analysis module 303. The implementation of other modules is similar. In addition, all or part of these modules can be integrated together, or they can be implemented independently. The processing element here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each module above can be completed by an integrated logic circuit of hardware in the processor element or instructions in the form of software.
[0071] In the technical solution of this application, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved are in compliance with the relevant laws and regulations and do not violate public order and good morals.
[0072] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.
[0073] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 4As shown, the electronic device may include: a transceiver 121 , a processor 122 , and a memory 123 .
[0074] The processor 122 executes the computer-executable instructions stored in the memory, so that the processor 122 executes the scheme in the above embodiment. The processor 122 can be a general-purpose processor, including a central processing unit CPU, a network processor (network processor, NP), etc.; it can also be a digital signal processor DSP, an application-specific integrated circuit ASIC, a field programmable gate array FPGA or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.
[0075] The memory 123 is connected to the processor 122 via a system bus and completes communication between them. The memory 123 is used to store computer program instructions.
[0076] The transceiver 121 may be used to obtain tasks to be executed and configuration information of the tasks to be executed.
[0077] The system bus can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The system bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The transceiver is used to realize the communication between the database access device and other computers (such as clients, read-write libraries, and read-only libraries). The memory may include random access memory (RAM) and may also include non-volatile memory.
[0078] The electronic device provided in the embodiment of the present application may be the terminal device of the above embodiment.
[0079] An embodiment of the present application also provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions are executed on a computer, the computer executes the technical solution of the code migration method for front-end framework upgrade in the above embodiment.
[0080] An embodiment of the present application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. At least one processor can read the computer program from the computer-readable storage medium. When at least one processor executes the computer program, it can implement the technical solution of the code migration method for front-end framework upgrade in the above embodiment.
[0081] In the process of implementation, the computer program product can be written in one or more programming languages or a combination thereof to perform the computer program code of the present application, and the programming language includes an object-oriented programming language, such as Java, Smalltalk, C++, and also includes a conventional procedural programming language, such as "C" language or similar programming language. The program code can be executed completely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on the remote computer, or completely on the remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).
[0082] Note that the above are only preferred embodiments of the present application and the technical principles used. Those skilled in the art will understand that the present application is not limited to the specific embodiments herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present application. Therefore, although the present application is described in more detail through the above embodiments, the present application is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present application, and the scope of the present application is determined by the scope of the appended claims.
Claims
1. A code migration method for front-end framework upgrade, characterized in that: include: Read the JavaScript file in the folder of the current page and determine the type of the JavaScript file, wherein the current page is a front-end page developed under the vue2 framework; In response to the type of the JavaScript file being a page file, identifying a target method in the page file through a pre-configured target function, and intercepting parameters of the target method; Obtain the input parameter object of the parameter, and parse the input parameter object to obtain the template information and attribute information of the target object; According to the grammatical rules of the target framework, the template information and the attribute information are grammatically converted to obtain the target file under the target framework, wherein the target framework is the vue3 framework.
2. The method according to claim 1, characterized in that Also includes: In response to the type of the JavaScript file being a configuration file, parsing the interface information and routing information in the configuration file; If the target file under the target framework already exists, the interface information and routing information are respectively merged with the interface information and routing information of the current page in the target file to update the target file.
3. The method according to claim 1, characterized in that Also includes: In the process of traversing all page folders in the project to be migrated, the folders of each page are recursively traversed and hierarchically parsed according to the nested relationship between the pages.
4. The method according to claim 2, characterized in that: Also includes: In the process of traversing all page folders in the project to be migrated, if there is a second page that shares the same configuration file with the current page, determining whether there is currently a processing task for the configuration file corresponding to the second page; If it exists, the processing task of the configuration file corresponding to the current page is put into a queue to be executed, and after the processing task of the configuration file corresponding to the second page is completed, the processing task of the configuration file corresponding to the current page in the queue to be executed is executed.
5. The method according to claim 1, characterized in that Before obtaining the template information and attribute information of the target object by parsing the input parameter object, the method further includes: The template path, JavaScript module import declaration information and variable declaration information of the target object are parsed according to the input parameter object.
6. The method according to claim 1, characterized in that The target object is a vue object.
7. A code migration device for front-end framework upgrade, characterized in that: include: A reading module is used to read the JavaScript file in the folder of the current page and determine the type of the JavaScript file, wherein the current page is a front-end page developed under the vue2 framework; an identification module, for identifying a target method in the page file by a pre-configured target function in response to the type of the JavaScript file being a page file, and intercepting parameters of the target method; A parsing module, used to obtain an input parameter object of the parameter, and parse the input parameter object to obtain template information and attribute information of the target object; The conversion module is used to perform syntax conversion on the template information and attribute information according to the syntax rules of the target framework to obtain the target file under the target framework, wherein the target framework is the vue3 framework.
8. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the code migration method for front-end framework upgrade according to any one of claims 1-6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the code migration method for front-end framework upgrade according to any one of claims 1 to 6.
10. A computer program product, characterized in that It includes a computer program, which, when executed by a processor, implements the code migration method for front-end framework upgrade described in any one of claims 1 to 6.
