primate 0.13.2 → 0.14.1
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/package.json +2 -2
- package/src/bin.js +7 -1
- package/src/commands/create.js +41 -0
- package/src/commands/exports.js +3 -0
- package/src/commands/help.js +3 -0
- package/src/commands/start.js +19 -0
- package/src/config.js +3 -3
- package/src/exports.js +4 -0
- package/src/route.js +1 -1
- package/src/run.js +3 -18
- package/src/serve.js +2 -1
- package/exports.js +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "primate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "Expressive, minimal and extensible framework for JavaScript",
|
|
5
5
|
"homepage": "https://primatejs.com",
|
|
6
6
|
"bugs": "https://github.com/primatejs/primate/issues",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"node": ">=17.9.0"
|
|
23
23
|
},
|
|
24
24
|
"type": "module",
|
|
25
|
-
"exports": "./exports.js"
|
|
25
|
+
"exports": "./src/exports.js"
|
|
26
26
|
}
|
package/src/bin.js
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
import args from "runtime-compat/args";
|
|
3
|
+
import * as commands from "./commands/exports.js";
|
|
4
|
+
import run from "./run.js";
|
|
5
|
+
|
|
6
|
+
const command = name => commands[name] ?? commands.help;
|
|
7
|
+
|
|
8
|
+
await run(args[0] === undefined ? commands.start : command(args[0]));
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {Path} from "runtime-compat/fs";
|
|
2
|
+
import package_json from "../../package.json" assert {type: "json"};
|
|
3
|
+
|
|
4
|
+
const createModule = async () => {
|
|
5
|
+
const space = 2;
|
|
6
|
+
try {
|
|
7
|
+
// will throw if cannot find a package.json up the filesystem hierarchy
|
|
8
|
+
await Path.root();
|
|
9
|
+
} catch (error) {
|
|
10
|
+
const rootConfig = JSON.stringify({
|
|
11
|
+
name: "primate-app",
|
|
12
|
+
private: true,
|
|
13
|
+
dependencies: {
|
|
14
|
+
primate: `^${package_json.version}`,
|
|
15
|
+
},
|
|
16
|
+
scripts: {
|
|
17
|
+
run: "npx primate",
|
|
18
|
+
},
|
|
19
|
+
type: "module",
|
|
20
|
+
}, null, space);
|
|
21
|
+
await Path.resolve().join("package.json").file.write(rootConfig);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const createConfig = async env => {
|
|
26
|
+
const name = "primate.config.js";
|
|
27
|
+
const template = "export default {};";
|
|
28
|
+
const root = (await Path.root()).join(name);
|
|
29
|
+
if (await root.exists) {
|
|
30
|
+
env.log.warn(`${root} already exists`);
|
|
31
|
+
} else {
|
|
32
|
+
await root.file.write(template);
|
|
33
|
+
env.log.info(`created config at ${root}`);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default async env => {
|
|
38
|
+
await createModule();
|
|
39
|
+
await createConfig(env);
|
|
40
|
+
};
|
|
41
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import register from "../register.js";
|
|
2
|
+
import compile from "../compile.js";
|
|
3
|
+
import publish from "../publish.js";
|
|
4
|
+
import bundle from "../bundle.js";
|
|
5
|
+
import route from "../route.js";
|
|
6
|
+
import serve from "../serve.js";
|
|
7
|
+
|
|
8
|
+
export default async env => {
|
|
9
|
+
// register handlers
|
|
10
|
+
await register(env);
|
|
11
|
+
// compile server-side code
|
|
12
|
+
await compile(env);
|
|
13
|
+
// publish client-side code
|
|
14
|
+
await publish(env);
|
|
15
|
+
// bundle client-side code
|
|
16
|
+
await bundle(env);
|
|
17
|
+
// serve
|
|
18
|
+
serve({router: await route(env.paths.routes, env.handlers), ...env});
|
|
19
|
+
};
|
package/src/config.js
CHANGED
|
@@ -87,12 +87,12 @@ export default async (filename = "primate.config.js") => {
|
|
|
87
87
|
},
|
|
88
88
|
};
|
|
89
89
|
env.log.info(`${package_json.name} \x1b[34m${package_json.version}\x1b[0m`);
|
|
90
|
-
const modules =
|
|
90
|
+
const {modules} = config;
|
|
91
91
|
// modules may load other modules
|
|
92
92
|
const loads = await Promise.all(modules
|
|
93
93
|
.filter(module => module.load !== undefined)
|
|
94
|
-
.map(module => module.load()
|
|
94
|
+
.map(module => module.load()));
|
|
95
95
|
|
|
96
96
|
return cache("config", filename, () => ({...env, resources,
|
|
97
|
-
modules: modules.concat(loads)}));
|
|
97
|
+
modules: modules.concat(loads.flat())}));
|
|
98
98
|
};
|
package/src/exports.js
ADDED
package/src/route.js
CHANGED
|
@@ -35,7 +35,7 @@ export default async (definitions, handlers) => {
|
|
|
35
35
|
[verb, (path, callback) => add(verb, path, callback)])),
|
|
36
36
|
map: (path, callback) => add("map", path, callback),
|
|
37
37
|
alias: (key, value) => aliases.push({key, value}),
|
|
38
|
-
route: async request => {
|
|
38
|
+
route: async ({request}) => {
|
|
39
39
|
const {method} = request.original;
|
|
40
40
|
const url = new URL(`https://primatejs.com${request.pathname}`);
|
|
41
41
|
const {pathname, searchParams} = url;
|
package/src/run.js
CHANGED
|
@@ -1,21 +1,6 @@
|
|
|
1
1
|
import config from "./config.js";
|
|
2
|
-
import register from "./register.js";
|
|
3
|
-
import compile from "./compile.js";
|
|
4
|
-
import publish from "./publish.js";
|
|
5
|
-
import bundle from "./bundle.js";
|
|
6
|
-
import route from "./route.js";
|
|
7
|
-
import serve from "./serve.js";
|
|
8
2
|
|
|
9
|
-
export default async
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
await register(env);
|
|
13
|
-
// compile server-side code
|
|
14
|
-
await compile(env);
|
|
15
|
-
// publish client-side code
|
|
16
|
-
await publish(env);
|
|
17
|
-
// bundle client-side code
|
|
18
|
-
await bundle(env);
|
|
19
|
-
// serve
|
|
20
|
-
serve({router: await route(env.paths.routes, env.handlers), ...env});
|
|
3
|
+
export default async command => {
|
|
4
|
+
// env should initialised before any commands run
|
|
5
|
+
await command(await config());
|
|
21
6
|
};
|
package/src/serve.js
CHANGED
|
@@ -44,7 +44,7 @@ export default env => {
|
|
|
44
44
|
// handle is the last module to be executed
|
|
45
45
|
const handlers = [...modules, router.route].reduceRight((acc, handler) =>
|
|
46
46
|
input => handler(input, acc));
|
|
47
|
-
return await respond(await handlers(request))(env, headers);
|
|
47
|
+
return await respond(await handlers({request, env}))(env, headers);
|
|
48
48
|
} catch (error) {
|
|
49
49
|
env.log.error(error);
|
|
50
50
|
return http404()(env, headers);
|
|
@@ -72,6 +72,7 @@ export default env => {
|
|
|
72
72
|
status: statuses.OK,
|
|
73
73
|
headers: {
|
|
74
74
|
"Content-Type": mime(published.src),
|
|
75
|
+
Etag: published.integrity,
|
|
75
76
|
},
|
|
76
77
|
});
|
|
77
78
|
}
|
package/exports.js
DELETED