@swell/cli 2.0.19 → 2.0.20

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.
@@ -3,6 +3,7 @@ import { Flags } from '@oclif/core';
3
3
  import ora from 'ora';
4
4
  import * as semver from 'semver';
5
5
  import config from '../../lib/config.js';
6
+ import { readRcFile } from '../../lib/app-config.js';
6
7
  import { selectEnvironmentId, selectLoggedInStoreId, } from '../../lib/stores.js';
7
8
  import style from '../../lib/style.js';
8
9
  import { RemoteAppCommand } from '../../remote-app-command.js';
@@ -123,10 +124,20 @@ Without a store specified, install the app in the Live environment of the curren
123
124
  }
124
125
  }
125
126
  async confirmRemoveDevelopmentApp(storeToInstall) {
126
- const existingSourcedApps = await this.api.get({ adminPath: `/client/apps` }, {
127
- query: { source_id: this.app.id },
128
- });
129
- if (existingSourcedApps.results[0]?.id) {
127
+ let sourceAppId;
128
+ try {
129
+ const sourceApp = await readRcFile(this.swellRcPath());
130
+ sourceAppId = sourceApp?.id;
131
+ }
132
+ catch (error) {
133
+ // noop
134
+ }
135
+ const existingSourcedApps = sourceAppId
136
+ ? await this.api.get({ adminPath: `/client/apps` }, {
137
+ query: { source_id: sourceAppId },
138
+ })
139
+ : null;
140
+ if (existingSourcedApps?.results[0]?.id) {
130
141
  const continueInstall = await confirm({
131
142
  default: false,
132
143
  message: `${style.storeId(storeToInstall)} has a development version of ${style.appConfigValue(this.app.name)}. Do you want to replace it with an installed instance?`,
@@ -194,9 +194,29 @@ export class RemoteAppCommand extends AppCommand {
194
194
  const appLabel = this.app.type === 'theme' ? 'theme' : 'app';
195
195
  let app = updateApp || {};
196
196
  if (!app.id) {
197
+ // May already have a dev instance
198
+ let existingDevApp;
199
+ try {
200
+ existingDevApp = await this.api.get({
201
+ adminPath: `/apps/${this.swellConfig.store.id}`,
202
+ });
203
+ // Check if existing dev app is owned by the current store
204
+ const currentStore = localConfig.getDefaultStore();
205
+ if (existingDevApp?.client_id !== currentStore) {
206
+ existingDevApp = null;
207
+ }
208
+ }
209
+ catch {
210
+ // noop
211
+ }
197
212
  spinner.start(`Creating ${appLabel}...`);
198
- app = await this.handleRequestErrors(async () => this.api.post({ adminPath: '/apps' }, { body }), () => spinner.fail('Error creating app.'));
199
- this.appCreated = true;
213
+ if (existingDevApp) {
214
+ app = await this.handleRequestErrors(async () => this.api.put({ adminPath: `/apps/${existingDevApp.id}` }, { body }), () => spinner.fail('Error updating app.'));
215
+ }
216
+ else {
217
+ app = await this.handleRequestErrors(async () => this.api.post({ adminPath: '/apps' }, { body }), () => spinner.fail('Error creating app.'));
218
+ this.appCreated = true;
219
+ }
200
220
  }
201
221
  else if (app.id) {
202
222
  spinner.start(`Updating ${appLabel}...`);
@@ -296,7 +316,7 @@ export class RemoteAppCommand extends AppCommand {
296
316
  return this.api.post({ adminPath: `/client/apps` }, {
297
317
  body: { app_id: this.app.id, version },
298
318
  onAsyncGetPath: (response) => ({
299
- adminPath: `/client/app-async-status/${response.id}`,
319
+ adminPath: `/client/app-async-status/${response.app_id}`,
300
320
  }),
301
321
  spinner,
302
322
  });
@@ -584,7 +604,7 @@ export class RemoteAppCommand extends AppCommand {
584
604
  await this.api.put({ adminPath: `/client/apps/${this.app.id}` }, {
585
605
  body: { version },
586
606
  onAsyncGetPath: (response) => ({
587
- adminPath: `/client/app-async-status/${response.id}`,
607
+ adminPath: `/client/app-async-status/${response.app_id}`,
588
608
  }),
589
609
  spinner,
590
610
  });
@@ -1891,5 +1891,5 @@
1891
1891
  ]
1892
1892
  }
1893
1893
  },
1894
- "version": "2.0.19"
1894
+ "version": "2.0.20"
1895
1895
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swell/cli",
3
- "version": "2.0.19",
3
+ "version": "2.0.20",
4
4
  "type": "module",
5
5
  "description": "Swell's command line interface/utility",
6
6
  "keywords": [