code-to-essay
The library essay is a code generator from a readme file but this library is a reverse operation.
Inspiration
I used eassy
and made a simple project that can generate many code files of javascript (ES7). That can create a good document because you can update code and docs in the same time. I would like to create a converter from code files structure into readme. It will be also created by essay
after convert them.
Getting started
- Install this library
npm i -g code-to-essay
- Write a pathname with prefix
c2e:
in your README.md
c2e:src/main.js
- Convert them with command
c2e
- Setting your project follow
essay
format (https://github.com/dtinth/essay)
Now, the project could be generated by essay
.
Implementation
main.js
will start first when you call c2e build
.
// main.js#!/usr/bin/env nodeconst README = const lines = READMEconst newContexts = const newDocs = newContexts
converter.js
is a module that contains
isCode
check this line is start withc2e:
that mean This line is code, right ?convertCodeToContext
convert codec2e:
to context (code and block)convertLineToContext
pass line as params and return the correct contextconvertLinesToContexts
convert all lines to contexts (array)
// converter.js const isCode = { return line === 0} const convertCodeToContext = { const pathname = line const header = `// ` const code = const end = "\`\`\`" const start = end + 'js' const context = start header code end return context} const convertLineToContext = { return ? : line} const convertLinesToContexts = { const contexts = lines return contexts}
file.js
is a module that contains
getTextFromFile
receive pathname and return textwriteFileFromText
receive text and pathname as params and write file
// file.js const projectPath = const getTextFromFile = { console return } const writeFileFromText = { console return }