Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit a30fdda

Browse files
committed
cleanup of shred-map logic to accommodate new api doc build
1 parent 26a1405 commit a30fdda

File tree

11 files changed

+178
-114
lines changed

11 files changed

+178
-114
lines changed

gulpfile.js

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ var fs = fsExtra;
1717
var docShredder = require('./public/doc-shredder/doc-shredder');
1818

1919
var _shredOptions = {
20-
examplesDir: path.resolve('./public/docs/_examples'),
21-
fragmentsDir: path.resolve('./public/docs/_fragments')
20+
examplesDir: './public/docs/_examples',
21+
fragmentsDir: './public/docs/_fragments'
2222
};
2323

2424
//var _apiShredOptions = {
@@ -69,7 +69,7 @@ gulp.task('shred-full', ['shred-clean'], function() {
6969
});
7070

7171
gulp.task('shred-clean', function(cb) {
72-
var cleanPath = path.join(_shredOptions.basePath, _shredOptions.fragmentsDir, '**/*.*')
72+
var cleanPath = path.join(_shredOptions.fragmentsDir, '**/*.*')
7373
del([ cleanPath, '!**/*.ovr.*'], function (err, paths) {
7474
// console.log('Deleted files/folders:\n', paths.join('\n'));
7575
cb();
@@ -121,27 +121,25 @@ gulp.task('git-changed-examples', ['shred-full'], function(){
121121
console.log(JSON.stringify(jadeExampleMap, null, " "));
122122
console.log("-----");
123123
}).catch(function(err) {
124+
console.log(err);
124125
throw err;
125126
});
126127
});
127128

128-
129129
gulp.task('build-api-docs', function() {
130130
if (!fs.existsSync('../angular')) {
131131
throw new Error('build-api-docs task requires the angular2 repo to be at ' + path.resolve('../angular'));
132132
}
133133
try {
134134
var dgeni = new Dgeni([require('./public/api-builder/angular.io-package')]);
135135
return dgeni.generate();
136-
} catch(x) {
137-
console.log(x);
138-
console.log(x.stack);
139-
throw x;
136+
} catch(err) {
137+
console.log(err);
138+
console.log(err.stack);
139+
throw err;
140140
}
141141
});
142142

143-
144-
145143
function filterOutExcludedPatterns(fileNames, excludeMatchers) {
146144
return fileNames.filter(function(fileName) {
147145
return !excludeMatchers.some(function(excludeMatcher) {
@@ -152,8 +150,8 @@ function filterOutExcludedPatterns(fileNames, excludeMatchers) {
152150

153151
function buildShredMaps(shouldWrite) {
154152
var options = _.extend(_shredOptions, {
155-
jadeDir: '.',
156-
outputDir: '.',
153+
jadeDir: './public/docs',
154+
outputDir: './public/docs',
157155
writeFilesEnabled: shouldWrite
158156
});
159157
return docShredder.buildShredMap(options).then(function(docs) {
@@ -163,7 +161,7 @@ function buildShredMaps(shouldWrite) {
163161

164162
// returns a promise containing filePaths with any changed or added examples;
165163
function getChangedExamples(sha) {
166-
var examplesPath = path.join(_shredOptions.basePath, _shredOptions.examplesDir);
164+
var examplesPath = _shredOptions.examplesDir;
167165
var relativePath = path.relative(process.cwd(), examplesPath);
168166
return Git.Repository.open(".").then(function(repo) {
169167
if (sha.length) {
@@ -179,7 +177,7 @@ function getChangedExamples(sha) {
179177
}
180178

181179
function getChangedExamplesAfter(date, relativePath) {
182-
var examplesPath = path.join(_shredOptions.basePath, _shredOptions.examplesDir);
180+
var examplesPath = _shredOptions.examplesDir;
183181
var relativePath = path.relative(process.cwd(), examplesPath);
184182
return Git.Repository.open(".").then(function(repo) {
185183
return repo.getHeadCommit();
@@ -241,36 +239,36 @@ function shredWatch(shredOptions, postShredAction) {
241239
}
242240

243241
function jadeShredMapToJadeExampleMap(jadeShredMap, examplePaths) {
242+
// remove dups in examplePaths
244243
var exampleSet = {};
245244
examplePaths.forEach(function(examplePath) {
246245
exampleSet[examplePath] = examplePath;
247246
});
248-
var basePath = jadeShredMap.basePath;
247+
var basePath = path.resolve(".");
249248
var jadeToFragMap = jadeShredMap.jadeToFragMap;
250249
var jadeExampleMap = {};
251250
for (var jadePath in jadeToFragMap) {
252-
var fullJadePath = path.join(basePath, jadePath);
251+
var relativeJadePath = path.relative(basePath, jadePath);
253252
var vals = jadeToFragMap[jadePath];
254253
vals.forEach(function(val) {
255-
var examplePath = path.join(basePath, val.examplePath);
256-
if (exampleSet[examplePath] != null) {
257-
addKeyValue(jadeExampleMap, fullJadePath, examplePath);
254+
var relativeExamplePath = path.relative(basePath, val.examplePath);
255+
if (exampleSet[relativeExamplePath] != null) {
256+
addKeyValue(jadeExampleMap, relativeJadePath, relativeExamplePath);
258257
}
259258
});
260259
}
261260
return jadeExampleMap;
262261
}
263262

264263
function jadeShredMapToExampleJadeMap(jadeShredMap) {
265-
var basePath = jadeShredMap.basePath;
264+
266265
var jadeToFragMap = jadeShredMap.jadeToFragMap;
267266
var exampleJadeMap = {};
268267
for (var jadePath in jadeToFragMap) {
269-
var fullJadePath = path.join(basePath, jadePath);
270268
var vals = jadeToFragMap[jadePath];
271269
vals.forEach(function(val) {
272-
var examplePath = path.join(basePath, val.examplePath);
273-
addKeyValue(exampleJadeMap, examplePath, fullJadePath);
270+
var examplePath = val.examplePath;
271+
addKeyValue(exampleJadeMap, examplePath, jadePath);
274272
});
275273
}
276274
return exampleJadeMap;
@@ -287,9 +285,10 @@ function addKeyValue(map, key, value) {
287285
}
288286
}
289287

290-
291-
// added options are: shouldLog
292-
// cb is function(err, stdout, stderr);
288+
// Synchronously execute a chain of commands.
289+
// cmds: an array of commands
290+
// options: { shouldLog: true, shouldThrow: true }
291+
// cb: function(err, stdout, stderr)
293292
function execCommands(cmds, options, cb) {
294293
options = options || {};
295294
options.shouldThrow = options.shouldThrow == null ? true : options.shouldThrow;

public/doc-shredder/doc-shredder.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@ var delPromise = Q.denodeify(del);
77
var Dgeni = require('dgeni');
88
var _ = require('lodash');
99

10-
11-
1210
var shred = function(shredOptions) {
1311
try {
1412
var pkg = createShredPackage(shredOptions);
1513
var dgeni = new Dgeni([ pkg]);
1614
return dgeni.generate();
17-
} catch(x) {
18-
console.log(x.stack);
19-
throw x;
15+
} catch(err) {
16+
console.log(err);
17+
console.log(err.stack);
18+
throw err;
2019
}
2120
}
2221

@@ -43,9 +42,10 @@ var buildShredMap = function(shredMapOptions) {
4342
var pkg = createShredMapPackage(shredMapOptions);
4443
var dgeni = new Dgeni([ pkg]);
4544
return dgeni.generate();
46-
} catch(x) {
47-
console.log(x.stack);
48-
throw x;
45+
} catch(err) {
46+
console.log(err);
47+
console.log(err.stack);
48+
throw err;
4949
}
5050
}
5151

@@ -94,7 +94,7 @@ function createShredPackage(shredOptions) {
9494
})
9595
.config(function(writeFilesProcessor) {
9696
// Specify where the writeFilesProcessor will write our generated doc files
97-
writeFilesProcessor.outputFolder = options.fragmentsDir;
97+
writeFilesProcessor.outputFolder = path.resolve(options.fragmentsDir);
9898
});
9999
return pkg;
100100
}
@@ -118,7 +118,7 @@ var createShredMapPackage = function(mapOptions) {
118118
// default configs - may be overriden
119119
.config(function(readFilesProcessor) {
120120
// Specify the base path used when resolving relative paths to source and output files
121-
readFilesProcessor.basePath = '/'; // options.basePath;
121+
readFilesProcessor.basePath = '/';
122122

123123
// Specify collections of source files that should contain the documentation to extract
124124
var extns = ['*.jade' ];
@@ -145,7 +145,7 @@ var createShredMapPackage = function(mapOptions) {
145145
unescapeCommentsProcessor.$enabled = false;
146146
} else {
147147
// Specify where the writeFilesProcessor will write our generated doc files
148-
writeFilesProcessor.outputFolder = options.outputDir;
148+
writeFilesProcessor.outputFolder = path.resolve(options.outputDir);
149149
}
150150
})
151151
.config(function(templateFinder) {
@@ -181,25 +181,33 @@ var createShredMapPackage = function(mapOptions) {
181181
}
182182

183183
function resolveShredOptions(shredOptions) {
184-
return _.defaults({}, shredOptions, {
184+
var so = _.defaults({}, shredOptions, {
185185
// read files from any subdir under here
186-
examplesDir: path.resolve("./docs/_examples"),
186+
examplesDir: "./docs/_examples",
187187
// shredded files get copied here with same subdir structure.
188-
fragmentsDir: path.resolve("./docs/_fragments"),
188+
fragmentsDir: "./docs/_fragments",
189189
// whether to include subdirectories when shredding.
190190
includeSubdirs: true
191191
});
192+
193+
so.examplesDir = path.resolve(so.examplesDir);
194+
so.fragmentsDir = path.resolve(so.fragmentsDir);
195+
return so;
192196
}
193197

194198
function resolveMapOptions(mapOptions) {
195-
return _.defaults({}, mapOptions, {
199+
var so = _.defaults({}, mapOptions, {
196200
// read files from any subdir under here
197-
jadeDir: path.resolve("./docs"),
198-
fragmentsDir: path.resolve("./docs/_fragments"),
199-
examplesDir: path.resolve("./docs/_examples"),
201+
jadeDir: "./docs",
202+
fragmentsDir: "./docs/_fragments",
203+
examplesDir: "./docs/_examples",
200204
// whether to include subdirectories when shredding.
201205
includeSubdirs: true
202206
});
207+
so.jadeDir = path.resolve(so.jadeDir);
208+
so.examplesDir = path.resolve(so.examplesDir);
209+
so.fragmentsDir = path.resolve(so.fragmentsDir);
210+
return so;
203211
}
204212

205213
function initializePackage(pkg) {

public/doc-shredder/fileShredder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = function fileShredder(log, regionExtractor) {
2424
default:
2525
return [];
2626
}
27-
log.info("fileShredder processing: " + fileInfo.projectRelativePath);
27+
log.info("fileShredder processing: " + fileInfo.relativePath);
2828
if (commentMarkers) {
2929
return regionExtractor(fileInfo.content, commentMarkers);
3030
} else {

public/doc-shredder/shredMapProcessor.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,29 @@ module.exports = function shredMapProcessor(log) {
1919

2020
docs.forEach(function(doc) {
2121
var jadePath = path.join(options.jadeDir, doc.fileInfo.relativePath);
22-
var fragInfos = doc.fragPaths.map(function(fragPath) {
23-
var relativeFragPath = path.join(options.fragmentsDir, fragPath) + '.md';
24-
var fullPath = path.join(options.basePath, relativeFragPath);
25-
22+
var fragInfoSet = {};
23+
doc.fragPaths.forEach(function(fragPath) {
24+
var fullFragPath = path.join(options.fragmentsDir, fragPath) + '.md';
2625
var examplePath = getExampleName(fragPath);
27-
var relativeExamplePath = path.join(options.examplesDir, examplePath);
28-
var fragInfo = { fragPath: relativeFragPath, examplePath: relativeExamplePath, exists: fs.existsSync(fullPath) };
26+
var fullExamplePath = path.join(options.examplesDir, examplePath);
27+
var fragInfo = { fragPath: fullFragPath, examplePath: fullExamplePath, exists: fs.existsSync(fullFragPath) };
28+
fragInfoSet[fragPath] = fragInfo;
2929
if (fragInfo.exists) {
30-
var jadePaths = fragToJadeMap[fragInfo];
31-
if (!jadePaths) {
32-
jadePaths = [];
33-
fragToJadeMap[fragPath] = jadePaths;
30+
var jadePathsSet = fragToJadeMap[fragPath];
31+
if (!jadePathsSet) {
32+
jadePathsSet = {};
33+
fragToJadeMap[fragPath] = jadePathsSet;
3434
}
35-
jadePaths.push(jadePath);
35+
jadePathsSet[jadePath] = jadePath;
3636
}
37-
return fragInfo;
3837
});
39-
jadeToFragMap[jadePath] = fragInfos;
38+
jadeToFragMap[jadePath] = _.values(fragInfoSet);
4039
});
41-
var basePath = path.relative(process.cwd(), this.options.basePath);
40+
for (var key in fragToJadeMap) {
41+
fragToJadeMap[key] = _.keys(fragToJadeMap[key]);
42+
}
43+
4244
var shredMap = {
43-
basePath: basePath,
4445
jadeToFragMap: jadeToFragMap
4546
};
4647

@@ -53,12 +54,10 @@ module.exports = function shredMapProcessor(log) {
5354
outputPath: 'xref-jade.json'
5455
}, {
5556
docType: 'xref-jade.html',
56-
basePath: basePath,
5757
jadeToFragMap: jadeToFragMap,
5858
outputPath: 'xref-jade-to-frag.html'
5959
}, {
6060
docType: 'xref-frag.html',
61-
basePath: basePath,
6261
fragToJadeMap: fragToJadeMap,
6362
outputPath: 'xref-frag-to-jade.html'
6463
}];

public/doc-shredder/xref-frag.html.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<h1> Frament path to jade path cross reference report
22

3-
<p>Base path: {{ doc.basePath }}</p>
43
<ol>
54
{% for fragPath, jadePaths in doc.fragToJadeMap %}
65
<li>

public/doc-shredder/xref-jade.html.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<h1> Jade path to fragment path cross reference report
22

3-
<p>Base path: {{ doc.basePath }}</p>
43
<ol>
54
{% for jadePath, fragInfos in doc.jadeToFragMap %}
65
<li>

public/docs/_examples/styleguide/js/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
<script src="app.js"></script>
77
</head>
88
<body>
9-
<my-app></my-app>
9+
<my-app>foo2</my-app>
1010
</body>
1111
</html>

public/docs/_fragments/styleguide/js/index.html.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<script src="app.js"></script>
77
</head>
88
<body>
9-
<my-app></my-app>
9+
<my-app>foo2</my-app>
1010
</body>
1111
</html>
1212

0 commit comments

Comments
 (0)