chore: eslint & prettier nits

This commit is contained in:
endiliey 2018-08-11 01:33:24 +08:00
parent 8f493605ad
commit 084063eabe
15 changed files with 152 additions and 142 deletions

View file

@ -20,6 +20,9 @@ async function getPort(reqPort) {
} }
module.exports = async function start(siteDir, cliOptions = {}) { module.exports = async function start(siteDir, cliOptions = {}) {
console.log('Start command invoked ...');
console.log(cliOptions);
// Process all related files as a prop // Process all related files as a prop
const props = await load(siteDir); const props = await load(siteDir);

View file

@ -20,7 +20,7 @@ module.exports = function loadConfig(siteDir, deleteCache = true) {
]; ];
const missingFields = requiredFields.filter(field => !config[field]); const missingFields = requiredFields.filter(field => !config[field]);
if (missingFields && missingFields.length > 0) { if (missingFields && missingFields.length > 0) {
throw new Error(missingFields.join(', ') + ' are missing in siteConfig.js'); throw new Error(`${missingFields.join(', ')} are missing in siteConfig.js`);
} }
return config; return config;
}; };

View file

@ -37,7 +37,7 @@ function fileToComponentName(file) {
str = str.replace(/^[\W_]+|[\W_]+$/g, '').toLowerCase(); str = str.replace(/^[\W_]+|[\W_]+$/g, '').toLowerCase();
str = str.charAt(0).toUpperCase() + str.slice(1); str = str.charAt(0).toUpperCase() + str.slice(1);
str = str.replace(/[\W_]+(\w|$)/g, (_, ch) => ch.toUpperCase()); str = str.replace(/[\W_]+(\w|$)/g, (_, ch) => ch.toUpperCase());
return ext ? ext.toUpperCase() + str : str; return ext ? ext.toUpperCase() + str : str;
} }
module.exports = { module.exports = {

View file

@ -30,9 +30,9 @@ module.exports = function createProdConfig(props) {
]); ]);
// show compilation progress bar and build time // show compilation progress bar and build time
config.plugin('niceLog').use(webpackNiceLog, [{name: 'Production'}]); config.plugin('niceLog').use(webpackNiceLog, [{name: 'Production'}]);
// Webpack Bundle Analyzer to check which causes huge bundle size // Webpack Bundle Analyzer to check which causes huge bundle size
config.plugin('bundleAnalyzer').use(bundleAnalyzer); config.plugin('bundleAnalyzer').use(bundleAnalyzer);
return config; return config;
}; };

View file

@ -1,12 +1,12 @@
const path = require('path'); const path = require('path');
module.exports = { module.exports = {
rootDir: path.resolve(__dirname, '..'), rootDir: path.resolve(__dirname, '..'),
verbose: true, verbose: true,
testURL: 'http://localhost/', testURL: 'http://localhost/',
testEnvironment: 'node', testEnvironment: 'node',
moduleNameMapper: { moduleNameMapper: {
'^@lib/(.*)$': '<rootDir>/lib/$1' '^@lib/(.*)$': '<rootDir>/lib/$1'
}, },
testPathIgnorePatterns: ['/node_modules/', '__fixtures__'] testPathIgnorePatterns: ['/node_modules/', '__fixtures__']
}; };

View file

@ -1,4 +1,4 @@
module.exports = { module.exports = {
title: 'Munseo', title: 'Munseo',
baseUrl: '/' baseUrl: '/'
}; };

View file

@ -1 +1,3 @@
export default () => <div>Baz</div>; import React from 'react';
export default () => <div>Baz</div>;

View file

@ -1 +1,3 @@
export default () => <div>Foo</div>; import React from 'react';
export default () => <div>Foo</div>;

View file

@ -1 +1,3 @@
export default () => <div>Foo in subfolder</div>; import React from 'react';
export default () => <div>Foo in subfolder</div>;

View file

@ -1 +1,3 @@
export default () => <div>Index</div>; import React from 'react';
export default () => <div>Index</div>;

View file

@ -1,7 +1,7 @@
module.exports = { module.exports = {
title: 'Hello', title: 'Hello',
tagline: 'Hello World', tagline: 'Hello World',
organizationName: 'endiliey', organizationName: 'endiliey',
projectName: 'hello', projectName: 'hello',
baseUrl: '/' baseUrl: '/'
}; };

View file

@ -1,35 +1,35 @@
import path from 'path'; import path from 'path';
import loadConfig from '@lib/load/config.js'; import loadConfig from '@lib/load/config';
describe('loadConfig', () => { describe('loadConfig', () => {
test('website with valid siteConfig', () => { test('website with valid siteConfig', () => {
const siteDir = path.join(__dirname, '__fixtures__', 'simple-site'); const siteDir = path.join(__dirname, '__fixtures__', 'simple-site');
const config = loadConfig(siteDir); const config = loadConfig(siteDir);
expect(config).toEqual({ expect(config).toEqual({
baseUrl: '/', baseUrl: '/',
organizationName: 'endiliey', organizationName: 'endiliey',
projectName: 'hello', projectName: 'hello',
tagline: 'Hello World', tagline: 'Hello World',
title: 'Hello' title: 'Hello'
}); });
expect(config).not.toEqual({}); expect(config).not.toEqual({});
}); });
test('website with incomplete siteConfig', () => { test('website with incomplete siteConfig', () => {
const siteDir = path.join(__dirname, '__fixtures__', 'bad-site'); const siteDir = path.join(__dirname, '__fixtures__', 'bad-site');
expect(() => { expect(() => {
loadConfig(siteDir); loadConfig(siteDir);
}).toThrowErrorMatchingInlineSnapshot( }).toThrowErrorMatchingInlineSnapshot(
`"tagline, organizationName, projectName are missing in siteConfig.js"` `"tagline, organizationName, projectName are missing in siteConfig.js"`
); );
}); });
test('website with no siteConfig', () => { test('website with no siteConfig', () => {
const siteDir = path.join(__dirname, '__fixtures__', 'nonExisting'); const siteDir = path.join(__dirname, '__fixtures__', 'nonExisting');
expect(() => { expect(() => {
loadConfig(siteDir); loadConfig(siteDir);
}).toThrowErrorMatchingInlineSnapshot( }).toThrowErrorMatchingInlineSnapshot(
`"title, tagline, organizationName, projectName, baseUrl are missing in siteConfig.js"` `"title, tagline, organizationName, projectName, baseUrl are missing in siteConfig.js"`
); );
}); });
}); });

View file

@ -1,21 +1,21 @@
import loadDocs from '@lib/load/docs.js'; import loadDocs from '@lib/load/docs';
import path from 'path'; import path from 'path';
describe('loadDocs', () => { describe('loadDocs', () => {
test('simple docs', async () => { test('simple docs', async () => {
const docsDir = path.join(__dirname, '__fixtures__', 'simple-docs'); const docsDir = path.join(__dirname, '__fixtures__', 'simple-docs');
const docsData = await loadDocs(docsDir); const docsData = await loadDocs(docsDir);
expect(docsData).toMatchSnapshot(); expect(docsData).toMatchSnapshot();
expect(docsData).not.toBeNull(); expect(docsData).not.toBeNull();
}); });
test('no docs', async () => { test('no docs', async () => {
const nonExistingDocsDir = path.join( const nonExistingDocsDir = path.join(
__dirname, __dirname,
'__fixtures__', '__fixtures__',
'nonExistingDocs' 'nonExistingDocs'
); );
const docsData = await loadDocs(nonExistingDocsDir); const docsData = await loadDocs(nonExistingDocsDir);
expect(docsData).toEqual([]); expect(docsData).toEqual([]);
}); });
}); });

View file

@ -1,17 +1,17 @@
import loadPages from '@lib/load/pages.js'; import loadPages from '@lib/load/pages';
import path from 'path'; import path from 'path';
describe('loadPages', () => { describe('loadPages', () => {
test('valid pages', async () => { test('valid pages', async () => {
const pagesDir = path.join(__dirname, '__fixtures__', 'simple-pages'); const pagesDir = path.join(__dirname, '__fixtures__', 'simple-pages');
const pagesData = await loadPages(pagesDir); const pagesData = await loadPages(pagesDir);
expect(pagesData).toMatchSnapshot(); expect(pagesData).toMatchSnapshot();
expect(pagesData).not.toBeNull(); expect(pagesData).not.toBeNull();
}); });
test('invalid pages', async () => { test('invalid pages', async () => {
const nonExistingDir = path.join(__dirname, '__fixtures__', 'nonExisting'); const nonExistingDir = path.join(__dirname, '__fixtures__', 'nonExisting');
const pagesData = await loadPages(nonExistingDir); const pagesData = await loadPages(nonExistingDir);
expect(pagesData).toEqual([]); expect(pagesData).toEqual([]);
}); });
}); });

View file

@ -1,38 +1,37 @@
import path from 'path'; import {fileToPath, fileToComponentName} from '@lib/load/utils';
import {fileToPath, fileToComponentName} from '@lib/load/utils.js';
describe('load utils', () => {
describe('load utils', () => { test('fileToComponentName', () => {
test('fileToComponentName', () => { const asserts = {
const asserts = { 'index.md': 'MDIndex',
'index.md': 'MDIndex', 'hello/index.md': 'MDHelloIndex',
'hello/index.md': 'MDHelloIndex', 'foo.md': 'MDFoo',
'foo.md': 'MDFoo', 'foo-bar.md': 'MDFooBar',
'foo-bar.md': 'MDFooBar', 'index.js': 'JSIndex',
'index.js': 'JSIndex', 'foobar.js': 'JSFoobar',
'foobar.js': 'JSFoobar', 'docusaurus/index.js': 'JSDocusaurusIndex',
'docusaurus/index.js': 'JSDocusaurusIndex', '234.md': 'MD234',
'234.md': 'MD234', '2018-07-08-test.md': 'MD20180708Test',
'2018-07-08-test.md': 'MD20180708Test', '%asd.md': 'MDAsd'
'%asd.md': 'MDAsd' };
}; Object.keys(asserts).forEach(file => {
Object.keys(asserts).forEach(file => { expect(fileToComponentName(file)).toBe(asserts[file]);
expect(fileToComponentName(file)).toBe(asserts[file]); });
}); });
});
test('fileToPath', () => {
test('fileToPath', () => { const asserts = {
const asserts = { 'index.md': '/',
'index.md': '/', 'hello/index.md': '/hello/',
'hello/index.md': '/hello/', 'foo.md': '/foo',
'foo.md': '/foo', 'foo/bar.md': '/foo/bar',
'foo/bar.md': '/foo/bar', 'index.js': '/',
'index.js': '/', 'hello/index.js': '/hello/',
'hello/index.js': '/hello/', 'foo.js': '/foo',
'foo.js': '/foo', 'foo/bar.js': '/foo/bar'
'foo/bar.js': '/foo/bar' };
}; Object.keys(asserts).forEach(file => {
Object.keys(asserts).forEach(file => { expect(fileToPath(file)).toBe(asserts[file]);
expect(fileToPath(file)).toBe(asserts[file]); });
}); });
}); });
});