Disclosure of Invention
In order to solve the technical problems mentioned in the background art, the invention provides an applet conversion method and device, which can be used for rapidly converting and distributing a wechat applet to other applet platforms as a standard software project, reducing development cost and realizing maximum multiplexing of the wechat applet.
The embodiment of the invention provides the following specific technical scheme:
in a first aspect, an applet converting method for converting a wechat applet into a target applet of a target platform is provided, the method comprising:
converting the plurality of code files of the WeChat applet into a plurality of initial code files supported by the target platform according to the acquired conversion instruction;
determining a plurality of functional components corresponding to the plurality of initial code files, and identifying the component category of each functional component, wherein the component category comprises a general functional component, a functional component to be degraded and a functional component to be replaced;
converting the plurality of initial code files according to a conversion rule corresponding to the component type of each functional component to obtain a plurality of target code files of the target applet;
outputting the plurality of object code files to generate the target applet.
Further, the converting, according to the obtained conversion instruction, the plurality of code files of the wechat applet into a plurality of initial code files supported by the target platform includes:
according to the item directory of the wechat applet carried by the conversion instruction, acquiring a plurality of code files of the wechat applet, wherein the code files comprise a WXML file, a JS file, a WXSS file and a JSON file;
analyzing the code files into syntax trees of tree structures respectively;
and traversing the nodes on each syntax tree, and outputting each processed syntax tree as a plurality of initial code files supported by the target platform.
Further, the syntax tree is a DOM tree.
Further, the identifying the component category of each of the functional components includes:
and determining the component category corresponding to the functional component identification of each functional component according to the mapping relation between the functional component identification and the component category which are created in advance.
Further, the converting the plurality of initial code files according to the conversion rule corresponding to the component type of each functional component to obtain a plurality of object code files of the object applet includes:
if the component type of the functional component is a general functional component, reserving codes corresponding to the functional component in the plurality of initial code files;
if the component type of the functional component is the functional component to be degraded, performing degradation processing on codes corresponding to the functional component in the plurality of initial code files;
and if the component type of the functional component is the functional component to be replaced, replacing the code corresponding to the functional component in the plurality of initial code files with a pre-acquired target code corresponding to the functional component.
In a second aspect, there is provided an applet converting apparatus for converting a wechat applet into a target applet of a target platform, the apparatus comprising:
the first conversion module is used for converting the plurality of code files of the WeChat small program into a plurality of initial code files supported by the target platform according to the acquired conversion instruction;
the determining module is used for determining a plurality of functional components corresponding to the plurality of initial code files;
the identification module is used for identifying the component category of each functional component, and the component category comprises a general functional component, a functional component to be degraded and a functional component to be replaced;
a second conversion module, configured to convert the multiple initial code files according to a conversion rule corresponding to a component category of each functional component, to obtain multiple target code files of the target applet;
an output module to output the plurality of object code files to generate the object applet.
Further, the first conversion module is specifically configured to:
according to the item directory of the wechat applet carried by the conversion instruction, acquiring a plurality of code files of the wechat applet, wherein the code files comprise a WXML file, a JS file, a WXSS file and a JSON file;
analyzing the code files into syntax trees of tree structures respectively;
and traversing the nodes on each syntax tree, and outputting each processed syntax tree as a plurality of initial code files supported by the target platform.
Further, the syntax tree is a DOM tree.
Further, the identification module is specifically configured to:
and determining the component category corresponding to the functional component identifier of each functional component according to the mapping relation between the functional component identifier and the component category which are created in advance.
Further, the second conversion module is specifically configured to:
if the component type of the functional component is a general functional component, reserving codes corresponding to the functional component in the plurality of initial code files;
if the component type of the functional component is the functional component to be degraded, performing degradation processing on codes corresponding to the functional component in the plurality of initial code files;
and if the component type of the functional component is the functional component to be replaced, replacing the code corresponding to the functional component in the plurality of initial code files with a target code corresponding to the pre-acquired functional component.
In a third aspect, an electronic device is provided, including:
one or more processors;
storage means for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement the applet transforming method as described in the first aspect above.
In a fourth aspect, there is provided a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the applet converting method as described in the first aspect above.
The embodiment of the invention provides an applet converting method and device, which are used for converting a WeChat applet into a target applet of a target platform, firstly converting a plurality of code files of the WeChat applet into a plurality of initial code files supported by the target platform, and determining a plurality of functional components corresponding to the plurality of initial code files; then identifying the component category of each functional component, wherein the component category comprises a general functional component, a functional component to be degraded and a functional component to be replaced; and finally, converting the plurality of initial code files according to a conversion rule corresponding to the component category of each functional component to obtain a plurality of target code files of the target small program, and outputting the plurality of target code files to generate the target small program, so that the small WeChat program can be quickly converted and distributed to other small program platforms as a standard software project, the development cost can be reduced, the maximum multiplexing of the small WeChat program is realized, and the normal development of the small WeChat program project is not influenced.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The embodiment of the invention provides an applet converting method, which is used for converting a WeChat applet into a target applet of a target platform. The server may be an independent server or a server cluster composed of a plurality of servers. The method can be used for converting and distributing the WeChat small program to other small program platforms as a standard software project, not only can reduce the development cost and realize the maximum multiplexing of the WeChat small program, but also can not influence the normal development of the WeChat small program project. The target platform in the embodiment of the present invention may be a hundred-degree applet platform, a byte-jumping applet platform, or another applet platform.
Example one
An embodiment of the present invention provides an applet converting method, configured to convert a WeChat applet into a target applet of a target platform, and referring to fig. 1, the method includes the following steps:
and S1, converting a plurality of code files of the WeChat applet into a plurality of initial code files supported by a target platform according to the acquired conversion instruction.
The conversion instruction is used for indicating the conversion of the wechat applet into the target applet of the target platform, and the conversion instruction carries the project name and the directory path of the wechat applet, the project name and the release directory path of the target applet.
In practical application, an interface of the applet converter can be provided for a user, so that the user can input the item name and the directory path of the applet and the item name and the release directory path of the target applet on the interface of the applet converter, and generate a conversion instruction after the user clicks a conversion key on the interface to start conversion processing. The applet converter can be started in a command line mode by using npm, and the configuration of the applet converter is stored in a js file form and is output in a module form.
The plurality of code files of the WeChat applet comprise a WXML file, a JS file, a WXSS file and a JSON file.
Specifically, the WXML file is a WXML template file using WXML as suffix, and WXML (WeiXin Markup Language) is a set of tag languages designed by a framework, and a structure of a page can be constructed by combining a basic component and an event system. The JS file is a JS script logic file taking JS as suffix, and can monitor and process the life cycle function of the WeChat applet and declare a global variable in the JS file. The WXSS file is a WXSS Style file with WXSS as a suffix, the WXSS (WeiXin Style Sheets) is a set of Style languages and is used for describing the component styles of the WXML, and the WXSS is used for determining how the components of the WXML should be displayed. The JSON file is a JSON configuration file taking JSON as a suffix, which pages of the applet are composed can be configured in the JSON file, the window background color of the applet is configured, the style of the navigation bar is configured, the default title is configured, and the like.
Specifically, the implementation process of step S1 may include:
and S11, acquiring a plurality of code files of the WeChat applet, including a WXML file, a JS file, a WXSS file and a JSON file, according to the item directory of the WeChat applet carried by the conversion instruction.
Specifically, a NodeJS + FS + PATH library is used for carrying out full scanning on the project directory, extracting the WXML file, the JS file, the WXSS file and the JSON file for carrying out page grouping, and reading text contents in each code file.
And S12, respectively analyzing the code files into a syntax tree with a tree structure, performing traversal processing on nodes on the syntax tree, and outputting the processed syntax tree as a plurality of initial code files supported by a target platform.
Wherein, the syntax tree is a DOM syntax tree.
Specifically, the plurality of code files are respectively analyzed into DOM (document object model) syntax trees, nodes on each DOM syntax tree are traversed, each node is converted according to a syntax conversion library between the WeChat applet platform and the target platform, and the converted DOM syntax trees are output as a plurality of initial code files supported by the target platform.
Exemplarily, taking a hundredth applet as an example, in the development environment of the hundredth applet, the engineering files are divided into four types of SWAN, CSS, JS and JSON, where SWAN is similar to the WXML file of the wechat applet and is also an XML syntax. However, grammars such as logic judgment and circulation of the SWAN file of the Baidu applet on the XML are different from writing methods and using methods of the WXML file of the WeChat applet on the XML. And therefore this difference needs to be corrected. When the WXML file is modified, firstly, the WXML file is analyzed into a DOM tree, then, leaf nodes on the DOM tree are traversed, checked and modified according to an XML grammar conversion rule between the WXML file and the SWAN file, and then, the DOM tree is output as the SWAN file. After the WXSS file is analyzed into a DOM tree, leaf nodes on the DOM tree are subjected to traversal check and modification according to CSS syntax conversion rules between the WXSS file and the CSS file, then the DOM tree is output to be the CSS file, and a JS file and a JSON file of the WeChat applet are obtained by adopting a similar syntax conversion mode based on the JS file and the JSON file of the WeChat applet.
In this embodiment, the structure can be ensured to be complete by using the DOM tree for syntax transformation, and the output content is highly readable. And the whole project of the WeChat applet is organized into a project tree according to the dependency relationship, and then view correction and model correction are performed according to the characteristics of the conversion target platform, so that the WeChat applet can be suitable for converting to different applet platforms.
And S2, determining a plurality of functional components corresponding to the plurality of initial code files, and identifying the component types of the functional components, wherein the component types comprise a general functional component, a functional component to be degraded and a functional component to be replaced.
Specifically, the determining the implementation process of the plurality of functional components corresponding to the plurality of initial code files may include:
and reading codes in each initial code file, and determining a plurality of corresponding functional components.
Specifically, the implementation process of identifying the component category of each functional component in step S2 may include:
and determining the component category corresponding to the functional component identification of each functional component according to the mapping relation between the functional component identification and the component category which are created in advance.
The functional components of the wechat applet and the functional components supported by the target platform can be compared in advance, and the mapping relation between the functional component identification and the component type of the wechat applet is established according to the comparison result.
The general functional component means that a certain functional component of the WeChat applet can be directly used as a functional component of the hundred applet. For example, both the wechat applet and the hundredth applet have "commodity details" in the shopping function, and the functional component corresponding to the "commodity details" is a general functional component.
The functional component to be degraded refers to a function that the function of a certain functional component of the wechat applet exceeds the function supported by the MVVM framework, that is, when the functional component supported by the target platform is only matched with the functional part of the functional component of the wechat applet, the functional component is the functional component to be degraded. For example, the hundredth applet does not have the WXS function of the WeChat applet, but has a similar filter function, and the functional component corresponding to the WXS is the functional component to be degraded.
The functional component to be replaced is a functional component which is developed by customizing a certain functional component of the WeChat applet aiming at a special service scene, and when the functions of the functional component supported by the target platform and the functional component of the WeChat applet are not matched completely, the functional component is the functional component to be replaced. For example, a user login scene has a large platform difference between a WeChat applet and a Baidu applet, a functional component corresponding to the user login scene is a functional component to be replaced, and for example, functional components corresponding to service scenes such as payment, point burying, risk control and the like are also functional components to be replaced.
And S3, converting the plurality of initial code files according to the conversion rule corresponding to the component type of each functional component to obtain a plurality of target code files of the target small program.
Specifically, the implementation process of step S3 may include:
if the component type of the functional component is the general functional component, reserving codes corresponding to the functional component in a plurality of initial code files;
if the component type of the functional component is the functional component to be degraded, performing degradation processing on codes corresponding to the functional component in a plurality of initial code files;
and if the component type of the functional component is the functional component to be replaced, replacing the code corresponding to the functional component in the plurality of initial code files with the target code corresponding to the pre-acquired functional component.
When the codes corresponding to the general-purpose functional components are reserved, the corresponding codes can be directly used as codes in the code file of the target small program.
When the code corresponding to the functional component to be degraded is subjected to degradation processing, the view and the data can be directly bound, that is, the degradation processing is performed according to the lowest level of degradation conversion. For example, in a hundredth applet, which does not have the WXS function owned by the WeChat applet, but has a similar filter function, firstly, the WXS can be parsed and converted (CMD = > ES 6-MODELE), then the tag in xml is changed to < WXS > as < filter >, and the original configuration is invoked to realize demotion. For another example, SWAN files in the Baidu applet do not support coexistence of two instructions for/if in the same tag, and such instruction nodes are searched and split into two instruction nodes during the demotion processing, so as to implement demotion.
In the above example process, the WXS function in the wechat applet is demoted, and the WXS data snoop is converted into the component data snoop, so that the component data snoop conforms to the MVVM general rule, and the conversion product can be used in any MVVM framework.
When the code corresponding to the functional component to be replaced is replaced, the code corresponding to the functional component to be replaced can be replaced by a target code corresponding to a pre-acquired functional component in a plurality of initial code files, wherein the target code is stored in a preset code library after being independently developed. For example, in a user login scenario, a large platform difference exists between a hundred-degree applet and a WeChat applet, so that login processes of the hundred-degree applet and the WeChat applet are very different, the object code in the hundred-degree applet is separately developed and stored in a preset code library, the object code is called in a conversion process, codes corresponding to functional components to be replaced in the WeChat applet are directly covered, and in addition, similar processing is required for services such as payment, point burying, risk control and the like.
And S4, outputting a plurality of object code files to generate the object small program.
Specifically, the target applet is generated by outputting the plurality of target code files to a release directory path of the target applet. Wherein, a plurality of object code files of the object small program have the same path and file name, so as to facilitate the developer to reduce configuration items.
Exemplarily, the SWAN file, the CSS file, the JS file, and the JSON file obtained by the conversion are exported to a distribution directory path of the hundred-degree applet to generate the hundred-degree applet.
The applet converting method provided by the embodiment of the invention is used for converting a WeChat applet into a target applet of a target platform, firstly converting a plurality of code files of the WeChat applet into a plurality of initial code files supported by the target platform, and determining a plurality of functional components corresponding to the plurality of initial code files; then identifying the component category of each functional component, wherein the component category comprises a general functional component, a functional component to be degraded and a functional component to be replaced; and finally, converting the plurality of initial code files according to a conversion rule corresponding to the component category of each functional component to obtain a plurality of target code files of the target small program, and outputting the plurality of target code files to generate the target small program, so that the micro-messaging small program can be quickly converted and distributed to other small program platforms as a standard software project, development cost can be reduced, the maximum multiplexing of the micro-messaging small program is realized, and meanwhile, the normal development of the micro-messaging small program project is not influenced.
Example two
An embodiment of the present invention provides an applet converting apparatus, configured to convert a WeChat applet into a target applet of a target platform, and referring to fig. 2, the apparatus includes the following:
the first conversion module 21 is configured to convert, according to the obtained conversion instruction, the multiple code files of the WeChat applet into multiple initial code files supported by the target platform;
a determining module 22, configured to determine a plurality of functional components corresponding to the plurality of initial code files;
the identification module 23 is used for identifying the component category of each functional component, wherein the component category comprises a general functional component, a functional component to be degraded and a functional component to be replaced;
the second conversion module 24 is configured to convert the multiple initial code files according to a conversion rule corresponding to the component type of each functional component to obtain multiple target code files of the target applet;
and an output module 25, configured to output a plurality of object code files to generate an object applet.
Further, the first conversion module 21 is specifically configured to:
according to the item directory of the WeChat applet, acquiring a plurality of code files of the WeChat applet, wherein the code files comprise a WXML file, a JS file, a WXSS file and a JSON file;
respectively analyzing the plurality of code files into a syntax tree of a tree structure;
and traversing the nodes on each syntax tree, and outputting each processed syntax tree as a plurality of initial code files supported by the target platform.
Further, the syntax tree is a DOM tree.
Further, the identification module 23 is specifically configured to:
and determining the component category corresponding to the functional component identification of each functional component according to the mapping relation between the functional component identification and the component category which are created in advance.
Further, the second conversion module 24 is specifically configured to:
if the component type of the functional component is a universal functional component, reserving codes corresponding to the functional component in a plurality of initial code files;
if the component type of the functional component is the functional component to be degraded, performing degradation processing on codes corresponding to the functional component in a plurality of initial code files;
and if the component type of the functional component is the functional component to be replaced, replacing the code corresponding to the functional component in the plurality of initial code files with the target code corresponding to the pre-acquired functional component.
The applet converting apparatus provided in this embodiment of the present invention is similar to the applet converting method provided in the embodiment of the present invention, and is capable of executing the applet converting method provided in the embodiment of the present invention. For details of the applet conversion method provided in the embodiments of the present invention, details thereof are not described herein.
In addition, an embodiment of the present invention further provides an electronic device, including:
one or more processors;
storage means for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement the applet transforming method as described in the first aspect above.
Furthermore, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, which when executed by a processor implements the applet converting method according to the first aspect.
All the above-mentioned optional technical solutions can be combined arbitrarily to form the optional embodiments of the present invention, and are not described herein again.
As will be appreciated by one of skill in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, embodiments of the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
Embodiments of the present invention are described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including the preferred embodiment and all changes and modifications that fall within the true spirit and scope of the embodiments of the present invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.