UNPKG

1.1 kBJavaScriptView Raw
1/**
2 * Copyright 2017 Google Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17const markdownToc = require('markdown-toc');
18const Message = require('./Message');
19
20/**
21 * @param {!Array<!Source>} sources
22 * @return {!Array<!Message>}
23 */
24module.exports = function(sources) {
25 const warnings = [];
26 for (const source of sources) {
27 const newText = markdownToc.insert(source.text());
28 if (source.setText(newText))
29 warnings.push('Regenerated table-of-contexts: ' + source.projectPath());
30 }
31 return warnings.map(warning => Message.warning(warning));
32};