mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 08:07:26 +02:00
chore: eslint & prettier nits
This commit is contained in:
parent
8f493605ad
commit
084063eabe
15 changed files with 152 additions and 142 deletions
|
@ -20,6 +20,9 @@ async function getPort(reqPort) {
|
|||
}
|
||||
|
||||
module.exports = async function start(siteDir, cliOptions = {}) {
|
||||
console.log('Start command invoked ...');
|
||||
console.log(cliOptions);
|
||||
|
||||
// Process all related files as a prop
|
||||
const props = await load(siteDir);
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ module.exports = function loadConfig(siteDir, deleteCache = true) {
|
|||
];
|
||||
const missingFields = requiredFields.filter(field => !config[field]);
|
||||
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;
|
||||
};
|
||||
|
|
|
@ -37,7 +37,7 @@ function fileToComponentName(file) {
|
|||
str = str.replace(/^[\W_]+|[\W_]+$/g, '').toLowerCase();
|
||||
str = str.charAt(0).toUpperCase() + str.slice(1);
|
||||
str = str.replace(/[\W_]+(\w|$)/g, (_, ch) => ch.toUpperCase());
|
||||
return ext ? ext.toUpperCase() + str : str;
|
||||
return ext ? ext.toUpperCase() + str : str;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -30,9 +30,9 @@ module.exports = function createProdConfig(props) {
|
|||
]);
|
||||
// show compilation progress bar and build time
|
||||
config.plugin('niceLog').use(webpackNiceLog, [{name: 'Production'}]);
|
||||
|
||||
|
||||
// Webpack Bundle Analyzer to check which causes huge bundle size
|
||||
config.plugin('bundleAnalyzer').use(bundleAnalyzer);
|
||||
|
||||
|
||||
return config;
|
||||
};
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
rootDir: path.resolve(__dirname, '..'),
|
||||
verbose: true,
|
||||
testURL: 'http://localhost/',
|
||||
testEnvironment: 'node',
|
||||
moduleNameMapper: {
|
||||
'^@lib/(.*)$': '<rootDir>/lib/$1'
|
||||
},
|
||||
testPathIgnorePatterns: ['/node_modules/', '__fixtures__']
|
||||
};
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
rootDir: path.resolve(__dirname, '..'),
|
||||
verbose: true,
|
||||
testURL: 'http://localhost/',
|
||||
testEnvironment: 'node',
|
||||
moduleNameMapper: {
|
||||
'^@lib/(.*)$': '<rootDir>/lib/$1'
|
||||
},
|
||||
testPathIgnorePatterns: ['/node_modules/', '__fixtures__']
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = {
|
||||
title: 'Munseo',
|
||||
baseUrl: '/'
|
||||
};
|
||||
module.exports = {
|
||||
title: 'Munseo',
|
||||
baseUrl: '/'
|
||||
};
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
export default () => <div>Baz</div>;
|
||||
import React from 'react';
|
||||
|
||||
export default () => <div>Baz</div>;
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
export default () => <div>Foo</div>;
|
||||
import React from 'react';
|
||||
|
||||
export default () => <div>Foo</div>;
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
export default () => <div>Foo in subfolder</div>;
|
||||
import React from 'react';
|
||||
|
||||
export default () => <div>Foo in subfolder</div>;
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
export default () => <div>Index</div>;
|
||||
import React from 'react';
|
||||
|
||||
export default () => <div>Index</div>;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module.exports = {
|
||||
title: 'Hello',
|
||||
tagline: 'Hello World',
|
||||
organizationName: 'endiliey',
|
||||
projectName: 'hello',
|
||||
baseUrl: '/'
|
||||
};
|
||||
module.exports = {
|
||||
title: 'Hello',
|
||||
tagline: 'Hello World',
|
||||
organizationName: 'endiliey',
|
||||
projectName: 'hello',
|
||||
baseUrl: '/'
|
||||
};
|
||||
|
|
|
@ -1,35 +1,35 @@
|
|||
import path from 'path';
|
||||
import loadConfig from '@lib/load/config.js';
|
||||
|
||||
describe('loadConfig', () => {
|
||||
test('website with valid siteConfig', () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'simple-site');
|
||||
const config = loadConfig(siteDir);
|
||||
expect(config).toEqual({
|
||||
baseUrl: '/',
|
||||
organizationName: 'endiliey',
|
||||
projectName: 'hello',
|
||||
tagline: 'Hello World',
|
||||
title: 'Hello'
|
||||
});
|
||||
expect(config).not.toEqual({});
|
||||
});
|
||||
|
||||
test('website with incomplete siteConfig', () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'bad-site');
|
||||
expect(() => {
|
||||
loadConfig(siteDir);
|
||||
}).toThrowErrorMatchingInlineSnapshot(
|
||||
`"tagline, organizationName, projectName are missing in siteConfig.js"`
|
||||
);
|
||||
});
|
||||
|
||||
test('website with no siteConfig', () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'nonExisting');
|
||||
expect(() => {
|
||||
loadConfig(siteDir);
|
||||
}).toThrowErrorMatchingInlineSnapshot(
|
||||
`"title, tagline, organizationName, projectName, baseUrl are missing in siteConfig.js"`
|
||||
);
|
||||
});
|
||||
});
|
||||
import path from 'path';
|
||||
import loadConfig from '@lib/load/config';
|
||||
|
||||
describe('loadConfig', () => {
|
||||
test('website with valid siteConfig', () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'simple-site');
|
||||
const config = loadConfig(siteDir);
|
||||
expect(config).toEqual({
|
||||
baseUrl: '/',
|
||||
organizationName: 'endiliey',
|
||||
projectName: 'hello',
|
||||
tagline: 'Hello World',
|
||||
title: 'Hello'
|
||||
});
|
||||
expect(config).not.toEqual({});
|
||||
});
|
||||
|
||||
test('website with incomplete siteConfig', () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'bad-site');
|
||||
expect(() => {
|
||||
loadConfig(siteDir);
|
||||
}).toThrowErrorMatchingInlineSnapshot(
|
||||
`"tagline, organizationName, projectName are missing in siteConfig.js"`
|
||||
);
|
||||
});
|
||||
|
||||
test('website with no siteConfig', () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'nonExisting');
|
||||
expect(() => {
|
||||
loadConfig(siteDir);
|
||||
}).toThrowErrorMatchingInlineSnapshot(
|
||||
`"title, tagline, organizationName, projectName, baseUrl are missing in siteConfig.js"`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
import loadDocs from '@lib/load/docs.js';
|
||||
import path from 'path';
|
||||
|
||||
describe('loadDocs', () => {
|
||||
test('simple docs', async () => {
|
||||
const docsDir = path.join(__dirname, '__fixtures__', 'simple-docs');
|
||||
const docsData = await loadDocs(docsDir);
|
||||
expect(docsData).toMatchSnapshot();
|
||||
expect(docsData).not.toBeNull();
|
||||
});
|
||||
|
||||
test('no docs', async () => {
|
||||
const nonExistingDocsDir = path.join(
|
||||
__dirname,
|
||||
'__fixtures__',
|
||||
'nonExistingDocs'
|
||||
);
|
||||
const docsData = await loadDocs(nonExistingDocsDir);
|
||||
expect(docsData).toEqual([]);
|
||||
});
|
||||
});
|
||||
import loadDocs from '@lib/load/docs';
|
||||
import path from 'path';
|
||||
|
||||
describe('loadDocs', () => {
|
||||
test('simple docs', async () => {
|
||||
const docsDir = path.join(__dirname, '__fixtures__', 'simple-docs');
|
||||
const docsData = await loadDocs(docsDir);
|
||||
expect(docsData).toMatchSnapshot();
|
||||
expect(docsData).not.toBeNull();
|
||||
});
|
||||
|
||||
test('no docs', async () => {
|
||||
const nonExistingDocsDir = path.join(
|
||||
__dirname,
|
||||
'__fixtures__',
|
||||
'nonExistingDocs'
|
||||
);
|
||||
const docsData = await loadDocs(nonExistingDocsDir);
|
||||
expect(docsData).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
import loadPages from '@lib/load/pages.js';
|
||||
import path from 'path';
|
||||
|
||||
describe('loadPages', () => {
|
||||
test('valid pages', async () => {
|
||||
const pagesDir = path.join(__dirname, '__fixtures__', 'simple-pages');
|
||||
const pagesData = await loadPages(pagesDir);
|
||||
expect(pagesData).toMatchSnapshot();
|
||||
expect(pagesData).not.toBeNull();
|
||||
});
|
||||
|
||||
test('invalid pages', async () => {
|
||||
const nonExistingDir = path.join(__dirname, '__fixtures__', 'nonExisting');
|
||||
const pagesData = await loadPages(nonExistingDir);
|
||||
expect(pagesData).toEqual([]);
|
||||
});
|
||||
});
|
||||
import loadPages from '@lib/load/pages';
|
||||
import path from 'path';
|
||||
|
||||
describe('loadPages', () => {
|
||||
test('valid pages', async () => {
|
||||
const pagesDir = path.join(__dirname, '__fixtures__', 'simple-pages');
|
||||
const pagesData = await loadPages(pagesDir);
|
||||
expect(pagesData).toMatchSnapshot();
|
||||
expect(pagesData).not.toBeNull();
|
||||
});
|
||||
|
||||
test('invalid pages', async () => {
|
||||
const nonExistingDir = path.join(__dirname, '__fixtures__', 'nonExisting');
|
||||
const pagesData = await loadPages(nonExistingDir);
|
||||
expect(pagesData).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,38 +1,37 @@
|
|||
import path from 'path';
|
||||
import {fileToPath, fileToComponentName} from '@lib/load/utils.js';
|
||||
|
||||
describe('load utils', () => {
|
||||
test('fileToComponentName', () => {
|
||||
const asserts = {
|
||||
'index.md': 'MDIndex',
|
||||
'hello/index.md': 'MDHelloIndex',
|
||||
'foo.md': 'MDFoo',
|
||||
'foo-bar.md': 'MDFooBar',
|
||||
'index.js': 'JSIndex',
|
||||
'foobar.js': 'JSFoobar',
|
||||
'docusaurus/index.js': 'JSDocusaurusIndex',
|
||||
'234.md': 'MD234',
|
||||
'2018-07-08-test.md': 'MD20180708Test',
|
||||
'%asd.md': 'MDAsd'
|
||||
};
|
||||
Object.keys(asserts).forEach(file => {
|
||||
expect(fileToComponentName(file)).toBe(asserts[file]);
|
||||
});
|
||||
});
|
||||
|
||||
test('fileToPath', () => {
|
||||
const asserts = {
|
||||
'index.md': '/',
|
||||
'hello/index.md': '/hello/',
|
||||
'foo.md': '/foo',
|
||||
'foo/bar.md': '/foo/bar',
|
||||
'index.js': '/',
|
||||
'hello/index.js': '/hello/',
|
||||
'foo.js': '/foo',
|
||||
'foo/bar.js': '/foo/bar'
|
||||
};
|
||||
Object.keys(asserts).forEach(file => {
|
||||
expect(fileToPath(file)).toBe(asserts[file]);
|
||||
});
|
||||
});
|
||||
});
|
||||
import {fileToPath, fileToComponentName} from '@lib/load/utils';
|
||||
|
||||
describe('load utils', () => {
|
||||
test('fileToComponentName', () => {
|
||||
const asserts = {
|
||||
'index.md': 'MDIndex',
|
||||
'hello/index.md': 'MDHelloIndex',
|
||||
'foo.md': 'MDFoo',
|
||||
'foo-bar.md': 'MDFooBar',
|
||||
'index.js': 'JSIndex',
|
||||
'foobar.js': 'JSFoobar',
|
||||
'docusaurus/index.js': 'JSDocusaurusIndex',
|
||||
'234.md': 'MD234',
|
||||
'2018-07-08-test.md': 'MD20180708Test',
|
||||
'%asd.md': 'MDAsd'
|
||||
};
|
||||
Object.keys(asserts).forEach(file => {
|
||||
expect(fileToComponentName(file)).toBe(asserts[file]);
|
||||
});
|
||||
});
|
||||
|
||||
test('fileToPath', () => {
|
||||
const asserts = {
|
||||
'index.md': '/',
|
||||
'hello/index.md': '/hello/',
|
||||
'foo.md': '/foo',
|
||||
'foo/bar.md': '/foo/bar',
|
||||
'index.js': '/',
|
||||
'hello/index.js': '/hello/',
|
||||
'foo.js': '/foo',
|
||||
'foo/bar.js': '/foo/bar'
|
||||
};
|
||||
Object.keys(asserts).forEach(file => {
|
||||
expect(fileToPath(file)).toBe(asserts[file]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue