CN113254405B - File conversion method, device, equipment and medium - Google Patents
File conversion method, device, equipment and medium Download PDFInfo
- Publication number
- CN113254405B CN113254405B CN202110609983.9A CN202110609983A CN113254405B CN 113254405 B CN113254405 B CN 113254405B CN 202110609983 A CN202110609983 A CN 202110609983A CN 113254405 B CN113254405 B CN 113254405B
- Authority
- CN
- China
- Prior art keywords
- file
- grammar
- sass
- target
- preset
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/16—File or folder operations, e.g. details of user interfaces specifically adapted to file systems
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/17—Details of further file system functions
- G06F16/178—Techniques for file synchronisation in file systems
- G06F16/1794—Details of file format conversion
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/903—Querying
- G06F16/90335—Query processing
- G06F16/90344—Query processing by using string matching techniques
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/20—Natural language analysis
- G06F40/253—Grammatical analysis; Style critique
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- Computational Linguistics (AREA)
- Audiology, Speech & Language Pathology (AREA)
- General Health & Medical Sciences (AREA)
- Health & Medical Sciences (AREA)
- Artificial Intelligence (AREA)
- Human Computer Interaction (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The application provides a file conversion method, a device, equipment and a medium, wherein the file conversion method comprises the following steps: identifying a target file from a preset catalog; converting the file content in the target file from the first grammar to the second grammar to obtain converted file content; and writing the converted file content back to the target file. In this embodiment, by automatically scanning all files under the preset directory, the target file to be converted can be automatically identified and automatically converted, so that repetitive work is reduced, the time consumption is short, and omission and errors are not easy to cause.
Description
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a medium for file conversion.
Background
Currently, sass (SYNTACTICALLY AWESOME STYLESHEETS, cascading style sheet language) is used as a preprocessor of cascading style sheets (CASCADING STYLE SHEETS, abbreviated as CSS) in many front-end projects, but in the Sass use process, the situation that the download NPM (Node PACKAGE MANAGER, node packet manager) depends on packet reporting errors is often encountered, so that the daily development efficiency is seriously affected, while another CSS preprocessor Less has the same function as Sass, but does not have the problem, so that the need of converting Sass to Less arises.
In the related art, a front-end developer needs to manually convert Sass into Less, and the manual conversion needs to do a great deal of repetitive work, so that a long time is consumed, and omission and errors are easily caused.
Disclosure of Invention
The application provides a file conversion method, a device, equipment and a medium.
An embodiment of a first aspect of the present application provides a file conversion method, including: identifying a target file from a preset catalog; converting the file content in the target file from a first grammar to a second grammar to obtain converted file content; and writing the converted file content back to the target file.
According to the file conversion method, the target file is identified from the preset catalog, the file content in the target file is converted from the first grammar to the second grammar, the converted file content is obtained, and then the converted file content is written back into the target file. In this embodiment, by automatically scanning all files under the preset directory, the target file to be converted can be automatically identified and automatically converted, so that repetitive work is reduced, the time consumption is short, and omission and errors are not easy to cause.
An embodiment of a second aspect of the present application provides a file conversion device, including: the identification module is configured to identify the target file from the preset catalogue; the conversion module is configured to convert the file content in the target file from a first grammar to a second grammar to obtain converted file content; and the write-back module is configured to write back the converted file content into the target file.
According to the file conversion device, the target file is identified from the preset catalog, the file content in the target file is converted from the first grammar to the second grammar, the converted file content is obtained, and then the converted file content is written back into the target file. In this embodiment, by automatically scanning all files under the preset directory, the target file to be converted can be automatically identified and automatically converted, so that repetitive work is reduced, the time consumption is short, and omission and errors are not easy to cause.
An embodiment of a third aspect of the present application provides an electronic device, including: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the file conversion method as described in the embodiment of the first aspect above.
An embodiment of a fourth aspect of the present application proposes a computer-readable storage medium storing computer instructions for causing the computer to execute the file conversion method according to the embodiment of the first aspect described above.
Additional aspects and advantages of the application will be set forth in part in the description which follows and, in part, will be obvious from the description, or may be learned by practice of the application.
Drawings
The foregoing and/or additional aspects and advantages of the application will become apparent and readily appreciated from the following description of the embodiments, taken in conjunction with the accompanying drawings, in which:
FIG. 1 is a flowchart illustrating a method for converting files according to an embodiment of the present application;
FIG. 2 is a flowchart illustrating a file conversion method according to another embodiment of the present application;
FIG. 3 is a flowchart illustrating a file conversion method according to another embodiment of the present application;
FIG. 4 is a flowchart illustrating a file conversion method according to another embodiment of the present application;
FIG. 5 is a flowchart illustrating a file conversion method according to another embodiment of the present application;
FIG. 6 is a schematic diagram of a file conversion device according to an embodiment of the present application;
Fig. 7 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
Embodiments of the present application are described in detail below, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to like or similar elements or elements having like or similar functions throughout. The embodiments described below by referring to the drawings are illustrative and intended to explain the present application and should not be construed as limiting the application.
In the description of the present application, the term "CSS" is a computer language used to represent file styles such as HTML (Hyper Text Markup Language ) or XML (eXtended Markup Language, extensible markup language).
In the description of the present application, the term "Sass" is a precompiled language for CSS. It provides variable, nesting, mixing, function, etc. functions and is fully compatible with CSS syntax.
In the description of the present application, the term "Less" is a one-door CSS pre-processing language that extends the CSS language, adding properties such as variables, mixin, functions, etc., making CSS easier to maintain and extend.
In the description of the present application, the term "JavaScript" is an interpreted scripting language, a dynamic type, a weak type, a prototype-based language, and a built-in support type.
In the description of the present application, the term "NPM" is a package management tool of the JavaScript world, and is a default package management tool of the node. Js platform. Code can be installed, shared and distributed through NPM, and project dependency relationships are managed.
In the description of the present application, the term "node. Js" is a JavaScript running environment based on the Chrome V8 engine. Js uses an event driven, non-blocking I/O (Input/Output) model, making it lightweight and efficient.
In the description of the present application, the term "Cheerio" is a node. Js crawl page module specifically tailored for server, fast, flexible, implemented jQuery core implementation. Is suitable for various Web (webpage) crawler programs.
In the description of the present application, the term "DOM" (Document Object Model ) is a standard programming interface for processing extensible markup language recommended by the W3C (World Wide Web Consortium ) organization. It is a platform and language independent application program interface (Application Programming Interface, API for short) that can dynamically access programs and scripts and update their content, structure and style of www documents.
In the description of the present application, the term "regular expression" describes a pattern (pattern) of character string matching, which can be used to check whether a string contains a certain sub-string, replace a matching sub-string, or take out a sub-string that meets a certain condition from a certain string, etc.
The file conversion method, apparatus, device and medium according to the embodiments of the present application are described below with reference to the accompanying drawings.
Fig. 1 is a flowchart illustrating a file conversion method according to an embodiment of the present application. The file conversion method according to the embodiment of the present application may be performed by the file conversion device according to the embodiment of the present application, and the file conversion device may be disposed in the converter. As shown in fig. 1, the file conversion method according to the embodiment of the present application specifically includes the following steps:
S101, identifying the target file from the preset catalogue.
Specifically, in the file conversion method according to the embodiment of the present application, the file content in the target file is converted from a first syntax to a second syntax, where the first syntax is sass syntax, and the second syntax is less syntax, and the target file may be sass file or vue file. After starting file conversion, the converter, for example sass less converter, traverses all files under a preset directory, for example, dirPath directory, specifically, can recursively traverse all files under the preset directory by a fs.readdirSync method of node.js, judge the type of each file, and identify the file to be converted from the type of each file, namely identify the target file.
S102, converting the file content in the target file from the first grammar to the second grammar to obtain converted file content.
Specifically, the converter may be preset with a rule of converting the first grammar to the second grammar, for example, a rule of converting sass grammar to less grammar, which is defined by using a regular expression, for example, a JavaScript regular expression. The converter can acquire file contents in the target file through a fs.readFileSync method of node.js, and convert the file contents in the target file from a first grammar to a second grammar according to a preset conversion rule of the converter to acquire converted file contents.
S103, writing the converted file content back to the target file.
Specifically, the converter can write back the converted file content to the corresponding target file through the fs.writefileSync method of node.js, so as to complete the grammar conversion of the target file.
According to the file conversion method, the target file is identified from the preset catalog, the file content in the target file is converted from the first grammar to the second grammar, the converted file content is obtained, and then the converted file content is written back into the target file. In this embodiment, the file conversion rule is preset through the JavaScript regular expression, and all files under the specified directory are automatically scanned through node.js, so that the files needing to be converted can be identified and automatically converted, the repetitive work is reduced, the consumed time is short, and omission and errors are not easy to cause.
Fig. 2 is a flowchart of a file conversion method according to another embodiment of the present application. As shown in fig. 2, based on the embodiment shown in fig. 1, step S101 may specifically include:
s201, acquiring a file conversion instruction.
Specifically, when file conversion needs to be started, an input file conversion instruction may be obtained, where the file conversion instruction may include a type of a converter and a directory where a target file to be converted is located, that is, a preset directory, for example, the file conversion instruction may be sass less < dirPath >, and then a file conversion process is performed by using a preset sass less converter.
S202, identifying the target file from the preset catalogue according to the file conversion instruction.
Specifically, the target file is identified from the preset directory according to the file conversion instruction, for example, from the preset directory dirPath according to the file conversion instruction sass less < dirPath >.
As a possible implementation manner, the "identifying the target file from the preset directory" in the step S202 may include the following steps: acquiring file names of files under a preset directory; and identifying whether the file is a target file according to the suffix in the file name.
Specifically, the converter may obtain the file name of the file under the preset directory by a path. Extname method of node. Js, determine whether the suffix of the file name is sass or vue, if yes, the file needs to be converted, and determine the file as the target file.
According to the file conversion method, the target file is identified from the preset directory according to the suffix in the file name, the file content in the target file is converted from the first grammar to the second grammar, the converted file content is obtained, and then the converted file content is written back into the target file. In this embodiment, by automatically scanning all files under the preset directory, the target file to be converted can be automatically identified and automatically converted, so that repetitive work is reduced, the time consumption is short, and omission and errors are not easy to cause. Whether the file is the target file is identified according to the suffix in the file name, so that the identification of the target file can be quickly and accurately realized, and the conversion efficiency is improved.
Fig. 3 is a flowchart illustrating a file conversion method according to another embodiment of the present application. As shown in fig. 3, when the target file is sass files based on the embodiment shown in fig. 1, step S102 may specifically include:
s301, acquiring a preset sass grammar matching rule and a preset less grammar replacement rule.
Specifically, javaScript regular expressions may be used, and grammar matching rules corresponding to various sass grammars may be defined in advance for various sass grammars, and grammar replacement rules corresponding to various less grammars may be defined for various less grammars.
S302, determining matched target sass grammar in file content in the target file according to sass grammar matching rules.
Specifically, the matching target sass grammar can be determined in the file content in the target file based on the preset sass grammar matching rule acquired in step S301 by using a replay method of JavaScript.
S303, replacing the target sass grammar with the target less grammar according to the less grammar replacement rule to obtain the converted file content.
Specifically, the target sass grammar matched in step S302 can be replaced by a corresponding target less grammar based on the less grammar replacement rule obtained in step S301 by a replace method of JavaScript, so as to obtain the converted file content.
According to the file conversion method, the target file is identified from the preset catalog, the file content in the target file is converted from the first grammar to the second grammar based on the preset sass grammar matching rule and the preset less grammar replacement rule, converted file content is obtained, and then the converted file content is written back into the target file. In this embodiment, by automatically scanning all files under the preset directory, the target file to be converted can be automatically identified and automatically converted, so that repetitive work is reduced, the time consumption is short, and omission and errors are not easy to cause. Based on a preset sass grammar matching rule and a preset less grammar replacement rule, matching of target sass grammar and replacement of target less grammar in sass files can be rapidly and accurately realized, and conversion efficiency is improved.
Fig. 4 is a flowchart of a file conversion method according to another embodiment of the present application. As shown in fig. 4, when the target file is vue files based on the embodiment shown in fig. 1, step S102 may specifically include:
s401, acquiring a preset sass grammar matching rule and a preset less grammar replacement rule.
Specifically, javaScript regular expressions may be used, and grammar matching rules corresponding to various sass grammars may be defined in advance for various sass grammars, and grammar replacement rules corresponding to various less grammars may be defined for various less grammars.
S402, converting file content in the target file into a document object model.
Specifically, the converter may load the file content in the target file by using the load method cheerio, and convert the file content in the target file into a document object model, i.e., a dom object.
S403, acquiring the style node content from the document object model.
Specifically, the transformer may obtain style node content from the dom object through the node selector function of cheerio.
S404, determining matched target sass grammar in the style node content according to sass grammar matching rules.
Specifically, the matching target sass grammar can be determined in the style node content by a replay method of JavaScript based on the preset sass grammar matching rule acquired in step S401.
S405, replacing the target sass grammar with the target less grammar according to the less grammar replacement rule to obtain the converted file content.
Specifically, the target sass grammar matched in step S402 can be replaced by a corresponding target less grammar based on the less grammar replacement rule obtained in step S401 by a replace method of JavaScript, so as to obtain the converted file content.
According to the file conversion method, the target file is identified from the preset catalog, the file content in the target file is converted from the first grammar to the second grammar, the converted file content is obtained, and then the converted file content is written back into the target file. In this embodiment, by automatically scanning all files under the preset directory, the target file to be converted can be automatically identified and automatically converted, so that repetitive work is reduced, the time consumption is short, and omission and errors are not easy to cause. Based on a preset sass grammar matching rule and a preset less grammar replacement rule, matching of target sass grammar and replacement of target less grammar in vue files can be rapidly and accurately realized, and conversion efficiency is improved.
In order to clearly illustrate the file conversion method according to the embodiment of the present application, the file conversion method according to the embodiment of the present application is described in detail below with reference to fig. 5. As shown in fig. 5, the file conversion method according to the embodiment of the present application specifically includes the following steps:
S501, start switching.
S502, acquiring a file conversion instruction.
S503, traversing all files under the preset directory according to the file conversion instruction, and obtaining file names of the files under the preset directory.
S504, identifying whether the file is a target file according to the suffix in the file name.
If the target file is sass, steps S505 to S506 are executed. If the target file is vue files, steps S508 to S510 are executed.
S505, a preset sass grammar matching rule and a preset less grammar replacement rule are obtained.
S506, determining matched target sass grammar in file content in the target file according to sass grammar matching rules. Step S511 is continued.
S507, acquiring a preset sass grammar matching rule and a preset less grammar replacement rule.
S508, converting the file content in the target file into a document object model.
S509, acquiring style node contents from the document object model.
S510, determining matched target sass grammar in the style node content according to sass grammar matching rules. Step S511 is continued.
S511, replacing the target sass grammar with the target less grammar according to the less grammar replacement rule to obtain the converted file content.
S512, writing the converted file content back to the target file.
S513, the conversion is completed.
In order to achieve the above embodiments, the embodiments of the present application further provide a file conversion device. Fig. 6 is a schematic structural diagram of a file conversion device according to an embodiment of the application. As shown in fig. 6, the file conversion apparatus 600 according to the embodiment of the present application may specifically include: an identification module 601, a conversion module 602, and a write-back module 603.
The identifying module 601 is configured to identify the target file from the preset directory.
The conversion module 602 is configured to convert the file content in the target file from the first syntax to the second syntax, so as to obtain converted file content.
The write-back module 603 is configured to write back the converted file content to the target file.
In one embodiment of the present application, the identification module 601 may specifically include: a first acquisition unit configured to acquire a file conversion instruction; the first identification unit is configured to identify the target file from the preset catalog according to the file conversion instruction.
In one embodiment of the present application, the identification module 601 may specifically include: the second acquisition unit is configured to acquire the file name of the file under the preset directory; and a second identifying unit configured to identify whether the file is a target file according to the suffix in the file name.
In one embodiment of the present application, the first syntax is sass syntax, the second syntax is less syntax, and the object file is sass file or vue file.
In one embodiment of the present application, the object file is sass files, and the conversion module 602 may specifically include: a third obtaining unit configured to obtain a preset sass grammar matching rule and a preset less grammar replacement rule; a first determining unit configured to determine a matched target sass grammar in file contents in a target file according to sass grammar matching rules; and the first replacing unit is configured to replace the target sass grammar with the target less grammar according to the less grammar replacing rule to obtain the converted file content.
In one embodiment of the present application, the object file is vue files, and the conversion module 602 may specifically include: a fourth obtaining unit configured to obtain a preset sass grammar matching rule and a preset less grammar replacement rule; a conversion unit configured to convert file contents in the target file into a document object model; a fifth acquisition unit configured to acquire style node contents from the document object model; a second determining unit configured to determine a matched target sass grammar in the style node content according to sass grammar match rules; and the second replacing unit is configured to replace the target sass grammar with the target less grammar according to the less grammar replacing rule to obtain the converted file content.
According to the file conversion device, the target file is identified from the preset catalog, the file content in the target file is converted from the first grammar to the second grammar, the converted file content is obtained, and then the converted file content is written back into the target file. In this embodiment, by automatically scanning all files under the preset directory, the target file to be converted can be automatically identified and automatically converted, so that repetitive work is reduced, the time consumption is short, and omission and errors are not easy to cause. Whether the file is the target file is identified according to the suffix in the file name, so that the identification of the target file can be quickly and accurately realized, and the conversion efficiency is improved. Based on a preset sass grammar matching rule and a preset less grammar replacement rule, the matching of the target sass grammar and the replacement of the target less grammar in the sass and vue files can be rapidly and accurately realized, and the conversion efficiency is improved.
According to an embodiment of the present application, the present application also provides an electronic device and a readable storage medium.
As shown in fig. 7, there is a block diagram of an electronic device of a file conversion method according to an embodiment of the present application. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile apparatuses, such as smart voice interaction devices, personal digital assistants, cellular telephones, smart phones, wearable devices, and other similar computing apparatuses. The components shown herein, their connections and relationships, and their functions, are meant to be exemplary only, and are not meant to limit implementations of the applications described and/or claimed herein.
As shown in fig. 7, the electronic device includes: one or more processors 701, memory 702, and interfaces for connecting the various components, including high-speed interfaces and low-speed interfaces. The various components are interconnected using different buses and may be mounted on a common motherboard or in other manners as desired. The processor 701 may process instructions executing within the electronic device, including instructions stored in or on memory to display graphical information of a GUI on an external input/output device, such as a display device coupled to an interface. In other embodiments, multiple processors and/or multiple buses may be used, if desired, along with multiple memories and multiple memories. Also, multiple electronic devices may be connected, each providing a portion of the necessary operations (e.g., as a server array, a set of blade servers, or a multiprocessor system). One processor 701 is illustrated in fig. 7.
Memory 702 is a non-transitory computer readable storage medium provided by the present application. The memory stores instructions executable by the at least one processor to cause the at least one processor to perform the file conversion method provided by the present application. The non-transitory computer readable storage medium of the present application stores computer instructions for causing a computer to execute the file conversion method provided by the present application.
The memory 702 is used as a non-transitory computer readable storage medium for storing non-transitory software programs, non-transitory computer executable programs, and modules, such as program instructions/modules (e.g., the identification module 601, the conversion module 602, and the write-back module 603 shown in fig. 6) corresponding to the file conversion method according to the embodiment of the present application. The processor 701 executes various functional applications of the server and data processing by executing non-transitory software programs, instructions, and modules stored in the memory 702, that is, implements the file conversion method in the above-described method embodiment.
Memory 702 may include a storage program area that may store an operating system, at least one application program required for functionality, and a storage data area; the storage data area may store data created according to the use of the electronic device of the risk control method, and the like. In addition, the memory 702 may include high-speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory 702 optionally includes memory remotely located relative to processor 701, which may be connected to the electronics of the risk control method via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The electronic device of the file conversion method may further include: an input device 703 and an output device 704. The processor 701, the memory 702, the input device 703 and the output device 704 may be connected by a bus or otherwise, in fig. 7 by way of example.
The input device 703 may receive input numeric or character information and generate key signal inputs related to user settings and function control of the electronic device of the file conversion method, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, a pointer stick, one or more mouse buttons, a track ball, a joystick, etc. The output device 704 may include a display apparatus, auxiliary lighting devices (e.g., LEDs), and haptic feedback devices (e.g., vibration motors), among others. The display device may include, but is not limited to, a Liquid Crystal Display (LCD), a Light Emitting Diode (LED) display, and a plasma display. In some implementations, the display device may be a touch screen.
Various implementations of the systems and techniques described here can be realized in digital electronic circuitry, integrated circuitry, application specific ASIC (application specific integrated circuit), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs, the one or more computer programs may be executed and/or interpreted on a programmable system including at least one programmable processor, which may be a special purpose or general-purpose programmable processor, that may receive data and instructions from, and transmit data and instructions to, a storage system, at least one input device, and at least one output device.
These computing programs (also referred to as programs, software applications, or code) include machine instructions for a programmable processor, and may be implemented in a high-level procedural and/or object-oriented programming language, and/or in assembly/machine language. As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, apparatus, and/or device (e.g., magnetic discs, optical disks, memory, programmable Logic Devices (PLDs)) used to provide machine instructions and/or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal used to provide machine instructions and/or data to a programmable processor.
To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and pointing device (e.g., a mouse or trackball) by which a user can provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic input, speech input, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a background component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such background, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), wide Area Networks (WANs), and the internet.
The computer system may include a client and a server. The client and server are typically remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, also called a cloud computing server or a cloud host, and is a host product in a cloud computing service system, so that the defects of high management difficulty and weak service expansibility in the traditional physical hosts and VPS service ("Virtual PRIVATE SERVER" or simply "VPS") are overcome.
It should be appreciated that various forms of the flows shown above may be used to reorder, add, or delete steps. For example, the steps described in the present application may be performed in parallel, sequentially, or in a different order, provided that the desired results of the disclosed embodiments are achieved, and are not limited herein.
In the description of this specification, the terms "first," "second," and the like are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defining "a first" or "a second" may explicitly or implicitly include at least one such feature. In the description of the present application, the meaning of "plurality" means at least two, for example, two, three, etc., unless specifically defined otherwise.
While embodiments of the present application have been shown and described above, it will be understood that the above embodiments are illustrative and not to be construed as limiting the application, and that variations, modifications, alternatives and variations may be made to the above embodiments by one of ordinary skill in the art within the scope of the application.
Claims (7)
1. A method for converting a file, comprising:
identifying a target file from a preset directory, wherein the target file is sass files or vue files;
Converting the file content in the target file from a first grammar to a second grammar to obtain converted file content;
Writing the converted file content back to the target file;
the first grammar is sass grammar, and the second grammar is less grammar;
When the target file is sass files, the converting the file content in the target file from the first grammar to the second grammar to obtain converted file content includes:
obtaining a preset sass grammar matching rule and a preset less grammar replacement rule, wherein the method comprises the following steps: using JavaScript regular expressions, defining grammar matching rules corresponding to various sass grammars for various sass grammars in advance, and defining grammar replacement rules corresponding to various less grammars for various less grammars;
Converting file contents in the target file into a document object model;
Acquiring style node content from the document object model;
Determining a matched target sass grammar in the style node content according to the sass grammar matching rules;
and replacing the target sass grammar with the target less grammar according to the less grammar replacement rule to obtain the converted file content.
2. The method of claim 1, wherein identifying the target file from the preset directory comprises:
Acquiring a file conversion instruction;
And identifying the target file from the preset catalogue according to the file conversion instruction.
3. The method of claim 1, wherein identifying the target file from the preset directory comprises:
acquiring the file name of the file under the preset directory;
And identifying whether the file is the target file according to the suffix in the file name.
4. A document conversion apparatus, comprising:
the identification module is configured to identify a target file from a preset directory, wherein the target file is sass files or vue files;
The conversion module is configured to convert the file content in the target file from a first grammar to a second grammar to obtain converted file content;
the write-back module is configured to write back the converted file content into the target file;
The conversion module is further configured to, when the target file is sass files,
Obtaining a preset sass grammar matching rule and a preset less grammar replacement rule, wherein the method comprises the following steps: using JavaScript regular expressions, defining grammar matching rules corresponding to various sass grammars for various sass grammars in advance, and defining grammar replacement rules corresponding to various less grammars for various less grammars;
Converting file contents in the target file into a document object model;
Acquiring style node content from the document object model;
Determining a matched target sass grammar in the style node content according to the sass grammar matching rules;
and replacing the target sass grammar with the target less grammar according to the less grammar replacement rule to obtain the converted file content, wherein the first grammar is sass grammar and the second grammar is less grammar.
5. The file conversion apparatus of claim 4, wherein the identification module comprises:
A first acquisition unit configured to acquire a file conversion instruction;
And the first identification unit is configured to identify the target file from the preset catalogue according to the file conversion instruction.
6. An electronic device, comprising:
at least one processor; and
A memory communicatively coupled to the at least one processor; wherein,
The memory stores instructions executable by the at least one processor to enable the at least one processor to perform the file conversion method of any one of claims 1-3.
7. A computer-readable storage medium storing computer instructions for causing the computer to perform the file conversion method according to any one of claims 1 to 3.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202110609983.9A CN113254405B (en) | 2021-06-01 | 2021-06-01 | File conversion method, device, equipment and medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202110609983.9A CN113254405B (en) | 2021-06-01 | 2021-06-01 | File conversion method, device, equipment and medium |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN113254405A CN113254405A (en) | 2021-08-13 |
| CN113254405B true CN113254405B (en) | 2024-07-16 |
Family
ID=77185832
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202110609983.9A Active CN113254405B (en) | 2021-06-01 | 2021-06-01 | File conversion method, device, equipment and medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN113254405B (en) |
Families Citing this family (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN113961244B (en) * | 2021-12-22 | 2022-04-08 | 深圳市明源云科技有限公司 | Page conversion method, device, equipment and storage medium |
Citations (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN110888645A (en) * | 2019-10-12 | 2020-03-17 | 贝壳技术有限公司 | Method, device and storage medium for converting into small program |
Family Cites Families (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US7788290B2 (en) * | 2007-03-27 | 2010-08-31 | Microsoft Corporation | Automatic file conversion to a target format |
| US8984165B2 (en) * | 2008-10-08 | 2015-03-17 | Red Hat, Inc. | Data transformation |
| US11003835B2 (en) * | 2018-10-16 | 2021-05-11 | Atos Syntel, Inc. | System and method to convert a webpage built on a legacy framework to a webpage compatible with a target framework |
| CN110109671B (en) * | 2019-02-28 | 2023-05-16 | 深圳点猫科技有限公司 | Webpack label size and style conversion method and device |
-
2021
- 2021-06-01 CN CN202110609983.9A patent/CN113254405B/en active Active
Patent Citations (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN110888645A (en) * | 2019-10-12 | 2020-03-17 | 贝壳技术有限公司 | Method, device and storage medium for converting into small program |
Also Published As
| Publication number | Publication date |
|---|---|
| CN113254405A (en) | 2021-08-13 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| KR102497463B1 (en) | Mini-program execution method, mini-program execution device, electronic device and storage medium | |
| EP3896567B1 (en) | Page pre-rendering method and apparatus, electronic device, and storage medium | |
| KR102585797B1 (en) | Method, device, electronic equiment and storage medium for determining page theme | |
| KR101099272B1 (en) | Web page rendering mechanism using external programmatic themes | |
| KR20210040850A (en) | Method, apparatus, device, and storage medium for parsing document | |
| US20120096429A1 (en) | Wiring web widgets of a web mashup | |
| CN111274127B (en) | Code jumping method, device, equipment and medium in code evaluation | |
| CN112015468B (en) | Interface document processing method and device, electronic equipment and storage medium | |
| CN113722647A (en) | Method and device for displaying information | |
| JP2021099798A (en) | Method and device for structuring data, computer device, and medium | |
| KR102550540B1 (en) | Landing page processing method, device, equipment and medium | |
| CN105683957B (en) | Stylesheet speculative preloading | |
| US11775290B2 (en) | Detection of API backward compatibility across software versions | |
| CN113254043A (en) | Web front-end project processing method and device, electronic equipment and storage medium | |
| CN105528369B (en) | Webpage code-transferring method, device and server | |
| EP3872630A2 (en) | Request processing method and apparatus, electronic device, and computer storage medium | |
| CN113254405B (en) | File conversion method, device, equipment and medium | |
| CN111880778B (en) | Method and device for generating interface document, electronic equipment and storage medium | |
| KR20210037628A (en) | Code reuse processing method, device, electronic equipment, computer readable storage medium and computer program | |
| CN112287266B (en) | A web page configuration processing method and its device, equipment and storage medium | |
| CN112130888A (en) | Method, device and equipment for updating application program and computer storage medium | |
| CN111966433B (en) | Method, device, storage medium and electronic device for changing language in page | |
| CN116302414A (en) | Task scheduling method and device, electronic equipment and storage medium | |
| JP7213337B2 (en) | Application interface realization method, device, device and medium on upper platform layer | |
| CN112379885A (en) | Applet compiling method, device and equipment and readable storage medium |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |