CN114064003A - Applet generation method, apparatus, device and storage medium - Google Patents

Applet generation method, apparatus, device and storage medium Download PDF

Info

Publication number
CN114064003A
CN114064003A CN202111358314.5A CN202111358314A CN114064003A CN 114064003 A CN114064003 A CN 114064003A CN 202111358314 A CN202111358314 A CN 202111358314A CN 114064003 A CN114064003 A CN 114064003A
Authority
CN
China
Prior art keywords
file
syntax tree
abstract syntax
target
applet
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111358314.5A
Other languages
Chinese (zh)
Inventor
朱桂锋
林挺
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
WeBank Co Ltd
Original Assignee
WeBank Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by WeBank Co Ltd filed Critical WeBank Co Ltd
Priority to CN202111358314.5A priority Critical patent/CN114064003A/en
Publication of CN114064003A publication Critical patent/CN114064003A/en
Priority to PCT/CN2022/102158 priority patent/WO2023087720A1/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/37Compiler construction; Parser generation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/447Target code generation

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The application provides an applet generating method, an applet generating device, an applet generating equipment and a storage medium. And correspondingly storing the codes in the component files to the temporary files respectively, wherein each temporary file comprises a WXML temporary file, a JS temporary file and a WXSS temporary file. And converting the codes in each temporary file according to a preset conversion strategy to obtain each applet component file, completing the conversion from the VUE component to the applet component, and generating the applet according to each applet component file. The conversion is carried out based on the preset conversion strategy to obtain the small program components, so that the efficiency of obtaining each small program component and generating the small program is effectively improved, the granularity of the modifiable content is smaller, the correctness of the small program components is guaranteed, the corresponding relation between the codes before and after modification can be obtained, and the follow-up maintenance is facilitated.

Description

Applet generation method, apparatus, device and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a storage medium for generating an applet.
Background
The WeChat applet, abbreviated as the applet, is an application which can be used without downloading and installing, and a user can open the application in a scanning or searching mode, so that an instant use concept is embodied and is widely used. At present, the applet cannot load the content such as HTML (hypertext Markup Language) pages, and the HTML pages need to be opened in the use process of the applet, so that the applet components need to be generated according to the components used by the existing HTML pages.
The HTML page may be formed using VUE components, the file contents of which include HTML template files, javascript (js) files, and Cascading Style Sheets (CSS) files. There are currently two ways to obtain an applet component from a VUE component. One is to replace each single file component in the VUE component with a corresponding component required by the applet by adopting a manual replacement mode, and create a new applet json (javascript Object notification) configuration file. The other is to replace the VUE component with an applet component by a regular expression.
However, the two existing methods have disadvantages, for example, the manual replacement method is inefficient, the accuracy of the replacement result cannot be guaranteed, manual detection is required, the position of the code after replacement is difficult to record, and the code before and after replacement lacks a corresponding relationship, so that the position where an error occurs needs to be manually positioned in the subsequent modification and maintenance stage, and when an error occurs in a syntax level, tool assistance is lacked, and repeated development of the same function is caused. The code processing is relatively rough and uniform through the regular expression replacement mode, the problem location time is long, and when long character strings are encountered, the efficiency of the regular expression is low. It can be seen that a need exists for an applet generation method that overcomes the above-mentioned deficiencies of the prior art in generating applet components from VUE components.
Disclosure of Invention
The application provides an applet generating method, an applet generating device and a storage medium, and the applet generating method is used for overcoming the technical defects existing in the existing method that manual replacement or regular expression replacement is adopted to replace a VUE component.
In a first aspect, the present application provides an applet generating method, including:
reading a VUE component by using a preset asynchronous reading tool to obtain each component file in the VUE component, wherein each component file comprises a page file, a JS file and a CSS file of a cascading style sheet;
correspondingly storing the codes in each component file into each temporary file respectively, wherein each temporary file comprises a micro beacon markup language WXML temporary file, a JS temporary file and a micro message cascading style sheet WXSS temporary file;
and converting codes in each temporary file according to a preset conversion strategy to correspondingly obtain each small program component file so as to generate a small program according to each small program component file, wherein the preset conversion strategy comprises traversing each node of each abstract syntax tree to modify a target node of each abstract syntax tree, and each abstract syntax tree is correspondingly formed for the codes in each temporary file.
In a possible design, the converting the code in each temporary file according to a preset conversion policy to obtain each applet component file correspondingly includes:
converting the codes in the WXML temporary file according to a first preset conversion rule to generate a WXML target file;
converting the codes in the JS temporary file according to a second preset conversion rule to generate a JS target file;
converting the codes in the WXSS temporary file according to a third preset conversion rule to generate a WXSS target file;
wherein the preset transformation policy includes the first preset transformation rule, the second preset transformation rule, and the third preset transformation rule, and each applet component file includes the WXML target file, the JS target file, and the WXSS target file.
In one possible design, the converting codes in the WXML temporary file according to a first preset conversion rule to generate a WXML target file includes:
reading the WXML temporary file by using the preset asynchronous reading tool to obtain codes in the WXSS temporary file;
analyzing codes in the WXML temporary file by using a page analyzer to obtain a first abstract syntax tree, wherein the first abstract syntax tree comprises descriptions of all contents in the page file;
modifying the first abstract syntax tree according to the first preset conversion rule to obtain a first target abstract syntax tree;
and generating a first target code according to the first target abstract syntax tree, and obtaining the WXML target file according to the first target code.
In one possible design, the modifying the first abstract syntax tree according to the first preset transformation rule to obtain a first target abstract syntax tree includes:
traversing the first abstract syntax tree to obtain a form label, and replacing the label content in the form label according to a preset label mapping table;
modifying a target node of the first abstract syntax tree according to a format modification rule;
determining a first abstract syntax tree which is replaced by the preset label mapping table and modified by the format modification rule as the first target abstract syntax tree;
wherein the first preset conversion rule includes the preset label mapping table and the format modification rule.
In one possible design, the format modification rule includes:
modifying a column rendering format in the first abstract syntax tree into an applet list rendering format;
modifying the conditional rendering format in the first abstract syntax tree into an applet conditional rendering format;
and modifying the event binding format in the first abstract syntax tree into an applet event binding format.
In one possible design, the converting codes in the JS temporary file according to a second preset conversion rule to generate the JS target file includes:
reading the JS temporary file by using the preset asynchronous reading tool so as to obtain a code in the JS temporary file;
analyzing the codes in the JS temporary file by using an analysis plug-in to obtain a second abstract syntax tree, wherein the second abstract syntax tree comprises descriptions of all contents in the JS file;
modifying the second abstract syntax tree according to the second preset conversion rule to obtain a second target abstract syntax tree;
and generating a second target code according to the second target abstract syntax tree, and obtaining the JS target file according to the second target code.
In one possible design, the modifying the second abstract syntax tree according to the second preset transformation rule to obtain a second target abstract syntax tree includes:
and traversing the second abstract syntax tree, and modifying a target node of the second abstract syntax tree according to an attribute modification rule to obtain the second target abstract syntax tree, wherein the second preset conversion rule comprises the attribute modification rule.
In one possible design, the attribute modification rule includes:
acquiring the attribute and the value of a return function, and replacing the return data of the return function with the attribute and the value of the return function to modify the definition of the data attribute in the second abstract syntax tree, wherein the return data of the return function is the definition of the data attribute in the second abstract syntax tree before modification;
respectively modifying the props attribute definition in the second abstract syntax tree and the definition mode corresponding to the default attribute value into a target attribute definition and a target definition mode, wherein the target attribute definition and the target definition mode meet the attribute definition requirement of the applet;
modifying the data reading mode of the second abstract syntax tree into a target reading mode, wherein the target reading mode meets a life cycle hook function of the applet;
and modifying the assignment expression in the second abstract syntax tree into a small program execution function mode.
In one possible design, the transforming the code in the WXSS temporary file according to a third preset transformation rule to generate a WXSS target file includes:
reading the WXSS temporary file by using the preset asynchronous reading tool to obtain codes in the WXSS temporary file;
analyzing codes in the WXSS temporary file by using a syntax analyzer to obtain a third abstract syntax tree, wherein the third abstract syntax tree comprises descriptions of all contents in the CSS label;
traversing and modifying the third abstract syntax tree according to the third preset conversion rule to obtain a third target abstract syntax tree;
and generating a third target code according to the third target abstract syntax tree, and obtaining the WXSS target file according to the third target code.
In one possible design, traversing and modifying the third abstract syntax tree according to the third preset transformation rule to obtain a third target abstract syntax tree includes:
traversing the third abstract syntax tree, and modifying the third abstract syntax tree according to a selector modification rule to obtain the third target abstract syntax tree, wherein the third preset conversion rule comprises the selector modification rule.
In one possible design, the selector modifies a rule comprising:
modifying the measurement unit declared by a target selector in the third abstract syntax tree into a target measurement unit, wherein the target measurement unit meets the adaptive size unit of the small program;
logging a limited selector, the limited selector being any selector in the third abstract syntax tree that is not supported by the applet.
In one possible design, after obtaining the applet component files, the method further includes:
and generating an information file according to the codes in the JS target file, wherein the information file is used for recording the position information of the codes of all the applet component files in the codes of the VUE components.
In one possible design, before the reading the VUE component using the default asynchronous reading tool, the method further includes:
and generating a work instruction according to the component generation requirement, and responding to the work instruction to run a command line tool, wherein the command line tool is used for starting the applet generation method.
In a second aspect, the present application provides an applet generating apparatus, comprising:
the acquisition module is used for reading the VUE component by using a preset asynchronous reading tool to obtain each component file in the VUE component, wherein each component file comprises a page file, a JS file and a Cascading Style Sheet (CSS) file;
the storage module is used for correspondingly storing the codes in the component files into temporary files respectively, and each temporary file comprises a micro beacon markup language WXML temporary file, a JS temporary file and a micro message cascading style sheet WXSS temporary file;
and the processing module is used for converting the codes in each temporary file according to a preset conversion strategy to correspondingly obtain each small program component file so as to generate a small program according to each small program component file, wherein the preset conversion strategy comprises traversing each node of each abstract syntax tree to modify a target node of each abstract syntax tree, and each abstract syntax tree is correspondingly formed for the codes in each temporary file.
In a third aspect, the present application provides an electronic device, comprising:
a processor; and the number of the first and second groups,
a memory for storing a computer program for the processor;
wherein the processor is configured to implement any one of the possible applet generating methods provided by the first aspect via execution of the computer program.
In a fourth aspect, the present application provides a computer-readable storage medium, on which a computer program is stored, which, when executed by a processor, implements any one of the possible applet generating methods provided in the first aspect.
In a fifth aspect, the present application further provides a computer program product comprising a computer program that, when executed by a processor, implements any one of the possible applet generating methods provided in the first aspect.
The application provides an applet generating method, device, equipment and storage medium. And correspondingly storing the codes in each component file to each temporary file respectively, wherein each temporary file comprises a micro beacon markup language WXML temporary file, a JS temporary file and a micro message cascading style sheet WXSS temporary file. And finally, converting the codes in each temporary file according to a preset conversion strategy to obtain each applet component file, completing the conversion from the VUE component to the applet component, and further generating the applet according to each applet component file. And the preset conversion strategy comprises traversing each node of each abstract syntax tree to modify a target node of each abstract syntax tree, wherein each abstract syntax tree is correspondingly formed by codes in each temporary file. The conversion is carried out based on the preset conversion strategy to obtain the small program components, so that the efficiency of obtaining each small program component and generating the small program is effectively improved, the granularity of the modifiable content is smaller, the correctness of the obtained small program components is guaranteed, the corresponding relation between the codes before and after modification can be obtained, and the follow-up maintenance is facilitated.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present application, and for those skilled in the art, other drawings can be obtained according to these drawings without inventive exercise.
Fig. 1 is a schematic view of an application scenario provided in an embodiment of the present application;
fig. 2 is a schematic flowchart of an applet generating method according to an embodiment of the present application;
FIG. 3 is a schematic diagram of a file storage according to an embodiment of the present application;
fig. 4 is a schematic flowchart of another applet generating method provided in an embodiment of the present application;
fig. 5 is a schematic flowchart of another applet generating method according to an embodiment of the present application;
fig. 6 is a schematic flowchart of another applet generating method provided in the embodiment of the present application;
fig. 7 is a schematic flowchart of another applet generating method provided in the embodiment of the present application;
fig. 8 is a schematic structural diagram of an applet generating apparatus according to an embodiment of the present application;
fig. 9 is a schematic structural diagram of a processing module according to an embodiment of the present disclosure;
fig. 10 is a schematic structural diagram of an electronic device provided in the present application.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Rather, they are merely examples of methods and apparatus consistent with certain aspects of the present application, as detailed in the appended claims.
The terms "first," "second," "third," "fourth," and the like in the description and in the claims of the present application and in the above-described drawings (if any) are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the application described herein are, for example, capable of operation in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
Since the applet cannot load contents such as HTML (hypertext Markup Language) pages, and the HTML pages need to be opened during the use of the applet, the applet components need to be generated from components used by the existing HTML pages. The HTML page may be formed using VUE components, including HTML templates, JavaScript (JS) components, and Cascading Style Sheets (CSS) components. There are currently two ways to obtain an applet component from a VUE component. One is to replace each single file component in the VUE component with a corresponding component required by the applet by adopting a manual replacement mode, and to create an applet json (javascript Object notification) configuration file. The other is to replace the VUE component with an applet component by a regular expression. However, the two methods have the problems of low conversion efficiency, incapability of ensuring correctness, difficulty in positioning in a maintenance stage due to lack of corresponding relation of codes before and after replacement and the like.
In view of the above problems in the prior art, the present application provides an inventive concept of a applet generating method, which includes: and correspondingly storing codes in each component file included by the VUE component into each temporary file, converting the codes in each temporary file by using a preset conversion strategy to correspondingly obtain each applet component file, completing the conversion from the VUE component to the applet component, and further generating the applet according to each applet component file. The method comprises the steps of obtaining a VUE component, converting the VUE component into a small program component, wherein the preset conversion strategy comprises traversing each node of each abstract syntax tree to modify a target node of each abstract syntax tree, and each abstract syntax tree is formed by corresponding codes in each temporary file.
An exemplary application scenario of the embodiments of the present application is described below.
Fig. 1 is a schematic view of an application scenario provided in an embodiment of the present application. As shown in fig. 1, the network is used to provide a medium for a communication link between the server 11 and the terminal device 12. The network may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few. The server 11 and the terminal device 12 may interact with each other via a network to receive or transmit messages. The server 11 may be configured to execute the corresponding electronic device of the applet generating method provided in the embodiment of the present application, and the terminal device 12 may run the generated applet. The applet generating method provided by the embodiment of the present application is executed by the server 11 to convert the VUE components into applet components, and further generate an applet, so that an applet, for example, an HTML page formed by the VUE components can be loaded on the terminal device 12.
In the embodiment of the present application, types of the server 11 and the terminal device 12 in the above description are not limited, for example, the server 11 may also be a server cluster, the terminal device 12 may be a smart phone, smart glasses, a smart bracelet, a smart watch, a tablet computer, and the like, and the terminal device 12 in fig. 1 is illustrated by taking a smart phone as an example.
It should be noted that the above application scenarios are only exemplary, and the applet generating method, apparatus, device and storage medium provided in the embodiments of the present application include, but are not limited to, the above application scenarios.
The following describes the technical solutions of the present application and how to solve the above technical problems with specific embodiments. The following several specific embodiments may be combined with each other, and details of the same or similar concepts or processes may not be repeated in some embodiments. Embodiments of the present application will be described below with reference to the accompanying drawings.
Fig. 2 is a schematic flowchart of an applet generating method according to an embodiment of the present disclosure. As shown in fig. 2, the applet generating method provided in the embodiment of the present application includes:
s101: and reading the VUE component by using a preset asynchronous reading tool to obtain each component file in the VUE component.
Each component file comprises a page file, a JS file and a Cascading Style Sheet (CSS) file.
And reading the file content of the VUE component by using a preset asynchronous reading tool to obtain each component file in the VUE component. Wherein the VUE component is an abstract data type of view and interaction logic, which contains HTML templates, CSS styles, and JS logical code fragments, the VUE component can be compiled into executable H5 code using, for example, the VUE-loader plug-in of the webpack packaging tool.
In the embodiment of the application, the VUE component is read through the preset asynchronous reading tool, and each component file is obtained according to the content contained in the VUE component, namely the page file, the JS file and the CSS file of the cascading style sheet are obtained. The page file can be understood as a file for storing codes of an HTML template, the JS file can be understood as a file for storing JS logic code segments, and the CSS file can be understood as a file for storing codes of CSS styles. Therefore, by reading the file content of the VUE component, component files can be obtained according to the file content contained in the VUE component, and each component file is shown in the left part of fig. 3, and fig. 3 is a file storage diagram provided by the embodiment of the present application.
Readfilesync, for example, may be used to asynchronously read the contents of each part of a file contained in a VUE file.
In one possible design, before reading the VUE component using the default asynchronous reading tool, the method further includes:
and generating a work instruction according to the component generation requirement, and executing a command line tool in response to the work instruction, wherein the command line tool is used for enabling the applet generation method provided by the embodiment of the application. It can be appreciated that component generation requirements are used to characterize the currently existing component conversion requirements, requiring conversion of existing VUE components. Further, an auxiliary tool may be set, and the VUE component is converted by the auxiliary tool, where the auxiliary tool is a command line tool capable of enabling the applet generating method provided in the embodiment of the present application in response to the work instruction. The working prompt corresponding to the command line tool may be set according to an actual situation, and the embodiment of the present application is not limited thereto.
S102: and correspondingly storing the codes in the component files to the temporary files respectively.
Wherein, each temporary file comprises a micro beacon Language (WeiXin Markup Language) WXML temporary file, a JS temporary file and a Weixinststyles sheet (WeixinStyle Sheets) WXSS temporary file.
In order to enable the codes of the VUE components before and after conversion to have clear corresponding relations and ensure the correctness of each applet component obtained after conversion, the codes in each component file obtained according to the VUE components can be respectively and correspondingly stored in each temporary file, and then the codes in each temporary file are respectively converted.
For example, based on the correspondence between the codes in each component file and the codes in each applet component file to be finally converted, the codes in the page file may be stored in the WXML temporary file, the codes in the JS file may be stored in the JS temporary file, and the codes in the CSS file may be stored in the WXSS temporary file. Continuing with FIG. 3, the right portion of FIG. 3 shows temporary files to which component files are stored.
Optionally, when the component files are correspondingly stored in the temporary files, the document format in each temporary file may be set according to an actual situation, for example, the document format may be a notepad format, a document format, and the like, which is not limited in this embodiment of the present application.
S103: and converting the codes in each temporary file according to a preset conversion strategy to correspondingly obtain each applet component file so as to generate the applet according to each applet component file.
And the preset conversion strategy comprises traversing each node of each abstract syntax tree to modify a target node of each abstract syntax tree, wherein each abstract syntax tree is correspondingly formed for codes in each temporary file.
When the codes in each temporary file are respectively converted to obtain each small program component file, a preset conversion strategy is introduced to achieve the purpose of traversing each node of each abstract syntax tree to modify the nodes needing to be modified, namely target nodes, and the codes in each temporary file correspondingly form respective abstract syntax trees. And after the codes in each temporary file are converted by the preset conversion strategy, correspondingly determining each converted temporary file as an applet component file, thereby correspondingly obtaining each applet component file. And on the basis of obtaining each applet component file, reading and loading the file content in each obtained applet component file to generate the applet. And the file content in each small program component file is each small program component obtained after conversion. In addition, when the applet is generated, a target file with a JSON suffix needs to be created, and the target file with the JSON suffix is a configuration JSON file of the applet, wherein the file content is { "component": true }.
In a possible design, a possible implementation manner of converting the code in each temporary file according to the preset conversion policy in step S103 to obtain each applet component file is shown in fig. 4. Fig. 4 is a schematic flowchart of another applet generating method according to an embodiment of the present application. As shown in fig. 4, the embodiment of the present application includes:
s201: and converting the codes in the WXML temporary file according to a first preset conversion rule to generate a WXML target file.
S202: and converting the codes in the JS temporary file according to a second preset conversion rule to generate a JS target file.
S203: and transforming the codes in the WXSS temporary file according to a third preset transformation rule to generate a WXSS target file.
The preset conversion strategy comprises a first preset conversion rule, a second preset conversion rule and a third preset conversion rule, and each applet component file comprises a WXML target file, a JS target file and a WXSS target file.
The preset conversion strategy comprises a first preset conversion rule, a second preset conversion rule and a third preset conversion rule, wherein the first preset conversion rule is a specific rule for converting codes in the WXML temporary file, the second preset conversion rule is a specific rule for converting codes in the JS temporary file, and the third preset conversion rule is a specific rule for converting codes in the WXSS temporary file.
Correspondingly, after the codes in the WXML temporary file are converted by the first preset conversion rule, the WXML temporary file is determined as the WXML target file, that is, the codes in the WXML target file are the codes converted by the first preset conversion rule. And after the codes in the JS temporary file are converted by a second preset conversion rule, determining the JS temporary file as a JS target file, namely determining the codes in the JS target file as the codes converted by the second preset conversion rule. And after the codes in the CSS temporary file are converted by a third preset conversion rule, determining the CSS temporary file as a CSS target file, namely, the codes in the CSS target file are the codes converted by the third preset conversion rule.
It should be noted that the specific content of each of the first preset conversion rule, the second preset conversion rule, and the third preset conversion rule is a code required for converting a code in each temporary file into a corresponding applet component, and when the first preset conversion rule, the second preset conversion rule, and the third preset conversion rule are adopted, the abstract syntax tree formed by the code in each temporary file is used, so that the conversion from the code in each temporary file to the corresponding applet code is realized by traversing each node of each abstract syntax tree and modifying a target node of each abstract syntax tree, the conversion efficiency is improved, the modifiable content granularity is smaller, and the modification correctness is further ensured. The target node of each abstract syntax tree is the node where the VUE component and the applet component are different.
Further, after the applet component files are obtained, an information file is generated according to codes in the JS target file, and the information file is adopted to record position information of the codes of the applet component files in the codes of the VUE components, so that later debugging is facilitated.
According to the applet generating method provided by the embodiment of the application, firstly, a VUE component is read by using a preset asynchronous reading tool, and each component file in the VUE component is obtained and comprises a page file, a JS file and a CSS file. And correspondingly storing the codes in the component files to temporary files respectively, wherein each temporary file comprises a WXML temporary file, a JS temporary file and a WXSS temporary file. And finally, converting the codes in each temporary file according to a preset conversion strategy to obtain each applet component file, completing the conversion from the VUE component to the applet component, and further generating the applet according to the file content in each applet component file. And the preset conversion strategy comprises traversing each node of each abstract syntax tree to modify a target node of each abstract syntax tree, wherein each abstract syntax tree is correspondingly formed by codes in each temporary file. The conversion is carried out based on the preset conversion strategy to obtain the small program components, so that the efficiency of obtaining each small program component and generating the small program is effectively improved, the granularity of the modifiable content is smaller, the correctness of the obtained small program components is guaranteed, the corresponding relation between the codes before and after modification can be obtained, and the follow-up maintenance is facilitated.
In one possible design, a possible implementation of step S201 is shown in fig. 5. Fig. 5 is a flowchart illustrating a further applet generating method according to an embodiment of the present application. As shown in fig. 5, the embodiment of the present application includes:
s2011: and reading the WXML temporary file by using a preset asynchronous reading tool to obtain codes in the WXML temporary file.
And reading the file content of the WXML temporary file by using a preset asynchronous reading tool so as to obtain the codes in the WXML temporary file, wherein the step is a process of reading the file content of the WXML temporary file by using the preset asynchronous reading tool and converting the read file content into a corresponding character string.
A preset asynchronous read tool may be, for example, fs.
S2012: and analyzing codes in the WXML temporary file by using a page analyzer to obtain a first abstract syntax tree.
Wherein the first abstract syntax tree includes a description of all content in the page file.
And analyzing the codes in the WXML temporary file, namely analyzing the character strings obtained in the above steps, by using a page analyzer such as htmlparser2, and correspondingly obtaining an abstract syntax tree corresponding to the codes in the WXML temporary file, namely a first abstract syntax tree. An Abstract Syntax Tree (AST) is a Tree representation of the Abstract Syntax structure of the source code, and each node on the Tree is structured Abstract data of a corresponding node in the source code. Thus, the first abstract syntax tree defines each part of the page file in detail, i.e. the first abstract syntax tree comprises a description of all the content of the page file.
S2013: and modifying the first abstract syntax tree according to a first preset conversion rule to obtain a first target abstract syntax tree.
And modifying the first abstract syntax tree by adopting a first preset conversion rule, and determining the modified first abstract syntax tree as a first target abstract syntax tree to obtain the first target abstract syntax tree.
As can be seen from the description of the foregoing embodiment, the specific content of the first preset conversion rule is a corresponding rule followed when modifying the code in the WXML temporary file into the code required by the corresponding applet. In the applet, the contents related to the code in the WXML temporary file do not need the contents in the DOCTYPE tag at the top, and only the contents in the body tag need to be focused. In other words, when the first abstract syntax tree is modified by using the first preset conversion rule, only the content of the node of the first abstract syntax tree where the body tag is located needs TO be focused, for example, the body tag may have only one sub-ELEMENT div, and the div has two sub-ELEMENTs, namely, TEXT (TEXT) "VUE TO MP" and a tag (ELEMENT) span, and the tag span has only one sub-ELEMENT, and is "This is detail" of type TEXT (TEXT).
And modifying the first abstract syntax tree according to a first preset conversion rule to obtain an abstract syntax tree which is the first target abstract syntax tree, and executing the step S2014 to obtain the WXML target file.
S2014: and generating a first target code according to the first target abstract syntax tree, and obtaining a WXML target file according to the first target code.
And determining the content represented by the first target abstract syntax tree as a first target code, namely generating the first target code according to the first target abstract syntax tree, determining the file to which the first target code belongs as a WXML target file, namely obtaining the WXML target file according to the first target code, and thus completing the conversion from the codes in the page file in the VUE component to the codes in the WXML target file in the applet component file.
In one possible design, possible implementations of step S2013 include:
and traversing the first abstract syntax tree, obtaining the form label in the first abstract syntax tree, and replacing the label content in the form label according to a preset label mapping table. The form tags are customized for the purpose of describing standard HTML tags in the pagefile that are different from the applet component writing. And modifying the form label by using a preset label mapping table so as to modify the form label into a label supported by the applet. The preset label mapping table is shown in table 1 below:
TABLE 1
Figure BDA0003358067110000131
Figure BDA0003358067110000141
And modifying the target node of the first abstract syntax tree according to the format modification rule, and then determining the first abstract syntax tree which is replaced by the preset expression mapping table and modified by the format modification rule as the first target abstract syntax tree. The first preset conversion rule adopted for modifying the first abstract syntax tree comprises the preset expression mapping table and a format modification rule. The format modification rule includes modifying a target node of the first abstract syntax tree such that the format of the modified code conforms to the specific modifications involved in the applet component requirements.
In one possible design, the format modification rules may include the following:
for example, the column rendering format in the first abstract syntax tree is modified into an applet list rendering format, and specifically, the writing method of the column rendering format in the VUE component is as follows: since (item, index) in list "v-bind" key "needs to be modified into the applet list rendering format: < tag wx: for { { list } } "wx: key ═ index" > < tag >.
For example, the conditional rendering format in the first abstract syntax tree is modified into the applet conditional rendering format, and specifically, the writing method of the conditional rendering format in the VUE component is as follows:
<tag v-if=“a”></tag>
<tag v—else-if=“b”></tag>
<tag v—else></tag>
thus, a writing method modified to the applet conditional rendering format is required, as follows:
<tag wx:if={{a}}></tag>
<tag wx:elif={{b}}></tag>
<tag wx:else></tag>
for example, the event binding format in the first abstract syntax tree is modified into an applet event binding format, and the writing method of the event binding format in the VUE component is as follows: the writing method for modifying the binding format of the applet event into the binding format of the applet event is as follows: < tag binddap ═ doSomething >.
And the node to which the content for representing the list rendering, the condition rendering and the event binding belongs in the first abstract syntax tree is a target node of the first abstract syntax tree.
In the applet generating method provided in the embodiment of the application, codes in the WXML temporary file are converted according to a first preset conversion rule to obtain a WXML target file, and the codes in the WXML target file are used for representing a WXML template in an applet component. The target node of the first abstract syntax tree is modified by traversing the first abstract syntax tree and according to a preset tag mapping table and a format modification rule included by the first preset conversion rule, so that codes in the WXML target file obtained after modification meet the operation requirement of the applet, the conversion efficiency from codes in a page file in the VUE component to codes in the WXML target file is improved, the modifiable content granularity is smaller, the correctness of the codes in the obtained WXML target file is guaranteed, the corresponding relation between the codes in the page file and the codes in the WXML target file, namely the codes before and after modification, is guaranteed, and the subsequent code maintenance and error positioning are facilitated.
In one possible design, a possible implementation of step S202 is shown in fig. 6. Fig. 6 is a schematic flowchart of another applet generating method according to an embodiment of the present application. As shown in fig. 6, the embodiment of the present application includes:
s2021: and reading the JS temporary file by using a preset asynchronous reading tool so as to obtain a code in the JS temporary file.
And reading the file content of the JS temporary file by using a preset asynchronous reading tool so as to obtain a code in the JS temporary file, wherein the step is a process of reading the file content of the JS temporary file by using the preset asynchronous reading tool and converting the read file content into a corresponding character string.
A preset asynchronous read tool may be, for example, fs.
S2022: and analyzing the codes in the JS temporary file by using an analysis plug-in to obtain a second abstract syntax tree.
Wherein the second abstract syntax tree includes a description of all content in the JS file.
And analyzing the codes in the JS temporary file, namely analyzing the character strings obtained in the steps by adopting a parse method such as @ baseband/parser, and correspondingly obtaining an abstract syntax tree corresponding to the codes in the JS temporary file, namely a second abstract syntax tree. An Abstract Syntax Tree (AST) is a Tree representation of the Abstract Syntax structure of the source code, and each node on the Tree is structured Abstract data of a corresponding node in the source code. Thus, the second abstract syntax tree defines each part of the JS file in detail, i.e. the second abstract syntax tree includes a description of all the content of the JS file.
S2023: and modifying the second abstract syntax tree according to a second preset conversion rule to obtain a second target abstract syntax tree.
And modifying the second abstract syntax tree by adopting a second preset conversion rule, and determining the modified second abstract syntax tree as a second target abstract syntax tree to obtain a second target abstract syntax tree.
As can be seen from the description of the foregoing embodiment, the specific content of the second preset conversion rule is a corresponding rule that is followed when the code in the JS temporary file is modified into the code required by the corresponding applet. The content of the code in the JS file in the VUE component is reflected in the three attributes of data, created and methods, so that the second preset conversion rule can be characterized by setting a corresponding attribute modification rule to modify the second abstract syntax tree.
And modifying the second abstract syntax tree according to a second preset conversion rule to obtain an abstract syntax tree which is the second target abstract syntax tree, and executing the step S2024 to obtain the JS target file.
S2024: and generating a second target code according to the second target abstract syntax tree, and obtaining the JS target file according to the second target code.
And determining the content represented by the second target abstract syntax tree as a second target code, namely generating the second target code according to the second target abstract syntax tree, determining a file to which the second target code belongs as a JS target file, namely obtaining the JS target file according to the second target code, and thus completing the conversion from the codes in the JS file in the VUE component to the codes in the JS target file in the applet component.
In one possible design, the possible implementation manner of step 2023 includes:
and traversing the second abstract syntax tree, modifying the target node of the second abstract syntax tree according to the attribute modification rule, and determining the modified second abstract syntax tree as a second target abstract syntax tree, thereby obtaining a second target abstract syntax tree. The specific content of the second preset conversion rule is a corresponding rule followed when the code in the JS temporary file is modified into the code required by the corresponding applet, and the corresponding rule may specifically include an attribute modification rule.
In one possible design, the attribute modification rules include the following:
for example, the definition of the data attribute in the VUE component is defined by the return data of a return (return) function, but since the object definition is directly used in the applet, for the data attribute, the attribute and the value of the return function are first obtained, and then the data attribute is directly defined by the attribute and the value of the return function, that is, the return data of the return function is replaced by the attribute and the value of the return function, the definition of the data attribute in the second abstract syntax tree is modified, and the return data of the return function is the definition of the data attribute in the second abstract syntax data before modification, that is, in the VUE component corresponding to the VUE component, for example, the definition of the data attribute in the applet component is defined in the form of "key" or "value".
The attribute modification rule further comprises modification of the props attribute definition, for example, the props attribute definition in the second abstract syntax tree and the definition mode corresponding to the default attribute value are modified into a target attribute definition and a target definition mode respectively, wherein the target attribute definition and the target definition mode meet the attribute definition requirement of the applet. Specifically, the definition of the attributes for the prop in the VUE component is as follows:
props:{
mode:{type:Number,default:0}
}。
the property modification rule is to modify the aforementioned "pops" into "properties", the "pops" is a definition of the pops property, the "properties" is a definition of the target property, the "default" is a definition of a corresponding default property value of the pops property definition, the "default" is a modification of the "default" into "value", and the "value" is a target definition mode, which meets the property definition requirement of the applet. Therefore, the definition of the prop attribute in the VUE component, that is, the definition of the prop attribute in the second abstract syntax tree and the definition mode of the corresponding default attribute value are modified by the attribute modification rule, so as to obtain the target attribute definition and the target definition mode which meet the attribute definition requirement of the applet, as follows:
properties:{
mode:{type:Number,value:0}
}。
the attribute modification rule further includes: and modifying the data reading mode of the second abstract syntax tree into a target reading mode, wherein the target reading mode meets the life cycle hook function of the small program. For example, reading data in the VUE component is by directly using "this. And a level is added to the reading of data in the applet component, and the format is "this. When the expression of 'thisaxpression' is encountered while traversing the second abstract syntax tree, the corresponding 'property' is replaced, for example, the expression 'this. name' in the VUE component belongs to 'MemberExpression' in the second abstract syntax tree, where 'this' represents 'thisaxpression' and 'name' represents 'property' of type 'Identifier'. In the applet component, "this.data.name" belongs to "MemberExpression" in the modified second abstract syntax tree, the "this.data" belongs to a sub "MemberExpression", and the "name" is used as a "property" of the "Identifier" type at the same level as the sub "MemberExpression", so that the data reading mode of the second abstract syntax tree is modified to meet the target reading mode of the lifecycle hook function of the applet.
The attribute modification rules also include a manner of modifying the assignment expressions in the second abstract syntax tree into functions for execution by the applet. The VUE component can directly perform assignment, for example, when assignment of "name" is required, the assignment is performed according to the expression "this. However, in applets, the following expression must be used to correctly assign values:
this.setData({
name: 'value'
})。
The evaluation expression in the small program is a small program execution function mode. The setData is built in the applet, and when the assignment expression is modified, the assignment expression in the second abstract syntax tree needs to be modified into a mode of executing the function by the applet. Name is 'value' the definition of the entire expression in the second abstract syntax tree is "expressstate", the subdivision is defined as expression "of the type in the negative value expression" assignementeexpression ", the operation symbol" operator "represents" ═ the name is the left part of the entire assignment expression, and the value is the right part.
And the node to which the attribute modification rule relates and which is partially in the second abstract syntax tree is a target node of the second abstract syntax tree.
According to the small program generating method provided by the embodiment of the application, codes in the JS temporary file are converted according to a second preset conversion rule to obtain the JS target file, and the codes in the JS target file are used for representing JS logic code segments in the small program component. The target node of the second abstract syntax tree is modified by traversing the second abstract syntax tree and according to the attribute modification rule included by the second preset conversion rule, so that the codes in the JS target file obtained after modification meet the operation requirement of the applet, the conversion efficiency from the codes in the JS file in the VUE component to the codes in the JS target file is improved, the granularity of the modifiable content is smaller, the correctness of the codes in the JS target file is ensured, the corresponding relation between the codes in the JS file and the codes in the JS target file, namely, between the codes before and after modification is ensured, and subsequent code maintenance and error positioning are facilitated.
In one possible design, a possible implementation of step S203 is shown in fig. 7. Fig. 7 is a schematic flowchart of another applet generating method according to an embodiment of the present application. As shown in fig. 7, the embodiment of the present application includes:
s2031: and reading the WXSS temporary file by using a preset asynchronous reading tool to obtain codes in the WXSS temporary file.
And reading the file content of the WXSS temporary file by using a preset asynchronous reading tool so as to obtain the codes in the WXSS temporary file, wherein the step is a process of reading the file content of the WXSS temporary file by using the preset asynchronous reading tool and converting the read file content into a corresponding character string.
A preset asynchronous read tool may be, for example, fs.
S2032: and analyzing the codes in the WXSS temporary file by using a syntax analyzer to obtain a third abstract syntax tree.
Wherein the third abstract syntax tree comprises a description of all content in the CSS file.
Analyzing the codes in the WXSS temporary file, namely analyzing the character strings obtained in the step, by using parser such as a cascading style sheet-tree (CSSTREE), and correspondingly obtaining an abstract syntax tree corresponding to the codes in the WXSS temporary file, namely a third abstract syntax tree. An Abstract Syntax Tree (AST) is a Tree representation of the Abstract Syntax structure of the source code, and each node on the Tree is structured Abstract data of a corresponding node in the source code. Thus, the third abstract syntax tree defines each part of the CSS file in detail, i.e. the third abstract syntax tree comprises a description of all the content in the CSS file.
S2033: and modifying the third abstract syntax tree according to a third preset conversion rule to obtain a third target abstract syntax tree.
And modifying the third abstract syntax tree by adopting a third preset conversion rule, and determining the modified third abstract syntax tree as a third target abstract syntax tree to obtain a third target abstract syntax tree.
As can be seen from the description of the foregoing embodiment, the specific content of the third preset transformation rule is a corresponding rule that is followed when the code in the WXSS temporary file is modified into the code required by the corresponding applet.
And modifying the third abstract syntax tree according to a third preset conversion rule to obtain an abstract syntax tree which is a third target abstract syntax tree, and executing the step S2034 to obtain the WXSS target file.
S2034: and generating a third target code according to the third target abstract syntax tree, and obtaining the WXSS target file according to the third target code.
And determining the content represented by the third target abstract syntax tree as a third target code, namely generating the third target code according to the third target abstract syntax tree, determining a file to which the third target code belongs as a WXSS target file, namely obtaining the WXSS target file according to the third target code, and thus completing the conversion from codes in the CSS file in the VUE component to codes in the WXSS target file in the applet component file.
In one possible design, possible implementations of step S2033 include:
and traversing the third abstract syntax tree, modifying the target node of the third abstract syntax tree according to the modification rule of the selector, and determining the modified third abstract syntax tree as a third target abstract syntax tree, thereby obtaining a third target abstract syntax tree. The third preset transformation rule may specifically include a selector modification rule, and the third preset transformation rule is a correspondence rule followed when the code in the WXSS temporary file is modified into the code required by the corresponding applet.
In one possible design, the selector modification rules include the following:
for example, the metric unit declared by the target selector in the third abstract syntax tree is modified to a target metric unit that satisfies the adaptive size unit of each applet. For example, in the VUE component, there is a rule statement, and it is known through the rule statement that a CSS selector of type "classsector" corresponds to a value "params-list-row", and "block" corresponds to a value indicating a CSS selector, for example, the value declares that a bottom margin "padding-bottom" is 10, and the measurement unit of the value is "px". And since the applet uses "rpx" as the measure unit, that is, "rpx" as the target measure unit, which satisfies the adaptive size unit of the applet, the third abstract syntax tree is traversed to modify the target selector, for example, of type "Dimension" and its declared measure unit "px" in the third abstract syntax tree, all in a 1:1 manner to the target measure unit "rpx". And the node to which the content with the type of 'Dimension' and the stated measurement unit of 'px' in the third abstract syntax tree belongs is the target node of the third abstract syntax tree.
Additionally, the selector modification rule further includes utilizing a logging limited selector. For applets, the supported selectors are limited, and if traversing the third abstract syntax tree finds that the third abstract syntax tree includes selectors not supported by applets, the selectors not supported by the applets need to be recorded by using logs, and the selectors not supported by the applets are limited selectors, in other words, the limited selectors can be any selectors not supported by the applets in the third abstract syntax tree.
The selectors supported by the current applet are a Class Selector (Class Selector), an ID Selector (ID Selector), an Element Selector (Type Selector), and a Pseudo Element Selector (Pseudo Element Selector).
The logging is to prompt the developer that the applet uses style rules which are not currently supported, but the applet can be normally compiled, and only the applet has no corresponding effect. For example, "input [ type ]" is an attribute selector (attributesector), which has no effect in applets, but is still compiled normally, prompting the developer in the manner of a log record in generating the WXSS target file.
In the applet generating method provided in the embodiment of the application, codes in the WXSS temporary file are transformed according to a third preset transformation rule to obtain a WXSS target file, and the codes in the WXSS target file are used for representing a WXSS component style in an applet component. And modifying the target node of the third abstract syntax tree by traversing the third abstract syntax tree and according to a selector modification rule included by a third preset conversion rule, so that codes in the modified WXSS target file meet the operation requirement of the applet, thereby not only improving the conversion efficiency from codes in the CSS file in the VUE component to codes in the WXSS target file, but also reducing the granularity of the modifiable content, ensuring the correctness of the codes in the obtained WXSS target file, ensuring the corresponding relationship between the codes in the CSS file and the codes in the WXSS target file, namely the codes before and after modification, and facilitating subsequent code maintenance and error positioning.
Fig. 8 is a schematic structural diagram of an applet generating apparatus according to an embodiment of the present application. As shown in fig. 8, an applet generating apparatus 300 provided in an embodiment of the present application includes:
the obtaining module 301 is configured to read the VUE component by using a preset asynchronous reading tool, and obtain each component file in the VUE component, where each component file includes a page file, a JS file, and a cascading style sheet CSS file.
The storage module 302 is configured to store the codes in each component file into each temporary file, where each temporary file includes a micro beacon markup language WXML temporary file, a JS temporary file, and a micro message cascading style sheet WXSS temporary file.
The processing module 303 is configured to convert the codes in each temporary file according to a preset conversion policy to obtain each applet component file correspondingly, so as to generate an applet according to each applet component file. The pre-set transformation strategy includes traversing each node of each abstract syntax tree to modify a target node of each abstract syntax tree, each abstract syntax tree being formed for code correspondence within each temporary file.
In a possible design, fig. 9 is a schematic structural diagram of a processing module according to an embodiment of the present disclosure. As shown in fig. 9, the processing module 303 in the applet generating apparatus 300 according to the embodiment of the present application includes:
the first processing submodule 3031 is configured to convert codes in the WXML temporary file according to a first preset conversion rule, and generate a WXML target file;
the second processing submodule 3032 is configured to convert the codes in the JS temporary file according to a second preset conversion rule, and generate a JS target file;
and the third processing sub-module 3033 is configured to convert the codes in the WXSS temporary file according to a third preset conversion rule, and generate a WXSS target file.
The preset conversion strategy comprises a first preset conversion rule, a second preset conversion rule and a third preset conversion rule, and each applet component file comprises a WXML target file, a JS target file and a WXSS target file.
In one possible design, the first processing submodule 3031 is specifically configured to:
reading the WXML temporary file by using a preset asynchronous reading tool to obtain codes in the WXSS temporary file;
analyzing codes in the WXML temporary file by using a page analyzer to obtain a first abstract syntax tree, wherein the first abstract syntax tree comprises descriptions of all contents in the page file;
modifying the first abstract syntax tree according to a first preset conversion rule to obtain a first target abstract syntax tree;
and generating a first target code according to the first target abstract syntax tree, and obtaining a WXML target file according to the first target code.
In one possible design, the first processing submodule 3031 is further configured to:
traversing the first abstract syntax tree to obtain a form label, and replacing the label content in the form label according to a preset label mapping table;
modifying the target node of the first abstract syntax tree according to the format modification rule;
determining the first abstract syntax tree which is replaced by the preset label mapping table and modified by the format modification rule as a first target abstract syntax tree;
the first preset conversion rule comprises a preset label mapping table and a format modification rule.
In one possible design, the format modification rules include:
modifying the column rendering format in the first abstract syntax tree into an applet list rendering format;
modifying the conditional rendering format in the first abstract syntax tree into an applet conditional rendering format;
and modifying the event binding format in the first abstract syntax tree into an applet event binding format.
In one possible design, the second processing submodule 3032 is specifically configured to:
reading the JS temporary file by using a preset asynchronous reading tool to obtain a code in the JS temporary file;
analyzing the codes in the JS temporary file by using an analysis plug-in to obtain a second abstract syntax tree, wherein the second abstract syntax tree comprises descriptions of all contents in the JS file;
modifying the second abstract syntax tree according to a second preset conversion rule to obtain a second target abstract syntax tree;
and generating a second target code according to the second target abstract syntax tree, and obtaining the JS target file according to the second target code.
In one possible design, the second processing submodule 3032 is further configured to:
and traversing the second abstract syntax tree, and modifying the target node of the second abstract syntax tree according to the attribute modification rule to obtain a second target abstract syntax tree, wherein the second preset conversion rule comprises the attribute modification rule.
In one possible design, the attribute modification rule includes:
acquiring the attribute and the value of the return function, and replacing the return data of the return function by using the attribute and the value of the return function to modify the definition of the data attribute in the second abstract syntax tree, wherein the return data of the return function is the definition of the data attribute in the second abstract syntax tree before modification;
respectively modifying the props attribute definition in the second abstract syntax tree and the definition mode corresponding to the default attribute value into a target attribute definition and a target definition mode, wherein the target attribute definition and the target definition mode meet the attribute definition requirements of the applet;
modifying the data reading mode of the second abstract syntax tree into a target reading mode, wherein the target reading mode meets a life cycle hook function of the small program;
and modifying the assignment expression in the second abstract syntax tree into a small program execution function mode.
In one possible design, the third processing submodule 3033 is specifically configured to:
reading the WXSS temporary file by using a preset asynchronous reading tool to obtain codes in the WXSS temporary file;
analyzing codes in the WXSS temporary file by using a syntax analyzer to obtain a third abstract syntax tree, wherein the third abstract syntax tree comprises descriptions of all contents in the CSS label;
traversing and modifying the third abstract syntax tree according to a third preset conversion rule to obtain a third target abstract syntax tree;
and generating a third target code according to the third target abstract syntax tree, and obtaining the WXSS target file according to the third target code.
In one possible design, the third processing submodule 3033 is further configured to:
and traversing the third abstract syntax tree, and modifying the third abstract syntax tree according to the selector modification rule to obtain a third target abstract syntax tree, wherein the third preset conversion rule comprises the selector modification rule.
In one possible design, the selector modifies the rule, including:
modifying the metering unit declared by the target selector in the third abstract syntax tree into a target metering unit, wherein the target metering unit meets the self-adaptive size unit of the small program;
a logging finite selector is utilized, the finite selector being any selector unsupported by the applet in the third abstract syntax tree.
In one possible design, the applet generating apparatus 300 further includes: and a fourth processing submodule. The fourth processing submodule is configured to:
and generating an information file according to the codes in the JS target file, wherein the information file is used for recording the position information of the codes of all the applet component files in the codes of the VUE components.
In one possible design, the applet generating apparatus 300 further includes: and a fifth processing submodule. The fifth processing sub-module is configured to:
generating a work order according to the component generation requirement, and executing a command line tool in response to the work order, wherein the command line tool is used for starting an applet generation method.
It should be noted that the applet generating apparatus provided in fig. 8 and 9 and the optional embodiments may be configured to execute each step of the applet generating method provided in any embodiment, and specific implementation manners and technical effects are similar and are not described herein again.
The foregoing embodiments of the apparatus provided in this application are merely exemplary, and the module division is only one logic function division, and there may be another division manner in actual implementation. For example, multiple modules may be combined or may be integrated into another system. The coupling of the various modules to each other may be through interfaces that are typically electrical communication interfaces, but mechanical or other forms of interfaces are not excluded. Thus, modules described as separate components may or may not be physically separate, may be located in one place, or may be distributed in different locations on the same or different devices.
Fig. 10 is a schematic structural diagram of an electronic device provided in the present application. As shown in fig. 10, the electronic device 400 may include: at least one processor 401 and memory 402. Fig. 10 shows an electronic device as an example of a processor.
A memory 402 for storing computer programs for the processor 401. In particular, the program may include program code including computer operating instructions.
Memory 402 may comprise high-speed RAM memory and may also include non-volatile memory (non-volatile memory), such as at least one disk memory.
The processor 401 is configured to execute the computer program stored by the memory 402 to implement the steps of the applet generating method in the above embodiments of the method.
The processor 401 may be a Central Processing Unit (CPU), an Application Specific Integrated Circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application.
Alternatively, the memory 402 may be separate or integrated with the processor 401. When the memory 402 is a device independent of the processor 401, the electronic device 400 may further include:
a bus 403 for connecting the processor 401 and the memory 402. The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, an Extended ISA (EISA) bus, or the like. Buses may be classified as address buses, data buses, control buses, etc., but do not represent only one bus or type of bus.
Alternatively, in a specific implementation, if the memory 402 and the processor 401 are integrated on a chip, the memory 402 and the processor 401 may communicate through an internal interface.
The present application also provides a computer-readable storage medium, which may include: a variety of media that can store program codes, such as a usb disk, a removable hard disk, a read-only memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and in particular, the computer-readable storage medium stores a computer program, and when at least one processor of the electronic device executes the computer program, the electronic device executes the steps of the applet generating method provided in the foregoing various embodiments.
Embodiments of the present application also provide a computer program product, which includes a computer program, and the computer program is stored in a readable storage medium. The computer program can be read from a readable storage medium by at least one processor of the electronic device, and the execution of the computer program by the at least one processor causes the electronic device to implement the steps of the applet generating method provided in the various embodiments described above.
Other embodiments of the present application will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention following, in general, the principles of the application and including such departures from the present disclosure as come within known or customary practice within the art to which the invention pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the application being indicated by the following claims.
It will be understood that the present application is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the application is limited only by the appended claims.

Claims (17)

1. An applet generating method comprising:
reading a VUE component by using a preset asynchronous reading tool to obtain each component file in the VUE component, wherein each component file comprises a page file, a JS file and a CSS file of a cascading style sheet;
correspondingly storing the codes in each component file into each temporary file respectively, wherein each temporary file comprises a micro beacon markup language WXML temporary file, a JS temporary file and a micro message cascading style sheet WXSS temporary file;
and converting codes in each temporary file according to a preset conversion strategy to correspondingly obtain each small program component file so as to generate a small program according to each small program component file, wherein the preset conversion strategy comprises traversing each node of each abstract syntax tree to modify a target node of each abstract syntax tree, and each abstract syntax tree is correspondingly formed for the codes in each temporary file.
2. The applet generating method according to claim 1, wherein the converting the codes in each temporary file according to a preset conversion policy to obtain each applet component file correspondingly comprises:
converting the codes in the WXML temporary file according to a first preset conversion rule to generate a WXML target file;
converting the codes in the JS temporary file according to a second preset conversion rule to generate a JS target file;
converting the codes in the WXSS temporary file according to a third preset conversion rule to generate a WXSS target file;
wherein the preset transformation policy includes the first preset transformation rule, the second preset transformation rule, and the third preset transformation rule, and each applet component file includes the WXML target file, the JS target file, and the WXSS target file.
3. The applet generating method according to claim 2, wherein the converting the codes in the WXML temporary file according to the first preset converting rule to generate a WXML target file comprises:
reading the WXML temporary file by using the preset asynchronous reading tool to obtain codes in the WXSS temporary file;
analyzing codes in the WXML temporary file by using a page analyzer to obtain a first abstract syntax tree, wherein the first abstract syntax tree comprises descriptions of all contents in the page file;
modifying the first abstract syntax tree according to the first preset conversion rule to obtain a first target abstract syntax tree;
and generating a first target code according to the first target abstract syntax tree, and obtaining the WXML target file according to the first target code.
4. The applet generation method according to claim 3, wherein the modifying the first abstract syntax tree according to the first predetermined transformation rule to obtain a first target abstract syntax tree comprises:
traversing the first abstract syntax tree to obtain a form label, and replacing the label content in the form label according to a preset label mapping table;
modifying a target node of the first abstract syntax tree according to a format modification rule;
determining a first abstract syntax tree which is replaced by the preset label mapping table and modified by the format modification rule as the first target abstract syntax tree;
wherein the first preset conversion rule includes the preset label mapping table and the format modification rule.
5. The applet generation method according to claim 4, characterized in that the format modification rules comprise:
modifying a column rendering format in the first abstract syntax tree into an applet list rendering format;
modifying the conditional rendering format in the first abstract syntax tree into an applet conditional rendering format;
and modifying the event binding format in the first abstract syntax tree into an applet event binding format.
6. The applet generation method according to claim 2, wherein the converting the code in the JS temporary file according to a second preset conversion rule to generate a JS target file includes:
reading the JS temporary file by using the preset asynchronous reading tool so as to obtain a code in the JS temporary file;
analyzing the codes in the JS temporary file by using an analysis plug-in to obtain a second abstract syntax tree, wherein the second abstract syntax tree comprises descriptions of all contents in the JS file;
modifying the second abstract syntax tree according to the second preset conversion rule to obtain a second target abstract syntax tree;
and generating a second target code according to the second target abstract syntax tree, and obtaining the JS target file according to the second target code.
7. The applet generation method according to claim 6, wherein the modifying the second abstract syntax tree according to the second predetermined transformation rule to obtain a second target abstract syntax tree comprises:
and traversing the second abstract syntax tree, and modifying a target node of the second abstract syntax tree according to an attribute modification rule to obtain the second target abstract syntax tree, wherein the second preset conversion rule comprises the attribute modification rule.
8. The applet generation method according to claim 7, characterized in that the property modification rules comprise:
acquiring the attribute and the value of a return function, and replacing the return data of the return function with the attribute and the value of the return function to modify the definition of the data attribute in the second abstract syntax tree, wherein the return data of the return function is the definition of the data attribute in the second abstract syntax tree before modification;
respectively modifying the props attribute definition in the second abstract syntax tree and the definition mode corresponding to the default attribute value into a target attribute definition and a target definition mode, wherein the target attribute definition and the target definition mode meet the attribute definition requirement of the applet;
modifying the data reading mode of the second abstract syntax tree into a target reading mode, wherein the target reading mode meets a life cycle hook function of the applet;
and modifying the assignment expression in the second abstract syntax tree into a small program execution function mode.
9. The applet generation method according to claim 2, wherein the transforming the code in the WXSS temporary file according to a third preset transformation rule to generate a WXSS target file comprises:
reading the WXSS temporary file by using the preset asynchronous reading tool to obtain codes in the WXSS temporary file;
analyzing codes in the WXSS temporary file by using a syntax analyzer to obtain a third abstract syntax tree, wherein the third abstract syntax tree comprises descriptions of all contents in the CSS label;
traversing and modifying the third abstract syntax tree according to the third preset conversion rule to obtain a third target abstract syntax tree;
and generating a third target code according to the third target abstract syntax tree, and obtaining the WXSS target file according to the third target code.
10. The applet generation method according to claim 9, wherein traversing and modifying the third abstract syntax tree according to the third predetermined transformation rule to obtain a third target abstract syntax tree comprises:
traversing the third abstract syntax tree, and modifying the third abstract syntax tree according to a selector modification rule to obtain the third target abstract syntax tree, wherein the third preset conversion rule comprises the selector modification rule.
11. The applet generation method according to claim 10, characterized in that the selector modifies the rules, comprising:
modifying the measurement unit declared by a target selector in the third abstract syntax tree into a target measurement unit, wherein the target measurement unit meets the adaptive size unit of the small program;
logging a limited selector, the limited selector being any selector in the third abstract syntax tree that is not supported by the applet.
12. The applet generating method according to claim 2, further comprising, after the obtaining each applet component file:
and generating an information file according to the codes in the JS target file, wherein the information file is used for recording the position information of the codes of all the applet component files in the codes of the VUE components.
13. The applet generation method according to any one of claims 1 to 12, characterized in that before the reading of the VUE components with the preset asynchronous reading tool, it further comprises:
and generating a work instruction according to the component generation requirement, and responding to the work instruction to run a command line tool, wherein the command line tool is used for starting the applet generation method.
14. An applet generating apparatus, comprising:
the acquisition module is used for reading the VUE component by using a preset asynchronous reading tool to obtain each component file in the VUE component, wherein each component file comprises a page file, a JS file and a Cascading Style Sheet (CSS) file;
the storage module is used for correspondingly storing the codes in the component files into temporary files respectively, and each temporary file comprises a micro beacon markup language WXML temporary file, a JS temporary file and a micro message cascading style sheet WXSS temporary file;
and the processing module is used for converting the codes in each temporary file according to a preset conversion strategy to correspondingly obtain each small program component file so as to generate a small program according to each small program component file, wherein the preset conversion strategy comprises traversing each node of each abstract syntax tree to modify a target node of each abstract syntax tree, and each abstract syntax tree is correspondingly formed for the codes in each temporary file.
15. An electronic device, comprising:
a processor; and the number of the first and second groups,
a memory for storing a computer program for the processor;
wherein the processor is configured to implement the applet generating method of any one of claims 1 to 13 via execution of the computer program.
16. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the applet generating method as claimed in any one of claims 1 to 13.
17. A computer program product comprising a computer program, characterized in that the computer program, when being executed by a processor, carries out the applet generating method as claimed in any one of claims 1 to 13.
CN202111358314.5A 2021-11-16 2021-11-16 Applet generation method, apparatus, device and storage medium Pending CN114064003A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202111358314.5A CN114064003A (en) 2021-11-16 2021-11-16 Applet generation method, apparatus, device and storage medium
PCT/CN2022/102158 WO2023087720A1 (en) 2021-11-16 2022-06-29 Applet generation method and apparatus, device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111358314.5A CN114064003A (en) 2021-11-16 2021-11-16 Applet generation method, apparatus, device and storage medium

Publications (1)

Publication Number Publication Date
CN114064003A true CN114064003A (en) 2022-02-18

Family

ID=80272822

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111358314.5A Pending CN114064003A (en) 2021-11-16 2021-11-16 Applet generation method, apparatus, device and storage medium

Country Status (2)

Country Link
CN (1) CN114064003A (en)
WO (1) WO2023087720A1 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114579182A (en) * 2022-02-24 2022-06-03 拉扎斯网络科技(上海)有限公司 Applet cross-end application method, related device and computer storage medium
WO2023087720A1 (en) * 2021-11-16 2023-05-25 深圳前海微众银行股份有限公司 Applet generation method and apparatus, device and storage medium
CN116954571A (en) * 2023-09-21 2023-10-27 深圳凡泰极客科技有限责任公司 Development processing method and device for applet plug-in and computer readable storage medium

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9239710B2 (en) * 2013-03-15 2016-01-19 ArtinSoft Corporation Programming language transformations with abstract syntax tree extensions
CN108268262A (en) * 2017-12-27 2018-07-10 广东耐思尼克信息技术有限公司 Realize the method, apparatus and system that HTML is converted to wechat small routine
CN108664248A (en) * 2018-05-14 2018-10-16 北京汉能光伏投资有限公司 A kind of generation method and device of wechat small routine
CN110333863B (en) * 2019-06-17 2023-05-30 无线生活(杭州)信息科技有限公司 Method and device for generating and displaying applet page
CN110888645A (en) * 2019-10-12 2020-03-17 贝壳技术有限公司 Method, device and storage medium for converting into small program
CN114064003A (en) * 2021-11-16 2022-02-18 深圳前海微众银行股份有限公司 Applet generation method, apparatus, device and storage medium

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023087720A1 (en) * 2021-11-16 2023-05-25 深圳前海微众银行股份有限公司 Applet generation method and apparatus, device and storage medium
CN114579182A (en) * 2022-02-24 2022-06-03 拉扎斯网络科技(上海)有限公司 Applet cross-end application method, related device and computer storage medium
CN116954571A (en) * 2023-09-21 2023-10-27 深圳凡泰极客科技有限责任公司 Development processing method and device for applet plug-in and computer readable storage medium
CN116954571B (en) * 2023-09-21 2023-12-22 深圳凡泰极客科技有限责任公司 Development processing method and device for applet plug-in and computer readable storage medium

Also Published As

Publication number Publication date
WO2023087720A1 (en) 2023-05-25

Similar Documents

Publication Publication Date Title
CN114064003A (en) Applet generation method, apparatus, device and storage medium
CN106919434B (en) Code generation method and device
US8392884B2 (en) Test case automatic generation method for testing proactive GSM application on SIM cards
US8522221B1 (en) Techniques for automatic generation of instruction-set documentation
CN106412086B (en) Method and system for automatically generating communication code by using protocol description file
CN111399853A (en) Templated deployment method of machine learning model and custom operator
US10303760B2 (en) Cascading style sheet meta language performance
CN102117241A (en) Multi-core system debugging method and multi-core system
CN107451112B (en) Form tool data checking method, device, terminal equipment and storage medium
CN112231197A (en) Page testing method and device and storage medium
Mendonça et al. Test2feature: Feature-based test traceability tool for highly configurable software
CN112948400A (en) Database management method, database management device and terminal equipment
CN116151162A (en) Automatic design method, device, equipment and medium for register codes and documents
CN115080444A (en) Test case conversion method and device, electronic equipment and storage medium
CN114327614A (en) Method and application for recording and analyzing data flow of reference model
CN113961238A (en) Object conversion method and device, electronic equipment and storage medium
CN107577476A (en) A kind of Android system source code difference analysis method, server and medium based on Module Division
CN108628606B (en) Method and system for generating WEB network management application program of embedded equipment
CN113010550A (en) Batch processing object generation and batch processing method and device for structured data
CN117075912B (en) Method for program language conversion, compiling method and related equipment
CN117234466B (en) Enterprise management software development method, system, equipment and storage medium
EP1183596B1 (en) Generating optimized computer data field conversion routines
US11650802B2 (en) Idiomatic source code generation
CN109960497A (en) Call method and device between a kind of script file
CN114090007A (en) Multi-language text generation method, terminal and storage medium suitable for development language

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination