primate 0.9.1 → 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 CHANGED
@@ -1,54 +1,19 @@
1
1
  # Primate
2
2
 
3
- Primal JavaScript framework.
3
+ An expressive, minimal and extensible framework for JavaScript.
4
4
 
5
5
  ## Getting started
6
6
 
7
- Lay out app
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("/", () => html`<site-index date="${new Date()}" />`);
11
+ router.get("/", () => "Hello, world!");
21
12
  };
22
13
 
23
14
  ```
24
15
 
25
- Create a component in `components/site-index.html`
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. Routes are loaded from `routes`.
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 a `RouteError`.
98
+ (same pathname and same HTTP verb) throws an error.
134
99
 
135
100
  ### Basic GET route
136
101
 
@@ -292,14 +257,7 @@ export default class User extends Domain {
292
257
 
293
258
  ```
294
259
 
295
- ## Stores
296
-
297
- Stores interface data. Primate comes with volatile in-memory store used as a
298
- default. Other stores can be imported as modules.
299
-
300
- Stores are loaded from `stores`.
301
-
302
- ### Resources
260
+ ## Resources
303
261
 
304
262
  * Website: https://primatejs.com
305
263
  * IRC: Join the `#primate` channel on `irc.libera.chat`.
@@ -1,46 +1,16 @@
1
1
  # Primate
2
2
 
3
- Primal JavaScript framework.
3
+ An expressive, minimal and extensible framework for JavaScript.
4
4
 
5
5
  ## Getting started
6
6
 
7
- Lay out app
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/site.js
10
+ // getting-started/hello.js
17
11
  ```
18
12
 
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
29
- ```
30
-
31
- Run
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. Routes are loaded from `routes`.
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 a `RouteError`.
56
+ (same pathname and same HTTP verb) throws an error.
87
57
 
88
58
  ### Basic GET route
89
59
 
@@ -153,14 +123,7 @@ aside from the type.
153
123
  // domains/predicates.js
154
124
  ```
155
125
 
156
- ## Stores
157
-
158
- Stores interface data. Primate comes with volatile in-memory store used as a
159
- default. Other stores can be imported as modules.
160
-
161
- Stores are loaded from `stores`.
162
-
163
- ### Resources
126
+ ## Resources
164
127
 
165
128
  * Website: https://primatejs.com
166
129
  * IRC: Join the `#primate` channel on `irc.libera.chat`.
package/TODO ADDED
@@ -0,0 +1,4 @@
1
+ remove ssl hint from documentation -> maybe add a "running an https server"
2
+ add RouteError
3
+ add the possibility to pass strings to attributes (rework internally data to
4
+ hang at attributes)
package/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "primate",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "author": "Terrablue <terrablue@proton.me>",
5
5
  "bugs": "https://github.com/primatejs/primate/issues",
6
6
  "repository": "https://github.com/primatejs/primate",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "primate",
3
- "version": "0.9.1",
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": "^0.12.2"
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
+ };
@@ -7,10 +7,6 @@
7
7
  "http": {
8
8
  "host": "localhost",
9
9
  "port": 9999,
10
- "ssl": {
11
- "key": "ssl/default.key",
12
- "cert": "ssl/default.crt"
13
- },
14
10
  "csp": {
15
11
  "default-src": "'self'",
16
12
  "object-src": "'none'",
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
- const files = (await Path.list(definitions)).map(route => import(route));
59
- await Promise.all(files.map(async route => (await route).default(router)));
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 new Bundler(conf).bundle();
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(`https://${host}:${port}`).nl();
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
- };