@swell/cli 2.9.4 → 2.9.6
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/app-command.d.ts +2 -3
- package/dist/app-command.js +3 -6
- package/dist/commands/app/dev.d.ts +2 -2
- package/dist/commands/app/dev.js +49 -33
- package/dist/commands/app/frontend/dev.js +12 -6
- package/dist/commands/app/push.d.ts +1 -0
- package/dist/commands/app/push.js +3 -3
- package/dist/commands/app/release.js +2 -2
- package/dist/commands/create/app.d.ts +1 -1
- package/dist/commands/create/app.js +1 -1
- package/dist/commands/create/frontend.js +3 -3
- package/dist/commands/create/tests.js +10 -8
- package/dist/commands/inspect/extensions.js +4 -4
- package/dist/commands/schema.js +21 -18
- package/dist/commands/theme/dev.js +5 -5
- package/dist/commands/theme/push.d.ts +1 -0
- package/dist/commands/theme/push.js +3 -3
- package/dist/create-app-command.js +2 -2
- package/dist/create-config-command.d.ts +1 -1
- package/dist/create-config-command.js +3 -3
- package/dist/help/custom-help.d.ts +1 -1
- package/dist/help/types.d.ts +1 -1
- package/dist/lib/api.d.ts +1 -0
- package/dist/lib/api.js +1 -1
- package/dist/lib/app-config.d.ts +13 -8
- package/dist/lib/app-config.js +25 -23
- package/dist/lib/apps/app-config.d.ts +5 -5
- package/dist/lib/apps/app-config.js +53 -37
- package/dist/lib/apps/index.d.ts +15 -14
- package/dist/lib/apps/index.js +40 -23
- package/dist/lib/apps/paths.d.ts +1 -1
- package/dist/lib/apps/paths.js +3 -3
- package/dist/lib/bundle.js +26 -17
- package/dist/lib/config.d.ts +8 -8
- package/dist/lib/config.js +8 -10
- package/dist/lib/constants.d.ts +9 -9
- package/dist/lib/create/content.d.ts +6 -6
- package/dist/lib/create/content.js +7 -8
- package/dist/lib/create/function.d.ts +5 -6
- package/dist/lib/create/function.js +7 -8
- package/dist/lib/create/index.d.ts +8 -9
- package/dist/lib/create/index.js +7 -8
- package/dist/lib/create/model.d.ts +4 -4
- package/dist/lib/create/model.js +4 -5
- package/dist/lib/create/notification.d.ts +2 -3
- package/dist/lib/create/setting.d.ts +4 -4
- package/dist/lib/create/setting.js +3 -4
- package/dist/lib/create/tests/templates/mock-request.js +30 -0
- package/dist/lib/create/tests/templates/setup-globals.js +35 -0
- package/dist/lib/create/tests/types.d.ts +3 -4
- package/dist/lib/create/tests.d.ts +1 -2
- package/dist/lib/create/tests.js +12 -13
- package/dist/lib/create/webhook.d.ts +6 -6
- package/dist/lib/create/webhook.js +15 -10
- package/dist/lib/function-source-analysis.js +3 -3
- package/dist/lib/info.d.ts +1 -1
- package/dist/lib/logs/index.d.ts +1 -0
- package/dist/lib/logs/line-output.d.ts +1 -0
- package/dist/lib/logs/line-output.js +12 -4
- package/dist/lib/logs/output.d.ts +1 -0
- package/dist/lib/logs/table-output.d.ts +1 -0
- package/dist/lib/logs/table-output.js +8 -5
- package/dist/lib/package-manager.d.ts +5 -5
- package/dist/lib/package-manager.js +9 -7
- package/dist/lib/proxy.js +4 -3
- package/dist/lib/sessions.d.ts +1 -2
- package/dist/lib/sessions.js +1 -2
- package/dist/lib/stores.d.ts +6 -6
- package/dist/lib/stores.js +5 -6
- package/dist/lib/swell-function-wrapper.d.ts +1 -193
- package/dist/lib/swell-function-wrapper.js +24 -1
- package/dist/lib/theme-sync.js +0 -5
- package/dist/push-app-command.d.ts +7 -6
- package/dist/push-app-command.js +35 -37
- package/dist/remote-app-command.d.ts +6 -4
- package/dist/remote-app-command.js +39 -25
- package/dist/swell-api-command.d.ts +1 -0
- package/dist/swell-api-command.js +3 -3
- package/dist/types/index.d.ts +94 -0
- package/dist/types/index.js +4 -0
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
|
@@ -1,193 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Handle a function request.
|
|
3
|
-
* @param {Request} originalRequest from cloudflare
|
|
4
|
-
* @param {*} _env cloudflare environment vars
|
|
5
|
-
* @param {*} context cloudflare conttext
|
|
6
|
-
* @returns {Promise<SwellResponse>}
|
|
7
|
-
*/
|
|
8
|
-
declare function request(originalRequest: Request, _env: any, context: any): Promise<SwellResponse>;
|
|
9
|
-
/**
|
|
10
|
-
* Invokes one of the function types that are available.
|
|
11
|
-
*
|
|
12
|
-
* Type-1: Named export function handlers
|
|
13
|
-
* ```
|
|
14
|
-
* export function post (req) {
|
|
15
|
-
*
|
|
16
|
-
* }
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* Important note:
|
|
20
|
-
* - `delete` func cannot be implemented in Type-1 since it's a reserved name. So, consider using Type-3.
|
|
21
|
-
*
|
|
22
|
-
* Type-2: Default export function handlers
|
|
23
|
-
* ```
|
|
24
|
-
* export default function (req) {
|
|
25
|
-
*
|
|
26
|
-
* }
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* Type-3: Default object with named function handlers
|
|
30
|
-
* ```
|
|
31
|
-
* export default {
|
|
32
|
-
* delete(req) {
|
|
33
|
-
*
|
|
34
|
-
* },
|
|
35
|
-
* post(req) {
|
|
36
|
-
*
|
|
37
|
-
* },
|
|
38
|
-
* }
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* @param {SwellRequest} req
|
|
42
|
-
* @param {Event} context
|
|
43
|
-
*/
|
|
44
|
-
declare function executeModuleHandler(req: SwellRequest, context: Event): Promise<any>;
|
|
45
|
-
/**
|
|
46
|
-
* Helper to determine if a value is an ordinary object.
|
|
47
|
-
* @param {any} obj
|
|
48
|
-
* @returns {boolean}
|
|
49
|
-
*/
|
|
50
|
-
declare function isOrdinaryObject(val: any): boolean;
|
|
51
|
-
declare function validateWorkflowParams(params: any): any;
|
|
52
|
-
declare function validateWorkflowParamValue(value: any, seen?: WeakSet<object>): void;
|
|
53
|
-
declare function validateWorkflowParamArray(value: any, seen: any): void;
|
|
54
|
-
declare function validateWorkflowParamObject(value: any, seen: any): void;
|
|
55
|
-
declare function createWorkflowParamsError(code: any, message: any): SwellError;
|
|
56
|
-
declare namespace originalConsole {
|
|
57
|
-
let log: {
|
|
58
|
-
(...data: any[]): void;
|
|
59
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
60
|
-
};
|
|
61
|
-
let info: {
|
|
62
|
-
(...data: any[]): void;
|
|
63
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
64
|
-
};
|
|
65
|
-
let debug: {
|
|
66
|
-
(...data: any[]): void;
|
|
67
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
68
|
-
};
|
|
69
|
-
let warn: {
|
|
70
|
-
(...data: any[]): void;
|
|
71
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
72
|
-
};
|
|
73
|
-
let error: {
|
|
74
|
-
(...data: any[]): void;
|
|
75
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
declare const WORKFLOW_PARAMS_MAX_BYTES: number;
|
|
79
|
-
/**
|
|
80
|
-
* Class representing a Swell request.
|
|
81
|
-
*/
|
|
82
|
-
declare class SwellRequest {
|
|
83
|
-
constructor(req: any, context: any);
|
|
84
|
-
originalRequest: any;
|
|
85
|
-
context: any;
|
|
86
|
-
appId: any;
|
|
87
|
-
storeId: any;
|
|
88
|
-
accessToken: any;
|
|
89
|
-
publicKey: any;
|
|
90
|
-
store: any;
|
|
91
|
-
session: any;
|
|
92
|
-
logParams: any;
|
|
93
|
-
apiHost: any;
|
|
94
|
-
id: any;
|
|
95
|
-
isLocalDev: boolean;
|
|
96
|
-
swell: SwellAPI;
|
|
97
|
-
rawBody: string;
|
|
98
|
-
body: {};
|
|
99
|
-
query: {};
|
|
100
|
-
data: {};
|
|
101
|
-
_logs: any[];
|
|
102
|
-
assignRequestProps(req: any): void;
|
|
103
|
-
initialize(): Promise<void>;
|
|
104
|
-
url: URL | undefined;
|
|
105
|
-
parseJson(input: any): any;
|
|
106
|
-
log(level: any, ...line: any[]): void;
|
|
107
|
-
getIngestableLogs(response: any): {
|
|
108
|
-
params: any;
|
|
109
|
-
} | undefined;
|
|
110
|
-
formatRequestData(): string;
|
|
111
|
-
ingestLogs(response: any): Promise<void>;
|
|
112
|
-
/**
|
|
113
|
-
* Merge values into app data for the current request.
|
|
114
|
-
* @param {object|string} idOrValues string to indicate app ID, or values to merge
|
|
115
|
-
* @param {object|undefined} values values to merge into app data
|
|
116
|
-
* @returns {object} existing app data merged with values
|
|
117
|
-
* @throws {Error} if app id is missing or values is not a plain object
|
|
118
|
-
*/
|
|
119
|
-
appValues(idOrValues: object | string, values: object | undefined): object;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Class representing the Swell backend API.
|
|
123
|
-
*/
|
|
124
|
-
declare class SwellAPI {
|
|
125
|
-
constructor(req: any, context: any);
|
|
126
|
-
request: any;
|
|
127
|
-
baseUrl: any;
|
|
128
|
-
basicAuth: string;
|
|
129
|
-
context: any;
|
|
130
|
-
workflows: {
|
|
131
|
-
create: (name: any, params: any) => Promise<any>;
|
|
132
|
-
};
|
|
133
|
-
toBase64(inputString: any): string;
|
|
134
|
-
stringifyQuery(queryObject: any, prefix: any): any;
|
|
135
|
-
makeRequest(method: any, url: any, data: any): Promise<any>;
|
|
136
|
-
get(url: any, query: any): Promise<any>;
|
|
137
|
-
put(url: any, data: any): Promise<any>;
|
|
138
|
-
post(url: any, data: any): Promise<any>;
|
|
139
|
-
delete(url: any, data: any): Promise<any>;
|
|
140
|
-
settings(id?: any): Promise<any>;
|
|
141
|
-
createWorkflow(name: any, params: any): Promise<any>;
|
|
142
|
-
/**
|
|
143
|
-
* Atomic multi-op write. Throws SwellError with a stable `error.code`
|
|
144
|
-
* (transaction_conflict | transaction_timeout | transaction_throttled
|
|
145
|
-
* | transaction_op_failed | transaction_error). Retry is off by
|
|
146
|
-
* default — opt in with `{ retry: true }` or pass overrides.
|
|
147
|
-
*
|
|
148
|
-
* @param {Array<{method: string, url: string, data?: any}>} ops
|
|
149
|
-
* @param {{ retry?: true | { limit?: number, base?: number, max?: number, jitter?: boolean } }} [opts]
|
|
150
|
-
* @returns {Promise<any[]>}
|
|
151
|
-
*/
|
|
152
|
-
transaction(ops: Array<{
|
|
153
|
-
method: string;
|
|
154
|
-
url: string;
|
|
155
|
-
data?: any;
|
|
156
|
-
}>, opts?: {
|
|
157
|
-
retry?: true | {
|
|
158
|
-
limit?: number | undefined;
|
|
159
|
-
base?: number | undefined;
|
|
160
|
-
max?: number | undefined;
|
|
161
|
-
jitter?: boolean | undefined;
|
|
162
|
-
} | undefined;
|
|
163
|
-
} | undefined): Promise<any[]>;
|
|
164
|
-
}
|
|
165
|
-
declare const DEFAULT_RETRY: Readonly<{
|
|
166
|
-
limit: 3;
|
|
167
|
-
base: 100;
|
|
168
|
-
max: 5000;
|
|
169
|
-
jitter: true;
|
|
170
|
-
}>;
|
|
171
|
-
declare const RETRYABLE_CODES: Set<string>;
|
|
172
|
-
/**
|
|
173
|
-
* Class representing a Swell error.
|
|
174
|
-
*/
|
|
175
|
-
declare class SwellError extends Error {
|
|
176
|
-
constructor(message: any, options?: {});
|
|
177
|
-
status: any;
|
|
178
|
-
body: any;
|
|
179
|
-
code: any;
|
|
180
|
-
retry: any;
|
|
181
|
-
get isRetryable(): boolean;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Class representing a Swell response.
|
|
185
|
-
*/
|
|
186
|
-
declare class SwellResponse extends Response {
|
|
187
|
-
static _respond(req: any, response: any, context: any): Promise<any>;
|
|
188
|
-
static _consumeNativeResponse(response: any): Promise<SwellResponse>;
|
|
189
|
-
static _respondWithLogs(response: any, req: any): SwellResponse;
|
|
190
|
-
constructor(data: any, options?: {});
|
|
191
|
-
_swellData: any;
|
|
192
|
-
_swellOptions: {};
|
|
193
|
-
}
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
const originalConsole = {
|
|
3
2
|
log: console.log,
|
|
4
3
|
info: console.info,
|
|
@@ -231,6 +230,9 @@ class SwellRequest {
|
|
|
231
230
|
},
|
|
232
231
|
};
|
|
233
232
|
}
|
|
233
|
+
reject(code, message, options = {}) {
|
|
234
|
+
return new SwellRejection(code, message, options);
|
|
235
|
+
}
|
|
234
236
|
}
|
|
235
237
|
/**
|
|
236
238
|
* Class representing the Swell backend API.
|
|
@@ -415,6 +417,26 @@ class SwellError extends Error {
|
|
|
415
417
|
return RETRYABLE_CODES.has(this.code);
|
|
416
418
|
}
|
|
417
419
|
}
|
|
420
|
+
class SwellRejection extends Error {
|
|
421
|
+
constructor(code, message, options = {}) {
|
|
422
|
+
const status = typeof options.status === 'number' &&
|
|
423
|
+
options.status >= 400 &&
|
|
424
|
+
options.status < 500
|
|
425
|
+
? options.status
|
|
426
|
+
: 422;
|
|
427
|
+
super(message || 'Request rejected by function');
|
|
428
|
+
this.name = 'SwellRejection';
|
|
429
|
+
this.status = status;
|
|
430
|
+
this.code = code;
|
|
431
|
+
this.body = {
|
|
432
|
+
$reject: {
|
|
433
|
+
code,
|
|
434
|
+
message: this.message,
|
|
435
|
+
status,
|
|
436
|
+
},
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
}
|
|
418
440
|
/**
|
|
419
441
|
* Class representing a Swell response.
|
|
420
442
|
*/
|
|
@@ -598,3 +620,4 @@ function createWorkflowParamsError(code, message) {
|
|
|
598
620
|
status: 400,
|
|
599
621
|
});
|
|
600
622
|
}
|
|
623
|
+
export {};
|
package/dist/lib/theme-sync.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import getPort, { portNumbers } from 'get-port';
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3
|
-
// @ts-ignore - http-proxy has incomplete TypeScript definitions
|
|
4
2
|
import httpProxy from 'http-proxy';
|
|
5
3
|
import http from 'node:http';
|
|
6
4
|
import util from 'node:util';
|
|
7
5
|
import zlib from 'node:zlib';
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
9
|
-
// @ts-ignore - ws library uses named exports differently
|
|
10
|
-
// eslint-disable-next-line import/no-named-as-default
|
|
11
6
|
import WebSocket, { WebSocketServer } from 'ws';
|
|
12
7
|
const gunzipAsync = util.promisify(zlib.gunzip);
|
|
13
8
|
const inflateAsync = util.promisify(zlib.inflate);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
3
|
import type { GlobbyFilterFunction } from 'globby';
|
|
3
4
|
import * as fs from 'node:fs';
|
|
4
5
|
import { App, AppConfig, ConfigType, FrontendProjectType } from './lib/apps/index.js';
|
|
@@ -26,7 +27,7 @@ export declare abstract class PushAppCommand extends RemoteAppCommand {
|
|
|
26
27
|
deployAppFrontend(force?: boolean, log?: boolean): Promise<void>;
|
|
27
28
|
deployFrontend(projectType: FrontendProjectType): Promise<string>;
|
|
28
29
|
ensureAppExists(file?: string, shouldCreate?: boolean): Promise<boolean>;
|
|
29
|
-
ensureLoggedIn(): Promise<
|
|
30
|
+
ensureLoggedIn(): Promise<void>;
|
|
30
31
|
exec(command: string, cwd?: string, onOutput?: (string: string) => any | false): Promise<void>;
|
|
31
32
|
execFrontend(command: string, onOutput?: (string: string) => any | false): Promise<void>;
|
|
32
33
|
getAllAppStorefronts(params?: {
|
|
@@ -46,8 +47,8 @@ export declare abstract class PushAppCommand extends RemoteAppCommand {
|
|
|
46
47
|
targetPath?: string;
|
|
47
48
|
}, shouldChoose?: boolean): Promise<App | undefined>;
|
|
48
49
|
getExistingApp(appId: string): Promise<App>;
|
|
49
|
-
getFrontendDeploymentHash(): string | undefined
|
|
50
|
-
getFrontendProjectType(required?: boolean): FrontendProjectType | null
|
|
50
|
+
getFrontendDeploymentHash(): Promise<string | undefined>;
|
|
51
|
+
getFrontendProjectType(required?: boolean): Promise<FrontendProjectType | null>;
|
|
51
52
|
getStorefrontToPull(args?: {
|
|
52
53
|
appId?: string;
|
|
53
54
|
targetPath?: string;
|
|
@@ -77,7 +78,7 @@ export declare abstract class PushAppCommand extends RemoteAppCommand {
|
|
|
77
78
|
logStorefrontFrontendUrl(storefront?: any, branchId?: string): void;
|
|
78
79
|
pushFile(relativePath: string): Promise<void>;
|
|
79
80
|
pushFilePath(relativePath: string, force?: boolean): Promise<void>;
|
|
80
|
-
resolveAppPath(appId?: string, targetPath?: string): string
|
|
81
|
+
resolveAppPath(appId?: string, targetPath?: string): Promise<string>;
|
|
81
82
|
runWatchChangeQueue(): Promise<void>;
|
|
82
83
|
saveCurrentStorefront(): void;
|
|
83
84
|
logLocalPreviewUrl(): void;
|
|
@@ -89,7 +90,7 @@ export declare abstract class PushAppCommand extends RemoteAppCommand {
|
|
|
89
90
|
logChanges?: boolean;
|
|
90
91
|
onChange?: (appConfig?: AppConfig, result?: any) => void;
|
|
91
92
|
syncAll?: boolean;
|
|
92
|
-
}): Promise<
|
|
93
|
+
}): Promise<fs.FSWatcher>;
|
|
93
94
|
wranglerDeployFrontend(_projectType: FrontendProjectType): Promise<string>;
|
|
94
95
|
private confirmRemoveInstalledApp;
|
|
95
96
|
}
|
package/dist/push-app-command.js
CHANGED
|
@@ -6,7 +6,7 @@ import * as path from 'node:path';
|
|
|
6
6
|
import Stream from 'node:stream';
|
|
7
7
|
import ora from 'ora';
|
|
8
8
|
import { default as swellConfig } from './lib/app-config.js';
|
|
9
|
-
import { ConfigType, getFrontendProjectValidValues, allConfigFilesInDir, CUSTOM_FRAMEWORK_SLUG, appConfigFromFile,
|
|
9
|
+
import { ConfigType, getFrontendProjectValidValues, allConfigFilesInDir, CUSTOM_FRAMEWORK_SLUG, appConfigFromFile, filePathExistsAsync, findAppConfig, getConfigTypeFromPath, getConfigTypeKeyFromValue, getFrontendProjectType, getProjectCommands, globAllFilesByPath, hashString, isPathDirectory, } from './lib/apps/index.js';
|
|
10
10
|
import { getGlobIgnorePathsChecker } from './lib/apps/paths.js';
|
|
11
11
|
import { slugFromApp } from './lib/apps/slug.js';
|
|
12
12
|
import { default as localConfig } from './lib/config.js';
|
|
@@ -121,7 +121,7 @@ export class PushAppCommand extends RemoteAppCommand {
|
|
|
121
121
|
return;
|
|
122
122
|
}
|
|
123
123
|
// Get commands transformed for the detected package manager
|
|
124
|
-
const { buildCommand } = getProjectCommands(this.appPath, projectType);
|
|
124
|
+
const { buildCommand } = await getProjectCommands(this.appPath, projectType);
|
|
125
125
|
if (!buildCommand) {
|
|
126
126
|
// No build command needed for this framework
|
|
127
127
|
return;
|
|
@@ -251,11 +251,11 @@ export class PushAppCommand extends RemoteAppCommand {
|
|
|
251
251
|
}
|
|
252
252
|
async deployAppFrontend(force, log) {
|
|
253
253
|
const currentStore = localConfig.getDefaultStore();
|
|
254
|
-
const projectType = this.getFrontendProjectType(false);
|
|
254
|
+
const projectType = await this.getFrontendProjectType(false);
|
|
255
255
|
if (!projectType) {
|
|
256
256
|
return;
|
|
257
257
|
}
|
|
258
|
-
const deploymentHash = this.getFrontendDeploymentHash();
|
|
258
|
+
const deploymentHash = await this.getFrontendDeploymentHash();
|
|
259
259
|
// Build and deploy only if there are files to push
|
|
260
260
|
if (deploymentHash &&
|
|
261
261
|
(force || deploymentHash !== this.app.frontend?.deployment_hash)) {
|
|
@@ -335,7 +335,6 @@ export class PushAppCommand extends RemoteAppCommand {
|
|
|
335
335
|
this.log('Logging in...\n');
|
|
336
336
|
await this.config.runCommand('login');
|
|
337
337
|
this.log();
|
|
338
|
-
return true;
|
|
339
338
|
}
|
|
340
339
|
}
|
|
341
340
|
async exec(command, cwd, onOutput) {
|
|
@@ -395,8 +394,8 @@ export class PushAppCommand extends RemoteAppCommand {
|
|
|
395
394
|
const klass = this.ctor;
|
|
396
395
|
const currentStore = localConfig.getDefaultStore();
|
|
397
396
|
await this.api.setStoreEnv(currentStore, klass.orientation?.env);
|
|
398
|
-
this.resolveAppPath(appId, targetPath);
|
|
399
|
-
if (isPathDirectory(this.appPath)) {
|
|
397
|
+
await this.resolveAppPath(appId, targetPath);
|
|
398
|
+
if (await isPathDirectory(this.appPath)) {
|
|
400
399
|
this.swellConfig = await swellConfig(this.appPath);
|
|
401
400
|
const localAppId = String(this.swellConfig.get('id'));
|
|
402
401
|
const localAppType = String(this.swellConfig.get('type'));
|
|
@@ -431,8 +430,8 @@ export class PushAppCommand extends RemoteAppCommand {
|
|
|
431
430
|
}
|
|
432
431
|
}
|
|
433
432
|
}
|
|
434
|
-
getFrontendDeploymentHash() {
|
|
435
|
-
const localConfigs = this.getLocalAppConfigs();
|
|
433
|
+
async getFrontendDeploymentHash() {
|
|
434
|
+
const localConfigs = await this.getLocalAppConfigs();
|
|
436
435
|
let frontendHashes = localConfigs
|
|
437
436
|
.filter((config) => config.filePath?.startsWith(`frontend${path.sep}`))
|
|
438
437
|
.map((config) => config.hash)
|
|
@@ -444,13 +443,13 @@ export class PushAppCommand extends RemoteAppCommand {
|
|
|
444
443
|
}
|
|
445
444
|
return frontendHashes.length > 0 ? hashString(frontendHashes) : undefined;
|
|
446
445
|
}
|
|
447
|
-
getFrontendProjectType(required = true) {
|
|
446
|
+
async getFrontendProjectType(required = true) {
|
|
448
447
|
this.frontendPath = path.join(this.appPath, 'frontend');
|
|
449
|
-
const frontendExists =
|
|
448
|
+
const frontendExists = await filePathExistsAsync(this.frontendPath);
|
|
450
449
|
if (!required && !frontendExists) {
|
|
451
450
|
return null;
|
|
452
451
|
}
|
|
453
|
-
const projectType = getFrontendProjectType(this.appPath);
|
|
452
|
+
const projectType = await getFrontendProjectType(this.appPath);
|
|
454
453
|
if (!projectType) {
|
|
455
454
|
// If frontend not required, just return null (don't error)
|
|
456
455
|
if (!required) {
|
|
@@ -470,10 +469,10 @@ export class PushAppCommand extends RemoteAppCommand {
|
|
|
470
469
|
const { appId, targetPath } = args;
|
|
471
470
|
const targetStorefront = flags['storefront-id'];
|
|
472
471
|
const targetApp = await this.getAppToPull(args, false);
|
|
473
|
-
this.resolveAppPath(appId, targetPath);
|
|
472
|
+
await this.resolveAppPath(appId, targetPath);
|
|
474
473
|
// Only use default if path exists
|
|
475
474
|
let defaultStorefront;
|
|
476
|
-
if (isPathDirectory(this.appPath)) {
|
|
475
|
+
if (await isPathDirectory(this.appPath)) {
|
|
477
476
|
defaultStorefront = localConfig.getDefaultStorefront(this.appPath);
|
|
478
477
|
}
|
|
479
478
|
await this.setStorefrontEnv(flags, defaultStorefront);
|
|
@@ -496,7 +495,7 @@ export class PushAppCommand extends RemoteAppCommand {
|
|
|
496
495
|
const appId = this.appType === 'theme'
|
|
497
496
|
? this.storefront.theme_app_id
|
|
498
497
|
: this.storefront.app_id;
|
|
499
|
-
this.resolveAppPath(this.storefront.name, targetPath);
|
|
498
|
+
await this.resolveAppPath(this.storefront.name, targetPath);
|
|
500
499
|
this.app = await this.getApp(appId);
|
|
501
500
|
}
|
|
502
501
|
else {
|
|
@@ -504,7 +503,7 @@ export class PushAppCommand extends RemoteAppCommand {
|
|
|
504
503
|
// However it's a good fallback in case the storefront was deleted
|
|
505
504
|
// Choosing a theme app will proceed to pull app files
|
|
506
505
|
this.app = await this.chooseAppToPull();
|
|
507
|
-
this.resolveAppPath(this.app.name, targetPath);
|
|
506
|
+
await this.resolveAppPath(this.app.name, targetPath);
|
|
508
507
|
}
|
|
509
508
|
}
|
|
510
509
|
else {
|
|
@@ -632,7 +631,7 @@ export class PushAppCommand extends RemoteAppCommand {
|
|
|
632
631
|
break;
|
|
633
632
|
}
|
|
634
633
|
default: {
|
|
635
|
-
config = appConfigFromFile(configFile, configType, this.appPath);
|
|
634
|
+
config = await appConfigFromFile(configFile, configType, this.appPath);
|
|
636
635
|
this.watchingChangeQueue.set(configFile, {
|
|
637
636
|
action: 'push',
|
|
638
637
|
appConfig: config,
|
|
@@ -678,19 +677,21 @@ export class PushAppCommand extends RemoteAppCommand {
|
|
|
678
677
|
async pushFile(relativePath) {
|
|
679
678
|
const basePath = relativePath.split(path.sep)[0];
|
|
680
679
|
const configType = getConfigTypeFromPath(basePath) || ConfigType.FILE;
|
|
681
|
-
const config = appConfigFromFile(relativePath, configType, this.appPath);
|
|
680
|
+
const config = await appConfigFromFile(relativePath, configType, this.appPath);
|
|
682
681
|
await this.pushRemoteFile(config);
|
|
683
682
|
}
|
|
684
683
|
async pushFilePath(relativePath, force) {
|
|
685
684
|
const topDir = relativePath.split(path.sep)[0];
|
|
686
|
-
const configType =
|
|
687
|
-
const configTypeKey = getConfigTypeKeyFromValue(configType) ||
|
|
685
|
+
const configType = getConfigTypeFromPath(topDir) || ConfigType.FILE;
|
|
686
|
+
const configTypeKey = getConfigTypeKeyFromValue(configType) || ConfigType.FILE;
|
|
688
687
|
const exAppConfigs = (this.app?.configs || []).filter((config) => config.filePath?.startsWith(`${relativePath}/`));
|
|
689
|
-
const
|
|
690
|
-
const pushFiles = [];
|
|
688
|
+
const promises = [];
|
|
691
689
|
for (const { configFile } of allConfigFilesInDir(this.appPath, relativePath, configTypeKey)) {
|
|
692
|
-
|
|
693
|
-
|
|
690
|
+
promises.push(appConfigFromFile(configFile, configType, this.appPath));
|
|
691
|
+
}
|
|
692
|
+
const allFiles = await Promise.all(promises);
|
|
693
|
+
const pushFiles = [];
|
|
694
|
+
for (const config of allFiles) {
|
|
694
695
|
const exConfig = exAppConfigs.find((exConfig) => config.filePath === exConfig.filePath);
|
|
695
696
|
if (!force && exConfig && exConfig.hash === config.hash) {
|
|
696
697
|
continue;
|
|
@@ -705,18 +706,16 @@ export class PushAppCommand extends RemoteAppCommand {
|
|
|
705
706
|
// eslint-disable-next-line no-await-in-loop
|
|
706
707
|
await Promise.all(pushFiles
|
|
707
708
|
.splice(0, pushConcurrency)
|
|
708
|
-
.map(
|
|
709
|
-
await this.pushRemoteFile(appConfig);
|
|
710
|
-
}));
|
|
709
|
+
.map((appConfig) => this.pushRemoteFile(appConfig)));
|
|
711
710
|
}
|
|
712
711
|
}
|
|
713
712
|
// Remove any deleted files
|
|
714
713
|
if (filesToRemove.length > 0) {
|
|
715
714
|
while (filesToRemove.length > 0) {
|
|
716
715
|
// eslint-disable-next-line no-await-in-loop
|
|
717
|
-
await Promise.all(filesToRemove
|
|
718
|
-
|
|
719
|
-
|
|
716
|
+
await Promise.all(filesToRemove
|
|
717
|
+
.splice(0, PUSH_CONCURRENCY)
|
|
718
|
+
.map((appConfig) => this.removeRemoteFile(appConfig)));
|
|
720
719
|
}
|
|
721
720
|
}
|
|
722
721
|
if (!hasChanges && !force) {
|
|
@@ -727,12 +726,12 @@ export class PushAppCommand extends RemoteAppCommand {
|
|
|
727
726
|
this.log(`${style.success('✔')} Pushed ${style.path(relativePath)} to ${style.appConfigValue(this.app.name)}.`);
|
|
728
727
|
}
|
|
729
728
|
}
|
|
730
|
-
resolveAppPath(appId, targetPath) {
|
|
729
|
+
async resolveAppPath(appId, targetPath) {
|
|
731
730
|
const resolvedAppId = appId || '';
|
|
732
731
|
let resolvedPath = targetPath || resolvedAppId;
|
|
733
732
|
// If app_id matches directory, use it as target path
|
|
734
733
|
if (!targetPath &&
|
|
735
|
-
isPathDirectory(path.resolve(process.cwd(), resolvedAppId))) {
|
|
734
|
+
(await isPathDirectory(path.resolve(process.cwd(), resolvedAppId)))) {
|
|
736
735
|
resolvedPath = resolvedAppId;
|
|
737
736
|
}
|
|
738
737
|
// Reset app path if appId is provided
|
|
@@ -761,7 +760,7 @@ export class PushAppCommand extends RemoteAppCommand {
|
|
|
761
760
|
}));
|
|
762
761
|
}
|
|
763
762
|
catch {
|
|
764
|
-
//
|
|
763
|
+
// TODO: Ignore only some errors
|
|
765
764
|
}
|
|
766
765
|
}
|
|
767
766
|
/* eslint-enable no-await-in-loop */
|
|
@@ -844,13 +843,12 @@ export class PushAppCommand extends RemoteAppCommand {
|
|
|
844
843
|
await this.setWatchingFiles();
|
|
845
844
|
if (syncAll) {
|
|
846
845
|
await this.pushAppConfigs();
|
|
847
|
-
fs.watch(this.appPath, { recursive: true }, async (_eventType, _filename) => {
|
|
846
|
+
return fs.watch(this.appPath, { recursive: true }, async (_eventType, _filename) => {
|
|
848
847
|
await this.pushAppConfigs();
|
|
849
848
|
await this.setWatchingFiles();
|
|
850
849
|
});
|
|
851
|
-
return;
|
|
852
850
|
}
|
|
853
|
-
fs.watch(this.appPath, { recursive: true }, this.watchListener);
|
|
851
|
+
return fs.watch(this.appPath, { recursive: true }, this.watchListener);
|
|
854
852
|
}
|
|
855
853
|
async wranglerDeployFrontend(_projectType) {
|
|
856
854
|
let deploymentUrl;
|
|
@@ -859,7 +857,7 @@ export class PushAppCommand extends RemoteAppCommand {
|
|
|
859
857
|
let outputBuffer = '';
|
|
860
858
|
this.log(`\nDeploying to Cloudflare...\n`);
|
|
861
859
|
// Get the wrangler deploy command for the detected package manager
|
|
862
|
-
const pm = detectPackageManager(this.appPath);
|
|
860
|
+
const pm = await detectPackageManager(this.appPath);
|
|
863
861
|
const deployCommand = transformCommand('npx wrangler deploy', pm);
|
|
864
862
|
try {
|
|
865
863
|
await this.execFrontend(deployCommand, (string) => {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type Ora } from 'ora';
|
|
2
|
+
import type { AppCommandOrientation } from './types/index.js';
|
|
1
3
|
import { AppCommand } from './app-command.js';
|
|
2
4
|
import { App, AppConfig, AppVersion } from './lib/apps/index.js';
|
|
3
5
|
/**
|
|
@@ -24,12 +26,12 @@ export declare abstract class RemoteAppCommand extends AppCommand {
|
|
|
24
26
|
getConfigData(configId: string): Promise<any>;
|
|
25
27
|
protected getCreateUpdateApp(updateApp?: App | null): Promise<App>;
|
|
26
28
|
protected getInstalledApp(): Promise<any>;
|
|
27
|
-
protected getLocalAppConfigs(): AppConfig[]
|
|
29
|
+
protected getLocalAppConfigs(): Promise<AppConfig[]>;
|
|
28
30
|
protected getVersion(version?: null | string | undefined): Promise<AppVersion>;
|
|
29
31
|
protected getVersions(version?: null | string | undefined): Promise<AppVersion[]>;
|
|
30
32
|
protected handleRequestErrors(request: () => any, spinnerError?: () => void): Promise<any>;
|
|
31
33
|
init(): Promise<void>;
|
|
32
|
-
protected installApp(version: string, spinner?:
|
|
34
|
+
protected installApp(version: string, spinner?: Ora): Promise<any>;
|
|
33
35
|
isConfigDeprecated(config: AppConfig): boolean;
|
|
34
36
|
localFrontendUrl(storeId: string, localId: string): string;
|
|
35
37
|
logOrientation(orientation?: AppCommandOrientation): Promise<void>;
|
|
@@ -51,8 +53,8 @@ export declare abstract class RemoteAppCommand extends AppCommand {
|
|
|
51
53
|
storefrontFrontendUrl(storeId: string, storefront?: any, branchId?: string, preview?: boolean): string;
|
|
52
54
|
protected swellRcPath(): string;
|
|
53
55
|
protected timestampStyled(): string;
|
|
54
|
-
protected updateInstalledApp(version: string, spinner?:
|
|
55
|
-
protected updateVersion(version: string, body: any, spinner?:
|
|
56
|
+
protected updateInstalledApp(version: string, spinner?: Ora): Promise<void>;
|
|
57
|
+
protected updateVersion(version: string, body: any, spinner?: Ora): Promise<void>;
|
|
56
58
|
/**
|
|
57
59
|
* Reads the .swellrc file and sets up the remote app configuration.
|
|
58
60
|
*
|