Skip to content

Commit 85e9d7a

Browse files
committed
can now output doks to a specific folder
1 parent a195baa commit 85e9d7a

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed

bin/doks

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
3+
require('../lib/index')

lib/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
require('coffee-script/register');
3+
4+
var Parser = require("./parser.coffee");
5+
var parser = new Parser({config: "doks.json"});
6+
7+
parser.write();

lib/parser.coffee

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ _ = require "lodash"
33
_.str = require "underscore.string"
44
glob = require "glob"
55
fs = require "fs"
6+
ncp = require "ncp"
67

78
class Expressions
89
@START_COMMENT =
@@ -31,27 +32,34 @@ class Parser
3132

3233
constructor: (options) ->
3334

34-
options = @parseNewOptions options.config if options.config
35+
if options.config
36+
options = @parseNewOptions options.config
3537

3638
@setOptions options
3739

3840
parseNewOptions: (file) ->
39-
JSON.parse fs.readFileSync file, encoding: "UTF-8"
41+
try
42+
JSON.parse fs.readFileSync file, encoding: "UTF-8"
43+
catch e
44+
console.error "FATAL: No doks.json file found (or invalid config)."
4045

41-
setOptions: (@options) ->
46+
setOptions: (@options = {}) ->
4247
@options.language ?= "coffee"
4348
@options.glob ?= "**/*.#{@options.language}"
4449
@options.lib ?= "angular"
4550
@options.theme ?= "bootstrap"
4651
@options.arrayTags ?= []
4752
@options.defaults ?= {}
4853
@options.json ?= ""
54+
@options.outputPath ?= "doks"
4955

5056
getOnlyFileName: (filePath) ->
5157
filePath.split("\\").pop().split("/").pop()
5258

5359
getFiles: ->
54-
throw new Error "You have to set a glob first!" if not @options.glob
60+
if not @options.glob
61+
console.error "FATAL: No file glob set."
62+
return []
5563

5664
glob.sync @options.glob
5765

@@ -175,7 +183,10 @@ class Parser
175183

176184
fileMap
177185

178-
write: (fileLoc = "output.json") ->
186+
copyTemplate: ->
187+
ncp "./themes/#{@options.theme}/#{@options.lib}", @options.outputPath, (e) ->
188+
189+
write: (fileLoc = "#{@options.outputPath}/output.json") ->
179190
startDate = Date.now()
180191
parsedData = @parse()
181192
endDate = Date.now()
@@ -189,4 +200,6 @@ class Parser
189200

190201
fs.writeFile fileLoc, JSON.stringify data
191202

203+
@copyTemplate()
204+
192205
module.exports = exports = Parser

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
{
22
"name": "doks",
3-
"version": "0.0.0",
3+
"version": "0.1.0",
44
"description": "A configurable, bring-your-own-template documentation generator aimed for user and developer documentation based on source code.",
5-
"main": "index.js",
5+
"main": "lib/index.js",
6+
"bin": {
7+
"doks": "bin/doks"
8+
},
69
"directories": {
710
"test": "test"
811
},
912
"dependencies": {
13+
"coffee-script": "^1.8.0",
1014
"glob": "^4.0.6",
1115
"load-grunt-tasks": "^1.0.0",
1216
"lodash": "^2.4.1",
17+
"ncp": "^1.0.1",
1318
"underscore.string": "^2.4.0"
1419
},
1520
"devDependencies": {
16-
"coffee-script": "^1.8.0",
1721
"grunt": "^0.4.5",
1822
"grunt-contrib-connect": "^0.9.0",
1923
"grunt-contrib-watch": "^0.6.1",

test/parser/ParserTest.coffee

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ console.log "==COFFEE=="
1818
parser.write()
1919
#console.log parser.parse()
2020

21-
parser = new Parser
22-
language: "js"
23-
glob: "test/samples/Math.js"
24-
arrayTags: [
25-
'param'
26-
]
21+
#parser = new Parser
22+
# language: "js"
23+
# glob: "test/samples/Math.js"
24+
# arrayTags: [
25+
# 'param'
26+
# ]
2727

28-
console.log "==JS=="
28+
#console.log "==JS=="
2929
#console.log parser.parse()

0 commit comments

Comments
 (0)