Skip to content
Permalink
Browse files

Scaffold out project structure / dependencies

  • Loading branch information...
thesephist committed Jan 10, 2019
1 parent 0081c02 commit 0fb83e64b9fb21a9f20716f3de800fd404142fb6
Showing with 499 additions and 2 deletions.
  1. +3 −0 .gitignore
  2. +9 −1 README.md
  3. +4 −0 litterate.config.js
  4. +18 −1 package.json
  5. +11 −0 src/defaults.js
  6. +37 −0 src/generate.js
  7. +37 −0 src/index.js
  8. +28 −0 templates/index.html
  9. +97 −0 templates/main.css
  10. +31 −0 templates/source.html
  11. 0 test/test.js
  12. +224 −0 yarn.lock
@@ -1,3 +1,6 @@
# Litterate
coverage/

# Logs
logs
*.log
@@ -1,2 +1,10 @@
# litterate
Generate beautiful literate programming-style description of your code from comment annotations

Litterate is a command line tool to generate beautiful literate programming-style description of your code from comment annotations.

It's just being built, but feel free to check out what the output may look like when it's done, on [the documentation page for Torus](https://thesephist.github.io/torus/torus.js.html).

## Contributing

- `yarn install` to install dependencies (npm should work for these commands too, but the project prefers Yarn and we use a Yarn lockfile.)
- `yarn test` to run tests
@@ -0,0 +1,4 @@
//> This is the litterate configuration file for litterate itself.
module.exports = {
// use defaults everything for now.
}
@@ -5,5 +5,22 @@
"main": "src/index.js",
"repository": "git@github.com:thesephist/litterate.git",
"author": "Linus Lee <linus@thesephist.com>",
"license": "MIT"
"license": "MIT",
"scripts": {
"self": "node ./src/index.js",
"test": "mocha test/"
},
"bin": {
"litterate": "./src/index.js"
},
"dependencies": {
"glob": "^7.1.3",
"marked": "^0.6.0",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^5.2.0"
}
}
@@ -0,0 +1,11 @@
//> The default configuration file if the user doesn't specify a value
// for any options
module.exports = {
files: [
'./src/*.js',
],
//> We default to this because this is where GitHub Pages pulls from.
outputDirectory: './docs/',
annotationBlockFirst: '//>',
annotationBlockRest: '//',
}
@@ -0,0 +1,37 @@
//> This file contains the bulk of the logic for generating
// litterate pages. This file exports a function that the
// command-line utility calls with configurations.

const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp');
const marked = require('marked');

const INDEX_PAGE = fs.readFileSync(path.resolve(__dirname, '../templates/index.html'));
const SOURCE_PAGE = fs.readFileSync(path.resolve(__dirname, '../templates/source.html'));

const resolveTemplate = (templateContent, templateValues) => {
for (const [key, value] of Object.entries(templateValues)) {
templateContent = templateContent.replace(
new RegExp(`/{{${key}}}/`, 'g'),
value
);
}
return templateContent;
}

const createAndSavePage = async (sourcePath) => {
// TODO
}

const generateLitteratePages = async ({
files,
outputDirectory,
//... other options to come
}) => {

}

module.exports = {
generateLitteratePages,
}
@@ -0,0 +1,37 @@
//> This file is the entry point for the command-line utility,
// and is focused on handling processing CLI arguments and
// figuring out the right options to pass to the docs generator.

//> We use `minimist` to parse command line arguments (`process.argv`)
const minimist = require('minimist');
const DEFAULTS = require('./defaults.js');
const { generateLitteratePages } = require('./generate.js');

//> Read + parse command line arguments into a dictionary (object)
const ARGS = minimist(process.argv.slice(2));

const userConfigPath = ARGS['config'] || '../litterate.config.js';
const USER_CONFIG = require(userConfigPath);
const CONFIG = Object.assign(
{},
DEFAULTS,
USER_CONFIG
);

//> Reconcile `ARGS` and `CONFIG` together; `ARGS` overrides
// any `CONFIG` file option.
for (const [optionName, optionValue] of Object.entries(ARGS)) {
switch (optionName) {
case '_':
CONFIG.files = optionValue;
break;
case 'o':
case 'output':
CONFIG.output = optionValue;
break;
default:
throw new Error(`${optionName} is not a valid option, but was set to ${optionValue}`);
}
}

generateLitteratePages(CONFIG);
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>{{title}}</title>
<link rel="stylesheet" href="main.css">
</head>

<body>
<main>
<div class="line">
<div class="doc">
<h1>{{title}}</h1>
{{descriptionParagraphs}}

<hr>

<p><strong>Annotated source files</strong></p>
{{sourcesList}}
</div>
<pre></pre>
</div>
</main>
</body>

</html>
@@ -0,0 +1,97 @@
html,
body {
margin: 0;
padding: 0;
font-family: 'Helvetica', 'Arial', sans-serif;
}
main {
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: left;
margin: 0 auto;
background: #f8f8f8;
}
h1,
h2,
h3,
h4,
h5,
h6 {
font-weight: normal;
line-height: 1.3em;
}
.line {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: flex-end;
font-size: 16px;
}
.line:first-child .doc {
padding-top: 64px;
}
.line:last-child .doc {
padding-bottom: 64px;
}
.line:last-child {
align-items: flex-start;
}
.doc {
min-height: 24px;
width: 380px;
line-height: 1.5em;
flex-shrink: 0;
flex-grow: 0;
padding-left: 32px;
padding-right: 32px;
background: #fff;
}
.doc p {
margin: 0;
}
pre {
margin: 0;
margin-left: 8px;
line-height: 1.5em;
font-size: 14px;
}
code {
font-size: .9em;
background: #f8f8f8;
box-sizing: border-box;
padding: 2px 4px;
border: 1px solid #aaa;
}
pre,
code {
font-family: 'Menlo', 'Monaco', monospace;
overflow: hidden !important; /* override hljs's scroll style */
}
.source .lineNumber {
font-weight: normal;
opacity: .2;
margin-right: 18px;
width: 36px;
text-align: right;
display: inline-block;
}
.hljs {
padding: 0 !important;
background: transparent !important;
}
.fade {
opacity: .35;
}
a {
opacity: .8;
color: #777;
display: inline-block;
margin-bottom: 18px;
}
p a {
margin-bottom: 0;
}
a:hover {
opacity: 1;
}
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>{{title}} annotated source</title>
<link rel="stylesheet" href="main.css">
</head>

<body>
<main>
<div class="line">
<div class="doc">
<h1>{{title}} <span class="fade">annotated source</span></h1>
<em><a class="back" href="./">Back to index</a></em>
</div>
<pre></pre>
</div>
{{lines}}
</main>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/github-gist.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js"></script>
<script>
for (const el of document.querySelectorAll('.line pre')) {
hljs.highlightBlock(el);
}
</script>
</body>

</html>
No changes.

0 comments on commit 0fb83e6

Please sign in to comment.
You can’t perform that action at this time.