Front-end project packaging method and device, computer equipment and readable storage medium
By calling packaging script files and generating packaging commands in the financial technology industry, multiple front-end projects under the monorepo framework are packaged simultaneously, solving the problem of inefficiency caused by configuration differences and achieving efficient front-end project deployment.
Patent Information
- Application Number
- CN202411248993.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-05
- Publication Date
- 2024-12-13
AI Technical Summary
In the financial technology industry, the configuration differences in front-end projects lead to low packaging efficiency, and a single front-end project needs to be packaged in a single time, resulting in inefficiency.
By calling the preset packaging script file, the projects under the monorepo framework are extracted, and packaging commands are generated based on the project name and packaging environment variables, and the packaging commands are executed to achieve the simultaneous packaging of multiple front-end projects, avoiding single-time packaging of a single project .
It improves the efficiency of front-end project packaging, simplifies the deployment process, reduces the file size and generation time of deployment packages, and improves development efficiency.
Smart Images

Figure CN119127289A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of development assistance technology, and in particular to a front-end project packaging method, device, computer equipment and readable storage medium. Background Art
[0002] In the financial technology industry (such as insurance and banking), when deploying a front-end project to a server, the front-end project needs to be packaged and then the packaged deployment package is deployed to the server. At present, in the relevant technology, when packaging a front-end project, due to the differences in configurations of different front-end projects, a single front-end project needs to be packaged once, resulting in low efficiency in packaging the front-end project.
[0003] Therefore, how to improve the efficiency of packaging front-end projects has become an urgent problem to be solved. Summary of the invention
[0004] The present application provides a front-end project packaging method, apparatus, computer equipment and readable storage medium, which can effectively improve the efficiency of packaging front-end projects.
[0005] In a first aspect, the present application provides a front-end project packaging method, the method comprising:
[0006] According to the project packaging command input by the user, the preset packaging script file is called to extract files from each project under the monorepo framework to obtain one or more different projects to be packaged;
[0007] Generate a packaging command according to the project name and packaging environment variables corresponding to each of the to-be-packaged projects;
[0008] The packaging command is executed to package each of the items to be packaged, and a deployment package corresponding to each of the items to be packaged is obtained.
[0009] In one embodiment, before calling the preset packaging script file, it also includes: installing the execa dependency package in the monorepo framework and creating the packaging script file; adding the running command corresponding to the packaging script file to the first configuration file that the monorepo framework depends on.
[0010] In one embodiment, calling a preset packaging script file includes: executing a run command in the first configuration file based on the execa dependency package, wherein the run command is used to call the packaging script file.
[0011] In one embodiment, the file extraction of each project under the monorepo framework to obtain one or more different projects to be packaged includes: performing file traversal based on the subdirectory corresponding to each of the projects to obtain directory files and non-directory files corresponding to each of the projects; performing file filtering on the non-directory files corresponding to each of the projects to obtain candidate projects, wherein the non-directory files include configuration files in the project; and determining the project to be packaged according to the directory files corresponding to the candidate projects.
[0012] In one embodiment, determining the project to be packaged based on the directory file corresponding to the candidate project includes: obtaining a second configuration file in the candidate project; if the second configuration file includes an identification field corresponding to a common component, filtering the candidate project files based on the identification field to obtain the project to be packaged.
[0013] In one embodiment, the file extraction of each project under the monorepo framework to obtain one or more different projects to be packaged includes: obtaining a first configuration file that the monorepo framework depends on, the first configuration file includes an array, and the array includes the project names of the projects to be packaged; extracting projects according to the project names in the array to obtain the projects to be packaged.
[0014] In one embodiment, before generating a packaging command according to the project name and packaging environment variables corresponding to each of the projects to be packaged, it also includes: calling the command line parameter tool library in the monorepo framework to extract parameters of the project packaging command to obtain the packaging environment variables.
[0015] In one embodiment, packaging each of the projects to be packaged to obtain a deployment package corresponding to each of the projects to be packaged includes: deleting historically packaged deployment packages; setting a maximum number of files for each packaging; and packaging each of the projects to be packaged based on the maximum number of files to obtain a deployment package corresponding to each of the projects to be packaged.
[0016] In a second aspect, the present application further provides a front-end project packaging device, the front-end project packaging device comprising:
[0017] The file extraction module is used to call the preset packaging script file according to the project packaging command input by the user, extract files from each project under the monorepo framework, and obtain one or more different projects to be packaged;
[0018] A packaging command generation module, used to generate a packaging command according to the project name and packaging environment variables corresponding to each of the to-be-packaged projects;
[0019] The project packaging module is used to execute the packaging command, package each of the projects to be packaged, and obtain a deployment package corresponding to each of the projects to be packaged.
[0020] In a third aspect, the present application further provides a computer device, the computer device comprising a memory and a processor;
[0021] The memory is used to store computer programs;
[0022] The processor is used to execute the computer program and implement the front-end project packaging method as described above when executing the computer program.
[0023] In a fourth aspect, the present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the processor implements the front-end project packaging method as described above.
[0024] The present application discloses a front-end project packaging method, device, computer equipment and readable storage medium, the method comprising: according to the project packaging command input by the user, calling a preset packaging script file, extracting files from each project under the monorepo framework, and obtaining one or more different projects to be packaged; generating a packaging command according to the project name and packaging environment variables corresponding to each of the projects to be packaged; executing the packaging command, packaging each of the projects to be packaged, and obtaining a deployment package corresponding to each of the projects to be packaged. The embodiment of the present application, according to the user's project packaging command, calls the packaging script file to extract files from each project under the monorepo framework, obtains one or more different projects to be packaged, generates a packaging command according to the project name and packaging environment variables corresponding to each project to be packaged, executes the packaging command, and packages each of the projects to be packaged, so as to realize the packaging of multiple different front-end projects according to one project packaging command, avoid single packaging of a single front-end project, and effectively improve the efficiency of packaging front-end projects. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0026] Figure 1 is a structural schematic diagram of a computer device provided in an embodiment of the present application;
[0027] Figure 2It is a schematic flow chart of a front-end project packaging method provided in an embodiment of the present application;
[0028] Figure 3 is a schematic flow chart of sub-steps of file extraction provided in an embodiment of the present application;
[0029] Figure 4 is a schematic flow chart of another sub-step of file extraction provided in an embodiment of the present application;
[0030] Figure 5 It is a schematic block diagram of a front-end project packaging device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0031] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0032] The flowcharts shown in the accompanying drawings are only examples and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may also be decomposed, combined or partially merged, so the actual execution order may change according to actual conditions.
[0033] It should be understood that the terms used in this application specification are only for the purpose of describing specific embodiments and are not intended to limit the application. As used in this application specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0034] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0035] Currently, in the related art, when packaging a front-end project, due to differences in configurations of different front-end projects, a single front-end project needs to be packaged once, resulting in low efficiency in packaging the front-end project.
[0036] To this end, the embodiments of the present application provide a front-end project packaging method, device, computer equipment and readable storage medium. Among them, the front-end project packaging method can be applied to a computer device, by calling a packaging script file to extract files from each project under the monorepo framework according to the user's project packaging command, obtaining one or more different projects to be packaged, generating a packaging command according to the project name and packaging environment variables corresponding to each project to be packaged, executing the packaging command, and packaging each project to be packaged, which can realize the packaging of multiple different front-end projects according to one project packaging command, avoiding a single packaging of a single front-end project, and effectively improving the efficiency of packaging front-end projects.
[0037] Exemplarily, the computer device can be a server or a terminal. The server can be an independent server or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms. The terminal can be an electronic device such as a smartphone, tablet computer, laptop computer, and desktop computer.
[0038] Exemplarily, a front-end project refers to a project in a front-end page, and the front-end project may be an insurance system project, a banking system project, a trading system project, a claims system project, and the like.
[0039] It should be noted that in the Monorepo (monopoly code repository management) architecture, all project codes are stored in the same code repository instead of being scattered in multiple repositories. One of the advantages of this architecture is that it is easy to share code and dependencies, because all projects are in the same repository and can share the same dependencies and toolchain.
[0040] See also Figure 1 , Figure 1 1 is a schematic diagram of a computer device provided in an embodiment of the present application. The computer device may include a processor and a memory, wherein the processor and the memory may be connected via a bus, and the bus may be any applicable bus such as an Inter-integrated Circuit (I2C) bus.
[0041] The memory may include a storage medium and an internal memory. The storage medium may be a non-volatile storage medium or a volatile storage medium. The storage medium may store an operating system and a computer program, and the internal memory provides an environment for the operation of the computer program in the storage medium. The computer program includes program instructions, and when the program instructions are executed, the processor may execute the front-end project packaging method described in any embodiment.
[0042] The processor is used to provide computing and control capabilities and support the operation of the entire computer equipment.
[0043] The processor may be a central processing unit (CPU), a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor, or any conventional processor.
[0044] In one embodiment, the processor is used to run a computer program stored in the memory to implement the following steps:
[0045] According to the project packaging command input by the user, the preset packaging script file is called to extract files from each project under the monorepo framework to obtain one or more different projects to be packaged; a packaging command is generated according to the project name and packaging environment variables corresponding to each project to be packaged; the packaging command is executed to package each project to be packaged and obtain the deployment package corresponding to each project to be packaged.
[0046] In one embodiment, before implementing the calling of the preset packaging script file, the processor is further used to implement:
[0047] Install the execa dependency package in the monorepo framework and create a packaging script file; in the first configuration file that the monorepo framework depends on, add the run command corresponding to the packaging script file.
[0048] In one embodiment, when the processor implements calling a preset packaging script file, it is used to implement:
[0049] The run command in the first configuration file is executed based on the execa dependency package, and the run command is used to call the packaged script file.
[0050] In one embodiment, when the processor extracts files from each project under the monorepo framework to obtain one or more different projects to be packaged, it is used to implement:
[0051] Perform file traversal based on the subdirectory corresponding to each project to obtain the directory files and non-directory files corresponding to each project; perform file filtering on the non-directory files corresponding to each project to obtain candidate projects, and the non-directory files include configuration files in the project; determine the project to be packaged based on the directory files corresponding to the candidate projects.
[0052] In one embodiment, when the processor determines the project to be packaged according to the directory file corresponding to the candidate project, it is used to implement:
[0053] The second configuration file in the candidate project is obtained; if the second configuration file includes an identification field corresponding to the common component, the candidate project is filtered according to the identification field to obtain the project to be packaged.
[0054] In one embodiment, when the processor extracts files from each project under the monorepo framework to obtain one or more different projects to be packaged, it is used to implement:
[0055] Get the first configuration file that the monorepo framework depends on, the first configuration file includes an array, and the array includes the project name of the project to be packaged;
[0056] Extract items according to the item names in the array to obtain the items to be packaged.
[0057] In one embodiment, before generating a packaging command according to the project name corresponding to each to-be-packaged project and the packaging environment variable, the processor is further configured to implement:
[0058] Call the command line parameter tool library in the monorepo framework to extract parameters of the project packaging command and obtain the packaging environment variables.
[0059] In one embodiment, when the processor packages each to-be-packaged project and obtains a deployment package corresponding to each to-be-packaged project, it is used to implement:
[0060] Delete the historically packaged deployment packages; set the maximum number of files for each package; based on the maximum number of files, package each project to be packaged to obtain the deployment package corresponding to each project to be packaged.
[0061] Some embodiments of the present application are described in detail below in conjunction with the accompanying drawings. In the absence of conflict, the following embodiments and features of the embodiments can be combined with each other. Figure 2 , Figure 2 is a schematic flow chart of a front-end project packaging method provided in an embodiment of the present application. Figure 2 As shown, the front-end project packaging method may include steps S101 to S103.
[0062] Step S101: According to the project packaging command input by the user, call the preset packaging script file, extract files from each project under the monorepo framework, and obtain one or more different projects to be packaged.
[0063] It should be noted that the front-end project packaging method provided in the embodiment of the present application can be applied to the scenario of packaging one or more different front-end projects with one click and deploying them to the server. It is understandable that for multiple projects to be packaged, only one project packaging command is needed to package the projects to be packaged, and obtain the deployment package corresponding to each project to be packaged, without the need for the user to trigger the project packaging command for each project to be packaged, thereby greatly improving the efficiency of packaging the front-end project, thereby improving the development efficiency. In addition, multiple projects to be packaged will not be packaged into one deployment package.
[0064] Exemplarily, according to the project packaging command input by the user, the preset packaging script file can be called to extract files from each project under the monorepo framework to obtain one or more different projects to be packaged. It should be noted that when the project packaging command input by the user in the front-end page is detected, the packaging script file can be called to extract files from each project under the monorepo framework to obtain one or more different projects to be packaged.
[0065] The packaging script file is a pre-created file used to extract the items to be packaged. For example, the packaging script file may be a build.js file.
[0066] It should be noted that there are multiple different projects under the monorepo framework, and the files in each project can be found through the subdirectories of the monorepo framework.
[0067] In some embodiments, before calling the preset packaging script file, it can also include: installing the execa dependency package in the monorepo framework and creating a packaging script file; adding the running command corresponding to the packaging script file to the first configuration file that the monorepo framework depends on.
[0068] It should be noted that the execa dependency package is a program package that can provide the dependency environment required for the packaged script file to run. The execa dependency package is similar to the built-in module child_process of Node.js, allowing scripts to be run in child processes. At the same time, the execa dependency package can synchronize callback functions and support more systems.
[0069] Exemplarily, the first configuration file that the monorepo framework depends on can be a package.json file. It should be noted that the package.json file is a configuration file automatically generated in the root directory of the monorepo framework, which is used to define the configuration information of the project and the various modules required. In an embodiment of the present application, a run command corresponding to the packaging script file can be added to the first configuration file, so that the packaging script file can be called by executing the run command in the first configuration file.
[0070] In the above embodiment, by installing the execa dependency package in the monorepo framework, it is possible to provide the dependency environment required for the packaged script file to run. By adding the running command corresponding to the packaged script file to the first configuration file that the monorepo framework depends on, the packaged script file can be called later by executing the running command in the first configuration file.
[0071] In some embodiments, calling a preset packaging script file may include: executing a run command in a first configuration file based on an execa dependency package, where the run command is used to call the packaging script file.
[0072] Exemplarily, when the packaged script file is called, the run command in the first configuration file may be executed based on the execa dependency package.
[0073] In the above embodiment, by executing the running command in the first configuration file based on the execa dependency package, it is possible to call the packaging script file in the dependency environment required for the packaging script file to run, thereby ensuring the normal running of the packaging script file.
[0074] See also Figure 3 , Figure 3 is a schematic flow chart of the sub-steps of file extraction provided in an embodiment of the present application. Figure 3 As shown, in step S101, files of each project under the monorepo framework are extracted to obtain one or more different projects to be packaged, which may include steps S201 to S203.
[0075] Step S201: perform file traversal based on the subdirectories corresponding to each project to obtain directory files and non-directory files corresponding to each project.
[0076] Exemplarily, the packaging script file build.js may be called to perform file traversal based on the subdirectories corresponding to each project to obtain directory files and non-directory files corresponding to each project.
[0077] It should be noted that in the embodiment of the present application, the file system (fs) module in the packaged script file build.js can be used to traverse the subdirectories corresponding to the project. Among them, the fs module is a built-in module in node, which is used for operations such as adding, deleting, modifying, and searching local files or directories.
[0078] For example, directory files refer to files that need to be packaged in the project, and non-directory files refer to files that do not need to be packaged, such as configuration files such as gitignore and .eslintignore.
[0079] Step S202: Filter the non-directory files corresponding to each project to obtain candidate projects. The non-directory files include configuration files in the project.
[0080] In some embodiments, after performing file traversal based on the subdirectory corresponding to each project and obtaining the directory files and non-directory files corresponding to each project, the non-directory files corresponding to the project can be filtered to obtain candidate projects. The non-directory files include configuration files in the project.
[0081] Exemplarily, the isDiretory function in the fs module may be used to filter the non-directory files corresponding to each project, and the projects after the file filtering are determined as candidate projects. In this case, the candidate projects include the directory files in the project.
[0082] By filtering the non-directory files corresponding to each project to obtain candidate projects, it is possible to filter the non-directory files in the project and avoid packaging directory files, which can not only improve the packaging efficiency but also reduce the file size of the deployment package obtained by packaging.
[0083] Step S203: Determine the project to be packaged according to the directory file corresponding to the candidate project.
[0084] Exemplarily, after filtering the non-directory files corresponding to each project to obtain candidate projects, the projects to be packaged can be determined based on the directory files corresponding to the candidate projects.
[0085] In some embodiments, the project to be packaged may be generated according to the directory file corresponding to the candidate project, that is, the project to be packaged includes the directory file.
[0086] In an embodiment of the present application, folders that do not need to be packaged in the project, such as public components, can also be filtered out. It should be noted that public components are similar to directory files in a project, but public components do not need to be packaged. In an embodiment of the present application, public components that do not need to be packaged can be secondary filtered by configuring the configuration files in the project.
[0087] In some embodiments, determining the project to be packaged based on the directory file corresponding to the candidate project may include: obtaining a second configuration file in the candidate project; if the second configuration file includes an identification field corresponding to the common component, filtering the candidate project files based on the identification field to obtain the project to be packaged.
[0088] It should be noted that the second configuration file is different from the first configuration file. The second configuration file is set in each project, while the first configuration file is set in the root directory under the monorepo framework. Corresponding identification fields can be set for common components and stored in the second configuration file. Among them, the content of the identification field can be set according to actual conditions, and this application does not limit this.
[0089] Exemplarily, the second configuration file in the candidate project may be read, and when the second configuration file includes an identification field corresponding to the common component, the candidate project is filtered according to the identification field to obtain the project to be packaged.
[0090] In the above embodiment, by obtaining the second configuration file in the candidate project and filtering the files of the candidate project according to the identification field when the second configuration file includes the identification field corresponding to the common component, it is possible to filter the common components in the candidate project and avoid packaging files that are not related to the project. This can not only improve the efficiency of project packaging, but also reduce the file size of the deployment package obtained by packaging.
[0091] See also Figure 4 , Figure 4 FIG. 1 is a schematic flow chart of another sub-step of file extraction provided in an embodiment of the present application. Figure 4 As shown, in step S101, files of each project under the monorepo framework are extracted to obtain one or more different projects to be packaged, which may include the following steps S301 and S302.
[0092] Step S301, obtain the first configuration file that the monorepo framework depends on, the first configuration file includes an array, and the array includes the project name of the project to be packaged.
[0093] It should be noted that when it comes to packaging the unchanged project, if the second configuration file in the project needs to be configured every time, it will cause cumbersome operations and waste time. In the embodiment of the present application, the packaging script file build.js also supports filtering the projects to be packaged through an array, and the project names of the projects to be packaged can be added to the array in the first configuration file, without adding the project names of the unchanged projects to the array in the first configuration file, which can avoid the need to configure the second configuration file in the project every time, simplify the operation process, and thus improve the efficiency of packaging projects.
[0094] Exemplarily, the array in the first configuration file package.json that the monorepo framework depends on can be read to obtain the project names of the projects in the array.
[0095] Step S302: extract items according to the item names in the array to obtain items to be packaged.
[0096] Exemplarily, each project in the monorepo framework can be extracted according to the project name in the array, and the project corresponding to the project name in the array is determined as the project to be packaged.
[0097] In the above embodiment, by obtaining the first configuration file that the monorepo framework depends on and extracting the project according to the project name in the array in the first configuration file, not only can the repeated packaging of unchanged projects be avoided, but also the need to configure the second configuration file in the project each time can be avoided, thereby improving the efficiency of packaging the project.
[0098] Step S102: Generate a packaging command according to the project name and packaging environment variables corresponding to each to-be-packaged project.
[0099] Exemplarily, the packaging environment variables may include a test environment and a production environment, wherein the test environment may be represented as stg and the production environment may be represented as prod.
[0100] In some embodiments, before generating a packaging command according to the project name and packaging environment variables corresponding to each project to be packaged, it also includes: calling the command line parameter tool library in the monorepo framework to extract parameters of the project packaging command to obtain the packaging environment variables.
[0101] The command line parameter tool library may be a minimist tool library, which is a tool library used by the Node.js environment to collect command line parameters.
[0102] Exemplarily, the command line parameter tool library in the monorepo framework can be called through the execa dependency package to extract parameters of the project packaging command and obtain the packaging environment variables. For example, when the project packaging command is node build.js-estg, the parameter "stg" can be extracted as the packaging environment variable, and the packaging environment variable is the test environment. For another example, when the project packaging command is node build.js-prod, the parameter "prod" can be extracted as the packaging environment variable, and the packaging environment variable is the production environment.
[0103] It should be noted that since the types of deployment packages generated by packaging projects using different packaging environment variables are different, the packaging environment variables need to be determined before packaging the project. The packaging environment variables can be determined according to the operating environment of the server.
[0104] In some embodiments, a packaging command can be generated according to the project name and packaging environment variables corresponding to each to-be-packaged project. Exemplarily, a packaging command can be generated according to the project name and packaging environment variables corresponding to each to-be-packaged project through the execa dependency package.
[0105] In the above embodiment, by generating a packaging command according to the project name and packaging environment variables corresponding to each project to be packaged, multiple projects to be packaged can be packaged based on the same packaging environment variables, so that the packaged deployment package can be normally deployed and run in the server.
[0106] Step S103: execute the packaging command to package each project to be packaged, and obtain a deployment package corresponding to each project to be packaged.
[0107] In some embodiments, after generating a packaging command according to the project name and packaging environment variables corresponding to each project to be packaged, the packaging command can be executed through the execa dependency package to package each project to be packaged, obtain the deployment package corresponding to each project to be packaged, and deploy the deployment package to the server.
[0108] By executing the packaging command to package each project to be packaged, it is possible to package multiple different front-end projects according to one project packaging command, avoiding single packaging of a single front-end project, and effectively improving the efficiency of packaging front-end projects.
[0109] In an embodiment of the present application, in order to prevent confusion in the files in the packaged project, the packaging command can be placed in a promise function for synchronous execution, and the packaged deployment package is returned through promise.race(), thereby avoiding the deployment package from being stuck in the packaging process.
[0110] In some embodiments, each project to be packaged is packaged to obtain a deployment package corresponding to each project to be packaged, including: deleting historically packaged deployment packages; setting a maximum number of files for each package; and based on the maximum number of files, packaging each project to be packaged to obtain a deployment package corresponding to each project to be packaged.
[0111] It should be noted that the historically packaged deployment package may be the deployment package left over from the last packaging. By deleting the historically packaged deployment package, it is possible to avoid generating too many useless files.
[0112] Exemplarily, the maximum number of files to be packaged each time can be set according to actual conditions, and the specific value is not limited here.
[0113] Exemplarily, each to-be-packaged project can be packaged based on the maximum number of files through the execa dependency package, a deployment package corresponding to each to-be-packaged project can be obtained, and the deployment package can be deployed to the server.
[0114] By packaging each project to be packaged based on the maximum number of files, you can avoid the error-prone problem of packaging too many files at one time.
[0115] It should be noted that when deploying front-end projects, the relevant technology requires the use of CI (Continuous Integration) / CD (Continuous Deployment) style pipeline deployment, and the number of front-end projects at the front end corresponds to the number of pipelines required, which makes the deployment process of the front-end project cumbersome and complicated, reducing the efficiency of deploying the front-end project. In the embodiment of the present application, since it is not necessary to execute the project packaging command once for each front-end project, when deploying the deployment package to the server, a CI / CD style pipeline can be used, and the deployment can be completed by placing the corresponding deployment package in the corresponding directory of the server through a shell script, so that multiple front-end projects can be deployed on one pipeline, and pipeline configurations such as environment deployment, quality inspection, security scanning, and interface testing can be fully shared, which greatly saves deployment time, thereby improving the efficiency of deploying front-end projects.
[0116] It should be noted that the CI / CD pipeline refers to connecting and coding each step of the entire ecological chain from development to deployment through the pipeline, so that the development process can become more efficient and faster through the form of an automated pipeline.
[0117] The front-end project packaging method provided by the above embodiment can implement calling the packaging script file in the dependent environment required for the running of the packaging script file by executing the running command in the first configuration file based on the execa dependency package, thereby ensuring the normal operation of the packaging script file; by filtering the non-directory files corresponding to each project to obtain the candidate project, the non-directory files in the project can be filtered to avoid packaging the directory files, which can not only improve the packaging efficiency but also reduce the file size of the deployment package obtained by packaging; by obtaining the second configuration file in the candidate project and filtering the candidate project according to the identification field when the second configuration file includes the identification field corresponding to the common component, the common components in the candidate project can be filtered to avoid packaging the files unrelated to the project, which can not only improve the efficiency of project packaging but also reduce the file size of the deployment package obtained by packaging; by obtaining the first configuration file dependent on the monorepo framework and extracting the project according to the project name in the array in the first configuration file, not only the repeated packaging of the unchanged project can be avoided, but also the need to configure the second configuration file in the project each time can be avoided, thereby improving the efficiency of packaging the project; by packaging each project to be packaged based on the maximum number of files, the problem of easy errors in packaging too many files at one time can be avoided.
[0118] See also Figure 5 , Figure 5 The embodiment of the present application further provides a schematic block diagram of a front-end project packaging device 1000, which is used to execute the aforementioned front-end project packaging method. The front-end project packaging device 1000 can be configured in a computer device.
[0119] like Figure 5 As shown, the front-end project packaging device 1000 includes: a file extraction module 1001, a packaging command generation module 1002 and a project packaging module 1003.
[0120] The file extraction module 1001 is used to call the preset packaging script file according to the project packaging command input by the user, extract files from each project under the monorepo framework, and obtain one or more different projects to be packaged.
[0121] The packaging command generation module 1002 is used to generate a packaging command according to the project name and packaging environment variables corresponding to each to-be-packaged project.
[0122] The project packaging module 1003 is used to execute the packaging command, package each project to be packaged, and obtain a deployment package corresponding to each project to be packaged.
[0123] It should be noted that those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described device and each module can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0124] A computer-readable storage medium is also provided in an embodiment of the present application. The computer-readable storage medium stores a computer program. The computer program includes program instructions. The processor executes the program instructions to implement any front-end project packaging method provided in the embodiment of the present application.
[0125] For example, the program is loaded by the processor and may execute the following steps:
[0126] According to the project packaging command input by the user, the preset packaging script file is called to extract files from each project under the monorepo framework to obtain one or more different projects to be packaged; a packaging command is generated according to the project name and packaging environment variables corresponding to each project to be packaged; the packaging command is executed to package each project to be packaged and obtain the deployment package corresponding to each project to be packaged.
[0127] The computer-readable storage medium may be an internal storage unit of the computer device of the aforementioned embodiment, such as a hard disk or memory of the computer device. The computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital card (Secure Digital Card, SD Card), a flash card (Flash Card), etc. equipped on the computer device.
[0128] Furthermore, the computer-readable storage medium may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function, etc.; the data storage area may store data created according to the use of the blockchain node, etc.
[0129] The blockchain referred to in this application is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0130] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A front-end project packaging method, characterized in that: include: According to the project packaging command input by the user, the preset packaging script file is called to extract files from each project under the monorepo framework to obtain one or more different projects to be packaged; Generate a packaging command according to the project name and packaging environment variables corresponding to each of the to-be-packaged projects; The packaging command is executed to package each of the items to be packaged, and a deployment package corresponding to each of the items to be packaged is obtained.
2. The front-end project packaging method according to claim 1, characterized in that: Before calling the preset packaging script file, it also includes: Install the execa dependency package in the monorepo framework and create the packaging script file; In the first configuration file that the monorepo framework depends on, add the running command corresponding to the packaging script file; The calling of the preset packaging script file includes: The run command in the first configuration file is executed based on the execa dependency package, where the run command is used to call the packaging script file.
3. The front-end project packaging method according to claim 1, characterized in that: The files of each project under the monorepo framework are extracted to obtain one or more different projects to be packaged, including: Perform file traversal based on the subdirectories corresponding to each of the projects to obtain directory files and non-directory files corresponding to each of the projects; Perform file filtering on non-directory files corresponding to each of the projects to obtain candidate projects, wherein the non-directory files include configuration files in the projects; The project to be packaged is determined according to the directory file corresponding to the candidate project.
4. The front-end project packaging method according to claim 3 is characterized in that: The step of determining the project to be packaged according to the directory file corresponding to the candidate project includes: Obtain a second configuration file from the candidate project; If the second configuration file includes an identification field corresponding to a common component, the candidate items are filtered according to the identification field to obtain the items to be packaged.
5. The front-end project packaging method according to claim 1, characterized in that: The files of each project under the monorepo framework are extracted to obtain one or more different projects to be packaged, including: Obtain a first configuration file that the monorepo framework depends on, where the first configuration file includes an array, and the array includes the project name of the project to be packaged; Projects are extracted according to the project names in the array to obtain the projects to be packaged.
6. The front-end project packaging method according to claim 1, characterized in that: Before generating a packaging command according to the project name corresponding to each of the to-be-packaged projects and the packaging environment variable, the method further includes: The command line parameter tool library in the monorepo framework is called to extract parameters of the project packaging command to obtain the packaging environment variables.
7. The front-end project packaging method according to claim 1, characterized in that: The step of packaging each of the to-be-packaged projects to obtain a deployment package corresponding to each of the to-be-packaged projects includes: Delete the historically packaged deployment packages; Set the maximum number of files to be packaged each time; Based on the maximum number of files, each of the to-be-packaged items is packaged to obtain a deployment package corresponding to each of the to-be-packaged items.
8. A front-end project packaging device, characterized in that: include: The file extraction module is used to call the preset packaging script file according to the project packaging command input by the user, extract files from each project under the monorepo framework, and obtain one or more different projects to be packaged; A packaging command generation module, used to generate a packaging command according to the project name and packaging environment variables corresponding to each of the to-be-packaged projects; The project packaging module is used to execute the packaging command, package each of the projects to be packaged, and obtain a deployment package corresponding to each of the projects to be packaged.
9. A computer device, characterized in that: The computer device includes a memory and a processor; The memory is used to store computer programs; The processor is used to execute the computer program and implement the front-end project packaging method as described in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor implements the front-end project packaging method according to any one of claims 1 to 7.
