CN109783133B - Code packaging method and device, computer equipment and storage medium - Google Patents

Code packaging method and device, computer equipment and storage medium Download PDF

Info

Publication number
CN109783133B
CN109783133B CN201910044789.3A CN201910044789A CN109783133B CN 109783133 B CN109783133 B CN 109783133B CN 201910044789 A CN201910044789 A CN 201910044789A CN 109783133 B CN109783133 B CN 109783133B
Authority
CN
China
Prior art keywords
state
code module
current
determining
module
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910044789.3A
Other languages
Chinese (zh)
Other versions
CN109783133A (en
Inventor
陈强
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Chengshi Wanglin Information Technology Co Ltd
Original Assignee
Beijing Chengshi Wanglin Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Chengshi Wanglin Information Technology Co Ltd filed Critical Beijing Chengshi Wanglin Information Technology Co Ltd
Priority to CN201910044789.3A priority Critical patent/CN109783133B/en
Publication of CN109783133A publication Critical patent/CN109783133A/en
Application granted granted Critical
Publication of CN109783133B publication Critical patent/CN109783133B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Stored Programmes (AREA)

Abstract

The invention discloses a code packaging method, a code packaging device, computer equipment and a storage medium, wherein the method comprises the following steps: determining the current introduction state of a code module included in an entry file of the application software; determining an object code module of the import state to be adjusted in the entry file according to the environment to be packaged selected by the user and each current import state; adjusting the current lead-in state of each object code module to obtain an entry file to be compiled; and compiling the entry file to be compiled to obtain a packed file corresponding to the environment to be packed. By using the method, compiling and packaging of different packaging environments based on the same entry file are realized, and compared with the method for compiling and packaging different entry files corresponding to different packaging environments, the method reduces the space resource occupation for repeatedly introducing the same code into different entry files, reduces the risk of code introduction errors, and reduces the maintenance cost required by code packaging.

Description

Code packaging method and device, computer equipment and storage medium
Technical Field
The present invention relates to the field of computer application technologies, and in particular, to a code packing method and apparatus, a computer device, and a storage medium.
Background
Currently, in software project development, the front end of the software project development adopts new syntax standard ECMAScript 6 or ECMAScript 7 of JavaScript language to write JS (JavaScript) codes, but browsers cannot support the syntax well, so before deploying the JS codes in the browser environment, a translation process needs to be executed first, that is, the JS codes are converted into codes capable of being recognized by the browser. This transformation process is referred to in software project development as packaging, and the files generated after packaging may be referred to as bundle files. Generally, in software project development, when a Javascript framework (library) and business code are written, a scenario that different codes need to be provided in a test environment and a production environment is often encountered (for example, more code modules need to be provided in the test environment than in the production environment), and thus, when packaging is performed in different environments, code modules participating in packaging are different.
In the existing packaging scheme, for the same development project, in order to implement packaging operations in different environments, different entry files are usually set corresponding to the different environments, then code modules required by the different environments are respectively introduced (copied) into the entry files corresponding to the environments, and finally the entry files in the different environments are compiled to obtain the packaging files in the corresponding environments. The defects of the existing packaging method are as follows: 1) for code modules in different environments, the code modules need to be repeatedly introduced into different entry files, so that unnecessary space resource occupation is caused; 2) for specific code modules belonging to different environments, an entry file belonging to the specific code module needs to be manually determined and correspondingly introduced, so that the occupation of human resources is increased, and the risk of code introduction errors is increased; 3) for a code module, if the code module contains both public codes belonging to two environments and non-public codes belonging to any one environment, then a public code part in the code module needs to be extracted and redefined as a new code module, but the mode of extracting the codes to form the new code module is easy to increase the total number of the code modules, thereby increasing the maintenance cost of the developed software.
Disclosure of Invention
The embodiment of the invention provides a code packaging method, a code packaging device, computer equipment and a storage medium, and simply and efficiently realizes packaging of code modules required under different packaging environments.
In a first aspect, an embodiment of the present invention provides a code packing method, including:
determining the current introduction state of a code module included in an entry file of the application software;
determining an object code module of the import state to be adjusted in the entry file according to the environment to be packaged selected by the user and each current import state;
adjusting the current lead-in state of each object code module to obtain an entry file to be compiled;
and compiling the entry file to be compiled to obtain a packed file corresponding to the environment to be packed.
Further, the current introduction state includes: a non-readable state and a readable state;
correspondingly, the determining the current introduction state of the code module included in the entry file of the application software comprises the following steps: determining the current introduction state of a code module with an annotation mark in an entry file of the application software as a non-readable state; and determining the current introduced state of the code module without the annotation mark in the entry file as a readable state.
Further, the annotation is marked as: including strings of set annotation identifiers and set key identifiers.
Further, the determining an object code module of the import state to be adjusted in the entry file according to the environment to be packaged selected by the user and each of the current import states includes: determining an environment to be packaged selected by a user, and traversing each code module in the entry file; if the code module belongs to the environment to be packaged and the current introduction state of the code module is a non-readable state, determining that the code module is a target code module of which the introduction state is to be adjusted; and if the code module does not belong to the environment to be packaged and the current introduction state of the code module is a readable state, determining that the code module is a target code module of which the introduction state is to be adjusted.
Further, the adjusting the current introduction state of each target code module includes: for each object code module, if the current introduction state of the object code module is a non-readable state, adjusting the current introduction state of the object code module based on a first adjustment policy; if the current introduction state of the target code module is a readable state, adjusting the current introduction state of the target code module based on a second adjustment strategy;
wherein the first adjustment strategy is different from the second adjustment strategy.
Further, the adjusting the current incoming state of the target code module based on the first adjustment policy includes: searching for an annotation mark of the target code module; and replacing the found annotation mark by the set character.
Further, the adjusting the current incoming state of the target code module based on the second adjustment policy includes: determining the start-stop position of the object code module in the entry file; annotation tags are added at the start and stop positions.
In a second aspect, an embodiment of the present invention provides a code packaging apparatus, including:
the state determining module is used for determining the current introduction state of the code module included in the entry file of the application software;
the target determining module is used for determining a target code module of the import state to be adjusted in the entry file according to the environment to be packaged selected by the user and each current import state;
the state adjusting module is used for adjusting the current introduction state of each target code module to obtain an entry file to be compiled;
and the file compiling module is used for compiling the entry file to be compiled to obtain a packed file corresponding to the environment to be packed.
In a third aspect, an embodiment of the present invention provides a computer device, including:
one or more processors;
storage means for storing one or more programs;
the one or more programs are executed by the one or more processors, so that the one or more processors implement the code packaging method provided by the embodiment of the invention.
In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the code packaging method provided by the embodiment of the present invention.
In the code packing method, the device, the computer equipment and the storage medium, the packing method firstly determines the current lead-in state of a code module included in an entry file of application software, then determines an object code module of which the lead-in state is to be adjusted in the entry file according to a to-be-packed environment selected by a user and each current lead-in state, then adjusts the current lead-in state of each object code module to obtain an entry file to be compiled, and finally compiles the entry file to be compiled to obtain a packed file corresponding to the to-be-packed environment. According to the technical scheme, the packaging files suitable for different packaging environments can be obtained by introducing all code modules of the introduced application software into the same entry file for compiling, compared with the mode that the different packaging environments correspond to different entry files for packaging, the method reduces the space resource occupation of repeatedly introducing the same codes into different entry files, reduces the risk of code introduction errors when the codes are introduced into different entry files, and simultaneously avoids code module separation caused by the fact that different parts of the code modules are suitable for different packaging environments, thereby reducing the maintenance cost required by code packaging.
Drawings
Fig. 1 is a schematic flowchart of a code packing method according to an embodiment of the present invention;
fig. 2 is a schematic flowchart of a code packing method according to a second embodiment of the present invention;
fig. 3 is a block diagram of a code packaging apparatus according to a third embodiment of the present invention;
fig. 4 is a hardware structure diagram of a computer device according to a fourth embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Example one
Fig. 1 is a flowchart of a code packaging method according to an embodiment of the present invention, where the method is suitable for compiling and packaging a front-end code module of a developed application under different packaging environments, and the method may be executed by a code packaging apparatus, where the apparatus may be implemented by software and/or hardware and is generally integrated on a computer device, and the computer device may specifically be an electronic device supporting development and programming of the application.
It can be understood that the code packaging method provided by the present embodiment may be specifically executed as a packaging plug-in the application software development process.
As shown in fig. 1, a code packing method provided in an embodiment of the present invention includes the following operations:
s101, determining the current introduction state of the code module included in the entry file of the application software.
In this embodiment, the application software may specifically refer to software developed by a developer, the entry file may specifically refer to a compilable file required for translating a front-end code of the application software to generate a browser recognizable code, and this embodiment may introduce a front-end-oriented code module in the developed application software into the entry file. The current introduction state is specifically understood to be the current read state of the code module of the application software in the entry file, and may be a readable state capable of being read or a non-readable state incapable of being read. In this embodiment, it may be default that the import states of the code modules when the code modules are initially imported into the entry file are both non-readable states or both readable states, and the code packing method of this embodiment may adjust the current import states of the code modules as needed.
It should be noted that the current introduction state in this embodiment may include: a non-readable state and a readable state; it is understood that the code module in the entry file of the embodiment has only one current introduction state, which is either in a non-readable state or a readable state.
And S102, determining an object code module of the import state to be adjusted in the entry file according to the environment to be packaged selected by the user and each current import state.
In this embodiment, the user may specifically refer to a developer or a tester in application software development, the user may set a currently required environment to be packaged according to a packaging requirement in actual application, and the environment to be packaged specifically may include a test environment for application software testing and a production environment for application software release.
It can be understood that, when determining the to-be-packaged environment is equivalent to determining the to-be-packaged code module belonging to the to-be-packaged environment and needing to be packaged, the specific determination may preferably be: and acquiring the code names of all code modules belonging to the environment to be packaged from a preset attribution relation table of the packaging environment and the code modules. Therefore, the embodiment can determine the corresponding code module to be packaged from the entry file based on the acquired code name.
It should be noted that, for the code modules to be packaged that satisfy the environment to be packaged in the entry file, the subsequent packaging operation can be performed only when the current introduction state of the code modules to be packaged is a readable state. For all code modules included in the entry packing file, the current introduction state of the code modules may be a readable state or a non-readable state, and if the current introduction state not attributed to the environment to be packed is in the readable state or the current introduction state attributed to the packing environment is in the non-readable state, the compiling and packing of the entry file cannot be normally performed based on the entry file currently, so that in order to ensure the correctness of the packed file obtained by compiling and packing, the step may determine the target code module whose introduction state needs to be adjusted according to the current introduction state of each code module in the entry file and the environment to be packed selected by the user.
S103, adjusting the current lead-in state of each object code module to obtain an entry file to be compiled.
In this step, the determined current import state of the target code module may be specifically adjusted, so that, in the import file with the adjusted import state, only the current import state of the code module belonging to the environment to be packaged is a readable state, and the current import states of the other code modules are all non-readable states, and finally, the import file with the adjusted import state may be recorded as the import file to be compiled.
For example, the embodiment may change the code module from the readable state to the non-readable state by adding a special mark to the code module, or may change the code module from the non-readable state to the readable state by replacing the special mark in the code module with the setting text.
And S104, compiling the entry file to be compiled to obtain a packed file corresponding to the environment to be packed.
The step specifically realizes the compiling operation of the entry file to be compiled, and the compiled file can be recorded as a packaging file (such as a bundle file generated by compiling) meeting the environment to be packaged.
Compared with the prior method for packaging different entry files corresponding to different packaging environments, the method for packaging codes provided by the embodiment of the invention reduces the space resource occupation of repeatedly introducing the same codes into different entry files, reduces the risk of code introduction errors when the codes are introduced into different entry files, and simultaneously avoids the separation of the code modules because different parts of the code modules are suitable for different packaging environments, thereby reducing the maintenance cost required by code packaging.
Example two
Fig. 2 is a flowchart illustrating a code packaging method according to a second embodiment of the present invention, where the present embodiment is optimized based on the above embodiment, and in the present embodiment, the determining of the current import state of the code module included in the entry file of the application software is further embodied as: determining the current introduction state of a code module with an annotation mark in an entry file of the application software as a non-readable state; and determining the current introduced state of the code module without the annotation mark in the entry file as a readable state.
Meanwhile, in this embodiment, the object code module of the import state to be adjusted in the entry file is determined according to the environment to be packaged selected by the user and each of the current import states, and the method is further embodied as follows: traversing each code module in the entry file; if the code module belongs to the environment to be packaged and the current introduction state of the code module is a non-readable state, determining that the code module is a target code module of which the introduction state is to be adjusted; and if the code module does not belong to the environment to be packaged and the current introduction state of the code module is a readable state, determining that the code module is a target code module of which the introduction state is to be adjusted.
In addition, the present embodiment further specifies adjusting the current introduction state of each of the target code modules as: if the current introduction state of the target code module is a non-readable state, adjusting the current introduction state of the target code module based on a first adjustment strategy; and if the current introduction state of the target code module is a readable state, adjusting the current introduction state of the target code module based on a second adjusting strategy.
As shown in fig. 2, a code packing method provided in an embodiment of the present invention specifically includes the following operations:
s201, determining that the current introduction state of the code module with the annotation mark in the entry file of the application software is a non-readable state.
S202, determining that the current introduction state of the code module without the annotation mark in the entry file is a readable state.
In this embodiment, the foregoing S201 and S202 give specific implementations of determining the current introduction state of the code module in the entry file of the application software.
Specifically, the present embodiment may perform traversal on the code modules in the entry file to determine whether each code module carries a comment flag, determine the current introduction state of the code module carrying the comment flag as a non-readable state, and determine the current introduction state of the code module not carrying the comment flag as a readable state.
Further, the annotation is marked as: including a string of setting annotation identifiers and setting key identifiers, the present embodiment has the advantage of setting annotation tags as described above in order to distinguish them from conventional annotation tags contained in a portal file. The setting comment identifier can be an identifier used as a conventional comment mark, and the setting key identifier can be a setting character string.
Illustratively, to distinguish from conventional annotation TAGs, the present implementation may annotate code modules in the portal file in the form of identifier characters of the conventional annotation TAGs in combination with set strings, e.g., code modules may be annotated with '/' __ TAG _ START __ 'and' __ TAG _ END __/'and may be considered to be in a non-readable state between'/'__ TAG _ START __' and '__ TAG _ END __/', where '/' and '/' are set annotation identifiers in the annotation TAGs set by the present implementation, and strings '__ TAG _ START __' and '__ TAG _ END __' may be considered as set key identifiers.
It should be noted that the code module may be regarded as a function, and therefore, when traversing the entry file, different code modules may be distinguished by determining the start and end identifiers of a function. In addition, considering that there may be some common codes applicable to different packaging environments in one code module, and another part of codes is non-common codes applicable to a certain packaging environment, in order to ensure that the codes in one code module satisfy different packaging environments, this embodiment may divide one code module into a plurality of sub-code modules, and set the introduction state of each sub-code module respectively (may set the default introduction state of each sub-code module as a non-readable state with a comment flag), and this embodiment may use each sub-code module as an independent code module and perform the determination and adjustment operation of the corresponding current introduction state based on the code packaging method of this embodiment.
S203, determining the environment to be packaged selected by the user.
The step can be specifically used for acquiring the to-be-packaged environment selected by a software developer or a tester to be subjected to code packaging. After the current import state of each code module in the environment to be packaged and the entry file is obtained, the following S204 to S207 may be executed in a loop to determine the target code module of which the import state is to be adjusted.
S204, sequentially selecting a code module in the entry file as a current module to be packaged;
specifically, this step is equivalent to a loop start step, and is specifically used to select a code module to be determined, and mark the code module to be determined as a current module to be packaged. In the following S205 in this embodiment, it is necessary to determine the home relationship between the selected current code module and the environment to be packaged and the current introduction state of the selected current code module.
S205, judging whether the current code module belongs to the environment to be packaged and whether the current introduced state of the current code module is a non-readable state, if the current introduced state is the non-readable state, executing S206; if the attribution is readable, or if the non-attribution is not readable, S207 is executed.
Specifically, according to a preset attribution relationship table between a packaging environment and a code module, determining whether the code module belongs to the environment to be packaged by combining a code name of a currently selected code module, if the code module belongs to the environment to be packaged, in order to implement compilation of the code module in the environment to be packaged, an introduction state of the code module in an entry file needs to be set to a readable state, and if the current introduction state of the code module is a non-readable state, the introduction state of the current code module needs to be adjusted before the entry file is compiled, so that S206 may be executed to determine the current code module as a target code module of which the introduction state is to be adjusted when determining that the current code module belongs to and is not readable.
Similarly, if the current code module does not belong to the environment to be packaged, it is known that the package file formed by compiling and packaging the environment to be packaged cannot contain the relevant information of the current code module, and therefore, the import state of the current code module in the entry file needs to be set to a non-readable state, and if the current import state of the code module is a readable state, the import state of the code module needs to be completed before compiling the entry file, so that when the current code module is determined to belong to and be non-readable, S206 needs to be executed to determine the current code module as the target code module of which the import state is to be adjusted.
Furthermore, it is understood that for a current code module selected from the portal file, if the current code module satisfies the following condition: the environment to be packaged is not attributed to and the current introduction state is a non-readable state; or if the current import state is a readable state and belongs to the environment to be packaged, the import state does not need to be adjusted, and thus when the current code module meets the two determination conditions, S207 needs to be executed
S206, determining that the current code module is the target code module to be adjusted and introduced, and executing S208.
This step may be performed, for example, when it is determined that the current code module is homed and non-readable, or alternatively, non-homed and readable.
S207, the current code module is not needed to be used as the target code module of the lead-in state to be adjusted, and S208 is executed.
This step may be performed, for example, when the current code module is determined to be homed and readable, or alternatively, non-homed and non-readable.
S208, judging whether the current code module is the tail code module in the entry file, if so, executing S209; if not, the process returns to the step S204.
In this embodiment, after the determination of the above-mentioned S205 or S207 is performed on the selected current code module, it may be determined based on this step whether the selected current code module is an end code module in the entry file, if the selected current code module is the end code module, the operations of the above-mentioned S204 to S207 may be ended, and if the selected current code module is not the end code module, the operations of the above-mentioned S204 to S207 may be executed in a loop by returning to S204.
S209, adjusting the current lead-in state of each object code module to obtain an entry file to be compiled.
After the target code modules needing to be subjected to the introduction state adjustment in the entry file are determined, the introduction states of all the target code modules can be adjusted, so that the entry file to be compiled is obtained, wherein the entry file to be compiled comprises the target code modules after the introduction states are adjusted and other original code modules without the introduction states being adjusted.
Specifically, this step may implement the adjustment of the introduction state by adopting different operations according to the current introduction state of the target code module. Further, the present embodiment will adjust the current introduction state of each target code module, which is embodied as: for each object code module, if the current introduction state of the object code module is a non-readable state, adjusting the current introduction state of the object code module based on a first adjustment policy; if the current introduction state of the target code module is a readable state, adjusting the current introduction state of the target code module based on a second adjustment strategy; wherein the first adjustment strategy is different from the second adjustment strategy.
Specifically, the adjusting the current introduction state of the target code module based on the first adjustment policy includes: searching for an annotation mark of the target code module; and replacing the found annotation mark by the set character.
In this embodiment, when the current introduction state of the target code module is a non-readable state, the target code module may be considered to carry the annotation TAGs '/' __ TAG _ START __ ' and ' __ TAG _ END __/', and this step may find the annotation TAG carried by the target code module and replace the annotation TAG with a set character. Illustratively, the comment TAG '/' __ TAG _ START __ 'may be replaced with a space character, and the comment TAG' __ TAG _ END __ '/' may also be replaced with a space character, thereby changing the introduction state of the target code module to a readable state.
Specifically, the adjusting the current introduction state of the target code module based on the second adjustment policy includes: determining the start-stop position of the object code module in the entry file; annotation tags are added at the start and stop positions.
In this embodiment, when the current introduction state of the target code module is a readable state, the target code module may be considered to not carry a comment TAG, and to adjust the target code module to a non-readable state, comment TAGs need to be added at the beginning and the END of the target code module, and this step may find the beginning and the END of the target code module, and add the comment TAGs at the beginning and the END, respectively, for example, '/' __ TAG _ START __ ' may be added at the beginning of the target code module, and ' __ TAG _ END __/' may be added at the END of the target code module, so as to change the introduction state of the target code module to a non-readable state.
S210, compiling the entry file to be compiled to obtain a packed file corresponding to the environment to be packed.
The code packing method provided by the second embodiment of the invention embodies the determination operation of the current lead-in code of the code module in the entry file, embodies the determination operation of the target code module to be adjusted in the lead-in state in the entry file, and embodies the replacement adjustment operation of adjusting the current lead-in state of the target code module. By utilizing the method, the packed files suitable for different packing environments can be obtained by introducing all code modules of the introduced application software into the same entry file for compiling, and compared with the mode that the prior different packing environments are packed corresponding to different entry files, the method reduces the space resource occupation of repeatedly introducing the same codes into different entry files, reduces the risk of code introduction errors when the codes are introduced into different entry files, and simultaneously avoids the separation of the code modules due to the fact that different parts of the code modules are suitable for different packing environments, thereby reducing the maintenance cost required by code packing.
EXAMPLE III
Fig. 3 is a block diagram of a code packaging apparatus according to a third embodiment of the present invention. The device is suitable for compiling and packaging the front-end code module of the developed application software under different packaging environments, can be realized by software and/or hardware, and is generally integrated on a computer device supporting the development and programming of the application software, as shown in fig. 3, the device comprises: a state determination module 31, a target determination module 32, a state adjustment module 33, and a file compilation module 34.
The state determining module 31 is configured to determine a current introduction state of a code module included in an entry file of the application software;
a target determining module 32, configured to determine, according to the environment to be packaged selected by the user and each current import state, a target code module of the import state to be adjusted in the entry file;
a state adjusting module 33, configured to adjust a current introduction state of each object code module, to obtain an entry file to be compiled;
and the file compiling module 34 is configured to compile the entry file to be compiled to obtain a packed file corresponding to the environment to be packed.
In this embodiment, first, the current introduction state of the code module included in the entry file of the application software is determined by the state determination module 31; then, determining an object code module of the import state to be adjusted in the entry file through an object determination module 32 according to the environment to be packaged selected by the user and each current import state; then, the current introduction state of each object code module is adjusted through a state adjusting module 33 to obtain an entry file to be compiled; and finally, compiling the entry file to be compiled through the file compiling module 34 to obtain a packed file corresponding to the environment to be packed.
The code packing device provided by the third embodiment of the invention can obtain the packing files suitable for different packing environments by introducing all code modules of the introduced application software into the same entry file for compiling, and compared with the realization that the existing different packing environments correspond to different entry files for packing, the device reduces the space resource occupation of repeatedly introducing the same code into different entry files, reduces the risk of code introduction errors when the code is introduced into different entry files, and simultaneously avoids the separation of the code modules because different parts of the code modules are suitable for different packing environments, thereby reducing the maintenance cost required by code packing.
Further, the current introduction state includes: a non-readable state and a readable state;
correspondingly, the state determining module 31 is specifically configured to:
determining the current introduction state of a code module with an annotation mark in an entry file of the application software as a non-readable state; and determining the current introduced state of the code module without the annotation mark in the entry file as a readable state.
Further, the annotation is marked as: including strings of set annotation identifiers and set key identifiers.
Further, the target determination module 32 is specifically configured to:
determining an environment to be packaged selected by a user, and traversing each code module in the entry file; when the code module belongs to the environment to be packaged and the current introduction state of the code module is a non-readable state, determining that the code module is a target code module of which the introduction state is to be adjusted; and when the code module does not belong to the environment to be packaged and the current introduction state of the code module is a readable state, determining that the code module is a target code module of which the introduction state is to be adjusted.
Further, the state adjustment module 33 includes:
a first adjusting unit, configured to, for each target code module, adjust a current introduction state of the target code module based on a first adjusting policy when the current introduction state of the target code module is a non-readable state;
a second adjusting unit, configured to, for each target code module, adjust a current introduction state of the target code module based on a second adjusting policy when the current introduction state of the target code module is a readable state;
the file acquisition unit is used for acquiring the entry file to be compiled after the introduction state is adjusted;
wherein the first adjustment strategy is different from the second adjustment strategy.
Further, the first adjusting unit is specifically configured to:
and when the current introduced state of the target code module is a non-readable state, searching the annotation mark of the target code module, and replacing the searched annotation mark with set characters.
Further, the second adjusting unit is specifically configured to:
when the current introduction state of the object code module is a readable state, determining a start-stop position of the object code module in the entry file, and adding an annotation mark at the start-stop position.
Example four
Fig. 4 is a hardware structure diagram of a computer device according to a fourth embodiment of the present invention, specifically, the computer device includes: a processor and a storage device. At least one instruction is stored in the storage device, and the instruction is executed by the processor, so that the computer device executes the code packaging method according to the embodiment of the method.
Referring to fig. 4, the computer device may specifically include: a processor 40, a storage device 41, a display 42, an input device 43, an output device 44, and a communication device 45. The number of processors 40 in the computer device may be one or more, and one processor 40 is taken as an example in fig. 4. The number of the storage devices 41 in the computer apparatus may be one or more, and one storage device 41 is taken as an example in fig. 4. The processor 40, the storage means 41, the display 42, the input means 43, the output means 44 and the communication means 45 of the computer device may be connected by a bus or in another way, as exemplified by the bus connection in fig. 4.
The storage device 41 is a computer-readable storage medium, and can be used to store software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the embodiments of the present invention (for example, the status determination module 31, the target determination module 32, the status adjustment module 33, the file compiling module 34, and the like in the code packaging device provided in the above embodiments). The storage device 41 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating device, an application program required for at least one function; the storage data area may store data created according to use of the computer device, and the like. Further, the storage device 41 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some examples, storage 41 may further include memory located remotely from processor 40, which may be connected to a computer device over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
In general, the display screen 42 is used for displaying data according to instructions from the processor 40, and is also used for receiving touch operations applied to the display screen 42 and sending corresponding signals to the processor 40 or other devices. Optionally, when the display screen 42 is an infrared screen, the display screen further includes an infrared touch frame, and the infrared touch frame is disposed around the display screen 42, and may also be configured to receive an infrared signal and send the infrared signal to the processor 40 or other computer devices.
Communication means 45 for establishing a communication connection with other computer devices, which may be wired communication means and/or wireless communication means.
The input means 43 may be used for receiving input numeric or character information and generating key signal inputs related to user settings and function control of the computer apparatus, and may also be a camera for acquiring images and a sound pickup computer apparatus for acquiring audio in video data. The output device 44 may include a video computer device such as a display screen and an audio computer device such as a speaker. It should be noted that the specific composition of the input device 43 and the output device 44 can be set according to actual conditions.
The processor 40 executes various functional applications and data processing of the computer device, i.e., implements the above-described code packing method, by executing software programs, instructions, and modules stored in the storage device 41.
Specifically, in the embodiment, when the processor 40 executes one or more programs stored in the storage device 41, the following operations are specifically implemented: determining the current introduction state of a code module included in an entry file of the application software; determining an object code module of the import state to be adjusted in the entry file according to the environment to be packaged selected by the user and each current import state; adjusting the current lead-in state of each object code module to obtain an entry file to be compiled; and compiling the entry file to be compiled to obtain a packed file corresponding to the environment to be packed.
An embodiment of the present invention further provides a computer-readable storage medium, where when a program in the storage medium is executed by a processor of a computer device, the computer device is enabled to execute the code packing method according to the above embodiment. Illustratively, the code packing method according to the above embodiment includes: determining the current introduction state of a code module included in an entry file of the application software; determining an object code module of the import state to be adjusted in the entry file according to the environment to be packaged selected by the user and each current import state; adjusting the current lead-in state of each object code module to obtain an entry file to be compiled; and compiling the entry file to be compiled to obtain a packed file corresponding to the environment to be packed.
It should be noted that, as for the embodiments of the apparatus, the computer device, and the storage medium, since they are basically similar to the embodiments of the method, the description is relatively simple, and in the relevant places, reference may be made to the partial description of the embodiments of the method.
From the above description of the embodiments, it is obvious for those skilled in the art that the present invention can be implemented by software and necessary general hardware, and certainly, can also be implemented by hardware, but the former is a better embodiment in many cases. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which may be stored in a computer-readable storage medium, such as a floppy disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a FLASH Memory (FLASH), a hard disk or an optical disk of a computer, and includes several instructions for enabling a computer device (which may be a robot, a personal computer, a server, or a network device) to execute the code packaging method according to any embodiment of the present invention.
It should be noted that, in the code packaging apparatus, each unit and each module included in the code packaging apparatus are only divided according to functional logic, but are not limited to the above division as long as the corresponding function can be implemented; in addition, specific names of the functional units are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present invention.
It should be understood that portions of the present invention may be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, the various steps or methods may be implemented in software or firmware stored in memory and executed by suitable instruction execution devices. For example, if implemented in hardware, as in another embodiment, any one or combination of the following techniques, which are known in the art, may be used: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application specific integrated circuit having an appropriate combinational logic gate circuit, a Programmable Gate Array (PGA), a Field Programmable Gate Array (FPGA), or the like.
In the description herein, references to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the invention. In this specification, the schematic representations of the terms used above do not necessarily refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (14)

1. A method of packaging code, comprising:
determining the current introduction state of a code module included in an entry file of the application software;
the current introduction state includes: a non-readable state and a readable state;
the determining the current introduction state of the code module included in the entry file of the application software comprises the following steps:
determining the current introduction state of a code module with an annotation mark in an entry file of the application software as a non-readable state;
determining that the current introduced state of the code module without the annotation mark in the entry file is a readable state;
determining an object code module of the import state to be adjusted in the entry file according to the environment to be packaged selected by the user and each current import state;
adjusting the current lead-in state of each object code module to obtain an entry file to be compiled;
and compiling the entry file to be compiled to obtain a packed file corresponding to the environment to be packed.
2. The method of claim 1, wherein the annotation tag is: including strings of set annotation identifiers and set key identifiers.
3. The method of claim 1, wherein the determining the object code modules of the import file with the import status to be adjusted according to the environment to be packaged selected by the user and each of the current import statuses comprises:
determining an environment to be packaged selected by a user, and traversing each code module in the entry file;
if the code module belongs to the environment to be packaged and the current introduction state of the code module is a non-readable state, determining that the code module is a target code module of which the introduction state is to be adjusted;
and if the code module does not belong to the environment to be packaged and the current introduction state of the code module is a readable state, determining that the code module is a target code module of which the introduction state is to be adjusted.
4. The method of claim 3, wherein said adjusting a current introduction state of each of said object code modules comprises:
for each object code module, if the current introduction state of the object code module is a non-readable state, adjusting the current introduction state of the object code module based on a first adjustment policy;
if the current introduction state of the target code module is a readable state, adjusting the current introduction state of the target code module based on a second adjustment strategy;
wherein the first adjustment strategy is different from the second adjustment strategy.
5. The method of claim 4, wherein adjusting the current incoming state of the target code module based on the first adjustment policy comprises:
searching for an annotation mark of the target code module;
and replacing the found annotation mark by the set character.
6. The method of claim 4, wherein adjusting the current incoming state of the target code module based on a second adjustment policy comprises:
determining the start-stop position of the object code module in the entry file;
annotation tags are added at the start and stop positions.
7. A code packaging apparatus, comprising:
the state determining module is used for determining the current introduction state of the code module included in the entry file of the application software;
the current introduction state includes: a non-readable state and a readable state;
correspondingly, the state determination module is specifically configured to:
determining the current introduction state of a code module with an annotation mark in an entry file of the application software as a non-readable state;
determining that the current introduced state of the code module without the annotation mark in the entry file is a readable state;
the target determining module is used for determining a target code module of the import state to be adjusted in the entry file according to the environment to be packaged selected by the user and each current import state;
the state adjusting module is used for adjusting the current introduction state of each target code module to obtain an entry file to be compiled;
and the file compiling module is used for compiling the entry file to be compiled to obtain a packed file corresponding to the environment to be packed.
8. The apparatus of claim 7, wherein the annotation is marked as: including strings of set annotation identifiers and set key identifiers.
9. The apparatus of claim 7, wherein the goal determination module is specifically configured to:
determining an environment to be packaged selected by a user, and traversing each code module in the entry file;
when the code module belongs to the environment to be packaged and the current introduction state of the code module is a non-readable state, determining that the code module is a target code module of which the introduction state is to be adjusted;
and when the code module does not belong to the environment to be packaged and the current introduction state of the code module is a readable state, determining that the code module is a target code module of which the introduction state is to be adjusted.
10. The apparatus of claim 9, wherein the state adjustment module comprises:
a first adjusting unit, configured to, for each target code module, adjust a current introduction state of the target code module based on a first adjusting policy when the current introduction state of the target code module is a non-readable state;
a second adjusting unit, configured to, for each target code module, adjust a current introduction state of the target code module based on a second adjusting policy when the current introduction state of the target code module is a readable state;
the file acquisition unit is used for acquiring the entry file to be compiled after the introduction state is adjusted;
wherein the first adjustment strategy is different from the second adjustment strategy.
11. The apparatus according to claim 10, wherein the first adjusting unit is specifically configured to:
and when the current introduced state of the target code module is a non-readable state, searching the annotation mark of the target code module, and replacing the searched annotation mark with set characters.
12. The apparatus according to claim 10, wherein the second adjusting unit is specifically configured to:
when the current introduction state of the object code module is a readable state, determining a start-stop position of the object code module in the entry file, and adding an annotation mark at the start-stop position.
13. A computer device, comprising:
one or more processors;
storage means for storing one or more programs;
the one or more programs being executable by the one or more processors to cause the one or more processors to implement the code packaging method of any of claims 1-6.
14. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the code packing method of any one of claims 1 to 6.
CN201910044789.3A 2019-01-17 2019-01-17 Code packaging method and device, computer equipment and storage medium Active CN109783133B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910044789.3A CN109783133B (en) 2019-01-17 2019-01-17 Code packaging method and device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910044789.3A CN109783133B (en) 2019-01-17 2019-01-17 Code packaging method and device, computer equipment and storage medium

Publications (2)

Publication Number Publication Date
CN109783133A CN109783133A (en) 2019-05-21
CN109783133B true CN109783133B (en) 2022-03-22

Family

ID=66500904

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910044789.3A Active CN109783133B (en) 2019-01-17 2019-01-17 Code packaging method and device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN109783133B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110659253A (en) * 2019-09-03 2020-01-07 北京达佳互联信息技术有限公司 File packaging method and device, electronic equipment and medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107066291A (en) * 2017-02-09 2017-08-18 阿里巴巴集团控股有限公司 Packaging method, device and the equipment of SDK, computer-readable recording medium
CN108304175A (en) * 2018-01-29 2018-07-20 口碑(上海)信息技术有限公司 Packaging method and device is isolated in code file

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7281237B2 (en) * 2003-01-16 2007-10-09 Sun Microsystems, Inc. Run-time verification of annotated software code

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107066291A (en) * 2017-02-09 2017-08-18 阿里巴巴集团控股有限公司 Packaging method, device and the equipment of SDK, computer-readable recording medium
CN108304175A (en) * 2018-01-29 2018-07-20 口碑(上海)信息技术有限公司 Packaging method and device is isolated in code file

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
"webpack解惑:多入口文件打包策略 ";吕大豹;《博客园:https://www.cnblogs.com/lvdabao/p/5944420.html》;20161010;第1-10页 *

Also Published As

Publication number Publication date
CN109783133A (en) 2019-05-21

Similar Documents

Publication Publication Date Title
CN111142988B (en) Page test method and device, storage medium and electronic equipment
US8949799B2 (en) Program log record optimization
CN105335137A (en) Method and device used for processing source file
CN104461898A (en) Application testing method, center control server, test terminal and system
JP2008176793A (en) Software test system, method, and computer-readable recording medium having program stored for executing this method
CN108763094B (en) Test case generation method, device, equipment and storage medium
CN111124479B (en) Method and system for analyzing configuration file and electronic equipment
US20190034195A1 (en) Systems and methods for providing patchable rom firmware
CN107330028A (en) Expansion application methods and system of a kind of Apache NiFi in terms of source data input database
CN110968314B (en) Page generation method and device
CN105160018A (en) Method, device and system for image copy/paste
CN106776266B (en) Configuration method of test tool and terminal equipment
CN109783133B (en) Code packaging method and device, computer equipment and storage medium
US10659321B2 (en) Electronic apparatus for recording debugging information and control method thereof
CN111443920B (en) Frame migration method and device
JP7318704B2 (en) Test equipment, test method and program
CN106484375B (en) Instruction block loading method, soft switch equipment and system
CN111414168A (en) Web application development method and device based on mind map and electronic equipment
CN109815455A (en) Item file treating method and apparatus
CN113760291A (en) Log output method and device
CN114816364A (en) Method, device and application for dynamically generating template file based on Swagger
CN111061627B (en) Webpage embedding method and device, electronic equipment and storage medium
CN113656006A (en) Rich text rendering method and rendering equipment
CN103678134A (en) Method and device for obtaining browser script information with faults to be analyzed browser
CN110716746B (en) Method and device for converting RN style code into applet style code

Legal Events

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