Skip to content

Commit e83c351

Browse files
committed
add demo folder structure to template with @domain-group/fe-co-demo
1 parent 0a5c4ea commit e83c351

File tree

13 files changed

+110
-24
lines changed

13 files changed

+110
-24
lines changed

packages/react-scripts/config/paths.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ module.exports = {
5151
dotenv: resolveApp('.env'),
5252
appBuild: resolveApp('build'),
5353
appPublic: resolveApp('public'),
54-
appHtml: resolveApp('public/index.html'),
55-
appIndexJs: resolveApp('src/index.js'),
54+
appHtml: resolveApp('demo/index.html'),
55+
appIndexJs: resolveApp('demo/index.jsx'),
5656
appPackageJson: resolveApp('package.json'),
5757
appSrc: resolveApp('src'),
58+
appDemo: resolveApp('demo'),
5859
yarnLockFile: resolveApp('yarn.lock'),
5960
testsSetup: resolveApp('src/setupTests.js'),
6061
appNodeModules: resolveApp('node_modules'),
@@ -71,10 +72,11 @@ module.exports = {
7172
appPath: resolveApp('.'),
7273
appBuild: resolveApp('build'),
7374
appPublic: resolveApp('public'),
74-
appHtml: resolveApp('public/index.html'),
75-
appIndexJs: resolveApp('src/index.js'),
75+
appHtml: resolveApp('demo/index.html'),
76+
appIndexJs: resolveApp('demo/index.jsx'),
7677
appPackageJson: resolveApp('package.json'),
7778
appSrc: resolveApp('src'),
79+
appDemo: resolveApp('demo'),
7880
yarnLockFile: resolveApp('yarn.lock'),
7981
testsSetup: resolveApp('src/setupTests.js'),
8082
appNodeModules: resolveApp('node_modules'),
@@ -101,10 +103,11 @@ if (
101103
appPath: resolveApp('.'),
102104
appBuild: resolveOwn('../../build'),
103105
appPublic: resolveOwn('template/public'),
104-
appHtml: resolveOwn('template/public/index.html'),
105-
appIndexJs: resolveOwn('template/src/index.js'),
106+
appHtml: resolveOwn('template/demo/index.html'),
107+
appIndexJs: resolveOwn('template/demo/index.jsx'),
106108
appPackageJson: resolveOwn('package.json'),
107109
appSrc: resolveOwn('template/src'),
110+
appDemo: resolveOwn('template/demo'),
108111
yarnLockFile: resolveOwn('template/yarn.lock'),
109112
testsSetup: resolveOwn('template/src/setupTests.js'),
110113
appNodeModules: resolveOwn('node_modules'),

packages/react-scripts/config/webpack.config.dev.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ module.exports = {
164164
loader: require.resolve('eslint-loader'),
165165
},
166166
],
167-
include: paths.appSrc,
167+
include: [paths.appSrc, paths.appDemo],
168168
},
169169
{
170170
// "oneOf" will traverse all following loaders until one will
@@ -185,7 +185,7 @@ module.exports = {
185185
// Process JS with Babel.
186186
{
187187
test: /\.(js|jsx|mjs)$/,
188-
include: paths.appSrc,
188+
include: [paths.appSrc, paths.appDemo],
189189
loader: require.resolve('babel-loader'),
190190
options: {
191191
// @remove-on-eject-begin

packages/react-scripts/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "domain-react-scripts",
3-
"version": "0.1.0",
3+
"author": "Albert Still <albert.still@domain.com.au>",
4+
"version": "0.0.0",
45
"description": "Configuration and scripts for Domain React components",
56
"repository": "DomainGroupOSS/create-react-app",
67
"license": "MIT",

packages/react-scripts/scripts/init.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module.exports = function(
3838
// Setup the script rules
3939
appPackage.scripts = {
4040
start: 'domain-react-scripts start',
41-
build: 'domain-react-scripts build',
41+
// build: 'domain-react-scripts build',
4242
test: 'domain-react-scripts test --env=jsdom',
4343
};
4444

@@ -129,6 +129,22 @@ module.exports = function(
129129
}
130130
}
131131

132+
let devDepArgs;
133+
if (useYarn) {
134+
devDepArgs = ['add', '--dev'];
135+
} else {
136+
devDepArgs = ['install', '--save-dev', verbose && '--verbose'].filter(
137+
e => e
138+
);
139+
}
140+
devDepArgs.push('@domain-group/fe-co-demo');
141+
142+
const proc = spawn.sync(command, devDepArgs, { stdio: 'inherit' });
143+
if (proc.status !== 0) {
144+
console.error(`\`${command} ${devDepArgs.join(' ')}\` failed`);
145+
return;
146+
}
147+
132148
// Display the most elegant way to cd.
133149
// This needs to handle an undefined originalDirectory for
134150
// backward compatibility with old global-cli's.

packages/react-scripts/scripts/start.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,48 @@ if (process.env.HOST) {
6868
console.log();
6969
}
7070

71-
const legacyInputSassPath = path.join(paths.appPath, 'src', 'legacy.scss');
72-
const legacyOutputCssPath = path.join(paths.appSrc, 'legacy.css');
73-
if (fs.existsSync(legacyInputSassPath)) {
71+
const legacySrcInputSassPath = path.join(paths.appSrc, 'legacy.scss');
72+
const legacySrcOutputCssPath = path.join(paths.appSrc, 'legacy.css');
73+
if (fs.existsSync(legacySrcInputSassPath)) {
7474
console.log(
7575
chalk.cyan(
7676
'Detected `src/legacy.scss`, attempting to compile to `src/legacy.css` using node-sass.'
7777
)
7878
);
7979

8080
const { css } = sass.renderSync({
81-
file: legacyInputSassPath,
81+
file: legacySrcInputSassPath,
8282
includePaths: [paths.appNodeModules],
8383
});
8484

85-
fs.writeFileSync(legacyOutputCssPath, css);
85+
fs.writeFileSync(legacySrcOutputCssPath, css);
8686

8787
console.log(
8888
chalk.cyan('Successfully wrote compiled Sass to `src/legacy.css`')
8989
);
9090
}
9191

92+
const legacyDemoInputSassPath = path.join(paths.appDemo, 'legacy.scss');
93+
const legacyDemoOutputCssPath = path.join(paths.appDemo, 'legacy.css');
94+
if (fs.existsSync(legacyDemoInputSassPath)) {
95+
console.log(
96+
chalk.cyan(
97+
'Detected `demo/legacy.scss`, attempting to compile to `demo/legacy.css` using node-sass.'
98+
)
99+
);
100+
101+
const { css } = sass.renderSync({
102+
file: legacyDemoInputSassPath,
103+
includePaths: [paths.appNodeModules],
104+
});
105+
106+
fs.writeFileSync(legacyDemoOutputCssPath, css);
107+
108+
console.log(
109+
chalk.cyan('Successfully wrote compiled Sass to `demo/legacy.css`')
110+
);
111+
}
112+
92113
// We attempt to use the default port but if it is busy, we offer the user to
93114
// run on a different port. `choosePort()` Promise resolves to the next free port.
94115
choosePort(HOST, DEFAULT_PORT)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Example from '../src';
2+
3+
const fixtureGroups = [
4+
{
5+
component: Example,
6+
fixtures: {
7+
'One Column': {
8+
props: {
9+
isTwoColumn: false,
10+
},
11+
},
12+
'Two Columns': {
13+
props: {
14+
isTwoColumn: true,
15+
},
16+
},
17+
},
18+
},
19+
];
20+
21+
export default fixtureGroups;
File renamed without changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import FeCoDemo from '@domain-group/fe-co-demo';
4+
import fixtures from './fixtures';
5+
import './legacy.css';
6+
7+
ReactDOM.render(
8+
<FeCoDemo fixtureGroups={fixtures} />,
9+
document.getElementById('root'),
10+
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@import '@domain-group/fe-co-demo/lib/scss/fe-co-demo';
2+
3+
html,
4+
body,
5+
#root {
6+
height: 100%;
7+
width: 100%;
8+
}

packages/react-scripts/template/gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ yarn-debug.log*
2121
yarn-error.log*
2222

2323
# Domain legacy Sass
24+
/demo/legacy.css
2425
/src/legacy.css

0 commit comments

Comments
 (0)