primate 0.15.2 → 0.15.4
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 +1 -1
- package/src/bin.js +1 -4
- package/src/commands/create.js +2 -0
- package/src/commands/dev.js +3 -0
- package/src/commands/exports.js +10 -3
- package/src/commands/serve.js +3 -0
- package/src/config.js +18 -9
- package/src/exports.js +1 -2
- package/src/primate.config.js +1 -0
- package/src/run.js +2 -4
- package/src/start.js +27 -0
- package/src/commands/start.js +0 -19
package/package.json
CHANGED
package/src/bin.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import args from "runtime-compat/args";
|
|
3
|
-
import * as commands from "./commands/exports.js";
|
|
4
3
|
import run from "./run.js";
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
await run(args[0] === undefined ? commands.start : command(args[0]));
|
|
5
|
+
await run(args[0]);
|
package/src/commands/create.js
CHANGED
package/src/commands/exports.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {default as dev} from "./dev.js";
|
|
2
|
+
import {default as serve} from "./serve.js";
|
|
3
|
+
import {default as create} from "./create.js";
|
|
4
|
+
import {default as help} from "./help.js";
|
|
5
|
+
|
|
6
|
+
const commands = {dev, serve, create, help};
|
|
7
|
+
|
|
8
|
+
const run = name => commands[name] ?? help;
|
|
9
|
+
|
|
10
|
+
export default name => name === undefined ? dev : run(name);
|
package/src/config.js
CHANGED
|
@@ -58,9 +58,10 @@ export default async (filename = "primate.config.js") => {
|
|
|
58
58
|
const root = await getRoot();
|
|
59
59
|
const config = await getConfig(root, filename);
|
|
60
60
|
|
|
61
|
-
const resources = [];
|
|
62
61
|
const env = {
|
|
63
62
|
...config,
|
|
63
|
+
resources: [],
|
|
64
|
+
entrypoints: [],
|
|
64
65
|
paths: qualify(root, config.paths),
|
|
65
66
|
root,
|
|
66
67
|
log: {...log, error: error => log.error(error, config)},
|
|
@@ -70,21 +71,29 @@ export default async (filename = "primate.config.js") => {
|
|
|
70
71
|
handlers: {...handlers},
|
|
71
72
|
render: async ({body = "", head = ""} = {}) => {
|
|
72
73
|
const html = await index(env);
|
|
73
|
-
const heads = resources.map(({src, code, type, inline, integrity}) => {
|
|
74
|
-
const tag = "script";
|
|
75
|
-
const pre =
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
const heads = env.resources.map(({src, code, type, inline, integrity}) => {
|
|
75
|
+
const tag = type === "style" ? "link" : "script";
|
|
76
|
+
const pre = type === "style"
|
|
77
|
+
? `<${tag} rel="stylesheet" integrity="${integrity}"`
|
|
78
|
+
: `<${tag} type="${type}" integrity="${integrity}"`;
|
|
79
|
+
const middle = type === "style"
|
|
80
|
+
? ` href="${src}">`
|
|
81
|
+
: ` src="${src}">`;
|
|
82
|
+
const post = type === "style" ? "" : `</${tag}>`;
|
|
83
|
+
return inline ? `${pre}>${code}${post}` : `${pre}${middle}${post}`;
|
|
78
84
|
}).join("\n");
|
|
79
85
|
return html
|
|
80
86
|
.replace("%body%", () => body)
|
|
81
87
|
.replace("%head%", () => `${head}${heads}`);
|
|
82
88
|
},
|
|
83
|
-
publish: async ({src, code, type = "", inline = false}) => {
|
|
89
|
+
publish: async ({src, code, type = "", inline = false, main}) => {
|
|
84
90
|
const integrity = await hash(code);
|
|
85
|
-
resources.push({src, code, type, inline, integrity});
|
|
91
|
+
env.resources.push({src, code, type, inline, integrity, main});
|
|
86
92
|
return integrity;
|
|
87
93
|
},
|
|
94
|
+
bootstrap: ({type, code}) => {
|
|
95
|
+
env.entrypoints.push({type, code});
|
|
96
|
+
},
|
|
88
97
|
};
|
|
89
98
|
env.log.info(`${package_json.name} \x1b[34m${package_json.version}\x1b[0m`);
|
|
90
99
|
const {modules} = config;
|
|
@@ -93,6 +102,6 @@ export default async (filename = "primate.config.js") => {
|
|
|
93
102
|
.filter(module => module.load !== undefined)
|
|
94
103
|
.map(module => module.load()));
|
|
95
104
|
|
|
96
|
-
return cache("config", filename, () => ({...env,
|
|
105
|
+
return cache("config", filename, () => ({...env,
|
|
97
106
|
modules: modules.concat(loads.flat())}));
|
|
98
107
|
};
|
package/src/exports.js
CHANGED
package/src/primate.config.js
CHANGED
package/src/run.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import config from "./config.js";
|
|
2
|
+
import command from "./commands/exports.js";
|
|
2
3
|
|
|
3
|
-
export default async
|
|
4
|
-
// env should initialised before any commands run
|
|
5
|
-
await command(await config());
|
|
6
|
-
};
|
|
4
|
+
export default async name => command(name)(await config());
|
package/src/start.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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, operations = {}) => {
|
|
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
|
+
|
|
16
|
+
// after publish hook, publish a zero assumptions app.js (no css imports)
|
|
17
|
+
const code = env.entrypoints.filter(({type}) => type === "script")
|
|
18
|
+
.map(({code}) => code).join("");
|
|
19
|
+
await env.publish({src: `${env.dist}.js`, code, type: "module"});
|
|
20
|
+
|
|
21
|
+
if (operations?.bundle) {
|
|
22
|
+
// bundle client-side code
|
|
23
|
+
await bundle(env);
|
|
24
|
+
}
|
|
25
|
+
// serve
|
|
26
|
+
serve({router: await route(env), ...env});
|
|
27
|
+
};
|
package/src/commands/start.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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), ...env});
|
|
19
|
-
};
|