()
| 30 | |
| 31 | |
| 32 | function createJSFilesFromMarkdown(){ |
| 33 | console.log(chalk.green(`Building tutorial files from markdowns`)); |
| 34 | fs.readdir(TUTORIAL_PATH, function(err, items) { |
| 35 | items.forEach(function(file) { |
| 36 | var filePath = path.join(TUTORIAL_PATH, file); |
| 37 | fs.stat(filePath, function(err, stats) { |
| 38 | if (stats.isFile() && isFileOfExtension(file, MARKDOWN_FILE_EXTENSION)) { |
| 39 | fs.readFile(filePath, 'utf-8', function(err, data) { |
| 40 | const newFileName = getFileNameWithoutExtension(file) + '.js'; |
| 41 | const newFilePath = path.join(TUTORIAL_BUILD_PATH, newFileName); |
| 42 | const dataToWrite = `export default \` ${data.replace(/`/g, '\\\`')} \``; |
| 43 | fs.writeFile(newFilePath, dataToWrite, function(err) { |
| 44 | if (err) { |
| 45 | console.log(chalk.red(`Error writing file - %s`), newFilePath); |
| 46 | throw new Error(err); |
| 47 | } |
| 48 | }) |
| 49 | }) |
| 50 | } |
| 51 | }) |
| 52 | }) |
| 53 | }); |
| 54 | } |
| 55 | |
| 56 | function getFileNameWithoutExtension(filename) { |
| 57 | return filename.split('.').slice(0, -1).join('.'); |
no test coverage detected