Front-end code resource version management method and device, electronic equipment and storage medium
By automatically executing release and build commands when the front-end code resource is updated, and uploading the generated resource files to the server, the inconvenience of manually creating version number folders in the existing technology and the cost and compatibility issues of third-party release pipelines. Achieve efficient and automated front-end code resource management.
Patent Information
- Application Number
- CN202411411531.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-10
- Publication Date
- 2025-02-07
AI Technical Summary
In the prior art, when the front-end code resource is updated, manual creation of version number folders is prone to errors and inconvenient. Third-party release pipelines require additional costs and are incompatible with servers of multiple service providers.
When the front-end code resource is updated, the release command is executed and the version name format is checked. If it meets the predefined format, the build command is executed to generate the resource file to be published and upload it to the server, and the folder name is defined as the version name.
It realizes the automated construction and upload of front-end code resources, reduces manual intervention, improves development and operation and maintenance efficiency, reduces the risk of errors, and is suitable for projects with frequent version iterations.
Smart Images

Figure CN119396454A_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of the present specification relate to the field of code management technology, and in particular, to a front-end code resource version management method, device, electronic device, and storage medium. Background Art
[0002] In software development, developers usually use front-end frameworks to build user interfaces. Front-end frameworks provide a set of tools and libraries to help developers develop and maintain front-end code more efficiently. Since different browsers and different versions of browsers have different levels of support for the front-end code written by developers, in order to ensure that the front-end code written by developers can run normally on various browsers, it is necessary to use packaging and building tools to convert the front-end code written by developers into low-version front-end code that most browsers can understand.
[0003] After the front-end code resources are packaged and built, they are usually uploaded to a file resource server to speed up the loading of the front-end code resources and improve the user experience. In some embodiments, each time the front-end code resources are updated, the developer will manually create a new version number folder to store the updated front-end code resources, but this method is very inconvenient and prone to errors. In other embodiments, each time the front-end code resources are updated, a third-party publishing pipeline is used for automatic updates, but this method usually requires additional costs, and the third-party publishing pipeline may only support server uploads for specific platforms and is not compatible with servers of multiple service providers. Summary of the invention
[0004] The present disclosure provides a front-end code resource version management method, the method comprising:
[0005] In response to an update of the front-end code resource, executing a publishing command in the project directory where the front-end code resource is located;
[0006] If the version name format of the front-end code resource conforms to the predefined version name format, execute the build command in the project configuration file of the front-end code resource to enable the front-end code resource to generate a resource file to be published;
[0007] In response to the front-end code resource being constructed, the generated resource file to be published is uploaded to the server, and the folder name in the upload path parameter is defined as the version name of the front-end code resource.
[0008] Optionally, the front-end code resource performs version update iteration on a code development branch, and the method further includes:
[0009] If the name of the code branch where the front-end code resource is located conforms to the predefined version name format, then the version name format of the front-end code resource conforms to the predefined version name format;
[0010] The predefined version name format is a version number composed of numbers or letters.
[0011] Optionally, executing a build command in a project configuration file of the front-end code resource so that the front-end code resource generates a resource file to be published includes:
[0012] Displaying an interactive command line operation interface to the publisher, so that the publisher can choose whether to execute the construction operation of the front-end code resource on a local terminal device or on a remote server;
[0013] In response to the publisher's selection, a build command in the project configuration file of the front-end code resource is executed at a corresponding position, so that the front-end code resource generates a resource file to be published.
[0014] Optionally, uploading the generated resource file to be published to the server includes:
[0015] Upload the generated resource file to be published to the server via the Hypertext Transfer Protocol; or,
[0016] Upload the generated resource files to be published to the server through the software development kit provided by a third party;
[0017] The server is a self-built server or a content distribution network CDN server.
[0018] Optionally, the front-end code resource is used to be called and displayed by the front-end application; after uploading the generated resource file to be published to the server and defining the folder name in the upload path parameter as the version name of the front-end code resource, the method further includes:
[0019] Calling an API interface to write the version name of the front-end code resource into the front-end resource configuration center, so that the front-end application can obtain the latest version name of the front-end code resource from the front-end resource configuration center when running;
[0020] Among them, the front-end resource configuration center is used to centrally manage the version names of the front-end code resources.
[0021] Optionally, after writing the version name of the front-end code resource into the front-end resource configuration center so that the front-end application obtains the latest version name of the front-end code resource from the front-end resource configuration center when running, the method further includes:
[0022] Merge the code development branch where the front-end code resources are located into the code development trunk branch.
[0023] Optionally, the method further includes:
[0024] If the build command is not found in the project configuration file of the front-end code resource, the process is stopped and a prompt message is returned to the publisher so that the publisher can add a build command of the default configuration or a build command of a custom configuration.
[0025] The present disclosure also provides a front-end code resource version management device, the device comprising:
[0026] A first execution unit, configured to execute a publishing command in a project directory where the front-end code resource is located in response to an update of the front-end code resource;
[0027] A second execution unit is used to execute a build command in a project configuration file of the front-end code resource if the version name format of the front-end code resource conforms to a predefined version name format, so that the front-end code resource generates a resource file to be published;
[0028] The uploading unit is used to upload the generated resource file to be published to the server in response to the front-end code resource being constructed, and define the folder name in the upload path parameter as the version name of the front-end code resource.
[0029] The present disclosure also provides an electronic device, comprising a communication interface, a processor, a memory and a bus, wherein the communication interface, the processor and the memory are interconnected via the bus;
[0030] The memory stores machine-readable instructions, and the processor executes the above method by calling the machine-readable instructions.
[0031] The present disclosure also provides a machine-readable storage medium, wherein the machine-readable storage medium stores machine-readable instructions, and when the machine-readable instructions are called and executed by a processor, the above method is implemented.
[0032] Through the embodiments of the present disclosure, after the front-end code resources are updated, a release command is executed in the project directory where the front-end code resources are located to start the release process of the front-end code resources; if the version name format of the front-end code resources conforms to the predefined version name format, the build command in the project configuration file of the front-end code resources is executed to enable the front-end code resources to generate resource files to be released; after the front-end code resources are built, the generated resource files to be released are uploaded to the server, and the folder name in the upload path parameter is defined as the version name of the front-end code resources. Accordingly, the present disclosure can realize the efficient construction and uploading of updated front-end code resources through a series of standardized and automated steps, which is particularly suitable for projects that require frequent version iterations. In this way, the version number of the updated front-end code resources is automatically generated according to the rules, and the entire process can reduce manual intervention, significantly improve the efficiency of development and operation and maintenance, and reduce the risk of errors. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the technical solutions of the embodiments of this specification, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0034] Figure 1 It is a flowchart of a front-end code resource version management method shown in an exemplary embodiment;
[0035] Figure 2 is a schematic diagram of selecting a construction location of a front-end code resource according to an exemplary embodiment;
[0036] Figure 3 It is a flowchart of a front-end code resource version management method shown in an exemplary embodiment;
[0037] Figure 4 is a hardware structure diagram of an electronic device shown in an exemplary embodiment;
[0038] Figure 5 It is a block diagram of a front-end code resource version management device shown in an exemplary embodiment. DETAILED DESCRIPTION
[0039] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this specification.
[0040] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0041] In software development, developers usually use front-end frameworks to build user interfaces. Front-end frameworks provide a set of tools and libraries to help developers develop and maintain front-end code more efficiently. Since different browsers and different versions of browsers have different levels of support for the front-end code written by developers, in order to ensure that the front-end code written by developers can run normally on various browsers, it is necessary to use packaging and building tools to convert the front-end code written by developers into low-version front-end code that most browsers can understand.
[0042] After the front-end code resources are packaged and built, they are usually uploaded to a file resource server to speed up the loading of the front-end code resources and improve the user experience. In some embodiments, each time the front-end code resources are updated, the developer will manually create a new version number folder (such as version number 1.1) to store the updated front-end code resources, but this method is very inconvenient and prone to errors. In other embodiments, each time the front-end code resources are updated, a third-party publishing pipeline is used for automatic updates, but this method usually requires additional costs, and the third-party publishing pipeline may only support server uploads for a specific platform and is not compatible with servers of multiple service providers.
[0043] In view of this, this specification aims to propose a technical solution for automatically packaging and building updated front-end code resources and uploading them to a server.
[0044] During implementation, first, after the front-end code resources are updated, a publishing command is executed in the project directory where the front-end code resources are located to start the publishing process of the front-end code resources; further, if the version name format of the front-end code resources conforms to the predefined version name format, the build command in the project configuration file of the front-end code resources is executed to enable the front-end code resources to generate resource files to be published; finally, after the front-end code resources are built, the generated resource files to be published are uploaded to the server, and the folder name in the upload path parameter is defined as the version name of the front-end code resources.
[0045] For example, an e-commerce platform wants to update its product display page to improve the user experience on mobile devices. The front-end development team may add new interactive scripts to recommend products based on the user's browsing history, and update product images to improve image quality. After completing these updates, the front-end resources will be repackaged and deployed to the server. When users visit the website, they will load the new code resources and experience the updated functions and styles. The e-commerce platform uses a version control system (such as Git) to manage code changes. Whenever a developer submits an update, these changes will be recorded in the version history. Through the Git command, you can view the file changes and submission history to understand the content of each submission. When it is detected that the developer has submitted an update, the developed command line tool is used to execute the release command in the project directory where the updated front-end code resources are located, triggering the build and upload process of the updated front-end code resources. Then, determine whether the updated version name format 1.0.1 of the front-end code resource complies with the predefined version name format xyz, where x, y, and z are version numbers composed of numbers or letters. Since it complies, the build command npm run build in the project configuration file of the front-end code resource (usually the package.json file) can be executed to complete the packaging and building of the front-end code resource, and generate the front-end code resource file to be released in the dist file in the root directory. Finally, the front-end code resource file to be released (version 1.0.1) is uploaded to the specified CDN directory: / cdn / path / to / resources / v1.0.1 through the API interface of the third-party CDN (Content Delivery Network) service.
[0046] It can be seen that in the technical solution of this specification, after the front-end code resources are updated, a release command is executed in the project directory where the front-end code resources are located to start the release process of the front-end code resources; if the version name format of the front-end code resources conforms to the predefined version name format, the build command in the project configuration file of the front-end code resources is executed to enable the front-end code resources to generate resource files to be released; after the front-end code resources are built, the generated resource files to be released are uploaded to the server, and the folder name in the upload path parameter is defined as the version name of the front-end code resources. Accordingly, the present disclosure can realize the efficient construction and uploading of updated front-end code resources through a series of standardized and automated steps, which is particularly suitable for projects that require frequent version iterations. In this way, the version number of the updated front-end code resources is automatically generated according to the rules, and the entire process can reduce manual intervention, significantly improve the efficiency of development and operation and maintenance, and reduce the risk of errors.
[0047] The present disclosure is described below through specific embodiments in combination with specific application scenarios.
[0048] See also Figure 1 , Figure 1 This is a flowchart of a front-end code resource version management method shown in an exemplary embodiment. The method can perform the following steps:
[0049] Step 102: In response to an update of the front-end code resource, a publishing command is executed in the project directory where the front-end code resource is located.
[0050] For example, an e-commerce platform wants to update its product display page to improve the user experience on mobile devices. The front-end development team may add new interactive scripts to recommend products based on the user's browsing history, and update product images to improve image quality. After completing these updates, the front-end resources will be repackaged and deployed to the server. When users visit the website, they will load the new code resources and experience the updated functions and styles. The e-commerce platform uses a version control system (such as Git) to manage code changes. Whenever a developer submits an update, these changes will be recorded in the version history. Through the Git command, you can view the file changes and submission history to understand the content of each submission. When it is detected that the developer has submitted an update, the developed command line tool is used to execute the release command in the project directory where the updated front-end code resources are located, triggering the build and upload process of the updated front-end code resources.
[0051] Among them, the front-end code resources mainly refer to the code and related resources used to build the user interface of a website or web application. Front-end development focuses on the part that users can interact with directly. Front-end code resources usually include the following main contents: HTML (HyperText Markup Language), which is the basis of the structure and layout of web page content. It defines the display structure of text, links, pictures, tables, lists, etc. in web pages; CSS (Cascading Style Sheets), which is used to set the visual and layout of web pages, including layout, color, font, spacing, etc., which can help developers create responsive designs that adapt to different devices and screen sizes; pictures and graphics, including pictures and graphic resources in formats such as JPEG, PNG, SVG, GIF, etc., for the visual display of web pages. The present disclosure does not limit the specific content of the front-end code resources. The front-end code resources are called and displayed by the front-end application. These resources are written, debugged and optimized during the development process, and finally generate optimized resource files through the build process. Front-end applications refer to web applications running in user browsers. These web applications obtain the required resource files from the server or CDN through HTTP requests. The project directory where the front-end code resources are located refers to the directory where the folders of the project files and codes are stored. The updates of the front-end code resources may include: functional updates, such as adding new interactive features or pages; style changes: improving the visual style of the website; bug fixes: solving problems found in user feedback or testing; security updates: fixing security vulnerabilities, etc. This disclosure does not limit the updates of the front-end code resources.
[0052] Step 104: If the version name format of the front-end code resource conforms to the predefined version name format, execute the build command in the project configuration file of the front-end code resource to enable the front-end code resource to generate a resource file to be released.
[0053] For example, determine whether the version name format 1.0.1 of the updated front-end code resource complies with the predefined version name format xyz, where x, y, and z are version numbers composed of numbers or letters. Since it complies, the build command npm run build in the project configuration file of the front-end code resource (usually the package.json file) can be executed to complete the packaging and building of the front-end code resource, and generate the front-end code resource file to be released in the dist file in the root directory.
[0054] Among them, there is usually a json file with the configuration, description and other information of the current project in the root directory of the front-end project. The file name is package.json, and the file content is in json format. Generally, it will have a scripts attribute to configure other commands such as project startup, building, testing, etc., for developers to execute different commands in different scenarios. In the technical solution disclosed in the present invention, only the build is executed, and the default is the value of the build attribute under the scripts attribute. In the front-end project, the package.json file is the core of the npm package manager, which contains the configuration information and script commands of the project. npm is the default package manager for the JavaScript runtime environment Node.js. It allows developers to install, share and manage dependent code, which is usually published and used in the form of packages. To execute the build command, one or more scripts are usually defined in the scripts attribute of the package.json file. First, you need to view the scripts defined in the package.json file. Open the package.json file in the root directory of the project and search for the "scripts" attribute. You may see the following:
[0055]
[0056] In this example, the "build" script is used to build the code for the production environment. Since the "build" script has been defined in the front-end project, the developer can execute the construction of the front-end code resources through the npm run build command. If the build command is not found, the publishing process stops and the publisher is prompted. In the technical solution of the present disclosure, the build command can also be a custom build command. In the package.json file, there is generally a build command for the project, which is usually named build. However, when the developer has multiple environments or custom build commands, the developer may not call it build. For example, the name may be onlineBuild, dailyBuild, etc. If this is the case, when executing npm runbuild during the build, an error of missing script (Missing script: "build") will be reported. Therefore, when executing a custom build command, it is necessary to specify the method name of the build. If it is not specified, the default is build.
[0057] The dist folder is usually an abbreviation of "distribution" in front-end projects, which means distribution or release. This folder is used to store the final product after construction or compilation, that is, the front-end code resources ready to be deployed to the production environment. The dist folder usually does not contain the source code of the project, but contains the built code.
[0058] Step 106: In response to the front-end code resource being constructed, the generated resource file to be published is uploaded to the server, and the folder name in the upload path parameter is defined as the version name of the front-end code resource.
[0059] For example, after the build command npm run build is executed, the front-end code resource project has been built, and its version name can be based on the current Git commit, or manually specified, such as version name 1.0.1. Then, define the path to upload to the server and set the folder name to the version name. Assuming that the base path of the server is / home / deploy_user / deployment / , the upload path can be defined as: / home / deploy_user / deployment / 1.0.1. The specific upload method can be to upload the resource files in the dist directory to the specified CDN directory through the API interface of a third-party CDN (Content Delivery Network) service. After the upload is complete, the deployment script or pipeline moves these resource files to the root directory of the website, or updates the CDN configuration to make the new version effective.
[0060] Among them, front-end code resource construction refers to the use of tools to compile, package and process source code (HTML, CSS, JavaScript, etc.) to generate files that can be used directly in the browser. The build process is usually triggered by npm scripts (such as npm runbuild), and the build rules are defined using configuration files. Among them, monitoring whether the build is completed can be achieved by writing scripts to monitor the event of the build completion, or configuring hooks in the build tool. The version name is used to identify the labels of different release stages of the front-end code resources, usually following the semantic version naming rules, with the format of major version number.minor version number.revision number (such as 1.0.1). CDN (Content Delivery Network) is a distributed network service used to speed up the speed at which users access websites or applications and cache content on globally distributed nodes. Application Programming Interface (API) is an agreement for interaction between software, allowing data and functions to be transmitted between different programs.
[0061] In the embodiment of the present disclosure, through the above steps, the built front-end code resources can be automatically uploaded to the server, and the folder is named with the version name. This ensures that each deployment is traceable and can be easily rolled back to the previous version.
[0062] In one embodiment shown, the front-end code resource performs version update iteration on a code development branch, and the method also includes: if the name of the code branch where the front-end code resource is located conforms to a predefined version name format, then the version name format of the front-end code resource conforms to the predefined version name format; wherein, the predefined version name format is a version number composed of numbers or letters.
[0063] For example, the front-end development team is using Git for version control and adopting the Git Flow development model, which means there are multiple development branches, including the master branch and feature branches for feature development. A developer in the team develops a new feature of the front-end code resource on a branch called feature-1.0.1 of the feature branch of feature development. When the development of the new feature is completed and it needs to be prepared for release, it is necessary to make sure that the name of the development branch must conform to the format of feature-xyz, where xyz is the version number, which must be a number and named according to the semantic version control rules. Since feature-1.0.1 conforms to the format of feature-xyz, it is considered that the version name format of the updated front-end code resource conforms to the predefined version name format.
[0064] Among them, the version update iteration of front-end code resources usually follows certain workflows and best practices to ensure the maintainability of the code and the efficiency of team collaboration. A common practice is to use multiple branches (such as main branches and development branches) to manage different development tasks and version iterations. The main branch is usually the stable version of the project, and all release versions are made from this branch. The development branch is used for daily development work, and all new features and fixes are merged into this branch first. When checking the code branch name, you can execute a script or pipeline step to check whether the name of the current development branch (ie feature-1.0.1) conforms to the predefined version name format. Once it is confirmed that the branch name conforms to the predefined version name format, the pipeline will automatically trigger the build process to build the front-end code resources.
[0065] In this embodiment, the name of the code branch where the front-end code resource is located is used to reflect the version name of the front-end code resource. As long as the code branch is named correctly, the version name of the front-end code resource can be considered to comply with regulations, and subsequent automated processes can be carried out. The technical solution disclosed in the present invention can ensure that the code is clear and easy to understand, while maintaining the clarity and consistency of version control, and facilitating the efficient management of the software release process.
[0066] It should be noted that the predefined version name format may not be xyz, and can be customized by the user as needed. For the customized release version name format, parameter verification can be used to determine whether the version name format of the updated front-end code resource complies with the rules. The parameter type is a regular expression.
[0067] In one embodiment shown, executing the build command in the project configuration file of the front-end code resource so that the front-end code resource generates a resource file to be published includes: displaying an interactive command line operation interface to the publisher so that the publisher can choose whether to execute the build operation of the front-end code resource on a local terminal device or on a remote server; in response to the publisher's choice, executing the build command in the project configuration file of the front-end code resource at a corresponding location so that the front-end code resource generates a resource file to be published.
[0068] For example, see Figure 2 , Figure 2 FIG. 1 is a schematic diagram showing a method of selecting a construction location of a front-end code resource according to an exemplary embodiment. Figure 2 As shown, the local terminal device 202 is connected to the remote server 206 via the network 204. The local terminal device 202 creates an interactive command line interface through the Node.js script. When the Node.js script is run, an interactive command line interface is displayed to the publisher, and then the publisher selects whether to perform the build operation on the local terminal device or on the remote server. If the publisher chooses to build locally, the Node.js script will execute the npm runbuild command in the local terminal to generate the resource files to be published. If the publisher chooses to build on the remote server, the Node.js script will connect to the remote server via SSH to execute the build command and generate the front-end code resource files to be published.
[0069] Among them, the building process can be configured in advance by the user as needed, or accept the user's choice when starting the build command to determine whether the build is completed on the local computer or on the remote server. The build process of the local build is performed on the developer's local machine, which means that local computing resources (CPU, memory, disk space, etc.) are used. The build process of the remote server build is performed on the remote server, which means that the computing resources of the remote server are used. Creating an interactive command line interface (CLI, Command Line Interface) through a Node.js script means using the Node.js programming language to develop a program that can run in a command line environment and can interact with the user in real time. This interface allows users to communicate with the program by entering commands or options.
[0070] In the embodiments of the present disclosure, this flexible and automated construction solution, first, improves the efficiency and quality of software development. Developers can choose to build projects on local or remote servers as needed to adapt to different development and deployment environment requirements; second, through the interactive command line operation interface, it simplifies the user's operation process, making the construction process more intuitive and easy to use; finally, the automated construction process reduces human participation and possible errors, and improves the reliability and efficiency of front-end code resource construction.
[0071] In one embodiment shown, uploading the generated resource files to be published to the server includes: uploading the generated resource files to be published to the server through the Hypertext Transfer Protocol; or uploading the generated resource files to be published to the server through a software development kit provided by a third party; wherein the server is a self-built server or a content distribution network CDN server.
[0072] For example, if resource files to be published are generated in the dist directory, these resource files can be uploaded through the Hypertext Transfer Protocol (HTTP). You need to use HTTP requests to upload the resource files to be published to a self-built server or content distribution network CDN. Assume that the server address is https: / / example.com / , and you want to upload the resource files to the / versions / 1.0.1 / directory. You can use command line tools (such as curl) or programming languages (such as Python, Node.js) to send HTTP requests. You can also upload resource files through SDK (Software Development Kit). You need to install the SDK first, and then use the SDK to write a script to upload resource files. This script will configure the access key and bucket, and then upload the resource files to be published one by one to the specified path.
[0073] Among them, Hypertext Transfer Protocol (HTTP) is one of the most widely used protocols on the Internet, used for information exchange between clients and servers. It defines the format of requests and responses between clients and servers. HTTP requests can be sent using command line tools (such as curl) or programming language libraries (such as Python's requests library, Node.js's axios library). For the specific tools for sending HTTP requests, this disclosure does not limit this. Command line tools, such as curl, are file transfer tools that work in command line mode using URL syntax. Software Development Kit (SDK) is used to help developers create applications for specific software applications, software frameworks, etc. Self-built servers refer to servers that are built and maintained by organizations or individuals, which can be physical servers or virtual servers.
[0074] The built front-end code resource files are uploaded to the server or CDN and stored in the specified path. When the user opens the front-end application, the browser will parse the resource link in the HTML file and initiate an HTTP request based on the resource link to download the required resource files from the server or CDN. After the browser has downloaded all the resource files, it will parse the HTML file, apply the CSS style, and execute the JavaScript code. Finally, the browser renders the page and displays it to the user.
[0075] In one embodiment shown, the front-end code resources are used to be called and displayed by the front-end application; after uploading the generated resource file to be published to the server and defining the folder name in the upload path parameter as the version name of the front-end code resource, the method also includes: calling an API interface to write the version name of the front-end code resource into the front-end resource configuration center, so that the front-end application can obtain the latest version name of the front-end code resource from the front-end resource configuration center when it is running; wherein the front-end resource configuration center is used to centrally manage the version name of the front-end code resources.
[0076] For example, suppose the front-end development team develops a JavaScript front-end application that needs to load a JavaScript library file from the server. The new version 1.0.1 of the JavaScript library file has just been completed. After uploading it to the server, the API interface is called using an HTTP request to send the version information 1.0.1 to the front-end resource configuration center. After receiving the request, the front-end resource configuration center updates its database or storage system and marks the latest version of the JavaScript library file as 1.0.1. When the user opens the front-end application, the front-end application requests the API interface of the front-end resource configuration center to obtain the latest version of the JavaScript library file. The front-end application requests the corresponding front-end code resource file from the server based on the version information 1.0.1 of the JavaScript library file returned by the front-end resource configuration center.
[0077] Among them, the front-end resource configuration center is a system or service used to centrally store and manage the configuration information of the front-end code resources, including the version name of the resources. This can be implemented using cloud services or independent databases (such as MySQL, MongoDB). Writing the version name of the front-end code resources is the process of storing the new version information of the front-end code resources in the front-end resource configuration center. Specifically, you can write a script or program to call the API interface to write the new version information of the front-end code resources as configuration data to the corresponding database or cloud service. After writing, if a callback API is configured, call the API to write the currently released version information to the front-end resource configuration center. This step ensures that the front-end application can automatically use the latest resource version.
[0078] In one embodiment shown, after writing the version name of the front-end code resource into the front-end resource configuration center so that the front-end application obtains the latest version name of the front-end code resource from the front-end resource configuration center during runtime, the method also includes: merging the code development branch where the front-end code resource is located into the code development trunk branch.
[0079] For example, a front-end project uses Git for version control. The front-end code of the project is hosted on GitHub, with the development branch feature / new-feature and the main branch main. A new feature has been developed on the development branch feature / new-feature, including the addition of some new components and pages. Developers use a simple JSON file config.json in the front-end resource configuration center to store the version name v1.0.1 of the front-end code resources after the new feature is developed. Specifically, on the feature / new-feature branch, edit the config.json file, update the version name to v1.0.1, and then commit the changes to the feature / new-feature branch, and push the changes to the feature / new-feature branch of the remote repository. Before merging, developers need to switch back to the main branch, make sure the local main branch main is up to date, and then merge the feature / new-feature branch into the main branch. If there are conflicts during the merge, manually resolve the conflicts and commit the changes, and finally push the merged code to the main branch of the remote repository.
[0080] Among them, the code development trunk branch is the main branch of the project, which usually contains a stable version of the code. In this embodiment, the trunk branch is main. The code development branch is a branch used to develop new features or fix bugs, usually created from the trunk branch. In this embodiment, the development branch is feature / new-feature. In this embodiment, Git is a distributed version control system used to track and manage code changes during the software development process. GitHub is a Git-based code hosting platform that provides code hosting, version control, collaboration and other functions. A conflict refers to when merging two branches, if the same part of the same file is modified in both branches, Git cannot automatically decide which version to use, and a conflict will occur.
[0081] In this embodiment, after the release is completed, the development branch is automatically merged into the main branch, which can realize the automated process of code building, resource release, and code merging. In addition, merging the code of the development branch into the main branch can ensure that the main branch always contains the latest features and fixes, which helps to maintain the consistency and stability of the code base. The merged main branch can be quickly deployed to the test environment or production environment, so that new features can be fed back by users as soon as possible, helping developers to adjust and improve in time.
[0082] In one embodiment shown, the method also includes: if the build command is not found in the project configuration file of the front-end code resource, stopping the process and returning a prompt message to the publisher so that the publisher can add a default configuration build command or a custom configuration build command.
[0083] For example, a front-end project uses package.json as the project configuration file. The project is hosted on GitHub and built and managed using Node.js and npm. You can use the publish.js script to automate the publishing process. The script checks whether package.json contains a build command (that is, checks whether there is a build attribute in the scripts object). If not, the process is stopped and a prompt message is returned to the publisher, such as an error message: "Error: Build command not found in package.json." to prompt the publisher to add a build command and stop the publishing process.
[0084] Among them, the release process is a series of steps to deploy the front-end code from the development environment to the production environment, including building, testing, packaging, uploading, etc. Scripts are programs used to automate tasks. In this example, publish.js is a Node.js script used to automate the release process. GitHub is a Git-based code hosting platform that provides code hosting, version control, collaboration and other functions. Node.js is a JavaScript runtime environment used to run JavaScript code on the server side. npm is a package manager for Node.js, which is used to install, manage and publish Node.js packages. The file content of the package.json file can be read using the fs module of Node.js. Parsing the package.json file usually involves parsing the read file content into a JSON object, checking whether the parsed JSON object contains a scripts object, and whether there is a build attribute in the scripts object.
[0085] In this embodiment, when no build command is found in the project configuration file package.json of the front-end code resource, the publishing process can be stopped and a prompt message can be returned to the publisher, so that the publisher can add a default configuration build command or a custom configuration build command. This can ensure the smooth progress of the publishing process and avoid errors caused by the lack of necessary configuration.
[0086] In order to help those skilled in the art better understand this method, Figure 3 This method is described.
[0087] See also Figure 3 , Figure 3 FIG. 1 is a flowchart of a method for managing front-end code resource versions according to an exemplary embodiment. Figure 3As shown, when the method is started, it is first determined whether the branch name of the code branch for the front-end resource version update conforms to the predefined version name format xyz; then, if it does not conform to the predefined version name format xyz, a prompt message is returned to the publisher, and the publishing process of the front-end code resource is ended. If it conforms to the predefined version name format xyz, the resource construction is performed on the local terminal device or on the remote server selected by the publisher, and it is determined whether to use the remote server resource or the local terminal device resource to execute the construction command; after the front-end code resource is built, a front-end code resource file to be published is generated, and then the generated front-end code resource file is processed or uploaded; then, it is determined whether the API interface is configured. If the API interface is configured, the API interface is called to write the updated version of the front-end code resource into the front-end resource configuration center, and then the code development branch of the updated front-end code resource version is merged into the trunk branch. If the API interface is not configured, the code development branch of the updated front-end code resource version is directly merged into the trunk branch, and finally the update and upload process of the front-end code resource is ended.
[0088] Corresponding to the above-mentioned embodiment of the front-end code resource version management method, this specification also provides an embodiment of a front-end code resource version management device.
[0089] See also Figure 4 , Figure 4 It is a hardware structure diagram of an electronic device shown in an exemplary embodiment. At the hardware level, the device includes a processor 402, an internal bus 404, a network interface 406, a memory 408 and a non-volatile memory 410, and of course may also include other required hardware. One or more embodiments of this specification can be implemented based on software, such as the processor 402 reading the corresponding computer program from the non-volatile memory 410 into the memory 408 and then running it. Of course, in addition to the software implementation, one or more embodiments of this specification do not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc., that is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0090] See also Figure 5 , Figure 5 is a block diagram of a front-end code resource version management device shown in an exemplary embodiment. The front-end code resource version management device 500 can be applied to Figure 4 In the electronic device shown in the figure, the technical solution of this specification is implemented. The device includes:
[0091] The first execution unit 502 is used for executing a publishing command in the project directory where the front-end code resource is located in response to the front-end code resource being updated;
[0092] The second execution unit 504 is used to execute the build command in the project configuration file of the front-end code resource if the version name format of the front-end code resource conforms to the predefined version name format, so that the front-end code resource generates a resource file to be released;
[0093] The uploading unit 506 is used to upload the generated resource file to be published to the server in response to the front-end code resource being constructed, and define the folder name in the upload path parameter as the version name of the front-end code resource.
[0094] In this embodiment, the front-end code resource performs version update iteration on a code development branch, and the device further includes:
[0095] A judging unit, configured to determine whether the version name format of the front-end code resource complies with the predefined version name format if the name of the code branch where the front-end code resource is located complies with the predefined version name format;
[0096] The predefined version name format is a version number composed of numbers or letters.
[0097] In this embodiment, the second execution unit includes:
[0098] A display subunit, used to display an interactive command line operation interface to the publisher, so that the publisher can choose to execute the construction operation of the front-end code resource on a local terminal device or on a remote server;
[0099] The construction subunit is used to execute the construction command in the project configuration file of the front-end code resource at the corresponding position in response to the selection of the publisher, so that the front-end code resource generates a resource file to be published.
[0100] In this embodiment, the uploading unit includes:
[0101] A first uploading subunit is used to upload the generated resource file to be published to the server through the Hypertext Transfer Protocol;
[0102] The second uploading subunit is used to upload the generated resource files to be published to the server through a software development kit provided by a third party; wherein the server is a self-built server or a content distribution network CDN server.
[0103] In this embodiment, the front-end code resource is used to be called and displayed by the front-end application; after uploading the generated resource file to be published to the server and defining the folder name in the upload path parameter as the version name of the front-end code resource, the device further includes:
[0104] A calling unit is used to call an API interface and write the version name of the front-end code resource into a front-end resource configuration center so that the front-end application can obtain the latest version name of the front-end code resource from the front-end resource configuration center when it is running; wherein the front-end resource configuration center is used to centrally manage the version name of the front-end code resource.
[0105] In this embodiment, after writing the version name of the front-end code resource into the front-end resource configuration center so that the front-end application obtains the latest version name of the front-end code resource from the front-end resource configuration center when running, the device further includes:
[0106] The merging unit is used to merge the code development branch where the front-end code resources are located into the code development trunk branch.
[0107] In this embodiment, the device further includes:
[0108] The return unit is used to stop the process and return a prompt message to the publisher if the build command is not found in the project configuration file of the front-end code resource, so that the publisher can add a default configuration build command or a custom configuration build command.
[0109] The implementation process of the functions and effects of each unit in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.
[0110] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can refer to the partial description of the method embodiments. The device embodiments described above are only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this specification. Ordinary technicians in this field can understand and implement it without paying creative work.
[0111] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.
[0112] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0113] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0114] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0115] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0116] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0117] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0118] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "one", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0119] It should be understood that although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of this specification, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0120] The above description is merely a preferred embodiment of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present specification shall be included in the scope of protection of one or more embodiments of the present specification.
Claims
1. A front-end code resource version management method, characterized in that: The method comprises: In response to an update of the front-end code resource, executing a publishing command in the project directory where the front-end code resource is located; If the version name format of the front-end code resource conforms to the predefined version name format, execute the build command in the project configuration file of the front-end code resource to enable the front-end code resource to generate a resource file to be published; In response to the front-end code resource being constructed, the generated resource file to be published is uploaded to the server, and the folder name in the upload path parameter is defined as the version name of the front-end code resource.
2. The method according to claim 1, characterized in that The front-end code resource performs version update iteration on a code development branch, and the method further includes: If the name of the code branch where the front-end code resource is located conforms to the predefined version name format, then the version name format of the front-end code resource conforms to the predefined version name format; The predefined version name format is a version number composed of numbers or letters.
3. The method according to claim 1, characterized in that The executing the build command in the project configuration file of the front-end code resource so that the front-end code resource generates a resource file to be published includes: Displaying an interactive command line operation interface to the publisher, so that the publisher can choose whether to execute the construction operation of the front-end code resource on a local terminal device or on a remote server; In response to the publisher's selection, a build command in the project configuration file of the front-end code resource is executed at a corresponding position, so that the front-end code resource generates a resource file to be published.
4. The method according to claim 1, characterized in that: The step of uploading the generated resource file to be published to the server includes: Upload the generated resource file to be published to the server via the Hypertext Transfer Protocol; or, Upload the generated resource files to be published to the server through the software development kit provided by a third party; The server is a self-built server or a content distribution network CDN server.
5. The method according to claim 1, characterized in that The front-end code resource is used to be called and displayed by the front-end application; after uploading the generated resource file to be published to the server and defining the folder name in the upload path parameter as the version name of the front-end code resource, the method further includes: Calling an API interface to write the version name of the front-end code resource into the front-end resource configuration center, so that the front-end application can obtain the latest version name of the front-end code resource from the front-end resource configuration center when running; Among them, the front-end resource configuration center is used to centrally manage the version names of the front-end code resources.
6. The method according to claim 5, characterized in that After writing the version name of the front-end code resource into the front-end resource configuration center so that the front-end application can obtain the latest version name of the front-end code resource from the front-end resource configuration center when running, the method further includes: Merge the code development branch where the front-end code resources are located into the code development trunk branch.
7. The method according to claim 1, characterized in that The method further comprises: If the build command is not found in the project configuration file of the front-end code resource, the process is stopped and a prompt message is returned to the publisher so that the publisher can add a build command of the default configuration or a build command of a custom configuration.
8. A front-end code resource version management device, characterized in that: The device comprises: A first execution unit, configured to execute a publishing command in a project directory where the front-end code resource is located in response to an update of the front-end code resource; A second execution unit is used to execute a build command in a project configuration file of the front-end code resource if the version name format of the front-end code resource conforms to a predefined version name format, so that the front-end code resource generates a resource file to be published; The uploading unit is used to upload the generated resource file to be published to the server in response to the front-end code resource being constructed, and define the folder name in the upload path parameter as the version name of the front-end code resource.
9. An electronic device, characterized in that: It includes a communication interface, a processor, a memory and a bus, wherein the communication interface, the processor and the memory are interconnected via the bus; The memory stores machine-readable instructions, and the processor executes the method according to any one of claims 1 to 7 by calling the machine-readable instructions.
10. A machine-readable storage medium, characterized in that: The machine-readable storage medium stores machine-readable instructions, and when the machine-readable instructions are called and executed by the processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Front-end resource management method, system and equipment
CN114035824A
Method for automatically identifying difference of submitted log based on gitlab code
CN117573564A
Versioned project associations
US7152224B1