Skip to content

Commit

Permalink
add eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
SaraVieira committed Dec 23, 2018
1 parent c2a7676 commit c3030e2
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 45 deletions.
1 change: 1 addition & 0 deletions .eslintignore
@@ -0,0 +1 @@
node_modules/
11 changes: 11 additions & 0 deletions .eslintrc
@@ -0,0 +1,11 @@
{
"extends": "standard",
"globals": {
"test": true,
"expect": true
},
"rules": {
"space-before-function-paren": 0,
"indent": 0
}
}
2 changes: 0 additions & 2 deletions .fiddly.config.json
@@ -1,6 +1,4 @@
{
"name": "Fiddly",
"logo": "https://rawcdn.githack.com/SaraVieira/fiddly/6738c1458270f72effd8126a3090a6e5dbe9a0a6/logo.png",
"description": "Create beautiful and simple HTML pages from your Readme.md files",
"darkTheme": true
}
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,3 +6,4 @@ coverage
yarn.lock
public
package.lock
.eslintcache
14 changes: 14 additions & 0 deletions .prettierrc
@@ -0,0 +1,14 @@
{
"semi": false,
"overrides": [
{
"files": "*.md",
"options": {
"printWidth": 70,
"useTabs": false,
"trailingComma": "none",
"proseWrap": "never"
}
}
]
}
20 changes: 15 additions & 5 deletions package.json
@@ -1,17 +1,17 @@
{
"name": "fiddly",
"description": "Create beautiful and simple HTML pages from your Readme.md files",
"version": "0.0.1",
"description": "fiddly CLI",
"private": true,
"bin": {
"fiddly": "bin/fiddly"
},
"scripts": {
"format": "prettier --write **/*.{js,json} && standard --fix",
"lint": "standard",
"format": "prettier --write \"src/**/*.js\"",
"lint": "eslint . --cache --fix",
"pretest": "npm run lint",
"test": "jest",
"posttest": "npm run format",
"watch": "jest --watch",
"snapupdate": "jest --updateSnapshot",
"coverage": "jest --coverage",
"build": "./bin/fiddly"
},
Expand All @@ -33,13 +33,23 @@
"to-css": "^1.2.1"
},
"devDependencies": {
"eslint": "^5.11.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"jest": "^23.6.0",
"prettier": "^1.12.1",
"standard": "^12.0.1"
},
"jest": {
"testEnvironment": "node"
},
"repository": {
"type": "git",
"url": "https://github.com/SaraVieira/fiddly"
},
"standard": {
"env": [
"jest"
Expand Down
2 changes: 1 addition & 1 deletion src/cli.js
Expand Up @@ -3,7 +3,7 @@ const { build } = require('gluegun')
/**
* Create the cli and kick it off
*/
async function run (argv) {
async function run(argv) {
// create a CLI runtime
const cli = build()
.brand('fiddly')
Expand Down
4 changes: 4 additions & 0 deletions src/commands/css/css.css
Expand Up @@ -80,6 +80,10 @@ header {
margin: 20px 0;
}

header h1 {
text-transform: capitalize;
}

h1 {
font-family: "Playfair Display", serif;
font-size: 48px;
Expand Down
56 changes: 19 additions & 37 deletions src/commands/fiddly.js
Expand Up @@ -2,6 +2,10 @@ const showdown = require('showdown')
var toCss = require('to-css')
const CleanCSS = require('clean-css')
const createHTML = require('create-html')
const corner = require('../utils/githubCorner')
const capitalize = require('../utils/capitalize')
const fiddlyImports = require('../utils/fiddlyImports.js')
const header = require('../utils/header.js')

showdown.extension('header-anchors', function() {
var ancTpl =
Expand Down Expand Up @@ -30,25 +34,16 @@ module.exports = {
name: 'fiddly',
run: async toolbox => {
const {
parameters,
template: { generate },
print: { info, success },
filesystem
} = toolbox
const options =
filesystem.read(`${process.cwd()}/.fiddly.config.json`, 'json') || {}
const dist = options.dist || 'public'
const packageJSON =
filesystem.read(`${process.cwd()}/package.json`, 'json') || {}

// CSS

const styleString = style =>
Object.entries(style).reduce((styleString, [propName, propValue]) => {
propName = propName.replace(
/([A-Z])/g,
matches => `-${matches[0].toLowerCase()}`
)
return `${styleString}${propName}:${propValue};`
}, '')
const css = filesystem.read(`${__dirname}/css/css.css`).concat(
toCss(options.styles, {
selector: s => `#fiddly ${s}`,
Expand All @@ -62,38 +57,25 @@ module.exports = {
)

// HTML
const name = options.file || 'Readme' || 'readme' || 'README'
const markdown = filesystem.read(`${process.cwd()}/${name}.md`)

const header =
options && !options.noHeader
? `<header>${options.name ? `<h1>${options.name}</h1>` : ''}${
options.logo
? `<img class="logo" src="${options.logo}" alt="logo" />`
: ''
}</header>`
: ''
const file = options.file || 'Readme' || 'readme' || 'README'
const markdown = filesystem.read(`${process.cwd()}/${file}.md`)
const description = options.description || packageJSON.description
const name = options.name || packageJSON.name

var html = createHTML({
title: options.name,
css: [
'https://rawcdn.githack.com/yegor256/tacit/42137b0c4369dbc6616aef1b286cda5aff467314/tacit-css-1.3.5.min.css',
'style.css',
'https://unpkg.com/prismjs@1.15.0/themes/prism.css'
],
title: capitalize(name),
css: fiddlyImports.css,
scriptAsync: true,
script: [
'https://unpkg.com/prismjs@1.15.0/prism.js',
'https://unpkg.com/prismjs@1.15.0/components/prism-json.min.js',
'https://unpkg.com/prismjs@1.15.0/components/prism-bash.min.js'
],
script: fiddlyImports.js,
lang: 'en',
head: `<meta charset="utf-8" /><meta http-equiv="x-ua-compatible" content="ie=edge" /><meta name="description" content="${
options.description
}" /><meta name="viewport" content="width=device-width, initial-scale=1" />`,
head: `<meta charset="utf-8" /><meta http-equiv="x-ua-compatible" content="ie=edge" /><meta name="description" content="${description}" /><meta name="viewport" content="width=device-width, initial-scale=1" />`,
body: `<div id="fiddly"><div class="body ${
options.darkTheme ? 'dark' : ''
}"><div class="container">${header}${converter.makeHtml(
}"><div class="container">${
packageJSON.repository
? corner(packageJSON.repository.url, options.darkTheme)
: ''
}${header(options, name)}${converter.makeHtml(
markdown
)}</div></div></div>`,
favicon: options.favicon || null
Expand Down
1 change: 1 addition & 0 deletions src/utils/capitalize.js
@@ -0,0 +1 @@
module.exports = string => string.charAt(0).toUpperCase() + string.slice(1)
11 changes: 11 additions & 0 deletions src/utils/fiddlyImports.js
@@ -0,0 +1,11 @@
exports.css = [
'https://rawcdn.githack.com/yegor256/tacit/42137b0c4369dbc6616aef1b286cda5aff467314/tacit-css-1.3.5.min.css',
'style.css',
'https://unpkg.com/prismjs@1.15.0/themes/prism.css'
]

exports.js = [
'https://unpkg.com/prismjs@1.15.0/prism.js',
'https://unpkg.com/prismjs@1.15.0/components/prism-json.min.js',
'https://unpkg.com/prismjs@1.15.0/components/prism-bash.min.js'
]
8 changes: 8 additions & 0 deletions src/utils/githubCorner.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/utils/header.js
@@ -0,0 +1,9 @@
module.exports = (options, name) => {
return options && !options.noHeader
? `<header>${name ? `<h1>${name}</h1>` : ''}${
options.logo
? `<img class="logo" src="${options.logo}" alt="logo" />`
: ''
}</header>`
: ''
}

0 comments on commit c3030e2

Please sign in to comment.