-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.js
157 lines (137 loc) · 6.02 KB
/
publish.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* @namespace jsdoc-skeleton
* @description <p>
* //
* </p>
* @author K. McCormick <https://github.com/blackdrago>
*/
// TODO: remove this
var fs = require ('jsdoc/fs');
var env = require('jsdoc/env');
var path = require('jsdoc/path');
var templateHelper = require('jsdoc/util/templateHelper');
var envUtils = require('./utils/env');
var docletUtils = require('./utils/doclet');
var arrayUtils = require('./utils/array');
var textUtils = require('./utils/text');
var htmlUtils = require('./utils/html');
var fileUtils = require('./utils/files');
var viewUtils = require('./utils/view');
var templateUtils = require('./utils/template');
var navUtils = require('./utils/nav');
/**
* @memberof jsdoc-skeleton
* @function publish
* @description <p>
* //
* </p>
* @param {TAFFY} taffyData
* @param {object} opts
* @param {Tutorial} tutorials
* @see {@link http://taffydb.com/|TaffyDB}
*/
exports.publish = function(taffyData, opts, tutorials)
{
var customLogicPath = path.join(envUtils.customDir(), 'publish.js');
if (fs.existsSync(customLogicPath)) {
var customPublish = require('./custom/publish');
customPublish.publish(taffyData, opts, tutorials);
} else {
// start by creating the output directory (if it doesn't already exist)
var outdir = envUtils.outDir();
fileUtils.createDirectory(outdir);
// copy over all the static files
var staticDirs = envUtils.staticDirs();
staticDirs.forEach(function(dir) {
fileUtils.copyAllFiles(dir, outdir);
});
// create the two primary files
var indexUrl = templateHelper.getUniqueFilename('index');
var globalUrl = templateHelper.getUniqueFilename('global');
templateHelper.registerLink('global', globalUrl);
// setup tutorials (for templateHelper)
templateHelper.setTutorials(tutorials);
// prepare taffyData for processing
var data = taffyData;
data = templateHelper.prune(data);
data.sort('longname, version, since');
templateHelper.addEventListeners(data);
// iterate over each Doclet of data
// SEE: node_modules/jsdoc/lib/jsdoc/doclet.js
var sourceFiles = [];
data().each(function(doclet) {
// process example data for this Doclet
if (doclet.examples) {
doclet.examples = docletUtils.processExamples(doclet);
}
// update any @see internal "jump" links
if (doclet.see) {
doclet.see.forEach( function(seeItem, index) {
doclet.see[index] = docletUtils.jumpHashToHtmlLink(doclet, seeItem);
});
}
// if this doclet has a source path, add it to our known sources
sourceFiles = docletUtils.addSourceFilePath(sourceFiles, doclet);
});
// if sourceFiles exist, make sure they've got 'relativePath' values
if (arrayUtils.size(sourceFiles) > 0) {
sourceFiles = fileUtils.mapRelativePaths(
sourceFiles,
path.commonPrefix(Object.keys(sourceFiles))
);
}
// iterate over the Doclets again and assign relativePaths
data().each(function(doclet) {
var url = templateHelper.createLink(doclet);
templateHelper.registerLink(doclet.longname, url);
var docletPath = docletUtils.filePath(doclet);
if (docletPath != null && sourceFiles.indexOf(docletPath) != -1) {
doclet.meta.shortpath = sourceFiles[docletPath].relativePath;
}
// assign the doclet ID
doclet = docletUtils.assignIdFromLongNameToUrl(doclet);
// assign signature components, if necessary
doclet = docletUtils.assignSignatureComponents(doclet);
// assign attributes
doclet = docletUtils.addAttribsProperty(doclet);
});
// iteration #3 over doclets (must be done AFTER all URLs are generated)
data().each(function(doclet) {
// NOTE: this function allows for a third optional parameter of 'class'
// e.g., CSS class to assign to ancestor links
doclet.ancestors = templateHelper.getAncestorLinks(data, doclet);
// given a doclet kind, assign associated signatures and attributes
if (['member', 'constant'].indexOf(doclet.kind)) {
doclet = docletUtils.addSignatureTypes(doclet);
doclet = docletUtils.addAttribsProperty(doclet);
doclet.kind = 'member';
}
});
// TODO: complete this (still in progress)
var members = templateHelper.getMembers(data);
members.tutorials = tutorials.children;
// check if we output pretty-print source files - and if so, generate them
// so that other files can link to them
var outSourceFiles = envUtils.getConfSetting(['default', 'outputSourceFiles'], false);
if (outSourceFiles) {
// TODO: code this
// generateSourceFiles(sourceFiles, opts.encoding);
}
// establish templating, assign configuration settings, and augment it with helpers
var view = {};
view.layout = envUtils.primaryLayoutFile();
view.outputSourceFiles = outSourceFiles;
view.linkto = templateHelper.linkto;
view.resolveAuthorLinks = templateHelper.resolveAuthorLinks;
view.tutoriallink = htmlUtils.tutorialLink;
view.htmlsafe = htmlUtils.htmlsafe;
// special case: find function - wrap it so that view can call find(needle)
// without specifying the haystack over and over again
view.find = function(needle) {
return templateHelper.find(data, needle);
};
// now that the essentials have been established, build the navigation menu
// TODO: complete this (still in development)
//view.nav = navUtils.generate(members);
}
}