File processing method and device for applet, electronic equipment and storage medium
By determining and updating file dependencies in the applet, automatic subcontracting of dependent files is achieved, the problem of the main package size exceeding the limit and manual subcontracting errors is solved, and the operation reliability of the applet is improved.
Patent Information
- Application Number
- CN202411120010.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-14
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2044-08-14
AI Technical Summary
In mini programs, there are more and more public methods for main packages, resulting in the volume of main packages exceeding the limit. Manual subcontracting is prone to errors, reducing the operating reliability of mini programs.
By obtaining the hash object in the applet, determining the file dependencies of the main package and subcontract, updating the path of the dependent file, moving the dependent file from the main package to the corresponding subcontract, realizing automatic subcontracting of dependent files, reducing the Subcontracting error rate.
It improves the operating reliability of the mini program, reduces the chance of the main package volume exceeding the limit, and enhances the reliability of subcontracting.
Smart Images

Figure CN119025138A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for processing files of a small program. Background Art
[0002] With the continuous development of the Internet, mini-program technology has been introduced into the daily services of various platforms. Mini-programs are lightweight applications that can be used without downloading. In order to ensure smooth operation, the function of supporting mini-program sub-package loading has been launched. The mini-program is divided into main packages and sub-packages. Users can load them on demand when using them, and the size of the main package and sub-packages is limited.
[0003] Public methods in the main package can be used in subpackages. With the iteration of the Mini Program, there are more and more public methods in the main package. When the size of the main package exceeds the limit, manual subpackage is currently used to copy and move the code in the main package to the subpackage in use. If multiple subpackages are in use, multiple copies of the code need to be copied to the corresponding subpackages. The manual subpackage method is prone to errors, resulting in low reliability of the Mini Program. Summary of the invention
[0004] The main purpose of the embodiments of the present application is to propose a file processing method, device, electronic device and storage medium for a mini-program, aiming to improve the operating reliability of the mini-program.
[0005] To achieve the above-mentioned purpose, a first aspect of an embodiment of the present application proposes a file processing method of a small program, the method comprising:
[0006] Obtain a first hash object, wherein the first hash object includes key-value pairs corresponding to each file in the mini-program; the key in the key-value pair corresponding to each file indicates the file path of the file, and the value in the key-value pair corresponding to each file indicates the file content of the file;
[0007] Determine the file dependencies between the main package and the sub-packages in the mini-program;
[0008] Determine, according to the file dependency relationship, dependent files in the main package that the sub-package depends on;
[0009] Performing an update operation on the first hash object, wherein the update operation includes: updating the path indicated by the key in the key-value pair corresponding to the dependent file in the first hash object to the path of the subpackage that depends on the dependent file;
[0010] Delete the file in the applet, and use the updated key-value pair in the first hash object to perform the file writing operation of the applet.
[0011] In some embodiments, after determining the file dependency relationship between the main package and the sub-packages in the mini-program, the method further includes:
[0012] Determine the non-dependent files in the main package according to the file dependency relationship;
[0013] After performing the file writing operation of the applet by using the updated key-value pair in the first hash object, the method further includes:
[0014] The non-dependent file is deleted from the applet.
[0015] In some embodiments, after determining the file dependency relationship between the main package and the sub-packages in the mini-program, the method further includes:
[0016] Determine the non-dependent files in the main package according to the file dependency relationship;
[0017] The updating operation further includes:
[0018] Delete the key-value pair corresponding to the non-dependent file in the first hash object.
[0019] In some embodiments, determining the file dependency relationship between the main package and the sub-packages in the mini-program includes:
[0020] Generate a second hash object, wherein the second hash object includes key-value pairs corresponding to each json file in the mini-program; the key in the key-value pair corresponding to each json file indicates the file path of the json file, and the value in the key-value pair corresponding to each json file indicates the file content of the json file; the second hash object records the dependency relationship of each file in the mini-program through the file content indicated by the value in each key-value pair;
[0021] Analyze the global configuration file of the mini-program to identify the file package to which each file in the mini-program belongs, wherein the file package is a main package or a sub-package;
[0022] The file dependency relationship between the main package and the sub-package is determined according to the second hash object and the file packages to which each file in the mini-program belongs.
[0023] In some embodiments, after determining the dependent file in the main package that the sub-package depends on according to the file dependency relationship, and before performing the update operation on the first hash object, the method further includes:
[0024] Generate a third hash object, wherein the third hash object includes a key-value pair corresponding to the dependent file; the key of the key-value pair corresponding to the dependent file indicates a path of a subpackage that depends on the dependent file, and the value of the key-value pair corresponding to the dependent file indicates a file path of the dependent file;
[0025] The updating of the path indicated by the key in the key-value pair corresponding to each dependent file in the first hash object to the path of the subpackage that depends on the dependent file includes:
[0026] Update the value of the key in the key-value pair corresponding to the dependent file in the first hash object to the value of the key in the key-value pair corresponding to the dependent file in the third hash object.
[0027] In some embodiments, updating the path indicated by the key in the key-value pair corresponding to each dependent file in the first hash object to the path of the subpackage that depends on the dependent file includes:
[0028] Update the file path of the dependent file in the main package to the path of the subpackage that depends on the dependent file;
[0029] Using the updated paths of the dependent files in the main package, the values of the keys in the key-value pairs corresponding to the dependent files in the first hash object are updated.
[0030] In some embodiments, updating the file path of the dependent file in the main package to the path of the subpackage that depends on the dependent file includes:
[0031] Determine the file type corresponding to the dependent file;
[0032] The file path of the dependent file is updated to a path of a subpackage that depends on the dependent file by using a path modification method corresponding to the file type.
[0033] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application proposes a file processing device for a small program, the device comprising:
[0034] An acquisition module, configured to acquire a first hash object, wherein the first hash object includes key-value pairs corresponding to each file in the mini-program; the key in the key-value pair corresponding to each file indicates a file path of the file, and the value in the key-value pair corresponding to each file indicates a file content of the file;
[0035] A first determination module, used to determine the file dependency relationship between the main package and the sub-packages in the mini-program;
[0036] A second determination module, configured to determine, according to the file dependency relationship, dependent files in the main package that the sub-package depends on;
[0037] An update module, configured to perform an update operation on the first hash object, wherein the update operation comprises: updating a path indicated by a key in a key-value pair corresponding to the dependent file in the first hash object to a path of a subpackage that depends on the dependent file;
[0038] An execution module is used to delete files in the applet and use the updated key-value pairs in the first hash object to execute the file writing operation of the applet.
[0039] To achieve the above objectives, a third aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the method described in the first aspect is implemented.
[0040] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in the first aspect is implemented.
[0041] In an embodiment of the present application, a first hash object including key-value pairs corresponding to each file in the mini-program is provided. In the first hash object, the key in the key-value pair corresponding to each file indicates the file path of the file, and the value indicates the file content of the file. After determining the file dependency relationship between the main package and the sub-package in the mini-program and identifying each dependent file in the main package that the sub-package depends on, an update operation can be performed on the first hash object, and the path indicated by the key in the key-value pair corresponding to each dependent file in the first hash object is updated to the path of the sub-package that depends on the dependent file, and then the file in the mini-program is deleted, and the file write operation of the mini-program is performed using the key-value pair in the updated first hash object. In this way, the dependent file will be written into the sub-package that depends on the dependent file, realizing automatic sub-packaging of the dependent file. In this way, the sub-packaging error rate of the dependent file can be reduced, thereby improving the reliability of sub-packaging, and further improving the operation reliability of the mini-program. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 This is one of the flowcharts of the file processing method of the mini program provided in the embodiment of the present application;
[0043] Figure 2 This is the second flowchart of the file processing method of the mini program provided in the embodiment of the present application;
[0044] Figure 3 This is the third flowchart of the file processing method of the mini program provided in the embodiment of the present application;
[0045] Figure 4 This is the fourth flowchart of the file processing method of the mini program provided in the embodiment of the present application;
[0046] Figure 5 It is a structural diagram of a file processing device of a small program provided in an embodiment of the present application;
[0047] Figure 6 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION
[0048] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0049] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0050] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0051] Artificial intelligence (AI) is a new technical science that studies and develops theories, methods, technologies and application systems for simulating, extending and expanding human intelligence. AI is a branch of computer science that attempts to understand the essence of intelligence and produce a new type of intelligent machine that can respond in a similar way to human intelligence. Research in this field includes robotics, speech recognition, image recognition, natural language processing and expert systems. AI can simulate the information process of human consciousness and thinking. AI is also a theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0052] Natural language processing (NLP): NLP uses computers to process, understand and apply human languages (such as Chinese, English, etc.). NLP is a branch of artificial intelligence and an interdisciplinary subject between computer science and linguistics. It is often referred to as computational linguistics. Natural language processing includes grammatical analysis, semantic analysis, and text understanding. Natural language processing is often used in technical fields such as machine translation, handwritten and printed character recognition, speech recognition and text-to-speech conversion, information intent recognition, information extraction and filtering, text classification and clustering, public opinion analysis and opinion mining. It involves data mining related to language processing, machine learning, knowledge acquisition, knowledge engineering, artificial intelligence research, and linguistic research related to language computing.
[0053] Information Extraction: A text processing technology that extracts specified types of entity, relationship, event and other factual information from natural language text and forms structured data output. Information extraction is a technology that extracts specific information from text data. Text data is composed of some specific units, such as sentences, paragraphs, and chapters. Text information is composed of some small specific units, such as characters, words, phrases, sentences, paragraphs, or a combination of these specific units. Extracting noun phrases, names, place names, etc. from text data are all text information extraction. Of course, the information extracted by text information extraction technology can be various types of information.
[0054] Image caption generates a natural language description for an image and uses the generated description to help applications understand the semantics expressed in the image visual scene. For example, image captioning can convert image retrieval into text retrieval, which is used to classify images and improve image retrieval results. People usually only need to take a quick glance to describe the details of the image visual scene, while automatically adding descriptions to images is a comprehensive and arduous computer vision task that requires converting the complex information contained in the image into a natural language description. Compared with ordinary computer vision tasks, image captioning not only requires identifying objects from images, but also requires associating the identified objects with natural semantics and describing them in natural language. Therefore, image description requires people to extract deep features of images, associate them with semantic features, and convert them for generating descriptions.
[0055] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, AI is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0056] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0057] The file processing method of the mini program provided in the embodiment of the present application can be applied to electronic devices such as terminals or servers, and can be specifically executed by electronic devices or software or plug-ins in electronic devices. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the file processing method of the mini program, etc., but is not limited to the above forms.
[0058] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0059] It should be noted that in each specific implementation of the present application, when it comes to the need to perform relevant processing based on data related to user identity or characteristics such as user information, user behavior data, user historical data, and user location information, the user's permission or consent will be obtained first, and the collection, use, and processing of these data will comply with relevant laws, regulations, and standards. In addition, when the embodiment of the present application needs to obtain the user's sensitive personal information, the user's separate permission or consent will be obtained through a pop-up window or by jumping to a confirmation page. After clearly obtaining the user's separate permission or consent, the necessary user-related data for the normal operation of the embodiment of the present application will be obtained.
[0060] The following describes the file processing method of the mini-program provided in the embodiment of the present application in conjunction with specific embodiments.
[0061] like Figure 1 As shown, the file processing method of the mini-program in the embodiment of the present application may include the following steps:
[0062] Step 101, obtain a first hash object, wherein the first hash object includes key-value pairs corresponding to each file in the mini-program; the key in the key-value pair corresponding to each file indicates the file path of the file, and the value in the key-value pair corresponding to each file indicates the file content of the file.
[0063] In the embodiment of the present application, a first hash object (file_contents) is provided, and the first hash object includes key-value pairs corresponding to each file in the applet. In the first hash object, for each file, the key of the corresponding key-value pair indicates the current file path of the file, and the value of the corresponding key-value pair indicates the current file content of the file.
[0064] It is understandable that when a file in the mini-program is updated, the first hash object may be updated accordingly. Further, the file update in the mini-program may include at least one of the following: adding or reducing a file in the mini-program; changing the storage location of a file in the mini-program; or changing the content of a file in the mini-program.
[0065] In specific implementation, the mini-program can be traversed to identify various files in the mini-program, such as js, json, wxml, wxss and other resource files; then, based on the identified files, the first hash object is constructed or updated.
[0066] Step 102, determining the file dependencies between the main package and the sub-packages in the mini-program.
[0067] In specific implementation, the dependency analysis can be performed on the files in the main package and sub-packages in the mini-program to obtain the file dependency relationship between the main package and sub-packages in the mini-program. The embodiment of the present application does not limit the method of performing dependency analysis on files, and any method that can be used for dependency analysis can fall within the protection scope of the embodiment of the present application.
[0068] The file dependencies between the main package and sub-packages in the applet can indicate at least one of the following:
[0069] Files in the main package that are depended on by the main package files;
[0070] Files in the main package that the sub-package files depend on;
[0071] Files in the main package that are not dependencies.
[0072] In the embodiments of the present application, reliance can also be understood as reference or use.
[0073] In one example, it is assumed that the applet includes a main package, sub-package 1 and sub-package 2. The main package includes files a, b, c and d; sub-package 1 includes files e and f; and sub-package 2 includes file g.
[0074] If file a is dependent on file d and file f; file b is dependent on file c, and file c is dependent on file f and file g. Then, file a is a file in the main package that is dependent on the main package file and the sub-package file, file b is a file in the main package that is dependent on the main package file, file c is a file in the main package that is dependent on the sub-package file, and file d is a file in the main package that is not dependent.
[0075] Step 103: Determine, based on the file dependency relationship, dependent files in the main package that the sub-package depends on.
[0076] In an embodiment of the present application, in order to reduce the size of the main package, the files in the main package that the sub-package files depend on indicated in the file dependency relationship can be determined as dependent files in the main package that the sub-package files depend on, and then these dependent files can be moved from the main package to the sub-package by executing steps 104 and 105.
[0077] In practical applications, the number of dependent files may be greater than or equal to 1. Each dependent file may be dependent on at least one subpackage file, and further, the at least one subpackage file may belong to one subpackage or to different subpackages. Subpackage files that depend on different dependent files may be the same or different, which may be determined according to actual conditions, and the embodiments of the present application do not limit this.
[0078] Step 104, performing an update operation on the first hash object, wherein the update operation includes: updating the path indicated by the key in the key-value pair corresponding to the dependent file in the first hash object to the path of the subpackage that depends on the dependent file.
[0079] In an embodiment of the present application, the dependent file can be moved from the main package to the sub-package by maintaining the first hash object.
[0080] In specific implementation, in order to move a dependent file from the main package to the sub-package, the path indicated by the key in the key-value pair corresponding to the dependent file in the first hash object can be updated, and the indicated path can be updated from the current storage location of the dependent file to: the path of the sub-package to which the sub-package file that depends on the dependent file belongs.
[0081] It can be understood that when a dependent file is dependent on files in n sub-packages, in order to maintain the normal operation of the mini-program, the dependent file needs to be moved to these n sub-packages. Therefore, after updating the first hash object, the key in the key-value pair corresponding to the dependent file indicates the addresses of n sub-packages, where n is a positive integer.
[0082] Step 105, delete the files in the applet, and use the updated key-value pairs in the first hash object to perform the file writing operation of the applet.
[0083] From the foregoing content, it can be seen that the first hash object includes key-value pairs corresponding to each file in the mini-program, and the key in the key-value pair corresponding to each file indicates the file path of the file, and the value indicates the file content of the file. Therefore, in an embodiment of the present application, the updated first hash object can be used to execute the file write operation of the mini-program, overwriting or creating a new file.
[0084] In order to move dependent files from the main package to the sub-package, in some embodiments, the dependent files can be first deleted from the applet, and then the key-value pairs of the dependent files in the updated first hash object can be used to rewrite the dependent files in the applet. In other embodiments, all files in the applet can be deleted, and then the files of the applet can be rewritten using the updated first hash object. Compared with the latter, the former only processes the dependent files in the applet, so the number of file processing can be reduced. Compared with the former, the latter does not need to distinguish between dependent files and other files, so the file processing steps can be reduced.
[0085] It can be understood that since the path indicated by the key in the key-value pair of the dependent file in the updated first hash object is updated to the path of the corresponding subpackage, the dependent file will be written into the corresponding subpackage, thus ensuring the accuracy of the dependent file movement.
[0086] The file processing method of the mini program of the embodiment of the present application is provided with a first hash object including key-value pairs corresponding to each file in the mini program. In the first hash object, the key in the key-value pair corresponding to each file indicates the file path of the file, and the value indicates the file content of the file. After determining the file dependency relationship between the main package and the sub-package in the mini program, and identifying each dependent file in the main package that is dependent on the sub-package, an update operation can be performed on the first hash object, and the path indicated by the key in the key-value pair corresponding to each dependent file in the first hash object is updated to the path of the sub-package that depends on the dependent file, and then the file in the mini program is deleted, and the file write operation of the mini program is performed using the key-value pair in the updated first hash object, so that the dependent file will be written into the sub-package that depends on the dependent file, and the automatic sub-packaging of the dependent file is realized. In this way, the sub-packaging error rate of the dependent file can be reduced, thereby improving the reliability of the sub-packaging, and then improving the operation reliability of the mini program. In addition, by automatically sub-packaging the dependent file, the probability of the main package exceeding the limit can be reduced.
[0087] In some embodiments, the file processing method of the applet of the embodiment of the present application is as follows: Figure 2 As shown, the following steps may be included:
[0088] Step 201, obtain a first hash object, wherein the first hash object includes key-value pairs corresponding to each file in the mini-program; the key in the key-value pair corresponding to each file indicates the file path of the file, and the value in the key-value pair corresponding to each file indicates the file content of the file.
[0089] Step 202, determining the file dependencies between the main package and the sub-packages in the mini-program.
[0090] Step 203: Determine, based on the file dependency relationship, the dependent files in the main package that the sub-package depends on.
[0091] For the specific implementation of steps 201 to 203, please refer to steps 101 to 103, which will not be repeated here.
[0092] Step 204: determine the non-dependent files in the main package according to the file dependency relationship.
[0093] In this embodiment, in order to further reduce the size of the main package, redundant files in the main package may be further deleted. In this embodiment of the present application, non-dependent files in the main package may be determined as redundant files.
[0094] In specific implementation, the non-dependent files in the main package indicated in the file dependency relationship can be determined as non-dependent files in the main package. It can be understood that the number of non-dependent files can be greater than or equal to 1.
[0095] The embodiment of the present application does not limit the execution order of step 203 and step 204, which can be determined based on actual needs and is not limited by the embodiment of the present application.
[0096] Step 205: perform an update operation on the first hash object, wherein the update operation includes: updating the path indicated by the key in the key-value pair corresponding to the dependent file in the first hash object to the path of the subpackage that depends on the dependent file.
[0097] Step 206, delete the files in the applet, and use the updated key-value pairs in the first hash object to perform the file writing operation of the applet.
[0098] For the specific implementation of step 205 and step 206, please refer to step 104 and step 105, which will not be repeated here.
[0099] Step 207: Delete the non-dependency file from the applet.
[0100] After determining the non-dependent files in the main package, the non-dependent files can be deleted from the main package. This can further reduce the probability of the main package size exceeding the limit, thereby improving the running reliability of the mini program.
[0101] The embodiment of the present application does not limit the execution order of step 205 and step 206 for realizing automatic subpackaging of dependent files, and step 207 for realizing automatic deletion of redundant files. The specific execution order can be determined based on actual needs, and the embodiment of the present application does not limit this.
[0102] As can be seen from the foregoing, the files written by the file writing operation of the applet may include only dependent files or all files of the applet. In the case where the files written by the file writing operation of the applet include only dependent files, steps 205 and 206 for realizing automatic subpackaging of dependent files, and step 207 for realizing automatic deletion of redundant files may be executed in parallel or successively. In the case where the files written by the file writing operation of the applet include all files of the applet, the deletion operation of the non-dependent files may be executed after the file writing operation of the applet is executed.
[0103] Understandably, compared to Figure 1 Example, Figure 2 The embodiment can further delete redundant files in the main package. Thus, through this embodiment, both the automatic subpackaging of dependent files and the deletion of redundant files can be achieved, thereby reducing the probability of the main package size exceeding the limit, thereby improving the running reliability of the mini program.
[0104] In some embodiments, the file processing method of the applet of the embodiment of the present application is as follows: Figure 3 shown. Figure 3 Example and Figure 2 The main difference between the embodiments is that the methods of deleting undependant files are different. Figure 2 In the embodiment, the deletion of the undependant files can be implemented independently of the first hash object; Figure 3 In the embodiment, the deletion of the non-dependent files can be implemented based on the first hash object, as described below.
[0105] like Figure 3 As shown, the file processing method of the mini-program in the embodiment of the present application may include the following steps:
[0106] Step 301, obtain a first hash object, wherein the first hash object includes key-value pairs corresponding to each file in the mini-program; the key in the key-value pair corresponding to each file indicates the file path of the file, and the value in the key-value pair corresponding to each file indicates the file content of the file.
[0107] Step 302, determining the file dependency relationship between the main package and the sub-packages in the mini-program.
[0108] Step 303: Determine, based on the file dependency relationship, the dependent files in the main package that the sub-package depends on.
[0109] Step 304: Determine the non-dependent files in the main package according to the file dependency relationship.
[0110] For the specific implementation of steps 301 to 304, please refer to steps 101 to 104, which will not be repeated here.
[0111] Step 305, performing an update operation on the first hash object, wherein the update operation includes: updating the path indicated by the key in the key-value pair corresponding to the dependent file in the first hash object to the path of the subpackage that depends on the dependent file; deleting the key-value pair corresponding to the non-dependent file in the first hash object.
[0112] Compared with step 205, step 305 further includes updating the first hash object by: deleting the key-value pairs corresponding to the non-dependent files in the first hash object. That is, the updated first hash object does not include the key-value pairs corresponding to the non-dependent files in the main package.
[0113] Step 306, delete the file in the applet, and use the updated key-value pair in the first hash object to perform the file write operation of the applet.
[0114] In step 306, in order to delete the non-dependent files in the main package, all files in the mini-program can be deleted, and then the updated first hash object is used to rewrite the files in the mini-program. It can be understood that since the updated first hash object does not include the key-value pairs corresponding to the non-dependent files in the main package, the files rewritten according to the updated first hash object will not include the non-dependent files in the main package, thereby achieving the deletion of the non-dependent files. In this way, compared to Figure 2 Example, Figure 3 The embodiment does not need to perform an additional and separate deletion operation of non-dependent files, thereby reducing the operation burden.
[0115] In this embodiment, for redundant files, their corresponding key-value pairs can be deleted from the first hash object, and then the updated first hash object is used to rewrite the files of the mini program to achieve automatic deletion of non-dependent files. In this way, the file processing steps can be reduced while minimizing the size of the main package, thereby reducing the operating burden.
[0116] In some embodiments, step 102 may include:
[0117] Generate a second hash object, wherein the second hash object includes key-value pairs corresponding to each json file in the mini-program; the key in the key-value pair corresponding to each json file indicates the file path of the json file, and the value in the key-value pair corresponding to each json file indicates the file content of the json file; the second hash object records the dependency relationship of each file in the mini-program through the file content indicated by the value in each key-value pair;
[0118] Analyze the global configuration file of the mini-program to identify the file package to which each file in the mini-program belongs, wherein the file package is a main package or a sub-package;
[0119] The file dependency relationship between the main package and the sub-package is determined according to the second hash object and the file packages to which each file in the mini-program belongs.
[0120] Considering that the file content of the json file records the dependencies of each component, and the components are composed of files such as js, json, wxml and wxss, the dependencies between the files of the mini-program can be determined by the file content of the json file. Based on this, in this embodiment, a second hash object (file_dependencies) including key-value pairs corresponding to each json file in the mini-program can be generated, and the dependencies of the files are recorded by the second hash object. In the second hash object, the key in the key-value pair corresponding to each json file indicates the file path of the json file, and the value indicates the file content of the json file.
[0121] In addition, the global configuration file (app.json) of the mini program can be analyzed to distinguish and mark the information of the main package (main_packages) and sub-packages (sub_packages), such as the file information included in the main package and the sub-package, so that the relationship between the file and the sub-package in the mini program can be determined based on the global configuration file.
[0122] Afterwards, the dependencies between the files in the mini-program and the ownership relationship between the files and sub-packages in the mini-program can be determined based on the second hash object, and the file dependencies between the main package and the sub-package can be determined.
[0123] In this embodiment, the dependency relationship between files in the mini-program is determined by a second hash object including key-value pairs corresponding to each json file in the mini-program, and the relationship between files and sub-packages in the mini-program is determined by analyzing the global configuration file of the mini-program, thereby determining the file dependency relationship between the main package and the sub-package. In this way, the reliability of determining the file dependency relationship between the main package and the sub-package can be improved, thereby improving the operating reliability of the mini-program.
[0124] The following describes the update of the path indicated by the key in the key-value pair corresponding to the dependent file in the first hash object.
[0125] In some embodiments, after determining the dependent file in the main package that the sub-package depends on according to the file dependency relationship, and before performing the update operation on the first hash object, the method further includes:
[0126] Generate a third hash object, wherein the third hash object includes a key-value pair corresponding to the dependent file; the key of the key-value pair corresponding to the dependent file indicates a path of a subpackage that depends on the dependent file, and the value of the key-value pair corresponding to the dependent file indicates a file path of the dependent file;
[0127] The updating of the path indicated by the key in the key-value pair corresponding to each dependent file in the first hash object to the path of the subpackage that depends on the dependent file includes:
[0128] Update the value of the key in the key-value pair corresponding to the dependent file in the first hash object to the value of the key in the key-value pair corresponding to the dependent file in the third hash object.
[0129] In some embodiments of the present application, a third hash object (sub_outside_packages) may be further generated to record relevant information of the dependent file, such as information of the subpackage corresponding to the dependent file. The subpackage corresponding to a dependent file may be understood as the subpackage to which the subpackage file that depends on the dependent file belongs. Then, the path information of the dependent file is updated using the relevant information of the dependent file recorded in the third hash object.
[0130] In this embodiment, the third hash object may include key-value pairs corresponding to dependent files. In the third hash object, the key in the key-value pair corresponding to a dependent file indicates the path of the subpackage to which the subpackage file that depends on the dependent file belongs, and the value indicates the file path of the dependent file.
[0131] Since the key in the key-value pair corresponding to the dependent file in the third hash object indicates the path of the corresponding sub-package, in this embodiment, the file path of the dependent file can be updated by adjusting the value of the key in the key-value pair corresponding to the dependent file in the first hash object to the value of the key in the key-value pair corresponding to the dependent file in the third hash object. In this way, the reliability of the update of the file path of the dependent file can be improved.
[0132] In some other embodiments, updating the path indicated by the key in the key-value pair corresponding to each dependent file in the first hash object to the path of the subpackage that depends on the dependent file includes:
[0133] Update the file path of the dependent file in the main package to the path of the subpackage that depends on the dependent file;
[0134] Using the updated paths of the dependent files in the main package, the values of the keys in the key-value pairs corresponding to the dependent files in the first hash object are updated.
[0135] In this embodiment, the file path of the dependent file can be first updated from the current file path to the path of the corresponding sub-package. Then, the value of the key in the key-value pair corresponding to the dependent file in the first hash object is updated using the updated path of the dependent file, so that the value of the key in the key-value pair corresponding to the dependent file in the first hash object indicates the updated path of the dependent file.
[0136] In specific implementation, in some implementations, after determining the dependent file and its corresponding sub-package, the file path of the dependent file in the main package can be directly updated to the path of the sub-package that depends on the dependent file. In other implementations, the file path of the dependent file in the main package can be updated to the path of the sub-package that depends on the dependent file based on the third hash object.
[0137] In this embodiment, the updated path of the dependent file is directly used to update the value of the key in the key-value pair corresponding to the dependent file in the first hash object, which can simplify the update of the file path of the dependent file.
[0138] Further, updating the file path of the dependent file in the main package to the path of the subpackage that depends on the dependent file includes:
[0139] Determine the file type corresponding to the dependent file;
[0140] The file path of the dependent file is updated to a path of a subpackage that depends on the dependent file by using a path modification method corresponding to the file type.
[0141] In this embodiment, further, considering that there are various file types, the path modification methods of different file types may be different. In order to improve the update reliability of the file path of the dependent files, the file type corresponding to each dependent file can be determined first, and then the path modification method corresponding to the file type of the dependent file can be used to update the file path.
[0142] Optionally, for json files, you can modify the usingComponents field to point to a new relative path to modify the path of the json file. For js files, you can use @babel / traverse to traverse the AST (abstract syntax tree) and replace the file path to modify the path of the js file. For wxml and wxss files, you can replace the path by comparing the paths.
[0143] In this embodiment, for each dependent file, the path modification method corresponding to the file type is adopted to update the file path, so that the update reliability of the file path of the dependent file can be improved.
[0144] It should be noted that the various embodiments and implementation methods in the embodiments of the present application can be implemented independently or in combination without conflicting with each other. The specific implementation method can be determined based on actual needs, and the embodiments of the present application are not limited to this.
[0145] For ease of understanding, an example is provided below using a scenario implementation example.
[0146] In this scenario embodiment, if Figure 4 As shown, the following steps may be included:
[0147] Initialize scanning: traverse the applet file package, identify configuration and resource files such as js, .json, wxml, wxss, etc., and build a hash object file_contents, where the key is the file path and the value is the file content.
[0148] Dependency extraction: Filter out all .json files from file_contents, parse these files to extract the dependencies between components, and form a new hash object file_dependencies to record the dependencies of each file.
[0149] Package structure identification: Analyze app.json, distinguish and mark the main package (main_packages) and sub-package (sub_packages) information.
[0150] Dependency analysis: According to file_dependencies, as well as the information of main packages (main_packages) and sub-packages (sub_packages), recursively analyze the dependencies of the files in the main package and sub-packages, identify the main package files that are not depended on by other files, and generate a redundant file list (main_unused_packages), as well as the main package files that the sub-package files depend on, and generate sub_outside_packages.
[0151] File migration and processing: Move the main package dependency files listed in sub_outside_packages to the corresponding sub-package folders. Update the path information of these files according to sub_outside_packages. For json files, directly modify the usingComponents field to point to the new relative path; for js files, use @babel / traverse to traverse AST and replace the file path; for wxml and wxss files, directly replace the path.
[0152] Content update and writing: Update the information in file_contents according to the processed content. Then, traverse file_contents and perform file writing operations according to the latest key-value pairs to overwrite or create new configuration and resource files.
[0153] Redundant file cleanup: According to main_unused_packages, safely delete those files that are no longer needed.
[0154] In this scenario embodiment, the above method can be executed by the applet automatic sub-package plug-in, such as Figure 4 As shown, the applet automatic packaging plug-in may include a scanner, an analyzer, a resolver, a mover, and a cleaner.
[0155] In this embodiment, the mini-program automatic sub-packaging plug-in only needs to write code once to realize the automatic sub-packaging of dependent files and the automatic cleaning of redundant files. The code is highly maintainable, effectively avoiding repeated code writing and reducing the probability of errors. In addition, the calling relationship between the main package and the sub-package is clear, and the redundant code that is not referenced can be automatically removed and optimized to reduce the overall code volume.
[0156] See also Figure 5 The present application also provides a file processing device for a small program, which can implement the file processing method of the small program, and the device includes:
[0157] The acquisition module 501 is used to acquire a first hash object, wherein the first hash object includes key-value pairs corresponding to each file in the mini-program; the key in the key-value pair corresponding to each file indicates the file path of the file, and the value in the key-value pair corresponding to each file indicates the file content of the file;
[0158] A first determination module 502 is used to determine the file dependency relationship between the main package and the sub-packages in the mini-program;
[0159] A second determination module 503 is used to determine, according to the file dependency relationship, dependent files in the main package that the sub-package depends on;
[0160] An update module 504 is used to perform an update operation on the first hash object, wherein the update operation includes: updating the path indicated by the key in the key-value pair corresponding to the dependent file in the first hash object to a path of a subpackage that depends on the dependent file;
[0161] The execution module 505 is used to delete the files in the applet and use the updated key-value pairs in the first hash object to execute the file writing operation of the applet.
[0162] The file processing device of the mini program in the embodiment of the present application can implement each step in the file processing method of the mini program mentioned above and achieve the same beneficial effects, which will not be repeated here.
[0163] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the file processing method of the above-mentioned applet when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.
[0164] See also Figure 6 , Figure 6 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:
[0165] The processor 601 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solution provided in the embodiment of the present application.
[0166] The memory 602 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 602 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 602, and the processor 601 calls and executes the file processing method of the applet in the embodiment of this application.
[0167] The input / output interface 603 is used to implement information input and output.
[0168] The communication interface 604 is used to realize the communication interaction between this device and other devices. Communication can be realized through wired methods (such as USB, network cable, etc.) or wireless methods (such as mobile network, WIFI, Bluetooth, etc.).
[0169] The bus 605 transmits information between various components of the device (eg, the processor 601 , the memory 602 , the input / output interface 603 , and the communication interface 604 ).
[0170] The processor 601 , the memory 602 , the input / output interface 603 and the communication interface 604 are connected to each other in communication within the device via the bus 605 .
[0171] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer program, and when the computer program is executed by a processor, it implements the file processing method of the above-mentioned applet.
[0172] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0173] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0174] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.
[0175] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0176] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.
[0177] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0178] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0179] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0180] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0181] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0182] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store programs.
[0183] The preferred embodiments of the present application are described above with reference to the accompanying drawings, but the scope of the rights of the present application is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present application should be within the scope of the rights of the present application.
Claims
1. A file processing method for a small program, It is characterized in that The method comprises: Obtain a first hash object, wherein the first hash object includes key-value pairs corresponding to each file in the mini-program; the key in the key-value pair corresponding to each file indicates the file path of the file, and the value in the key-value pair corresponding to each file indicates the file content of the file; Determine the file dependencies between the main package and the sub-packages in the mini-program; Determine, according to the file dependency relationship, dependent files in the main package that the sub-package depends on; Performing an update operation on the first hash object, wherein the update operation includes: updating the path indicated by the key in the key-value pair corresponding to the dependent file in the first hash object to the path of the subpackage that depends on the dependent file; Delete the file in the applet, and use the updated key-value pair in the first hash object to perform the file writing operation of the applet.
2. The method according to claim 1, It is characterized in that After determining the file dependency relationship between the main package and the sub-packages in the mini-program, the method further includes: Determine the non-dependent files in the main package according to the file dependency relationship; After performing the file writing operation of the applet by using the updated key-value pair in the first hash object, the method further includes: The non-dependent file is deleted from the applet.
3. The method according to claim 1, It is characterized in that After determining the file dependency relationship between the main package and the sub-packages in the mini-program, the method further includes: Determine the non-dependent files in the main package according to the file dependency relationship; The updating operation further includes: Delete the key-value pair corresponding to the non-dependent file in the first hash object.
4. The method according to claim 1, It is characterized in that Determining the file dependency relationship between the main package and the sub-packages in the mini-program includes: Generate a second hash object, wherein the second hash object includes key-value pairs corresponding to each json file in the mini-program; the key in the key-value pair corresponding to each json file indicates the file path of the json file, and the value in the key-value pair corresponding to each json file indicates the file content of the json file; the second hash object records the dependency relationship of each file in the mini-program through the file content indicated by the value in each key-value pair; Analyze the global configuration file of the mini-program to identify the file package to which each file in the mini-program belongs, wherein the file package is a main package or a sub-package; The file dependency relationship between the main package and the sub-package is determined according to the second hash object and the file packages to which each file in the mini-program belongs.
5. The method according to claim 1, It is characterized in that After determining the dependent file in the main package that the sub-package depends on according to the file dependency relationship, and before performing the update operation on the first hash object, the method further includes: Generate a third hash object, wherein the third hash object includes a key-value pair corresponding to the dependent file; the key of the key-value pair corresponding to the dependent file indicates a path of a subpackage that depends on the dependent file, and the value of the key-value pair corresponding to the dependent file indicates a file path of the dependent file; The updating of the path indicated by the key in the key-value pair corresponding to each dependent file in the first hash object to the path of the subpackage that depends on the dependent file includes: Update the value of the key in the key-value pair corresponding to the dependent file in the first hash object to the value of the key in the key-value pair corresponding to the dependent file in the third hash object.
6. The method according to claim 1, It is characterized in that The updating of the path indicated by the key in the key-value pair corresponding to each dependent file in the first hash object to the path of the subpackage that depends on the dependent file includes: Update the file path of the dependent file in the main package to the path of the subpackage that depends on the dependent file; Using the updated paths of the dependent files in the main package, the values of the keys in the key-value pairs corresponding to the dependent files in the first hash object are updated.
7. The method according to claim 6, It is characterized in that The updating of the file path of the dependent file in the main package to the path of the subpackage that depends on the dependent file includes: Determine the file type corresponding to the dependent file; The file path of the dependent file is updated to a path of a subpackage that depends on the dependent file by using a path modification method corresponding to the file type.
8. A file processing device for a small program, It is characterized in that The device comprises: An acquisition module, configured to acquire a first hash object, wherein the first hash object includes key-value pairs corresponding to each file in the mini-program; the key in the key-value pair corresponding to each file indicates a file path of the file, and the value in the key-value pair corresponding to each file indicates a file content of the file; A first determination module, used to determine the file dependency relationship between the main package and the sub-packages in the mini-program; A second determination module, configured to determine, according to the file dependency relationship, dependent files in the main package that the sub-package depends on; An update module, configured to perform an update operation on the first hash object, wherein the update operation comprises: updating a path indicated by a key in a key-value pair corresponding to the dependent file in the first hash object to a path of a subpackage that depends on the dependent file; An execution module is used to delete files in the applet and use the updated key-value pairs in the first hash object to execute the file writing operation of the applet.
9. An electronic device, It is characterized in that The electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the file processing method of the applet described in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium storing a computer program. It is characterized in that When the computer program is executed by a processor, the file processing method of the applet described in any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Method and system for obtaining Unity 3D resource reference relationship
CN111078309A
Dependent file packaging method, device and equipment and computer readable storage medium
CN111399863A
Applet local compiling method, device and equipment and computer readable storage medium
CN114003234A
Small program compiling method and device, medium and equipment
CN116185421A
Data caching method and device based on local file in WeChat applet
CN117171117A
