@swell/cli 2.0.1-alpha.13 → 2.0.1-alpha.16
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/commands/app/install.d.ts +5 -2
- package/dist/commands/app/install.js +41 -38
- package/dist/commands/app/push.d.ts +3 -3
- package/dist/commands/app/push.js +46 -47
- package/dist/commands/app/version.js +3 -3
- package/dist/commands/create/app.d.ts +8 -8
- package/dist/commands/create/app.js +74 -71
- package/dist/commands/create/content.d.ts +2 -2
- package/dist/commands/create/content.js +10 -10
- package/dist/commands/create/function.d.ts +1 -1
- package/dist/commands/create/function.js +20 -20
- package/dist/commands/create/model.d.ts +2 -2
- package/dist/commands/create/model.js +11 -11
- package/dist/commands/create/notification.d.ts +2 -2
- package/dist/commands/create/notification.js +36 -38
- package/dist/commands/login.d.ts +1 -1
- package/dist/commands/login.js +7 -6
- package/dist/commands/logs.js +2 -0
- package/dist/create-collection-command.d.ts +6 -6
- package/dist/create-collection-command.js +19 -19
- package/dist/create-command.js +6 -4
- package/dist/lib/api.d.ts +3 -2
- package/dist/lib/api.js +11 -8
- package/dist/lib/app-config.d.ts +1 -0
- package/dist/lib/app-config.js +5 -3
- package/dist/lib/apps/index.d.ts +1 -1
- package/dist/lib/apps/index.js +1 -1
- package/dist/lib/apps/paths.d.ts +1 -1
- package/dist/lib/apps/paths.js +1 -1
- package/dist/lib/bundle.js +4 -5
- package/dist/lib/constants.js +2 -3
- package/dist/lib/create/content.d.ts +1 -1
- package/dist/lib/create/content.js +1 -1
- package/dist/lib/create/function.d.ts +2 -2
- package/dist/lib/create/function.js +2 -2
- package/dist/lib/create/index.d.ts +1 -1
- package/dist/lib/create/index.js +6 -6
- package/dist/lib/create/model.d.ts +2 -2
- package/dist/lib/create/notification.d.ts +2 -2
- package/dist/lib/sessions.js +2 -2
- package/dist/lib/stores.d.ts +4 -1
- package/dist/lib/stores.js +6 -3
- package/dist/lib/swell-function-wrapper.d.ts +2 -2
- package/dist/lib/swell-function-wrapper.js +2 -2
- package/dist/remote-app-command.d.ts +2 -2
- package/dist/remote-app-command.js +18 -18
- package/oclif.manifest.json +60 -57
- package/package.json +2 -1
package/dist/create-command.js
CHANGED
|
@@ -44,14 +44,16 @@ export class CreateCommand extends AppCommand {
|
|
|
44
44
|
async getCollectionOptions() {
|
|
45
45
|
const models = await this.api.post({ adminPath: `/data/$get/:models` }, {
|
|
46
46
|
body: {
|
|
47
|
-
limit: 1000,
|
|
48
|
-
client_id: null,
|
|
49
|
-
app_id: null,
|
|
50
47
|
abstract: { $ne: true },
|
|
48
|
+
// eslint-disable-next-line camelcase
|
|
49
|
+
app_id: null,
|
|
50
|
+
// eslint-disable-next-line camelcase
|
|
51
|
+
client_id: null,
|
|
51
52
|
deprecated: { $ne: true },
|
|
53
|
+
fields: 'name, namespace',
|
|
54
|
+
limit: 1000,
|
|
52
55
|
name: { $nin: ['events', 'notifications', 'settings'] },
|
|
53
56
|
sort: 'namespace asc, name asc',
|
|
54
|
-
fields: 'name, namespace',
|
|
55
57
|
},
|
|
56
58
|
});
|
|
57
59
|
return (models?.results?.map((model) => model.namespace ? `${model.namespace}/${model.name}` : model.name) || []);
|
package/dist/lib/api.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
export default class Api {
|
|
2
|
+
private envId;
|
|
2
3
|
private secretKey;
|
|
3
4
|
private storeId;
|
|
4
|
-
private envId;
|
|
5
5
|
constructor(storeId?: string, envId?: string, secretKey?: string);
|
|
6
|
-
setStoreEnv(storeId: string, envId?: string): void;
|
|
7
6
|
api(pathOpts: Api.Paths, options: Api.RequestOptions): Promise<any>;
|
|
8
7
|
delete(pathOpts: Api.Paths, options?: Api.RequestOptions): Promise<any>;
|
|
9
8
|
get(pathOpts: Api.Paths, options?: Api.RequestOptions): Promise<any>;
|
|
10
9
|
isAdmin(): boolean;
|
|
11
10
|
post(pathOpts: Api.Paths, options?: Api.RequestOptions): Promise<any>;
|
|
12
11
|
put(pathOpts: Api.Paths, options?: Api.RequestOptions): Promise<any>;
|
|
12
|
+
setStoreEnv(storeId: string, envId?: string): void;
|
|
13
|
+
truncatePath(path: string | undefined): string | undefined;
|
|
13
14
|
}
|
package/dist/lib/api.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fetch from 'node-fetch';
|
|
2
2
|
import config from './config.js';
|
|
3
|
-
import {
|
|
3
|
+
import { API_BASE_URL, getAdminApiBaseUrl } from './constants.js';
|
|
4
4
|
const defaultHeaders = (opts) => ({
|
|
5
5
|
'Content-Type': 'application/json',
|
|
6
6
|
...opts,
|
|
@@ -23,18 +23,14 @@ const authenticatedHeaders = (storeId, opts = {}) => {
|
|
|
23
23
|
return defaultHeaders(moreOpts);
|
|
24
24
|
};
|
|
25
25
|
export default class Api {
|
|
26
|
+
envId;
|
|
26
27
|
secretKey;
|
|
27
28
|
storeId;
|
|
28
|
-
envId;
|
|
29
29
|
constructor(storeId, envId, secretKey) {
|
|
30
30
|
this.storeId = storeId;
|
|
31
31
|
this.envId = envId;
|
|
32
32
|
this.secretKey = secretKey;
|
|
33
33
|
}
|
|
34
|
-
setStoreEnv(storeId, envId) {
|
|
35
|
-
this.storeId = storeId;
|
|
36
|
-
this.envId = envId;
|
|
37
|
-
}
|
|
38
34
|
async api(pathOpts, options) {
|
|
39
35
|
const storeId = this.storeId || config.getDefaultStore();
|
|
40
36
|
let path;
|
|
@@ -51,8 +47,8 @@ export default class Api {
|
|
|
51
47
|
},
|
|
52
48
|
};
|
|
53
49
|
path = this.isAdmin()
|
|
54
|
-
? `${getAdminApiBaseUrl(storeId)}/${pathOpts.adminPath}`
|
|
55
|
-
: `${API_BASE_URL}/${pathOpts.backendPath}`;
|
|
50
|
+
? `${getAdminApiBaseUrl(storeId)}/${this.truncatePath(pathOpts.adminPath)}`
|
|
51
|
+
: `${API_BASE_URL}/${this.truncatePath(pathOpts.backendPath)}`;
|
|
56
52
|
if (options.query) {
|
|
57
53
|
const query = new URLSearchParams(options.query);
|
|
58
54
|
path += `?${query.toString()}`;
|
|
@@ -123,4 +119,11 @@ export default class Api {
|
|
|
123
119
|
...options,
|
|
124
120
|
});
|
|
125
121
|
}
|
|
122
|
+
setStoreEnv(storeId, envId) {
|
|
123
|
+
this.storeId = storeId;
|
|
124
|
+
this.envId = envId;
|
|
125
|
+
}
|
|
126
|
+
truncatePath(path) {
|
|
127
|
+
return path?.startsWith('/') ? path.slice(1) : path;
|
|
128
|
+
}
|
|
126
129
|
}
|
package/dist/lib/app-config.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ declare function config(configDirPath?: string): LocalApp;
|
|
|
23
23
|
/**
|
|
24
24
|
* Returns a new configuration instance in the current working directory only.
|
|
25
25
|
*
|
|
26
|
+
* @param path Path of the current working directory
|
|
26
27
|
* @returns Conf
|
|
27
28
|
*/
|
|
28
29
|
declare function newConfig(path?: string): any;
|
package/dist/lib/app-config.js
CHANGED
|
@@ -5,12 +5,13 @@ import Conf from 'conf';
|
|
|
5
5
|
import * as fs from 'node:fs';
|
|
6
6
|
import * as path from 'node:path';
|
|
7
7
|
const schema = {
|
|
8
|
+
description: { type: 'string' },
|
|
8
9
|
id: { type: 'string' },
|
|
9
|
-
|
|
10
|
+
integrations: { type: 'array' },
|
|
10
11
|
name: { type: 'string' },
|
|
11
|
-
description: { type: 'string' },
|
|
12
|
-
type: { type: 'string' },
|
|
13
12
|
permissions: { type: 'array' },
|
|
13
|
+
type: { type: 'string' },
|
|
14
|
+
version: { type: 'string' },
|
|
14
15
|
};
|
|
15
16
|
const APP_FILE_NAME = 'swell';
|
|
16
17
|
const APP_FILE_EXT = 'json';
|
|
@@ -115,6 +116,7 @@ function config(configDirPath = '') {
|
|
|
115
116
|
/**
|
|
116
117
|
* Returns a new configuration instance in the current working directory only.
|
|
117
118
|
*
|
|
119
|
+
* @param path Path of the current working directory
|
|
118
120
|
* @returns Conf
|
|
119
121
|
*/
|
|
120
122
|
function newConfig(path) {
|
package/dist/lib/apps/index.d.ts
CHANGED
|
@@ -64,4 +64,4 @@ declare function findAppConfig(app: App, file: string, configType: ConfigType):
|
|
|
64
64
|
declare function batchAppConfigsByType(appConfigs: AppConfig[]): Array<any>;
|
|
65
65
|
export { App, AppVersion, ConfigInputFields, ConfigPaths, ConfigPathsType, ConfigType, appConfigFromFile, appLogoIcon, batchAppConfigsByType, fileExists, findAppConfig, getConfigTypeFromPath, getConfigTypeKeyFromValue, hasAllowedFileExtension, isAppLogoIcon, writeFile, writeJsonFile, };
|
|
66
66
|
export { AppConfig, FunctionProcessingError, IgnoringFileError, } from './app-config.js';
|
|
67
|
-
export { allConfigDirsPaths, allConfigFilesPaths, allConfigFilesPathsByType,
|
|
67
|
+
export { allConfigDirsPaths, allConfigFilesPaths, allConfigFilesPathsByType, configFilePath, getAllConfigPaths, } from './paths.js';
|
package/dist/lib/apps/index.js
CHANGED
|
@@ -164,4 +164,4 @@ export { ConfigInputFields, ConfigPaths, ConfigType,
|
|
|
164
164
|
// functions
|
|
165
165
|
appConfigFromFile, appLogoIcon, batchAppConfigsByType, fileExists, findAppConfig, getConfigTypeFromPath, getConfigTypeKeyFromValue, hasAllowedFileExtension, isAppLogoIcon, writeFile, writeJsonFile, };
|
|
166
166
|
export { AppConfig, FunctionProcessingError, IgnoringFileError, } from './app-config.js';
|
|
167
|
-
export { allConfigDirsPaths, allConfigFilesPaths, allConfigFilesPathsByType,
|
|
167
|
+
export { allConfigDirsPaths, allConfigFilesPaths, allConfigFilesPathsByType, configFilePath, getAllConfigPaths, } from './paths.js';
|
package/dist/lib/apps/paths.d.ts
CHANGED
|
@@ -15,4 +15,4 @@ declare function allConfigFilesPathsByType(appPath: string, configTypeKey: strin
|
|
|
15
15
|
}, void, unknown>;
|
|
16
16
|
declare function configFilePath(appPath: string, config: AppConfig): string;
|
|
17
17
|
declare function getAllConfigPaths(): Array<string>;
|
|
18
|
-
export { allConfigDirsPaths, allConfigFilesPaths, allConfigFilesPathsByType,
|
|
18
|
+
export { allConfigDirsPaths, allConfigFilesPaths, allConfigFilesPathsByType, configFilePath, getAllConfigPaths, };
|
package/dist/lib/apps/paths.js
CHANGED
|
@@ -51,4 +51,4 @@ function getAllConfigPaths() {
|
|
|
51
51
|
}
|
|
52
52
|
return configPaths;
|
|
53
53
|
}
|
|
54
|
-
export { allConfigDirsPaths, allConfigFilesPaths, allConfigFilesPathsByType,
|
|
54
|
+
export { allConfigDirsPaths, allConfigFilesPaths, allConfigFilesPathsByType, configFilePath, getAllConfigPaths, };
|
package/dist/lib/bundle.js
CHANGED
|
@@ -24,7 +24,7 @@ export async function bundleFunction(filePath) {
|
|
|
24
24
|
.join('\n');
|
|
25
25
|
// Remove comments with to get a unique hash in the API
|
|
26
26
|
// Because esbuild puts the file name as a comment
|
|
27
|
-
code = code.
|
|
27
|
+
code = code.replaceAll(/^\n?\/\/.*/gm, '');
|
|
28
28
|
// eslint-disable-next-line no-new-func
|
|
29
29
|
const evalFn = new Function(`${code}\nreturn { ...moduleExports }`);
|
|
30
30
|
const { config, ...moduleExports } = evalFn();
|
|
@@ -32,7 +32,6 @@ export async function bundleFunction(filePath) {
|
|
|
32
32
|
return { code, config, dependencies, moduleExports };
|
|
33
33
|
}
|
|
34
34
|
catch (error) {
|
|
35
|
-
console.log(error);
|
|
36
35
|
throw new Error(`Unable to compile function ${filePath}: ${error.message}`);
|
|
37
36
|
}
|
|
38
37
|
}
|
|
@@ -44,13 +43,13 @@ function getSwellFunctionWrapper() {
|
|
|
44
43
|
async function minifyCode(code) {
|
|
45
44
|
try {
|
|
46
45
|
const result = await esbuild.transform(code, {
|
|
47
|
-
minifyWhitespace: true,
|
|
48
46
|
minifyIdentifiers: false,
|
|
49
47
|
minifySyntax: false,
|
|
48
|
+
minifyWhitespace: true,
|
|
50
49
|
});
|
|
51
50
|
return result.code;
|
|
52
51
|
}
|
|
53
|
-
catch (
|
|
54
|
-
throw new Error('Compilation error:',
|
|
52
|
+
catch (error) {
|
|
53
|
+
throw new Error('Compilation error:', error.message);
|
|
55
54
|
}
|
|
56
55
|
}
|
package/dist/lib/constants.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
+
/* eslint-disable no-template-curly-in-string */
|
|
1
2
|
import { env } from './config.js';
|
|
2
3
|
// note: env values stored in ~/.swell/env.json
|
|
3
4
|
// url for backend api calls
|
|
4
5
|
export const API_BASE_URL = env.get('API_BASE_URL') || 'https://api.swell.store';
|
|
5
6
|
// url for admin api calls
|
|
6
|
-
export const ADMIN_API_BASE_URL =
|
|
7
|
-
// eslint-disable-next-line no-template-curly-in-string
|
|
8
|
-
env.get('ADMIN_API_BASE_URL') || 'https://${STORE_ID}.swell.store/admin/api';
|
|
7
|
+
export const ADMIN_API_BASE_URL = env.get('ADMIN_API_BASE_URL') || 'https://${STORE_ID}.swell.store/admin/api';
|
|
9
8
|
// url host for admin login
|
|
10
9
|
export const LOGIN_HOST = env.get('LOGIN_HOST') || 'https://${STORE_ID}.swell.store';
|
|
11
10
|
// helpers to get constants with replacements
|
|
@@ -7,11 +7,11 @@ interface CreateFunctionArgs {
|
|
|
7
7
|
interface WriteFunctionFileParams {
|
|
8
8
|
description: string;
|
|
9
9
|
events: string;
|
|
10
|
-
route: string;
|
|
11
10
|
functionName: string;
|
|
12
11
|
language: FunctionLanguage;
|
|
12
|
+
route: string;
|
|
13
13
|
schedule: string;
|
|
14
14
|
trigger: FunctionType;
|
|
15
15
|
}
|
|
16
|
-
declare const getFunctionTemplate: ({ description, events, route, schedule,
|
|
16
|
+
declare const getFunctionTemplate: ({ description, events, language, route, schedule, trigger, }: WriteFunctionFileParams) => string;
|
|
17
17
|
export { CreateFunctionArgs, FunctionLanguage, FunctionType, WriteFunctionFileParams, getFunctionTemplate, };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const getFunctionTemplate = ({ description, events, route, schedule,
|
|
1
|
+
const getFunctionTemplate = ({ description, events, language, route, schedule, trigger, }) => {
|
|
2
2
|
let typeAppend = ``;
|
|
3
3
|
if (trigger === 'model') {
|
|
4
4
|
const eventsList = events
|
|
5
5
|
.split(/\s*,\s*/g)
|
|
6
|
-
.filter(
|
|
6
|
+
.filter(Boolean)
|
|
7
7
|
.map((eventName) => `'${eventName}'`)
|
|
8
8
|
.join(', ');
|
|
9
9
|
typeAppend = `,
|
|
@@ -10,4 +10,4 @@ declare const toFunctionFileName: (value: string) => string;
|
|
|
10
10
|
declare const toCollectionName: (value: string) => string;
|
|
11
11
|
declare const toCollectionLabel: (value: string) => string;
|
|
12
12
|
declare const toNotificationLabel: (value: string) => string;
|
|
13
|
-
export { CreateFileParams,
|
|
13
|
+
export { CreateFileParams, toAppId, toAppName, toCollectionLabel, toCollectionName, toFileName, toFunctionFileName, toNotificationLabel, };
|
package/dist/lib/create/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { dasherize, pluralize,
|
|
1
|
+
import { dasherize, pluralize, titleize, underscore } from 'inflection';
|
|
2
2
|
// Example: 'My Thing' => 'my-thing'
|
|
3
3
|
const toFileName = (value) => dasherize(underscore(value.split('.')[0].replace(' ', '_'))).toLowerCase();
|
|
4
4
|
// Example: 'my-things' => 'My Things'
|
|
5
5
|
const toAppName = (value) => pluralize(titleize(value).replace('-', ' '));
|
|
6
6
|
// Example: 'My App' => 'my_app'
|
|
7
7
|
const toAppId = (value) => String(value || '')
|
|
8
|
-
.
|
|
9
|
-
.
|
|
10
|
-
.
|
|
11
|
-
.
|
|
8
|
+
.replaceAll(/[^\s\w./:-]/g, '')
|
|
9
|
+
.replaceAll(/[_\s-:./]+/g, '_')
|
|
10
|
+
.replaceAll(/^_+|_+$/g, '')
|
|
11
|
+
.replaceAll(/([a-z])([A-Z])/g, '$1_$2')
|
|
12
12
|
.toLowerCase();
|
|
13
13
|
// Example: 'My Thing' => 'my-thing'
|
|
14
14
|
// And: 'myThing' => 'myThing'
|
|
@@ -19,4 +19,4 @@ const toCollectionName = (value) => pluralize(value.replaceAll(/[^A-Za-z]/g, '-'
|
|
|
19
19
|
const toCollectionLabel = (value) => pluralize(titleize(value).replace('-', ' '));
|
|
20
20
|
// Example: 'order-receipt' => 'Order Receipt'
|
|
21
21
|
const toNotificationLabel = (value) => titleize(value).replace('-', ' ');
|
|
22
|
-
export {
|
|
22
|
+
export { toAppId, toAppName, toCollectionLabel, toCollectionName, toFileName, toFunctionFileName, toNotificationLabel, };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
interface CreateModelFileBody {
|
|
2
|
-
label?: string;
|
|
3
2
|
collection?: string;
|
|
4
3
|
description?: string;
|
|
5
|
-
fields?: ModelFieldResponse;
|
|
6
4
|
events?: ModelEventObject;
|
|
5
|
+
fields?: ModelFieldResponse;
|
|
6
|
+
label?: string;
|
|
7
7
|
}
|
|
8
8
|
interface ModelEventObject {
|
|
9
9
|
types?: ModelEvent[];
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
interface WriteNotificationsFileParams {
|
|
2
|
+
admin?: boolean;
|
|
2
3
|
description: string;
|
|
3
4
|
event: string;
|
|
4
5
|
model: string;
|
|
5
6
|
name: string;
|
|
6
|
-
subject: string;
|
|
7
|
-
admin?: boolean;
|
|
8
7
|
once?: boolean;
|
|
8
|
+
subject: string;
|
|
9
9
|
}
|
|
10
10
|
interface CreateNotificationFileBody {
|
|
11
11
|
admin?: boolean;
|
package/dist/lib/sessions.js
CHANGED
|
@@ -20,7 +20,6 @@ function createServer(onSessionId, storeId) {
|
|
|
20
20
|
// the spinner is used to show progress while waiting for the browser
|
|
21
21
|
const spinner = ux.action;
|
|
22
22
|
serverForLogin({
|
|
23
|
-
storeId,
|
|
24
23
|
onPost(req) {
|
|
25
24
|
// we received the session id from the browser so we can move on
|
|
26
25
|
const sessionId = req.headers['x-session'];
|
|
@@ -37,6 +36,7 @@ function createServer(onSessionId, storeId) {
|
|
|
37
36
|
].join(' '));
|
|
38
37
|
await open(loginUrl);
|
|
39
38
|
},
|
|
39
|
+
storeId,
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
@@ -52,7 +52,7 @@ function createServer(onSessionId, storeId) {
|
|
|
52
52
|
* from the browser
|
|
53
53
|
* @returns void
|
|
54
54
|
*/
|
|
55
|
-
function serverForLogin({
|
|
55
|
+
function serverForLogin({ onPost, onStart, storeId, }) {
|
|
56
56
|
// flag to track if the POST and GET requests have been handled
|
|
57
57
|
// we only want to handle them once
|
|
58
58
|
let postHandled = false;
|
package/dist/lib/stores.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ declare function selectStoreId({ authorizations, currentStoreId, force, }: {
|
|
|
35
35
|
* Select the store to switch to from a CLI prompt from the list of
|
|
36
36
|
* already logged in stores.
|
|
37
37
|
*
|
|
38
|
+
* @param message Store selection message
|
|
38
39
|
* @returns The store ID to switch to
|
|
39
40
|
* @throws CLIError - If there are no stores to switch to
|
|
40
41
|
*/
|
|
@@ -42,6 +43,8 @@ declare function selectLoggedInStoreId(message?: string): Promise<string>;
|
|
|
42
43
|
/**
|
|
43
44
|
* Select an environment.
|
|
44
45
|
*
|
|
46
|
+
* @param message Environment selection message
|
|
47
|
+
* @returns Environment to switch to
|
|
45
48
|
* @throws CLIError - If there are no stores to switch to
|
|
46
49
|
*/
|
|
47
50
|
declare function selectEnvironmentId(message?: string): Promise<string>;
|
|
@@ -60,4 +63,4 @@ declare function modifyDefaultStore({ currentStoreId, storeId, }: {
|
|
|
60
63
|
currentStoreId: string;
|
|
61
64
|
storeId: string;
|
|
62
65
|
}): Promise<void>;
|
|
63
|
-
export { modifyDefaultStore, selectLoggedInStoreId, selectStoreId,
|
|
66
|
+
export { modifyDefaultStore, selectEnvironmentId, selectLoggedInStoreId, selectStoreId, showStores, };
|
package/dist/lib/stores.js
CHANGED
|
@@ -101,6 +101,7 @@ async function selectStoreId({ authorizations, currentStoreId, force = false, })
|
|
|
101
101
|
* Select the store to switch to from a CLI prompt from the list of
|
|
102
102
|
* already logged in stores.
|
|
103
103
|
*
|
|
104
|
+
* @param message Store selection message
|
|
104
105
|
* @returns The store ID to switch to
|
|
105
106
|
* @throws CLIError - If there are no stores to switch to
|
|
106
107
|
*/
|
|
@@ -123,14 +124,16 @@ async function selectLoggedInStoreId(message) {
|
|
|
123
124
|
new Separator(),
|
|
124
125
|
{ name: 'Login to another account', value: '' },
|
|
125
126
|
],
|
|
127
|
+
loop: false,
|
|
126
128
|
message: message || 'Which store do you want to switch to?',
|
|
127
129
|
pageSize: 25,
|
|
128
|
-
loop: false,
|
|
129
130
|
});
|
|
130
131
|
}
|
|
131
132
|
/**
|
|
132
133
|
* Select an environment.
|
|
133
134
|
*
|
|
135
|
+
* @param message Environment selection message
|
|
136
|
+
* @returns Environment to switch to
|
|
134
137
|
* @throws CLIError - If there are no stores to switch to
|
|
135
138
|
*/
|
|
136
139
|
async function selectEnvironmentId(message) {
|
|
@@ -145,7 +148,7 @@ async function selectEnvironmentId(message) {
|
|
|
145
148
|
value: 'test',
|
|
146
149
|
},
|
|
147
150
|
],
|
|
148
|
-
message: message || 'Which
|
|
151
|
+
message: message || 'Which environment?',
|
|
149
152
|
});
|
|
150
153
|
}
|
|
151
154
|
/**
|
|
@@ -170,4 +173,4 @@ async function modifyDefaultStore({ currentStoreId, storeId, }) {
|
|
|
170
173
|
config.setDefaultStore(storeId);
|
|
171
174
|
}
|
|
172
175
|
}
|
|
173
|
-
export { modifyDefaultStore, selectLoggedInStoreId, selectStoreId,
|
|
176
|
+
export { modifyDefaultStore, selectEnvironmentId, selectLoggedInStoreId, selectStoreId, showStores, };
|
|
@@ -84,11 +84,11 @@ declare class SwellRequest {
|
|
|
84
84
|
ingestLogs(response: any): Promise<void>;
|
|
85
85
|
/**
|
|
86
86
|
* Merge values into app data for the current request.
|
|
87
|
-
* @param {object|string
|
|
87
|
+
* @param {object|string} idOrValues string to indicate app ID, or values to merge
|
|
88
88
|
* @param {object|undefined} values values to merge into app data
|
|
89
89
|
* @returns {object|undefined} existing app data merged with values if passed
|
|
90
90
|
*/
|
|
91
|
-
appValues(idOrValues
|
|
91
|
+
appValues(idOrValues: object | string, values?: object | undefined): object | undefined;
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
94
|
* Class representing the Swell backend API.
|
|
@@ -182,11 +182,11 @@ class SwellRequest {
|
|
|
182
182
|
}
|
|
183
183
|
/**
|
|
184
184
|
* Merge values into app data for the current request.
|
|
185
|
-
* @param {object|string
|
|
185
|
+
* @param {object|string} idOrValues string to indicate app ID, or values to merge
|
|
186
186
|
* @param {object|undefined} values values to merge into app data
|
|
187
187
|
* @returns {object|undefined} existing app data merged with values if passed
|
|
188
188
|
*/
|
|
189
|
-
appValues(idOrValues
|
|
189
|
+
appValues(idOrValues, values = undefined) {
|
|
190
190
|
const appId = typeof idOrValues === 'string' ? appIdOrValues : this.appId;
|
|
191
191
|
const appValues = typeof idOrValues === 'string' ? values : idOrValues;
|
|
192
192
|
if (!appId || !isOrdinaryObject(appValues)) {
|
|
@@ -14,12 +14,14 @@ export declare abstract class RemoteAppCommand extends AppCommand {
|
|
|
14
14
|
protected getApp(id?: string): Promise<App>;
|
|
15
15
|
protected getAppWithConfig(id?: string): Promise<App>;
|
|
16
16
|
protected getCreateUpdateApp(updateApp?: App): Promise<App>;
|
|
17
|
+
protected getVersions(version?: null | string | undefined): Promise<AppVersion[]>;
|
|
17
18
|
protected handleRequestErrors(request: () => any, spinnerError?: () => void): Promise<any>;
|
|
18
19
|
init(): Promise<void>;
|
|
19
20
|
protected postConfig(configJson: any): Promise<any>;
|
|
20
21
|
protected pushConfigFile(appConfig: AppConfig): Promise<any>;
|
|
21
22
|
protected removeConfig(config: AppConfig): Promise<any>;
|
|
22
23
|
protected showErrors(errors: any, spinnerError?: () => void): void;
|
|
24
|
+
protected swellRcPath(): string;
|
|
23
25
|
protected syncAppConfigs(): Promise<{
|
|
24
26
|
installed: string[];
|
|
25
27
|
removed: string[];
|
|
@@ -31,6 +33,4 @@ export declare abstract class RemoteAppCommand extends AppCommand {
|
|
|
31
33
|
*/
|
|
32
34
|
private initApp;
|
|
33
35
|
private showOrientation;
|
|
34
|
-
protected getVersions(version?: string | undefined | null): Promise<AppVersion[]>;
|
|
35
|
-
protected swellRcPath(): string;
|
|
36
36
|
}
|
|
@@ -5,9 +5,9 @@ import ora from 'ora';
|
|
|
5
5
|
import { AppCommand } from './app-command.js';
|
|
6
6
|
import { appConfigFileExists, readRcFile, writeRcFile, } from './lib/app-config.js';
|
|
7
7
|
import { FunctionProcessingError, IgnoringFileError, allConfigFilesPaths, appConfigFromFile, appLogoIcon, batchAppConfigsByType, configFilePath, isAppLogoIcon, } from './lib/apps/index.js';
|
|
8
|
-
import { toAppId } from './lib/create/index.js';
|
|
9
8
|
import { default as swellConfig } from './lib/config.js';
|
|
10
9
|
import { getLoginHost } from './lib/constants.js';
|
|
10
|
+
import { toAppId } from './lib/create/index.js';
|
|
11
11
|
import style from './lib/style.js';
|
|
12
12
|
/**
|
|
13
13
|
* Extends the AppCommand with methods that ease managing remote apps and
|
|
@@ -22,7 +22,7 @@ export class RemoteAppCommand extends AppCommand {
|
|
|
22
22
|
dashboardUrl(flags = {}, storeId) {
|
|
23
23
|
const { env } = flags;
|
|
24
24
|
const envFlag = env || this.ctor.orientation?.env;
|
|
25
|
-
const outputEnv = envFlag === 'live' ? '' :
|
|
25
|
+
const outputEnv = envFlag === 'live' ? '' : envFlag ? 'test' : '';
|
|
26
26
|
return `${getLoginHost(storeId)}/admin/${outputEnv ? `${outputEnv}/` : ''}apps/${this.app.id}`;
|
|
27
27
|
}
|
|
28
28
|
async deleteConfig(configId) {
|
|
@@ -142,7 +142,7 @@ export class RemoteAppCommand extends AppCommand {
|
|
|
142
142
|
adminPath: `/apps/${this.appConfig.store.id}`,
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
|
-
catch
|
|
145
|
+
catch {
|
|
146
146
|
// noop
|
|
147
147
|
}
|
|
148
148
|
spinner.start(`Creating app...`);
|
|
@@ -180,6 +180,17 @@ export class RemoteAppCommand extends AppCommand {
|
|
|
180
180
|
}
|
|
181
181
|
return {};
|
|
182
182
|
}
|
|
183
|
+
async getVersions(version) {
|
|
184
|
+
const versionsResponse = await this.api.get({ adminPath: `/apps/${this.app.id}/versions` }, {
|
|
185
|
+
query: {
|
|
186
|
+
limit: 1000,
|
|
187
|
+
sort: 'version desc',
|
|
188
|
+
...(version ? { version } : undefined),
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
this.debugJson('getApp: versionsResponse', versionsResponse);
|
|
192
|
+
return versionsResponse.results || [];
|
|
193
|
+
}
|
|
183
194
|
async handleRequestErrors(request, spinnerError) {
|
|
184
195
|
try {
|
|
185
196
|
const response = await request();
|
|
@@ -291,6 +302,9 @@ export class RemoteAppCommand extends AppCommand {
|
|
|
291
302
|
.join(' '));
|
|
292
303
|
}
|
|
293
304
|
}
|
|
305
|
+
swellRcPath() {
|
|
306
|
+
return path.join(this.appPath, '.swellrc');
|
|
307
|
+
}
|
|
294
308
|
async syncAppConfigs() {
|
|
295
309
|
const configsToPush = [];
|
|
296
310
|
const installed = [];
|
|
@@ -306,8 +320,8 @@ export class RemoteAppCommand extends AppCommand {
|
|
|
306
320
|
const batches = batchAppConfigsByType(configsToPush);
|
|
307
321
|
for (const batch of batches) {
|
|
308
322
|
this.log(style.appConfigName(batch.label));
|
|
309
|
-
// eslint-disable-next-line no-await-in-loop
|
|
310
323
|
for (const appConfig of batch.configs) {
|
|
324
|
+
// eslint-disable-next-line no-await-in-loop
|
|
311
325
|
const installedConfig = await this.pushConfigFile(appConfig);
|
|
312
326
|
if (installedConfig)
|
|
313
327
|
installed.push(installedConfig.id);
|
|
@@ -375,18 +389,4 @@ export class RemoteAppCommand extends AppCommand {
|
|
|
375
389
|
this.log(orientationOutput.join(' '));
|
|
376
390
|
this.log();
|
|
377
391
|
}
|
|
378
|
-
async getVersions(version) {
|
|
379
|
-
const versionsResponse = await this.api.get({ adminPath: `/apps/${this.app.id}/versions` }, {
|
|
380
|
-
query: {
|
|
381
|
-
limit: 1000,
|
|
382
|
-
sort: 'version desc',
|
|
383
|
-
...(version ? { version } : undefined),
|
|
384
|
-
},
|
|
385
|
-
});
|
|
386
|
-
this.debugJson('getApp: versionsResponse', versionsResponse);
|
|
387
|
-
return versionsResponse.results || [];
|
|
388
|
-
}
|
|
389
|
-
swellRcPath() {
|
|
390
|
-
return path.join(this.appPath, '.swellrc');
|
|
391
|
-
}
|
|
392
392
|
}
|