-
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate config automatically for create-react-app (#512)
* Make getCosmosConfig a named export #452 * Add config generation for CRA #452 * Generate config when starting server #452
- Loading branch information
Showing
38 changed files
with
358 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/react-cosmos-config/src/__tests__/arg-path/custom-root-path.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/react-cosmos-config/src/__tests__/cli-path/custom-path/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/react-cosmos-config/src/__tests__/cli-path/default-path/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/react-cosmos-config/src/__tests__/cli-path/no-config-wrong-path/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
46 changes: 46 additions & 0 deletions
46
packages/react-cosmos-config/src/__tests__/generate/create-react-app/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// @flow | ||
|
||
import path from 'path'; | ||
import mkdirp from 'mkdirp'; | ||
import touch from 'touch'; | ||
import rimraf from 'rimraf'; | ||
import { generateCosmosConfig } from '../../../'; | ||
|
||
jest.mock('yargs', () => ({ argv: {} })); | ||
|
||
// Note: __fsoutput__ are in Jest's watchPathIgnorePatterns | ||
const outputPath = path.join(__dirname, '__fsoutput__'); | ||
const craWebpackConfigPath = path.join( | ||
outputPath, | ||
'node_modules/react-scripts/config/webpack.config.dev' | ||
); | ||
const cosmosConfigPath = path.join(outputPath, 'cosmos.config.js'); | ||
|
||
beforeEach(() => { | ||
global.process.cwd = () => outputPath; | ||
|
||
mkdirp.sync(path.dirname(craWebpackConfigPath)); | ||
touch.sync(craWebpackConfigPath); | ||
}); | ||
|
||
afterEach(() => { | ||
rimraf.sync(path.join(outputPath, 'node_modules')); | ||
rimraf.sync(cosmosConfigPath); | ||
}); | ||
|
||
describe('Create React App config generation', () => { | ||
it('returns correct name', () => { | ||
const generatedConfigFor = generateCosmosConfig(); | ||
expect(generatedConfigFor).toBe('Create React App'); | ||
}); | ||
|
||
it('creates config file', () => { | ||
generateCosmosConfig(); | ||
expect(require(cosmosConfigPath)).toEqual({ | ||
containerQuerySelector: '#root', | ||
webpackConfigPath: 'react-scripts/config/webpack.config.dev', | ||
publicPath: 'public', | ||
proxiesPath: 'src/cosmos.proxies' | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// @flow | ||
|
||
export const CRA_COSMOS_CONFIG = `module.exports = { | ||
containerQuerySelector: '#root', | ||
webpackConfigPath: 'react-scripts/config/webpack.config.dev', | ||
publicPath: 'public', | ||
// Optional: Create this file when you begin adding proxies | ||
proxiesPath: 'src/cosmos.proxies' | ||
}; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
packages/react-cosmos/src/server/__tests__/embed-modules-webpack-loader/old-fixtures.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 11 additions & 8 deletions
19
packages/react-cosmos/src/server/__tests__/extend-webpack-config/export.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 9 additions & 6 deletions
15
packages/react-cosmos/src/server/__tests__/extend-webpack-config/general.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 9 additions & 6 deletions
15
packages/react-cosmos/src/server/__tests__/extend-webpack-config/hmr-plugin-duplicate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 9 additions & 6 deletions
15
packages/react-cosmos/src/server/__tests__/extend-webpack-config/hmr.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.