Skip to content

Commit

Permalink
add eslint, precommit & refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
endiliey committed Jun 30, 2018
1 parent 0b10b19 commit 38e5668
Show file tree
Hide file tree
Showing 19 changed files with 4,857 additions and 2,192 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- run: *yarn
- save-cache: *save-yarn-cache
- run:
name: Check Prettier
name: Check Prettier & ESLint
command: yarn ci-check
- run:
name: Run Test Suites
Expand Down
16 changes: 16 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": ["fbjs", "prettier"],
"rules": {
"no-console": 0,
"radix": 0,
"no-unused-vars": 2
},
"overrides": [
{
"files": [ "examples/**/*.js" ],
"rules": {
"no-unused-vars": 0
}
}
]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

node_modules

.eslintcache
lib/core/metadata.js
lib/core/MetadataBlog.js
lib/pages/
Expand Down
5 changes: 2 additions & 3 deletions lib/__tests__/build-files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ beforeAll(() => {
});
});

function afterAll() {
afterAll(() => {
clearBuildFolder();
}
});

test('Build folder exists', function() {
return fs.stat(buildDir).then(function(status) {
Expand All @@ -73,7 +73,6 @@ test('Generated HTML for each Markdown resource', function() {
metadata.push(path.basename());
});
inputMarkdownFiles.forEach(function(file) {
const path = filepath.create(file);
const data = fs.readFileSync(file, 'utf8');
const frontmatter = fm(data);
expect(metadata).toContain(frontmatter.attributes.id + '.html');
Expand Down
2 changes: 0 additions & 2 deletions lib/core/DocsSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

const Metadata = require('./metadata.js');
const React = require('react');
const Container = require('./Container.js');
const SideNav = require('./nav/SideNav.js');
const siteConfig = require(process.cwd() + '/siteConfig.js');
const readCategories = require('../server/readCategories.js');

class DocsSidebar extends React.Component {
Expand Down
7 changes: 0 additions & 7 deletions lib/core/Redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
*/

const React = require('react');
const fs = require('fs');
const Head = require('./Head.js');
const translation = require('../server/translation.js');

const CWD = process.cwd();

// Component used to provide same head, header, footer, other scripts to all pages
class Redirect extends React.Component {
render() {
Expand All @@ -28,13 +25,9 @@ class Redirect extends React.Component {
this.props.config.url +
this.props.config.baseUrl +
(this.props.url || 'index.html');
let latestVersion;

const redirect = this.props.redirect || false;

if (fs.existsSync(CWD + '/versions.json')) {
latestVersion = require(CWD + '/versions.json')[0];
}
return (
<html>
<Head
Expand Down
2 changes: 0 additions & 2 deletions lib/core/Remarkable.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
const React = require('react');
const renderMarkdown = require('./renderMarkdown.js');

const CWD = process.cwd();

class Remarkable extends React.Component {
content() {
if (this.props.source) {
Expand Down
1 change: 0 additions & 1 deletion lib/core/Site.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

const React = require('react');
const fs = require('fs');
const classNames = require('classnames');

const HeaderNav = require('./nav/HeaderNav.js');
const Head = require('./Head.js');
Expand Down
6 changes: 3 additions & 3 deletions lib/publish-gh-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ shell.exec('git rm -rf .');

shell.cd('../..');

fromPath = path.join('build', `${PROJECT_NAME}`);
toPath = path.join('build', `${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`);
const fromPath = path.join('build', `${PROJECT_NAME}`);
const toPath = path.join('build', `${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`);
// In github.io case, project is deployed to root. Need to not recursively
// copy the deployment-branch to be.
excludePath = `${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`;
const excludePath = `${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`;

// cannot use shell.cp because it doesn't support copying dotfiles and we
// need to copy directories like .circleci, for example
Expand Down
1 change: 0 additions & 1 deletion lib/rename-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const chalk = require('chalk');
const fs = require('fs');
const glob = require('glob');
const path = require('path');
const readMetadata = require('./server/readMetadata.js');
const metadataUtils = require('./server/metadataUtils.js');

const CWD = process.cwd();
Expand Down
20 changes: 1 addition & 19 deletions lib/server/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,17 @@
* LICENSE file in the root directory of this source tree.
*/

const fs = require('fs-extra');
const path = require('path');
const os = require('os');
const Feed = require('feed');

const chalk = require('chalk');
const CWD = process.cwd();

const siteConfig = require(CWD + '/siteConfig.js');

const blogFolder = path.resolve('../blog/');
const readMetadata = require('./readMetadata.js');
const blogRootURL = siteConfig.url + siteConfig.baseUrl + 'blog';
const siteImageURL =
siteConfig.url + siteConfig.baseUrl + siteConfig.headerIcon;
const utils = require('../core/utils');

const renderMarkdown = require('../core/renderMarkdown.js');

/****************************************************************************/

let readMetadata;
let Metadata;

readMetadata = require('./readMetadata.js');
readMetadata.generateMetadataDocs();
Metadata = require('../core/metadata.js');

/****************************************************************************/

module.exports = function(type) {
console.log('feed.js triggered...');

Expand Down
12 changes: 5 additions & 7 deletions lib/server/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
*/

async function execute() {
const extractTranslations = require('../write-translations.js');

const metadataUtils = require('./metadataUtils');

const CWD = process.cwd();
const cssnano = require('cssnano');
const fs = require('fs-extra');
const readMetadata = require('./readMetadata.js');
const path = require('path');
const color = require('color');
const getTOC = require('../core/getTOC.js');
const React = require('react');
const mkdirp = require('mkdirp');
Expand Down Expand Up @@ -321,9 +318,11 @@ async function execute() {

// create sitemap
if (MetadataBlog.length > 0 || Object.keys(Metadata).length > 0) {
let targetFile = join(buildDir, 'sitemap.xml');
sitemap(xml => {
writeFileAndCreateFolder(targetFile, xml);
sitemap((err, xml) => {
if (!err) {
const targetFile = join(buildDir, 'sitemap.xml');
writeFileAndCreateFolder(targetFile, xml);
}
});
}

Expand Down Expand Up @@ -454,7 +453,6 @@ async function execute() {
fs.writeFileSync(mainCss, css);

// compile/copy pages from user
let pagesArr = [];
files = glob.sync(join(CWD, 'pages', '**'));
files.forEach(file => {
// Why normalize? In case we are on Windows.
Expand Down
3 changes: 0 additions & 3 deletions lib/server/readMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const CWD = process.cwd();
const path = require('path');
const fs = require('fs');
const glob = require('glob');
const chalk = require('chalk');

const metadataUtils = require('./metadataUtils');

Expand Down Expand Up @@ -180,8 +179,6 @@ function generateMetadataDocs() {
const docsDir = path.join(CWD, '../', getDocsPath());
let files = glob.sync(CWD + '/../' + getDocsPath() + '/**');
files.forEach(file => {
let language = 'en';

const extension = path.extname(file);

if (extension === '.md' || extension === '.markdown') {
Expand Down
14 changes: 7 additions & 7 deletions lib/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ function execute(port, options) {
const metadataUtils = require('./metadataUtils');

const env = require('./env.js');
const translation = require('./translation');
const express = require('express');
const React = require('react');
const request = require('request');
const fs = require('fs-extra');
const os = require('os');
const path = require('path');
const color = require('color');
const getTOC = require('../core/getTOC');
const {
blogRouting,
Expand Down Expand Up @@ -284,10 +281,13 @@ function execute(port, options) {
});

app.get(sitemapRouting(siteConfig.baseUrl), (req, res) => {
res.set('Content-Type', 'application/xml');

sitemap(xml => {
res.send(xml);
sitemap((err, xml) => {
if (err) {
res.status(500).send('Sitemap error');
} else {
res.set('Content-Type', 'application/xml');
res.send(xml);
}
});
});

Expand Down
9 changes: 1 addition & 8 deletions lib/server/sitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
*/

const fs = require('fs-extra');
const path = require('path');
const os = require('os');
const Feed = require('feed');

const chalk = require('chalk');
const glob = require('glob');
const CWD = process.cwd();

Expand Down Expand Up @@ -104,9 +100,6 @@ module.exports = function(callback) {
});

sm.toXML((err, xml) => {
if (err) {
return 'An error has occurred.';
}
callback(xml);
callback(err, xml);
});
};
1 change: 0 additions & 1 deletion lib/server/versionFallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const CWD = process.cwd();
const glob = require('glob');
const fs = require('fs');
const path = require('path');
const assert = require('assert');

const metadataUtils = require('./metadataUtils');

Expand Down
Loading

0 comments on commit 38e5668

Please sign in to comment.