Public style automatic injection method and device, equipment and storage medium

By automatically injecting instructions and preset functions to generate path-relative paths, the problem of public style loss in the Taro framework is solved, efficient and accurate style file injection is achieved, and the efficiency of multi-terminal application development is improved.

CN120406966APending Publication Date: 2025-08-01深圳市分期乐网络科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510478274.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-16
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

In the prior art, when using the Taro framework to package and compile applets, common styles are easily lost, and the solution to manual addition or complex configurations is inefficient and error-prone, and it is impossible to accurately inject public styles.

Method used

The style file to be injected is obtained through the automatic injection instruction, the path relative path is generated, and the preset functions are used for traversal reading and data import, and the style file injection is performed after detecting the framework environment state, realizing automatic injection of common styles.

Benefits of technology

It improves the injection efficiency and accuracy of public style files, reduces labor consumption and configuration errors, and is suitable for multi-end application development.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120406966A_ABST
    Figure CN120406966A_ABST
Patent Text Reader

Abstract

The invention discloses a public style automatic injection method and device, equipment and a storage medium, and the method comprises the steps: responding to an automatic injection instruction, and obtaining a to-be-injected style file corresponding to the automatic injection instruction; obtaining a first path of the public style file and a second path of the to-be-injected style file, and obtaining a relative path between the first path and the second path through a first preset function; performing traversal reading and preset data import on the to-be-injected style file through a second preset function and the relative path to obtain a processed style file; if it is detected that the preset framework environment is in the starting state, style file injection is conducted on the processed style file based on the public style file and a second preset function, and a target file corresponding to the to-be-injected style file is obtained. According to the embodiment of the invention, the position of the specified style file in the to-be-injected style file can be automatically identified, and the public style file is automatically injected, so that the injection efficiency and accuracy of the public style file are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and particularly to a method, apparatus, device and storage medium for automatically injecting common styles. Background Art

[0002] When using the Taro framework (an open cross - end and cross - framework solution) to package and compile mini - programs, the problem of missing common styles often occurs. Existing solutions usually involve manually adding common styles to different pages and components one by one during development, or making complex settings in the compilation configuration. However, these methods are not only inefficient but also error - prone. More specifically, the prior art has the following technical deficiencies:

[0003] 1. The method of manually adding common styles is extremely cumbersome, consuming a large amount of manpower and time. Especially when there are a large number of pages and components, it is easy to miss some.

[0004] 2. Complex compilation configuration settings require a relatively high level of technical skills from developers. Ordinary developers are difficult to master accurately, which easily leads to configuration errors.

[0005] 3. Existing methods lack the ability to intelligently identify different paths and cannot accurately inject common styles according to the specific positions of pages and components. Summary of the Invention

[0006] Embodiments of the present invention provide a method, apparatus, device and storage medium for automatically injecting common styles, aiming to solve the problems in the prior art that when there are missing common styles during the packaging and compilation of mini - programs, adding common styles to different pages and components one by one manually during development or making complex settings in the compilation configuration is not only inefficient but also error - prone.

[0007] In a first aspect, an embodiment of the present invention provides a method for automatically injecting common styles, which includes:

[0008] Responding to an automatic injection instruction, obtaining a style file to be injected corresponding to the automatic injection instruction;

[0009] Obtaining a first path of a common style file and a second path of the style file to be injected, and generating a relative path between the first path and the second path through a first preset function;

[0010] Traversing and reading the style file to be injected and importing preset data through a second preset function and the relative path to obtain a processed style file;

[0011] If it is detected that the preset framework environment is already in the startup state, then based on the public style file and the second preset function, perform style file injection on the processed style file to obtain a target file corresponding to the style file to be injected.

[0012] In a second aspect, an embodiment of the present invention further provides a public style automatic injection device, which includes:

[0013] A style file to be injected acquisition unit, configured to respond to an automatic injection instruction and acquire a style file to be injected corresponding to the automatic injection instruction;

[0014] A relative path acquisition unit, configured to acquire a first path of a public style file and a second path of the style file to be injected, and generate a relative path between the first path and the second path through a first preset function;

[0015] A traversal reading unit, configured to perform traversal reading and preset data import on the style file to be injected through a second preset function and the relative path to obtain a processed style file;

[0016] An automatic injection unit, configured to, if it is detected that the preset framework environment is already in the startup state, then based on the public style file and the second preset function, perform style file injection on the processed style file to obtain a target file corresponding to the style file to be injected.

[0017] In a third aspect, an embodiment of the present invention further provides a computer device, which includes a memory and a processor. A computer program is stored on the memory, and when the processor executes the computer program, the method described in the first aspect above is implemented.

[0018] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium. The computer storage medium stores a computer program, and the computer program includes program instructions. When the program instructions are executed by a processor, the method described in the first aspect above can be implemented.

[0019] The embodiments of the present invention provide a method, apparatus, device and storage medium for automatic injection of common styles. The method includes: in response to an automatic injection instruction, obtaining a style file to be injected corresponding to the automatic injection instruction; obtaining a first path of a common style file and a second path of the style file to be injected, and obtaining a relative path between the first path and the second path through a first preset function; traversing and reading the style file to be injected and importing preset data through a second preset function and the relative path to obtain a processed style file; if it is detected that the preset framework environment has been started, injecting the processed style file based on the common style file and the second preset function to obtain a target file corresponding to the style file to be injected. The embodiments of the present invention can automatically identify the location of a specified style file in the style file to be injected and automatically inject the common style file, improving the injection efficiency and accuracy of the common style file. Description of the Drawings

[0020] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for the description of the embodiments will be briefly introduced below. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0021] Figure 1 It is a schematic diagram of the application scenario of the common style automatic injection method provided by the embodiments of the present invention;

[0022] Figure 2 It is a schematic flowchart of the common style automatic injection method provided by the embodiments of the present invention;

[0023] Figure 3 It is a schematic sub - flowchart of the common style automatic injection method provided by the embodiments of the present invention;

[0024] Figure 4 It is a schematic sub - flowchart of the common style automatic injection method provided by the embodiments of the present invention;

[0025] Figure 5 It is a schematic sub - flowchart of the common style automatic injection method provided by the embodiments of the present invention;

[0026] Figure 6 It is a schematic sub - flowchart of the common style automatic injection method provided by the embodiments of the present invention;

[0027] Figure 7 It is a schematic block diagram of the common style automatic injection device provided by the embodiments of the present invention;

[0028] Figure 8 It is a schematic block diagram of the computer device provided by the embodiments of the present invention. Detailed implementation mode

[0029] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

[0030] It should be understood that when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, wholes, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components, and / or their combinations.

[0031] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in this specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an", and "the" are intended to include the plural forms.

[0032] It should be further understood that the term "and / or" used in this specification of the present invention and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0033] Please refer to Figure 1 and Figure 2 at the same time, where Figure 1 is a schematic diagram of the scenario of the public style automatic injection method in the embodiment of the present invention, Figure 2 is a schematic flow diagram of the public style automatic injection method provided by the embodiment of the present invention. As Figure 1 shown, the public style automatic injection method provided by the embodiment of the present invention is applied to the server 10 or the user terminal 20, and the server 10 is communicatively connected to the user terminal 20.

[0034] As Figure 2 shown, the method includes the following steps S110-S140.

[0035] S110. In response to the automatic injection instruction, obtain the style file to be injected corresponding to the automatic injection instruction.

[0036] In this embodiment, the technical solution is described with the server or the user terminal as the execution subject. The Taro platform can be deployed in the server or the user terminal, and the Taro platform is an open cross-terminal and cross-framework solution platform, which can support users to develop multi-terminal applications using multiple frameworks, and a set of codes for a certain application can be compiled into multiple platforms, greatly improving the development efficiency. When automatic injection of common styles needs to be performed on the code of a certain application, first, the complete code file of the application needs to be imported into the Taro platform, and then after the import is completed, click the automatic injection start button on the user interface, and finally start the automatic injection process of the common style file, and the object to be processed in this automatic injection process is the style file to be injected (that is, the complete code file of the application in the above example). Among them, the common style file needs to be pre-stored in a specified storage area corresponding to the Taro platform for the Taro platform to call.

[0037] S120. Obtain the first path of the common style file and the second path of the style file to be injected, and generate a relative path between the first path and the second path through a first preset function.

[0038] In this embodiment, after obtaining the style file to be injected, it is also necessary to obtain the first path corresponding to the storage area where the common style file is stored and the second path corresponding to the current storage area of the style file to be injected. When the relative path between the first path and the second path is obtained, it is convenient to inject the common style file into the style file to be injected.

[0039] In one embodiment, as Figure 3 shown, step S120 includes:

[0040] S121. Obtain a first path array corresponding to the first path through the first preset function, and obtain a second path array corresponding to the second path through the first preset function;

[0041] S122. If it is determined that the first header data of the first path array is the same as the second header data of the second path array, delete the first header data of the first path array to update the first path array, and delete the second header data of the second path array to update the second path array;

[0042] S123. Compose the relative path in the order of the first preset string, the first path array, and the second path array.

[0043] In this embodiment, when obtaining the relative path between the first path and the second path, the specific process is to obtain the first path array corresponding to the first path through the first preset function (such as the getRelativePath function), and obtain the second path array corresponding to the second path through the first preset function. Among them, the first path array includes multiple array elements, and the array element ranked first is the root directory; similarly, the second path array includes multiple array elements, and the array element ranked first is the root directory. For example, if the first path is / home / user1 / file1, after the first path data is recognized and split by the first preset function, the first path array obtained includes four array elements: "", "home", "user1", and "file1". Of course, the above example is only for illustration and does not limit the first path to the above example. After obtaining the first path array and the second path array based on the first preset function, first compare whether the first header data of the first path array is the same as the second header data of the second path array, that is, compare whether the array elements corresponding to the first header data are the same as the array elements corresponding to the second header data. When it is determined that the first header data of the first path array is the same as the second header data of the second path array, delete the first header data of the first path array to update the first path array, and delete the second header data of the second path array to update the second path array. The two updated path arrays obtained still cannot be used as the relative path, and it is also necessary to splice them in the order of the first preset string (such as ".."), the first path array, and the second path array to form the relative path.

[0044] S130. Traverse and read the to-be-injected style file and import preset data through the second preset function and the relative path to obtain a processed style file.

[0045] In this embodiment, after obtaining the relative path between the first path and the second path, the to-be-injected style file can also be traversed and read for directories, subdirectories, and files and preset data can be imported through the second preset function (such as the processDirectory function). The processed style file obtained through the above processing is convenient for subsequent automatic injection of common style files.

[0046] In one embodiment, as Figure 4 shown, step S130 includes:

[0047] S131. Recursively traverse and read the files and subdirectories in the to-be-injected style file through the second preset function to obtain a traversal and read list;

[0048] S132. Process the data of files or subdirectories in the traversal read list according to a preset layer-by-layer recursive processing strategy until all files in the deepest depth of the tree structure of the traversal read list are processed, obtaining the processed style file.

[0049] Among them, the traversal read list corresponds to a tree structure.

[0050] In this embodiment, after obtaining the files in the to-be-injected style file, the files and subdirectories in the to-be-injected style file can still be recursively traversed and read through the second preset function (such as the processDirectory function) to obtain a traversal read list, so as to obtain the location where the style file is located. Generally, the traversal read list is a tree structure, and the depth of its tree structure is also known. Through this layer-by-layer traversal method, the location where the style file is located will not be missed.

[0051] Moreover, process the data of files or subdirectories in the traversal read list according to a preset layer-by-layer recursive processing strategy. When it is a file and a style file of a specified format (such as a.ttss file), the complete file path of the style file is obtained and a formula style import statement is added at the specified position of the file, so as to quickly complete the layer-by-layer processing of the to-be-injected style file and obtain the processed style file.

[0052] In one embodiment, as Figure 5 shown, step S132 includes:

[0053] S1321. Traverse and read the i-th level directory in the to-be-injected style file through the second preset function to obtain the i-th level traversal result; where the initial value of i is 1, and the first level directory is the root directory in the to-be-injected style file;

[0054] S1322. Construct a complete file path for the files or subdirectories in the i-th level traversal result;

[0055] S1323. Obtain the i-th level traversal result status information corresponding to the files or subdirectories in the i-th level traversal result;

[0056] S1324. If it is determined based on the i-th level traversal result status information that there are several file data of the first preset file type in the i-th level traversal result, then update the complete file path for each file data in the i-th level traversal result based on the complete file path and the relative path, and add a preset formula style import statement to each file data in the i-th level traversal result to update each file data in the i-th level traversal result;

[0057] S1325. If it is determined that there is a subdirectory type in the i-th level traversal result based on the i-th level traversal result status information, increment i by 1 to update the value of i.

[0058] S1326. Determine that i is less than or equal to N, and then return to execute the step of traversing and reading the i-th level directory in the to-be-injected style file through the second preset function to obtain the i-th level traversal result; where N is the tree structure depth of the traversal and reading list.

[0059] S1327. If it is determined that i is greater than N, obtain the current to-be-injected style file as the processed style file.

[0060] In this embodiment, when performing data processing on files or subdirectories in the traversal and reading list according to a preset layer-by-layer recursive processing strategy, the specific process is to first traverse and read the i-th level directory in the to-be-injected style file to obtain the i-th level traversal result. Generally, when i = 1, the first-level directory read is the root directory in the to-be-injected style file, and generally does not include sub-files. At this time, the process of incrementing i by 1 to update the value of i will be executed, that is, the value of i is updated to 2, and then return to execute step S1321. After that, taking i = 2 as an example, its specific processing process is as follows:

[0061] 1) In the second-level traversal result, the complete file path can be constructed first based on const filePath = path.join(directoryPath, file) (where directoryPath refers to the file or subdirectory to be processed).

[0062] 2) Obtain the second-level traversal result status information corresponding to the file or subdirectory in the second-level traversal result through await fs.lstat(filePath)).isDirectory().

[0063] 3) If it is determined that there is file data of a number of first preset file types (such as a.ttss file corresponding to the style file) in the second-level traversal result based on the second-level traversal result status information, then each file data in the second-level traversal result is updated based on the complete file path and the relative path to form a complete file path (such as constrelativePathToCommonScss = await getRelativePath

[0064] (directoryPath,

[0065] path.join(rootDirectoryPath, 'common.scss'),)

[0066] Among them, rootDirectoryPath represents the complete file path of the file data in the second-level traversal result. path.join(rootDirectoryPath, 'common.scss') in the getRelative function represents obtaining the relative path of the file data relative to the style file common.scss, and directoryPath represents the updated complete file path. And for each file data in the second-level traversal result, a preset formula style import statement is added (such as const newValue = `@import "${relativePathToCommonScss}";\n` + data) to update each file data in the second-level traversal result.

[0067] 4) After completing the processing of all style files in the second-level traversal result (i.e., the processing in step 3), if it is determined based on the second-level traversal result status information that there are subdirectory types in the second-level traversal result, no processing is required, and directly increment i by 1 to update the value of i (for example, increment 2 by 1 to update to 3).

[0068] 5) If it is determined that the current i (such as 3 finally obtained in step 4) is less than or equal to N, then return to execute step 1). It should be noted that the value of i in step 1 at this time (such as 2) will be incremented by 1 every time a round is executed.

[0069] Until all files in the deepest depth of the tree structure of the traversal read list are processed to obtain the processed style file. It can be seen that through the above traversal processing method, the style files to be injected can be processed layer by layer to obtain the required processed style file.

[0070] In an embodiment, updating the complete file path for each file data in the i-level traversal result based on the complete file path and the relative path in step S1324 includes:

[0071] For each file data in the i-level traversal result, obtain the first preset string in the relative path, and replace the first preset string in the relative path with the complete file path of the file data to update the complete file path of the file data.

[0072] In this embodiment, still taking the above example, when processing each file data through the getRelativePath function, the function path.join(rootDirectoryPath, 'common.scss') replaces the first preset string (such as ".." in the above example) in the relative path with the complete file path of the file data to update the complete file path of the file data. Through this processing, the file paths of each file data in the traversal result can be quickly updated.

[0073] In one embodiment, after step S1324, it further includes:

[0074] If it is determined that there is file data in the i-th level traversal result that does not have the formula style import statement, add the formula style import statement to the corresponding file data to update the file data.

[0075] In this embodiment, after step S1324, it is also possible to further verify whether there is file data in the i-th level traversal result that does not have the formula style import statement. Once there is file data that does not have the formula style import statement, add the formula style import statement to the corresponding file data to update the file data. If each file data has the formula style import statement, no processing is required. Through the above method, the quick inspection and supplementation of the formula style import statement in the file data are realized.

[0076] S140. If it is detected that the preset framework environment has been started, then perform style file injection on the processed style file based on the common style file and the second preset function to obtain a target file corresponding to the style file to be injected.

[0077] In this embodiment, if it is detected that the preset framework environment has been started, it means that the Taro framework corresponding to the Taro platform has been started. At this time, the common style file can be called again based on the second preset function to perform style file injection on the processed style file to obtain a target file corresponding to the style file to be injected. Specifically, the positions in the processed style file where there are formula style import statements can be updated with the common style file, thereby realizing the automatic injection of the common style file.

[0078] In one embodiment, as Figure 6 shown, step S140 includes:

[0079] S141. Inject the common style file into the page directory in the processed style file through the second preset function to obtain a first injected file;

[0080] S142. Inject the common style file into the component directory in the first injection file through the second preset function to obtain the target file.

[0081] In this embodiment, when injecting the common style file into the processed style file through the second preset function, the injection process can be first performed on the page directory (such as through await processDirectory(path.resolve(outputPath, '. / pages'), outputPath), where '. / pages' represents the page directory and the resolve() function can implement the injection operation), and then the injection process is performed on the component directory (such as through await processDirectory(path.resolve(outputPath, '. / components'), outputPath), where '. / components' represents the component directory and the resolve() function can implement the injection operation) to obtain the target file. It can be seen that the automatic injection of the common style file into the corresponding position in the processed style file is achieved through the above method.

[0082] It can be seen that the embodiments implementing this method can automatically identify the location of the specified style file in the style file to be injected and automatically inject the common style file, improving the injection efficiency and accuracy of the common style file.

[0083] Figure 7 It is a schematic block diagram of a common style automatic injection device provided by an embodiment of the present invention. As Figure 7 shown, corresponding to the above common style automatic injection method, the present invention also provides a common style automatic injection device 100. The common style automatic injection device 100 includes units for executing the above common style automatic injection method. Please refer to Figure 7 . The common style automatic injection device 100 includes: a style file to be injected acquisition unit 110, a relative path acquisition unit 120, a traversal and reading unit 130, and an automatic injection unit 140.

[0084] The style file to be injected acquisition unit 110 is configured to obtain the style file to be injected corresponding to the automatic injection instruction in response to the automatic injection instruction.

[0085] In this embodiment, the technical solution is described with the server or the user terminal as the execution entity. The Taro platform can be deployed in the server or the user terminal, and the Taro platform is an open cross-terminal and cross-framework solution platform, which can support users to develop multi-terminal applications using multiple frameworks, and a set of codes for a certain application can be compiled into multiple platforms, greatly improving the development efficiency. When it is necessary to automatically inject common styles into the code of a certain application, first, the complete code file of the application needs to be imported into the Taro platform, and then after the import is completed, click the automatic injection start button on the user interface, and finally start the automatic injection process of the common style file, and the object to be processed in this automatic injection process is the style file to be injected (that is, the complete code file of the application in the above example). Among them, the common style file needs to be pre-stored in a specified storage area corresponding to the Taro platform for the Taro platform to call.

[0086] The relative path acquisition unit 120 is used to acquire the first path of the common style file and the second path of the style file to be injected, and generate a relative path between the first path and the second path through a first preset function.

[0087] In this embodiment, after the style file to be injected is acquired, it is also necessary to acquire the first path corresponding to the storage area where the common style file is stored and the second path corresponding to the style file to be injected in the current storage area. After the relative path between the first path and the second path is acquired, it is convenient to inject the common style file into the style file to be injected.

[0088] In one embodiment, the relative path acquisition unit 120 is used for:

[0089] Acquire a first path array corresponding to the first path through the first preset function, and acquire a second path array corresponding to the second path through the first preset function;

[0090] If it is determined that the first header data of the first path array is the same as the second header data of the second path array, delete the first header data of the first path array to update the first path array, and delete the second header data of the second path array to update the second path array;

[0091] Form the relative path in the order of the first preset string, the first path array, and the second path array.

[0092] In this embodiment, when obtaining the relative path between the first path and the second path, the specific process is to obtain the first path array corresponding to the first path through the first preset function (such as the getRelativePath function), and obtain the second path array corresponding to the second path through the first preset function. Among them, the first path array includes multiple array elements, and the array element ranked first is the root directory; similarly, the second path array includes multiple array elements, and the array element ranked first is the root directory. For example, if the first path is / home / user1 / file1, after the first path data is recognized and split by the first preset function, the first path array obtained includes four array elements: "", "home", "user1", and "file1". Of course, the above example is only for illustration and does not limit the first path to the above example. After obtaining the first path array and the second path array based on the first preset function, first compare whether the first header data of the first path array is the same as the second header data of the second path array, that is, compare whether the array elements corresponding to the first header data are the same as the array elements corresponding to the second header data. When it is determined that the first header data of the first path array is the same as the second header data of the second path array, delete the first header data of the first path array to update the first path array, and delete the second header data of the second path array to update the second path array. The two updated path arrays obtained still cannot be used as the relative path, and it is also necessary to splice them in the order of the first preset string (such as ".."), the first path array, and the second path array to form the relative path.

[0093] The traversing and reading unit 130 is used to traverse and read the to-be-injected style file and import preset data through the second preset function and the relative path, so as to obtain the processed style file.

[0094] In this embodiment, after obtaining the relative path between the first path and the second path, the second preset function (such as the processDirectory function) can also be used to traverse and read the directories, subdirectories and files of the to-be-injected style file and import preset data. The processed style file obtained after the above processing is convenient for subsequent automatic injection of common style files.

[0095] In one embodiment, the traversing and reading unit 130 is used for:

[0096] Recursively traverse and read the files and subdirectories in the to-be-injected style file through the second preset function to obtain a traversing and reading list;

[0097] Perform data processing on the files or subdirectories in the traversal reading list according to a preset layer-by-layer recursive processing strategy until all files in the deepest depth of the tree structure of the traversal reading list are processed, obtaining the processed style file.

[0098] Among them, the traversal reading list corresponds to a tree structure.

[0099] In this embodiment, after obtaining the files in the to-be-injected style file, the files and subdirectories in the to-be-injected style file can still be recursively traversed and read through the second preset function (such as the processDirectory function) to obtain a traversal reading list to obtain the location where the style file is located. Generally, the traversal reading list is a tree structure, and its tree structure depth is also known. Through this layer-by-layer traversal method, the location where the style file is located will not be missed.

[0100] Moreover, perform data processing on the files or subdirectories in the traversal reading list according to a preset layer-by-layer recursive processing strategy. When the file is a style file of a specified format (such as a.ttss file), the complete file path of the style file is obtained and a formula style import statement is added at the specified location in the file, thus quickly completing the layer-by-layer processing of the to-be-injected style file and obtaining the processed style file.

[0101] In one embodiment, the performing data processing on the files or subdirectories in the traversal reading list according to a preset layer-by-layer recursive processing strategy until all files in the deepest depth of the tree structure of the traversal reading list are processed, obtaining the processed style file, includes:

[0102] Traverse and read the i-th level directory in the to-be-injected style file through the second preset function to obtain the i-th level traversal result; where the initial value of i is 1, and the first level directory is the root directory in the to-be-injected style file;

[0103] Construct a complete file path for the files or subdirectories in the i-th level traversal result;

[0104] Obtain the i-th level traversal result status information corresponding to the files or subdirectories in the i-th level traversal result;

[0105] If it is determined based on the i-th level traversal result status information that there are several file data of the first preset file type in the i-th level traversal result, then update the complete file path for each file data in the i-th level traversal result based on the complete file path and the relative path, and add a preset formula style import statement to each file data in the i-th level traversal result to update each file data in the i-th level traversal result;

[0106] If it is determined based on the i-th level traversal result status information that a sub-directory type exists in the i-th level traversal result, then i is incremented by 1 to update the value of i;

[0107] If it is determined that i is less than or equal to N, then returning to the step of traversing and reading the i-th level directory in the style file to be injected using the second preset function to obtain the i-th level traversal result; wherein N is the tree structure depth of the traversal reading list;

[0108] If it is determined that i is greater than N, the current style file to be injected is obtained as the processed style file.

[0109] In this embodiment, when the traversal read list is used to process the data of files or subdirectories according to the preset layer-by-layer recursive processing strategy, the specific process is to first traverse and read the i-th level directory in the style file to be injected to obtain the i-th level traversal result. Generally, when i=1, the first-level directory read is the root directory of the style file to be injected, and generally does not include subfiles. At this time, the value of i will be updated by incrementing i by 1, that is, the value of i will be updated to 2, and then the process returns to step S1321. Afterwards, taking i=2 as an example, the specific processing process is as follows:

[0110] 11) In the second-level traversal result, the complete file path can be constructed based on const filePath = path.join(directoryPath, file) (where directoryPath refers to the file or subdirectory to be processed);

[0111] 12) Get the second-level traversal result status information corresponding to the file or subdirectory in the second-level traversal result through await fs.lstat(filePath)).isDirectory();

[0112] 13) If it is determined based on the second-level traversal result status information that there are several file data of the first preset file type (such as .ttss files corresponding to the style file) in the second-level traversal result, the complete file path of each file data in the second-level traversal result is updated based on the complete file path and the relative path (such as constrelativePathToCommonScss=await getRelativePath

[0113] (directoryPath,

[0114] path.join(rootDirectoryPath,'common.scss'),)

[0115] Among them, rootDirectoryPath represents the complete file path of the file data in the second-level traversal result. path.join(rootDirectoryPath, 'common.scss') in the getRelative function represents obtaining the relative path of the file data relative to the style file common.scss, and directoryPath represents the updated complete file path; and for each file data in the second-level traversal result, a preset formula style import statement is added correspondingly (such as const newValue = `@import "${relativePathToCommonScss}";\n` + data) to update each file data in the second-level traversal result;

[0116] 14) After completing the processing of all style files in the second-level traversal result (i.e., the processing in step 13), if it is determined based on the second-level traversal result status information that there are subdirectories in the second-level traversal result, no processing is required, and directly increment i by 1 to update the value of i, for example, increment 2 by 1 to update to 3;

[0117] 15) If it is determined that the current i (such as 3 finally obtained in step 14) is less than or equal to N, then return to execute step 11). It should be noted that the value of i in step 11 at this time (such as 2) will be incremented by 1 every time a round is executed.

[0118] Until all files in the deepest depth of the tree structure of the traversal read list are processed to obtain the processed style file. It can be seen that through the above traversal processing method, the style files to be injected can be processed layer by layer to obtain the required processed style files.

[0119] In one embodiment, updating the complete file path for each file data in the i-th level traversal result based on the complete file path and the relative path includes:

[0120] For each file data in the i-th level traversal result, obtain the first preset string in the relative path, and replace the first preset string in the relative path with the complete file path of the file data to update the complete file path of the file data.

[0121] In this embodiment, still taking the above example, when processing each file data through the getRelativePath function, the function path.join(rootDirectoryPath, 'common.scss') replaces the first preset string (such as '..' in the above example) in the relative path with the complete file path of the file data to update the complete file path of the file data. Through this processing, the file paths of each file data in the traversal result can be quickly updated.

[0122] In one embodiment, the traversing and reading unit 130 is further configured to:

[0123] If it is determined that there is file data in the i-th level traversal result that does not have the formula style import statement, add the formula style import statement to the corresponding file data to update the file data.

[0124] In this embodiment, it is also possible to further verify whether there is file data in the i-th level traversal result that does not have the formula style import statement. Once there is file data that does not have the formula style import statement, add the formula style import statement to the corresponding file data to update the file data. If each file data has the formula style import statement, no processing is required. Through the above method, the quick check and supplement of the formula style import statement in the file data are realized.

[0125] The automatic injection unit 140 is configured to, if it is detected that the preset framework environment has been started, perform style file injection on the processed style file based on the common style file and the second preset function to obtain a target file corresponding to the style file to be injected.

[0126] In this embodiment, if it is detected that the preset framework environment has been started, it means that the Taro framework corresponding to the Taro platform has been started. At this time, the common style file can be called again based on the second preset function to perform style file injection on the processed style file to obtain a target file corresponding to the style file to be injected. Specifically, the positions in the processed style file that have the formula style import statement can be updated with the common style file, thereby realizing the automatic injection of the common style file.

[0127] In one embodiment, the automatic injection unit 140 is configured to:

[0128] Inject the common style file into the page directory in the processed style file through the second preset function to obtain a first injected file;

[0129] Inject the common style file into the component directory in the first injection file through the second preset function to obtain the target file.

[0130] In this embodiment, when injecting the common style file into the processed style file through the second preset function, the page directory can be injected first (such as through await processDirectory(path.resolve(outputPath,'. / pages'), outputPath), where '. / pages' represents the page directory and the resolve() function can implement the injection operation), and then the component directory can be injected (such as through await processDirectory(path.resolve(outputPath,'. / components'), outputPath), where '. / components' represents the component directory and the resolve() function can implement the injection operation) to obtain the target file. It can be seen that through the above method, the automatic injection of the common style file into the corresponding position in the processed style file is realized.

[0131] It can be seen that implementing the embodiment of this device can automatically identify the location of the specified style file in the style file to be injected and automatically inject the common style file, improving the injection efficiency and accuracy of the common style file.

[0132] The above-mentioned common style automatic injection device can be implemented in the form of a computer program, and this computer program can run on a computer device as shown in Figure 8 shown.

[0133] Please refer to Figure 8 , Figure 8 which is a schematic block diagram of a computer device provided by an embodiment of the present invention. This computer device integrates any common style automatic injection device provided by the embodiment of the present invention.

[0134] Refer to Figure 8 , this computer device 400 includes a processor 402, a memory, and a network interface 405 connected through a system bus 401. Among them, the memory can include a storage medium 403 and an internal memory 404.

[0135] The storage medium 403 can store an operating system 4031 and a computer program 4032. This computer program 4032 includes program instructions, and when these program instructions are executed, the processor 402 can be made to execute a common style automatic injection method.

[0136] The processor 402 is used to provide computing and control capabilities to support the operation of the entire computer device.

[0137] The internal memory 404 provides an environment for the operation of the computer program 4032 in the storage medium 403. When the computer program 4032 is executed by the processor 402, the processor 402 can be caused to execute the above-mentioned common style automatic injection method.

[0138] The network interface 405 is used for network communication with other devices. Those skilled in the art can understand that Figure 8 the structure shown in is only a block diagram of some structures related to the solution of the present invention, and does not constitute a limitation on the computer device to which the solution of the present invention is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.

[0139] Among them, the processor 402 is used to run the computer program 4032 stored in the memory to implement the common style automatic injection method as described above.

[0140] It should be understood that in the embodiment of the present invention, the processor 402 may be a central processing unit (CPU), and the processor 402 may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), off-the-shelf programmable gate arrays (FPGAs) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0141] Those of ordinary skill in the art can understand that all or part of the process in the method of implementing the above embodiment can be completed by instructing relevant hardware through a computer program. The computer program includes program instructions, and the computer program can be stored in a storage medium, and the storage medium is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the above method embodiment.

[0142] Therefore, the present invention also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, where the computer program includes program instructions. When the program instructions are executed by the processor, the processor is caused to execute the common style automatic injection method as described above.

[0143] The storage medium can be a variety of computer-readable storage media such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a magnetic disk, or an optical disc, etc., which can store program codes.

[0144] Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present invention.

[0145] In several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of each unit is only a logical function division, and there can be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.

[0146] The steps in the method embodiments of the present invention can be adjusted, combined, and deleted according to actual needs. The units in the device embodiments of the present invention can be combined, divided, and deleted according to actual needs. In addition, the functional units in each embodiment of the present invention can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit.

[0147] 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 storage medium. Based on such an understanding, the technical solution of the present invention, in essence, 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. The computer software product is stored in a storage medium and includes several instructions to enable a computer device (which can be a personal computer, a terminal, or a network device, etc.) to execute all or part of the steps of the methods described in each embodiment of the present invention.

[0148] As described above, the above is only the specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present invention can easily think of various equivalent modifications or substitutions, and these modifications or substitutions should all be covered by the protection scope of the present invention. Therefore, the protection scope of the present invention should be subject to the protection scope of the claims.

Claims

1. A method for automatically injecting a common style, characterized in that Including: In response to an automatic injection instruction, obtain a style file to be injected corresponding to the automatic injection instruction; Obtain the first path of the common style file and the second path of the style file to be injected, and generate a relative path between the first path and the second path through a first preset function; Traverse and read the style file to be injected and import preset data through a second preset function and the relative path to obtain a processed style file; If it is detected that the preset framework environment has been started, inject the processed style file based on the common style file and the second preset function to obtain a target file corresponding to the style file to be injected.

2. The method according to claim 1, wherein The generating the relative path between the first path and the second path through the first preset function includes: Obtain a first path array corresponding to the first path through the first preset function, and obtain a second path array corresponding to the second path through the first preset function; If it is determined that the first header data of the first path array is the same as the second header data of the second path array, delete the first header data of the first path array to update the first path array, and delete the second header data of the second path array to update the second path array; Form the relative path in the order of a first preset string, the first path array, and the second path array.

3. The method according to claim 1, characterized in that, The traversing and reading the style file to be injected and importing preset data through the second preset function and the relative path to obtain a processed style file includes: Recursively traverse and read files and subdirectories in the style file to be injected through the second preset function to obtain a traversal and reading list; wherein, the traversal and reading list corresponds to a tree structure; Perform data processing on files or subdirectories in the traversal and reading list according to a preset layer-by-layer recursive processing strategy until all files in the deepest depth of the tree structure of the traversal and reading list are processed to obtain the processed style file.

4. The method according to claim 3, characterized in that, The performing data processing on files or subdirectories in the traversal and reading list according to a preset layer-by-layer recursive processing strategy until all files in the deepest depth of the tree structure of the traversal and reading list are processed to obtain the processed style file includes: Traverse and read the i-th level directory in the style file to be injected through the second preset function to obtain an i-th level traversal result; wherein, the initial value of i is 1, and the first level directory is the root directory in the style file to be injected; Construct a complete file path for the files or subdirectories in the i-th level traversal result; Obtain the i-th level traversal result status information corresponding to the files or subdirectories in the i-th level traversal result; If it is determined based on the status information of the i-th level traversal result that there are several file data of the first preset file type in the i-th level traversal result, then each file data in the i-th level traversal result is updated with the complete file path based on the complete file path and the relative path, and a preset formula style import statement is added to each file data in the i-th level traversal result to update each file data in the i-th level traversal result; If it is determined based on the status information of the i-th level traversal result that there is a subdirectory type in the i-th level traversal result, then increment i by 1 to update the value of i; Determine that i is less than or equal to N, then return to execute the step of traversing and reading the i-th level directory in the to-be-injected style file through the second preset function to obtain the i-th level traversal result; where N is the depth of the tree structure of the traversal reading list; If it is determined that i is greater than N, then obtain the current to-be-injected style file as the processed style file.

5. The method according to claim 4, characterized in that, The step of updating the complete file path for each file data in the i-th level traversal result based on the complete file path and the relative path includes: For each file data in the i-th level traversal result, obtain the first preset string in the relative path, and replace the first preset string in the relative path with the complete file path of the file data to update the complete file path of the file data.

6. The method according to claim 4, wherein After the step of if it is determined based on the status information of the i-th level traversal result that there are several file data of the first preset file type in the i-th level traversal result, then each file data in the i-th level traversal result is updated with the complete file path based on the complete file path and the relative path, and a preset formula style import statement is added to each file data in the i-th level traversal result to update each file data in the i-th level traversal result, the method further includes: If it is determined that there is no formula style import statement in the file data in the i-th level traversal result, then add the formula style import statement to the corresponding file data to update the file data.

7. The method according to claim 1, characterized in that, The step of injecting the style file into the processed style file based on the common style file and the second preset function to obtain a target file corresponding to the to-be-injected style file includes: Inject the common style file into the page directory in the processed style file through the second preset function to obtain a first injected file; Inject the common style file into the component directory in the first injected file through the second preset function to obtain the target file.

8. An automatic injection device for common styles, characterized in that, Includes: A to-be-injected style file acquisition unit, configured to acquire a to-be-injected style file corresponding to the automatic injection instruction in response to the automatic injection instruction; A relative path acquisition unit, configured to acquire a first path of the common style file and a second path of the to-be-injected style file, and generate a relative path between the first path and the second path through a first preset function; A traversal reading unit, configured to perform traversal reading and preset data import on the to-be-injected style file through the second preset function and the relative path to obtain a processed style file; An automatic injection unit, configured to perform style file injection on the processed style file based on the common style file and the second preset function to obtain a target file corresponding to the style file to be injected if it is detected that the preset framework environment has been in a startup state.

9. A computer device, characterized in that, The computer device includes a memory and a processor. A computer program is stored on the memory. When the processor executes the computer program, the common style automatic injection method according to any one of claims 1-7 is implemented.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, and the computer program includes program instructions. When the program instructions are executed by a processor, the common style automatic injection method according to any one of claims 1-7 can be implemented.