@primate/angular 0.1.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/LICENSE +19 -0
- package/package.json +53 -0
- package/src/private/build/index.js +15 -0
- package/src/private/build/server.js +20 -0
- package/src/private/extension.js +1 -0
- package/src/private/pkgname.js +1 -0
- package/src/private/serve/index.js +10 -0
- package/src/private/serve/make-root.js +17 -0
- package/src/private/serve/render.js +33 -0
- package/src/private/serve/root-component.js +9 -0
- package/src/private/serve/selector.js +1 -0
- package/src/private/serve/set-mode.js +7 -0
- package/src/public/default.js +10 -0
- package/src/public/runtime.js +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) Terrablue <terrablue@proton.me> and contributors.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
16
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@primate/angular",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Primate Angular frontend",
|
|
5
|
+
"homepage": "https://primatejs.com/modules/angular",
|
|
6
|
+
"bugs": "https://github.com/primatejs/primate/issues",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"files": [
|
|
9
|
+
"src/**/*.js",
|
|
10
|
+
"!src/**/*.spec.js"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/primatejs/primate",
|
|
15
|
+
"directory": "packages/angular"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@angular/compiler": "18",
|
|
19
|
+
"@angular/core": "18",
|
|
20
|
+
"@angular/platform-browser": "18",
|
|
21
|
+
"@angular/platform-server": "18",
|
|
22
|
+
"@angular/ssr": "18",
|
|
23
|
+
"@rcompat/build": "^0.4.0",
|
|
24
|
+
"@rcompat/object": "^0.5.0",
|
|
25
|
+
"zone.js": "0.14",
|
|
26
|
+
"@primate/frontend": "^0.16.0"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"vue": "3",
|
|
30
|
+
"primate": "^0.32.0"
|
|
31
|
+
},
|
|
32
|
+
"type": "module",
|
|
33
|
+
"imports": {
|
|
34
|
+
"#*": {
|
|
35
|
+
"@primate/lt": "./src/private/*.js",
|
|
36
|
+
"default": "./src/private/*.js"
|
|
37
|
+
},
|
|
38
|
+
"#build": {
|
|
39
|
+
"@primate/lt": "./src/private/build/index.js",
|
|
40
|
+
"default": "./src/private/build/index.js"
|
|
41
|
+
},
|
|
42
|
+
"#serve": {
|
|
43
|
+
"@primate/lt": "./src/private/serve/index.js",
|
|
44
|
+
"default": "./src/private/serve/index.js"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"exports": {
|
|
48
|
+
".": {
|
|
49
|
+
"runtime": "./src/public/runtime.js",
|
|
50
|
+
"default": "./src/public/default.js"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import server from "./server.js";
|
|
2
|
+
|
|
3
|
+
export default extension => async (app, next) => {
|
|
4
|
+
const extensions = {
|
|
5
|
+
from: extension,
|
|
6
|
+
to: ".js",
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
app.register(extension, {
|
|
10
|
+
server: component => server(app, component, extensions),
|
|
11
|
+
client: _ => _,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
return next(app);
|
|
15
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import transform from "@rcompat/build/transform";
|
|
2
|
+
|
|
3
|
+
const options = {
|
|
4
|
+
loader: "ts",
|
|
5
|
+
tsconfig: {
|
|
6
|
+
compilerOptions: {
|
|
7
|
+
experimentalDecorators: true,
|
|
8
|
+
},
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default async (app, component, extensions) => {
|
|
13
|
+
const location = app.get("location");
|
|
14
|
+
const source = app.runpath(location.components);
|
|
15
|
+
const { code } = await transform(await component.text(), options);
|
|
16
|
+
const target_base = app.runpath(location.server, location.components);
|
|
17
|
+
const path = target_base.join(`${component.path}.js`.replace(source, ""));
|
|
18
|
+
await path.directory.create();
|
|
19
|
+
await path.write(code.replaceAll(extensions.from, extensions.to));
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default ".component.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default "@primate/angular";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { reflectComponentType } from "@angular/core";
|
|
2
|
+
import stringify from "@rcompat/object/stringify";
|
|
3
|
+
import root_component from "./root-component.js";
|
|
4
|
+
|
|
5
|
+
const double_to_single = string => string.replaceAll("\"", "'");
|
|
6
|
+
|
|
7
|
+
export default (real_root, props) => {
|
|
8
|
+
const { selector } = reflectComponentType(real_root);
|
|
9
|
+
const attributes = Object.entries(props)
|
|
10
|
+
.map(([key, value]) => `[${key}]="${double_to_single(stringify(value))}"`)
|
|
11
|
+
.join(" ");
|
|
12
|
+
|
|
13
|
+
return root_component({
|
|
14
|
+
imports: [real_root],
|
|
15
|
+
template: `<${selector} ${attributes}></${selector}>`,
|
|
16
|
+
});
|
|
17
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import "@angular/compiler";
|
|
2
|
+
import {
|
|
3
|
+
bootstrapApplication,
|
|
4
|
+
provideClientHydration,
|
|
5
|
+
} from "@angular/platform-browser";
|
|
6
|
+
import {
|
|
7
|
+
provideServerRendering,
|
|
8
|
+
renderApplication,
|
|
9
|
+
ɵSERVER_CONTEXT,
|
|
10
|
+
} from "@angular/platform-server";
|
|
11
|
+
import "zone.js";
|
|
12
|
+
import make_root from "./make-root.js";
|
|
13
|
+
import selector from "./selector.js";
|
|
14
|
+
|
|
15
|
+
// const common_engine = new CommonEngine();
|
|
16
|
+
|
|
17
|
+
export default async (given_component, props) => {
|
|
18
|
+
const component = make_root(given_component, props);
|
|
19
|
+
const document = `<${selector}></${selector}>`;
|
|
20
|
+
const bootstrap = () => bootstrapApplication(component, {
|
|
21
|
+
providers: [
|
|
22
|
+
provideServerRendering(),
|
|
23
|
+
{ provide: ɵSERVER_CONTEXT, useValue: "analog" },
|
|
24
|
+
...component.renderProviders || [],
|
|
25
|
+
provideClientHydration(),
|
|
26
|
+
],
|
|
27
|
+
});
|
|
28
|
+
const html = await renderApplication(bootstrap, { document });
|
|
29
|
+
const b_s = "<body>";
|
|
30
|
+
const b_e = "</body>";
|
|
31
|
+
// await common_engine.render({ bootstrap, document });
|
|
32
|
+
return html.slice(html.indexOf(b_s) + b_s.length, html.indexOf(b_e));
|
|
33
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default "app-root";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import build from "#build";
|
|
2
|
+
import default_extension from "#extension";
|
|
3
|
+
import pkgname from "#pkgname";
|
|
4
|
+
import serve from "#serve";
|
|
5
|
+
|
|
6
|
+
export default ({ extension = default_extension } = {}) => ({
|
|
7
|
+
name: pkgname,
|
|
8
|
+
build: build(extension),
|
|
9
|
+
serve: serve(extension),
|
|
10
|
+
});
|