Skip to content

Commit 39ded8e

Browse files
authored
Merge pull request #42 from fs-webdev/hf
Add template files for hf.
2 parents 38c8f7b + 9037c56 commit 39ded8e

File tree

10 files changed

+159
-5
lines changed

10 files changed

+159
-5
lines changed

packages/react-scripts/scripts/utils/frontierInit.js

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,21 @@ async function promptForConfig() {
2020
{
2121
type: 'checkbox',
2222
name: 'additionalFeatures',
23-
message: 'What additional features does your app require',
23+
message: 'What additional features does your app require (these are checkboxes)',
24+
default: ['electric-flow', 'header-footer'],
2425
choices: [
25-
{
26-
name: 'Using a shared Polymer Component within your React App?',
27-
value: 'polymer',
28-
},
2926
{
3027
name: `Configure app for Electric Flow`,
3128
value: 'electric-flow',
3229
},
30+
{
31+
name: `Include hf (header/footer)`,
32+
value: 'header-footer',
33+
},
34+
{
35+
name: 'Using a shared Polymer Component within your React App?',
36+
value: 'polymer',
37+
},
3338
],
3439
},
3540
];
@@ -48,6 +53,9 @@ function installFrontierDependencies(appPath, answers, useYarn, ownPath) {
4853
if (additionalFeatures.includes('electric-flow')) {
4954
configureEF(appPath, useYarn, ownPath);
5055
}
56+
if (additionalFeatures.includes('header-footer')) {
57+
configureHF(appPath, useYarn, ownPath);
58+
}
5159
injectPolymerCode(appPath);
5260

5361
const defaultModules = ['http-proxy-middleware@0.19.0', 'fs-webdev/exo'];
@@ -127,6 +135,40 @@ function configureEF(appPath, useYarn, ownPath) {
127135

128136
const templatePath = path.join(ownPath, 'template-ef');
129137
fs.copySync(templatePath, appPath, { overwrite: true });
138+
139+
alterPackageJsonFile(appPath, appPackage => {
140+
const packageJson = { ...appPackage };
141+
const additionalScripts = {
142+
"heroku-prebuild": "./heroku-prebuild.sh"
143+
};
144+
packageJson.scripts = sortScripts({ ...packageJson.scripts, ...additionalScripts });
145+
return packageJson;
146+
});
147+
}
148+
149+
function configureHF(appPath, useYarn, ownPath) {
150+
151+
const templatePath = path.join(ownPath, 'template-hf');
152+
fs.copySync(templatePath, appPath, { overwrite: true });
153+
154+
alterPackageJsonFile(appPath, appPackage => {
155+
const packageJson = { ...appPackage };
156+
const additionalScripts = {
157+
"build:prod": "PUBLIC_URL=https://edge.fscdn.org/assets/ react-scripts build",
158+
"heroku-postbuild": "npm run build:prod"
159+
};
160+
packageJson.scripts = sortScripts({ ...packageJson.scripts, ...additionalScripts });
161+
packageJson.main = "./server.js";
162+
163+
return packageJson;
164+
});
165+
166+
let modules = [
167+
'github:fs-webdev/hf#cra',
168+
'github:fs-webdev/snow#cra',
169+
'github:fs-webdev/startup',
170+
]
171+
installModulesSync(modules, useYarn);
130172
}
131173

132174
function cleanupFrontierCode(appPath) {}
@@ -154,3 +196,11 @@ function buildInstallCommandAndArgs(useYarn, saveDev = false) {
154196
}
155197
return { command, args };
156198
}
199+
200+
function sortScripts(scripts){
201+
const sortedScripts = {};
202+
Object.keys(scripts).sort().forEach(function(key) {
203+
sortedScripts[key] = scripts[key];
204+
});
205+
return sortedScripts;
206+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
https://github.com/heroku/heroku-buildpack-nodejs.git
2+
https://github.com/fs-webdev/heroku-buildpack-upload-static-assets-to-s3.git
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
if [ "$NODE_ENV" == "production" ]; then
4+
echo "-----> Building .npmrc and .netrc"
5+
6+
echo "//code.lds.org/artifactory/api/npm/npm-fhd/:_authToken=${NPM_TOKEN}" > .npmrc
7+
echo "@fs:registry=https://code.lds.org/artifactory/api/npm/npm-fhd/" >> .npmrc
8+
echo -e "machine github.com\n login $GITHUB_AUTH_TOKEN" > ~/.netrc
9+
fi
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: npx startup start -w ${WEB_CONCURRENCY:-4}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const setProxies = require('exo/proxy');
2+
const snow = require('snow');
3+
const setWebpackManifest = require('snow/lib/utils/webpackManifest.js');
4+
const snowConfig = require('./snow.config.js');
5+
const hf = require('hf');
6+
7+
/**
8+
* Expose the app
9+
*/
10+
const app = module.exports = snow(__dirname, hf, snowConfig);
11+
12+
setWebpackManifest(app,'build');
13+
14+
if (app.get('env') === 'development') {
15+
app.stack.front(function () {
16+
setProxies(app);
17+
});
18+
}
19+
20+
21+
app.stack.postRoute(function () {
22+
app.get('/',(req,res)=>{
23+
res.render('index', {
24+
indexPath: '../build/_index.html',
25+
// _layoutFile: './async_layout'
26+
})
27+
});
28+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var urlLookup = {
2+
'cas-public-api.cas.ident.service': process.env.BASE_URL + '/cas-public-api',
3+
'cis-public-api.cis.ident.service': process.env.BASE_URL + '/cis-public-api',
4+
};
5+
6+
var serviceLocatorOptions = {
7+
fallbackFunction: function (serviceName) {
8+
if (urlLookup[serviceName]) {
9+
return urlLookup[serviceName];
10+
}
11+
throw new Error(`${serviceName} was not found in binding registry or urlLookup`);
12+
}
13+
};
14+
15+
module.exports = {
16+
experiments : [
17+
{
18+
// Author/Owner: Tyler Graf
19+
name: 'coolExperiment',
20+
description: 'The coolest experiment',
21+
default: true
22+
}
23+
],
24+
proxyUser: true,
25+
cacheEncryption: true,
26+
serviceLocatorOptions
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const setProxies = require('exo/proxy');
2+
const hf = require('hf');
3+
const snow = require('snow');
4+
const path = require('path');
5+
const waitForWebpack = require('snow/lib/utils/waitForWebpack.js');
6+
7+
const initiatedDirectory = process.env.INIT_CWD;
8+
const snowConfig = require(path.join(initiatedDirectory, 'snow.config.js'));
9+
10+
module.exports = app => {
11+
setProxies(app);
12+
waitForWebpack(app);
13+
14+
snowConfig.app = app;
15+
snow(initiatedDirectory, hf, snowConfig);
16+
17+
app.get('/', (req, res, next) => {
18+
res.render('index', {
19+
indexPath: '../dist/_index.html',
20+
// _layoutFile: './async_layout'
21+
});
22+
});
23+
24+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<%
2+
page.secondaryNav = [
3+
{"href": appPath("/"), title: 'Stuff', "text": 'Stuff'},
4+
];
5+
page.showHelper = true;
6+
%>
7+
<h1>hi</h1>
8+
<div id="root"></div>
9+
<%- include(indexPath) %>

packages/react-scripts/template/gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
# production
1212
/build
1313

14+
# development
15+
/dist
16+
1417
# misc
1518
.DS_Store
19+
.env
1620
.env.local
1721
.env.development.local
1822
.env.test.local

0 commit comments

Comments
 (0)