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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "primate",
3
- "version": "0.15.2",
3
+ "version": "0.15.4",
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",
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
- const command = name => commands[name] ?? commands.help;
7
-
8
- await run(args[0] === undefined ? commands.start : command(args[0]));
5
+ await run(args[0]);
@@ -15,6 +15,8 @@ const createModule = async () => {
15
15
  },
16
16
  scripts: {
17
17
  start: "npx primate",
18
+ dev: "npx primate dev",
19
+ serve: "npx primate serve",
18
20
  },
19
21
  type: "module",
20
22
  }, null, space);
@@ -0,0 +1,3 @@
1
+ import start from "../start.js";
2
+
3
+ export default async env => start(env);
@@ -1,3 +1,10 @@
1
- export {default as start} from "./start.js";
2
- export {default as create} from "./create.js";
3
- export {default as help} from "./help.js";
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);
@@ -0,0 +1,3 @@
1
+ import start from "../start.js";
2
+
3
+ export default async env => start(env, {bundle: true});
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 = `<${tag} type="${type}" integrity="${integrity}"`;
76
- const post = `</${tag}>`;
77
- return inline ? `${pre}>${code}${post}` : `${pre} src="${src}">${post}`;
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, resources,
105
+ return cache("config", filename, () => ({...env,
97
106
  modules: modules.concat(loads.flat())}));
98
107
  };
package/src/exports.js CHANGED
@@ -1,5 +1,4 @@
1
- import {start} from "./commands/exports.js";
2
1
  import run from "./run.js";
3
2
 
4
3
  export * from "./handlers/exports.js";
5
- export default () => run(start);
4
+ export default command => run(command);
@@ -19,4 +19,5 @@ export default {
19
19
  components: "components",
20
20
  },
21
21
  modules: [],
22
+ dist: "app",
22
23
  };
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 command => {
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
+ };
@@ -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
- };