diff --git a/lib/commands/start.js b/lib/commands/start.js index cc373b79b4..a42804ad2b 100644 --- a/lib/commands/start.js +++ b/lib/commands/start.js @@ -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); diff --git a/lib/load/config.js b/lib/load/config.js index 3303e4f438..b5269b5a2f 100644 --- a/lib/load/config.js +++ b/lib/load/config.js @@ -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; }; diff --git a/lib/load/utils.js b/lib/load/utils.js index 38b2e5bbf9..05be648bb2 100644 --- a/lib/load/utils.js +++ b/lib/load/utils.js @@ -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 = { diff --git a/lib/webpack/prod.js b/lib/webpack/prod.js index 2dcb8e91a6..4e5a8d5944 100644 --- a/lib/webpack/prod.js +++ b/lib/webpack/prod.js @@ -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; }; diff --git a/test/jest.config.js b/test/jest.config.js index cb505b774e..7c7392384c 100644 --- a/test/jest.config.js +++ b/test/jest.config.js @@ -1,12 +1,12 @@ -const path = require('path'); - -module.exports = { - rootDir: path.resolve(__dirname, '..'), - verbose: true, - testURL: 'http://localhost/', - testEnvironment: 'node', - moduleNameMapper: { - '^@lib/(.*)$': '/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/(.*)$': '/lib/$1' + }, + testPathIgnorePatterns: ['/node_modules/', '__fixtures__'] +}; diff --git a/test/load/__fixtures__/bad-site/siteConfig.js b/test/load/__fixtures__/bad-site/siteConfig.js index 58d75f1d57..2f57430423 100644 --- a/test/load/__fixtures__/bad-site/siteConfig.js +++ b/test/load/__fixtures__/bad-site/siteConfig.js @@ -1,4 +1,4 @@ -module.exports = { - title: 'Munseo', - baseUrl: '/' -}; +module.exports = { + title: 'Munseo', + baseUrl: '/' +}; diff --git a/test/load/__fixtures__/simple-pages/bar/baz.js b/test/load/__fixtures__/simple-pages/bar/baz.js index 7bff47ab5f..75a8c70015 100644 --- a/test/load/__fixtures__/simple-pages/bar/baz.js +++ b/test/load/__fixtures__/simple-pages/bar/baz.js @@ -1 +1,3 @@ -export default () =>
Baz
; +import React from 'react'; + +export default () =>
Baz
; diff --git a/test/load/__fixtures__/simple-pages/foo.js b/test/load/__fixtures__/simple-pages/foo.js index cc15b8d603..3b52ec615c 100644 --- a/test/load/__fixtures__/simple-pages/foo.js +++ b/test/load/__fixtures__/simple-pages/foo.js @@ -1 +1,3 @@ -export default () =>
Foo
; +import React from 'react'; + +export default () =>
Foo
; diff --git a/test/load/__fixtures__/simple-pages/foo/index.js b/test/load/__fixtures__/simple-pages/foo/index.js index 64e2a041e5..5faf67ae13 100644 --- a/test/load/__fixtures__/simple-pages/foo/index.js +++ b/test/load/__fixtures__/simple-pages/foo/index.js @@ -1 +1,3 @@ -export default () =>
Foo in subfolder
; +import React from 'react'; + +export default () =>
Foo in subfolder
; diff --git a/test/load/__fixtures__/simple-pages/index.js b/test/load/__fixtures__/simple-pages/index.js index 8d3c74cde7..13063810a7 100644 --- a/test/load/__fixtures__/simple-pages/index.js +++ b/test/load/__fixtures__/simple-pages/index.js @@ -1 +1,3 @@ -export default () =>
Index
; +import React from 'react'; + +export default () =>
Index
; diff --git a/test/load/__fixtures__/simple-site/siteConfig.js b/test/load/__fixtures__/simple-site/siteConfig.js index 0e52974bd7..e64b9989cf 100644 --- a/test/load/__fixtures__/simple-site/siteConfig.js +++ b/test/load/__fixtures__/simple-site/siteConfig.js @@ -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: '/' +}; diff --git a/test/load/config.test.js b/test/load/config.test.js index 381ebbe0aa..f0015a0770 100644 --- a/test/load/config.test.js +++ b/test/load/config.test.js @@ -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"` + ); + }); +}); diff --git a/test/load/docs.test.js b/test/load/docs.test.js index bb967074f2..01588e12f9 100644 --- a/test/load/docs.test.js +++ b/test/load/docs.test.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([]); + }); +}); diff --git a/test/load/pages.test.js b/test/load/pages.test.js index b2d5e59004..7a76e76a82 100644 --- a/test/load/pages.test.js +++ b/test/load/pages.test.js @@ -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([]); + }); +}); diff --git a/test/load/utils.test.js b/test/load/utils.test.js index c292135d01..7012f191bd 100644 --- a/test/load/utils.test.js +++ b/test/load/utils.test.js @@ -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]); + }); + }); +});