@jay-framework/wix-deploy 0.24.0 → 0.24.1
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/dist/artifact-store.js +224 -0
- package/dist/index.d.ts +116 -0
- package/dist/index.js +1168 -0
- package/package.json +8 -8
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { items } from "@wix/data";
|
|
2
|
+
import crypto from "node:crypto";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
function makeItemId(version, relativePath) {
|
|
6
|
+
return crypto.createHash("sha256").update(`v${version}/${relativePath}`).digest("hex").slice(0, 32);
|
|
7
|
+
}
|
|
8
|
+
class WixDataArtifactStore {
|
|
9
|
+
collectionId;
|
|
10
|
+
version;
|
|
11
|
+
distDir;
|
|
12
|
+
cacheDir;
|
|
13
|
+
dataClient;
|
|
14
|
+
moduleRegistry;
|
|
15
|
+
manifestCache;
|
|
16
|
+
fetchPromises = /* @__PURE__ */ new Map();
|
|
17
|
+
constructor(options) {
|
|
18
|
+
this.collectionId = options.collectionId;
|
|
19
|
+
this.version = options.version;
|
|
20
|
+
this.distDir = options.distDir;
|
|
21
|
+
this.cacheDir = options.cacheDir;
|
|
22
|
+
this.dataClient = options.wixClient.use({ items });
|
|
23
|
+
this.moduleRegistry = options.moduleRegistry || {};
|
|
24
|
+
fs.mkdirSync(this.cacheDir, { recursive: true });
|
|
25
|
+
}
|
|
26
|
+
// ========================================================================
|
|
27
|
+
// ArtifactStore interface (reads)
|
|
28
|
+
// ========================================================================
|
|
29
|
+
async readManifest() {
|
|
30
|
+
if (this.manifestCache) return this.manifestCache;
|
|
31
|
+
const content = await this.ensureFile("route-manifest.json");
|
|
32
|
+
this.manifestCache = JSON.parse(content);
|
|
33
|
+
return this.manifestCache;
|
|
34
|
+
}
|
|
35
|
+
async readCacheData(relativePath) {
|
|
36
|
+
const cacheContent = await this.ensureFile(relativePath);
|
|
37
|
+
try {
|
|
38
|
+
const cacheData = JSON.parse(cacheContent);
|
|
39
|
+
return {
|
|
40
|
+
slowViewState: cacheData.slowViewState || {},
|
|
41
|
+
carryForward: cacheData.carryForward || {}
|
|
42
|
+
};
|
|
43
|
+
} catch {
|
|
44
|
+
return { slowViewState: {}, carryForward: {} };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async readPagePartsConfig(relativePath) {
|
|
48
|
+
const content = await this.ensureFile(relativePath);
|
|
49
|
+
return JSON.parse(content);
|
|
50
|
+
}
|
|
51
|
+
async loadServerElement(relativePath) {
|
|
52
|
+
return this.loadModule(relativePath, true);
|
|
53
|
+
}
|
|
54
|
+
async loadModule(modulePath, _local) {
|
|
55
|
+
if (this.moduleRegistry[modulePath]) {
|
|
56
|
+
return this.moduleRegistry[modulePath];
|
|
57
|
+
}
|
|
58
|
+
throw new Error(
|
|
59
|
+
`Module not found in registry: ${modulePath}. All JS modules must be bundled in entry.mjs.`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
getAssetPath(relativePath) {
|
|
63
|
+
return path.join(this.cacheDir, relativePath);
|
|
64
|
+
}
|
|
65
|
+
getBuildDir() {
|
|
66
|
+
return this.cacheDir;
|
|
67
|
+
}
|
|
68
|
+
// ========================================================================
|
|
69
|
+
// Eager loading (cold start)
|
|
70
|
+
// ========================================================================
|
|
71
|
+
async loadEagerFiles() {
|
|
72
|
+
console.log(
|
|
73
|
+
`[WixDataArtifactStore] Loading eager files v${this.version} from "${this.collectionId}"...`
|
|
74
|
+
);
|
|
75
|
+
let totalLoaded = 0;
|
|
76
|
+
let hasMore = true;
|
|
77
|
+
let offset = 0;
|
|
78
|
+
const limit = 50;
|
|
79
|
+
while (hasMore) {
|
|
80
|
+
const result = await this.dataClient.items.query(this.collectionId).eq("category", "eager").eq("version", this.version).skip(offset).limit(limit).find();
|
|
81
|
+
for (const item of result.items) {
|
|
82
|
+
this.writeToCache(item.path, item.content);
|
|
83
|
+
totalLoaded++;
|
|
84
|
+
}
|
|
85
|
+
hasMore = result.items.length === limit;
|
|
86
|
+
offset += limit;
|
|
87
|
+
}
|
|
88
|
+
console.log(`[WixDataArtifactStore] Loaded ${totalLoaded} eager files`);
|
|
89
|
+
}
|
|
90
|
+
// ========================================================================
|
|
91
|
+
// Lazy page file loading
|
|
92
|
+
// ========================================================================
|
|
93
|
+
async ensurePageFiles(preRenderedPath) {
|
|
94
|
+
const dir = path.dirname(preRenderedPath);
|
|
95
|
+
const base = preRenderedPath.replace(/\.jay-html$/, "");
|
|
96
|
+
const filesToEnsure = [
|
|
97
|
+
path.join(dir, "page-parts.json"),
|
|
98
|
+
`${base}.cache.json`,
|
|
99
|
+
`${base}.server-element.js`
|
|
100
|
+
];
|
|
101
|
+
await Promise.all(filesToEnsure.map((f) => this.ensureFile(f)));
|
|
102
|
+
}
|
|
103
|
+
// ========================================================================
|
|
104
|
+
// Writes (for upload-backend and renderer)
|
|
105
|
+
// ========================================================================
|
|
106
|
+
async writeFile(relativePath, content, category) {
|
|
107
|
+
const ext = path.extname(relativePath).slice(1);
|
|
108
|
+
const item = {
|
|
109
|
+
_id: makeItemId(this.version, relativePath),
|
|
110
|
+
version: this.version,
|
|
111
|
+
path: relativePath,
|
|
112
|
+
content,
|
|
113
|
+
fileType: ext || "unknown",
|
|
114
|
+
sizeBytes: Buffer.byteLength(content),
|
|
115
|
+
category
|
|
116
|
+
};
|
|
117
|
+
await this.dataClient.items.save(this.collectionId, item);
|
|
118
|
+
}
|
|
119
|
+
async writeFiles(files) {
|
|
120
|
+
const dataItems = files.map((f) => ({
|
|
121
|
+
_id: makeItemId(this.version, f.path),
|
|
122
|
+
version: this.version,
|
|
123
|
+
path: f.path,
|
|
124
|
+
content: f.content,
|
|
125
|
+
fileType: path.extname(f.path).slice(1) || "unknown",
|
|
126
|
+
sizeBytes: Buffer.byteLength(f.content),
|
|
127
|
+
category: f.category
|
|
128
|
+
}));
|
|
129
|
+
try {
|
|
130
|
+
await this.dataClient.items.bulkSave(this.collectionId, dataItems);
|
|
131
|
+
return dataItems.length;
|
|
132
|
+
} catch {
|
|
133
|
+
let count = 0;
|
|
134
|
+
for (const item of dataItems) {
|
|
135
|
+
try {
|
|
136
|
+
await this.dataClient.items.save(this.collectionId, item);
|
|
137
|
+
count++;
|
|
138
|
+
} catch {
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return count;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// ========================================================================
|
|
145
|
+
// Internal: file resolution
|
|
146
|
+
// ========================================================================
|
|
147
|
+
async ensureFile(relativePath) {
|
|
148
|
+
if (this.distDir) {
|
|
149
|
+
const distPath = path.join(this.distDir, relativePath);
|
|
150
|
+
if (fs.existsSync(distPath)) {
|
|
151
|
+
return fs.readFileSync(distPath, "utf8");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const cachePath = path.join(this.cacheDir, relativePath);
|
|
155
|
+
if (fs.existsSync(cachePath)) {
|
|
156
|
+
return fs.readFileSync(cachePath, "utf8");
|
|
157
|
+
}
|
|
158
|
+
const existing = this.fetchPromises.get(relativePath);
|
|
159
|
+
if (existing) return existing;
|
|
160
|
+
const promise = this.fetchFromCollection(relativePath);
|
|
161
|
+
this.fetchPromises.set(relativePath, promise);
|
|
162
|
+
try {
|
|
163
|
+
return await promise;
|
|
164
|
+
} finally {
|
|
165
|
+
this.fetchPromises.delete(relativePath);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async fetchFromCollection(relativePath) {
|
|
169
|
+
const id = makeItemId(this.version, relativePath);
|
|
170
|
+
try {
|
|
171
|
+
const item = await this.dataClient.items.get(
|
|
172
|
+
this.collectionId,
|
|
173
|
+
id
|
|
174
|
+
);
|
|
175
|
+
if (item?.content) {
|
|
176
|
+
this.writeToCache(relativePath, item.content);
|
|
177
|
+
return item.content;
|
|
178
|
+
}
|
|
179
|
+
} catch {
|
|
180
|
+
}
|
|
181
|
+
const result = await this.dataClient.items.query(this.collectionId).eq("path", relativePath).eq("version", this.version).limit(1).find();
|
|
182
|
+
if (result.items.length > 0) {
|
|
183
|
+
const item = result.items[0];
|
|
184
|
+
this.writeToCache(relativePath, item.content);
|
|
185
|
+
return item.content;
|
|
186
|
+
}
|
|
187
|
+
throw new Error(
|
|
188
|
+
`File not found in data collection: v${this.version}/${relativePath} (id: ${id})`
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
writeToCache(relativePath, content) {
|
|
192
|
+
const fullPath = path.join(this.cacheDir, relativePath);
|
|
193
|
+
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
|
|
194
|
+
if (relativePath.endsWith("page-parts.json")) {
|
|
195
|
+
try {
|
|
196
|
+
const config = JSON.parse(content);
|
|
197
|
+
const rewriteParts = (parts) => {
|
|
198
|
+
for (const part of parts) {
|
|
199
|
+
if (part.modulePath && part.source === "npm") {
|
|
200
|
+
const npmMatch = part.modulePath.match(/\/@jay-framework\/([^/]+)\//);
|
|
201
|
+
if (npmMatch) {
|
|
202
|
+
part.modulePath = `@jay-framework/${npmMatch[1]}`;
|
|
203
|
+
} else {
|
|
204
|
+
const pkgMatch = part.modulePath.match(/\/packages\/(wix-[^/]+)\//);
|
|
205
|
+
if (pkgMatch) {
|
|
206
|
+
part.modulePath = `@jay-framework/${pkgMatch[1]}`;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
if (config.parts) rewriteParts(config.parts);
|
|
213
|
+
if (config.instanceComponents) rewriteParts(config.instanceComponents);
|
|
214
|
+
content = JSON.stringify(config);
|
|
215
|
+
} catch {
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
fs.writeFileSync(fullPath, content, "utf8");
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
export {
|
|
222
|
+
WixDataArtifactStore,
|
|
223
|
+
makeItemId
|
|
224
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { WixClient } from '@wix/sdk';
|
|
2
|
+
import { ArtifactStore, RouteManifest, CacheEntry, ServerElementModule } from '@jay-framework/production-server/serve';
|
|
3
|
+
import * as _jay_framework_fullstack_component from '@jay-framework/fullstack-component';
|
|
4
|
+
import { ConsoleContext } from '@jay-framework/fullstack-component';
|
|
5
|
+
import { WixClientService } from '@jay-framework/wix-server-client';
|
|
6
|
+
import { JayHtmlValidatorFn } from '@jay-framework/compiler-shared';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* WixDataArtifactStore — implements ArtifactStore for Wix BaaS deployments.
|
|
10
|
+
*
|
|
11
|
+
* Reads eager files (route-manifest.json, build-metadata.json) from the dist
|
|
12
|
+
* directory alongside entry.mjs. Fetches lazy JSON files (page-parts, cache
|
|
13
|
+
* data) from a Wix data collection on demand and caches them to disk.
|
|
14
|
+
* All JS modules are resolved from the bundled MODULE_REGISTRY — no disk
|
|
15
|
+
* loading of JS files.
|
|
16
|
+
*
|
|
17
|
+
* Also supports writes (for upload-backend) to the data collection.
|
|
18
|
+
*
|
|
19
|
+
* Data collection schema:
|
|
20
|
+
* _id: string — sha256("{version}/{path}") truncated to 32 chars
|
|
21
|
+
* version: string — deploy version (e.g. "0.0.1-d849685dc3de")
|
|
22
|
+
* path: string — relative file path within backend dir
|
|
23
|
+
* content: string — file content (text)
|
|
24
|
+
* fileType: string — extension (js, json)
|
|
25
|
+
* sizeBytes: number — content byte length
|
|
26
|
+
* category: string — 'eager' | 'lazy'
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
interface WixDataArtifactStoreOptions {
|
|
30
|
+
wixClient: WixClient;
|
|
31
|
+
collectionId: string;
|
|
32
|
+
version: string;
|
|
33
|
+
/** Directory containing entry.mjs and eager files (route-manifest.json, build-metadata.json). Required for reads. */
|
|
34
|
+
distDir?: string;
|
|
35
|
+
/** Directory for caching lazy files fetched from the data collection */
|
|
36
|
+
cacheDir: string;
|
|
37
|
+
moduleRegistry?: Record<string, any>;
|
|
38
|
+
}
|
|
39
|
+
declare class WixDataArtifactStore implements ArtifactStore {
|
|
40
|
+
readonly collectionId: string;
|
|
41
|
+
readonly version: string;
|
|
42
|
+
private readonly distDir;
|
|
43
|
+
private readonly cacheDir;
|
|
44
|
+
private readonly dataClient;
|
|
45
|
+
private readonly moduleRegistry;
|
|
46
|
+
private manifestCache?;
|
|
47
|
+
private fetchPromises;
|
|
48
|
+
constructor(options: WixDataArtifactStoreOptions);
|
|
49
|
+
readManifest(): Promise<RouteManifest>;
|
|
50
|
+
readCacheData(relativePath: string): Promise<CacheEntry>;
|
|
51
|
+
readPagePartsConfig(relativePath: string): Promise<any>;
|
|
52
|
+
loadServerElement(relativePath: string): Promise<ServerElementModule>;
|
|
53
|
+
loadModule(modulePath: string, _local?: boolean): Promise<any>;
|
|
54
|
+
getAssetPath(relativePath: string): string;
|
|
55
|
+
getBuildDir(): string;
|
|
56
|
+
loadEagerFiles(): Promise<void>;
|
|
57
|
+
ensurePageFiles(preRenderedPath: string): Promise<void>;
|
|
58
|
+
writeFile(relativePath: string, content: string, category: 'eager' | 'lazy'): Promise<void>;
|
|
59
|
+
writeFiles(files: Array<{
|
|
60
|
+
path: string;
|
|
61
|
+
content: string;
|
|
62
|
+
category: 'eager' | 'lazy';
|
|
63
|
+
}>): Promise<number>;
|
|
64
|
+
private ensureFile;
|
|
65
|
+
private fetchFromCollection;
|
|
66
|
+
private writeToCache;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface BuildEntryInput {
|
|
70
|
+
collectionId?: string;
|
|
71
|
+
staticBaseUrl?: string;
|
|
72
|
+
excludePlugins?: string;
|
|
73
|
+
}
|
|
74
|
+
declare const buildEntry: _jay_framework_fullstack_component.JayCliCommand<BuildEntryInput> & _jay_framework_fullstack_component.JayCliCommandDefinition<BuildEntryInput, [ConsoleContext]>;
|
|
75
|
+
|
|
76
|
+
interface UploadBackendInput {
|
|
77
|
+
collectionId?: string;
|
|
78
|
+
dryRun?: boolean;
|
|
79
|
+
}
|
|
80
|
+
declare const uploadBackend: _jay_framework_fullstack_component.JayCliCommand<UploadBackendInput> & _jay_framework_fullstack_component.JayCliCommandDefinition<UploadBackendInput, [WixClientService, ConsoleContext]>;
|
|
81
|
+
|
|
82
|
+
interface DeployBaasInput {
|
|
83
|
+
dryRun?: boolean;
|
|
84
|
+
}
|
|
85
|
+
declare const deployBaas: _jay_framework_fullstack_component.JayCliCommand<DeployBaasInput> & _jay_framework_fullstack_component.JayCliCommandDefinition<DeployBaasInput, [ConsoleContext]>;
|
|
86
|
+
|
|
87
|
+
interface DeployInput {
|
|
88
|
+
collectionId?: string;
|
|
89
|
+
staticBaseUrl?: string;
|
|
90
|
+
excludePlugins?: string;
|
|
91
|
+
dryRun?: boolean;
|
|
92
|
+
}
|
|
93
|
+
declare const deploy: _jay_framework_fullstack_component.JayCliCommand<DeployInput> & _jay_framework_fullstack_component.JayCliCommandDefinition<DeployInput, [WixClientService, ConsoleContext]>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* wix-deploy setup hook
|
|
97
|
+
*
|
|
98
|
+
* Runs after wix-server-client setup. Reads wix.config.json to populate
|
|
99
|
+
* clientId and siteId in config/.wix.yaml (if they're still placeholders),
|
|
100
|
+
* then validates the data collection exists.
|
|
101
|
+
*/
|
|
102
|
+
interface SetupContext {
|
|
103
|
+
configDir: string;
|
|
104
|
+
projectRoot: string;
|
|
105
|
+
initError?: Error;
|
|
106
|
+
}
|
|
107
|
+
interface SetupResult {
|
|
108
|
+
status: 'configured' | 'needs-config' | 'error';
|
|
109
|
+
message?: string;
|
|
110
|
+
configCreated?: string[];
|
|
111
|
+
}
|
|
112
|
+
declare function setupWixDeploy(ctx: SetupContext): Promise<SetupResult>;
|
|
113
|
+
|
|
114
|
+
declare const validate: JayHtmlValidatorFn;
|
|
115
|
+
|
|
116
|
+
export { WixDataArtifactStore, type WixDataArtifactStoreOptions, buildEntry, deploy, deployBaas, setupWixDeploy, uploadBackend, validate };
|