@swell/cli 2.0.1-alpha.13 → 2.0.1-alpha.17

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 (91) hide show
  1. package/dist/app-command.d.ts +1 -1
  2. package/dist/app-command.js +8 -8
  3. package/dist/commands/app/dev.d.ts +18 -0
  4. package/dist/commands/app/dev.js +31 -0
  5. package/dist/commands/app/frontend/deploy.d.ts +17 -0
  6. package/dist/commands/app/frontend/deploy.js +44 -0
  7. package/dist/commands/app/frontend/dev.d.ts +21 -0
  8. package/dist/commands/app/frontend/dev.js +111 -0
  9. package/dist/commands/app/info.js +15 -8
  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 +4 -4
  13. package/dist/commands/app/install.js +37 -42
  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 +11 -14
  17. package/dist/commands/app/push.js +71 -143
  18. package/dist/commands/app/release.d.ts +13 -0
  19. package/dist/commands/app/release.js +150 -0
  20. package/dist/commands/app/version.d.ts +7 -6
  21. package/dist/commands/app/version.js +64 -43
  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 +150 -144
  26. package/dist/commands/create/content.d.ts +2 -2
  27. package/dist/commands/create/content.js +10 -10
  28. package/dist/commands/create/frontend.d.ts +12 -0
  29. package/dist/commands/create/frontend.js +41 -0
  30. package/dist/commands/create/function.d.ts +3 -3
  31. package/dist/commands/create/function.js +22 -22
  32. package/dist/commands/create/model.d.ts +2 -2
  33. package/dist/commands/create/model.js +11 -11
  34. package/dist/commands/create/notification.d.ts +4 -4
  35. package/dist/commands/create/notification.js +38 -40
  36. package/dist/commands/login.d.ts +1 -1
  37. package/dist/commands/login.js +12 -9
  38. package/dist/commands/logs.js +2 -1
  39. package/dist/commands/theme/dev.d.ts +23 -0
  40. package/dist/commands/theme/dev.js +167 -0
  41. package/dist/commands/theme/init.d.ts +9 -0
  42. package/dist/commands/theme/init.js +15 -0
  43. package/dist/commands/theme/pull.d.ts +20 -0
  44. package/dist/commands/theme/pull.js +65 -0
  45. package/dist/commands/theme/push.d.ts +19 -0
  46. package/dist/commands/theme/push.js +92 -0
  47. package/dist/create-app-command.d.ts +20 -0
  48. package/dist/create-app-command.js +254 -0
  49. package/dist/create-collection-command.d.ts +9 -9
  50. package/dist/create-collection-command.js +23 -23
  51. package/dist/{create-command.d.ts → create-config-command.d.ts} +1 -1
  52. package/dist/{create-command.js → create-config-command.js} +9 -7
  53. package/dist/lib/api.d.ts +6 -4
  54. package/dist/lib/api.js +58 -29
  55. package/dist/lib/app-config.d.ts +13 -5
  56. package/dist/lib/app-config.js +60 -23
  57. package/dist/lib/apps/app-config.d.ts +22 -8
  58. package/dist/lib/apps/app-config.js +202 -68
  59. package/dist/lib/apps/index.d.ts +93 -13
  60. package/dist/lib/apps/index.js +150 -50
  61. package/dist/lib/apps/paths.d.ts +14 -7
  62. package/dist/lib/apps/paths.js +73 -28
  63. package/dist/lib/bundle.js +4 -5
  64. package/dist/lib/config.d.ts +5 -1
  65. package/dist/lib/config.js +14 -0
  66. package/dist/lib/constants.d.ts +5 -0
  67. package/dist/lib/constants.js +22 -3
  68. package/dist/lib/create/content.d.ts +2 -2
  69. package/dist/lib/create/content.js +1 -1
  70. package/dist/lib/create/function.d.ts +2 -2
  71. package/dist/lib/create/function.js +2 -2
  72. package/dist/lib/create/index.d.ts +1 -1
  73. package/dist/lib/create/index.js +11 -7
  74. package/dist/lib/create/model.d.ts +2 -2
  75. package/dist/lib/create/notification.d.ts +2 -2
  76. package/dist/lib/info.js +2 -2
  77. package/dist/lib/sessions.js +2 -2
  78. package/dist/lib/stores.d.ts +5 -2
  79. package/dist/lib/stores.js +9 -6
  80. package/dist/lib/style.d.ts +2 -0
  81. package/dist/lib/style.js +2 -0
  82. package/dist/lib/swell-function-wrapper.d.ts +2 -2
  83. package/dist/lib/swell-function-wrapper.js +2 -2
  84. package/dist/push-app-command.d.ts +73 -0
  85. package/dist/push-app-command.js +765 -0
  86. package/dist/remote-app-command.d.ts +35 -9
  87. package/dist/remote-app-command.js +436 -164
  88. package/oclif.manifest.json +841 -125
  89. package/package.json +13 -1
  90. package/dist/commands/app/_pull.d.ts +0 -8
  91. package/dist/commands/app/_pull.js +0 -45
@@ -14,7 +14,7 @@ export declare abstract class AppCommand extends SwellCommand {
14
14
  static baseFlags: {
15
15
  'app-path': import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
16
16
  };
17
- appConfig: any;
17
+ swellConfig: any;
18
18
  appPath: string;
19
19
  constructor(argv: string[], config: Config);
20
20
  init(): Promise<void>;
@@ -1,5 +1,6 @@
1
+ import * as path from 'node:path';
1
2
  import { Flags } from '@oclif/core';
2
- import { default as appConfig } from './lib/app-config.js';
3
+ import { default as swellConfig } from './lib/app-config.js';
3
4
  import { SwellCommand } from './swell-command.js';
4
5
  /**
5
6
  * A base class for Swell CLI commands that do not require an app to be saved
@@ -16,17 +17,17 @@ export class AppCommand extends SwellCommand {
16
17
  // needs to be in a ES2021 format: https://github.com/oclif/oclif/issues/1100
17
18
  static baseFlags = {
18
19
  'app-path': Flags.string({
19
- description: 'path to the app directory',
20
+ description: 'path to your app directory',
20
21
  }),
21
22
  };
22
23
  // local app configuration, what developers define
23
- appConfig;
24
+ swellConfig;
24
25
  // the local path to the app directory
25
26
  appPath = '';
26
27
  constructor(argv, config) {
27
28
  super(argv, config);
28
- this.appConfig = appConfig();
29
- this.appPath = this.appConfig.swDirPath;
29
+ this.swellConfig = swellConfig();
30
+ this.appPath = path.resolve(this.swellConfig.swDirPath);
30
31
  }
31
32
  async init() {
32
33
  await super.init();
@@ -38,8 +39,7 @@ export class AppCommand extends SwellCommand {
38
39
  klass.flags = { ...klass.flags, ...AppCommand.baseFlags };
39
40
  const { flags } = await this.parse(klass);
40
41
  // if the user passed an app path, use it: reload the app config
41
- this.appConfig = appConfig(flags['app-path']);
42
- this.appPath = this.appConfig.swDirPath;
43
- this.debug(`config path loaded: ${this.appConfig.path}`);
42
+ this.swellConfig = swellConfig(flags['app-path']);
43
+ this.appPath = path.resolve(this.swellConfig.swDirPath);
44
44
  }
45
45
  }
@@ -0,0 +1,18 @@
1
+ import { Config } from '@oclif/core';
2
+ import { PushAppCommand } from '../../push-app-command.js';
3
+ export default class AppDev extends PushAppCommand {
4
+ static summary: string;
5
+ static examples: string[];
6
+ static flags: {
7
+ 'storefront-id': import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
8
+ 'storefront-select': import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
9
+ port: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
+ 'no-push': import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
11
+ };
12
+ static orientation: {
13
+ env: string;
14
+ };
15
+ static delayOrientation: boolean;
16
+ constructor(argv: string[], config: Config);
17
+ run(): Promise<void>;
18
+ }
@@ -0,0 +1,31 @@
1
+ import { Flags } from '@oclif/core';
2
+ import { PushAppCommand } from '../../push-app-command.js';
3
+ import AppFrontendDev from './frontend/dev.js';
4
+ export default class AppDev extends PushAppCommand {
5
+ static summary = `Run an app in dev mode from your local machine.`;
6
+ static examples = [
7
+ 'swell app dev',
8
+ 'swell app dev --storefront-id <id>',
9
+ 'swell app dev --port 3000',
10
+ ];
11
+ static flags = {
12
+ ...AppFrontendDev.flags,
13
+ 'storefront-id': Flags.string({
14
+ description: 'for storefront apps, identify a storefront to preview and push theme files to',
15
+ }),
16
+ 'storefront-select': Flags.boolean({
17
+ description: 'for storefront apps, prompt to select a storefront to preview',
18
+ default: false,
19
+ }),
20
+ };
21
+ static orientation = {
22
+ env: 'test',
23
+ };
24
+ static delayOrientation = true;
25
+ constructor(argv, config) {
26
+ super(argv, config);
27
+ }
28
+ async run() {
29
+ await this.config.runCommand('app:frontend:dev', this.argv);
30
+ }
31
+ }
@@ -0,0 +1,17 @@
1
+ import { Config } from '@oclif/core';
2
+ import { PushAppCommand } from '../../../push-app-command.js';
3
+ export default class AppFrontendDeploy extends PushAppCommand {
4
+ static summary: string;
5
+ static description: string;
6
+ static examples: string[];
7
+ static flags: {
8
+ force: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
9
+ 'storefront-id': import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
+ 'storefront-select': import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
11
+ };
12
+ static orientation: {
13
+ env: string;
14
+ };
15
+ constructor(argv: string[], config: Config);
16
+ run(): Promise<void>;
17
+ }
@@ -0,0 +1,44 @@
1
+ import { Flags } from '@oclif/core';
2
+ import { PushAppCommand } from '../../../push-app-command.js';
3
+ export default class AppFrontendDeploy extends PushAppCommand {
4
+ static summary = `Push frontend files to your Swell app.`;
5
+ static description = `Creates a new build using the relevant command depending on your frontend framework.
6
+ Once the build succeeds, this command will invoke Cloudflare Wrangler to upload
7
+ build assets using your own Cloudflare account. Once complete, Swell will update
8
+ the app's deployment URL and push the updated frontend files.`;
9
+ static examples = [
10
+ 'swell app frontend deploy',
11
+ 'swell app frontend deploy --force',
12
+ 'swell app frontend deploy --storefront-select',
13
+ 'swell app frontend deploy --storefront-id <id>',
14
+ ];
15
+ static flags = {
16
+ force: Flags.boolean({
17
+ description: 'force push and build all frontend files',
18
+ }),
19
+ 'storefront-id': Flags.string({
20
+ description: 'identify a storefront to preview deployment with',
21
+ }),
22
+ 'storefront-select': Flags.boolean({
23
+ description: 'prompt to select a storefront to preview deployment with',
24
+ default: false,
25
+ }),
26
+ };
27
+ static orientation = {
28
+ env: 'test',
29
+ };
30
+ constructor(argv, config) {
31
+ super(argv, config);
32
+ }
33
+ async run() {
34
+ const { flags } = await this.parse(AppFrontendDeploy);
35
+ const { force } = flags;
36
+ if (!(await this.ensureAppExists())) {
37
+ return;
38
+ }
39
+ if (this.app.type === 'storefront') {
40
+ await this.getStorefrontToPush(flags);
41
+ }
42
+ await this.deployAppFrontend(force);
43
+ }
44
+ }
@@ -0,0 +1,21 @@
1
+ import { Config } from '@oclif/core';
2
+ import { PushAppCommand } from '../../../push-app-command.js';
3
+ import { FrontendProjectType } from '../../../lib/apps/index.js';
4
+ export default class AppFrontendDev extends PushAppCommand {
5
+ static summary: string;
6
+ static examples: string[];
7
+ static flags: {
8
+ port: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
9
+ 'no-push': import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
10
+ 'storefront-id': import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
+ 'storefront-select': import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
12
+ };
13
+ static orientation: {
14
+ env: string;
15
+ };
16
+ constructor(argv: string[], config: Config);
17
+ run(): Promise<void>;
18
+ startDevServer(projectType: FrontendProjectType, port?: number): Promise<void>;
19
+ updateLocalProxy(proxyUrl: string, spinner: any, storefrontId?: string): Promise<void>;
20
+ logAppLocalUrl(storeId: string, sessionId: string): void;
21
+ }
@@ -0,0 +1,111 @@
1
+ import { Flags } from '@oclif/core';
2
+ import ngrok from 'ngrok';
3
+ import getPort, { portNumbers } from 'get-port';
4
+ import ora from 'ora';
5
+ import { default as localConfig } from '../../../lib/config.js';
6
+ import { PushAppCommand } from '../../../push-app-command.js';
7
+ import style from '../../../lib/style.js';
8
+ const FALLBACK_PORT = 3000;
9
+ export default class AppFrontendDev extends PushAppCommand {
10
+ static summary = `Run a frontend app in dev mode from your local machine.`;
11
+ static examples = [
12
+ 'swell app frontend dev',
13
+ 'swell app frontend dev --no-push',
14
+ 'swell app frontend dev --port 3000',
15
+ 'swell app frontend dev --storefront-select',
16
+ 'swell app frontend dev --storefront-id <id>',
17
+ ];
18
+ static flags = {
19
+ port: Flags.integer({
20
+ char: 'p',
21
+ description: 'override the default port to run the app locally',
22
+ }),
23
+ 'no-push': Flags.boolean({
24
+ description: 'skip pushing app files initially',
25
+ }),
26
+ 'storefront-id': Flags.string({
27
+ description: 'identify a storefront to preview with and push theme files to',
28
+ }),
29
+ 'storefront-select': Flags.boolean({
30
+ description: 'prompt to select a storefront to preview with',
31
+ default: false,
32
+ }),
33
+ };
34
+ static orientation = {
35
+ env: 'test',
36
+ };
37
+ constructor(argv, config) {
38
+ super(argv, config);
39
+ }
40
+ async run() {
41
+ const { flags } = await this.parse(AppFrontendDev);
42
+ const { port } = flags;
43
+ const noPush = flags['no-push'];
44
+ if (!(await this.ensureAppExists(undefined, false))) {
45
+ return;
46
+ }
47
+ if (!noPush) {
48
+ await this.pushAppConfigs();
49
+ }
50
+ if (this.app.type === 'storefront') {
51
+ await this.getStorefrontToPush(flags);
52
+ this.logStorefrontConnected();
53
+ }
54
+ this.saveCurrentStorefront();
55
+ const projectType = this.getFrontendProjectType();
56
+ await this.startDevServer(projectType, port);
57
+ }
58
+ async startDevServer(projectType, port) {
59
+ const currentStore = localConfig.getDefaultStore();
60
+ const spinner = ora();
61
+ // Find an open port starting at 3000
62
+ const freePort = port ||
63
+ (await getPort({ port: portNumbers(3000, 3100) })) ||
64
+ FALLBACK_PORT;
65
+ this.log(`Starting ${projectType.name} dev server...\n`);
66
+ // Start ngrok proxy
67
+ const proxyUrl = await ngrok.connect({
68
+ addr: freePort,
69
+ region: 'us', // TODO: make it configurable
70
+ });
71
+ await this.updateLocalProxy(proxyUrl, spinner, this.storefront?.id);
72
+ return this.exec(projectType.devCommand.replace('${PORT}', String(freePort)), (string) => {
73
+ // Hide useless astro warning about image optimization
74
+ if (string.includes('The current configuration does not support image optimization')) {
75
+ return false;
76
+ }
77
+ // Hide useless astro warning about .dev.vars
78
+ if (string.includes('There is no `.dev.vars` file')) {
79
+ return false;
80
+ }
81
+ // Hide astro localhost URL/network as it can confuse the user
82
+ if (string.includes('┃ Local') || string.includes('┃ Network')) {
83
+ return false;
84
+ }
85
+ // Started, show app url (TODO for nextjs)
86
+ if (string.includes('watching for file changes')) {
87
+ spinner.succeed(`Started ${projectType.name} dev server on port ${freePort}.\n`);
88
+ const sessionId = localConfig.getSessionId(currentStore);
89
+ setTimeout(() => this.logAppLocalUrl(currentStore, sessionId), 100);
90
+ this.watchForChanges();
91
+ }
92
+ });
93
+ }
94
+ async updateLocalProxy(proxyUrl, spinner, storefrontId) {
95
+ const storefront = this.app.type === 'storefront' &&
96
+ (await this.getAppStorefront({ storefront_id: storefrontId }));
97
+ await this.handleRequestErrors(async () => this.api.put({ adminPath: `/client/apps/${this.app.id}/local-proxy` }, {
98
+ body: {
99
+ proxy_url: proxyUrl,
100
+ storefront_id: storefront?.id || null,
101
+ storefront_slug: storefront?.slug || null,
102
+ },
103
+ }), () => spinner.fail('Error starting local proxy'));
104
+ }
105
+ logAppLocalUrl(storeId, sessionId) {
106
+ const frontendAppRoute = this.app.type === 'storefront' && this.app.storefront?.external
107
+ ? `/${this.app.private_id}`
108
+ : '';
109
+ this.log(`View it at ${style.link(`${this.localFrontendUrl(storeId, sessionId)}${frontendAppRoute}`)}\n`);
110
+ }
111
+ }
@@ -13,7 +13,6 @@ const FIELDS_TO_DISPLAY = [
13
13
  'published',
14
14
  'date_created',
15
15
  'date_updated',
16
- 'installed',
17
16
  'client',
18
17
  ];
19
18
  export default class AppInfo extends RemoteAppCommand {
@@ -46,25 +45,33 @@ it will output all versions of the app instead.`;
46
45
  async showAppInfo() {
47
46
  const spinner = ora();
48
47
  spinner.start('Retrieving app info...');
49
- this.app = await this.getAppWithConfig().catch((error) => {
50
- spinner.fail(`Error fetching app info:`);
51
- throw error;
48
+ const app = await this.getAppWithConfig().catch((error) => {
49
+ return null;
52
50
  });
51
+ this.app = app || this.swellConfig.store;
52
+ if (!this.app) {
53
+ spinner.fail('App not found');
54
+ return;
55
+ }
53
56
  if (spinner.isSpinning) {
54
57
  spinner.stop();
55
58
  }
56
59
  // we pull versions to make sure that what is displayed is the latest
57
- const versions = await this.getVersions();
60
+ const versions = app ? await this.getVersions() : [];
58
61
  // Output the app field information, e.g.:
59
62
  // Name: My App
60
63
  const fieldDefinitions = new FieldDefinitions(this.app, versions);
61
64
  for (const field of FIELDS_TO_DISPLAY) {
62
65
  const fieldDef = fieldDefinitions.getFieldDefinition(field);
63
- this.log(style.appConfigName(`${fieldDef.label}:`), fieldDef.value);
66
+ if (fieldDef.value) {
67
+ this.log(style.appConfigName(`${fieldDef.label}:`), fieldDef.value);
68
+ }
64
69
  }
65
70
  // dashboard url is built, not part of the app object
66
71
  // we display it at the end for better readability and simplicity
67
- this.log(style.appConfigName('Dashboard:'), style.link(this.dashboardUrl({}, this.app.client_id)));
72
+ if (this.app.client_id) {
73
+ this.log(style.appConfigName('Dashboard:'), style.link(this.dashboardUrl({}, this.app.client_id)));
74
+ }
68
75
  }
69
76
  async showVersions() {
70
77
  const spinner = ora();
@@ -81,7 +88,7 @@ it will output all versions of the app instead.`;
81
88
  spinner.succeed(`${this.app.name} app versions:\n`);
82
89
  const displayData = versions.map((appVersion) => [
83
90
  style.appConfigValue(appVersion.version),
84
- appVersion.notes,
91
+ appVersion.description,
85
92
  new Date(appVersion.date_created).toUTCString(),
86
93
  ]);
87
94
  this.log(table(displayData, {
@@ -0,0 +1,12 @@
1
+ import CreateApp from '../create/app.js';
2
+ export default class InitApp extends CreateApp {
3
+ static description: string;
4
+ static examples: {
5
+ command: string;
6
+ description: string;
7
+ }[];
8
+ static flags: {
9
+ yes: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
10
+ };
11
+ run(): Promise<void>;
12
+ }
@@ -0,0 +1,34 @@
1
+ import { Flags } from '@oclif/core';
2
+ import path from 'node:path';
3
+ import CreateApp from '../create/app.js';
4
+ export default class InitApp extends CreateApp {
5
+ static description = 'Initialize app swell.json in the current directory.';
6
+ static examples = [
7
+ {
8
+ command: 'swell app init',
9
+ description: 'Initialize app following command prompts.',
10
+ },
11
+ {
12
+ command: 'swell app init -y',
13
+ description: 'Initialize app and accept all default values.',
14
+ },
15
+ ];
16
+ static flags = {
17
+ yes: Flags.boolean({
18
+ char: 'y',
19
+ description: `accept all default values`,
20
+ }),
21
+ };
22
+ async run() {
23
+ const { flags } = await this.parse(InitApp);
24
+ const { yes: confirmYes } = flags;
25
+ const id = process.cwd().split(path.sep).pop() || 'Swell App';
26
+ await this.createSwellConfig({
27
+ inputId: id,
28
+ inputYes: confirmYes,
29
+ inputType: this.appType,
30
+ allowOverwrite: false,
31
+ nestedPath: false,
32
+ });
33
+ }
34
+ }
@@ -7,11 +7,11 @@ export default class AppInstall extends RemoteAppCommand {
7
7
  store: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
8
8
  version: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
9
9
  };
10
+ static orientation: {
11
+ env: string;
12
+ };
10
13
  static summary: string;
11
14
  run(): Promise<void>;
12
- private installApp;
13
- private installConfirmationMessage;
14
- private updateApp;
15
- private getInstalledApp;
16
15
  private confirmRemoveDevelopmentApp;
16
+ private installConfirmationMessage;
17
17
  }
@@ -1,19 +1,19 @@
1
1
  import { confirm } from '@inquirer/prompts';
2
2
  import { Flags } from '@oclif/core';
3
- import * as semver from 'semver';
4
3
  import ora from 'ora';
4
+ import * as semver from 'semver';
5
5
  import config from '../../lib/config.js';
6
+ import { selectEnvironmentId, selectLoggedInStoreId, } from '../../lib/stores.js';
6
7
  import style from '../../lib/style.js';
7
- import { selectLoggedInStoreId, selectEnvironmentId, } from '../../lib/stores.js';
8
8
  import { RemoteAppCommand } from '../../remote-app-command.js';
9
9
  export default class AppInstall extends RemoteAppCommand {
10
10
  static description = `Without a version specified, install the latest version of the app.
11
11
 
12
12
  Without a store specified, install the app in the Live environment of the current store.`;
13
13
  static examples = [
14
- 'swell install',
15
- 'swell install -v 3.2.7',
16
- 'swell install -v 1.0.0 -s my-store-id',
14
+ 'swell app install',
15
+ 'swell app install -v 3.2.7',
16
+ 'swell app install -v 1.0.0 -s my-store-id',
17
17
  ];
18
18
  static flags = {
19
19
  env: Flags.string({
@@ -35,6 +35,9 @@ Without a store specified, install the app in the Live environment of the curren
35
35
  },
36
36
  }),
37
37
  };
38
+ static orientation = {
39
+ env: 'test',
40
+ };
38
41
  static summary = 'Install an existing app in another store environment.';
39
42
  async run() {
40
43
  const { flags } = await this.parse(AppInstall);
@@ -91,7 +94,7 @@ Without a store specified, install the app in the Live environment of the curren
91
94
  }
92
95
  }
93
96
  else {
94
- extraMessage = ` ${style.appConfigValue(this.app.name)} v${versionToInstall} on ${style.storeId(storeToInstall)} [${envToInstall ? envToInstall : 'live'}]`;
97
+ extraMessage = ` ${style.appConfigValue(this.app.name)} v${versionToInstall} on ${style.storeId(storeToInstall)} [${envToInstall || 'live'}]`;
95
98
  }
96
99
  const shouldContinue = existingVersion ||
97
100
  (await this.confirmRemoveDevelopmentApp(storeToInstall));
@@ -99,60 +102,35 @@ Without a store specified, install the app in the Live environment of the curren
99
102
  return;
100
103
  }
101
104
  const spinner = ora();
105
+ this.log();
102
106
  // install or update app depending on whether it's already installed
103
107
  let request;
104
108
  if (existingInstalledApp?.id) {
105
- spinner.start(`Updating${extraMessage}...`);
106
- request = async () => this.updateApp(versionToInstall, envToInstall);
109
+ spinner.start(`Updating${extraMessage}`);
110
+ request = async () => this.updateInstalledApp(versionToInstall, spinner);
107
111
  }
108
112
  else {
109
- spinner.start(`Installing${extraMessage}...`);
110
- request = async () => this.installApp(versionToInstall, envToInstall);
113
+ spinner.start(`Installing${extraMessage}`);
114
+ request = async () => this.installApp(versionToInstall, spinner);
111
115
  }
112
116
  const response = await this.handleRequestErrors(request, () => spinner.fail('Something went wrong.'));
113
117
  if (response?.errors) {
114
118
  spinner.fail(`Error installing app: ${JSON.stringify(response.errors)}`);
115
119
  }
116
- spinner.succeed(`Install complete. Manage app settings in your dashboard at ${style.link(this.dashboardUrl({ flags: { env: envToInstall } }, storeToInstall))}.`);
117
- }
118
- async installApp(version, env) {
119
- return this.api.post({ adminPath: `/client/apps` },
120
- // eslint-disable-next-line camelcase
121
- { body: { app_id: this.app.id, version } });
122
- }
123
- installConfirmationMessage(storeToInstall, envToInstall, versionToInstall, existingVersion) {
124
- const message = [];
125
- if (existingVersion && semver.gt(versionToInstall, existingVersion)) {
126
- message.push('Updating');
127
- }
128
- else if (existingVersion &&
129
- semver.lt(versionToInstall, existingVersion)) {
130
- message.push('Rolling back');
131
- }
132
120
  else {
133
- message.push('Install');
121
+ spinner.succeed(`${existingInstalledApp?.id ? 'Update' : 'Install'} complete.\n`);
122
+ this.log(`Manage app settings in your dashboard at ${style.link(this.dashboardUrl({ flags: { env: envToInstall } }, storeToInstall))}.`);
134
123
  }
135
- let versionToShow = versionToInstall;
136
- versionToShow += versionToInstall === this.app.version ? ' (latest)' : '';
137
- message.push(style.appConfigValue(this.app.name), `v${versionToShow}`, `on ${style.storeId(storeToInstall)} [${envToInstall ? envToInstall : 'live'}]?`);
138
- return message.join(' ');
139
- }
140
- async updateApp(version, env) {
141
- await this.api.put({ adminPath: `/client/apps/${this.app.id}` }, { body: { version } });
142
- }
143
- async getInstalledApp() {
144
- // check if app is already installed on store
145
- return await this.api.get({ adminPath: `/client/apps/${this.app.id}` }, {});
146
124
  }
147
125
  async confirmRemoveDevelopmentApp(storeToInstall) {
148
126
  const existingSourcedApps = await this.api.get({ adminPath: `/client/apps` }, {
127
+ // eslint-disable-next-line camelcase
149
128
  query: { source_id: this.app.id },
150
129
  });
151
130
  if (existingSourcedApps.results[0]?.id) {
152
- console.log(existingSourcedApps.results[0]);
153
131
  const continueInstall = await confirm({
154
- message: `${style.storeId(storeToInstall)} has a development version of ${style.appConfigValue(this.app.name)}. Do you want to replace it with an installed instance?`,
155
132
  default: false,
133
+ message: `${style.storeId(storeToInstall)} has a development version of ${style.appConfigValue(this.app.name)}. Do you want to replace it with an installed instance?`,
156
134
  });
157
135
  if (!continueInstall) {
158
136
  return false;
@@ -168,12 +146,29 @@ Without a store specified, install the app in the Live environment of the curren
168
146
  });
169
147
  spinner.succeed('Development app removed.');
170
148
  }
171
- catch (err) {
149
+ catch (error) {
172
150
  spinner.fail(`Error removing development app from ${style.storeId(storeToInstall)}.`);
173
- this.logError(err.message);
151
+ this.logError(error.message);
174
152
  return false;
175
153
  }
176
154
  }
177
155
  return true;
178
156
  }
157
+ installConfirmationMessage(storeToInstall, envToInstall, versionToInstall, existingVersion) {
158
+ const message = [];
159
+ if (existingVersion && semver.gt(versionToInstall, existingVersion)) {
160
+ message.push('Updating');
161
+ }
162
+ else if (existingVersion &&
163
+ semver.lt(versionToInstall, existingVersion)) {
164
+ message.push('Rolling back');
165
+ }
166
+ else {
167
+ message.push('Install');
168
+ }
169
+ let versionToShow = versionToInstall;
170
+ versionToShow += versionToInstall === this.app.version ? ' (latest)' : '';
171
+ message.push(style.appConfigValue(this.app.name), `v${versionToShow}`, `on ${style.storeId(storeToInstall)} [${envToInstall || 'live'}]?`);
172
+ return message.join(' ');
173
+ }
179
174
  }
@@ -0,0 +1,15 @@
1
+ import { PushAppCommand } from '../../push-app-command.js';
2
+ export default class AppPull extends PushAppCommand {
3
+ static args: {
4
+ appId: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
5
+ targetPath: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
6
+ };
7
+ static flags: {
8
+ force: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
9
+ };
10
+ static summary: string;
11
+ static description: string;
12
+ static examples: string[];
13
+ run(): Promise<void>;
14
+ logPulledChanges(pulled: string[], removed: string[]): void;
15
+ }
@@ -0,0 +1,50 @@
1
+ import * as path from 'node:path';
2
+ import { Args, Flags } from '@oclif/core';
3
+ import { ConfigPaths, } from '../../lib/apps/index.js';
4
+ import style from '../../lib/style.js';
5
+ import { PushAppCommand } from '../../push-app-command.js';
6
+ export default class AppPull extends PushAppCommand {
7
+ static args = {
8
+ appId: Args.string({ default: '', description: 'app id to pull' }),
9
+ targetPath: Args.string({
10
+ default: '',
11
+ description: 'path to download app files into',
12
+ }),
13
+ };
14
+ static flags = {
15
+ force: Flags.boolean({
16
+ description: 'force pull all files',
17
+ default: false,
18
+ }),
19
+ };
20
+ static summary = 'Pull app files from Swell to your local machine.';
21
+ static description = `Pull all app files, a specific file, or a specific configuration
22
+ type from an app in your store's test environment to your local machine.
23
+
24
+ If APPID is not specified, you will be prompted with a list of apps to choose from.
25
+
26
+ App file directories:
27
+ ${Object.values(ConfigPaths)
28
+ .map((dir) => style.path(`${dir}/`))
29
+ .join('\n')}\n${style.path(`frontend/`)}`;
30
+ static examples = [
31
+ 'swell app pull',
32
+ 'swell app pull example_app',
33
+ 'swell app pull example_app example-folder',
34
+ 'swell app pull --force',
35
+ ];
36
+ async run() {
37
+ const { args, flags } = await this.parse(AppPull);
38
+ const { force } = flags;
39
+ await this.ensureLoggedIn();
40
+ this.app = await this.getAppToPull(args);
41
+ const { pulled, removed } = await this.pullAppConfigs(force);
42
+ this.logPulledChanges(pulled, removed);
43
+ }
44
+ logPulledChanges(pulled, removed) {
45
+ const typeLabel = this.appType === 'theme' ? 'theme' : 'app';
46
+ const changeCount = pulled.length + removed.length;
47
+ const pluralFiles = changeCount !== 1 ? 'files' : 'file';
48
+ this.log(`Pulled ${changeCount} ${pluralFiles} from ${style.appConfigValue(this.app.name)} ${typeLabel} in ${style.path(path.resolve(this.appPath))}.`);
49
+ }
50
+ }