Skip to content
This repository was archived by the owner on Feb 27, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
full house bem-config support
  • Loading branch information
awinogradov committed Apr 30, 2017
commit f1c81a6577b15bf4c03f0d007dcea2be8a2ac7ad
91 changes: 34 additions & 57 deletions packages/bem-react-scripts/config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,12 @@
const path = require('path');
const fs = require('fs');
const url = require('url');
const bemConfig = require('bem-config')();
const userOptions = bemConfig.moduleSync('create-bem-react-app');

// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebookincubator/create-react-app/issues/637
let subApp = false;
function resolveRoot() {
if (process.env.ROOT) {
subApp = true;
return process.env.ROOT;
}
return process.cwd();
}
const root = resolveRoot();
const appDirectory = fs.realpathSync(root);
function resolveSubApp(relativePath) {
return path.resolve(process.cwd(), relativePath);
}
const appDirectory = fs.realpathSync(process.cwd());
function resolveApp(relativePath) {
return path.resolve(appDirectory, relativePath);
}
Expand Down Expand Up @@ -77,35 +67,30 @@ function getPublicUrl(appPackageJson) {
// single-page apps that may serve index.html for nested URLs like /todos/42.
// We can't use a relative path in HTML because we don't want to load something
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
function getServedPath(appPackageJson) {
const publicUrl = getPublicUrl(appPackageJson);
const servedUrl = envPublicUrl ||
(publicUrl ? url.parse(publicUrl).pathname : '/');
const publicUrl = userOptions.publicUrl ||
getPublicUrl(resolveApp(userOptions.appPackageJson));
function getServedPath() {
if (publicUrl === './') return publicUrl;

const pubUrl = publicUrl;
const servedUrl = envPublicUrl || (pubUrl ? url.parse(pubUrl).pathname : '/');
return ensureSlash(servedUrl, true);
}

// config after eject: we're in ./config/
module.exports = {
appBuild: resolveApp('build'),
appPublic: resolveApp('public'),
appHtml: resolveApp('public/index.html'),
appIndexJs: resolveApp('src/index.js'),
appPackageJson: subApp
? resolveSubApp('package.json')
: resolveApp('package.json'),
appSrc: resolveApp('src'),
yarnLockFile: subApp ? resolveSubApp('yarn.lock') : resolveApp('yarn.lock'),
testsSetup: resolveApp('src/setupTests.js'),
appNodeModules: subApp
? resolveSubApp('node_modules')
: resolveApp('node_modules'),
appBuild: resolveApp(userOptions.appBuild),
appPublic: resolveApp(userOptions.appPublic),
appHtml: resolveApp(userOptions.appHtml),
appIndexJs: resolveApp(userOptions.appIndexJs),
appPackageJson: resolveApp(userOptions.appPackageJson),
appSrc: resolveApp(userOptions.appSrc),
yarnLockFile: resolveApp(userOptions.yarnLockFile),
testsSetup: resolveApp(userOptions.testsSetup),
appNodeModules: resolveApp(userOptions.appNodeModules),
nodePaths: nodePaths,
publicUrl: getPublicUrl(
subApp ? resolveSubApp('package.json') : resolveApp('package.json')
),
servedPath: getServedPath(
subApp ? resolveSubApp('package.json') : resolveApp('package.json')
),
publicUrl: publicUrl,
servedPath: getServedPath(),
};

// @remove-on-eject-begin
Expand All @@ -119,27 +104,19 @@ function resolveOwn(relativePath) {

// config before eject: we're in ./node_modules/bem-react-scripts/config/
module.exports = {
appPath: resolveApp('.'),
appBuild: resolveApp('build'),
appPublic: resolveApp('public'),
appHtml: resolveApp('public/index.html'),
appIndexJs: resolveApp('src/index.js'),
appPackageJson: subApp
? resolveSubApp('package.json')
: resolveApp('package.json'),
appSrc: resolveApp('src'),
yarnLockFile: subApp ? resolveSubApp('yarn.lock') : resolveApp('yarn.lock'),
testsSetup: resolveApp('src/setupTests.js'),
appNodeModules: subApp
? resolveSubApp('node_modules')
: resolveApp('node_modules'),
appPath: resolveApp(userOptions.appPath),
appBuild: resolveApp(userOptions.appBuild),
appPublic: resolveApp(userOptions.appPublic),
appHtml: resolveApp(userOptions.appHtml),
appIndexJs: resolveApp(userOptions.appIndexJs),
appPackageJson: resolveApp(userOptions.appPackageJson),
appSrc: resolveApp(userOptions.appSrc),
yarnLockFile: resolveApp(userOptions.yarnLockFile),
testsSetup: resolveApp(userOptions.testsSetup),
appNodeModules: resolveApp(userOptions.appNodeModules),
nodePaths: nodePaths,
publicUrl: getPublicUrl(
subApp ? resolveSubApp('package.json') : resolveApp('package.json')
),
servedPath: getServedPath(
subApp ? resolveSubApp('package.json') : resolveApp('package.json')
),
publicUrl: publicUrl,
servedPath: getServedPath(),
// These properties only exist before ejecting:
ownPath: resolveOwn('.'),
ownNodeModules: resolveOwn('node_modules'), // This is empty on npm 3
Expand All @@ -150,7 +127,7 @@ const reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`);
const reactScriptsLinked = fs.existsSync(reactScriptsPath) &&
fs.lstatSync(reactScriptsPath).isSymbolicLink();

// config before publish: we're in ./packages/react-scripts/config/
// config before publish: we're in ./packages/bem-react-scripts/config/
if (
!reactScriptsLinked &&
__dirname.indexOf(path.join('packages', 'bem-react-scripts', 'config')) !== -1
Expand Down
20 changes: 10 additions & 10 deletions packages/bem-react-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@
"react-scripts": "./bin/react-scripts.js"
},
"dependencies": {
"autoprefixer": "6.7.5",
"autoprefixer": "6.7.7",
"babel-core": "6.23.1",
"babel-eslint": "7.1.1",
"babel-jest": "18.0.0",
"babel-loader": "7.0.0-alpha.3",
"babel-plugin-bem-import": "^1.1.1",
"babel-loader": "7.0.0",
"babel-plugin-bem-import": "1.3.2",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react-app": "^2.1.1",
"babel-runtime": "^6.20.0",
"bem-config": "^3.2.3",
"bem-react-core": "^0.3.1",
"bem-config": "3.2.3",
"bem-react-core": "0.3.1",
"case-sensitive-paths-webpack-plugin": "1.1.4",
"chalk": "1.1.3",
"connect-history-api-fallback": "1.3.0",
"cross-spawn": "4.0.2",
"css-loader": "0.26.2",
"css-loader": "0.28.0",
"detect-port": "1.1.0",
"dotenv": "2.0.0",
"eslint": "3.16.1",
Expand All @@ -49,7 +49,7 @@
"eslint-plugin-jsx-a11y": "4.0.0",
"eslint-plugin-react": "6.4.1",
"extract-text-webpack-plugin": "2.1.0",
"file-loader": "0.10.1",
"file-loader": "0.11.1",
"fs-extra": "0.30.0",
"html-webpack-plugin": "2.28.0",
"http-proxy-middleware": "0.17.3",
Expand All @@ -60,10 +60,10 @@
"react-dev-utils": "^0.5.2",
"recursive-readdir": "2.1.0",
"strip-ansi": "3.0.1",
"style-loader": "0.13.2",
"style-loader": "0.16.1",
"url-loader": "0.5.8",
"webpack": "2.2.1",
"webpack-bem-loader": "^0.1.0",
"webpack": "2.4.1",
"webpack-bem-loader": "^0.3.0",
"webpack-dev-server": "2.4.1",
"webpack-manifest-plugin": "1.1.0",
"whatwg-fetch": "2.0.2"
Expand Down
24 changes: 17 additions & 7 deletions packages/bem-react-scripts/template/.bemrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
{
"root": true,
"levels": {
"./src/common": {
"src/components": {
"scheme": "nested",
"default": true
},
"./src/desktop": {
"scheme": "nested"
},
"./src/touch": {
"scheme": "nested"
}
},
"modules": {
"create-bem-react-app": {
"appPath": ".",
"appBuild": "build",
"appPublic": "public",
"appHtml": "public/index.html",
"appIndexJs": "src/index.js",
"appPackageJson": "package.json",
"appSrc": "src",
"yarnLockFile": "yarn.lock",
"testsSetup": "src/setupTests.js",
"appNodeModules": "node_modules",
"publicUrl": "",
"target": "web"
}
}
}
19 changes: 0 additions & 19 deletions packages/bem-react-scripts/template/src/common/App/App.js

This file was deleted.

27 changes: 27 additions & 0 deletions packages/bem-react-scripts/template/src/components/App/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { decl } from 'bem-react-core';

import Header from 'e:Header';
import Intro from 'e:Intro';

export default decl({
block: 'App',
content() {
return [
(
<Header key="h">
Welcome to BEM in your React
</Header>
),
(
<Intro key="i">
To get started, edit
{' '}
<code>src/common/App/App.js</code>
{' '}
and save to reload.
</Intro>
),
];
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { decl } from 'bem-react-core';
export default decl({
block: 'App',
elem: 'Header',
tag: 'h2'
tag: 'h2',
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { decl } from 'bem-react-core';
export default decl({
block: 'App',
elem: 'Intro',
tag: 'p'
tag: 'p',
});