Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ versions
archive
node_modules/
flow/
tests
2 changes: 2 additions & 0 deletions CLI_ANNOUNCE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# v1.8.0 port RangeStart can be specified via --port for serving apps
# v1.7.2 *NEW*
# v1.7.1 Do: sergeant create app_builder myawesomeapp
# v1.7.0 Added windows support. Stable version.
# v1.6.0 Support for data: svg url import resolution Stable version
Expand Down
69 changes: 41 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
# About Sergeant

A lightweight micro-services producing deno-[p]react SSG-first SEO-friendly framework.
A lightweight micro-services producing deno-[p]react SSG-first SEO-friendly
framework.

For a new era of frontend development with NO node_modules (Save GB+ files on disk).
For a new era of frontend development with NO node_modules (Save GB+ files on
disk).

+ Produces bundles within seconds for 100s of apps.
+ Cross-compile from multiple projects
+ Supports scss
+ Scaffolding
+ Has livereload
+ denocacheusage: 10MB only, bundle sizes less than 20KB (if u use preact), and 200KB for react.
- Produces bundles within seconds for 100s of apps.
- Cross-compile from multiple projects
- Supports scss
- Scaffolding
- Has livereload
- denocacheusage: 10MB only, bundle sizes less than 20KB (if u use preact), and
200KB for react.

Compare this with 200MB-400MB node_modules for a react hello world project.

Finally, you can `rimraf node_modules`.

# Sergeant is production ready from Day-1

✨ Sergeant 🫡 A front-end microservices framework!
✨ Sergeant 🫡 A front-end microservices framework!

```
███████╗███████╗██████╗ ██████╗ ███████╗ █████╗ ███╗ ██╗████████╗
Expand Down Expand Up @@ -52,15 +55,18 @@ Done
```

## Philosophy

1. No breaking changes (versioned imports)
2. SSG over SSR
3. Always bundle to one-file for 1-SPA

### More...

4. Support bundling multiple apps, SPAs via micro-services / app-routing
5. Support progressive and offline apps

# Commands

```
sergeant
sergeant build
Expand All @@ -69,64 +75,71 @@ sergeant serve --dev
```

# Install

Only need deno to install sergeant (esbuild is automatically imported):

## sergeant

```
deno install -A -f https://cdn.jsdelivr.net/gh/scriptmaster/sergeant@1.7.1/sergeant.ts
deno install -A -f https://cdn.jsdelivr.net/gh/scriptmaster/sergeant@1.8.0/sergeant.ts
```

Only need deno and sergeant and you can do `sergeant` or `sergeant serve`

### Build All apps:

`sergeant build`

### Live Dev Server all apps:
`sergeant serve`

`sergeant serve`

### Build specific app:

`sergeant build`

### Live Dev Server specific app:
`sergeant serve`

`sergeant serve`

## Installing Deno

https://docs.deno.com/runtime/manual/getting_started/installation

### Windows x64:
Using PowerShell (Windows):
irm https://deno.land/install.ps1 | iex
### Windows x64:

Using PowerShell (Windows): irm https://deno.land/install.ps1 | iex

#### Or Using Chocolatey:

choco install deno

### MacOS: brew install deno


# Deno Plugins:
Uses:
https://github.com/scriptmaster/esbuild_deno_loader

Uses: https://github.com/scriptmaster/esbuild_deno_loader
https://deno.land/x/esbuild_plugin_sass_deno
https://github.com/esbuild/community-plugins#plugins-for-deno

# Security of packages

How packages are downloaded?

Packages are primarily downloaded as ESM modules from https://esm.sh/package/ (instead of registry.npmjs.org).
+ It can be swapped to use enterprise ESM packages repository.
+ Packages
Packages are primarily downloaded as ESM modules from https://esm.sh/package/
(instead of registry.npmjs.org).

The package can be looked up in ./vendor/ and ./node_modules/ in the format mod.ts index.mjs index.cjs index.js
- It can be swapped to use enterprise ESM packages repository.
- Packages

The package can be looked up in ./vendor/ and ./node_modules/ in the format
mod.ts index.mjs index.cjs index.js

# DI

React Context API is an incorrect implementation of a simple DI with prop drilling.
In apps containing 20+ dependencies to provider, the context pattern could become 20+ nested nodes.
React Context API is an incorrect implementation of a simple DI with prop
drilling. In apps containing 20+ dependencies to provider, the context pattern
could become 20+ nested nodes.

DI enables you to directly provide the service/implementation for the consumer.

Expand All @@ -136,12 +149,12 @@ Extra watch dirs

Create app level deno.json and configure watching extra deps:

{
"watch": "emeraldcss"
}
{ "watch": "emeraldcss" }

# mithril
if an app dir contains mithril dir, its files (i.e., apps/appname/mithril/*.html or src/mithril/*.html) will be compiled as mithril files.

if an app dir contains mithril dir, its files (i.e., apps/appname/mithril/_.html
or src/mithril/_.html) will be compiled as mithril files.

# web framework

Expand Down
71 changes: 36 additions & 35 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
{
"imports": {
"react": "https://esm.sh/react@18.2.0?prod",
"react-dom": "https://esm.sh/react-dom@18.2.0?prod",
"preact": "https://esm.sh/preact@10.17.1",
"preact-router": "https://esm.sh/preact-router@4.1.2",
"preact-render-to-string/jsx": "https://esm.sh/preact-render-to-string@6.2.1/jsx",
"@preact/compat": "https://esm.sh/@preact/compat@17.1.2",
"react-redux": "./vendor/github.com/react-redux/src/index.ts",
"vue": "https://esm.sh/vue@3.3.4",
"d3": "https://esm.sh/d3@7.8.5",
"emeraldcss": "https://unpkg.com/emeraldcss@1.0.1",
"emeraldcss/": "https://unpkg.com/emeraldcss@1.0.1/",
"antd": "https://esm.sh/antd",
"@angular/cli": "https://esm.sh/@angular/cli",
"vendor": "https://esm.sh/vendor",
"react-router-dom": "https://esm.sh/react-router-dom"
},
"compilerOptions": {
"jsx": "react-jsx"
},
"tasks": {
"build": "deno run -A sergeant.ts",
"install": "deno install -A -f -n sergeant sergeant.ts",
"install_vendor": "deno install -A -f -n vendor vendor.ts",
"debug": "deno run -A sergeant.ts nn",
"ssg": "deno task build ssg; denoliver dist/ssg/static/ -p 3300"
},
"deploy": {
"project": "8ced75ac-cfa0-4a9b-9783-c8a8e1b3aaf9",
"exclude": [
"**/node_modules"
],
"entrypoint": "https://deno.land/std@0.217.0/http/file_server.ts"
}
}
"imports": {
"react": "https://esm.sh/react@18.3.1",
"react-dom": "https://esm.sh/react-dom@18.3.1",
"react-dom/": "https://esm.sh/react-dom@18.3.1/",
"preact": "https://esm.sh/preact@10.17.1",
"preact-router": "https://esm.sh/preact-router@4.1.2",
"preact-render-to-string/jsx": "https://esm.sh/preact-render-to-string@6.2.1/jsx",
"@preact/compat": "https://esm.sh/@preact/compat@17.1.2",
"react-redux": "./vendor/github.com/react-redux/src/index.ts",
"vue": "https://esm.sh/vue@3.3.4",
"d3": "https://esm.sh/d3@7.8.5",
"emeraldcss": "https://unpkg.com/emeraldcss@1.0.1",
"emeraldcss/": "https://unpkg.com/emeraldcss@1.0.1/",
"antd": "https://esm.sh/antd",
"@angular/cli": "https://esm.sh/@angular/cli",
"vendor": "https://esm.sh/vendor",
"react-router-dom": "https://esm.sh/react-router-dom"
},
"compilerOptions": {
"jsx": "react-jsx"
},
"tasks": {
"build": "deno run -A sergeant.ts",
"install": "deno install -A -f -n sergeant sergeant.ts",
"install_vendor": "deno install -A -f -n vendor vendor.ts",
"debug": "deno run -A sergeant.ts nn",
"ssg": "deno task build ssg; denoliver dist/ssg/static/ -p 3300"
},
"deploy": {
"project": "8ced75ac-cfa0-4a9b-9783-c8a8e1b3aaf9",
"exclude": [
"**/node_modules"
],
"entrypoint": "https://deno.land/std@0.217.0/http/file_server.ts"
}
}
21 changes: 2 additions & 19 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 19 additions & 5 deletions sergeant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ import {
// To get started:
// deno install -f -A sergeant.ts; sergeant serve

const portRangeStart = 3000;
const VERSION = "v1.7.2";
const port = { RangeStart: 3000 };
const VERSION = "v1.8.0";
const ESBUILD_MODE = Deno.env.get("ESBUILD_PLATFORM") ||
Deno.env.get("ESBUILD_MODE") || "neutral";
const ESBUILD_FORMAT = Deno.env.get("ESBUILD_FORMAT") || "esm";
Expand Down Expand Up @@ -266,14 +266,28 @@ async function buildApps(appName = "") {
}

async function serveApps(appName: string) {
if (args.includes("--port")) {
const portIndex = args.indexOf("--port");
if (args[portIndex + 1] && parseInt(args[portIndex + 1], 10)) {
port.RangeStart = parseInt(args[portIndex + 1], 10);
// console.log("port RangeStart:", port.RangeStart);
}
}
if (args.includes("-p")) {
const portIndex = args.indexOf("-p");
if (args[portIndex + 1] && parseInt(args[portIndex + 1], 10)) {
port.RangeStart = parseInt(args[portIndex + 1], 10);
// console.log("port RangeStart:", port.RangeStart);
}
}
if (appName && appName[0] != "-") { //do not mistake for a flag like: --dev
if (!existsSync(app(appName))) {
return console.log("No such app: ", app(appName));
}
return await serveRefresh(appName, portRangeStart);
return await serveRefresh(appName, port.RangeStart);
} else if (appsDir == "src") {
console.log("Serving .");
await serveRefresh(".", portRangeStart);
await serveRefresh(".", port.RangeStart);
return;
}

Expand All @@ -283,7 +297,7 @@ async function serveApps(appName: string) {
for await (const dirEntry of Deno.readDir(appsDir)) {
if (dirEntry.isDirectory && dirEntry.name[0] != ".") {
// const appDir = join(appsDir, dirEntry.name);
await serveRefresh(dirEntry.name, portRangeStart + servers);
await serveRefresh(dirEntry.name, port.RangeStart + servers);
servers++;
}
}
Expand Down