asjs-express 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +360 -0
- package/bin/create-asjs-app.js +223 -0
- package/lib/asjs.js +306 -13
- package/lib/client/asjs-router.js +46 -1
- package/package.json +12 -2
- package/templates/minimal/README.md.tpl +12 -0
- package/templates/minimal/app.js.tpl +29 -0
- package/templates/minimal/gitignore.tpl +4 -0
- package/templates/minimal/package.json.tpl +15 -0
- package/templates/minimal/views/home.asjs.tpl +5 -0
- package/templates/minimal/views/layouts/main.asjs.tpl +16 -0
- package/templates/starter/README.md.tpl +12 -0
- package/templates/starter/app.js.tpl +54 -0
- package/templates/starter/gitignore.tpl +4 -0
- package/templates/starter/package.json.tpl +15 -0
- package/templates/starter/views/about.asjs.tpl +10 -0
- package/templates/starter/views/home.asjs.tpl +10 -0
- package/templates/starter/views/layouts/main.asjs.tpl +16 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const express = require('express');
|
|
2
|
+
const { setupAsjs } = require('asjs-express');
|
|
3
|
+
|
|
4
|
+
const app = express();
|
|
5
|
+
const port = process.env.PORT || __PORT__;
|
|
6
|
+
|
|
7
|
+
const asjs = setupAsjs(app, {
|
|
8
|
+
rootDir: __dirname,
|
|
9
|
+
defaultLayout: 'layouts/main',
|
|
10
|
+
navItems: [
|
|
11
|
+
{ href: '/', label: 'Home', activeMode: 'exact' },
|
|
12
|
+
{ href: '/about', label: 'About', activeMode: 'exact' }
|
|
13
|
+
],
|
|
14
|
+
transitions: 'fade',
|
|
15
|
+
prefetch: true,
|
|
16
|
+
loadingBar: true
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const buildPage = asjs.createPageModel({
|
|
20
|
+
pageDescription: '__APP_TITLE__ starter created by ASJS.',
|
|
21
|
+
renderSummary: []
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
app.get('/', asjs.createPageRoute('home', {
|
|
25
|
+
buildPage,
|
|
26
|
+
renderState: {
|
|
27
|
+
delay: 120,
|
|
28
|
+
label: 'Home page ready',
|
|
29
|
+
narrative: 'ASJS prepared the page model before the HTML response reached the browser.'
|
|
30
|
+
}
|
|
31
|
+
}, () => ({
|
|
32
|
+
title: '__APP_TITLE__',
|
|
33
|
+
heroTitle: 'Welcome to __APP_TITLE__.',
|
|
34
|
+
heroText: 'This starter already includes the built-in header, SPA navigation, and a render-state example.'
|
|
35
|
+
})));
|
|
36
|
+
|
|
37
|
+
app.get('/about', asjs.createPageRoute('about', {
|
|
38
|
+
buildPage,
|
|
39
|
+
renderState: {
|
|
40
|
+
delay: 140,
|
|
41
|
+
label: 'About page ready',
|
|
42
|
+
narrative: 'The second route uses the same layout and internal navigation flow.'
|
|
43
|
+
}
|
|
44
|
+
}, () => ({
|
|
45
|
+
title: 'About | __APP_TITLE__',
|
|
46
|
+
heroTitle: 'The starter is ready to grow.',
|
|
47
|
+
heroText: 'Add new routes, layouts, forms, and partials without leaving the ASJS server-rendered flow.'
|
|
48
|
+
})));
|
|
49
|
+
|
|
50
|
+
app.use(asjs.errors());
|
|
51
|
+
|
|
52
|
+
app.listen(port, () => {
|
|
53
|
+
console.log(`__APP_TITLE__ running at http://localhost:${port}`);
|
|
54
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__PACKAGE_NAME__",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "ASJS starter app generated by npx asjs-express",
|
|
6
|
+
"main": "app.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "node app.js",
|
|
9
|
+
"start": "node app.js"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"asjs-express": "^__ASJS_VERSION__",
|
|
13
|
+
"express": "__EXPRESS_VERSION__"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<section style="max-width: 760px; margin: 40px auto; padding: 24px;">
|
|
2
|
+
<span>Starter about</span>
|
|
3
|
+
<h1><%= heroTitle %></h1>
|
|
4
|
+
<p><%= heroText %></p>
|
|
5
|
+
<div style="margin-top: 20px;">
|
|
6
|
+
<% renderSummary.forEach((item) => { %>
|
|
7
|
+
<div><strong><%= item.label %>:</strong> <%= item.value %></div>
|
|
8
|
+
<% }) %>
|
|
9
|
+
</div>
|
|
10
|
+
</section>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<section style="max-width: 760px; margin: 40px auto; padding: 24px;">
|
|
2
|
+
<span>Starter home</span>
|
|
3
|
+
<h1><%= heroTitle %></h1>
|
|
4
|
+
<p><%= heroText %></p>
|
|
5
|
+
<div style="margin-top: 20px;">
|
|
6
|
+
<% renderSummary.forEach((item) => { %>
|
|
7
|
+
<div><strong><%= item.label %>:</strong> <%= item.value %></div>
|
|
8
|
+
<% }) %>
|
|
9
|
+
</div>
|
|
10
|
+
</section>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title><%= title %></title>
|
|
7
|
+
<%- asjs.clientTags({ preload: true, theme: true }) %>
|
|
8
|
+
</head>
|
|
9
|
+
<body<%- asjs.bodyAttrs() %>>
|
|
10
|
+
<%- asjs.progressMarkup() %>
|
|
11
|
+
<%- asjs.header() %>
|
|
12
|
+
<main class="view-frame"<%- asjs.viewAttrs() %>>
|
|
13
|
+
<%- body %>
|
|
14
|
+
</main>
|
|
15
|
+
</body>
|
|
16
|
+
</html>
|