primate 0.9.0 → 0.9.2
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 +10 -63
- package/README.template.md +9 -57
- package/TODO +4 -0
- package/module.json +1 -1
- package/package.json +2 -2
- package/src/bundle.js +15 -0
- package/src/preset/primate.json +0 -4
- package/src/route.js +4 -2
- package/src/run.js +3 -11
- package/src/serve.js +1 -1
- package/html.js +0 -13
- package/src/Bundler.js +0 -40
package/README.md
CHANGED
|
@@ -1,54 +1,19 @@
|
|
|
1
1
|
# Primate
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An expressive, minimal and extensible framework for JavaScript.
|
|
4
4
|
|
|
5
5
|
## Getting started
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
```sh
|
|
10
|
-
mkdir -p app/{routes,components,ssl} && cd app
|
|
11
|
-
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
Create a route for `/` in `routes/site.js`
|
|
7
|
+
Create a route in `routes/hello.js`
|
|
15
8
|
|
|
16
9
|
```js
|
|
17
|
-
import html from "@primate/html";
|
|
18
|
-
|
|
19
10
|
export default router => {
|
|
20
|
-
router.get("/", () =>
|
|
11
|
+
router.get("/", () => "Hello, world!");
|
|
21
12
|
};
|
|
22
13
|
|
|
23
14
|
```
|
|
24
15
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
```html
|
|
28
|
-
Today's date is ${date}.
|
|
29
|
-
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
Generate SSL files
|
|
33
|
-
|
|
34
|
-
```sh
|
|
35
|
-
openssl req -x509 -out ssl/default.crt -keyout ssl/default.key -newkey rsa:2048 -nodes -sha256 -batch
|
|
36
|
-
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
Run
|
|
40
|
-
|
|
41
|
-
```sh
|
|
42
|
-
npx primate
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## Table of contents
|
|
46
|
-
|
|
47
|
-
* [Serving content](#serving-content)
|
|
48
|
-
* [Routing](#routing)
|
|
49
|
-
* [Domains](#domains)
|
|
50
|
-
* [Stores](#stores)
|
|
51
|
-
* [Components](#components)
|
|
16
|
+
Add `{"type": "module"}` to your `package.json` and run `npx primate`.
|
|
52
17
|
|
|
53
18
|
## Serving content
|
|
54
19
|
|
|
@@ -127,10 +92,10 @@ export default router => {
|
|
|
127
92
|
|
|
128
93
|
## Routing
|
|
129
94
|
|
|
130
|
-
Routes map requests to responses.
|
|
95
|
+
Routes map requests to responses. They are loaded from `routes`.
|
|
131
96
|
|
|
132
97
|
The order in which routes are declared is irrelevant. Redeclaring a route
|
|
133
|
-
(same pathname and same HTTP verb) throws
|
|
98
|
+
(same pathname and same HTTP verb) throws an error.
|
|
134
99
|
|
|
135
100
|
### Basic GET route
|
|
136
101
|
|
|
@@ -189,7 +154,7 @@ export default router => {
|
|
|
189
154
|
router.get("/user/view/_id", request => request.path[2]);
|
|
190
155
|
|
|
191
156
|
// can be combined with named groups
|
|
192
|
-
router.alias("_name", "(
|
|
157
|
+
router.alias("_name", "(?<name>[a-z])+");
|
|
193
158
|
|
|
194
159
|
// will return name if matched, 404 otherwise
|
|
195
160
|
router.get("/user/view/_name", request => request.named.name);
|
|
@@ -223,10 +188,8 @@ export default router => {
|
|
|
223
188
|
|
|
224
189
|
## Domains
|
|
225
190
|
|
|
226
|
-
Domains represent a collection in a store
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
A collection is primarily described using the class `fields` property.
|
|
191
|
+
Domains represent a collection in a store, primarily with the class `fields`
|
|
192
|
+
property.
|
|
230
193
|
|
|
231
194
|
### Fields
|
|
232
195
|
|
|
@@ -294,14 +257,7 @@ export default class User extends Domain {
|
|
|
294
257
|
|
|
295
258
|
```
|
|
296
259
|
|
|
297
|
-
##
|
|
298
|
-
|
|
299
|
-
Stores interface data. Primate comes with volatile in-memory store used as a
|
|
300
|
-
default. Other stores can be imported as modules.
|
|
301
|
-
|
|
302
|
-
All stores are loaded from `stores`.
|
|
303
|
-
|
|
304
|
-
### Resources
|
|
260
|
+
## Resources
|
|
305
261
|
|
|
306
262
|
* Website: https://primatejs.com
|
|
307
263
|
* IRC: Join the `#primate` channel on `irc.libera.chat`.
|
|
@@ -309,12 +265,3 @@ All stores are loaded from `stores`.
|
|
|
309
265
|
## License
|
|
310
266
|
|
|
311
267
|
MIT
|
|
312
|
-
|
|
313
|
-
[getting-started]: https://primatejs.com/getting-started
|
|
314
|
-
[source-code]: https://github.com/primatejs/primate
|
|
315
|
-
[issues]: https://github.com/primatejs/primate/issues
|
|
316
|
-
[primate-file-store]: https://npmjs.com/primate-file-store
|
|
317
|
-
[primate-json-store]: https://npmjs.com/primate-json-store
|
|
318
|
-
[primate-mongodb-store]: https://npmjs.com/primate-mongodb-store
|
|
319
|
-
[primate-react]: https://github.com/primatejs/primate-react
|
|
320
|
-
[primate-vue]: https://github.com/primatejs/primate-vue
|
package/README.template.md
CHANGED
|
@@ -1,46 +1,16 @@
|
|
|
1
1
|
# Primate
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An expressive, minimal and extensible framework for JavaScript.
|
|
4
4
|
|
|
5
5
|
## Getting started
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
```sh
|
|
10
|
-
# getting-started/lay-out-app.sh
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Create a route for `/` in `routes/site.js`
|
|
7
|
+
Create a route in `routes/hello.js`
|
|
14
8
|
|
|
15
9
|
```js
|
|
16
|
-
// getting-started/
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
Create a component in `components/site-index.html`
|
|
20
|
-
|
|
21
|
-
```html
|
|
22
|
-
<!-- getting-started/site-index.html -->
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
Generate SSL files
|
|
26
|
-
|
|
27
|
-
```sh
|
|
28
|
-
# getting-started/generate-ssl.sh
|
|
10
|
+
// getting-started/hello.js
|
|
29
11
|
```
|
|
30
12
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
```sh
|
|
34
|
-
npx primate
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Table of contents
|
|
38
|
-
|
|
39
|
-
* [Serving content](#serving-content)
|
|
40
|
-
* [Routing](#routing)
|
|
41
|
-
* [Domains](#domains)
|
|
42
|
-
* [Stores](#stores)
|
|
43
|
-
* [Components](#components)
|
|
13
|
+
Add `{"type": "module"}` to your `package.json` and run `npx primate`.
|
|
44
14
|
|
|
45
15
|
## Serving content
|
|
46
16
|
|
|
@@ -80,10 +50,10 @@ Serve the component in your route
|
|
|
80
50
|
|
|
81
51
|
## Routing
|
|
82
52
|
|
|
83
|
-
Routes map requests to responses.
|
|
53
|
+
Routes map requests to responses. They are loaded from `routes`.
|
|
84
54
|
|
|
85
55
|
The order in which routes are declared is irrelevant. Redeclaring a route
|
|
86
|
-
(same pathname and same HTTP verb) throws
|
|
56
|
+
(same pathname and same HTTP verb) throws an error.
|
|
87
57
|
|
|
88
58
|
### Basic GET route
|
|
89
59
|
|
|
@@ -123,10 +93,8 @@ The order in which routes are declared is irrelevant. Redeclaring a route
|
|
|
123
93
|
|
|
124
94
|
## Domains
|
|
125
95
|
|
|
126
|
-
Domains represent a collection in a store
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
A collection is primarily described using the class `fields` property.
|
|
96
|
+
Domains represent a collection in a store, primarily with the class `fields`
|
|
97
|
+
property.
|
|
130
98
|
|
|
131
99
|
### Fields
|
|
132
100
|
|
|
@@ -155,14 +123,7 @@ aside from the type.
|
|
|
155
123
|
// domains/predicates.js
|
|
156
124
|
```
|
|
157
125
|
|
|
158
|
-
##
|
|
159
|
-
|
|
160
|
-
Stores interface data. Primate comes with volatile in-memory store used as a
|
|
161
|
-
default. Other stores can be imported as modules.
|
|
162
|
-
|
|
163
|
-
All stores are loaded from `stores`.
|
|
164
|
-
|
|
165
|
-
### Resources
|
|
126
|
+
## Resources
|
|
166
127
|
|
|
167
128
|
* Website: https://primatejs.com
|
|
168
129
|
* IRC: Join the `#primate` channel on `irc.libera.chat`.
|
|
@@ -170,12 +131,3 @@ All stores are loaded from `stores`.
|
|
|
170
131
|
## License
|
|
171
132
|
|
|
172
133
|
MIT
|
|
173
|
-
|
|
174
|
-
[getting-started]: https://primatejs.com/getting-started
|
|
175
|
-
[source-code]: https://github.com/primatejs/primate
|
|
176
|
-
[issues]: https://github.com/primatejs/primate/issues
|
|
177
|
-
[primate-file-store]: https://npmjs.com/primate-file-store
|
|
178
|
-
[primate-json-store]: https://npmjs.com/primate-json-store
|
|
179
|
-
[primate-mongodb-store]: https://npmjs.com/primate-mongodb-store
|
|
180
|
-
[primate-react]: https://github.com/primatejs/primate-react
|
|
181
|
-
[primate-vue]: https://github.com/primatejs/primate-vue
|
package/TODO
ADDED
package/module.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "primate",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"author": "Terrablue <terrablue@proton.me>",
|
|
5
5
|
"homepage": "https://primatejs.com",
|
|
6
6
|
"bugs": "https://github.com/primatejs/primate/issues",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"description": "Primal JavaScript framework",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"runtime-compat": "
|
|
11
|
+
"runtime-compat": "^0.12.3"
|
|
12
12
|
},
|
|
13
13
|
"bin": "bin/primate.js",
|
|
14
14
|
"devDependencies": {
|
package/src/bundle.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {File} from "runtime-compat/filesystem";
|
|
2
|
+
|
|
3
|
+
export default async conf => {
|
|
4
|
+
const {paths} = conf;
|
|
5
|
+
// remove public directory in case exists
|
|
6
|
+
if (await paths.public.exists) {
|
|
7
|
+
await paths.public.file.remove();
|
|
8
|
+
}
|
|
9
|
+
await paths.public.file.create();
|
|
10
|
+
|
|
11
|
+
if (await paths.static.exists) {
|
|
12
|
+
// copy static files to public
|
|
13
|
+
await File.copy(paths.static, paths.public);
|
|
14
|
+
}
|
|
15
|
+
};
|
package/src/preset/primate.json
CHANGED
package/src/route.js
CHANGED
|
@@ -55,7 +55,9 @@ export default async definitions => {
|
|
|
55
55
|
return typeof result === "function" ? result : guess(result);
|
|
56
56
|
},
|
|
57
57
|
};
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
if (await definitions.exists) {
|
|
59
|
+
const files = (await Path.list(definitions)).map(route => import(route));
|
|
60
|
+
await Promise.all(files.map(async route => (await route).default(router)));
|
|
61
|
+
}
|
|
60
62
|
return router;
|
|
61
63
|
};
|
package/src/run.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {Path, File} from "runtime-compat/filesystem";
|
|
2
|
-
import {default as Bundler, index} from "./Bundler.js";
|
|
3
1
|
import serve from "./serve.js";
|
|
4
2
|
import route from "./route.js";
|
|
3
|
+
import bundle from "./bundle.js";
|
|
5
4
|
import package_json from "../package.json" assert {type: "json"};
|
|
6
5
|
import log from "./log.js";
|
|
7
6
|
|
|
@@ -9,18 +8,11 @@ export default async conf => {
|
|
|
9
8
|
log.reset("Primate").yellow(package_json.version);
|
|
10
9
|
const {paths} = conf;
|
|
11
10
|
const router = await route(paths.routes);
|
|
12
|
-
await
|
|
11
|
+
await bundle(conf);
|
|
13
12
|
|
|
14
13
|
await serve({router,
|
|
15
14
|
paths: conf.paths,
|
|
16
|
-
index: await index(conf),
|
|
17
15
|
from: conf.paths.public,
|
|
18
|
-
http:
|
|
19
|
-
...conf.http,
|
|
20
|
-
key: await File.read(Path.resolve(conf.http.ssl.key)),
|
|
21
|
-
cert: await File.read(Path.resolve(conf.http.ssl.cert)),
|
|
22
|
-
keyFile: Path.resolve(conf.http.ssl.key),
|
|
23
|
-
certFile: Path.resolve(conf.http.ssl.cert),
|
|
24
|
-
},
|
|
16
|
+
http: conf.http,
|
|
25
17
|
});
|
|
26
18
|
};
|
package/src/serve.js
CHANGED
|
@@ -38,7 +38,7 @@ const Server = class Server {
|
|
|
38
38
|
return this.try(pathname + search, request, payload);
|
|
39
39
|
}, http);
|
|
40
40
|
const {port, host} = this.conf.http;
|
|
41
|
-
log.reset("on").yellow(
|
|
41
|
+
log.reset("on").yellow(`${host}:${port}`).nl();
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
async try(url, request, payload) {
|
package/html.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import html from "../src/handlers/html.js";
|
|
2
|
-
const components = {
|
|
3
|
-
"custom-tag": "<ct></ct>",
|
|
4
|
-
"custom-with-attribute": "<cwa value=\"${foo}\"></cwa>",
|
|
5
|
-
"custom-with-object-attribute": "<cwoa value=\"${foo.bar}\"></cwoa>",
|
|
6
|
-
"custom-with-slot": "<cws><slot/></cws>",
|
|
7
|
-
"for-with-object": "<fwo for=\"${foo}\"><span value=\"${bar}\"></span></fwo>",
|
|
8
|
-
"slot-before-custom": "<slot/><custom-tag></custom-tag>",
|
|
9
|
-
"custom-before-slot": "<custom-tag></custom-tag><slot/>",
|
|
10
|
-
};
|
|
11
|
-
const index = "<body>";
|
|
12
|
-
const conf = {components, index};
|
|
13
|
-
export default () => (strings, ...keys) => html(strings, ...keys)(conf);
|
package/src/Bundler.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import {Path, File} from "runtime-compat/filesystem";
|
|
2
|
-
|
|
3
|
-
const meta_url = new Path(import.meta.url).path;
|
|
4
|
-
const directory = Path.directory(meta_url);
|
|
5
|
-
const preset = `${directory}/preset`;
|
|
6
|
-
|
|
7
|
-
export default class Bundler {
|
|
8
|
-
constructor(conf) {
|
|
9
|
-
this.conf = conf;
|
|
10
|
-
this.debug = conf.debug;
|
|
11
|
-
this.index = conf.files.index;
|
|
12
|
-
this.scripts = [];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async bundle() {
|
|
16
|
-
const {paths} = this.conf;
|
|
17
|
-
|
|
18
|
-
// remove public directory in case exists
|
|
19
|
-
await File.remove(paths.public);
|
|
20
|
-
// create public directory
|
|
21
|
-
await File.create(paths.public);
|
|
22
|
-
|
|
23
|
-
// copy static files to public
|
|
24
|
-
await File.copy(paths.static, paths.public);
|
|
25
|
-
|
|
26
|
-
// read index.html from public, then remove it (we serve it dynamically)
|
|
27
|
-
await File.remove(`${paths.public}/${this.index}`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const index = async conf => {
|
|
32
|
-
let file;
|
|
33
|
-
const subdirectory = "static";
|
|
34
|
-
try {
|
|
35
|
-
file = await File.read(`${conf.paths[subdirectory]}/${conf.files.index}`);
|
|
36
|
-
} catch (error) {
|
|
37
|
-
file = await File.read(`${preset}/${subdirectory}/${conf.files.index}`);
|
|
38
|
-
}
|
|
39
|
-
return file;
|
|
40
|
-
};
|