Automatic code file copying method and device based on Taro, equipment and medium
By receiving packaging instructions and automatic packaging and copying of custom Taro plug-ins, the problems of manual copying of code files in mini program development are solved, and efficient code file storage is achieved.
Patent Information
- Application Number
- CN202411078204.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-07
- Publication Date
- 2024-12-27
AI Technical Summary
During the development of mini-programs, manually copying compiled code files to the corresponding directory is prone to errors and inefficient, especially because the cross-end development of Taro framework requires manual packaging, copying, uploading and deployment, which makes it time-consuming and easy An error occurred.
By receiving packaging instructions, the code files are automatically packaged and copied using the custom Taro plug-in, the copy files are generated, and the file name and path information is stored in the program code directory of the project directory, improving the copy efficiency.
It realizes automatic packaging and copying of code files, reduces the error rate and time-consuming of manual operations, improves the replication efficiency, and ensures accurate storage of code files.
Smart Images

Figure CN119201091A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software development, and in particular to a Taro-based code file automatic copying method, device, equipment and medium. Background Art
[0002] In the field of software development, with the widespread popularity of mini-programs, in the existing mini-program development process, although the Taro framework provides cross-end development capabilities, there are still a series of operations that need to be manually performed, such as packaging, copying, uploading, and deployment. For example, the compiled mini-program code needs to be copied to the corresponding mini-program directory, which is not only labor-intensive and time-consuming, but also due to the large number of mini-program types, manual execution can easily lead to copying errors and low copying efficiency. Summary of the invention
[0003] The embodiments of the present invention provide a Taro-based automatic code file copying method, device, equipment and medium to solve the problem in the prior art that manually copying the compiled mini-program code to the corresponding mini-program directory is prone to errors and has low efficiency.
[0004] A Taro-based code file automatic copying method, comprising:
[0005] Receive a packaging instruction, package all code files in the Taro code directory under the project directory into package files according to the variable script, command script and code compilation script in the packaging instruction, and store each package file in a preset directory under the Taro code directory;
[0006] When it is detected that all the code files have been packaged, all the packaged files in the preset directory are copied by using the path information in the custom Taro plug-in to obtain copy files corresponding to each packaged file;
[0007] All the copied files are stored in the corresponding program code directory under the project directory according to the file name of each copied file and the path information; wherein the file name is generated according to the variable value in the packaging instruction.
[0008] A Taro-based code file automatic copying device, comprising:
[0009] A file packaging module, for receiving a packaging instruction, packaging all code files in the Taro code directory under the project directory into packaging files according to the variable script, command script and code compilation script in the packaging instruction, and storing each of the packaging files in a preset directory under the Taro code directory;
[0010] A file copying module, for copying all the packaged files in the preset directory by using the path information in the custom Taro plug-in when it is detected that all the code files have been packaged, to obtain copy files corresponding to each packaged file;
[0011] A file storage module is used to store all the copied files in the corresponding program code directory under the project directory according to the file name of each copied file and the path information; wherein the file name is generated according to the variable value in the packaging instruction.
[0012] A computer device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor is used to execute the above-mentioned Taro-based automatic code file copying method.
[0013] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the automatic code file copying method based on Taro is implemented.
[0014] The above-mentioned Taro-based automatic code file copying method, device, equipment and medium, the Taro-based automatic code file copying method of the present invention includes receiving a packaging instruction, packaging all code files in the Taro code directory under the project directory into packaged files, and storing each packaged file in a preset directory under the Taro code directory; when it is monitored that all the code files have completed packaging, all the packaged files in the preset directory are copied through a custom Taro plug-in to obtain copy files corresponding to each packaged file; according to the file name of each copy file, all the copy files are stored in the corresponding program code directory under the project directory; wherein, the file name is generated according to the variable value in the packaging instruction.
[0015] The present invention realizes automatic packaging of all code files through packaging instructions, thereby realizing storage of packaged files. Through customizing Taro plug-ins, automatic copying of all packaged files is realized, and the acquisition of copied files is realized, so that the copied files are stored in the corresponding program code directory under the project directory, thereby improving the copying efficiency of packaged files. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0017] Figure 1 is a flow chart of a method for automatically copying code files based on Taro in one embodiment of the present invention;
[0018] Figure 2 is a flowchart of step S10 of the Taro-based code file automatic copying method in one embodiment of the present invention;
[0019] Figure 3 is a flowchart of step S20 of the Taro-based code file automatic copying method in one embodiment of the present invention;
[0020] Figure 4 is a flowchart of step S20 of the Taro-based code file automatic copying method in another embodiment of the present invention;
[0021] Figure 5 is a flowchart of step S201 of the Taro-based code file automatic copying method in one embodiment of the present invention;
[0022] Figure 6 is a flowchart of step S202 of the Taro-based code file automatic copying method in one embodiment of the present invention;
[0023] Figure 7 is a flowchart of step S206 of the Taro-based code file automatic copying method in one embodiment of the present invention;
[0024] Figure 8 It is a principle block diagram of a Taro-based code file automatic copying device in one embodiment of the present invention;
[0025] Fig. 9 is a schematic diagram of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION
[0026] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0027] In one embodiment, if Figure 1As shown, a method for automatically copying code files based on Taro is provided, comprising the following steps:
[0028] S10: receiving a packaging instruction, packaging all code files in the Taro code directory under the project directory into packaging files according to the variable script, command script and code compilation script in the packaging instruction, and storing each packaging file in a preset directory under the Taro code directory.
[0029] Understandably, packaging instructions refer to commands used to compile and package files or data. Project directory refers to the project directory of the applet, which is used to organize and store the directory structure of project files, codes, documents, resources, etc., such as work_mp. Taro code directory refers to the file directory structure of the project when using the Taro framework for multi-terminal development. The preset directory refers to the directory where the code files generated after the Taro project is compiled are stored. It can be the dist directory or other pre-set directories.
[0030] Specifically, the front-end project runs on the VSCode development tool, opens the terminal of the VSCode tool, manually enters the packaging instruction, and after receiving the packaging instruction, parses the packaging instruction to obtain the variable script, command script and code compilation script in the packaging instruction. The corresponding compilation platform type is determined by the variable script, such as weapp, i.e. WeChat, and the environment variable (wherein the variable name is APP_NAME) and the variable value (weapp-xxx) are set by the cross-env command of the variable script in the packaging instruction. Then, the command script is run to configure the project, so that the code that does not belong to the compilation platform type will be removed during compilation, and only the code under the compilation platform type will be retained. Then, all code files are compiled by the code compilation script of the Taro framework, so as to obtain the applet corresponding to the environment variable. Finally, all code files in the Taro code directory under the project directory are packaged as package files, wherein the names of the package files of different environments are different. After packaging is completed, a preset directory is generated in the Taro code directory under the project directory, and all packaged files are stored in the packaged product files in the preset directory under the Taro code directory. The file name is named after the xxx in the variable value, that is, all packaged products are stored in the preset directory under the Taro code directory with different file names, for example, XXX program, YYY program, etc.
[0031] S20: When it is detected that all the code files have been packaged, all the packaged files in the preset directory are copied by using the path information in the custom Taro plug-in to obtain copy files corresponding to each packaged file.
[0032] S30: storing all the copied files in a corresponding program code directory under the project directory according to the file name of each copied file and the path information; wherein the file name is generated according to the variable value in the packaging instruction.
[0033] Understandably, a custom Taro plugin refers to a script used to copy packaged files. A copied file is a copy of a file created in the program code directory that is exactly the same as the original file content. The copy is stored in a different location from the original file, but contains exactly the same data as the original file. The file name is generated based on the variable value in the packaging instruction. The program code directory refers to the directory structure corresponding to each packaged product under the project directory, such as the XXX program code directory.
[0034] Specifically, the packaging event is monitored through the packaging completion event, that is, the onBuildFinish event hook function of Taro. When it is monitored that all code files have completed packaging, the copy instruction is triggered, the custom Taro plug-in is called, and all packaged files in the preset directory are copied through the path information in the custom Taro plug-in, that is, the custom Taro plug-in identifies the name of the applet in the copy instruction, and then, through the path information of the packaged file and the applet name, all packaged files corresponding to the applet name are queried in the preset directory. Then, the packaged files corresponding to each applet are copied respectively, so as to obtain the copied files corresponding to each packaged file. Further, the file name of each copied file is parsed to determine the corresponding packaging program, and then the copied file is moved to the corresponding program code directory under the project directory through the path information for storage. Among them, the copied files of the programs in different environments of the same code file are stored in the same program code directory.
[0035] In a specific embodiment, the project directory includes a XXX program code directory and a YYY program code directory. The preset directory includes a packaged file after packaging the XXX applet and a packaged file after packaging the YYY applet. The custom Taro plug-in searches and copies the two packaged files through the path information to obtain a copy file, and then stores the copy file in the corresponding program code directory under the project directory through the storage path in the path information, that is, the copied file of the XXX applet is stored in the XXX program code directory, and the copied file of the YYY applet is stored in the YYY program code directory.
[0036] In the automatic code file copying method based on Taro of the present invention, all code files are automatically packaged through packaging instructions, thereby realizing the storage of packaged files. By customizing the Taro plug-in, all packaged files are automatically copied, and the copied files are obtained, so that the copied files are stored in the corresponding program code directory under the project directory, thereby improving the copying efficiency of the packaged files.
[0037] In one embodiment, if Figure 2 As shown, in step S10, all code files in the Taro code directory under the project directory are packaged into package files, including:
[0038] S101, setting environment variables and variable values corresponding to the environment variables according to the variable script in the packaging instruction; the environment variables are used to determine the running environment of the code file.
[0039] S102, determining a packaging path of the directory where all the code files corresponding to the environment variable are located according to the command script in the packaging instruction.
[0040] S103, compiling all the code files corresponding to the packaging path through the code compilation script in the packaging instruction to obtain the mini-program to be packaged corresponding to the variable value.
[0041] S104, packaging all the mini-programs to be packaged in the Taro code directory under the project directory through the packaging path to obtain packaging files corresponding to each of the code files.
[0042] Understandably, environment variables are information used to store the operating environment in the Taro code directory. The variable value refers to the name used to identify or describe the operating environment of a specific application, such as WeChat or Douyin. The mini program to be packaged refers to the program that converts the code file into a program corresponding to the variable value. The packaged file refers to one or more code files compressed into a compressed file, which is the final product ready to be deployed to the operating environment.
[0043] Specifically, the front-end project runs on the VSCode development tool. Open the terminal of the VSCode tool, manually enter the packaging instruction and send it. After receiving the packaging instruction, parse the packaging instruction to obtain the variable script, command script and code compilation script. Set the environment variables, variable names and variable values through the variable script, that is, set the environment variables according to cross-env, that is, set the environment variables to APP_NAME=weapp-xxx, and identify the variable names and variable values in the environment variables. Then, determine the packaging path of the directory where all code files are located through the command script in the packaging instruction, that is, run npm run set, determine the path of the directory where all code files are located through the set script, and determine the path as the packaging path. Next, compile the code files through the code compilation script in the packaging instruction, that is, convert the code files into small programs to be packaged that meet the environment variable operation through Tarobuild--type weapp--blended. Furthermore, all the mini-programs to be packaged in the Taro code directory under the project directory are packaged through the packaging path, that is, the location of the mini-programs to be packaged is determined through the packaging path, and the converted mini-programs to be packaged are compiled and packaged to obtain the packaging files corresponding to each code file.
[0044] In this embodiment, through the packaging instructions, the environment variables and variable values are set, the packaging path is determined, and the code files are converted into small programs to be packaged that are suitable for the environment, thereby realizing automatic packaging of all code files.
[0045] In one embodiment, if Figure 3 As shown, in step S20, all the packaged files in the preset directory are copied by a custom Taro plug-in to obtain copy files corresponding to each packaged file, including:
[0046] S201, parsing command line parameters in the environment variable to obtain an original parameter array, and obtaining other parameters except the first original parameter from the original parameter array.
[0047] S202, determining an execution command according to a first parameter among all the other parameters, and setting a program directory name and an output directory name according to the execution command.
[0048] S203, obtaining an absolute path corresponding to the parent directory of the directory where the packaged file is located, determining a root path corresponding to the parent directory according to the absolute path, and determining an access path for the packaged file according to the program directory name and the root path.
[0049] S204, determining an output file path according to the output directory name and the absolute path;
[0050] S205, initializing a target path according to the access path, and detecting whether the target path exists. If the target path already exists, deleting all files under the target path.
[0051] S206, copying all the packaged files from the output file path to the program code directory corresponding to the target path to obtain a copied file.
[0052] Understandably, a copy script refers to a program used to automatically copy files or data. The original parameter array refers to a collection of command line parameters, which usually contains all the commands and options entered by the user when executing the npm script. The execution command refers to the task that needs to be performed. The access path refers to the path information of the location of the copy package file. The output file path is the path information of the output copied file. The target path refers to the path information used to point to the storage of the copied file.
[0053] Specifically, add a copy script to the preset directory, that is, add a plugin-copy.js. Then, get the environment variable and parse the npm command line parameters in the environment variable, that is, parse the command line parameters passed by the environment variable Taro_ENV.npm_config_argv to get the original parameter array. Delete the first parameter in the original parameter array to get other parameters except the first original parameter. Read the first parameter among other parameters, and determine the task to be executed according to the value of the first parameter, that is, execute the command. Check whether there is a specific string in the execution command. If it exists, set the program directory name and output directory name according to the string. Next, get the absolute path corresponding to the parent directory of the directory where the packaged file is located (that is, dirname, a global variable, indicating the directory where the packaged file is located), and traverse two levels upward in the absolute path through the path.resolve function to get the root path. For example, if the packaged file is located in the / projects / my-app / Taro-plugin directory, the path.resolve function will return / projects / my-app. The program directory name and the root path are processed by the path.join function, that is, the root path and the program directory name are connected to form a complete path pointing to the mini-program directory, so as to obtain the complete access path of the packaged file location. For example, if the root path is / projects / my-app and the program directory name is weapp, the access path is / projects / my-app / weapp. Further, the output directory name and the absolute path are processed by the path.resolve function, that is, the path.resolve function takes the absolute path and the output directory name as parameters to generate an output path, so as to obtain the output file path. Then, the target path is initialized according to the access path, that is, the access path and taro in the program code directory are spliced together to form a new path, which points to the taro subdirectory under the miniappPath directory. For example, if miniappPath is / users / example / miniapp, then after executing this line of code, destPath will be / users / example / miniapp / taro. Next, the fs.existsSync function is used to detect whether the target path exists, that is, to detect whether there is a path used to point to the program code directory under the project directory. If it exists, determine if the target path already exists. If the target path already exists, delete all the last packaged files under the target path.Finally, all packaged files are copied from the preset directory corresponding to the output file path to the program code directory corresponding to the target path, that is, all packaged files are copied from the output file path to the target path through the copySync function, thereby obtaining copy files corresponding to each packaged file.
[0054] In this embodiment, the automatic copying of all packaged files and the acquisition of copied files are realized by customizing the Taro plug-in, so that the copied files are stored in the program code directory, thereby improving the efficiency of file copying.
[0055] In one embodiment, if Figure 4 As shown, in the step S20, that is, before detecting whether there is a target path, the step further includes:
[0056] S207: Determine the environment type corresponding to each of the packaged files according to the variable value corresponding to the environment variable.
[0057] S208: When the environment type is a target type, a target path corresponding to the target type is set according to the access path and the program code directory.
[0058] Understandably, the environment type refers to the environment in which the program runs, such as WeChat, Douyin, Baidu, etc. The target path is used to store the path information of the copied file in the program code directory under the project directory. The variable value refers to the value of the environment variable. The program code directory path refers to the path information for accessing the program code directory. The target type refers to the environment type set in advance, such as WeChat, Douyin, Baidu, etc.
[0059] Specifically, the environment variable Taro_env is detected to determine the value corresponding to the environment variable, that is, the variable value. Then, the type corresponding to the variable value is determined as the environment type corresponding to each packaged file, for example, h5 corresponds to the H5 page, weapp corresponds to WeChat, swan corresponds to Baidu, qq corresponds to QQ, etc. Further, the target type is obtained, and the environment type and the target type are matched to determine whether the environment type is the target type. When the environment type is the target type, the access path and the program code directory are obtained, and then the complete access path of the packaged file location and the program code directory for storing the copied file are connected through the path.join function, that is, path.join (access path, program code directory), so as to obtain the target path.
[0060] In this embodiment, the running environment of the packaged file is determined by the variable value, and the environment type is determined. The target path is set by the access path and the program code directory path.
[0061] In one embodiment, if Figure 5 As shown, in step S201, that is, parsing the command line parameters in the environment variables to obtain the original parameter array, including:
[0062] S2011, parsing the argv object in the npm command line parameter of the environment variable to obtain the original properties in the argv object.
[0063] S2012, parsing the original attributes in the argv object to obtain an original parameter array containing at least one original command line parameter.
[0064] Understandably, the original attribute refers to the original attribute in the argv object.
[0065] Specifically, the environment variable, Taro_ENV.npm_config_argv, is obtained, and then the argv object in the npm command line parameter of the environment variable is parsed, that is, the JSON string in the argv object is parsed into a JavaScript object or array through the JSON.parse function, and stored in the argv constant, thereby obtaining the original attributes in the argv object. Further, the original attributes in the argv object are parsed, that is, the original attribute is taken out from the argv object, and the value of the original attribute (usually an array containing all commands and options entered by the user when executing the npm script) is stored in a preset constant, which contains the original parameter list of the npm command, so that the original parameter array containing at least one original command line parameter can be obtained.
[0066] In this embodiment, by parsing the argv object in the npm command line parameter of the environment variable, the acquisition of the original attributes in the argv object is realized. By parsing the original attributes in the argv object, the acquisition of the original parameter array is realized, thereby facilitating the subsequent determination of the execution command.
[0067] In one embodiment, if Figure 6 As shown, in step S202, that is, determining the execution command according to the first parameter among all the other parameters, and setting the program directory name and the output directory name according to the execution command, including:
[0068] S2021: When the first parameter among the other parameters is a target command parameter, parse the target command parameter to obtain a target character string included in the target command parameter.
[0069] S2022: Setting a program directory name and an output directory name according to the target character string.
[0070] It can be understood that the target character string refers to a specific character string set in advance, for example, tt:xxx.
[0071] Specifically, when the first parameter obtained from other parameters is a target command parameter, the target command parameter is detected, that is, the string in the target command parameter is queried to determine whether the target command parameter contains the target string. When the target command parameter contains the target string, the target command parameter is parsed to obtain the target string, and then the program directory name and the output directory name are set according to the target string. Before setting the program directory name and the output directory name, the two defined variable string variables program directory name and output directory name are initialized so that the two directories are empty.
[0072] In a specific embodiment, if the target command parameter contains the string tt:xxx, the program directory name is set to 'xxx_tt, and the output directory name is set to .. / dist / tt / xxx. If the target command parameter contains the string tt:yyy, the program directory name is set to yyy_tt, and the output directory name is set to .. / dist / tt / yyy. If the target command parameter contains the string weapp:xxx, the program directory name is set to xxx_mp, and the output directory name is set to .. / dist / weapp / xxx. If the target command parameter contains the string swan:xxx, the program directory name is set to xxx_mp, and the output directory name is set to .. / dist / swan / xxx.
[0073] In this embodiment, by parsing the target command parameter, it is possible to detect whether the target command parameter contains the target string, thereby extracting the target string, and further setting the program directory name and the output directory name.
[0074] In one embodiment, if Figure 7 As shown, in step S206, all the packaged files are copied from the output file path to the program code directory corresponding to the target path, including:
[0075] S2061, using a preset copy function to copy all the packaged files in the preset directory corresponding to the output file path to the program code directory corresponding to each packaged file in the project directory corresponding to the target path.
[0076] S2062: After all the packaged files are copied, output a copy completion notification.
[0077] Understandably, the preset copy function refers to the copySync function, which is used to copy the packaged file.
[0078] Specifically, after deleting all files under the target path, obtain the preset copy function, and use the fs.copySync function to copy the packaged file from the preset directory corresponding to the output file path to the target path, that is, the preset copy function copies all packaged files in the preset directory through the output file path to obtain the copied file. And store all the copied files in the program code directory under the project directory corresponding to the target path through the target path, that is, according to the file name of the copied file, store each copied file in the program code directory corresponding to the file name of the copied file under the project directory, and name the folder of the copied file stored in the program code directory Taro.
[0079] In this embodiment, the automatic copying of the packaged file is achieved through the preset copy function, thereby copying the packaged file in the preset directory to the corresponding program code directory, and further realizing the notification of the copy completion event.
[0080] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0081] In one embodiment, a Taro-based automatic code file copying device is provided, and the Taro-based automatic code file copying device corresponds to the Taro-based automatic code file copying method in the above embodiment. Figure 8 As shown, the Taro-based code file automatic copying device includes a file packaging module 10, a file copying module 20 and a file storage module 30. The detailed description of each functional module is as follows:
[0082] A file packaging module 10 is used to receive a packaging instruction, package all code files in the Taro code directory under the project directory into package files according to the variable script, command script and code compilation script in the packaging instruction, and store each package file in a preset directory under the Taro code directory;
[0083] The file copying module 20 is used to copy all the packaged files in the preset directory by using the path information in the custom Taro plug-in when it is detected that all the code files have been packaged, so as to obtain copy files corresponding to each packaged file;
[0084] The file storage module 30 is used to store all the copied files in the corresponding program code directory under the project directory according to the file name of each copied file and the path information; wherein the file name is generated according to the variable value in the packaging instruction.
[0085] Optionally, the file packaging module 10 includes:
[0086] A variable value unit, used to set environment variables and variable values corresponding to the environment variables according to the variable script in the packaging instruction; the environment variables are used to determine the running environment of the code file;
[0087] A packaging path unit, used to determine the packaging path of the directory where all the code files corresponding to the environment variable are located according to the command script in the packaging instruction;
[0088] The small program unit to be packaged is used to compile all the code files corresponding to the packaging path through the code compilation script in the packaging instruction to obtain the small program to be packaged corresponding to the variable value;
[0089] The packaging processing unit is used to package all the mini-programs to be packaged in the Taro code directory under the project directory through the packaging path to obtain packaging files corresponding to each code file.
[0090] Optionally, the file copy module 20 includes:
[0091] The original parameter unit is used to parse the command line parameters in the environment variable to obtain the original parameter array, and obtain other parameters except the first original parameter from the original parameter array;
[0092] An execution command unit, used for determining an execution command according to a first parameter among all the other parameters, and setting a program directory name and an output directory name according to the execution command;
[0093] An access path unit, used to obtain an absolute path corresponding to a parent directory of the directory where the packaged file is located, determine a root path corresponding to the parent directory according to the absolute path, and determine an access path for the packaged file according to the program directory name and the root path;
[0094] An output file path unit, used to determine the output file path according to the output directory name and the absolute path;
[0095] A target path detection unit, used to initialize a target path according to the access path, and detect whether the target path exists, and if the target path already exists, delete all files under the target path;
[0096] The file copying unit is used to copy all the packaged files from the output file path to the program code directory corresponding to the target path to obtain a copy file.
[0097] Optionally, the file copy module 20 further includes:
[0098] An environment type unit, used to determine the environment type corresponding to each of the packaged files according to the variable value corresponding to the environment variable;
[0099] The target path setting unit is used to set a target path corresponding to the target type according to the access path and the program code directory when the environment type is the target type.
[0100] Optionally, the original parameter unit includes:
[0101] The environment variable parsing subunit is used to parse the argv object in the npm command line parameter of the environment variable to obtain the original properties in the argv object;
[0102] The original attribute parsing subunit is used to parse the original attributes in the argv object to obtain an original parameter array containing at least one original command line parameter.
[0103] Optionally, the command execution unit includes:
[0104] A target string subunit, used for parsing the target command parameter to obtain a target string included in the target command parameter when the first parameter among the other parameters is a target command parameter;
[0105] The directory name subunit is used to set the program directory name and the output directory name according to the target character string.
[0106] Optionally, the file copying unit includes:
[0107] A program code directory subunit is used to copy all the packaged files in the preset directory corresponding to the output file path to the program code directory corresponding to each packaged file under the project directory corresponding to the target path using a preset copy function;
[0108] The notification completion subunit is used to output a copy completion notification after all the packaged files are copied.
[0109] This application further provides Fig. 9A computer device is shown, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor is used to execute the Taro-based automatic code file copying method.
[0110] For the specific definition of computer equipment, processors and their units and modules, please refer to the definition of the automatic code file copying method based on Taro above, which will not be repeated here. Each module in the above-mentioned processor can be implemented in whole or in part by software, hardware and a combination thereof. It can be understood that the processor includes a processor, a memory, a network interface and a database connected by a device bus. Each module of the processor can be embedded in or independent of the processor in hardware form, or can be stored in the memory in software form, so that the processor can call and execute the operations corresponding to the above modules. Among them, the processor is used to provide computing and control capabilities. The memory includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating device, a computer program and a database. The internal memory provides an environment for the operation of the operating device and the computer program in the non-volatile storage medium. The database is used to store the data used by the automatic code file copying method based on Taro in the above-mentioned embodiment. The network interface is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for automatically copying code files based on Taro is implemented.
[0111] In one embodiment, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned Taro-based automatic code file copying method is implemented.
[0112] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0113] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0114] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. A method for automatically copying code files based on Taro, characterized in that: include: Receive a packaging instruction, package all code files in the Taro code directory under the project directory into package files according to the variable script, command script and code compilation script in the packaging instruction, and store each package file in a preset directory under the Taro code directory; When it is detected that all the code files have been packaged, all the packaged files in the preset directory are copied by using the path information in the custom Taro plug-in to obtain copy files corresponding to each packaged file; All the copied files are stored in the corresponding program code directory under the project directory according to the file name of each copied file and the path information; wherein the file name is generated according to the variable value in the packaging instruction.
2. The Taro-based automatic code file copying method according to claim 1, characterized in that: The step of packaging all code files in the Taro code directory under the project directory into packaged files according to the variable script, command script and code compilation script in the packaging instruction includes: Setting environment variables and variable values corresponding to the environment variables according to the variable script in the packaging instruction; the environment variables are used to determine the running environment of the code file; Determine the packaging path of the directory where all the code files corresponding to the environment variable are located according to the command script in the packaging instruction; Compile all the code files corresponding to the packaging path through the code compilation script in the packaging instruction to obtain the mini-program to be packaged corresponding to the variable value; All the mini-programs to be packaged in the Taro code directory under the project directory are packaged through the packaging path to obtain packaging files corresponding to each of the code files.
3. The Taro-based automatic code file copying method according to claim 1, characterized in that: The process of copying all the packaged files in the preset directory by using the path information in the custom Taro plug-in to obtain copy files corresponding to each packaged file includes: Parse the command line parameters in the environment variable to obtain an original parameter array, and obtain other parameters except the first original parameter from the original parameter array; Determine an execution command according to the first parameter among all the other parameters, and set a program directory name and an output directory name according to the execution command; Obtaining an absolute path corresponding to a parent directory of the directory where the packaged file is located, determining a root path corresponding to the parent directory according to the absolute path, and determining an access path for the packaged file according to the program directory name and the root path; Determine the output file path according to the output directory name and the absolute path; Initialize the target path according to the access path, and detect whether the target path exists. If the target path already exists, delete all files under the target path; All the packaged files are copied from the output file path to the program code directory corresponding to the target path to obtain copied files.
4. The Taro-based automatic code file copying method according to claim 3, characterized in that: Before detecting whether the target path exists, the method further includes: Determining the environment type corresponding to each of the packaged files according to the variable value corresponding to the environment variable; When the environment type is a target type, a target path corresponding to the target type is set according to the access path and the program code directory.
5. The Taro-based automatic code file copying method according to claim 3, characterized in that: The command line parameters in the environment variables are parsed to obtain the original parameter array, including: Parse the argv object in the npm command line parameter of the environment variable to obtain the original properties in the argv object; Parse the raw attributes in the argv object to obtain a raw argument array containing at least one raw command line argument.
6. The Taro-based automatic code file copying method according to claim 3, characterized in that: Determining the execution command according to the first parameter among all the other parameters, and setting the program directory name and the output directory name according to the execution command, includes: When the first parameter among the other parameters is a target command parameter, parsing the target command parameter to obtain a target character string included in the target command parameter; The program directory name and the output directory name are set according to the target string.
7. The Taro-based automatic code file copying method according to claim 3, characterized in that: The step of copying all the packaged files from the output file path to the program code directory corresponding to the target path includes: Copy all the packaged files in the preset directory corresponding to the output file path to the program code directory corresponding to each packaged file in the project directory corresponding to the target path using a preset copy function; After all the packaged files are copied, a copy completion notification is output.
8. A Taro-based code file automatic copying device, characterized in that: include: A file packaging module, for receiving a packaging instruction, packaging all code files in the Taro code directory under the project directory into packaging files according to the variable script, command script and code compilation script in the packaging instruction, and storing each of the packaging files in a preset directory under the Taro code directory; A file copying module, for copying all the packaged files in the preset directory by using the path information in the custom Taro plug-in when it is detected that all the code files have been packaged, to obtain copy files corresponding to each packaged file; A file storage module is used to store all the copied files in the corresponding program code directory under the project directory according to the file name of each copied file and the path information; wherein the file name is generated according to the variable value in the packaging instruction.
9. A computer device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor is used to execute the Taro-based automatic code file copying method according to any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method for automatically copying a code file based on Taro as described in any one of claims 1 to 7 is implemented.