endpoint-ei
v1.4.2
Published
ejs intermediate is a build environment for nodejs it simply compiles a folder of ejs fun stuff. but this is used in every project.
Maintainers
Readme
ENDPOINT-EI
EJS Intermediate Build
By Syonfox
A simple build tooling to compile ejs files to a directory -with some context
then some helper scripts that use this in cloudflare pages context.
Changelog:
v1.4.2
- moved messy notes to
/mess - Add support for server to server index.html if present rather then directory listing by default
- updated web site at https://ei.sgol.pub/
- fixed bugs in server
- todo fix the live server next.
v1.4.1
- add node shebangs
v1.4.0
- fix director context
- add ei-serv, ei-live to bin support
- note depends on node 14+
Timing
Due to the complex nature of this project.
I would like to spend a moment disusing execution timing of the different scripts.
$ ls -sh -t1
total 112K
8.0K README.md
4.0K ulib // build output mess
4.0K functions // build output dev tests
4.0K package.json
8.0K server.js // theis is the endpoint dev server nice single file http server in nodejs.
12K package-lock.json
4.0K node_modules
4.0K eisgp.sh // ei src . global.json && git commit -m "pub" && git push ;
4.0K global.json // context for ei build (build.js called from build.sh)
4.0K public // MAIN BUILD OUTPUT (all folders in src)
4.0K cmd.sh // the npx endpoint-ei cli tool
4.0K mess // random stuf
4.0K src // The website ei.sgol.pub
4.0K server-live.js
8.0K build.js // the main npx endpoint-ei --build or npm run ei
4.0K build.sh // project build script
4.0K clean.sh // project clen script
4.0K eisg.sh // aliase for build
4.0K init.sh // COOL this is a project creation template.
4.0K PLANING.md
4.0K publish.sh
8.0K QUICKSTART.md
First a developer does some work in /src/public
cd src
cd public
wget https://sgol.pub/src/ip ; # downalods a json file named ip
bash ipjsontree.sh ip ; # converts it to ip.html
firefox ip.htmlthen you can build with npx endpoint-ei --build ./src . global.json
Read the Scripts n' Bincat package.json
Fancy example bootstrap script:
If you are reading this and understand it all ask us for a job. we are loo9king for deticated partners who want to colaberate on new projects. for fun and profit (postman)[https://app.getpostman.com/join-team?invite_code=ae56402b69bf9790d65960d149958896]
https://elements.getpostman.com/redirect?entityId=28647518-aba18cd9-cbd4-4011-95b1-ce2ba5155e5b&entityType=collection
mkdir myapp ; cd myapp ;
npm init
npm install endpoint-ei -g
npm install endpoint-ei --save-dev
npx eisg ; # this builds ./src/*.ejs -> ./ ignorein partials folders and copying all other filse. ejs has global.json from execution folder available
mkdir functions
mkdir public
mkdir ./src/
midir ./src/functions
mkdir ./src/public
echo {"FOO":"BAR"}
npx ei ./src . global.json; # if installed
node build src . global.json # to run locally in this repo

NEW WOO
npx [email protected] --server /path/to/static/assetshttps://sgol.pub/JS_EVERYWHERE_EVERYTHING_ALL_AT_ONCE
Deploy an entire new project to git and cloudflair in under 5 mins
https://freemap.sgol.pub/fm/yolobud
READ package.json
This publishes only build.js
everything else is a demo app
ei uses itself as a dev dependency to show you how you could use it
ejs intermediate is a intermediate layer for developing apps.
essential we have an folder of build assets this can be anything.
so we start with a folder
mkdir ./app
mkdir ./app/src
nano ./app/package.json
nano ./app/.gitignore
nano ./app/README.md
bash ./app/build.sh
bash ./app/publish.shecho "Generally the main build outputs are"
ls ./app/public ; # Static assets that are usually free to host
ls ./app/function ; # pages worker function
let everything be relative to the execution root i hope lol
from now own we are going inside the app folder this is the project we are recusivaly building.
There are some assumptions:
sourceis a folderdestPathdest is a path we will try and create the folder- all files are named with proper extensions +.ejs
- if you dont want a file compiled but its ejs put it in
partialsfolder these are ignored - the context of the build command is passed as global
- each dir can optionally have a
ejs_dir_context.json - each ejs file excluding partial may have a corresponding
compleate/path/to/mydoc.html.ejs.replace('.ejs', '.context.json'); - all other files should probably be copied directly, separately only ejs is built in this step
npm install endpoint-ei
# npx ei source destPath global.json
#Cloudflari pages
mkdir src # a src directory
mkdir src/function # a directory for all static assets
mkdir src/public # a directory for all pages worker functions.
echo '{"FOO":"BAR"}' > global.json # define global context
npx ei src . global.json # build src into current director recursively ignoring partials folders
# If you trust cloud-flare otherwise just push to git
npx wrangler pages dev ./public
# otherwise
git add *
git commit -m "publish"
git push
#
Prototype
se the shell lib_ejs.sh
It seems like you want to build a command-line tool that compiles EJS templates from a source folder to a destination folder while taking context information from JSON files and applying it to the templates. Here's an example of how you could achieve this using Node.js and the ejs package:
Project Setup:
First, make sure you have Node.js installed and set up in your project folder. Run the following command to install the required packages:
npm install ejs fs-extra minimistProject Structure:
Your project structure might look like this:
project/ ├── source/ │ ├── index.html.ejs │ ├── about.html.ejs │ ├── partials/ │ │ ├── header.ejs │ │ ├── footer.ejs │ ├── ... ├── dest/ ├── global.json ├── build.jsbuild.js:
Create a
build.jsscript to compile the EJS templates:const ejs = require('ejs'); const fs = require('fs-extra'); const minimist = require('minimist'); async function build(source, dest, globalContext) { // Read global context const globalData = require(globalContext); // Process files const files = await fs.readdir(source); for (const file of files) { if (file.endsWith('.ejs')) { const contextPath = file.replace('.ejs', '.context.json'); const filePath = `${source}/${file}`; const context = fs.existsSync(contextPath) ? require(contextPath) : {}; const compiled = await ejs.renderFile(filePath, { ...globalData, ...context }); const outputPath = `${dest}/${file.replace('.ejs', '')}`; await fs.writeFile(outputPath, compiled); console.log(`Compiled: ${filePath} -> ${outputPath}`); } else { const inputPath = `${source}/${file}`; const outputPath = `${dest}/${file}`; await fs.copy(inputPath, outputPath); console.log(`Copied: ${inputPath} -> ${outputPath}`); } } } // Parse command-line arguments const args = minimist(process.argv.slice(2)); const source = args._[0]; const dest = args._[1]; const globalContext = args._[2]; build(source, dest, globalContext) .then(() => console.log('Build completed successfully')) .catch(error => console.error('Error:', error));Usage:
To compile the EJS templates, run the following command:
mkdir functions ; # The ouput serverles cloudflare function mkdir public ; # The output statec pages assets mkdir src ; # The input src this should contain a src/function and src/public nano global.json ; # The global json contect for any ejs files to build node build.js src . global.jsontheoretically
Replace
sourcewith the path to your source folder,destwith the path to the destination folder, andglobal.jsonwith the path to your global context JSON file.
This script should read EJS templates from the source folder, apply context data from corresponding JSON files, and generate the compiled HTML files in the dest folder. Other non-EJS files will be copied directly to the destination folder. The script uses the ejs, fs-extra, and minimist packages to achieve this functionality.
I think we can theoretically build the projects like this on the fly in a cloud flare worker under 10 mb
