Open daveseah opened 1 year ago
Outlining all the bits of the current brunchjs-based build system to see what we can replace it with.
In package.json
we have several scripts defined:
brunch watch -s
is the main development version brunch build -e classroom
was used to generate a non-devserver version for use on a classroom LAN. brunch build -e package
is used to create static html demo sitesBefore running brunch
itself, there is a hack to create the app-config/netcreate-config.js
file using Ben's nc.js
configuration tool, and this is also imported into brunch-config.js
as the constant NC_CONFIG
// this file generated by NC command
const NC_CONFIG = {
dataset: "test",
port: "3000",
googlea: "0"
};
if (typeof process === "object") module.exports = NC_CONFIG;
if (typeof window === "object") window.NC_CONFIG = NC_CONFIG;
The nc.js
script MUST be run for Netcreate to function, though this is not strongly documented in the codebase itself. At minimum, you can do:
# create app-config/netcreate-config.js to use a database and template
# in the runtime directory
./nc.js --dataset='test'
# now you can start netcreate
npm run dev
In this example, the files test.loki
and test.template.toml
are created in the runtime
folder. These are used by the appserver to spawn a database instance (LokiJS) and a TOML file that contains the configuration of the "templated features".
Brunch works by collecting all the same types of file into a concatenated bundle stufed into the public
directory (brunch default).
The brunch-config.js
file is used by the brunch
command, and the devserver is loaded in brunch-server.js
(these are both hardcoded filenames used by brunch).
The brunch-config.js
file specifies these main bundles:
javascript files:
app* -> scripts/netc-app.js
!app -> scripts/netc-lib.js
css
app, node_modules -> styles/netc-app.css
There are specific plugins to handle transpilation and static files.
babel:
presets: env, react
copycat:
app-config/* -> public/config
app-data/* -> public/data
app-templates/* -> public/templates
app-htmldemos/* -> public/htmldemos
There are specific environmental switches: classroom, package, and package-debug
The brunch custom webserver is used by brunch watch --server
which looks for a hardcoded brunch-server.js
filename.
Ours does quite a bit in configuration:
/
to serve index.ejs
with the values from netcreate-configWhen the server is finally started, the callback does a number of additional checks.
Then it configures the underlying system:
The server instance also gets an error
handler to detect EADDRINUSE
NOTE: The template system is complicated and its code is extremely difficult follow. There are legacy datafiles in app-templates
and app-data
that may or may not be related. Awaiting confirmation on what these are currently being used for.
The build tool
brunch
that is used to compile the NetCreate app is no longer actively developed or supported. For future-proofing, we may want to consider replacing it with a more modern tool.BACKGROUND
Brunch is the Javascript Build Tool aka "bundler" that's currently used in NetCreate-2018 and still used in NetCreate-ITEST. At the time it was a contender to Webpack, the bundler that eventually won out. Brunch is no longer actively maintained and many of its dependencies require security updates. However, the true security needs are on the webserver side, not the developer's build tool side; in other words, so long as the web app itself is secure, the tools that we use to build the web app maybe don't have to. This is something we will need to untangle, probably when we get to the server architecture point.
TECH REVIEW
I've made a note of what the current bundler process does:
brunch
command usesbrunch-config.js
to tell it how to combine our source files into "bundles" of javascript and css to be copied topublic
.app
app
(node_modules)app-data
,app-template
,htmldemo
, andapp-config
into the top level of thepublic
siteassets
directory into the top level ofpublic
app/assets/index.ejs
EJS template and delivered by the Express server defined in our custombrunch-server.js
. For the static version of the site, anindex.html
is generated from this template.SOLUTION
We just need to produce these bundles in an alternate way so they can be included in
app/index.ejs
. For reference, here's the general structure of that file:In the above you can see:
netc-app.css
loadedconfig/netcreate-config.js
loaded, which sets database params (dynamically generated bync.js
)NC_UNISYS
declarednetc-lib.js
loadednetc-app.js
loadedrequire('init')
runs the code frominit.jsx
, which starts the entire appOur later projects (e.g. GEMSTEP) already have converted to Webpack so it should not be too much of a problem, just an annoyance to deal with on a scheduled "technical debt" week when we start doing those.