-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
141 lines (126 loc) · 4.22 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
var nodeExtend = require('node.extend');
var Q = require('q');
var fse = require('fs-extra');
var path = require('path');
var request = require('request');
var zlib = require('zlib');
var glob = require('glob');
var DocModel = function () {
Object.defineProperty(this, "id", {
get: function() {
return this.name
}
});
Object.defineProperty(this, "name", {
get: function() {
var name = this.data.content.match('^#(.+)');
if(name) {
name = name[1];
} else {
name = '';
}
return name;
}
});
Object.defineProperty(this, "module", {
get: function() {
return this.data.module
}
});
Object.defineProperty(this, "groupId", {
get: function () {
return this.data.groupId;
},
set: function (value) {
this.data.groupId = value;
}
});
}
DocModel.prototype.setData = function (data) {
this.data = data;
}
DocModel.prototype.setPath = function (path) {
this.path = path;
}
DocModel.prototype.toJSON = function () {
var data = nodeExtend({}, this.data);
data.path = this.path;
data.name = this.name;
data.id = this.id;
data.search = data.content;
data.sortOn = data.name;
data.handler = 'markdown';
return data;
}
DocModel.prototype.hasParent = function () {
return !!this.parentDoc;
}
var Plugin = function () {
};
Plugin.prototype = nodeExtend(Plugin.prototype, {
register: function (generator) {
this._generator = generator;
generator.on('FileParse', this.parseFile.bind(this));
generator.on('CreateDocs', this.createDocs.bind(this));
generator.on('CopyFiles', this.copyFiles.bind(this));
generator.on('SetupRunConfig', this.setupConfig.bind(this));
generator.on('ProcessConfig', this.processConfig.bind(this));
},
processConfig: function (configuration, promises) {
var deferred = Q.defer();
promises.push(deferred.promise);
if(configuration.showDocularDocs) {
var dest = 'downloaded/docular/';
console.log("Fetching docular source code for documentation");
request({url: 'https://github.com/Vertafore/docular/archive/master.tar.gz', encoding: null})
.on('error', deferred.reject)
.pipe(zlib.Unzip())
.on('error', deferred.reject)
.pipe(require('tar').Extract( { path: dest } ) )
.on('error', deferred.reject)
.on('end', function () {
console.log("Adding Docular docs to configuration");
configuration.groups.push({
groupTitle: 'Docular Docs',
groupId: 'docular',
groupIcon: 'lightbulb-o',
files: glob.sync('downloaded/docular/docular-master/docs/**/*.*')
});
deferred.resolve();
});
} else {
deferred.resolve();
}
},
parseFile: function (fileData, promises) {
if(fileData.extension === 'md') {
fileData.docs.push({
file: fileData.fileName,
handler: 'markdown',
content: fileData.content
})
}
},
copyFiles: function (webappDir) {
fse.ensureDirSync(webappDir + '/resources/plugins/markdown');
fse.copySync(path.resolve(__dirname, './web'), webappDir + '/resources/plugins/markdown');
},
setupConfig: function (configuration, promises) {
configuration.angularModules.push('docular.plugin.markdown');
configuration.javascript.push('resources/plugins/markdown/markdownPlugin.js');
},
createDocs: function (doc, promises) {
if(doc.handler === 'markdown') {
promises.push(function (currentModel) {
var docModel = new DocModel();
if(!currentModel) {
docModel.setData(doc);
} else {
docModel.setData(currentModel.toJSON());
}
return Q(docModel);
});
}
}
});
module.exports = Plugin;