Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
statictron
Advanced tools
Readme
Build a static website with built in (optional) ejs and css bundling support.
npm install --save statictron
npm install --global statictron
git clone https://github.com/markwylde/statictron.git
cd demo
statictron --loader ejs --loader css --output=./dist --ignore _paritals/** ./src
You can serve the outputted
dist
directory using any web server.Try servatron then browse to
http://0.0.0.0:8000
.servatron --port 8000 --directory dist
statictron cli - v3.0.3
Example usage:
statictron --loader ejs --loader css --watch --output=dist --ignore _partials/** --scope abc=123 src
statictron -l ejs -l css -w -o=dist -i _partials/** -s abc=123 src
Options:
--watch watch the source directory for changes and rebuild
--output (-o) pathName specify a directory to save the generated files to
--no-clean keep existing files in output directory
--ignore[] (-i) pattern a (or list of) glob pattern(s) that should be ignored from source
--scope[] var=val build an object to be passed to all loaders
--loader[] loaderName specify a built in loader to use
ejs parse any *.ejs file as ejs templates
css bundle any index.css files and ignore other css files
--help show this help screen
import statictron from 'statictron';
await statictron({
source: './src',
output: './dist',
loaders: [
statictron.loaders.ejs,
statictron.loaders.css
],
scope: {
exampleVariable: 'test123'
},
logger: console.log // default is undefined which means no logging
});
Every time a file is found in the source
directory, it will get passed through the provided loaders (in order);
A loader is a pure function that takes three arguments:
key | description | example |
---|---|---|
sourceFile | full source file path | /home/example/src/index.ejs |
targetFile | full assumed target file path | /home/example/dist/index.ejs |
options | the options you passed to statictron | { source, output, loaders, scope, logger } |
Return:
Note that the scope
on the options will contain additional variables if a loop was present higher up the chain.
A very basic example that replaces any 'hello.template' file's contents with 'hello world' is:
async function helloExampleLoader (sourceFile, targetFile, options) {
// skip any files that aren't `hello.template`
if (path.basename(file) !== 'hello.template') {
return
}
// get the source file data
// however, we won't need it for this example
// const result = await fs.readFile(sourceFile, 'utf8');
const result = 'Hello World';
// rename the file from `hello.template` to `hello.html`
const finalTarget = targetFile.replace('.template', '.html');
// save the new file to the new output target
await fs.mkdir(path.dirname(finalTarget), { recursive: true });
await fs.writeFile(finalTarget, result);
// rerun all the loaders again on our new target file
return finalTarget;
}
Now we have created our example loader, we can pass it into statictron as such:
await statictron({
source: './src',
output: './dist',
loaders: [
helloExampleLoader
]
})
There are two built in loaders, one for ejs
and one for css
.
You can loop through an array on the scope. For example:
await statictron({
source: './src',
output: './dist',
loaders: [
statictron.loaders.ejs,
statictron.loaders.css
],
scope: {
items: [{
keyA: 'some-example-1',
keyB: 'some-example-2'
}],
people: [{
id: 'first-person',
name: 'First Person'
}, {
id: 'second-person',
name: 'Second Person'
}]
},
logger: console.log // default is undefined which means no logging
});
Example file structure
[item of items]
[item.keyA].ejs
[item.keyB].ejs
[person of people]
[person.id].ejs
The left part of the folder structure would will be used as the key, passed into the scope.
So in the above [person.id].ejs
file:
first-person/index.html
and second-person/index.html
<%= person.name =>
will render 'First Person' and 'Second Person'For a full example, look at the demo or the api - file based loop test.
FAQs
Build a static website using ejs.
The npm package statictron receives a total of 4 weekly downloads. As such, statictron popularity was classified as not popular.
We found that statictron demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.