MCPcopy Index your code
hub / github.com/tyroprogrammer/learn-react-app / createJSFilesFromMarkdown

Function createJSFilesFromMarkdown

scripts/processMarkdown.js:32–54  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30
31
32function 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
56function getFileNameWithoutExtension(filename) {
57 return filename.split('.').slice(0, -1).join('.');

Callers 1

processMarkdown.jsFile · 0.85

Calls 3

isFileOfExtensionFunction · 0.85
readFileMethod · 0.80

Tested by

no test coverage detected