A small program development method and device
Through predefined project templates and public grammar rules, entry files and routing configuration information that comply with public grammar rules are generated, which solves the problem of multi-platform interoperability and compatibility in mini program development, achieves an efficient and unified development process, and reduces learning costs. and maintenance difficulty.
Patent Information
- Application Number
- CN202110944780.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-17
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2041-08-17
AI Technical Summary
The existing small program development framework needs to be developed separately for each platform, resulting in high development learning costs and low efficiency. In addition, there are differences in development styles and difficulty in maintenance during multi-person collaborative development, which violates the principle of cross-platform development.
Through predefined project templates and public grammar rules, we can generate entry files and routing configuration information that comply with public grammar rules, inject libraries and global configurations, assemble and package to generate small program applications, and achieve multi-platform interoperability and compatibility.
It reduces development and learning costs, improves development efficiency and maintainability, realizes interoperability and compatibility of small program applications on multiple platforms, simplifies the project structure, and follows a unified development style.
Smart Images

Figure CN113590125B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer software technology, and more specifically, to a method and device for developing a small program. Background Art
[0002] Mini Programs are a new type of application that connects users and services. In various host environments (mobile apps, car systems, IoT devices, etc.), users can install them without being notified, use them right away, and leave immediately after use, eliminating the trouble of installing too many apps.
[0003] There are many mini-program platforms, such as WeChat, Alipay, Baidu, Toutiao News, etc. These platforms have their own development frameworks, syntax, and development tools, and are not interoperable with each other. For each mini-program platform, it is necessary to develop a mini-program application that is compatible with it. This undoubtedly increases the development learning cost and reduces development efficiency.
[0004] At the same time, this goes against the inherent cross-platform feature of front-end development languages (HTML and CSS of W3C standards, JavaScript of ECMAScript specifications), namely "Write once, run anywhere" (WORA).
[0005] uni-app, launched by DCloud, is a mini-program development framework developed using Vue.js. It is developed based on Vue syntax, which to a certain extent smooths out the syntax differences of various mini-program platforms and can be published to mini-program platforms, iOS, Android, Web and other platforms.
[0006] However, on the one hand, uni-app supports limited Vue syntax, and you need to refer to the development documentation to use the supported syntax for development; on the other hand, the project structure created by uni-app needs to include the component folder of the corresponding platform when using the corresponding platform components. When there are many platforms, the project structure will become more complicated. Even if a new mini program platform appears, the development framework needs to add additional adaptation processing.
[0007] In addition, in a multi-person collaborative development model, each person has a different development style, which leads to a poor development experience and increases the difficulty of later maintenance of the project.
[0008] Therefore, when building a mini program platform, lowering the development learning threshold and maintaining consistency in team development are important technical issues that must be addressed. Summary of the invention
[0009] In view of this, the present application provides a method and device for developing a mini-program to develop a mini-program that is interoperable and compatible with multiple application platforms.
[0010] To achieve the above objectives, the first aspect of the present application provides a method for developing a small program, comprising:
[0011] Inserting the parameter configuration into a predefined project template to generate a project, wherein the project template is created based on a predefined file structure relationship, file format, and common syntax;
[0012] Parsing the engineering project and converting it according to preset common grammar rules to generate an entry file and routing configuration information that conforms to the common grammar rules;
[0013] Injecting the library and / or global configuration that the project depends on into the entry file to obtain a processed entry file;
[0014] Generate a mini-program application according to the processed entry file and the routing configuration information.
[0015] Preferably, the process of parsing the engineering project and converting it according to preset common grammar rules to generate an entry file that complies with the common grammar rules includes:
[0016] Parsing the engineering project to obtain the original entry file;
[0017] The life cycle of the original entry file is converted according to the conversion rules of Vue syntax and life cycle, and the application-level life cycle is injected to generate an entry file that conforms to the Vue syntax rules.
[0018] Preferably, the process of parsing the engineering project and converting it according to preset common grammar rules to generate routing configuration information that complies with the common grammar rules includes:
[0019] Parsing the engineering project to obtain original routing configuration information;
[0020] The original routing configuration information is converted according to the Vue grammar rules to generate routing configuration information that complies with the Vue grammar rules.
[0021] Preferably, the process of generating a mini-program application according to the processed entry file and the routing configuration information includes:
[0022] The routing page corresponding to the routing configuration information is assembled into a mini-program page according to the routing configuration information, and the mini-program page and the processed entry file are packaged into a mini-program application.
[0023] Preferably, the process of assembling the routing configuration information into a mini-program page includes:
[0024] According to the routing configuration information, obtain a routing page;
[0025] Parse the routing page to obtain the life cycle and component information of the routing page;
[0026] Convert the life cycle of the routing page to the application-level life cycle and the Vue syntax life cycle, and inject the corresponding components into the routing page according to the component information of the routing page to obtain the processed routing page;
[0027] The processed routing pages are assembled into a single file that conforms to the Vue syntax, and the single file that conforms to the Vue syntax constitutes the mini program page.
[0028] Preferably, the process of parsing the routing page and obtaining the life cycle and component information of the routing page includes:
[0029] Parse the index.js file of the routing page to obtain the life cycle of the routing page;
[0030] Parse the index.json file of the routing page to obtain component information of the routing page.
[0031] Preferably, the process of injecting corresponding components into the routing page according to the component information of the routing page includes:
[0032] According to the component information of the routing page, determine whether the routing page contains a custom component;
[0033] If so, the custom component is injected into the index.js file of the routing page through the abstract syntax tree AST.
[0034] Preferably, the process of converting the life cycle of the routing page into the application-level life cycle and the life cycle of the Vue syntax includes:
[0035] According to the preset correspondence between the life cycle of the routing page and the application-level life cycle, and according to the correspondence between the life cycle of the routing page and the life cycle of the Vue syntax, the life cycle of the routing page is converted into the corresponding application-level life cycle and the life cycle of the Vue syntax.
[0036] Preferably, the file types of the source files include html, css, js and json file types.
[0037] A second aspect of the present application provides a small program development device, including:
[0038] A construction unit, configured to insert parameter configuration into a predefined engineering template to generate an engineering project, wherein the engineering template is created based on a predefined file structure relationship, a file format, and a common syntax;
[0039] A conversion unit, used to parse the engineering project and convert it according to preset common grammar rules to generate an entry file and routing configuration information that conforms to the common grammar rules;
[0040] An injection unit, used for injecting the library and / or global configuration that the engineering project depends on into the entry file to obtain a processed entry file;
[0041] A synthesis unit is used to generate a mini-program application based on the processed entry file and the routing configuration information.
[0042] Through the above technical solution, it can be known that the present application defines the project template through the pre-designed file structure relationship, file format and common syntax. The project created based on the project template has a directory system with the same file structure, and its code files use the same file format and are constrained by the same common syntax, so that the structure of the project is clear and simple, and follows a unified development style, with high maintainability.
[0043] In addition, the project is parsed and converted according to the preset public grammar rules to generate the entry file and routing configuration information that conform to the preset public grammar rules; then the library and / or global configuration that the project depends on is injected into the entry file; finally, the mini-program application is assembled and packaged. This development process only relies on the preset public grammar rules, without customized private grammar, which reduces the learning cost of developers. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0045] Figure 1 A schematic diagram of a method for developing a small program disclosed in an embodiment of the present application;
[0046] Figure 2 The file structure of the engineering project disclosed in the embodiment of the present application is illustrated;
[0047] Figure 3 The template of the package.json file disclosed in the embodiment of this application is illustrated;
[0048] Figure 4 The processed package.json file disclosed in the embodiment of the present application is illustrated;
[0049] Figure 5 A schematic diagram of a mini-program development device disclosed in an embodiment of the present application;
[0050] Figure 6 This is a hardware structure block diagram of the mini-program development device disclosed in the embodiment of this application. DETAILED DESCRIPTION
[0051] For the purpose of reference and clarity, the descriptions, abbreviations or acronyms of the technical terms used below are summarized as follows:
[0052] Vue: is a progressive framework for building user interfaces;
[0053] AST: Abstract Syntax Tree (AST), is a tree representation of the abstract syntax structure of a source code, specifically the source code of a programming language;
[0054] html: Hypertext Markup Language is a markup language that defines the meaning and structure of web page content. Other technologies besides HTML are usually used to describe the performance and display effects (such as CSS) or functions and behaviors (such as JavaScript) of a web page;
[0055] js: JavaScript, a lightweight, interpreted or just-in-time compiled web programming language with function-first approach;
[0056] css: Cascading Style Sheets (CSS) is a style sheet language used to describe the presentation of HTML or XML (including XML branch languages such as SVG, MathML, and XHTML) documents;
[0057] json: is a syntax rule used to serialize objects, arrays, numbers, strings, Boolean values, and null.
[0058] 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 only 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.
[0059] Before describing the technical solution of the present application, the development environment and application environment of the mini program development method of the present application are briefly introduced. According to the mini program development method of the present application, developers can develop on computers based on iMac, Windows, or Linux operating systems. After the development is completed, the output finished package (i.e., the mini program application) needs to run on a specific App client (including Android, iOS). The specific App client refers to an App client that has been connected to an SDK that complies with the specifications of this mini program and has the basic environment for the mini program to run.
[0060] See also Figure 1 The mini-program development method provided in this application may include the following steps:
[0061] Step S100: creating a project based on a predefined project template.
[0062] Specifically, the parameter configuration is inserted into a predefined engineering template to generate an engineering project, wherein the engineering template is created based on a predefined file structure relationship, file format, and common syntax.
[0063] By pre-defining the file structure relationship, supported file formats, and common syntax of the project template, users do not need to add additional project compilation configuration files, routing configuration files, or platform compatibility configuration files when creating engineering projects.
[0064] In addition, the files included in the project can only include entry files, routing pages and custom components, making the structure of the entire project clearer and more concise.
[0065] The supported file formats may include one or more of html, js, json and css. To build a complete project, files with html, js and json syntax must be included. CSS files are used as page style description files and can be selected according to specific needs.
[0066] For the functional composition of files, the responsibilities of each file can be simplified to reduce complexity. For example, the organization of the page structure can be described by a file in html format, event binding and data-driven page dynamic change display can be described by a file in js format, the configuration of external components, the introduction of dependencies and the configuration of the navigation UI can be described by a file in json format, and the processing of page styles can be described by a file in css format.
[0067] For the supported public syntax, one or more public syntaxes can be included to avoid the learning cost of customized private syntaxes. For example, all syntax languages supported by W3C standards and ECMAScript specifications are supported.
[0068] In the later compilation and packaging stages of the project, the files that do not meet the requirements will be filtered and corresponding prompts will be given based on the above-defined file structure relationships, file formats and file syntax.
[0069] Step S200, generating an entry file and routing configuration information that conforms to common grammar rules.
[0070] Specifically, the engineering project in step S100 is parsed and converted according to preset common grammar rules to generate an entry file and routing configuration information that conforms to the common grammar rules.
[0071] Generally, entry files can include program entry files and page entry files. The program entry file is responsible for importing public files, adding global configurations, and instantiating specific objects; the page entry file includes the page root component, which is responsible for importing the required components and reserving display space for these components in specific pages through routing placeholders.
[0072] The routing configuration information includes routing pages and routing information between routing pages to achieve jumps between routing pages.
[0073] Step S300, completing dependency injection (Dependency Injection) and global configuration.
[0074] Specifically, for the entry file in the above step, this step can inject at least one of the libraries and global configurations that the engineering project depends on into the entry file to obtain a processed entry file.
[0075] Among them, through dependency injection, the processed entry file can realize the call of the dependent components; the global configuration is used to manage various APIs, constants and other objects in the engineering project. In addition, it can also adapt to changes in the project deployment environment.
[0076] Step S400, generate a mini program application.
[0077] Specifically, a mini-program application is generated based on the processed entry file in step S300 and the routing configuration information in step S200.
[0078] Through the above technical solution, it can be known that the mini-program development method provided in the embodiment of the present application defines the project template through a pre-designed file structure relationship, file format and common syntax. The project created based on the project template has a directory system with the same file structure, and its code files use the same file format and are constrained to the same common syntax, so that the structure of the project is clear and simple, and follows a unified development style, with high maintainability.
[0079] In addition, the project is parsed and converted according to the preset public grammar rules to generate the entry file and routing configuration information that conform to the preset public grammar rules; then the library and / or global configuration that the project depends on is injected into the entry file; finally, the mini-program application is assembled and packaged. This development process only relies on the preset public grammar rules, without customized private grammar, which reduces the learning cost of developers.
[0080] The following is a specific example to describe the process of creating a project in step S100. For a project template, the predefined file structure relationship is as follows: Figure 2 As shown, it includes entry files (app.js, app.json and app.css), project configuration file (project.config.json), page directory (pages), component directory (components) and package structure (package.json); the predefined file formats include js files, css files, json files and html files; the predefined public syntax specifications are W3C standards and ECMAScript specifications.
[0081] The public grammar rules mentioned in the above embodiments may adopt various types of public grammars such as W3C, ECMAScript, and Vue grammar based thereon. The following only takes Vue grammar rules as an example to introduce the process of creating an engineering project.
[0082] Vue is a progressive framework for building user interfaces that is easy to integrate with third-party libraries or existing projects. In addition, when used in conjunction with a modern tool chain and a variety of supporting libraries, Vue can drive complex single-page applications.
[0083] Among them, Vue.js uses HTML-based template syntax, allowing developers to declaratively bind DOM to the data of the underlying Vue instance. All Vue.js templates are legal HTML, so they can be parsed by browsers and HTML parsers that follow the specification.
[0084] Assume that a project named Test is created based on the Vue framework. The framework will use the create(projectName,options) function to read the file structure of the project template, obtain the directory under the file result, traverse the files and file contents under the directory, and output the mapping between the file name and the file content. Figure 2 shown.
[0085] Next, read the package.json file, recombining the project name Test, the project's preset dependency information, the execution script data, and the package.json file in the project template to generate a new package.json file. Figure 3 This example shows the contents of the package.json file in the project template. Figure 4 The example shows a new package.json file that is combined to write the project name, inject the execution command, and dependencies.
[0086] According to the context of the command execution, get the directory created by the current project, and write the data traversed by the above template into the directory according to the corresponding relationship read.
[0087] In the above step S200, there may be multiple methods to generate an entry file that complies with the common grammar rules. Based on this, in an optional embodiment, the process of parsing the engineering project in the above step S200 and converting it according to the preset common grammar rules to generate an entry file that complies with the common grammar rules may include:
[0088] A1, analyze the project and obtain the original entry file;
[0089] A2: Convert the lifecycle of the original entry file according to the conversion rules of Vue syntax and lifecycle, and inject the application-level lifecycle to generate an entry file that complies with the Vue syntax rules.
[0090] Specifically, A1 parses the app.js file of the project. The life cycle in the original development code of the app.js file is the Vue life cycle. According to the defined correspondence between the Vue life cycle and the mini-program life cycle, the life cycle of app.js is converted and injected into the application-level life cycle. The processed app.js file is used as the entry file for mini-program registration.
[0091] In A1 above, the engineering project can be parsed by the following function:
[0092]
[0093] Among them, compiler is a module of webpack. The compiler is passed into the apply method, and then the compiler object can be used in the apply method to monitor various events triggered by webpack at different times. In this solution, the run, watchRun and compilation hook functions are executed in the apply method. this.name is the custom plug-in name, and this._setConfig.bind() is a custom function for processing and parsing project configuration.
[0094] The above functions are used to parse the HTML, CSS, JS, and JSON configuration files in the project so that they can be processed accordingly according to different file types in the next step.
[0095] In A2 above, first, the original entry file can be parsed by the following function and processed into an entry file that conforms to Vue syntax:
[0096]
[0097] The entryLoader method receives the parsed file content, and the sourceMap parameter is used to map the actual code. In the entryLoader method, the addDependency() method injects the configuration file for file monitoring in the next stage of processing. The appAST (the corresponding AST parsed by app.js) is edited through the babelTraverse method of babel.
[0098] Then, the life cycle is parsed and converted through the following functions:
[0099] ['onLaunch','onShow','onHide','onBeforeDestroy'].find(name=>name===property.key.name)? okLifecycle.push(property):Properties.push(property)
[0100] Among them, ['onLaunch', 'onShow', 'onHide', 'onBeforeDestroy'] are the preset mini-program application-level lifecycle function names. The find() method is used to parse and convert the mini-program lifecycle in the actual code according to the preset lifecycle function names.
[0101] In A2 above, by injecting the application-level lifecycle, the problem of lack of native application-level lifecycle when developing H5 pages with Vue is solved. The application-level lifecycle is expanded on the basis of Vue. In addition to using the Vue lifecycle, developers can also use the application lifecycle function to handle business during development.
[0102] Specifically, the above-mentioned method for extending the application-level lifecycle can be: during the compilation phase, an SDK for calling client capabilities is injected into the mini-program, and the SDK can enable the mini-program to have the capabilities of native applications and lifecycle monitoring and processing capabilities. At the same time, the application-level lifecycle functions in the original code developed are identified by keywords, and then processed into lifecycle methods that can be identified in the SDK according to the defined mapping relationship.
[0103] In the above step S200, there may be multiple methods to generate routing configuration information that conforms to the common grammar rules. Based on this, in an optional embodiment, the process of parsing the engineering project in the above step S200 and converting it according to the preset common grammar rules to generate routing configuration information that conforms to the common grammar rules may include:
[0104] B1, analyzing the project to obtain the original routing configuration information;
[0105] B2: convert the original routing configuration information according to the Vue grammar rules to generate routing configuration information that complies with the Vue grammar rules.
[0106] In addition, based on the above implementation, you can also inject mini-program navbar and other UI type processing methods into the beforeEach method before entering the routing page to achieve personalized display and conditional jump of the routing page.
[0107] In the above B1, the process of parsing the project to obtain the original routing configuration can be specifically implemented by the following function:
[0108]
[0109] Among them, babelParse() is used to parse the routing configuration string into AST, routerConfigString is the routing configuration string parameter, and sourceType is the conversion type; pages.forEach() traverses the routing page pages to obtain the configuration file path of the routing page.
[0110] Read the configuration data of app.json in the project, convert the configuration data of each page into the router configuration of Vue syntax, and then assemble the processed routing configuration with the entry file.
[0111] In the above B2, specifically, the original routing configuration information can be converted using the vue-router syntax rules to generate routing configuration information that complies with the vue-router syntax rules. Among them, vue-router is the official routing library provided by Vue and is part of the Vue ecosystem. It is deeply integrated with the core of Vue.js and is easy to build single-page applications.
[0112] In the above step S400, there may be multiple methods to generate a mini-program application. Based on this, in an optional embodiment, the process of generating a mini-program application according to the processed entry file and routing configuration information in the above step S400 may include:
[0113] The routing page corresponding to the routing configuration information is assembled into a mini-program page according to the routing configuration information, and the mini-program page and the processed entry file are packaged into a mini-program application.
[0114] There are multiple ways to implement the assembly of the mini-program. Optionally, the process of assembling the routing configuration information into the mini-program page may include:
[0115] C1, obtain the routing page according to the routing configuration information;
[0116] C2, parses the routing page and obtains the life cycle and component information of the routing page;
[0117] C3, converts the life cycle of the routing page into the application-level life cycle and the life cycle of the Vue syntax, and injects the corresponding components into the routing page according to the component information of the routing page to obtain the processed routing page;
[0118] C4, assembling the processed routing page into a single file conforming to the Vue syntax, and the single file conforming to the Vue syntax constitutes the mini program page.
[0119] There are multiple methods for obtaining the life cycle and component information of the routing page in C2. Optionally, the process of parsing the routing page in C2 to obtain the life cycle and component information of the routing page may include:
[0120] D1, parse the index.js file of the routing page to obtain the life cycle of the routing page;
[0121] D2, parse the index.json file of the routing page to obtain the component information of the routing page.
[0122] For example, in D1, the file content of the index.js file is read, the vue lifecycle and application-level lifecycle function names used in the file are obtained, and they are converted according to the preset corresponding relationship.
[0123] In D2, by parsing the index.json file in a routing page, the usingComponents content is obtained from the file, and the usingComponents content contains the used component information.
[0124] There are multiple ways to implement the injection of routing page components in C3. Optionally, in C3, the process of injecting corresponding components into the routing page according to the component information of the routing page may include:
[0125] E1, judging whether the routing page contains a custom component according to the component information of the routing page;
[0126] E2: If yes, the custom component is injected into the index.js file of the routing page through the abstract syntax tree AST.
[0127] Specifically, in E2, the injection of custom components can be achieved through the following functions:
[0128]
[0129]
[0130] The routerPageLoader() method is the same as the entryLoader method mentioned above, receiving the content data source of the routing page and the sourceMap of the actual code mapping. ExpressionStatement is a method provided by babel, which is used to convert the lifecycle functions in pageAST (the parsed AST corresponding to index.js in the routing page).
[0131] There are multiple ways to achieve the conversion of the life cycle of the routing page in C3. Optionally, the process of converting the life cycle of the routing page into the application-level life cycle and the life cycle of the Vue syntax in C3 may include:
[0132] According to the preset correspondence between the life cycle of the routing page and the application-level life cycle, and according to the correspondence between the life cycle of the routing page and the life cycle of the Vue syntax, the life cycle of the routing page is converted into the corresponding application-level life cycle and the life cycle of the Vue syntax.
[0133] Among them, the application-level life cycle and the Vue syntax life cycle together constitute the life cycle of the mini program.
[0134] Specifically, in the above C3, the conversion of the routing page life cycle can be achieved through the following functions:
[0135]
[0136] The mini-program development device provided in an embodiment of the present application is described below. The mini-program development device described below and the mini-program development method described above can be referenced to each other.
[0137] See also Figure 5 The mini-program development device provided in the embodiment of the present application may include:
[0138] A construction unit 11, configured to insert parameter configuration into a predefined engineering template to generate an engineering project, wherein the engineering template is created based on a predefined file structure relationship, file format and common syntax;
[0139] The conversion unit 12 is used to parse the engineering project and convert it according to the preset common grammar rules to generate an entry file and routing configuration information that conforms to the common grammar rules;
[0140] An injection unit 13 is used to inject the library and / or global configuration that the engineering project depends on into the entry file to obtain a processed entry file;
[0141] The synthesis unit 14 is used to generate a mini-program application according to the processed entry file and the routing configuration information.
[0142] In an optional embodiment, the process in which the conversion unit 12 parses the engineering project and converts it according to the preset common grammar rules to generate an entry file conforming to the common grammar rules may include:
[0143] Parsing the engineering project to obtain the original entry file;
[0144] The life cycle of the original entry file is converted according to the Vue syntax rules and life cycle conversion, and the application-level life cycle is injected to generate an entry file that conforms to the Vue public syntax rules.
[0145] In an optional embodiment, the process in which the conversion unit 12 parses the engineering project and converts it according to a preset common grammar rule to generate routing configuration information that complies with the common grammar rule may include:
[0146] The engineering project is parsed to obtain original routing configuration information;
[0147] The original routing configuration information is converted according to the Vue grammar rules to generate routing configuration information that complies with the Vue grammar rules.
[0148] In an optional embodiment, the process of generating the mini-program application according to the processed entry file and the routing configuration information by the synthesis unit 14 may include:
[0149] The routing page corresponding to the routing configuration information is assembled into a mini-program page according to the routing configuration information, and the mini-program page and the processed entry file are packaged into a mini-program application.
[0150] In an optional embodiment, the process of assembling the routing configuration information into a mini-program page by the composing unit 14 may include:
[0151] According to the routing configuration information, obtain a routing page;
[0152] Parse the routing page to obtain the life cycle and component information of the routing page;
[0153] Convert the life cycle of the routing page to the application-level life cycle and the Vue syntax life cycle, and inject the corresponding components into the routing page according to the component information of the routing page to obtain the processed routing page;
[0154] The processed routing pages are assembled into a single file that conforms to the Vue syntax, and the single file that conforms to the Vue syntax constitutes the mini program page.
[0155] In an optional embodiment, the process in which the synthesis unit 14 parses the routing page to obtain the life cycle and component information of the routing page may include:
[0156] Parse the index.js file of the routing page to obtain the life cycle of the routing page;
[0157] Parse the index.json file of the routing page to obtain component information of the routing page.
[0158] In an optional embodiment, the process of the synthesis unit 14 injecting corresponding components into the routing page according to the component information of the routing page may include:
[0159] According to the component information of the routing page, determine whether the routing page contains a custom component;
[0160] If so, the custom component is injected into the index.js file of the routing page through the abstract syntax tree AST.
[0161] In an optional embodiment, the process in which the synthesis unit 14 converts the life cycle of the routing page into the application-level life cycle and the life cycle of the Vue syntax may include:
[0162] According to the preset correspondence between the life cycle of the routing page and the application-level life cycle, and according to the correspondence between the life cycle of the routing page and the life cycle of the Vue syntax, the life cycle of the routing page is converted into the corresponding application-level life cycle and the life cycle of the Vue syntax.
[0163] Among them, the application-level life cycle and the Vue syntax life cycle together constitute the life cycle of the mini program.
[0164] The mini-program development device provided in the embodiment of the present application can be applied to mini-program development device equipment, such as industrial computers, etc. Optionally, Figure 6 The hardware structure diagram of the small program development device is shown in FIG. Figure 3 The hardware structure of the applet development device may include: at least one processor 21, at least one communication interface 22, at least one memory 23 and at least one communication bus 24.
[0165] In the embodiment of the present application, the number of the processor 21, the communication interface 22, the memory 23, and the communication bus 24 is at least one, and the processor 21, the communication interface 22, and the memory 23 communicate with each other through the communication bus 24;
[0166] The processor 21 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application;
[0167] The memory 23 may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory;
[0168] The memory 23 stores a program, and the processor 21 can call the program stored in the memory 23, and the program is used to:
[0169] Inserting the parameter configuration into a predefined project template to generate a project, wherein the project template is created based on a predefined file structure relationship, file format, and common syntax;
[0170] Parsing the engineering project and converting it according to preset common grammar rules to generate an entry file and routing configuration information that conforms to the common grammar rules;
[0171] Injecting the library and / or global configuration that the project depends on into the entry file to obtain a processed entry file;
[0172] Generate a mini-program application according to the processed entry file and the routing configuration information.
[0173] Optionally, the detailed functions and extended functions of the program may refer to the above description.
[0174] In summary:
[0175] The embodiment of the present application defines the project template through a pre-designed file structure relationship, file format and common syntax. The project created based on the project template has a directory system with the same file structure, and its code files use the same file format and are constrained to the same common syntax, so that the structure of the project is clear and simple, and follows a unified development style, with high maintainability.
[0176] In addition, the project is parsed and converted according to the preset public grammar rules to generate the entry file and routing configuration information that conform to the preset public grammar rules; then the library and / or global configuration that the project depends on is injected into the entry file; finally, the mini-program application is assembled and packaged. This development process only relies on the preset public grammar rules, without customized private grammar, which reduces the learning cost of developers.
[0177] Furthermore, the mini-program application developed by this application has a low dependence on the host App. For apps of various platforms that have access to the mini-program development specification SDK that complies with this application, the mini-program developed by this application can be deployed to the host App of these platforms. Once developed, it can be reused on multiple platforms, realizing the interoperability and compatibility of mini-program applications with multiple platforms.
[0178] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article 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, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0179] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can refer to each other.
[0180] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for developing a small program, characterized in that: include: Inserting the parameter configuration into a predefined project template to generate a project, wherein the project template is created based on a predefined file structure relationship, file format, and common syntax; The engineering project is parsed and converted according to preset common grammar rules to generate an entry file and routing configuration information that conform to the common grammar rules; specifically, the process of parsing the engineering project and converting according to preset common grammar rules to generate an entry file that conforms to the common grammar rules includes: Parsing the engineering project to obtain the original entry file; The life cycle of the original entry file is converted according to the conversion rules of Vue syntax and life cycle, and the application-level life cycle is injected to generate an entry file that conforms to the Vue syntax rules; Injecting the library and / or global configuration that the project depends on into the entry file to obtain a processed entry file; Generate a mini-program application according to the processed entry file and the routing configuration information.
2. The method according to claim 1, characterized in that The process of parsing the engineering project and converting it according to preset common grammar rules to generate routing configuration information that complies with the common grammar rules includes: Parsing the engineering project to obtain original routing configuration information; The original routing configuration information is converted according to the Vue grammar rules to generate routing configuration information that complies with the Vue grammar rules.
3. The method according to claim 1, characterized in that The process of generating a mini-program application according to the processed entry file and the routing configuration information includes: The routing page corresponding to the routing configuration information is assembled into a mini-program page according to the routing configuration information, and the mini-program page and the processed entry file are packaged into a mini-program application.
4. The method according to claim 3, characterized in that The process of assembling the routing configuration information into a mini-program page includes: According to the routing configuration information, obtain a routing page; Parse the routing page to obtain the life cycle and component information of the routing page; Convert the life cycle of the routing page to the application-level life cycle and the Vue syntax life cycle, and inject the corresponding components into the routing page according to the component information of the routing page to obtain the processed routing page; The processed routing pages are assembled into a single file that conforms to the Vue syntax, and the single file that conforms to the Vue syntax constitutes the mini program page.
5. The method according to claim 4, characterized in that The process of parsing the routing page and obtaining the life cycle and component information of the routing page includes: Parse the index.js file of the routing page to obtain the life cycle of the routing page; Parse the index.json file of the routing page to obtain component information of the routing page.
6. The method according to claim 4, characterized in that The process of injecting corresponding components into the routing page according to the component information of the routing page includes: According to the component information of the routing page, determine whether the routing page contains a custom component; If so, the custom component is injected into the index.js file of the routing page through the abstract syntax tree AST.
7. The method according to claim 4, characterized in that The process of converting the life cycle of the routing page to the application-level life cycle and the life cycle of Vue syntax includes: According to the preset correspondence between the life cycle of the routing page and the application-level life cycle, and according to the correspondence between the life cycle of the routing page and the life cycle of the Vue syntax, the life cycle of the routing page is converted into the corresponding application-level life cycle and the life cycle of the Vue syntax.
8. The method according to any one of claims 1 to 7, characterized in that The file types of source files include html, css, js and json file types.
9. A small program development device, characterized in that: include: A construction unit, configured to insert parameter configuration into a predefined engineering template to generate an engineering project, wherein the engineering template is created based on a predefined file structure relationship, a file format, and a common syntax; The conversion unit is used to parse the engineering project and convert it according to the preset common grammar rules to generate an entry file and routing configuration information that conform to the common grammar rules; specifically, the process of parsing the engineering project and converting it according to the preset common grammar rules to generate an entry file that conforms to the common grammar rules includes: Parsing the engineering project to obtain the original entry file; The life cycle of the original entry file is converted according to the conversion rules of Vue syntax and life cycle, and the application-level life cycle is injected to generate an entry file that conforms to the Vue syntax rules; An injection unit, used for injecting the library and / or global configuration that the engineering project depends on into the entry file to obtain a processed entry file; A synthesis unit is used to generate a mini-program application based on the processed entry file and the routing configuration information.
