Skip to content

Commit 3e62d68

Browse files
authored
Merge pull request #2 from markdown-doc/feature/fancy_doc-next
[hotfix] 更改依赖注入的方式,加速rebuild过程
2 parents 53d253f + ac6b1da commit 3e62d68

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

lib/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ var markdownParser = require('./parser');
22
var insertDemos = require('./insert-demos');
33
var consolidateStyles = require('./consolidate-styles');
44

5-
// var beautyConsole = require('./lib').beautyConsole;
6-
75
/**
86
* 输出的sections中:
97
*
@@ -16,6 +14,5 @@ module.exports = function(content) {
1614
var ast = markdownParser.parse(content);
1715
var sections = insertDemos(ast, this);
1816
sections = consolidateStyles(sections);
19-
// beautyConsole(sections);
2017
return sections;
2118
};

lib/insert-demos.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ function getDemoID(filename) {
4444
return names.map(name => name.charAt(0).toUpperCase() + name.slice(1)).join('');
4545
}
4646

47-
function extractDemos(demosPath, i18n) {
47+
function extractDemos(demosPath, i18n, ctx) {
4848
var styles = [];
4949
var demos = fs.readdirSync(demosPath + '/demos').map(filename => {
50-
var demoAST = markdownParser.parse(fs.readFileSync(demosPath + '/demos/' + filename, { encoding: 'utf-8' })),
50+
var filePath = demosPath + '/demos/' + filename;
51+
ctx.addDependency(filePath)
52+
var demoAST = markdownParser.parse(fs.readFileSync(filePath, { encoding: 'utf-8' })),
5153
yaml;
5254
removePosition(demoAST, true);
5355

@@ -129,13 +131,12 @@ module.exports = function transformer(tree, ctx) {
129131
numberOfTopLevelNodes = nodes.length,
130132
path = ctx.context,
131133
i18n = extractI18N(ctx.resourcePath);
132-
ctx.addContextDependency(path + '/demos');
133134

134135
while (i < numberOfTopLevelNodes) {
135136
if (isAPIHeader(nodes[i]) && dirExists(path + '/demos')) {
136137
saveRoot(contentRoot);
137138
contentRoot = undefined;
138-
var demos = extractDemos(path, i18n);
139+
var demos = extractDemos(path, i18n, ctx);
139140
demos.forEach(function(demo) {
140141
addDemo(demo);
141142

0 commit comments

Comments
 (0)