primate 0.24.0 → 0.26.0
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/Logger.js +20 -16
- package/src/app.js +75 -69
- package/src/bin.js +1 -1
- package/src/commands/dev.js +1 -1
- package/src/commands/exports.js +3 -3
- package/src/commands/serve.js +1 -1
- package/src/cwd.js +1 -1
- package/src/defaults/primate.config.js +1 -1
- package/src/dispatch.js +13 -10
- package/src/errors.js +1 -1
- package/src/errors.json +5 -0
- package/src/exports.js +2 -2
- package/src/handlers/error.js +4 -4
- package/src/handlers/exports.js +7 -7
- package/src/handlers/html.js +7 -7
- package/src/handlers/json.js +3 -3
- package/src/handlers/redirect.js +3 -3
- package/src/handlers/stream.js +4 -4
- package/src/handlers/text.js +3 -3
- package/src/hooks/bundle.js +1 -1
- package/src/hooks/copy_includes.js +8 -8
- package/src/hooks/exports.js +9 -9
- package/src/hooks/handle.js +44 -37
- package/src/hooks/init.js +1 -1
- package/src/hooks/parse.js +8 -8
- package/src/hooks/publish.js +8 -42
- package/src/hooks/register.js +73 -2
- package/src/hooks/respond/duck.js +1 -1
- package/src/hooks/respond/exports.js +2 -2
- package/src/hooks/respond/respond.js +4 -4
- package/src/hooks/route.js +11 -11
- package/src/hooks/serve.js +3 -3
- package/src/hooks/stage.js +48 -0
- package/src/loaders/common.js +3 -3
- package/src/loaders/exports.js +3 -3
- package/src/loaders/modules.js +10 -7
- package/src/loaders/routes/exports.js +6 -4
- package/src/loaders/routes/load.js +2 -2
- package/src/loaders/routes/routes.js +2 -2
- package/src/loaders/routes.js +16 -15
- package/src/loaders/types.js +11 -4
- package/src/run.js +8 -8
- package/src/start.js +19 -10
- package/src/validate.js +1 -1
- package/src/hooks/compile.js +0 -45
- package/src/loaders/routes/errors.js +0 -3
- package/src/loaders/routes/guards.js +0 -3
- package/src/loaders/routes/layouts.js +0 -3
package/src/loaders/types.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
import {Path} from "
|
|
1
|
+
import { Path } from "rcompat/fs";
|
|
2
|
+
import { is } from "rcompat/invariant";
|
|
3
|
+
import { tryreturn } from "rcompat/sync";
|
|
2
4
|
import errors from "../errors.js";
|
|
3
5
|
import fs from "./common.js";
|
|
4
6
|
|
|
5
7
|
const filter = path => /^[a-z]/u.test(path.name);
|
|
6
8
|
|
|
7
9
|
export default async (log, directory, load = fs) => {
|
|
8
|
-
const types = await
|
|
10
|
+
const types = await fs({ log, directory, name: "types", filter });
|
|
9
11
|
|
|
10
12
|
const resolve = name => new Path(directory, name);
|
|
11
|
-
types.
|
|
12
|
-
|
|
13
|
+
types.every(([name, type]) => tryreturn(_ => {
|
|
14
|
+
is(type).object();
|
|
15
|
+
is(type.base).string();
|
|
16
|
+
is(type.validate).function();
|
|
17
|
+
return true;
|
|
18
|
+
}).orelse(_ => errors.InvalidTypeExport.throw(resolve(`${name}.js`))),
|
|
19
|
+
);
|
|
13
20
|
|
|
14
21
|
types.every(([name]) =>
|
|
15
22
|
/^(?:[a-z][^\W_]*)$/u.test(name) || errors.InvalidTypeName.throw(name));
|
package/src/run.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {tryreturn} from "
|
|
2
|
-
import {Path} from "
|
|
3
|
-
import {extend} from "
|
|
1
|
+
import { tryreturn } from "rcompat/async";
|
|
2
|
+
import { Path } from "rcompat/fs";
|
|
3
|
+
import { extend } from "rcompat/object";
|
|
4
4
|
import app from "./app.js";
|
|
5
|
-
import {default as Logger, bye} from "./Logger.js";
|
|
5
|
+
import { default as Logger, bye } from "./Logger.js";
|
|
6
6
|
import errors from "./errors.js";
|
|
7
7
|
import command from "./commands/exports.js";
|
|
8
8
|
import defaults from "./defaults/primate.config.js";
|
|
9
9
|
|
|
10
|
-
let logger = new Logger({level: Logger.Warn});
|
|
11
|
-
const {runtime = "node"} = import.meta;
|
|
10
|
+
let logger = new Logger({ level: Logger.Warn });
|
|
11
|
+
const { runtime = "node" } = import.meta;
|
|
12
12
|
|
|
13
13
|
const get_config = async root => {
|
|
14
14
|
const name = "primate.config.js";
|
|
15
15
|
const config = root.join(name);
|
|
16
|
-
return await config.exists
|
|
16
|
+
return await config.exists()
|
|
17
17
|
? tryreturn(async _ => {
|
|
18
18
|
const imported = (await import(config)).default;
|
|
19
19
|
|
|
@@ -21,7 +21,7 @@ const get_config = async root => {
|
|
|
21
21
|
errors.EmptyConfigFile.warn(logger, config);
|
|
22
22
|
|
|
23
23
|
return extend(defaults, imported);
|
|
24
|
-
}).orelse(({message}) =>
|
|
24
|
+
}).orelse(({ message }) =>
|
|
25
25
|
errors.ErrorInConfigFile.throw(message, `${runtime} ${config}`))
|
|
26
26
|
: defaults;
|
|
27
27
|
};
|
package/src/start.js
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
|
-
import {serve, Response, Status} from "
|
|
2
|
-
import {cascade, tryreturn} from "
|
|
1
|
+
import { serve, Response, Status } from "rcompat/http";
|
|
2
|
+
import { cascade, tryreturn } from "rcompat/async";
|
|
3
|
+
import { bold, blue } from "rcompat/colors";
|
|
3
4
|
import * as hooks from "./hooks/exports.js";
|
|
5
|
+
import { print } from "./Logger.js";
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
const base_hooks = ["init", "stage", "register", "publish", "bundle"];
|
|
8
|
+
|
|
9
|
+
export default async (app$, mode = "development") => {
|
|
10
|
+
app$.mode = mode;
|
|
6
11
|
// run one-time hooks
|
|
7
12
|
let app = app$;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
|
|
14
|
+
const { http } = app.config;
|
|
15
|
+
const address = `http${app.secure ? "s" : ""}://${http.host}:${http.port}`;
|
|
16
|
+
print(blue(bold(app.name)), blue(app.version), `at ${address}\n`);
|
|
17
|
+
|
|
18
|
+
app.log.info(`in ${bold(mode)} mode`, { module: "primate" });
|
|
19
|
+
|
|
20
|
+
for (const hook of base_hooks) {
|
|
21
|
+
app.log.info(`running ${bold(hook)} hooks`, { module: "primate" });
|
|
13
22
|
app = await hooks[hook](app);
|
|
14
23
|
}
|
|
15
24
|
|
|
@@ -20,9 +29,9 @@ export default async (app$, deactivated = []) => {
|
|
|
20
29
|
tryreturn(async _ => (await hooks.handle(app))(await app.parse(request)))
|
|
21
30
|
.orelse(error => {
|
|
22
31
|
app.log.auto(error);
|
|
23
|
-
return new Response(null, {status: Status.INTERNAL_SERVER_ERROR});
|
|
32
|
+
return new Response(null, { status: Status.INTERNAL_SERVER_ERROR });
|
|
24
33
|
}),
|
|
25
34
|
app.config.http);
|
|
26
35
|
|
|
27
|
-
await (await cascade(app.modules.serve))({...app, server});
|
|
36
|
+
await (await cascade(app.modules.serve))({ ...app, server });
|
|
28
37
|
};
|
package/src/validate.js
CHANGED
package/src/hooks/compile.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import {Path} from "runtime-compat/fs";
|
|
2
|
-
import {cascade} from "runtime-compat/async";
|
|
3
|
-
import copy_includes from "./copy_includes.js";
|
|
4
|
-
import cwd from "../cwd.js";
|
|
5
|
-
|
|
6
|
-
const html = /^.*.html$/u;
|
|
7
|
-
const defaults = cwd(import.meta, 2).join("defaults");
|
|
8
|
-
|
|
9
|
-
const pre = async app => {
|
|
10
|
-
const {config: {location}, path} = app;
|
|
11
|
-
|
|
12
|
-
// remove build directory in case exists
|
|
13
|
-
if (await path.build.exists) {
|
|
14
|
-
await path.build.file.remove();
|
|
15
|
-
}
|
|
16
|
-
await Promise.all(["server", "client", "components", "pages"]
|
|
17
|
-
.map(directory => app.runpath(directory).file.create()));
|
|
18
|
-
|
|
19
|
-
// copy framework pages
|
|
20
|
-
await app.stage(defaults, location.pages, html);
|
|
21
|
-
// overwrite transformed pages to build
|
|
22
|
-
await path.pages.exists && await app.stage(path.pages, location.pages, html);
|
|
23
|
-
|
|
24
|
-
if (await path.components.exists) {
|
|
25
|
-
// copy all files to build/components
|
|
26
|
-
await app.stage(path.components, location.components);
|
|
27
|
-
// copy .js files from components to build/server, since frontend
|
|
28
|
-
// frameworks handle non-js files
|
|
29
|
-
const to = Path.join(location.server, location.components);
|
|
30
|
-
await app.stage(path.components, to, /^.*.js$/u);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (await path.static.exists) {
|
|
34
|
-
// copy static files to build/server/static
|
|
35
|
-
await app.stage(path.static, new Path(location.server, location.static));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// copy additional subdirectories to build/server
|
|
39
|
-
await copy_includes(app, location.server);
|
|
40
|
-
|
|
41
|
-
return app;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export default async app =>
|
|
45
|
-
(await cascade(app.modules.compile))(await pre(app));
|