CN111399863B - Method, apparatus, device and computer readable storage medium for packaging dependent files - Google Patents
Method, apparatus, device and computer readable storage medium for packaging dependent files Download PDFInfo
- Publication number
- CN111399863B CN111399863B CN202010180529.1A CN202010180529A CN111399863B CN 111399863 B CN111399863 B CN 111399863B CN 202010180529 A CN202010180529 A CN 202010180529A CN 111399863 B CN111399863 B CN 111399863B
- Authority
- CN
- China
- Prior art keywords
- node
- file
- dependent
- dependency
- sub
- 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.)
- Active
Links
- 230000001419 dependent effect Effects 0.000 title claims abstract description 256
- 238000004806 packaging method and process Methods 0.000 title claims abstract description 71
- 238000000034 method Methods 0.000 title claims abstract description 58
- 238000012856 packing Methods 0.000 claims abstract description 39
- 238000009450 smart packaging Methods 0.000 abstract description 6
- 238000012545 processing Methods 0.000 description 10
- 238000004891 communication Methods 0.000 description 6
- 230000008569 process Effects 0.000 description 6
- 238000011161 development Methods 0.000 description 5
- 238000005516 engineering process Methods 0.000 description 4
- 230000008676 import Effects 0.000 description 3
- 230000008859 change Effects 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
- 230000006870 function Effects 0.000 description 1
- 238000007689 inspection Methods 0.000 description 1
- 238000012423 maintenance Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 238000005457 optimization Methods 0.000 description 1
- 238000003825 pressing Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/60—Software deployment
- G06F8/61—Installation
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Stored Programmes (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention discloses a method for packaging dependent files, 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; based on the dependency structure tree, determining a sub-package entry node of the applet item and a dependency node corresponding to the sub-package entry node; determining whether the dependent node is a master packet node based on the dependency structure tree; and if the target dependency file is the main package node, packaging the target dependency file corresponding to the dependency node into the main package of the small program item. The invention also discloses a dependent file packing device, equipment and a computer readable storage medium. According to the method, the device and the system, the project page of the applet page is read, so that the dependency structure tree is generated, and whether the dependency file is sub-packaged and referenced or is sub-packaged and referenced is determined based on the dependency structure tree, so that the dependency file is packaged into the main package or the sub-package, manual assignment is not needed, and intelligent packaging of the dependency file is realized.
Description
Technical Field
The present invention relates to the technical field of financial science and technology (Fintech), and in particular, to a method, an apparatus, a device, and a computer-readable storage medium for packaging dependent files.
Background
In recent years, with the development of financial technology (Fintech), particularly internet finance, applet 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 needs, it is often necessary to develop some applications, i.e. applets, which can be used without downloading. In the development of applets, developers can refer directly to off-the-shelf component code packages or functional code packages without having to re-write code, such code packages being referred to as third party dependent files.
In the existing applet development, a developer is required to manually specify whether a third party dependent file is packaged into an applet main package or an applet sub package, wherein the applet main package refers to a code package which needs to be downloaded when a user opens an applet for the first time, and the applet sub package refers to a small program code package which is quietly downloaded when the user browses the applet.
It is obvious that this packing method relies on the experience of the developer and is extremely intelligent.
Disclosure of Invention
The invention mainly aims to provide a method, a device, equipment and a computer readable storage medium for packaging dependent files, aiming at realizing intelligent packaging of third-party dependent files.
In order to achieve the above object, the present invention provides a method for packaging a dependent file, the method for packaging a dependent file comprising 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;
based on the dependency structure tree, determining a sub-package entry node of the applet item and a dependency node corresponding to the sub-package entry node;
determining whether the dependent node is a master packet node based on the dependency structure tree;
and if the target dependency file is the main package node, packaging the target dependency file corresponding to the dependency node into the main package of the small program item.
Preferably, after the step of determining whether the dependency node is a master packet node based on the dependency structure tree, the dependency file packing method further includes:
if the node is a sub-packaging node, determining the node number of the sub-packaging entry node referencing the dependency node based on the dependency 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 the sub-package corresponding to the sub-package entry node.
Preferably, the step of packaging the target dependency files corresponding to the dependency nodes into the sub-packets corresponding to the sub-packet entry nodes includes:
Generating an output path of the target dependent file based on the subcontracting name of the subcontracting, and generating a relative path of the subcontracting based on the dependency structure tree and the output path;
And packing 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 node is a master package node, the step of packaging the target dependency file corresponding to the dependency node into the master package of the applet item includes:
if the node is the main package node, determining the size of a target dependent file corresponding to the dependent 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 small program item.
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 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 a second dependent file of the node to be processed based on the file content 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 the first dependent file of the entry node based on the file content of the entry node includes:
reading the file content of the entry node and determining the file suffix of the file content;
a first dependent file of the ingress node is determined based on the file suffix.
Preferably, the step of determining, 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 comprises:
traversing to determine whether a file path of an entry node in the dependency structure tree contains a subcontracting name;
determining an entry node of a file path containing a subcontracting name as a subcontracting entry node of the applet item;
And determining the dependency node corresponding to the sub-package entry node based on the dependency structure tree.
Preferably, the step of determining whether the dependent node is a master packet 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 father node exists in the target node;
If the parent node does not contain the sub-packet name, determining that the dependent node is a main packet node;
If the node which does not contain the sub-packet name exists in the target node, determining whether the file path of the target node contains the sub-packet name, wherein if the node which does not contain the sub-packet name exists in the target node, the dependent node is determined to be a main packet node.
In addition, in order to achieve the above object, the present invention also provides a dependent file packing apparatus, including:
The generation 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;
The first determining module is used for 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;
the second determining module is used for determining whether the dependent node is a main packet node or not based on the dependent structure tree;
And the packing module is used for packing the target dependency file corresponding to the dependency node into the main package of the small program item if the target dependency file is the main package node.
Preferably, the packaging module is further configured to:
if the node is a sub-packaging node, determining the node number of the sub-packaging entry node referencing the dependency node based on the dependency 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 the sub-package corresponding to the sub-package entry node.
Preferably, the packaging module is further configured to:
Generating an output path of the target dependent file based on the subcontracting name of the subcontracting, and generating a relative path of the subcontracting based on the dependency structure tree and the output path;
And packing 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 node is the main package node, determining the size of a target dependent file corresponding to the dependent 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 small program item.
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 a second dependent file of the node to be processed based on the file content 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 the file suffix of the file content;
a first dependent file of the ingress node is determined based on the file suffix.
Preferably, the first determining module is further configured to:
traversing to determine whether a file path of an entry node in the dependency structure tree contains a subcontracting name;
determining an entry node of a file path containing a subcontracting name as a subcontracting entry node of the applet item;
And determining the dependency node corresponding to the sub-package entry node based on the dependency 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 father node exists in the target node;
If the parent node does not contain the sub-packet name, determining that the dependent node is a main packet node;
If the node which does not contain the sub-packet name exists in the target node, determining whether the file path of the target node contains the sub-packet name, wherein if the node which does not contain the sub-packet name exists in the target node, the dependent node is determined to be a main packet node.
In addition, to achieve the above object, the present invention also provides a dependent file packing apparatus including: the system comprises a memory, a processor and a dependent file packaging program stored on the memory and capable of running on the processor, wherein the dependent file packaging program realizes the steps of the dependent file packaging method when being executed by the processor.
In addition, in order to achieve the above object, the present invention also provides 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 as described above.
According to the dependency file packaging method, a project page of an applet project is read, and a dependency structure tree of the applet project is generated based on the project page; based on the dependency structure tree, determining a sub-package entry node of the applet item and a dependency node corresponding to the sub-package entry node; determining whether the dependent node is a master packet node based on the dependency structure tree; and if the target dependency file is the main package node, packaging the target dependency file corresponding to the dependency node into the main package of the small program item. According to the method, the device and the system, the project page of the applet page is read, so that the dependency structure tree is generated, and whether the dependency file is sub-packaged and referenced or is sub-packaged and referenced is determined based on the dependency structure tree, so that the dependency file is packaged into the main package or the sub-package, manual assignment is not needed, and intelligent packaging of the dependency file is realized.
Drawings
FIG. 1 is a schematic diagram of a device architecture of a hardware operating environment according to an embodiment of the present invention;
FIG. 2 is a flowchart of a first embodiment of a method for packaging dependent files according to the present invention;
FIG. 3 is a flowchart of a second embodiment of the method for packaging dependent files according to the present invention.
The achievement of the objects, functional features and advantages of the present invention will be further described with reference to the accompanying drawings, in conjunction with the embodiments.
Detailed Description
It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention.
Referring to fig. 1, fig. 1 is a schematic device structure of a hardware running 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 the communication bus 1002 is used to enable connected communication between these components. The user interface 1003 may include a Display, an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may further 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 stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also optionally be a storage device separate from the processor 1001 described above.
It will be appreciated by those skilled in the art that the device structure shown in fig. 1 is not limiting of the device and may include more or fewer components than shown, or may combine certain components, or a different arrangement of components.
As shown in FIG. 1, an operating system, a network communication module, a user interface module, and a dependent file packaging program may be included in memory 1005, which is a type of computer storage medium.
The operating system is a program for managing and controlling the dependent file packaging equipment and software resources and supports the operation of a network communication module, a user interface module, a dependent file packaging program and other programs or software; the network communication module is used to manage and control 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 a dependent file packaging program stored in a memory 1005 through a processor 1001 and performs operations in various embodiments of the dependent file packaging method described below.
Based on the hardware structure, the embodiment of the invention provides a method for packing the dependent file.
Referring to fig. 2, fig. 2 is a flowchart of a first embodiment of a method for packaging dependent files 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, based on the dependency structure tree, determining a sub-package entry node of the applet item and a dependency node corresponding to the sub-package entry node;
Step S30, determining whether the dependent node is a main packet node or not based on the dependent structure tree;
And step S40, if the node is a main package node, packaging the target dependency file corresponding to the dependency node into the main package of the small program item.
The method for packaging the dependent file is applied to the dependent file packaging equipment of financial institutions such as financial institutions or banking systems, the dependent file packaging equipment can be a terminal, a robot or PC equipment, and the dependent file packaging equipment is called as packaging equipment for short for convenience of description. The packaging device comprises a wxa2.X framework, wherein the wxa2.X framework is an applet development framework, and the function of the framework is to convert an applet item into an applet executable code through compiling, wherein the compiling refers to operations of resolving, escaping, encoding, replacing and the like of a source program. The packing device of this embodiment implements the capability of dynamically packing the third party dependency file in the pre-compiling stage of the applet through the wxa2.X framework, and in the specific implementation, configures the relevant rule by adding the relevant configuration item (optimization. Deppplit. Maxdep) in the configuration file (wxa. Config. Js) of wxa2.X, where the rule is: n sub-packages refer to the same dependent file, wxa2.X packages the dependent file into a main package and the like, so that the packaging equipment executes a preconfigured rule in an operating state to package the dependent file into a corresponding main package or sub-package, and intelligent packaging of the dependent file is realized.
Specifically, in the pre-compiling stage, complete dependency analysis is performed on the applet item through the wxa2.X framework, the dependency file of the applet item is collected, so that a dependency structure tree of the applet item is generated, and then whether the dependency file is packed into a main package or a sub package is determined according to the belonging relation of the dependency file in the dependency structure tree, so that intelligent packing of the dependency file is realized.
The following will explain each step in detail:
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 the wxa2.X framework, specifically, reads the item page of the applet item, and determines the dependency relationship of each item page of the applet item, so as to generate the dependency structure tree of the applet item, where the item page includes a page code, a file content, a file path, and the like, and the reference relationship of each item page is known in the development process of the applet item, for example, the item page a references the dependency file a, the item page B references the dependency file B, and the like, so that after the item page of the applet item is read, the dependency relationship of the item page can be determined, so as to generate the dependency structure tree.
In one embodiment, step S10 includes:
step 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 first established, then, the item pages of the applet items are read, and the item pages are listed in the processing queue as entry nodes, each entry node being 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 taking the first dependent file as a node to be processed;
Then dequeuing a node from the processing queue to start processing, specifically, sequentially reading file contents of the current entry node, determining dependent files of the current entry node according to the file contents, obtaining first dependent files of all entry nodes after all entry nodes are processed, and then pushing the first dependent files into the processing queue as nodes to be processed to become new nodes to be processed.
It should be noted that, the to-be-processed node corresponding to the dependency file may also refer to other dependency files, and therefore, the dependency file corresponding to the entry node needs to be pressed into the processing queue as the to-be-processed node.
In one embodiment, 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 the file suffix of the file content;
And determining the dependent file corresponding to the entry node based on the file suffix.
In an embodiment, after the project page is used as the entry node, the file content of the entry node is read, then the file suffix of the file content is determined, and then the dependent file corresponding to the entry node is determined according to the file suffix.
In an embodiment, the file suffix of the entry node has a one-to-one correspondence with the dependent file, so that the dependent file corresponding to the entry node can be determined after determining the file suffix of the file content to the entry node.
In specific implementation, the file suffix can be determined by the file type, namely, after the file content of the entry node is read, the file type is determined by the file content, then the file suffix is determined according to the file type, if the file type is js file, then the file suffix is js, and then the dependent file corresponding to the file suffix js is determined; if the file type is wxml files, determining that the file suffix is wxml, and determining the dependent files corresponding to the file suffix wxml; if the file type is css file, determining that the file suffix is css or wxss, and then determining the dependent file corresponding to the file suffix css or wxss; if the file type is json file, determining that the file suffix is json, and then determining that the file suffix is a dependent file corresponding to json, and the like.
Further, in another embodiment, the step of determining the first dependent file of the ingress node based on the file content of the ingress 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, considering that the file types are various, different file types cannot be read and found in the same way, so in one embodiment, after the file content is read, the file type is determined first, and then, according to the file type, the dependent file corresponding to the entry node is determined by using different code tools, that is, different code tools corresponding to different file types are provided, wherein the code tools are a section of program written by a developer for determining the dependent file corresponding to the different file types, and in the following description, the different code tools are denoted by different numbers.
In a specific implementation, for js file types, a first code tool may be used to convert the corresponding code into a first preset format, such as AST (abstract syntax tree), and then traverse all required and import statements.
For wxml files, after the file content is read by using a second code tool and converted into a second preset format, such as DOM (Document Object Model ), the src and href attributes in all DOM elements are traversed, and since the two attributes in the applet item support wxml introduce other dependent files, the dependent file corresponding to the current entry node can be determined by traversing the src and href attributes.
For css files, a third code tool may be used to match corresponding import and src statements, and since css or wxss may introduce other dependent files in both ways, the dependent file corresponding to the current entry node may be determined by matching the import and src statements.
For json files, it can be found by the fourth code tool if there is usingComponents configuration, and the applet item can only introduce other dependent files (one of which consists of the js, wxml, css, json files described above) by this configuration, so it can determine the dependent file corresponding to the current entry node, etc. by looking up usingComponents configuration.
It should be noted that, determining the dependent files of the entry nodes of different file types by using different code tools can accelerate the searching speed of the dependent files, and compared with the one-to-one correspondence between the file suffixes and the dependent files stored in advance, when the follow-up dependent rules change, the corresponding code tools can be developed for a certain type of file types without the one-to-one correspondence between the single stored file suffixes and the dependent files, thereby facilitating the follow-up maintenance.
Step a3, circularly executing a second dependent file of the node to be processed based on the file content 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;
after the dependent files of all the entry nodes are determined, the dependent files are pressed into a processing queue as the nodes to be processed, and the processing queue at the moment comprises the entry nodes and the nodes to be processed.
And then, circularly executing the second dependent file of the node to be processed, namely the dependent file of the dependent file, determining the second dependent file of the node to be processed as the node to be processed of the next cycle, pressing the second dependent file into a processing queue, wherein the processing queue at the moment comprises an entry node, a node corresponding to the dependent file of the entry node and a node corresponding to the dependent file.
And a step a4 of generating a dependency structure tree of the applet item based on the entry node and all the nodes to be processed.
At this time, the corresponding code is output to obtain a dependency structure tree of the applet item, and specifically, the entry node and all the nodes to be processed are connected to form the dependency structure tree.
Step S20, 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.
In this embodiment, after the dependency structure tree is obtained, the sub-package entry nodes of the applet item are determined first, that is, which sub-package is first determined, and then the dependency node corresponding to the sub-package entry node is determined.
Specifically, in one embodiment, step S20 includes:
Step b1, traversing to determine whether a file path of an entry node in the dependency structure tree contains a subcontract;
In one embodiment, it is determined by traversal whether the file path of each entry node in the dependency structure tree contains a subcontracting name, such as subpages/index.wxa, i.e., whether the file path of the entry node contains the first specific directory.
Step b2, determining an entry node of which the file path contains a subcontracting name as a subcontracting entry node of the applet item;
then, the entry node of the file path containing the subcontract is determined as the subcontract entry node of the applet item, and the entry node of the file path not containing the subcontract is not required to be managed.
And b3, determining the dependent node corresponding to the sub-package entry node based on the dependent structure tree.
And finally, finding out the dependency node corresponding to the sub-entry node according to the dependency structure tree, wherein the dependency node is a descendant node of the sub-entry node in the dependency structure tree, namely the sub-entry node refers to the target dependency file corresponding to the dependency node.
Step S30, based on the dependency structure tree, determining whether the dependency node is a master packet node.
In this embodiment, after determining the dependency node of the packetizing ingress node, it is further required to determine whether the dependency node is referenced by the main packet, that is, whether the current dependency node is a main packet node based on the dependency structure tree, specifically, determine which ingress nodes the dependency node is referenced by based on the dependency structure tree, that is, determine whether the parent node of the dependency node is a main packet ingress node, and if yes, determine that the current dependency node is a main packet node.
In one embodiment, step S30 includes:
Step c1, setting a father node of the dependent node as a target node based on the dependent structure tree, and determining whether the father node exists in the target node;
In one embodiment, a parent node of a current dependent node is determined to be a target node, and it is determined whether the target node has a parent node, i.e., whether a parent node of the dependent node has a parent node. It should be noted that the dependency node is a descendant node of the sub-packet entry node, that is, the dependency node includes a dependency child node, a dependency grandchild node, and the like, and when the dependency node is one, a parent node of the dependency node at least sub-packets the entry node; when the number of the dependent nodes is multiple, namely, the dependent nodes comprise multiple dependent child nodes or multiple dependent child nodes and multiple dependent grandchild nodes, the father node of each node needs to be set as the target node, and whether all the target nodes have the father nodes or not is determined through traversal.
Step c2, if so, determining whether a file path of a parent node of the target node contains a sub-packet name, wherein if so, determining that the dependent node is a main packet node;
If the parent node does not contain the sub-packet name, determining that the parent node of the current target node is the main packet node, and if the parent node of the current target node exists, determining that the target node is also the main packet node, namely, the current dependent node is the main packet node.
If there are M, N two parent nodes of the current dependency node, that is, the target node includes M and N, where M is a packetization entry node, then, if the file path of the parent node of N does not include a packetization name, then, it is determined that N is a main packet node, at this time, the dependency node is referred to by both packetization and 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 dependency file corresponding to the current dependency node should be downloaded at the first time, and therefore, the current dependency node is the main packet node.
If the file paths of the father node of the target node all contain packet names, determining the current dependent node as the packet node and being referenced by at least one packet.
And c3, if not, determining whether the file path of the target node contains the subcontract, wherein if the target node contains the node which does not contain the subcontract, determining the dependent node as the main packet node.
If the target node does not have a parent node, the target node is determined to be an entry node, so that the target node comprises at least one sub-packet entry node, at this time, only whether the file path of the target node contains a sub-packet name needs to be determined, if the target node has a node which does not contain the sub-packet name, the dependent node is determined to be referenced by both the sub-packet and the main packet, and the target dependent file is determined to be the main packet node.
If the file paths of the target nodes all contain the sub-packet names, the dependent nodes are determined to be sub-packet nodes and are referenced by at least one sub-packet.
In another embodiment, the type of each node of the dependency structure tree may be determined first, i.e., whether each node is a primary or a secondary packet node.
Specifically, a main packet inspection algorithm is adopted for determining:
i. and sequentially taking out a node P from the dependency structure tree, checking the father node of the P, if the father node is not present, the P is an entry node, directly judging the file path of the P, if the file path of the P does not contain a packet name, the P is a main packet node, ending the algorithm, and returning true.
Ii. If the P has a father node, traversing the father node of the P, if all father node file paths do not contain the subcontract, taking the P as a main packet node, ending the algorithm, and returning true.
And iii, checking whether the P is a dependent node, specifically detecting whether the file path of the P contains a second specific directory, such as node_ modules, if yes, determining that the P is the dependent node. If the P is determined to be a dependent node, i-iii are sequentially executed on the father nodes of the P, any father node returns true, the algorithm is ended, the P is judged to be a main packet node, and true is returned.
If the traversal is finished, P still does not meet the main packet judgment, and then false is returned, wherein P is a sub-packet node.
And step S40, if the node is a main package node, packaging the target dependency file corresponding to the dependency node into the main package of the small program item.
In this embodiment, if it is determined that the current dependency node is a master package node, the target dependency file corresponding to the dependency node is packaged into the master package of the applet item; and if the current dependent node is determined to be the sub-package node, packing the target dependent file corresponding to the dependent node into the 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; based on the dependency structure tree, determining a sub-package entry node of the applet item and a dependency node corresponding to the sub-package entry node; determining whether the dependent node is a master packet node based on the dependency structure tree; and if the target dependency file is the main package node, packaging the target dependency file corresponding to the dependency node into the main package of the small program item. According to the method, the device and the system, the project page of the applet page is read, so that the dependency structure tree is generated, and whether the dependency file is sub-packaged and referenced or is sub-packaged and referenced is determined based on the dependency structure tree, so that the dependency file is packaged into the main package or the sub-package, manual assignment is not needed, and intelligent packaging of the dependency file is realized.
Further, based on the first embodiment of the method for packaging the dependent file, a second embodiment of the method for packaging the dependent file is provided.
The second embodiment of the dependent file packing method differs from the first embodiment of the dependent file packing method in that, referring to fig. 3, the dependent file packing method further includes:
Step S50, if the sub-package node is the sub-package node, determining the node number of the sub-package entry node referencing 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 the sub-packets corresponding to the sub-packet entry nodes.
In this embodiment, if there are multiple sub-packets applying 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 packed into the main packet, so that the total size of the applet item can be reduced by N-1 target dependent files, where N is the number of sub-packets referencing the target dependent file.
The following will explain each step in detail:
And step S50, if the sub-package node is the sub-package node, determining the node number of the sub-package entry node referencing the dependency node based on the dependency structure tree.
In this embodiment, if it is determined that the dependency node is a sub-package node, the number of nodes referencing the sub-package entry node of the dependency node, that is, the number of sub-packages referencing the target dependency file corresponding to the dependency node, is determined through 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 the sub-packets corresponding to the sub-packet entry nodes.
In this embodiment, comparing the counted number of nodes with a preset number, and if the number of nodes of the sub-package entry node does not reach the preset number, packaging the target dependency files corresponding to the dependency nodes into sub-packages; if the number of the nodes of the sub-package entry node reaches a preset number, packing the target dependent files corresponding to the dependent nodes into the main package to reduce the total size of the applet item, wherein the preset number can be determined according to the actual situation, for example, according to the size of the target dependent files corresponding to the dependent nodes, for example, when the size of the target dependent files 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-packets corresponding to the sub-packet entry nodes includes:
Step d1, generating an output path of the target dependent file based on the sub-packet name of the sub-packet, and generating a relative path of the sub-packet based on the dependency structure tree and the output path;
In one embodiment, a new output path outputPath is generated for the target dependency file corresponding to the dependency node based on the subcontracting name of the subcontracting, e.g., x subcontracting, then the corresponding output path is x/npm/dependency name. Then, the relative path of the parent node relative to the new output path is regenerated according to the generated outputPath, and the relative path calculating method comprises the following steps: the output path of the parent node is an absolute path with respect to the newly generated outputPath, i.e., the new relative path.
Generating a corresponding relative path for the sub-packet entry node according to the new outputPath, wherein the relative path algorithm is as follows: the output path of the packetization ingress node is opposite 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.
Then, the target dependency file is packaged into a sub-package, and the sub-package's reference code is replaced according to the generated relative path so that the subsequent sub-package can correctly reference the target dependency file.
The present embodiment takes into account the following limitations in the current package size of applet items: the size of all sub-packets of the whole applet project is not more than 12M, and the size of a single sub-packet/main packet cannot be more than 2M, so that a third party dependent file on which the sub-packet depends should be put into the sub-packet as much as possible, and the space of the main packet can be saved, and the time for a user to load the applet for the first time is reduced; however, when N sub-packets depend on the same third-party dependent file at the same time, the dependent file is placed into the main packet in consideration of the total size of the small program packet, so that the total size of the small program item can be reduced by (N-1) third-party dependent file sizes, and intelligent packing of the dependent files is realized.
Further, based on the first and second embodiments of the present invention dependent file packing method, a third embodiment of the present invention dependent file packing method is provided.
The third embodiment of the dependent file packing method is different from the first and second embodiments of the dependent file packing method in that step S40 includes:
step e1, if the node is a main packet node, determining the size of a 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 a main package of the small program item.
In this embodiment, the applet item itself cannot be made very large like the application software, and in general, the main package of the applet item only has a size of 2M, so if the target dependency file is too large, it should be placed in the sub package, so that the main package has space, that is, the space of the main package preferentially places the files such as the code package corresponding to the main package.
The following will explain each step in detail:
and e1, if the node is a main packet node, determining the size of a target dependent file corresponding to the dependent node.
In this embodiment, if it is determined that the dependent node is a master packet node, the target dependent file corresponding to the dependent node should be normally placed in the master packet, but the size of the target dependent file needs to be determined first considering the size limitation of the master packet.
And e2, 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 small program item.
In this embodiment, comparing the size of the target dependent file with a preset size, and if the size of the target dependent file does not exceed the preset size, packing the target dependent file into a main package; if the size of the target dependent file exceeds the preset size, packaging the target dependent file into a sub-package, wherein the preset size can be set according to practical situations, for example, the size of the main package is determined, and when the method is implemented, the preset size can be set to be 500 kb.
In order to avoid the shortage of the main package space, the size of the target dependent file needs to be considered, so that the target dependent file is determined to be packaged into the main package or the sub package, and the intelligent packaging of the dependent file is realized.
The invention also provides a device for packaging the dependent file. The invention relates to a device for packaging dependent files, which comprises:
The generation 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;
The first determining module is used for 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;
the second determining module is used for determining whether the dependent node is a main packet node or not based on the dependent structure tree;
And the packing module is used for packing the target dependency file corresponding to the dependency node into the main package of the small program item if the target dependency file is the main package node.
Preferably, the packaging module is further configured to:
if the node is a sub-packaging node, determining the node number of the sub-packaging entry node referencing the dependency node based on the dependency 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 the sub-package corresponding to the sub-package entry node.
Preferably, the packaging module is further configured to:
Generating an output path of the target dependent file based on the subcontracting name of the subcontracting, and generating a relative path of the subcontracting based on the dependency structure tree and the output path;
And packing 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 node is the main package node, determining the size of a target dependent file corresponding to the dependent 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 small program item.
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 a second dependent file of the node to be processed based on the file content 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 the file suffix of the file content;
a first dependent file of the ingress node is determined based on the file suffix.
Preferably, the first determining module is further configured to:
traversing to determine whether a file path of an entry node in the dependency structure tree contains a subcontracting name;
determining an entry node of a file path containing a subcontracting name as a subcontracting entry node of the applet item;
And determining the dependency node corresponding to the sub-package entry node based on the dependency 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 father node exists in the target node;
If the parent node does not contain the sub-packet name, determining that the dependent node is a main packet node;
If the node which does not contain the sub-packet name exists in the target node, determining whether the file path of the target node contains the sub-packet name, wherein if the node which does not contain the sub-packet name exists in the target node, the dependent node is determined to be a 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 dependency file packaging program which, when executed by a processor, implements the steps of the dependency file packaging method as described above.
The method implemented when the dependency file packaging program running on the processor is executed may refer to various embodiments of the dependency file packaging method of the present invention, which are not described herein.
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 one … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The foregoing embodiment numbers of the present invention are merely for the purpose of description, and do not represent the advantages or disadvantages of the embodiments.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (e.g. ROM/RAM, magnetic disk, optical disk) as described above, comprising instructions for causing a terminal device (which may be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to perform the method according to the embodiments of the present invention.
The foregoing description is only of the preferred embodiments of the present invention, and is not intended to limit the scope of the invention, but rather is intended to cover any equivalents of the structures or equivalent processes disclosed herein, or any application, directly or indirectly, in the field of other related technology.
Claims (10)
1. The method for packaging the dependent file is characterized by comprising 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;
based on the dependency structure tree, determining a sub-package entry node of the applet item and a dependency node corresponding to the sub-package entry node;
determining whether the dependent node is a master packet node based on the dependency structure tree;
If the target dependency file is the main package node, packing the target dependency file corresponding to the dependency node into the main package of the applet item;
the step of determining whether the dependency node is a master packet 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 father node exists in the target node;
If the parent node does not contain the sub-packet name, determining that the dependent node is a main packet node;
If the node which does not contain the sub-packet name exists in the target node, determining whether the file path of the target node contains the sub-packet name, wherein if the node which does not contain the sub-packet name exists in the target node, the dependent node is determined to be a main packet node.
2. The dependent file packing method of claim 1, wherein after the step of determining whether the dependent node is a master packet node based on the dependency structure tree, the dependent file packing method further comprises:
if the node is a sub-packaging node, determining the node number of the sub-packaging entry node referencing the dependency node based on the dependency 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 the sub-package corresponding to the sub-package entry node.
3. The method of claim 2, wherein the step of packing each of the target dependent files corresponding to the dependent nodes into the sub-package corresponding to the sub-package entry node comprises:
Generating an output path of the target dependent file based on the subcontracting name of the subcontracting, and generating a relative path of the subcontracting based on the dependency structure tree and the output path;
And packing 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 of claim 1, wherein the step of packing the target dependency file corresponding to the dependency node into the main package of the applet item if the dependency file is the main package node comprises:
if the node is the main package node, determining the size of a target dependent file corresponding to the dependent 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 small program item.
5. The method of claim 1, wherein 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 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 a second dependent file of the node to be processed based on the file content 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 method of claim 5, wherein 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 the file suffix of the file content;
a first dependent file of the ingress node is determined based on the file suffix.
7. The method of 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 a file path of an entry node in the dependency structure tree contains a subcontracting name;
determining an entry node of a file path containing a subcontracting name as a subcontracting entry node of the applet item;
And determining the dependency node corresponding to the sub-package entry node based on the dependency structure tree.
8. A dependent file packing apparatus, the dependent file packing apparatus comprising:
The generation 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;
The first determining module is used for 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;
the second determining module is used for determining whether the dependent node is a main packet node or not based on the dependent structure tree;
The packing module is used for packing the target dependency file corresponding to the dependency node into the main package of the small program item if the target dependency file is the main package node;
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 father node exists in the target node;
If the parent node does not contain the sub-packet name, determining that the dependent node is a main packet node;
If the node which does not contain the sub-packet name exists in the target node, determining whether the file path of the target node contains the sub-packet name, wherein if the node which does not contain the sub-packet name exists in the target node, the dependent node is determined to be a main packet node.
9. A dependent file packing apparatus, the dependent file packing apparatus comprising: memory, a processor and a dependent file wrapper stored on the memory and executable on the processor, which when executed by the processor implements the steps of the dependent file wrapping method of any one of claims 1 to 7.
10. A computer readable storage medium, wherein a dependency file packaging program is stored on the computer readable storage medium, which when executed by a processor implements the steps of the dependency file packaging method according to any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010180529.1A CN111399863B (en) | 2020-03-13 | 2020-03-13 | Method, apparatus, device and computer readable storage medium for packaging dependent files |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010180529.1A CN111399863B (en) | 2020-03-13 | 2020-03-13 | Method, apparatus, device and computer readable storage medium for packaging dependent files |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111399863A CN111399863A (en) | 2020-07-10 |
CN111399863B true CN111399863B (en) | 2024-07-02 |
Family
ID=71430818
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010180529.1A Active CN111399863B (en) | 2020-03-13 | 2020-03-13 | Method, apparatus, device and computer readable storage medium for packaging dependent files |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111399863B (en) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111949312B (en) * | 2020-08-14 | 2024-02-09 | 曙光信息产业(北京)有限公司 | Packaging method and device for data module, computer equipment and storage medium |
CN113849217A (en) * | 2021-08-30 | 2021-12-28 | 北京达佳互联信息技术有限公司 | Resource packaging method and device, electronic equipment and storage medium |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109814913A (en) * | 2018-12-25 | 2019-05-28 | 华为终端有限公司 | Method and device for splitting, recombining and operating application package |
CN110532029A (en) * | 2019-09-04 | 2019-12-03 | 深圳前海微众银行股份有限公司 | Small routine generation method, device, equipment and computer readable storage medium |
Family Cites Families (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8266588B2 (en) * | 2007-11-12 | 2012-09-11 | International Business Machines Corporation | Creating projects in a rational application developer workspace |
US9355083B1 (en) * | 2015-02-06 | 2016-05-31 | Atlassian Pty Ltd | Systems and methods for generating an edit script |
CN110704096A (en) * | 2019-09-12 | 2020-01-17 | 北京达佳互联信息技术有限公司 | Packaging method and device of front-end item, storage medium and electronic equipment |
CN110825385B (en) * | 2019-10-29 | 2023-02-28 | 福建天泉教育科技有限公司 | Method for constructing read Native offline package and storage medium |
-
2020
- 2020-03-13 CN CN202010180529.1A patent/CN111399863B/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109814913A (en) * | 2018-12-25 | 2019-05-28 | 华为终端有限公司 | Method and device for splitting, recombining and operating application package |
CN110532029A (en) * | 2019-09-04 | 2019-12-03 | 深圳前海微众银行股份有限公司 | Small routine generation method, device, equipment and computer readable storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN111399863A (en) | 2020-07-10 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110990731A (en) | Rendering method, device and equipment of static webpage and computer storage medium | |
CN111045683A (en) | Applet code compiling method, device, equipment and medium | |
CN109871499A (en) | Page loading method and client | |
CN111399863B (en) | Method, apparatus, device and computer readable storage medium for packaging dependent files | |
CN110286917A (en) | File packing method, device, equipment and storage medium | |
CN111124544A (en) | Interface display method and device, electronic equipment and storage medium | |
CN112667287A (en) | Method, device and equipment for creating rule file and computer readable storage medium | |
CN110333872A (en) | A kind of processing method of application, device, equipment and medium | |
CN116431155A (en) | Front-end application construction method, medium, device and computing equipment | |
CN112052011A (en) | Method and device for combining small programs, electronic equipment and medium | |
CN113179269B (en) | Protocol data analysis method, system and medium based on Internet of things | |
CN111459497A (en) | WebPack-based resource package compiling method, system, server and storage medium | |
US7987454B2 (en) | System and method for emulating the processing of java server pages | |
CN115686606A (en) | Method, device, system and medium for displaying item dependency tree | |
CN111078631B (en) | File processing method, terminal equipment and storage medium | |
CN112597105A (en) | Processing method of file associated object, server side equipment and storage medium | |
CN116166907B (en) | Method and device for developing Web application by using WebAsssembly and service page compiling technology | |
CN110554867B (en) | Application processing method and device | |
CN113486267B (en) | Method, device, equipment and storage medium for analyzing application entry page | |
CN116302054A (en) | Development method and device of software project, storage medium and electronic equipment | |
CN114398073B (en) | Application updating method and device based on RN | |
CN117785213B (en) | Front-end construction tool and construction method based on Rust development | |
CN110716746B (en) | Method and device for converting RN style code into applet style code | |
CN112579129A (en) | Software updating method, device, equipment and storage medium based on server | |
CN111124914B (en) | Automatic test pre-compiling method, terminal and computer readable storage medium |
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 | ||
GR01 | Patent grant |