@swell/cli 2.0.1-alpha.16 → 2.0.1-alpha.18

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.
Files changed (86) hide show
  1. package/dist/app-command.d.ts +1 -1
  2. package/dist/app-command.js +9 -9
  3. package/dist/commands/app/dev.d.ts +16 -0
  4. package/dist/commands/app/dev.js +28 -0
  5. package/dist/commands/app/frontend/deploy.d.ts +15 -0
  6. package/dist/commands/app/frontend/deploy.js +41 -0
  7. package/dist/commands/app/frontend/dev.d.ts +19 -0
  8. package/dist/commands/app/frontend/dev.js +108 -0
  9. package/dist/commands/app/info.js +14 -9
  10. package/dist/commands/app/init.d.ts +12 -0
  11. package/dist/commands/app/init.js +34 -0
  12. package/dist/commands/app/install.d.ts +0 -3
  13. package/dist/commands/app/install.js +12 -21
  14. package/dist/commands/app/pull.d.ts +15 -0
  15. package/dist/commands/app/pull.js +50 -0
  16. package/dist/commands/app/push.d.ts +9 -12
  17. package/dist/commands/app/push.js +57 -131
  18. package/dist/commands/app/release.d.ts +13 -0
  19. package/dist/commands/app/release.js +148 -0
  20. package/dist/commands/app/version.d.ts +5 -4
  21. package/dist/commands/app/version.js +60 -39
  22. package/dist/commands/app/watch.d.ts +2 -4
  23. package/dist/commands/app/watch.js +3 -83
  24. package/dist/commands/create/app.d.ts +35 -11
  25. package/dist/commands/create/app.js +131 -128
  26. package/dist/commands/create/frontend.d.ts +12 -0
  27. package/dist/commands/create/frontend.js +38 -0
  28. package/dist/commands/create/function.d.ts +2 -2
  29. package/dist/commands/create/function.js +2 -2
  30. package/dist/commands/create/notification.d.ts +2 -2
  31. package/dist/commands/create/notification.js +2 -2
  32. package/dist/commands/env.d.ts +12 -0
  33. package/dist/commands/env.js +31 -0
  34. package/dist/commands/login.js +7 -7
  35. package/dist/commands/logs.js +0 -3
  36. package/dist/commands/theme/dev.d.ts +21 -0
  37. package/dist/commands/theme/dev.js +164 -0
  38. package/dist/commands/theme/init.d.ts +9 -0
  39. package/dist/commands/theme/init.js +15 -0
  40. package/dist/commands/theme/pull.d.ts +20 -0
  41. package/dist/commands/theme/pull.js +65 -0
  42. package/dist/commands/theme/push.d.ts +19 -0
  43. package/dist/commands/theme/push.js +89 -0
  44. package/dist/create-app-command.d.ts +20 -0
  45. package/dist/create-app-command.js +253 -0
  46. package/dist/create-collection-command.d.ts +3 -3
  47. package/dist/create-collection-command.js +4 -4
  48. package/dist/{create-command.d.ts → create-config-command.d.ts} +1 -1
  49. package/dist/{create-command.js → create-config-command.js} +3 -5
  50. package/dist/env/local.d.ts +8 -0
  51. package/dist/env/local.js +7 -0
  52. package/dist/env/production.d.ts +8 -0
  53. package/dist/env/production.js +7 -0
  54. package/dist/env/review.d.ts +8 -0
  55. package/dist/env/review.js +7 -0
  56. package/dist/env/staging.d.ts +8 -0
  57. package/dist/env/staging.js +7 -0
  58. package/dist/lib/api.d.ts +1 -0
  59. package/dist/lib/api.js +39 -13
  60. package/dist/lib/app-config.d.ts +12 -5
  61. package/dist/lib/app-config.js +57 -21
  62. package/dist/lib/apps/app-config.d.ts +17 -3
  63. package/dist/lib/apps/app-config.js +194 -66
  64. package/dist/lib/apps/index.d.ts +92 -12
  65. package/dist/lib/apps/index.js +145 -47
  66. package/dist/lib/apps/paths.d.ts +14 -7
  67. package/dist/lib/apps/paths.js +73 -28
  68. package/dist/lib/config.d.ts +9 -2
  69. package/dist/lib/config.js +49 -1
  70. package/dist/lib/constants.d.ts +5 -0
  71. package/dist/lib/constants.js +23 -4
  72. package/dist/lib/create/content.d.ts +1 -1
  73. package/dist/lib/create/index.js +5 -1
  74. package/dist/lib/info.js +2 -2
  75. package/dist/lib/stores.d.ts +5 -3
  76. package/dist/lib/stores.js +7 -5
  77. package/dist/lib/style.d.ts +2 -0
  78. package/dist/lib/style.js +2 -0
  79. package/dist/push-app-command.d.ts +73 -0
  80. package/dist/push-app-command.js +754 -0
  81. package/dist/remote-app-command.d.ts +35 -9
  82. package/dist/remote-app-command.js +417 -159
  83. package/oclif.manifest.json +817 -71
  84. package/package.json +13 -1
  85. package/dist/commands/app/_pull.d.ts +0 -8
  86. package/dist/commands/app/_pull.js +0 -45
@@ -2,6 +2,10 @@ import Conf from 'conf';
2
2
  import Configstore from 'configstore';
3
3
  import { homedir } from 'node:os';
4
4
  import path from 'node:path';
5
+ import localEnv from '../env/local.js';
6
+ import prodEnv from '../env/production.js';
7
+ import reviewEnv from '../env/review.js';
8
+ import stagingEnv from '../env/staging.js';
5
9
  import style from './style.js';
6
10
  const configPath = process.env.NODE_ENV === 'test'
7
11
  ? path.resolve(process.cwd(), 'test', '.swell', 'config.json')
@@ -28,6 +32,36 @@ const env = new Conf({
28
32
  projectName: 'swell',
29
33
  projectSuffix: '',
30
34
  });
35
+ function setEnv(name, reviewBranch) {
36
+ let newEnv = {};
37
+ if (name.startsWith('prod')) {
38
+ newEnv = { ...prodEnv };
39
+ }
40
+ else if (name.startsWith('stag')) {
41
+ newEnv = { ...stagingEnv };
42
+ }
43
+ else if (name.startsWith('local')) {
44
+ newEnv = { ...localEnv };
45
+ }
46
+ else if (name.startsWith('rev') || name.startsWith('ra')) {
47
+ if (reviewBranch) {
48
+ const reviewAppEnv = { ...reviewEnv };
49
+ const reviewDomain = reviewBranch.replaceAll('/', '-');
50
+ for (const key of Object.keys(reviewAppEnv)) {
51
+ reviewAppEnv[key] = reviewAppEnv[key].replace('${REVIEW_DOMAIN}', reviewDomain);
52
+ }
53
+ newEnv = reviewAppEnv;
54
+ }
55
+ else {
56
+ throw new Error('Review environment requires a branch name.');
57
+ }
58
+ }
59
+ else {
60
+ throw new Error(`Invalid environment '${name}'. Should be one of 'prod', 'staging', 'review', or 'local'.`);
61
+ }
62
+ env.set(newEnv);
63
+ return newEnv;
64
+ }
31
65
  /**
32
66
  * Get specified attributes for given object.
33
67
  *
@@ -68,6 +102,18 @@ function getDefaultStore() {
68
102
  function setDefaultStore(storeId) {
69
103
  return configStore.set('defaultStore', storeId);
70
104
  }
105
+ function getDefaultStorefront(appPath) {
106
+ const storeId = getDefaultStore();
107
+ const defaultStorefronts = configStore.get('defaultStorefronts') || {};
108
+ return defaultStorefronts[storeId]?.[appPath];
109
+ }
110
+ function setDefaultStorefront(appPath, storefrontId) {
111
+ const storeId = getDefaultStore();
112
+ const defaultStorefronts = configStore.get('defaultStorefronts') || {};
113
+ defaultStorefronts[storeId] = defaultStorefronts[storeId] || {};
114
+ defaultStorefronts[storeId][appPath] = storefrontId;
115
+ return configStore.set('defaultStorefronts', defaultStorefronts);
116
+ }
71
117
  function getSessionId(storeId) {
72
118
  if (!configStore.has('stores'))
73
119
  return;
@@ -122,10 +168,12 @@ const config = {
122
168
  get,
123
169
  getAll,
124
170
  getDefaultStore,
171
+ getDefaultStorefront,
125
172
  getSessionId,
126
173
  getUser,
127
174
  setDefaultStore,
175
+ setDefaultStorefront,
128
176
  setStore,
129
177
  setUser,
130
178
  };
131
- export { config as default, env };
179
+ export { config as default, env, setEnv };
@@ -1,5 +1,10 @@
1
1
  export declare const API_BASE_URL: any;
2
2
  export declare const ADMIN_API_BASE_URL: any;
3
3
  export declare const LOGIN_HOST: any;
4
+ export declare const APP_PAGES_HOST: any;
5
+ export declare const STOREFRONT_FRONTEND_HOST: any;
4
6
  export declare function getAdminApiBaseUrl(storeId: string): any;
5
7
  export declare function getLoginHost(storeId?: string): any;
8
+ export declare function getAppFrontendHost(storeId: string, installedAppId: string): any;
9
+ export declare function getStorefrontFrontendHost(storefrontSlug: string, branchId?: string): any;
10
+ export declare function getLocalFrontendHost(storeId: string, sessionId: string): any;
@@ -1,12 +1,18 @@
1
- /* eslint-disable no-template-curly-in-string */
1
+ import defaultEnv from '../env/production.js';
2
2
  import { env } from './config.js';
3
3
  // note: env values stored in ~/.swell/env.json
4
4
  // url for backend api calls
5
- export const API_BASE_URL = env.get('API_BASE_URL') || 'https://api.swell.store';
5
+ export const API_BASE_URL = env.get('API_BASE_URL') || defaultEnv.API_BASE_URL;
6
6
  // url for admin api calls
7
- export const ADMIN_API_BASE_URL = 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') || defaultEnv.ADMIN_API_BASE_URL;
8
8
  // url host for admin login
9
- export const LOGIN_HOST = env.get('LOGIN_HOST') || 'https://${STORE_ID}.swell.store';
9
+ export const LOGIN_HOST = env.get('LOGIN_HOST') || defaultEnv.LOGIN_HOST;
10
+ // url host for app frontend
11
+ export const APP_PAGES_HOST = env.get('APP_PAGES_HOST') || defaultEnv.APP_PAGES_HOST;
12
+ // url host for storefront app frontend
13
+ export const STOREFRONT_FRONTEND_HOST = env.get('STOREFRONT_FRONTEND_HOST') ||
14
+ env.get('STOREFRONT_PAGES_HOST') || // Deprecated
15
+ defaultEnv.STOREFRONT_FRONTEND_HOST;
10
16
  // helpers to get constants with replacements
11
17
  export function getAdminApiBaseUrl(storeId) {
12
18
  return ADMIN_API_BASE_URL.replace('${STORE_ID}', storeId);
@@ -14,3 +20,16 @@ export function getAdminApiBaseUrl(storeId) {
14
20
  export function getLoginHost(storeId) {
15
21
  return LOGIN_HOST.replace('${STORE_ID}', storeId || 'login');
16
22
  }
23
+ export function getAppFrontendHost(storeId, installedAppId) {
24
+ return APP_PAGES_HOST.replace('${STORE_ID}', storeId)
25
+ .replace('${APP_ID}', installedAppId)
26
+ .replace('${ENV}', 'app');
27
+ }
28
+ export function getStorefrontFrontendHost(storefrontSlug, branchId) {
29
+ return STOREFRONT_FRONTEND_HOST.replace('${STOREFRONT_SLUG}', storefrontSlug).replace('${BRANCH_PREFIX}', branchId ? `${branchId}.` : '');
30
+ }
31
+ export function getLocalFrontendHost(storeId, sessionId) {
32
+ return APP_PAGES_HOST.replace('${STORE_ID}', storeId)
33
+ .replace('${APP_ID}', sessionId)
34
+ .replace('${ENV}', 'local');
35
+ }
@@ -12,7 +12,7 @@ interface ContentViewProps {
12
12
  tabs: [];
13
13
  }
14
14
  type ContentView = 'edit' | 'list' | 'new';
15
- type ContentType = 'asset' | 'basic_html' | 'blocks' | 'boolean' | 'category_lookup' | 'checkbox' | 'checkboxes' | 'collection' | 'color' | 'currency' | 'customer_lookup' | 'date' | 'datetime' | 'document' | 'dropdown' | 'email' | 'field_group' | 'generic_lookup' | 'icon' | 'image' | 'long_text' | 'lookup' | 'markdown' | 'number' | 'percent' | 'phone' | 'product_lookup' | 'radio' | 'rich_html' | 'select' | 'short_text' | 'slider' | 'slug' | 'tags' | 'text' | 'textarea' | 'time' | 'toggle' | 'url' | 'variant_lookup' | 'video';
15
+ type ContentType = 'asset' | 'basic_html' | 'boolean' | 'category_lookup' | 'checkbox' | 'checkboxes' | 'collection' | 'color' | 'color_scheme' | 'color_scheme_group' | 'currency' | 'customer_lookup' | 'date' | 'datetime' | 'document' | 'dropdown' | 'email' | 'field_group' | 'font_family' | 'generic_lookup' | 'html' | 'icon' | 'image' | 'long_text' | 'lookup' | 'markdown' | 'number' | 'percent' | 'phone' | 'product_lookup' | 'radio' | 'rich_html' | 'rich_text' | 'select' | 'short_text' | 'slider' | 'slug' | 'tags' | 'text' | 'textarea' | 'time' | 'toggle' | 'url' | 'variant_lookup' | 'video';
16
16
  interface ContentFieldProps {
17
17
  id: string;
18
18
  label: string;
@@ -2,7 +2,11 @@ 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
- const toAppName = (value) => pluralize(titleize(value).replace('-', ' '));
5
+ const toAppName = (value) => titleize(value)
6
+ .replaceAll(/[_\s-:./-]+/g, ' ')
7
+ .replaceAll(/([a-z])([A-Z])/g, '$1 $2')
8
+ .replaceAll(/(\d)([a-z])/gi, '$1 $2')
9
+ .replaceAll(/([a-z])(\d)/gi, '$1 $2');
6
10
  // Example: 'My App' => 'my_app'
7
11
  const toAppId = (value) => String(value || '')
8
12
  .replaceAll(/[^\s\w./:-]/g, '')
package/dist/lib/info.js CHANGED
@@ -20,7 +20,7 @@ export class FieldDefinitions {
20
20
  get client() {
21
21
  return {
22
22
  label: 'Test store',
23
- transform: (client) => `${client.name} (${style.storeId(client.id)})`,
23
+ transform: (client) => client && `${client.name} (${style.storeId(client.id)})`,
24
24
  };
25
25
  }
26
26
  get dateCreated() {
@@ -57,7 +57,7 @@ export class FieldDefinitions {
57
57
  label: 'Version',
58
58
  transform: (_version) => {
59
59
  if (this.versions.length === 0) {
60
- return 'N/A';
60
+ return this.app.version || 'N/A';
61
61
  }
62
62
  return [
63
63
  style.appConfigValue(this.versions[0].version),
@@ -54,13 +54,15 @@ declare function selectEnvironmentId(message?: string): Promise<string>;
54
54
  * If there is no current store id, it will always be set as the default
55
55
  * without asking.
56
56
  *
57
- * @param currentStoreId - The ID of the default store
58
- * @param storeId - The ID of the store to set as the default
57
+ * @param storeParams -
58
+ * currentStoreId - The ID of the default store
59
+ * storeId - The ID of the store to set as the default
60
+ * @param force - True to force
59
61
  *
60
62
  * @returns void
61
63
  */
62
64
  declare function modifyDefaultStore({ currentStoreId, storeId, }: {
63
65
  currentStoreId: string;
64
66
  storeId: string;
65
- }): Promise<void>;
67
+ }, force?: boolean): Promise<void>;
66
68
  export { modifyDefaultStore, selectEnvironmentId, selectLoggedInStoreId, selectStoreId, showStores, };
@@ -157,19 +157,21 @@ async function selectEnvironmentId(message) {
157
157
  * If there is no current store id, it will always be set as the default
158
158
  * without asking.
159
159
  *
160
- * @param currentStoreId - The ID of the default store
161
- * @param storeId - The ID of the store to set as the default
160
+ * @param storeParams -
161
+ * currentStoreId - The ID of the default store
162
+ * storeId - The ID of the store to set as the default
163
+ * @param force - True to force
162
164
  *
163
165
  * @returns void
164
166
  */
165
- async function modifyDefaultStore({ currentStoreId, storeId, }) {
167
+ async function modifyDefaultStore({ currentStoreId, storeId, }, force = false) {
166
168
  let modifyDefault = false;
167
- if (currentStoreId && currentStoreId !== storeId) {
169
+ if (!force && currentStoreId && currentStoreId !== storeId) {
168
170
  modifyDefault = await confirm({
169
171
  message: `Do you want to make ${style.storeId(storeId)} your default store?`,
170
172
  });
171
173
  }
172
- if (!currentStoreId || modifyDefault) {
174
+ if (force || !currentStoreId || modifyDefault) {
173
175
  config.setDefaultStore(storeId);
174
176
  }
175
177
  }
@@ -5,9 +5,11 @@ declare const _default: {
5
5
  link: import("chalk").ChalkInstance;
6
6
  path: import("chalk").ChalkInstance;
7
7
  dim: import("chalk").ChalkInstance;
8
+ strike: import("chalk").ChalkInstance;
8
9
  command: import("chalk").ChalkInstance;
9
10
  storeId: import("chalk").ChalkInstance;
10
11
  currentUser: import("chalk").ChalkInstance;
12
+ appName: import("chalk").ChalkInstance;
11
13
  appEnvLive: import("chalk").ChalkInstance;
12
14
  appEnv: import("chalk").ChalkInstance;
13
15
  appConfigName: import("chalk").ChalkInstance;
package/dist/lib/style.js CHANGED
@@ -7,11 +7,13 @@ export default {
7
7
  link: chalk.blueBright.underline,
8
8
  path: chalk.underline,
9
9
  dim: chalk.dim,
10
+ strike: chalk.strikethrough,
10
11
  // styles for consistent output of some elements
11
12
  command: chalk.magenta.bold,
12
13
  storeId: chalk.yellow,
13
14
  currentUser: chalk.blueBright.underline,
14
15
  // apps
16
+ appName: chalk.yellow,
15
17
  appEnvLive: chalk.magenta,
16
18
  appEnv: chalk.yellow,
17
19
  appConfigName: chalk.yellow,
@@ -0,0 +1,73 @@
1
+ /// <reference types="node" />
2
+ import { App, AppConfig, ConfigType, FrontendProjectType } from './lib/apps/index.js';
3
+ import { RemoteAppCommand } from './remote-app-command.js';
4
+ type WatchFileEvent = 'change' | 'deleted' | 'new';
5
+ export declare abstract class PushAppCommand extends RemoteAppCommand {
6
+ frontendPath: string;
7
+ logWatchChanges: boolean;
8
+ onWatchChange?: ((appConfig?: AppConfig, result?: any) => void) | undefined;
9
+ watchingChangeQueue: Array<any>;
10
+ watchingChangeQueueRunning: boolean;
11
+ watchingFiles: Array<string>;
12
+ watchListener: (eventType: string, filename: Buffer | null | string) => Promise<void>;
13
+ buildFrontend(projectType: FrontendProjectType): Promise<void>;
14
+ chooseAppToPull(query?: any): Promise<App>;
15
+ createAppStorefront(hasOtherStorefronts?: boolean): Promise<any>;
16
+ deployAppFrontend(force?: boolean, log?: boolean): Promise<void>;
17
+ deployFrontend(projectType: FrontendProjectType): Promise<string>;
18
+ ensureAppExists(file?: string, shouldCreate?: boolean): Promise<boolean>;
19
+ ensureLoggedIn(): Promise<true | undefined>;
20
+ exec(command: string, onOutput?: (string: string) => any | false): Promise<void>;
21
+ getAllAppStorefronts(params?: {
22
+ type?: string;
23
+ }): Promise<any>;
24
+ getAllStorefronts(params?: {
25
+ app_id?: string;
26
+ theme_app_id?: string;
27
+ type?: string;
28
+ }): Promise<any>;
29
+ getAppStorefront(params?: {
30
+ storefront_id?: string;
31
+ type?: string;
32
+ }): Promise<any>;
33
+ getAppToPull(args: {
34
+ appId?: string;
35
+ targetPath?: string;
36
+ }, shouldChoose?: boolean): Promise<App | undefined>;
37
+ getExistingApp(appId: string): Promise<App>;
38
+ getFrontendDeploymentHash(): string | undefined;
39
+ getFrontendProjectType(required?: boolean): FrontendProjectType | null;
40
+ getStorefrontToPull(args?: {
41
+ appId?: string;
42
+ targetPath?: string;
43
+ }, flags?: {
44
+ 'storefront-id'?: string;
45
+ 'storefront-select'?: boolean;
46
+ }): Promise<any>;
47
+ getStorefrontToPush(flags?: {
48
+ 'storefront-id'?: string;
49
+ 'storefront-select'?: boolean;
50
+ }): Promise<any>;
51
+ handleWatchFileChange(configFile: string, configType: ConfigType, event: WatchFileEvent): Promise<void>;
52
+ logAppFrontendUrl(): void;
53
+ logDashboardUrl(flags: {
54
+ [flag: string]: any;
55
+ }): void;
56
+ logStorefrontConnected(): void;
57
+ logStorefrontFrontendUrl(storefront?: any, branchId?: string): void;
58
+ pushFile(relativePath: string): Promise<void>;
59
+ pushFilePath(relativePath: string, force?: boolean): Promise<void>;
60
+ resolveAppPath(appId?: string, targetPath?: string): string;
61
+ runWatchChangeQueue(): Promise<void>;
62
+ saveCurrentStorefront(): void;
63
+ setWatchingFiles(): void;
64
+ updateFrontendDeployment(currentStore: string, projectType: FrontendProjectType, deploymentUrl: string, deploymentHash: string): Promise<void>;
65
+ watchForChanges({ logChanges, onChange, syncAll, }?: {
66
+ logChanges?: boolean | undefined;
67
+ onChange?: (() => void) | undefined;
68
+ syncAll?: boolean | undefined;
69
+ }): Promise<void>;
70
+ wranglerDeployFrontend(projectType: FrontendProjectType): Promise<string>;
71
+ private confirmRemoveInstalledApp;
72
+ }
73
+ export {};