create-wirejs-app 2.0.6 → 2.0.8

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": "create-wirejs-app",
3
- "version": "2.0.6",
3
+ "version": "2.0.8",
4
4
  "description": "Initializes a wirejs package.",
5
5
  "author": "Jon Wire",
6
6
  "license": "MIT",
@@ -4,12 +4,8 @@
4
4
  "version": "1.0.0",
5
5
  "type": "module",
6
6
  "scripts": {
7
- "prestart": "node prebuild.js",
8
- "start": "",
9
- "prebuild": "node prebuild.js"
10
- },
11
- "devDependencies": {
12
- "rimraf": "^6.0.1"
7
+ "prestart": "wirejs-scripts prebuild-api",
8
+ "prebuild": "wirejs-scripts prebuild-api"
13
9
  },
14
10
  "exports": {
15
11
  "wirejs:client": "./index.client.js",
@@ -9,12 +9,12 @@
9
9
  ],
10
10
  "dependencies": {
11
11
  "wirejs-dom": "^1.0.34",
12
- "wirejs-resources": "^0.1.6-alpha",
12
+ "wirejs-resources": "^0.1.9-alpha",
13
13
  "dompurify": "^3.2.3",
14
14
  "marked": "^15.0.6"
15
15
  },
16
16
  "devDependencies": {
17
- "wirejs-scripts": "^3.0.1"
17
+ "wirejs-scripts": "^3.0.2"
18
18
  },
19
19
  "scripts": {
20
20
  "prebuild": "npm run prebuild --workspaces --if-present",
@@ -1,104 +0,0 @@
1
- import { writeFileSync } from 'fs';
2
-
3
- let API_URL = '/api';
4
- const indexModule = await import('./index.js');
5
-
6
- try {
7
- const backendConfigModule = await import('./config.js');
8
- const backendConfig = backendConfigModule.default;
9
- console.log("backend config found", backendConfig);
10
- if (backendConfig.apiUrl) {
11
- API_URL = backendConfig.apiUrl;
12
- }
13
- } catch {
14
- console.log("No backend API config found.");
15
- }
16
-
17
- function dedent(tabs, text) {
18
- const tabString = new Array(tabs).fill('\t').join('');
19
- return text.trim().replace(new RegExp(`^${tabString}`, 'gm'), '');
20
- }
21
-
22
- const apiCode = Object.keys(indexModule)
23
- .map(name => `export const ${name} = apiTree(${JSON.stringify([name])});`)
24
- .join('\n')
25
- ;
26
-
27
- const baseClient = dedent(1, /* js */ `
28
- async function wirejsCallApi(method, ...args) {
29
- function isNode() {
30
- return typeof args[0]?.cookies?.getAll === 'function'
31
- // return typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
32
- }
33
-
34
- function apiUrl() {
35
- if (isNode()) {
36
- return "${API_URL}";
37
- } else {
38
- return "/api";
39
- }
40
- }
41
-
42
- let cookieHeader = {};
43
-
44
- if (isNode()) {
45
- const context = args[0];
46
- const cookies = context.cookies.getAll();
47
- cookieHeader = typeof cookies === 'object'
48
- ? {
49
- Cookie: Object.entries(cookies).map(kv => kv.join('=')).join('; ')
50
- }
51
- : {};
52
- }
53
-
54
- const response = await fetch(apiUrl(), {
55
- method: 'POST',
56
- headers: {
57
- 'Content-Type': 'application/json',
58
- ...cookieHeader
59
- },
60
- body: JSON.stringify([{method, args:[...args]}]),
61
- });
62
- const body = await response.json();
63
-
64
- if (isNode()) {
65
- const context = args[0];
66
- for (const c of response.headers.getSetCookie()) {
67
- const parts = c.split(';').map(p => p.trim());
68
- const flags = parts.slice(1);
69
- const [name, value] = parts[0].split('=').map(decodeURIComponent);
70
- const httpOnly = flags.includes('HttpOnly');
71
- const secure = flags.includes('Secure');
72
- const maxAgePart = flags.find(f => f.startsWith('Max-Age='))?.split('=')[1];
73
- context.cookies.set({
74
- name,
75
- value,
76
- httpOnly,
77
- secure,
78
- maxAge: maxAgePart ? parseInt(maxAgePart) : undefined
79
- });
80
- }
81
- }
82
-
83
- const error = body[0].error;
84
- if (error) {
85
- throw new Error(error);
86
- }
87
-
88
- const value = body[0].data;
89
- return value;
90
- };
91
-
92
- function apiTree(path = []) {
93
- return new Proxy(function() {}, {
94
- apply(_target, _thisArg, args) {
95
- return wirejsCallApi(path, ...args);
96
- },
97
- get(_target, prop) {
98
- return apiTree([...path, prop]);
99
- }
100
- });
101
- };
102
- `);
103
-
104
- writeFileSync('index.client.js', [baseClient, apiCode].join('\n\n'));