Skip to content

Commit 2ddd191

Browse files
committed
Fix paths in Windows
1 parent 1ddb48f commit 2ddd191

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lib/insert-demos.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var fs = require('fs');
2+
var path = require('path');
23
var removePosition = require('unist-util-remove-position');
34
var u = require('unist-builder');
45
var _ = require('lodash');
@@ -12,6 +13,8 @@ var demoHeaders = {
1213
'en-US': 'Demos'
1314
}
1415

16+
var I18N_KEY_REGEXP = /\{i18n\.([^\}]*)\}/;
17+
1518
// var beautyConsole = require('./lib').beautyConsole;
1619

1720
/**
@@ -55,8 +58,9 @@ function getDemoID(filename) {
5558

5659
function extractDemos(demosPath, i18n, ctx) {
5760
var styles = [];
58-
var demos = fs.readdirSync(demosPath + '/demos').map(filename => {
59-
var filePath = demosPath + '/demos/' + filename;
61+
var demoDir = path.join(demosPath, 'demos');
62+
var demos = fs.readdirSync(demoDir).map(filename => {
63+
var filePath = path.join(demosDir, filename);
6064
ctx.addDependency(filePath)
6165
var demoAST = markdownParser.parse(fs.readFileSync(filePath, { encoding: 'utf-8' })),
6266
yamlPart = (demoAST && demoAST.children && demoAST.children[0]) || {},
@@ -67,13 +71,13 @@ function extractDemos(demosPath, i18n, ctx) {
6771
if (yamlPart.type === 'yaml') {
6872
yaml = parseYAML(yamlPart.value);
6973
} else {
70-
ctx.emitWarning(`\nYaml header in demo.md is required, ${demosPath + '/demos/' + filename} wasn't appended.\n`);
74+
ctx.emitWarning('\nYaml header in demo.md is required, ' + filePath + ' wasn\'t appended.\n');
7175
return null;
7276
}
7377

7478
// validate main content
7579
if (mainContent.type !== 'code') {
76-
ctx.emitWarning(`\nThe first 2 sections of demo.md must be yaml header and code block, ${demosPath + '/demos/' + filename} wasn't appended.\n`);
80+
ctx.emitWarning('\nThe first 2 sections of demo.md must be yaml header and code block, ' + filePath + ' wasn\'t appended.\n');
7781
return null;
7882
}
7983

@@ -96,9 +100,11 @@ function extractDemos(demosPath, i18n, ctx) {
96100
});
97101

98102
// check if any {i18n.xxx} exists after replace
99-
if (/\{i18n\.[^\}]*\}/.test(mainContent.value)) {
103+
var i18nMatchResult = I18N_KEY_REGEXP.exec(mainContent.value);
104+
if (i18nMatchResult) {
105+
var i18nMissingKey = i18nMatchResult[1];
100106
ctx.emitError(new Error(
101-
`\nUnrecognized i18n variable {i18n.${/\{i18n\.([^\}]*)\}/.exec(mainContent.value)[1]}} in ${demosPath + '/demos/' + filename}`
107+
'\nUnrecognized i18n variable {i18n.' + i18nMissingKey + '} in ' + filePath
102108
));
103109
return null;
104110
}

0 commit comments

Comments
 (0)