This repository has been archived by the owner on May 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
87 lines (75 loc) · 2.15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env node
/**
* 2011 Peter 'Pita' Martischka
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var parser = require('./parser');
var writer = require('./writer');
var fs = require("fs");
var path = require("path");
if(process.argv.length != 4)
{
console.error("Usage: doc.md $SRCFOLDER $DESTFOLDER");
process.exit(1);
}
var srcFolder = process.argv[2];
var destFolder = process.argv[3];
//check src Directory
var srcValid = false;
try
{
srcValid = fs.lstatSync(srcFolder).isDirectory();
} catch(e) {};
if(!srcValid)
{
console.error("'"+srcFolder + "' is no directory!");
process.exit(1);
}
//check dest directory
var destValid = false;
try
{
destValid = fs.lstatSync(destFolder).isDirectory();
} catch(e) {};
if(!destValid)
{
console.log("'"+destFolder + "' is no directory! I'll create it for you.");
fs.mkdirSync(destFolder);
}
//start recursive function
doFolder(srcFolder, ".");
function doFolder(srcFolder, folder)
{
//get the path and files
var folderPath = path.normalize(srcFolder + "/" + folder);
var files = fs.readdirSync(folderPath);
//go trough all files in this folder
for(var i in files)
{
var absolutePath = path.normalize(folderPath + "/" + files[i]);
var relativePath = path.normalize(folder + "/" + files[i]);
var isDirectory = fs.lstatSync(absolutePath).isDirectory();
//if this is a folder, call function recursively
if(isDirectory)
{
doFolder(srcFolder, relativePath);
}
//if this is a javascript file, parse it
else if(absolutePath.search(/.js$/) != -1)
{
var parsedObj = parser.parseFile(srcFolder, relativePath);
writer.parsedObj2md(destFolder, parsedObj);
}
}
}