@olenbetong/appframe-vite 1.1.0 → 1.2.2

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Ølen Betong
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/lib/build.js CHANGED
@@ -2,17 +2,16 @@ import { visualizer } from "rollup-plugin-visualizer";
2
2
  import { viteExternalsPlugin } from "vite-plugin-externals";
3
3
  import { importJson } from "./importJson.js";
4
4
  export async function addAppframeBuildConfig(config) {
5
- var _a, _b;
6
5
  let appPkg = await importJson("./package.json", true);
7
6
  let { appframe } = appPkg;
8
- config.build = (_a = config.build) !== null && _a !== void 0 ? _a : {};
7
+ config.build = config.build ?? {};
9
8
  config.build = {
10
9
  ...config.build,
11
10
  manifest: true,
12
11
  sourcemap: true,
13
12
  cssCodeSplit: false,
14
13
  };
15
- config.plugins = (_b = config.plugins) !== null && _b !== void 0 ? _b : [];
14
+ config.plugins = config.plugins ?? [];
16
15
  if (appframe.build.externals !== false) {
17
16
  config.plugins.push(viteExternalsPlugin({
18
17
  react: "React",
package/lib/devServer.js CHANGED
@@ -4,7 +4,7 @@ import fs from "node:fs/promises";
4
4
  import path from "node:path";
5
5
  import open from "open";
6
6
  import tcpPortUsed from "tcp-port-used";
7
- import { Client } from "@olenbetong/data-object";
7
+ import { Client } from "@olenbetong/appframe-data";
8
8
  import { importJson } from "./importJson.js";
9
9
  import { createAppframeProxy } from "./proxy.js";
10
10
  dotenv.config();
@@ -25,8 +25,7 @@ async function getUserSession() {
25
25
  return userSession;
26
26
  }
27
27
  function getLoginInfo() {
28
- var _a, _b, _c, _d;
29
- const hostname = (_d = (_b = (_a = appframe.proxy) === null || _a === void 0 ? void 0 : _a.hostname) !== null && _b !== void 0 ? _b : (_c = appframe.deploy) === null || _c === void 0 ? void 0 : _c.hostname) !== null && _d !== void 0 ? _d : "dev.obet.no";
28
+ const hostname = appframe.proxy?.hostname ?? appframe.deploy?.hostname ?? "dev.obet.no";
30
29
  const { APPFRAME_LOGIN: username, APPFRAME_PWD: password } = process.env;
31
30
  if (!username || !password) {
32
31
  throw new Error("Your Appframe credentials are not set in the environment variables. Username should be set in APPFRAME_LOGIN and password in APPFRAME_PWD.");
@@ -34,7 +33,6 @@ function getLoginInfo() {
34
33
  return { hostname, username, password };
35
34
  }
36
35
  export function createProxyMiddleware() {
37
- var _a;
38
36
  let { hostname, username, password } = getLoginInfo();
39
37
  const proxy = createAppframeProxy({ hostname, username, password });
40
38
  const proxyRoutes = [
@@ -52,7 +50,7 @@ export function createProxyMiddleware() {
52
50
  "/rowcount/*",
53
51
  "/lib/*"
54
52
  ];
55
- if ((_a = appframe.proxy) === null || _a === void 0 ? void 0 : _a.routes) {
53
+ if (appframe.proxy?.routes) {
56
54
  proxyRoutes.push(...appframe.proxy.routes);
57
55
  }
58
56
  const router = express.Router();
@@ -63,15 +61,17 @@ export function createProxyMiddleware() {
63
61
  }
64
62
  export function createHtmlTransformer() {
65
63
  return async (html) => {
66
- var _a, _b;
67
- let isPartner = ((_b = (_a = appPkg.appframe) === null || _a === void 0 ? void 0 : _a.article) === null || _b === void 0 ? void 0 : _b.hostname) === "partner.olenbetong.no";
64
+ let isPartner = appPkg.appframe?.article?.hostname === "partner.olenbetong.no";
68
65
  let userSession = await getUserSession();
69
66
  return html
70
- .replace("<!-- {Appframe} -->", `<script>
71
- af = globalThis.af ?? {};
72
- af.userSession = ${JSON.stringify(userSession)};
73
- </script>
74
- <script src="/file/article/static-script/${appframe.article.id}.js"></script>`)
67
+ .replace("<!-- {Appframe} -->", ` <script src="/lib/@olenbetong/appframe-core/1.0.2/dist/iife/af.common.js"></script>
68
+ <script src="/lib/@olenbetong/appframe-data/0.1.5/dist/iife/af.data.js"></script>
69
+
70
+ <script>
71
+ af = globalThis.af ?? {};
72
+ af.userSession = ${JSON.stringify(userSession)};
73
+ </script>
74
+ <script src="/file/article/static-script/${appframe.article.id}.js"></script>`)
75
75
  .replace(`<!-- {Theme} -->`, isPartner
76
76
  ? ` <link rel="stylesheet" href="/file/site/style/ob.application.min.css" />
77
77
  <link rel="stylesheet" href="/file/site/style/ob.theme.base.less" />
package/lib/index.js CHANGED
@@ -8,7 +8,10 @@ export default function appframe() {
8
8
  let config = {
9
9
  build: { target: ["chrome90", "safari14"] },
10
10
  resolve: {
11
- alias: [{ find: "@/", replacement: "/src/" }]
11
+ alias: [
12
+ { find: "@/", replacement: "/src/" },
13
+ { find: "~/", replacement: "/src/" }
14
+ ]
12
15
  }
13
16
  };
14
17
  if (command === "build") {
package/lib/proxy.js CHANGED
@@ -32,10 +32,9 @@ export async function login(hostname, username, password) {
32
32
  };
33
33
  console.log("Authenticating...");
34
34
  let request = https.request(options, response => {
35
- var _a, _b;
36
- let status = (_a = response.statusCode) !== null && _a !== void 0 ? _a : 600;
35
+ let status = response.statusCode ?? 600;
37
36
  if (status < 400) {
38
- let cookies = (_b = response.headers["set-cookie"]) !== null && _b !== void 0 ? _b : [];
37
+ let cookies = response.headers["set-cookie"] ?? [];
39
38
  let cookieObj = {};
40
39
  for (let cookie of cookies) {
41
40
  let [keyValue] = cookie.split(";");
@@ -67,13 +66,12 @@ export function createAppframeProxy(options) {
67
66
  const { hostname, password, protocol = "https", username } = options;
68
67
  const proxy = expressProxy(`${protocol}://${hostname}`, {
69
68
  proxyReqOptDecorator: async function (proxyReqOpts) {
70
- var _a, _b;
71
- if (!((_a = proxyReqOpts.path) === null || _a === void 0 ? void 0 : _a.startsWith("/login"))) {
69
+ if (!proxyReqOpts.path?.startsWith("/login")) {
72
70
  let authCookies = await login(hostname, username, password);
73
71
  let cookies = [];
74
72
  cookies.push(`AppframeWebAuth=${authCookies["AppframeWebAuth"]}`);
75
73
  cookies.push(`AppframeWebSession=${authCookies["AppframeWebSession"]}`);
76
- proxyReqOpts.headers = (_b = proxyReqOpts.headers) !== null && _b !== void 0 ? _b : {};
74
+ proxyReqOpts.headers = proxyReqOpts.headers ?? {};
77
75
  proxyReqOpts.headers["cookie"] = cookies.join(";");
78
76
  }
79
77
  return proxyReqOpts;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olenbetong/appframe-vite",
3
- "version": "1.1.0",
3
+ "version": "1.2.2",
4
4
  "description": "Tools to use and deploy Vite applications to Appframe",
5
5
  "main": "./lib/index.js",
6
6
  "type": "module",
@@ -19,6 +19,7 @@
19
19
  "author": "Bjørnar Vister Hansen <bvh@olenbetong.no>",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
+ "@olenbetong/appframe-data": "^0.1.6",
22
23
  "dotenv": "^16.0.1",
23
24
  "rollup-plugin-visualizer": "^5.6.0",
24
25
  "vite-plugin-externals": "^0.5.0"
@@ -31,12 +32,12 @@
31
32
  "vite": "^2.9.9"
32
33
  },
33
34
  "optionalDependencies": {
34
- "@olenbetong/data-object": "^1.0.0-alpha.65",
35
35
  "@types/express": "^4.17.13",
36
36
  "@types/express-http-proxy": "^1.6.3",
37
37
  "@types/tcp-port-used": "^1.0.1",
38
38
  "express-http-proxy": "^1.6.3",
39
39
  "open": "^8.4.0",
40
40
  "tcp-port-used": "^1.0.2"
41
- }
41
+ },
42
+ "gitHead": "6fe8b7c29fd1b1b2d225708f7530f8fd09e63f09"
42
43
  }