Detailed Description
The present application will be described in further detail with reference to the following drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not restrictive of the invention. It should be noted that, for convenience of description, only the portions related to the related invention are shown in the drawings.
It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict. The present application will be described in detail below with reference to the accompanying drawings in conjunction with embodiments.
Fig. 1 shows a flowchart of a method for generating a software engineering catalog structure annotation bird's eye view according to an embodiment of the present application. As shown in fig. 1, the method includes:
s101: the header annotation and the annotation file are used to write an annotation specification for a file or folder.
In a specific embodiment, an annotation specification of a file or a folder is written in the forms of a file header annotation, an annotation file and the like, the annotation of the file is added by adopting a plurality of lines of annotations of a file header, and the matching regularity of the plurality of lines of annotations (denoted as: regular A): commensrag =/\\ S \ S + \ S + (\ S) [ \ W ] \ S \/, and the method for extracting the comment content is as follows: [ File content ] match (commensurable region) [1 ]. And (4) directory annotation, namely, reading the content of the file by adopting a file with the file name comment under the directory as a carrier through a readFile method of an fs module.
S102: and traversing all contents in the item folder by using a directory tree recursion algorithm, extracting the annotation description and generating a directory structure tree.
In a specific embodiment, a directory tree recursive algorithm with a neglect condition is adopted for traversal, in the process of recursively reading child nodes of folders, specific folders, folder nodes and files are ignored, and finally tree data expressing a folder structure is generated.
In a specific embodiment, a specific method for generating the directory structure tree is as follows:
1. the specific folders, folder nodes, files that are intended to be ignored are stored by a dirTreeIgnore file under the root directory. The dirTreeIgnore file is read line by line, and filter terms are obtained. Wherein:
dirName/: representing all subdirectories and files under the filtering name dirName folder
A dirName: filtering folder named dirName
filiename: filtering files named as fileName
Identifying a regular expression of dirName/(: regular B): reg =/(\ S }/, where dirName = reg [1]
2. The item folder is read recursively, ignored if a dirName or fileName type of dirtreigore is encountered, and traversal of the subdirectory of dirName is stopped if a dirName/. type is encountered.
3. Generating tree data expressing a folder structure in a recursion process, wherein:
the tree structure data is denoted as DataTree, and the tree structure node data is denoted as DataItem
dataTree = [dataItem…]
dataItem = {
The path is a path of the file,
the fileName is the name of the file,
isdirection-whether a folder is present,
comment-a comment-is given,
mtime-the last change time,
child node of children: [ dataItem … ]
In a specific embodiment, the step S102 includes a plurality of sub-algorithms, and the steps and abbreviated codes of the sub-algorithms are as follows:
1. the method for reading line by line (denoted as sub-algorithm a) includes the following detailed steps:
reading a file through fs.readfile to obtain a data stream of the file;
delivering the data stream to a progressive reading module readline.
Monitoring a line event of a line-by-line reading module, and pushing line data into a stack each time the event is executed;
when the end event triggered by the line-by-line reading module occurs, returning to the stack to finish line-by-line reading; the shorthand code is as follows:
/**
line by line reading
@param filePath
@return {Promise<unknown>}
/
function readLine(filePath){
return new Promise((resolve, reject)=>{
fs.readFile(filePath, function (err,data) {
let baseData = new Buffer.from(data);
var bufferStream = new stream.PassThrough();
bufferStream.end(baseData);
var objReadline = readline.createInterface({
input:bufferStream
});
var arr = [];
objReadline.on('line',function (line) {
arr.push(line);
});
objReadline.on('close',function () {
resolve(arr);
});
});
});
2. dirTreeIgnore, method for obtaining filter terms (denoted as, sub-algorithm B), detailed steps are:
reading data list in a dirTreeIgnore (directory ignore file) file line by line through a sub-algorithm A;
circulating list, and matching whether to filter the filter items of the subset or not through the regular B;
thus splitting the list into two lists and returning: filter terms (dirName/' type) that filter only a subset (denoted as: ignorechldren), filter terms (dirName and fileName type) that filter the current file (denoted as: ignoreSelf). The shorthand code is as follows:
/**
DirTreeIgore, get the filter term
dirName/: representing all subdirectories and files under the filtering name dirName folder
dirName: filtering folder named dirName
fileName: filtering files named as fileName
/
async function getIgnoreList(){
dirTreeIgnore, get a list of ignorions
let ignoreList = await readLine(path.resolve(__dirname, '.dirTreeIgnore'))
.then((data)=>{return data});
let result = {
ignoreChildren: [],
ignoreSelf: [],
};
for(let ignoreItem of ignoreList){
If the match is a filtered subset only
let matchOnlyChildren = ignoreItem.match(/(\S*)\/\*$/);
if(matchOnlyChildren){
result.ignoreChildren.push(matchOnlyChildren[1]);
}else{
result.ignoreSelf.push(ignoreItem);
}
}
return result;
3. The method for reading annotation information (denoted as sub-algorithm C) comprises the following detailed steps:
if the path is a folder, reading the content of the comment file of comment in the directory as the comment content of the path;
if the path is of a file type, matching annotation content by regular A;
and finally returning the annotation content. The shorthand code is as follows:
/**
read annotation information
@param path
@return {*}
/
function readCommet(path){
if(isDirectory(path)){
return readCommentTxt(path);
}else{
let s = fs. readFileSync(path);
let reg = /\/\*+\s*\*+\s+(\S*)[\w\W]*\*+\/$/;
let result = s.match(reg);
return result && result[1];
}
4. Recursion generates a data tree (denoted as sub-algorithm D), recursion: the method in which function a internally calls itself (function a) and conditionally stops the process is called recursion. The detailed steps are as follows:
a recursive function FN (dataItem) is defined, where dataItem is the directory of the current recursive read. treeNode is the current recursion node of the data tree;
reading a child node list of a directory of the dataItem;
traversing the list to obtain the item, if the item is in the ignores self list, skipping, and continuing to execute the next item;
if the item is not in the ignoreSelf list, then a child node of the data tree is defined. Pushing into treeNode;
if the item is not of a folder type, or the item is in an ignoreChildren. If the child node of the item is to be ignored, skipping the recursion of the child node and continuing to execute the next item;
if the item is of folder type, and the item is not in ignoreChildren. Repeating executing FN on item;
therefore, the traversal of all the nodes of the target folder is completed, and a data tree root is generated. The shorthand code is as follows:
function FN(dataItem, treeNode){
let dirPath = dataItem.path;
// read dirPath lower node
let list = fs.readdirSync(dirPath)
let ignoreList = getIgnoreList();
for(let item of list){
if (entry) continue, filter out ignore item
let childNode = {
path: item.path,
fileName: item.fileName,
isDirectory: item.isDirectory,
comment: readCommet(item.path) || '',
mtime: item.mtime,
children: []
}
treeNode.children.push(childNode);
let isIgnoreChildren = ignoreList.ignoreChildren.includes(item)
if(item.isDirectory && !isIgnoreChildren){
FN(item, childNode)
}
}
return treeNode;
let root = {
path: __dirname,
fileName 'root directory name',
isDirectory: true,
comment, 'comment',
mtime: root.mtime,
children: []
;
FN({path: __dirname}, root);
s103: the directory structure tree is rendered as an editable tree and exported as an initial aerial view store. The initial aerial view is the first time the tool is applied to the project catalog, and no data cache file is generated.
In a specific embodiment, the dataTree generated in the above process is rendered into an editable tree by means of vue. Js subcomponent renders: and packaging the tree nodes into a vue.js component A, and circularly and recursively nesting the component A so as to render the tree, wherein the tree can be edited by setting an input in A.
In a specific embodiment, the tree data is derived as html or a bird's eye view in the form of a picture, and the directory structure tree is stored as a local file. And generating aerial views of various carriers by the edited dataTree in the above three methods: 1. generating html into a picture through an html2canvas module; 2. generating json data into a picture by canvas drawing; 3. and directly constructing json data into an html file through the fs module. Specifically, the dataTree data is saved as dataTree in a JSON file JSON (data is recorded as localdatre) through a writeFile of an fs module, a mapping table from itepath to item (recorded as datatremapp) is generated, and a shorthand code:
dataTreeMap = {
path: item node
}。
In a specific embodiment, step 103 is followed by traversing all contents in the project folder using a directory and file modification time comparison algorithm to update the initial bird's eye view. When the aerial view is generated later, the traversal efficiency can be improved through the comparison algorithm of the directory and the file modification time. The principle used by the directory and file modification time comparison algorithm is that when any file at any level of a folder is added, deleted or changed, the attribute mtime is changed. If the content of a file changes, the mtime of the file will also change.
In a specific embodiment, the comparison algorithm of the modification time of the directory and the file comprises: and executing a directory tree recursive algorithm, and comparing mtime of data of a node in the datatremap in detail 4 when traversing to the node. If mtime is inconsistent, indicating that the node or child node has changed, the node is read and recursion is performed. If mtime is consistent, the node is indicated and the child node is not changed, the cache (localdata tree in detail 4) is read, the data of the node of the localdata tree is directly extracted into the current dataTree, and the downward recursion is stopped. A method (sub-algorithm E) for fast mapping localDataTree and the current node: splitting the path of the current node into arrays according to '/', wherein the data corresponding to the node in the localdatreete is localdatreitem = localdatreete [ path [0] ] [ path [1] ] … [ path [ lastIndex ] ]. The detailed steps of the algorithm are as follows:
reading tree data localDataTree generated last time;
executing the directory tree recursion algorithm;
in the traversal process, acquiring a current traversal node item;
and comparing the mtimes, if the mtimes are equal to each other, indicating that the mtimes are not modified, quickly acquiring the data localtem of the current node in the localDataTree through the sub-algorithm E. Directly extracting the data into the current dataTree;
if not, then the modification is indicated, and then the recursion continues. The shorthand code is as follows:
// path to item mapping table
let dataTreeMap = {
' path ': item node '
// last generated tree data
let localDataTree = fs.readFileSync('dataTree.json');
/**
Alignment mtime
@param item
@return {boolean}
/
function isAltered(item){
if(!dataTreeMap || !dataTreeMap[item.path])return;
return item.mtime !== dataTreeMap[item.path]
/**
Get cache node
@param item
@return {null|Buffer}
/
function getLocalData(item){
if(isAltered(item)){
return null;
}
let pathArray = item.path.split('/');
let localItem = localDataTree;
for(let pathItem of pathArray){
localItem = localItem[pathItem];
}
return localItem;
With continued reference to fig. 2, fig. 2 is a flowchart illustrating a method for generating a software engineering catalog structure annotation bird's eye view according to a specific embodiment of the present application, the method specifically comprising the following steps:
step 201: and writing an annotation. And writing the annotation description of the file or the folder in the forms of header annotation, annotation file and the like.
Step 202: recursively reading the directory; step 203: the specified item is ignored. Step 204: and reading the cache. And reading all contents in the item folder by a directory tree recursive algorithm with a neglect condition, and extracting the annotation specification.
Step 205: it is determined whether a cache exists. If there is a cache, go to step 206: comparing the modification time; if no cache exists, go to step 209: reading nodes and annotating.
Step 207: and reading the cache. And if the modification time is consistent, which indicates that the node or the child node is not changed, reading the cache.
Step 208: an editable tree is generated. Js subcomponent rendering results in an editable tree.
Step 210: and (6) editing. Step 211: and generating a bird's-eye view. Step 212: and saving the file data. Exporting the editable tree generated in the step 208 as a html or picture form aerial view, and simultaneously storing the directory structure tree as a local file. And passes the file data saved in step 212 through step 213: path to data mapping and step 214: local TreeData is used as a cache input in step 204.
With continued reference to FIG. 3, FIG. 3 illustrates a framework diagram of a software engineering catalog structure annotation bird's eye view generation system, according to one embodiment of the present application. The system specifically includes an annotation specification writing unit 301, a directory structure tree generation unit 302, and a bird's eye view derivation unit 303. An annotation description writing unit: configuring an annotation specification for writing a file or folder with a header annotation and an annotation file; a directory structure tree generation unit: the method comprises the steps that a directory tree recursion algorithm is configured to traverse all contents under a project folder, annotation descriptions are extracted, and a directory structure tree is generated; bird's eye view derivation means: configured to render the directory structure tree as an editable tree and export to the initial aerial view storage. In some specific embodiments, the method further includes: the configuration is used for traversing all contents in the project folder by utilizing a directory and file modification time comparison algorithm and updating the initial aerial view.
Referring now to FIG. 4, shown is a block diagram of a computer system suitable for use in implementing the electronic device of an embodiment of the present application. The electronic device shown in fig. 4 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present application.
As shown in fig. 4, the computer system includes a Central Processing Unit (CPU) 401 that can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM) 402 or a program loaded from a storage section 408 into a Random Access Memory (RAM) 403. In the RAM 403, various programs and data necessary for system operation are also stored. The CPU 401, ROM 402, and RAM 403 are connected to each other via a bus 404. An input/output (I/O) interface 405 is also connected to bus 404.
The following components are connected to the I/O interface 405: an input section 406 including a keyboard, a mouse, and the like; an output section 407 including a display such as a Liquid Crystal Display (LCD) and a speaker; a storage section 408 including a hard disk and the like; and a communication section 409 including a network interface card such as a LAN card, a modem, or the like. The communication section 409 performs communication processing via a network such as the internet. A driver 410 is also connected to the I/O interface 405 as needed. A removable medium 411 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 410 as needed, so that a computer program read out therefrom is mounted in the storage section 408 as needed.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable storage medium, the computer program containing program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 409, and/or installed from the removable medium 411. The computer program performs the above-described functions defined in the method of the present application when executed by a Central Processing Unit (CPU) 401. It should be noted that the computer readable storage medium of the present application can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present application, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In this application, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable storage medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable storage medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present application may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, or the like, as well as conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present application may be implemented by software or hardware.
As another aspect, the present application also provides a computer-readable storage medium, which may be included in the electronic device described in the above embodiments; or may exist separately without being assembled into the electronic device. The computer readable storage medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: writing an annotation description of a file or a folder by using the file header annotation and the annotation file; traversing all contents under the item folder by using a directory tree recursion algorithm, extracting the annotation description, and generating a directory structure tree; and rendering the directory structure tree into an editable tree, and exporting the directory structure tree to an initial aerial view for storage.
The above description is only a preferred embodiment of the application and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the invention herein disclosed is not limited to the particular combination of features described above, but also encompasses other arrangements formed by any combination of the above features or their equivalents without departing from the spirit of the invention. For example, the above features may be replaced with (but not limited to) features having similar functions disclosed in the present application.