CN111399863A - Dependent file packaging method, device, equipment and computer readable storage medium - Google Patents

Dependent file packaging method, device, equipment and computer readable storage medium Download PDF

Info

Publication number
CN111399863A
CN111399863A CN202010180529.1A CN202010180529A CN111399863A CN 111399863 A CN111399863 A CN 111399863A CN 202010180529 A CN202010180529 A CN 202010180529A CN 111399863 A CN111399863 A CN 111399863A
Authority
CN
China
Prior art keywords
node
dependent
file
package
dependency
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
CN202010180529.1A
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 CN202010180529.1A priority Critical patent/CN111399863A/en
Publication of CN111399863A publication Critical patent/CN111399863A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/61Installation

Abstract

The invention discloses a dependent file packaging method, which comprises the following steps: reading a project page of an applet project, and generating a dependency structure tree of the applet project based on the project page; determining a sub-package entry node of the applet item and a dependent node corresponding to the sub-package entry node based on the dependency structure tree; determining whether the dependent node is a primary packet node based on the dependency structure tree; and if the dependency nodes are the main package nodes, packaging the target dependency files corresponding to the dependency nodes into the main package of the applet project. The invention also discloses a dependent file packaging device, equipment and a computer readable storage medium. According to the method and the device, the dependency structure tree is generated by reading the project page of the small program page, and the dependency file is determined to be referred by the sub-package or the main package based on the dependency structure tree, so that the dependency file is packaged into the main package or the sub-package without manual designation, and the intelligent packaging of the dependency file is realized.

Description

Dependent file packaging method, device, equipment and computer readable storage medium
Technical Field
The invention relates to the technical field of financial technology (Fintech), in particular to a dependent file packaging method, a dependent file packaging device, dependent file packaging equipment and a computer readable storage medium.
Background
In recent years, with the development of financial technology (Fintech), particularly internet finance, small program technology has been introduced into daily services of financial institutions such as banks. In the daily service process of financial institutions such as banks, in order to meet business requirements, small programs which are applications and can be used without downloading are often required to be developed. In the development process of the small program, a developer can directly refer to an existing component code package or a function code package without writing codes, and the code package is called a third-party dependent file.
The existing small program development needs a developer to manually specify whether a third-party dependent file is packaged into a main small program package or a sub-small program package, wherein the main small program package refers to a code package which needs to be downloaded when a user opens a small program at the first time, and the sub-small program package refers to a small program code package which is silently downloaded when the user browses the small program.
Obviously, the packaging method depends on the experience of developers and is extremely not intelligent.
Disclosure of Invention
The invention mainly aims to provide a dependent file packaging method, a dependent file packaging device, dependent file packaging equipment and a computer readable storage medium, and aims to realize intelligent packaging of third-party dependent files.
In order to achieve the above object, the present invention provides a dependent file packaging method, which includes the following steps:
reading a project page of an applet project, and generating a dependency structure tree of the applet project based on the project page;
determining a sub-package entry node of the applet item and a dependent node corresponding to the sub-package entry node based on the dependency structure tree;
determining whether the dependent node is a primary packet node based on the dependency structure tree;
and if the dependency nodes are the main package nodes, packaging the target dependency files corresponding to the dependency nodes into the main package of the applet project.
Preferably, after the step of determining whether the dependent node is a primary package node based on the dependency structure tree, the dependent file packaging method further includes:
if the node is a sub-packet node, determining the number of nodes of the sub-packet entry node which refers to the dependent node based on the dependent structure tree;
and if the number of the nodes does not reach the preset number, respectively packaging the target dependent files corresponding to the dependent nodes into sub-packets corresponding to the sub-packet entry nodes.
Preferably, the step of packaging the target dependent files corresponding to the dependent nodes into the sub-packages corresponding to the sub-package entry nodes respectively includes:
generating an output path of the target dependent file based on the packet name of the packet, and generating a relative path of the packet based on the dependency structure tree and the output path;
packaging the target dependent file into the sub-package, and replacing the reference code of the sub-package based on the relative path.
Preferably, if the dependency node is a main package node, the step of packaging the target dependency file corresponding to the dependency node into the main package of the applet project includes:
if the dependency node is the main package node, determining the size of a target dependency file corresponding to the dependency node;
and if the size of the target dependent file does not exceed the preset size, packaging the target dependent file into a main package of the applet project.
Preferably, the step of reading a project page of an applet project and generating a dependency structure tree of the applet project based on the project page includes:
reading a project page of an applet project, and taking the project page as an entry node;
determining a first dependent file of the entry node based on the file content of the entry node, and taking the first dependent file as a node to be processed;
circularly executing, based on the file content of the node to be processed, determining a second dependent file of the node to be processed, and taking the second dependent file as the node to be processed of the next cycle until no node to be processed is generated;
and generating a dependency structure tree of the applet item based on the entry node and all the nodes to be processed.
Preferably, the step of determining a first dependent file of the portal node based on the file content of the portal node comprises:
reading the file content of the entry node, and determining a file suffix of the file content;
determining a first dependent file of the ingress node based on the file suffix.
Preferably, the step of determining a sub-package entry node of the applet item and a dependency node corresponding to the sub-package entry node based on the dependency structure tree includes:
traversing to determine whether the file path of the entry node in the dependency structure tree contains a packet name;
determining an entry node of a file path containing a packet name as a packet entry node of the applet item;
and determining a dependent node corresponding to the sub-packet entry node based on the dependent structure tree.
Preferably, the step of determining whether the dependent node is a primary packet node based on the dependency structure tree includes:
setting a father node of the dependent node as a target node based on the dependent structure tree, and determining whether the target node has the father node;
if so, determining whether the file path of the father node of the target node contains a packet name, wherein if the father node of the target node does not contain the father node of the packet name, determining that the dependent node is a main packet node;
and if the node does not contain the packet name, determining whether the file path of the target node contains the packet name, wherein if the node which does not contain the packet name exists in the target node, determining that the dependent node is the main packet node.
In addition, to achieve the above object, the present invention also provides a dependent file packaging apparatus, including:
the generating module is used for reading a project page of an applet project and generating a dependency structure tree of the applet project based on the project page;
a first determining module, configured to determine, based on the dependency structure tree, a sub-package entry node of the applet item and a dependency node corresponding to the sub-package entry node;
a second determining module, configured to determine whether the dependent node is a primary packet node based on the dependency structure tree;
and the packaging module is used for packaging the target dependent file corresponding to the dependent node into the main package of the small program project if the target dependent file is the main package node.
Preferably, the packaging module is further configured to:
if the node is a sub-packet node, determining the number of nodes of the sub-packet entry node which refers to the dependent node based on the dependent structure tree;
and if the number of the nodes does not reach the preset number, respectively packaging the target dependent files corresponding to the dependent nodes into sub-packets corresponding to the sub-packet entry nodes.
Preferably, the packaging module is further configured to:
generating an output path of the target dependent file based on the packet name of the packet, and generating a relative path of the packet based on the dependency structure tree and the output path;
packaging the target dependent file into the sub-package, and replacing the reference code of the sub-package based on the relative path.
Preferably, the packaging module is further configured to:
if the dependency node is the main package node, determining the size of a target dependency file corresponding to the dependency node;
and if the size of the target dependent file does not exceed the preset size, packaging the target dependent file into a main package of the applet project.
Preferably, the generating module is further configured to:
reading a project page of an applet project, and taking the project page as an entry node;
determining a first dependent file of the entry node based on the file content of the entry node, and taking the first dependent file as a node to be processed;
circularly executing, based on the file content of the node to be processed, determining a second dependent file of the node to be processed, and taking the second dependent file as the node to be processed of the next cycle until no node to be processed is generated;
and generating a dependency structure tree of the applet item based on the entry node and all the nodes to be processed.
Preferably, the generating module is further configured to:
reading the file content of the entry node, and determining a file suffix of the file content;
determining a first dependent file of the ingress node based on the file suffix.
Preferably, the first determining module is further configured to:
traversing to determine whether the file path of the entry node in the dependency structure tree contains a packet name;
determining an entry node of a file path containing a packet name as a packet entry node of the applet item;
and determining a dependent node corresponding to the sub-packet entry node based on the dependent structure tree.
Preferably, the second determining module is further configured to:
setting a father node of the dependent node as a target node based on the dependent structure tree, and determining whether the target node has the father node;
if so, determining whether the file path of the father node of the target node contains a packet name, wherein if the father node of the target node does not contain the father node of the packet name, determining that the dependent node is a main packet node;
and if the node does not contain the packet name, determining whether the file path of the target node contains the packet name, wherein if the node which does not contain the packet name exists in the target node, determining that the dependent node is the main packet node.
In addition, to achieve the above object, the present invention also provides a dependent file packaging apparatus, including: the device comprises a memory, a processor and a dependent file packaging program which is stored on the memory and can run on the processor, wherein when the dependent file packaging program is executed by the processor, the steps of the dependent file packaging method are realized.
In addition, to achieve the above object, the present invention also provides a computer readable storage medium, on which a dependent file packaging program is stored, which, when being executed by a processor, implements the steps of the dependent file packaging method as described above.
The dependent file packaging method provided by the invention comprises the steps of reading a project page of an applet project, and generating a dependent structure tree of the applet project based on the project page; determining a sub-package entry node of the applet item and a dependent node corresponding to the sub-package entry node based on the dependency structure tree; determining whether the dependent node is a primary packet node based on the dependency structure tree; and if the dependency nodes are the main package nodes, packaging the target dependency files corresponding to the dependency nodes into the main package of the applet project. According to the method and the device, the dependency structure tree is generated by reading the project page of the small program page, and the dependency file is determined to be referred by the sub-package or the main package based on the dependency structure tree, so that the dependency file is packaged into the main package or the sub-package without manual designation, and the intelligent packaging of the dependency file is realized.
Drawings
FIG. 1 is a schematic diagram of an apparatus architecture of a hardware operating environment according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating a first embodiment of a dependent file packaging method according to the present invention;
FIG. 3 is a flowchart illustrating a second embodiment of a method for packaging dependent files according to the present invention.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
As shown in fig. 1, fig. 1 is a schematic device structure diagram of a hardware operating environment according to an embodiment of the present invention.
The device of the embodiment of the invention can be a mobile terminal or a server device.
As shown in fig. 1, the apparatus may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, a communication bus 1002. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory (e.g., a magnetic disk memory). The memory 1005 may alternatively be a storage device separate from the processor 1001.
Those skilled in the art will appreciate that the configuration of the apparatus shown in fig. 1 is not intended to be limiting of the apparatus and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
As shown in fig. 1, a memory 1005, which is a kind of computer storage medium, may include therein an operating system, a network communication module, a user interface module, and a dependent file packaging program.
The operating system is a program for managing and controlling the dependent file packaging equipment and the software resources, and supports the operation of the network communication module, the user interface module, the dependent file packaging program and other programs or software; the network communication module is used for managing and controlling the network interface 1002; the user interface module is used to manage and control the user interface 1003.
In the dependent file packaging apparatus shown in fig. 1, the dependent file packaging apparatus calls, by the processor 1001, a dependent file packaging program stored in the memory 1005, and performs operations in the following embodiments of the dependent file packaging method.
Based on the hardware structure, the embodiment of the dependent file packaging method is provided.
Referring to fig. 2, fig. 2 is a schematic flowchart of a first embodiment of a dependent file packaging method according to the present invention, where the method includes:
step S10, reading a project page of an applet project, and generating a dependency structure tree of the applet project based on the project page;
step S20, determining a sub-package entry node of the small program item and a dependent node corresponding to the sub-package entry node based on the dependency structure tree;
step S30, determining whether the dependent node is a main package node based on the dependent structure tree;
and step S40, if the dependency node is a main package node, packaging the target dependency file corresponding to the dependency node into the main package of the applet project.
The dependent file packaging method is applied to dependent file packaging equipment of financial institutions such as financial institutions or bank systems, the dependent file packaging equipment can be terminals, robots or PC equipment, and for convenience in description, the dependent file packaging equipment is called packaging equipment for short. The packaging device comprises a wxa2.x framework, wherein the wxa2.x framework is an applet development framework and has the function of converting an applet project into an executable code of an applet through compiling, and the compiling refers to analyzing, escaping, coding, replacing and the like of a source program. The packaging device of this embodiment implements, through the wxa2.x framework, the capability of dynamically packaging the third-party dependent file in the applet precompilation stage, and in specific implementation, configures, by adding a relevant configuration item (optimization, depsipit, maxdep) in the configuration file (wxa 2. x), a relevant rule, such as the rule is: the N sub-packages refer to the same dependent file, wxa2.x packages the dependent file into the main package, and the like, so that the packaging equipment executes a preset rule in the running state, packages the dependent file into the corresponding main package or the sub-packages, and realizes intelligent packaging of the dependent file.
Specifically, in the pre-compiling stage, complete dependency analysis is performed on the applet project through a wxa2.x framework, the dependency files of the applet project are collected, so that a dependency structure tree of the applet project is generated, and then whether the dependency files are packaged into a main package or a sub package is determined according to the affiliation of the dependency files in the dependency structure tree, so that intelligent packaging of the dependency files is achieved.
The respective steps will be described in detail below:
step S10, reading a project page of an applet project, and generating a dependency structure tree of the applet project based on the project page;
in this embodiment, the packaging device performs complete analysis on the applet item through a wxa2.x framework, specifically, reads a project page of the applet item, and determines a dependency relationship of each project page of the applet, so as to generate a dependency structure tree of the applet item, where the project page includes a page code, a file content, a file path, and the like, and in a development process of the applet item, a reference relationship of each project page is known, for example, a dependent file a is referred to by a project page a, and a dependent file B is referred to by a project page B, and therefore, after the project page of the applet item is read, the dependency relationship of the project page is determined, so as to generate the dependency structure tree.
In one embodiment, step S10 includes:
a1, reading a project page of an applet project, and taking the project page as an entry node;
in one embodiment, a processing queue is established, then a project page of an applet project is read, and the project page is listed in the processing queue as an entry node, where each entry node is a node to be processed.
Step a2, determining a first dependent file of the entry node based on the file content of the entry node, and using the first dependent file as a node to be processed;
then, dequeuing a node from the processing queue, starting processing, specifically, sequentially reading the file content of the current entry node, thereby determining the dependent file of the current entry node according to the file content, obtaining the first dependent files of all entry nodes after processing all entry nodes, and then pressing the first dependent files as nodes to be processed into the processing queue to become new nodes to be processed.
It should be noted that, since the pending node corresponding to the dependent file may refer to another dependent file, the dependent file corresponding to the entry node needs to be pushed into the processing queue as the pending node.
In one embodiment, the step of determining the first dependent file of the portal node based on the file content of the portal node comprises:
reading the file content of the entry node, and determining a file suffix of the file content;
and determining a dependent file corresponding to the entry node based on the file suffix.
In an embodiment, after the entry page is used as an entry node, the file content of the entry node is read, then a file suffix of the file content is determined, and then a dependent file corresponding to the entry node is determined according to the file suffix.
In one embodiment, the file suffix of the entry node has a one-to-one correspondence with the dependent file, and thus, the dependent file corresponding to the entry node may be determined after determining the file suffix to the file content of the entry node.
In specific implementation, the file suffix can be determined according to the file type, that is, after the file content of the entry node is read, the file type is determined according to the file content, and then the file suffix is determined according to the file type, if the file type is a js file, the file suffix is determined to be js, and then a dependent file corresponding to the js file suffix is determined; if the file type is wxml file, determining the file suffix as wxml, and then determining the dependent file corresponding to the file suffix wxml; if the file type is a cs file, determining that the file suffix is cs or wxss, and then determining a dependent file corresponding to the file suffix cs or wxss; and if the file type is a json file, determining a file suffix as json, and then determining a dependent file corresponding to the file suffix.
Further, in another embodiment, the step of determining a first dependent file of the portal node based on the file content of the portal node comprises the steps of:
reading the file content of the entry node, and determining the file type corresponding to the entry node based on the file content;
and determining a code tool corresponding to the file type, and determining a dependent file corresponding to the entry node based on the code tool.
In another embodiment, in consideration of the fact that the file types are various and different file types cannot be interpreted and searched in the same manner, in an embodiment, after the file content is read, the file type may be determined, and then, according to the file type, different code tools are used to determine the dependent file corresponding to the entry node, that is, different code tools correspond to different file types, where a code tool is a section of program written by a developer to determine the dependent file corresponding to different file types, and in the following, different code tools are represented by different numbers.
In specific implementation, for a js file type, a first code tool can be used to convert a corresponding code into a first preset format, for example, after AST (abstract syntax tree), all require and import statements are traversed, and since the Javascript language includes the two dependency introduction modes, a dependency file of a current entry node can be determined by traversing the require and import statements.
For wxml files, the file content can be read by using a second code tool and converted into a second preset format, for example, after a DOM (Document Object Model) is obtained, src and href attributes in all DOM elements are traversed, and since the applet item supports the introduction of other dependent files by the two attributes in wxml, a dependent file corresponding to the current entry node can be determined by traversing the src and href attributes.
For the css file, a third code tool can be used for matching corresponding import and src statements, and as css or wxss can introduce other dependent files in the two modes, the dependent file corresponding to the current entry node can be determined by matching import and src statements.
For the json file, whether the usingComponents configuration exists can be searched through a fourth code tool, and the applet item can only introduce other dependent files through the configuration (one dependent file is composed of the js, wxml, css and json file), so that the dependent file and the like corresponding to the current entry node can be determined through searching the usingComponents configuration.
It should be noted that, different code tools are used to determine the dependent files of the entry nodes of different file types, so that the search speed of the dependent files can be increased, and when the subsequent dependency rules change, corresponding code tools can be developed for a certain file type, without the need for a single one-to-one correspondence between the stored file suffix and the dependent file, which is convenient for subsequent maintenance.
Step a3, circularly executing, based on the file content of the node to be processed, determining a second dependent file of the node to be processed, and using the second dependent file as the node to be processed in the next cycle until no node to be processed is generated;
after determining the dependency files of all the entry nodes, pressing the dependency files as the nodes to be processed into a processing queue, wherein the processing queue at the moment comprises the entry nodes and the nodes to be processed.
Then, circularly executing, based on the file content of the node to be processed, determining a second dependent file of the node to be processed, namely the dependent file of the dependent file, and pressing the second dependent file into a processing queue as the node to be processed of the next cycle, where the processing queue at this time includes an entry node, a node corresponding to the dependent file of the entry node, and a node corresponding to the dependent file until no new node to be processed is generated, and at this time, the collection of the dependency relationship of the applet item is complete.
Step a4, generating a dependency structure tree of the applet item based on the entry node and all the nodes to be processed.
At this time, outputting the corresponding code to obtain the dependency structure tree of the applet item, and specifically, connecting the entry node and all the nodes to be processed to form the dependency structure tree.
And step S20, determining a sub-package entry node of the small program item and a dependent node corresponding to the sub-package entry node based on the dependency structure tree.
In this embodiment, after the dependency structure tree is obtained, the sub-package entry node of the applet item is determined first, that is, the sub-package entry node is determined first, and then the dependency node corresponding to the sub-package entry node is determined.
Specifically, in an embodiment, step S20 includes:
step b1, traversing to determine whether the file path of the entry node in the dependency structure tree contains a packet name;
in one embodiment, it is determined whether the file path of each entry node in the dependency structure tree includes a packet name, such as subpages/indexes.
Step b2, determining the entry node of the file path containing the subpackage name as the subpackage entry node of the small program item;
then, the entry node of the file path containing the packet name is determined as the packet entry node of the applet item, and the entry node of the file path not containing the packet name does not need to be managed first.
And b3, determining the dependent node corresponding to the sub-package entry node based on the dependent structure tree.
And finally, finding a dependent node corresponding to the sub-packet entry node according to the dependent structure tree, wherein the dependent node is a descendant node of the sub-packet entry node in the dependent structure tree, namely the sub-packet entry node refers to a target dependent file corresponding to the dependent node.
And step S30, determining whether the dependent node is a main package node or not based on the dependent structure tree.
In this embodiment, after determining the dependent node of the packet ingress node, it is further required to determine whether the dependent node is referred to by the main packet, that is, it is required to determine whether the current dependent node is the main packet node based on the dependent structure tree, specifically, it is determined which ingress nodes the dependent node is referred to by based on the dependent structure tree, that is, it is determined whether the parent node of the dependent node is the main packet ingress node, and if so, it is determined that the current dependent node is the main packet node.
In one embodiment, step S30 includes:
step c1, setting the father node of the dependent node as a target node based on the dependent structure tree, and determining whether the target node has the father node;
in one embodiment, the parent node of the current dependent node is determined as the target node, and whether the target node has the parent node, that is, whether the parent node of the dependent node exists is determined. It should be noted that the dependent node is a descendant node of the child packet entry node, that is, the dependent node includes a dependent child node, a dependent grandchild node, and the like, and when the dependent node is one, the parent node of the dependent node at least sub-packets the entry node; when the dependent node is multiple, that is, when the dependent node includes multiple dependent child nodes or multiple dependent child nodes and multiple dependent grandchild nodes, it is necessary to set a parent node of each node as a target node, and determine whether all the target nodes have the parent node in a traversal manner.
Step c2, if yes, determining whether the file path of the father node of the target node contains a subcontracting name, wherein if the father node of the target node contains a father node which does not contain a subcontracting name, determining that the dependent node is a main packet node;
if the child node does not contain the subpackage name, determining that the parent node of the current target node is a main package node, namely the current dependent node is the main package node.
If the current dependent node has M, N two father nodes, that is, the target node includes M and N, where M is a packet ingress node, then as long as the file path of the father node of N does not contain a packet name, it is determined that N is a main packet node, at this time, the dependent node is referred to by both the packet and the main packet, and since the main packet is a code packet that needs to be downloaded at the first time when the applet is opened, the target dependent file corresponding to the current dependent node should be downloaded at the first time, and thus the current dependent node is the main packet node.
And if the file paths of the father nodes of the target nodes all contain the packet names, determining that the current dependent node is a packet node and is referred by at least one packet.
And c3, if not, determining whether the file path of the target node contains a packet name, wherein if a node which does not contain the packet name exists in the target node, determining that the dependent node is a main packet node.
If the target node does not have a father node, the target node is determined to be an entry node, therefore, the target node comprises at least one sub-packet entry node, at this time, whether a file path of the target node contains a sub-packet name is only required to be determined, if the target node does not contain the sub-packet name, the dependent node is determined to be referred by the sub-packet and the main packet, and the target dependent file is determined to be the main packet node.
And if the file paths of the target nodes all contain the packet names, determining the dependent nodes as packet nodes and being referred by at least one packet.
In another embodiment, the type of each node in the dependency tree may be determined first, i.e., whether each node is a primary or a secondary node may be determined first.
Specifically, a primary package inspection algorithm is used for determining:
i. and sequentially taking out a node P from the dependency structure tree, checking a father node of the P, if no father node exists, taking the P as an entry node, directly judging the file path of the P, if the file path of the P does not contain a packet name, taking the P as a main packet node, ending the algorithm, and returning to true.
ii. And if the P has a father node, traversing the father node of the P, if all father node file paths do not contain the packet names, taking the P as a main packet node, ending the algorithm, and returning to true.
And iii, checking whether the P is a dependent node, specifically detecting whether a file path of the P comprises a second specific directory, if so, determining that the P is the dependent node. And if the P is determined to be a dependent node, sequentially executing i-iii to the father node of the P, returning true to any father node, ending the algorithm, judging the P to be a main packet node, and returning true.
If the traversal is finished and P still does not meet the judgment of the main packet, false is returned, and P is a packet node.
And step S40, if the dependency node is a main package node, packaging the target dependency file corresponding to the dependency node into the main package of the applet project.
In this embodiment, if it is determined that the current dependent node is a main package node, packaging a target dependent file corresponding to the dependent node into a main package of the applet project; and if the current dependent node is determined to be a sub-package node, packaging the target dependent file corresponding to the dependent node into a sub-package of the applet item.
The method comprises the steps of reading a project page of an applet project, and generating a dependency structure tree of the applet project based on the project page; determining a sub-package entry node of the applet item and a dependent node corresponding to the sub-package entry node based on the dependency structure tree; determining whether the dependent node is a primary packet node based on the dependency structure tree; and if the dependency nodes are the main package nodes, packaging the target dependency files corresponding to the dependency nodes into the main package of the applet project. According to the method and the device, the dependency structure tree is generated by reading the project page of the small program page, and the dependency file is determined to be referred by the sub-package or the main package based on the dependency structure tree, so that the dependency file is packaged into the main package or the sub-package without manual designation, and the intelligent packaging of the dependency file is realized.
Further, based on the first embodiment of the dependent file packaging method of the present invention, a second embodiment of the dependent file packaging method of the present invention is proposed.
The second embodiment of the dependent file packaging method is different from the first embodiment of the dependent file packaging method in that, referring to fig. 3, the dependent file packaging method further includes:
step S50, if the node is a sub-packet node, determining the number of nodes of the sub-packet entry node which refers to the dependency node based on the dependency structure tree;
and step S60, if the number of the nodes does not reach the preset number, respectively packaging the target dependent files corresponding to the dependent nodes into sub-packages corresponding to the sub-package entry nodes.
In this embodiment, if there is a situation where a plurality of sub-packages apply the same target dependent file, in order to avoid the total size of the applet item from being too large, the target dependent file is packaged into the main package, so that the total size of the applet item can be reduced by the size of N-1 target dependent files, where N is the number of sub-packages referencing the target dependent file.
The respective steps will be described in detail below:
and step S50, if the node is a subpackage node, determining the node number of the subpackage entry node which refers to the dependency node based on the dependency structure tree.
In this embodiment, if it is determined that the dependent node is a sub-packet node, the number of nodes referencing the sub-packet entry node of the dependent node is determined through the dependency structure tree, that is, the number of sub-packets referencing the target dependent file corresponding to the dependent node is counted.
And step S60, if the number of the nodes does not reach the preset number, respectively packaging the target dependent files corresponding to the dependent nodes into sub-packages corresponding to the sub-package entry nodes.
In this embodiment, the counted number of nodes is compared with a preset number, and if the number of nodes of the subpackage entry node does not reach the preset number, the target dependent files corresponding to the dependent nodes are respectively packaged into subpackages; and if the number of the nodes of the sub-package entry node reaches a preset number, packaging the target dependent file corresponding to the dependent node into the main package to reduce the total size of the small program item, wherein the preset number can be determined according to the actual condition, such as the size of the target dependent file corresponding to the dependent node, and if the size of the target dependent file is 100kb, the preset number is 4, and the like.
Further, in an embodiment, the step of packaging the target dependency files corresponding to the dependency nodes into the sub-packages corresponding to the sub-package entry nodes respectively includes:
step d1, generating an output path of the target dependent file based on the packet name of the packet, and generating a relative path of the packet based on the dependent structure tree and the output path;
in one embodiment, a new output path outputPath is generated for the target dependent file corresponding to the dependent node based on the packet name of the packet, and if x packets are used, the corresponding output path is x/npm/dependent name. Then, regenerating a relative path of the parent node relative to the new output path according to the generated outputPath, wherein the calculation method of the relative path comprises the following steps: the output path of the parent node is relative to the newly generated outputPath, i.e. the new relative path.
Generating a corresponding relative path for the packet ingress node according to the new outputPath, wherein the relative path algorithm is as follows: the output path of the packet ingress node is relative outputPath.
And d2, packaging the target dependent file into the sub-package, and replacing the reference code of the sub-package based on the relative path.
And then packaging the target dependent file into a sub-package, and replacing the reference code of the sub-package according to the generated relative path so that the target dependent file can be correctly referenced by the subsequent sub-package.
The present embodiment considers that the current packetization size of an applet item has the following limitations: all sub-package sizes of the whole applet project are not more than 12M, and the size of a single sub-package/main package cannot exceed 2M, so that a third party dependent file dependent on the sub-package should be put into the sub-package as much as possible, the space of the main package can be saved, and the time for a user to load the applet for the first time is reduced; however, when N sub-packages depend on the same third-party dependent file, the dependent file is placed into the main package in consideration of the total size of the small program package, so that the total size of the sub-small program project can be reduced by (N-1) third-party dependent file sizes, and intelligent packaging of the dependent file is realized.
Further, a third embodiment of the dependent file packaging method of the present invention is proposed based on the first and second embodiments of the dependent file packaging method of the present invention.
The third embodiment of the dependent file packaging method differs from the first and second embodiments of the dependent file packaging method in that step S40 includes:
step e1, if the node is a main package node, determining the size of the target dependent file corresponding to the dependent node;
and e2, if the size of the target dependent file does not exceed the preset size, packaging the target dependent file into the main package of the applet item.
In this embodiment, because the small program item itself is limited, it cannot be made very large as an application software, and generally, the main package of the small program item has a size of only 2M, so if the target dependent file is too large, it should be placed in the sub-package, so that the main package has a free space, that is, the space of the main package preferentially places files such as a code package corresponding to the main package.
The respective steps will be described in detail below:
and e1, if the node is the main package node, determining the size of the target dependent file corresponding to the dependent node.
In this embodiment, if it is determined that the dependent node is the primary package node, the target dependent file corresponding to the dependent node should be normally placed in the primary package, but the size of the target dependent file needs to be determined first in consideration of the size limit of the primary package.
And e2, if the size of the target dependent file does not exceed the preset size, packaging the target dependent file into the main package of the applet item.
In this embodiment, the size of the target dependent file is compared with a preset size, and if the size of the target dependent file does not exceed the preset size, the target dependent file is packed into a main package; and if the size of the target dependent file exceeds a preset size, packaging the target dependent file into a sub-package, wherein the preset size can be set according to the actual situation, such as the size is determined according to the size of the main package, and the preset size can be set to be 500kb and the like in specific implementation.
In order to avoid insufficient space of the main package, the size of the target dependent file needs to be considered, so that whether the target dependent file is packaged into the main package or the sub-package is determined, and intelligent packaging of the dependent file is achieved.
The invention also provides a dependent file packaging device. The dependent file packaging device of the invention comprises:
the generating module is used for reading a project page of an applet project and generating a dependency structure tree of the applet project based on the project page;
a first determining module, configured to determine, based on the dependency structure tree, a sub-package entry node of the applet item and a dependency node corresponding to the sub-package entry node;
a second determining module, configured to determine whether the dependent node is a primary packet node based on the dependency structure tree;
and the packaging module is used for packaging the target dependent file corresponding to the dependent node into the main package of the small program project if the target dependent file is the main package node.
Preferably, the packaging module is further configured to:
if the node is a sub-packet node, determining the number of nodes of the sub-packet entry node which refers to the dependent node based on the dependent structure tree;
and if the number of the nodes does not reach the preset number, respectively packaging the target dependent files corresponding to the dependent nodes into sub-packets corresponding to the sub-packet entry nodes.
Preferably, the packaging module is further configured to:
generating an output path of the target dependent file based on the packet name of the packet, and generating a relative path of the packet based on the dependency structure tree and the output path;
packaging the target dependent file into the sub-package, and replacing the reference code of the sub-package based on the relative path.
Preferably, the packaging module is further configured to:
if the dependency node is the main package node, determining the size of a target dependency file corresponding to the dependency node;
and if the size of the target dependent file does not exceed the preset size, packaging the target dependent file into a main package of the applet project.
Preferably, the generating module is further configured to:
reading a project page of an applet project, and taking the project page as an entry node;
determining a first dependent file of the entry node based on the file content of the entry node, and taking the first dependent file as a node to be processed;
circularly executing, based on the file content of the node to be processed, determining a second dependent file of the node to be processed, and taking the second dependent file as the node to be processed of the next cycle until no node to be processed is generated;
and generating a dependency structure tree of the applet item based on the entry node and all the nodes to be processed.
Preferably, the generating module is further configured to:
reading the file content of the entry node, and determining a file suffix of the file content;
determining a first dependent file of the ingress node based on the file suffix.
Preferably, the first determining module is further configured to:
traversing to determine whether the file path of the entry node in the dependency structure tree contains a packet name;
determining an entry node of a file path containing a packet name as a packet entry node of the applet item;
and determining a dependent node corresponding to the sub-packet entry node based on the dependent structure tree.
Preferably, the second determining module is further configured to:
setting a father node of the dependent node as a target node based on the dependent structure tree, and determining whether the target node has the father node;
if so, determining whether the file path of the father node of the target node contains a packet name, wherein if the father node of the target node does not contain the father node of the packet name, determining that the dependent node is a main packet node;
and if the node does not contain the packet name, determining whether the file path of the target node contains the packet name, wherein if the node which does not contain the packet name exists in the target node, determining that the dependent node is the main packet node.
The invention also provides a computer readable storage medium.
The computer readable storage medium of the present invention has stored thereon a dependent file packaging program, which when executed by a processor implements the steps of the dependent file packaging method as described above.
The method implemented when the dependent file packaging program running on the processor is executed may refer to each embodiment of the dependent file packaging method of the present invention, and details are not described here.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) as described above and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (11)

1. A dependent file packaging method, characterized in that the dependent file packaging method comprises the steps of:
reading a project page of an applet project, and generating a dependency structure tree of the applet project based on the project page;
determining a sub-package entry node of the applet item and a dependent node corresponding to the sub-package entry node based on the dependency structure tree;
determining whether the dependent node is a primary packet node based on the dependency structure tree;
and if the dependency nodes are the main package nodes, packaging the target dependency files corresponding to the dependency nodes into the main package of the applet project.
2. The dependent file packaging method of claim 1, wherein after the step of determining whether the dependent node is a primary package node based on the dependency structure tree, the dependent file packaging method further comprises:
if the node is a sub-packet node, determining the number of nodes of the sub-packet entry node which refers to the dependent node based on the dependent structure tree;
and if the number of the nodes does not reach the preset number, respectively packaging the target dependent files corresponding to the dependent nodes into sub-packets corresponding to the sub-packet entry nodes.
3. The dependent file packaging method according to claim 2, wherein the step of packaging the target dependent files corresponding to the dependent nodes into the sub-packages corresponding to the sub-package entry nodes respectively comprises:
generating an output path of the target dependent file based on the packet name of the packet, and generating a relative path of the packet based on the dependency structure tree and the output path;
packaging the target dependent file into the sub-package, and replacing the reference code of the sub-package based on the relative path.
4. The method for packaging the dependent file according to claim 1, wherein if the dependent file is a main package node, the step of packaging the target dependent file corresponding to the dependent node into the main package of the applet item includes:
if the dependency node is the main package node, determining the size of a target dependency file corresponding to the dependency node;
and if the size of the target dependent file does not exceed the preset size, packaging the target dependent file into a main package of the applet project.
5. The dependent file packaging method of claim 1, wherein the step of reading a project page of an applet project and generating a dependency structure tree for the applet project based on the project page comprises:
reading a project page of an applet project, and taking the project page as an entry node;
determining a first dependent file of the entry node based on the file content of the entry node, and taking the first dependent file as a node to be processed;
circularly executing, based on the file content of the node to be processed, determining a second dependent file of the node to be processed, and taking the second dependent file as the node to be processed of the next cycle until no node to be processed is generated;
and generating a dependency structure tree of the applet item based on the entry node and all the nodes to be processed.
6. The dependent file packaging method of claim 5, wherein the step of determining the first dependent file of the ingress node based on the file content of the ingress node comprises:
reading the file content of the entry node, and determining a file suffix of the file content;
determining a first dependent file of the ingress node based on the file suffix.
7. The dependent file packaging method according to claim 1, wherein the step of determining a sub-package entry node of the applet item based on the dependency structure tree, and a dependency node corresponding to the sub-package entry node comprises:
traversing to determine whether the file path of the entry node in the dependency structure tree contains a packet name;
determining an entry node of a file path containing a packet name as a packet entry node of the applet item;
and determining a dependent node corresponding to the sub-packet entry node based on the dependent structure tree.
8. The dependent file packaging method of any of claims 1-7, wherein the step of determining whether the dependent node is a primary package node based on the dependency structure tree comprises:
setting a father node of the dependent node as a target node based on the dependent structure tree, and determining whether the target node has the father node;
if so, determining whether the file path of the father node of the target node contains a packet name, wherein if the father node of the target node does not contain the father node of the packet name, determining that the dependent node is a main packet node;
and if the node does not contain the packet name, determining whether the file path of the target node contains the packet name, wherein if the node which does not contain the packet name exists in the target node, determining that the dependent node is the main packet node.
9. A dependent file packaging apparatus, characterized in that the dependent file packaging apparatus comprises:
the generating module is used for reading a project page of an applet project and generating a dependency structure tree of the applet project based on the project page;
a first determining module, configured to determine, based on the dependency structure tree, a sub-package entry node of the applet item and a dependency node corresponding to the sub-package entry node;
a second determining module, configured to determine whether the dependent node is a primary packet node based on the dependency structure tree;
and the packaging module is used for packaging the target dependent file corresponding to the dependent node into the main package of the small program project if the target dependent file is the main package node.
10. A dependent file packaging apparatus, characterized in that the dependent file packaging apparatus comprises: a memory, a processor, and a dependent file packaging program stored on the memory and executable on the processor, the dependent file packaging program when executed by the processor implementing the steps of the dependent file packaging method of any of claims 1 to 8.
11. A computer-readable storage medium, having stored thereon a dependent file packaging program which, when executed by a processor, implements the steps of the dependent file packaging method of any of claims 1 to 8.
CN202010180529.1A 2020-03-13 2020-03-13 Dependent file packaging method, device, equipment and computer readable storage medium Pending CN111399863A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010180529.1A CN111399863A (en) 2020-03-13 2020-03-13 Dependent file packaging method, device, equipment and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010180529.1A CN111399863A (en) 2020-03-13 2020-03-13 Dependent file packaging method, device, equipment and computer readable storage medium

Publications (1)

Publication Number Publication Date
CN111399863A true CN111399863A (en) 2020-07-10

Family

ID=71430818

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010180529.1A Pending CN111399863A (en) 2020-03-13 2020-03-13 Dependent file packaging method, device, equipment and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN111399863A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111949312A (en) * 2020-08-14 2020-11-17 曙光信息产业(北京)有限公司 Data module packaging method and device, computer equipment and storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111949312A (en) * 2020-08-14 2020-11-17 曙光信息产业(北京)有限公司 Data module packaging method and device, computer equipment and storage medium
CN111949312B (en) * 2020-08-14 2024-02-09 曙光信息产业(北京)有限公司 Packaging method and device for data module, computer equipment and storage medium

Similar Documents

Publication Publication Date Title
CN110990731A (en) Rendering method, device and equipment of static webpage and computer storage medium
CN109871499A (en) Page loading method and client
CN111680253B (en) Page application data packet generation method and device, computer equipment and storage medium
CN111240684B (en) Cutting method and device of JS codes, medium and electronic equipment
CN110286917A (en) File packing method, device, equipment and storage medium
JP5044942B2 (en) System and method for determining acceptance status in document analysis
JP2006221654A (en) Method and system for reducing delimiter
CN111045683A (en) Applet code compiling method, device, equipment and medium
CN113268245A (en) Code analysis method, device and storage medium
CN112527386B (en) Application program issuing method and device
KR101117165B1 (en) Web platform unit for mobile terminal connectioned web-application program in heterogeneous operating system
CN111459497A (en) WebPack-based resource package compiling method, system, server and storage medium
CN113179269B (en) Protocol data analysis method, system and medium based on Internet of things
CN111399863A (en) Dependent file packaging method, device, equipment and computer readable storage medium
CN112947900B (en) Web application development method and device, server and development terminal
CN116166907B (en) Method and device for developing Web application by using WebAsssembly and service page compiling technology
CN110990732A (en) Loading method, device and equipment based on webpage and storage medium
CN112527302A (en) Error detection method and device, terminal and storage medium
JP2006221657A (en) Display system and method of acceptance state
CN113568678B (en) Method and device for dynamically loading resources and electronic equipment
CN111151008B (en) Verification method and device for game operation data, configuration background and medium
JP2006221655A (en) Method and system for compiling schema
CN110716746B (en) Method and device for converting RN style code into applet style code
CN117827631A (en) Data processing method and device
CN114398073A (en) Application updating method and device based on RN

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