Skip to content

Commit 196316c

Browse files
committed
brunch + react skeleton w/ livereload and stub modules
1 parent 626b401 commit 196316c

File tree

10 files changed

+4818
-0
lines changed

10 files changed

+4818
-0
lines changed

build/app/assets/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>NetCreate Prototype</title>
5+
<meta charset="utf-8" />
6+
<script src="netc-lib.js"></script>
7+
<script src="netc-app.js"></script>
8+
</head>
9+
<body>
10+
<div id="system-shell"></div>
11+
<script>require("init")</script>
12+
</body>
13+
</html>

build/app/gui/App.jsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
3+
export default class App extends React.Component {
4+
5+
render() {
6+
return (
7+
<div id="content">
8+
<h1>NetCreate AppShell</h1>
9+
</div>
10+
);
11+
}
12+
13+
}

build/app/init.jsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import ReactDOM from 'react-dom';
2+
import React from 'react';
3+
import App from 'gui/App';
4+
5+
import UNISYS from 'sys/unisys';
6+
import DATASTORE from 'sys/datastore';
7+
8+
import SETTINGS from 'settings';
9+
10+
console.group('init.jsx module comparison');
11+
console.log('ReactDOM', ReactDOM);
12+
console.log('UNISYS', UNISYS);
13+
console.groupEnd();
14+
15+
console.log('> init.jsx loaded');
16+
17+
UNISYS.Initialize();
18+
DATASTORE.Initialize();
19+
20+
document.addEventListener('DOMContentLoaded', () => {
21+
console.log('init.jsx initializing App into #system-shell');
22+
ReactDOM.render(<App />, document.querySelector('#system-shell'));
23+
});

build/app/settings.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*//////////////////////////////// ABOUT \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*\
2+
3+
SETTINGS
4+
stub for testing module loading
5+
6+
\*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ * //////////////////////////////////////*/
7+
8+
console.log(`> SETTINGS system module loaded`);
9+
10+
/// STORAGE ///////////////////////////////////////////////////////////////////
11+
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
12+
13+
let S = {};
14+
let DATE = new Date();
15+
16+
/// MAIN GETTER/SETTER FUNCTION //////////////////////////////////////////////
17+
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
18+
/*/ settings.js returns a function as its module.exports value so
19+
syntax like let a = SETTINGS['key'] can be used.
20+
/*/ let MOD = ( a, b ) => {
21+
if (a===undefined) throw ('SETTINGS requires key or key,value parms');
22+
if (typeof a!=='string') throw ('SETTINGS parm1 must be key string');
23+
24+
if (b===undefined) {
25+
return S[a];
26+
} else {
27+
S[a] = b;
28+
return b;
29+
}
30+
}
31+
32+
/// API ///////////////////////////////////////////////////////////////////////
33+
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
34+
/*/ alternate call to set a key value pair
35+
/*/ MOD.Set = ( key, val ) => { MOD( key, val ) };
36+
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
37+
/*/ alternate call to retrieve a key
38+
/*/ MOD.Get = ( key ) => { MOD( key ) };
39+
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
40+
/*/ test time function
41+
/*/ MOD.CurrentTime = () => {
42+
return DATE.toDateString();
43+
};
44+
45+
46+
47+
/// EXPORT MODULE DEFINITION //////////////////////////////////////////////////
48+
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
49+
module.exports = MOD;

build/app/sys/datastore.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*//////////////////////////////// ABOUT \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*\
2+
3+
DATASTORE
4+
stub for testing module loading
5+
6+
\*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ * //////////////////////////////////////*/
7+
8+
// const SETTINGS = require('settings');
9+
import SETTINGS from 'settings';
10+
11+
let MOD = { module_name : 'DATASTORE' };
12+
let time = SETTINGS.CurrentTime();
13+
console.log(`> ${MOD.module_name} system module loaded ${time}`);
14+
15+
MOD.Initialize = () => {
16+
console.log(`${MOD.module_name} initializing`);
17+
if (SETTINGS('unisys')) console.log('SETTINGS unisys =',SETTINGS('unisys'));
18+
else (console.log('SETTINGS unisys is undefined'));
19+
};
20+
21+
module.exports = MOD;

build/app/sys/unisys.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*//////////////////////////////// ABOUT \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*\
2+
3+
UNISYS
4+
stub for testing module loading
5+
6+
\*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ * //////////////////////////////////////*/
7+
8+
// const SETTINGS = require('settings');
9+
import SETTINGS from 'settings';
10+
11+
let MOD = { module_name : 'UNISYS' };
12+
let time = SETTINGS.CurrentTime();
13+
console.log(`> ${MOD.module_name} system module loaded ${time}`);
14+
15+
MOD.Initialize = () => {
16+
console.log(`${MOD.module_name} initializing`);
17+
SETTINGS('unisys','loaded');
18+
};
19+
20+
module.exports = MOD;

build/brunch-config.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = {
2+
3+
files: {
4+
// NOTE: brunch includes ONLY files referred to by require() statements
5+
// NOTE: app, vendor, public are relative to this config file
6+
// NOTE: any directory is fair game for fileglob patterns
7+
javascripts: {
8+
joinTo: {
9+
'netc-app.js' : /^app/,
10+
'netc-lib.js' : /^(?!app)/
11+
}
12+
}
13+
},
14+
15+
plugins: {
16+
babel: {
17+
// brunch-babel plugin requires additional babel settings to enable jsx processing
18+
// npm i --save-dev babel babel-preset-env babel-preset-react
19+
// npm i --save-dev babel-brunch@github:babel/babel-brunch
20+
presets : ['env', 'react']
21+
}
22+
},
23+
24+
server: {
25+
port : 3000
26+
}
27+
28+
};

build/brunch-server.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*//////////////////////////////// ABOUT \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*\
2+
3+
NODE CUSTOM SERVER
4+
brunch-server.js is automatically used by brunch if it exists
5+
6+
\*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ * //////////////////////////////////////*/
7+
8+
const express = require('express');
9+
const app = express();
10+
11+
/// SERVER STATIC FILES ///////////////////////////////////////////////////////
12+
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
13+
app.use( express.static(__dirname + '/public') );
14+
15+
/// WEBSERVICE STUB ///////////////////////////////////////////////////////////
16+
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
17+
app.post('/action', (req, res, next) => {
18+
res.send('POST action completed!');
19+
});
20+
21+
/// MODULE EXPORT /////////////////////////////////////////////////////////////
22+
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23+
/*/ Export the module like this for Brunch.
24+
/*/ module.exports = (config, callback) => {
25+
26+
app.listen(config.port, function () {
27+
console.log(`APP SERVER LISTENING on PORT ${config.port}`);
28+
callback();
29+
});
30+
31+
// Return the app; it has the `close()` method, which would be ran when
32+
// Brunch server is terminated. This is a requirement.
33+
return app;
34+
35+
};

0 commit comments

Comments
 (0)