Skip to content

Commit c3030e2

Browse files
committed
add eslint
1 parent c2a7676 commit c3030e2

13 files changed

+95
-45
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

.eslintrc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "standard",
3+
"globals": {
4+
"test": true,
5+
"expect": true
6+
},
7+
"rules": {
8+
"space-before-function-paren": 0,
9+
"indent": 0
10+
}
11+
}

.fiddly.config.json

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
{
2-
"name": "Fiddly",
32
"logo": "https://rawcdn.githack.com/SaraVieira/fiddly/6738c1458270f72effd8126a3090a6e5dbe9a0a6/logo.png",
4-
"description": "Create beautiful and simple HTML pages from your Readme.md files",
53
"darkTheme": true
64
}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ coverage
66
yarn.lock
77
public
88
package.lock
9+
.eslintcache

.prettierrc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"semi": false,
3+
"overrides": [
4+
{
5+
"files": "*.md",
6+
"options": {
7+
"printWidth": 70,
8+
"useTabs": false,
9+
"trailingComma": "none",
10+
"proseWrap": "never"
11+
}
12+
}
13+
]
14+
}

package.json

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"name": "fiddly",
3+
"description": "Create beautiful and simple HTML pages from your Readme.md files",
34
"version": "0.0.1",
4-
"description": "fiddly CLI",
5-
"private": true,
65
"bin": {
76
"fiddly": "bin/fiddly"
87
},
98
"scripts": {
10-
"format": "prettier --write **/*.{js,json} && standard --fix",
11-
"lint": "standard",
9+
"format": "prettier --write \"src/**/*.js\"",
10+
"lint": "eslint . --cache --fix",
11+
"pretest": "npm run lint",
1212
"test": "jest",
13+
"posttest": "npm run format",
1314
"watch": "jest --watch",
14-
"snapupdate": "jest --updateSnapshot",
1515
"coverage": "jest --coverage",
1616
"build": "./bin/fiddly"
1717
},
@@ -33,13 +33,23 @@
3333
"to-css": "^1.2.1"
3434
},
3535
"devDependencies": {
36+
"eslint": "^5.11.0",
37+
"eslint-config-standard": "^12.0.0",
38+
"eslint-plugin-import": "^2.14.0",
39+
"eslint-plugin-node": "^8.0.0",
40+
"eslint-plugin-promise": "^4.0.1",
41+
"eslint-plugin-standard": "^4.0.0",
3642
"jest": "^23.6.0",
3743
"prettier": "^1.12.1",
3844
"standard": "^12.0.1"
3945
},
4046
"jest": {
4147
"testEnvironment": "node"
4248
},
49+
"repository": {
50+
"type": "git",
51+
"url": "https://github.com/SaraVieira/fiddly"
52+
},
4353
"standard": {
4454
"env": [
4555
"jest"

src/cli.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { build } = require('gluegun')
33
/**
44
* Create the cli and kick it off
55
*/
6-
async function run (argv) {
6+
async function run(argv) {
77
// create a CLI runtime
88
const cli = build()
99
.brand('fiddly')

src/commands/css/css.css

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ header {
8080
margin: 20px 0;
8181
}
8282

83+
header h1 {
84+
text-transform: capitalize;
85+
}
86+
8387
h1 {
8488
font-family: "Playfair Display", serif;
8589
font-size: 48px;

src/commands/fiddly.js

+19-37
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ const showdown = require('showdown')
22
var toCss = require('to-css')
33
const CleanCSS = require('clean-css')
44
const createHTML = require('create-html')
5+
const corner = require('../utils/githubCorner')
6+
const capitalize = require('../utils/capitalize')
7+
const fiddlyImports = require('../utils/fiddlyImports.js')
8+
const header = require('../utils/header.js')
59

610
showdown.extension('header-anchors', function() {
711
var ancTpl =
@@ -30,25 +34,16 @@ module.exports = {
3034
name: 'fiddly',
3135
run: async toolbox => {
3236
const {
33-
parameters,
34-
template: { generate },
3537
print: { info, success },
3638
filesystem
3739
} = toolbox
3840
const options =
3941
filesystem.read(`${process.cwd()}/.fiddly.config.json`, 'json') || {}
4042
const dist = options.dist || 'public'
43+
const packageJSON =
44+
filesystem.read(`${process.cwd()}/package.json`, 'json') || {}
4145

4246
// CSS
43-
44-
const styleString = style =>
45-
Object.entries(style).reduce((styleString, [propName, propValue]) => {
46-
propName = propName.replace(
47-
/([A-Z])/g,
48-
matches => `-${matches[0].toLowerCase()}`
49-
)
50-
return `${styleString}${propName}:${propValue};`
51-
}, '')
5247
const css = filesystem.read(`${__dirname}/css/css.css`).concat(
5348
toCss(options.styles, {
5449
selector: s => `#fiddly ${s}`,
@@ -62,38 +57,25 @@ module.exports = {
6257
)
6358

6459
// HTML
65-
const name = options.file || 'Readme' || 'readme' || 'README'
66-
const markdown = filesystem.read(`${process.cwd()}/${name}.md`)
67-
68-
const header =
69-
options && !options.noHeader
70-
? `<header>${options.name ? `<h1>${options.name}</h1>` : ''}${
71-
options.logo
72-
? `<img class="logo" src="${options.logo}" alt="logo" />`
73-
: ''
74-
}</header>`
75-
: ''
60+
const file = options.file || 'Readme' || 'readme' || 'README'
61+
const markdown = filesystem.read(`${process.cwd()}/${file}.md`)
62+
const description = options.description || packageJSON.description
63+
const name = options.name || packageJSON.name
7664

7765
var html = createHTML({
78-
title: options.name,
79-
css: [
80-
'https://rawcdn.githack.com/yegor256/tacit/42137b0c4369dbc6616aef1b286cda5aff467314/tacit-css-1.3.5.min.css',
81-
'style.css',
82-
'https://unpkg.com/[email protected]/themes/prism.css'
83-
],
66+
title: capitalize(name),
67+
css: fiddlyImports.css,
8468
scriptAsync: true,
85-
script: [
86-
'https://unpkg.com/[email protected]/prism.js',
87-
'https://unpkg.com/[email protected]/components/prism-json.min.js',
88-
'https://unpkg.com/[email protected]/components/prism-bash.min.js'
89-
],
69+
script: fiddlyImports.js,
9070
lang: 'en',
91-
head: `<meta charset="utf-8" /><meta http-equiv="x-ua-compatible" content="ie=edge" /><meta name="description" content="${
92-
options.description
93-
}" /><meta name="viewport" content="width=device-width, initial-scale=1" />`,
71+
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" />`,
9472
body: `<div id="fiddly"><div class="body ${
9573
options.darkTheme ? 'dark' : ''
96-
}"><div class="container">${header}${converter.makeHtml(
74+
}"><div class="container">${
75+
packageJSON.repository
76+
? corner(packageJSON.repository.url, options.darkTheme)
77+
: ''
78+
}${header(options, name)}${converter.makeHtml(
9779
markdown
9880
)}</div></div></div>`,
9981
favicon: options.favicon || null

src/utils/capitalize.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = string => string.charAt(0).toUpperCase() + string.slice(1)

src/utils/fiddlyImports.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
exports.css = [
2+
'https://rawcdn.githack.com/yegor256/tacit/42137b0c4369dbc6616aef1b286cda5aff467314/tacit-css-1.3.5.min.css',
3+
'style.css',
4+
'https://unpkg.com/[email protected]/themes/prism.css'
5+
]
6+
7+
exports.js = [
8+
'https://unpkg.com/[email protected]/prism.js',
9+
'https://unpkg.com/[email protected]/components/prism-json.min.js',
10+
'https://unpkg.com/[email protected]/components/prism-bash.min.js'
11+
]

src/utils/githubCorner.js

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/header.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = (options, name) => {
2+
return options && !options.noHeader
3+
? `<header>${name ? `<h1>${name}</h1>` : ''}${
4+
options.logo
5+
? `<img class="logo" src="${options.logo}" alt="logo" />`
6+
: ''
7+
}</header>`
8+
: ''
9+
}

0 commit comments

Comments
 (0)