Skip to content
This repository has been archived by the owner on Jul 24, 2019. It is now read-only.

Commit

Permalink
Add Beamery configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmckeb committed Feb 1, 2019
1 parent aa279ef commit 83a3726
Show file tree
Hide file tree
Showing 50 changed files with 701 additions and 227 deletions.
30 changes: 28 additions & 2 deletions bin/react-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,37 @@ const spawn = require('react-dev-utils/crossSpawn');
const args = process.argv.slice(2);

const scriptIndex = args.findIndex(
x => x === 'build' || x === 'eject' || x === 'start' || x === 'test'
x =>
x.startsWith('build') ||
x === 'eject' ||
x.startsWith('start') ||
x === 'test'
);
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
let script = scriptIndex === -1 ? args[0] : args[scriptIndex];
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];

// BMR_ENV config
const envs = require('../config/beamery/envs');
switch (script) {
case 'build':
process.env.BMR_ENV = envs.PRODUCTION;
break;
case 'build-dev':
script = 'build';
process.env.BMR_ENV = envs.DEVELOPMENT;
break;
case 'start-dev':
script = 'start';
process.env.BMR_ENV = envs.DEVELOPMENT;
break;
case 'build-stg':
script = 'build';
process.env.BMR_ENV = envs.STAGING;
break;
default:
process.env.BMR_ENV = envs.INDEPENDENT;
}

switch (script) {
case 'build':
case 'eject':
Expand Down
8 changes: 8 additions & 0 deletions config/beamery/envs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports = {
DEVELOPMENT: 'development',
PRODUCTION: 'production',
STAGING: 'staging',
INDEPENDENT: 'independent',
};
6 changes: 6 additions & 0 deletions config/beamery/jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

var enzyme = require('enzyme');
var Adapter = require('enzyme-adapter-react-16');

enzyme.configure({ adapter: new Adapter() });
27 changes: 27 additions & 0 deletions config/beamery/paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

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

const paths = {
buildPath: 'dist',
publicPath: false,
appIndexJs: 'src/index.full',
};

switch (process.env.BMR_ENV) {
case envs.PRODUCTION:
paths.publicPath = 'https://storage.googleapis.com/beamery/';
break;
case envs.STAGING:
paths.buildPath = '../app-bath/dist';
break;
case envs.DEVELOPMENT:
paths.buildPath = '../app-bath/dev';
break;
case envs.INDEPENDENT:
default:
paths.appIndexJs = 'src/index';
break;
}

module.exports = paths;
16 changes: 16 additions & 0 deletions config/beamery/prefixes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

const paths = require('../paths');
const appPackageJson = require(paths.appPackageJson);

// Use the `package.json` app name to simplify setup.
const appName = appPackageJson.name;
process.env.BMR_APP_NAME = appName;

module.exports = {
// Webpack allows us to define a path in sources. This can be useful for
// debugging against other applications.
devtoolRoot: appName ? appName + ':///' : '',
// This prefix is not used for `independent` builds.
filenamePrefix: appName ? appName : 'APP-NAME-UNDEFINED',
};
1 change: 1 addition & 0 deletions config/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function getClientEnvironment(publicUrl) {
// This should only be used as an escape hatch. Normally you would put
// images into the `src` and `import` them in code to get their paths.
PUBLIC_URL: publicUrl,
APP_NAME: process.env.BMR_APP_NAME,
}
);
// Stringify all values so we can feed into Webpack DefinePlugin
Expand Down
13 changes: 8 additions & 5 deletions config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
const path = require('path');
const fs = require('fs');
const url = require('url');
const beameryPaths = require('./beamery/paths');

// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebook/create-react-app/issues/637
Expand Down Expand Up @@ -42,7 +43,9 @@ const getPublicUrl = appPackageJson =>
function getServedPath(appPackageJson) {
const publicUrl = getPublicUrl(appPackageJson);
const servedUrl =
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
beameryPaths.publicPath ||
envPublicUrl ||
(publicUrl ? url.parse(publicUrl).pathname : '/');
return ensureSlash(servedUrl, true);
}

Expand Down Expand Up @@ -77,10 +80,10 @@ const resolveModule = (resolveFn, filePath) => {
module.exports = {
dotenv: resolveApp('.env'),
appPath: resolveApp('.'),
appBuild: resolveApp('build'),
appBuild: resolveApp(beameryPaths.buildPath),
appPublic: resolveApp('public'),
appHtml: resolveApp('public/index.html'),
appIndexJs: resolveModule(resolveApp, 'src/index'),
appIndexJs: resolveModule(resolveApp, beameryPaths.appIndexJs),
appPackageJson: resolveApp('package.json'),
appSrc: resolveApp('src'),
appTsConfig: resolveApp('tsconfig.json'),
Expand All @@ -99,10 +102,10 @@ const resolveOwn = relativePath => path.resolve(__dirname, '..', relativePath);
module.exports = {
dotenv: resolveApp('.env'),
appPath: resolveApp('.'),
appBuild: resolveApp('build'),
appBuild: resolveApp(beameryPaths.buildPath),
appPublic: resolveApp('public'),
appHtml: resolveApp('public/index.html'),
appIndexJs: resolveModule(resolveApp, 'src/index'),
appIndexJs: resolveModule(resolveApp, beameryPaths.appIndexJs),
appPackageJson: resolveApp('package.json'),
appSrc: resolveApp('src'),
appTsConfig: resolveApp('tsconfig.json'),
Expand Down
Loading

0 comments on commit 83a3726

Please sign in to comment.