@swell/cli 2.0.1-alpha.3 → 2.0.1-alpha.5

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.
@@ -1,9 +1,9 @@
1
1
  import { Args } from '@oclif/core';
2
2
  import { dasherize, pluralize, underscore } from 'inflection';
3
- import snakeCase from 'lodash/snakeCase.js';
4
3
  import * as path from 'node:path';
5
4
  import { newConfig } from '../../lib/app-config.js';
6
5
  import { ConfigPaths, writeJsonFile, } from '../../lib/apps/index.js';
6
+ import { toAppId } from '../../lib/create/index.js';
7
7
  import style from '../../lib/style.js';
8
8
  import { RemoteAppCommand } from '../../remote-app-command.js';
9
9
  export default class AppPull extends RemoteAppCommand {
@@ -25,7 +25,7 @@ export default class AppPull extends RemoteAppCommand {
25
25
  const config = newConfig();
26
26
  const appConfigJson = {
27
27
  description: this.app.description || '',
28
- id: snakeCase(this.app.name),
28
+ id: toAppId(this.app.name),
29
29
  name: this.app.name,
30
30
  version: this.app.version,
31
31
  };
@@ -41,16 +41,19 @@ ${Object.values(ConfigPaths)
41
41
  const { file } = flags;
42
42
  const currentStore = swellConfig.getDefaultStore();
43
43
  this.api.setStoreEnv(currentStore, 'test');
44
- this.app = await this.getAppWithConfig(undefined, false);
44
+ this.app = await this.getAppWithConfig('', false);
45
45
  const confirmExistingApp = await this.confirmRemoveInstalledApp(currentStore);
46
46
  if (confirmExistingApp === false) {
47
47
  return;
48
48
  }
49
49
  // If app exists but owned by another client, offer to create a new instance
50
- if (this.app.client_id !== currentStore) {
50
+ if (this.app.client_id && this.app.client_id !== currentStore) {
51
51
  if (!confirmExistingApp?.id) {
52
+ const otherAppName = this.app.name || this.appConfig.get('name');
52
53
  const confirmPushNew = await confirm({
53
- message: `${style.appConfigValue(this.app.name)} has a dev version in another store (${style.storeId(this.app.client_id)}). Do you want to create a new development instance in ${style.storeId(currentStore)}?`,
54
+ message: `${style.appConfigValue(otherAppName)} has a dev version in another ${this.app.client_id
55
+ ? `store ${style.dim(`(${this.app.client_id})`)}`
56
+ : 'environment'}. Do you want to create a new development instance in ${style.storeId(currentStore)}?`,
54
57
  default: false,
55
58
  });
56
59
  if (!confirmPushNew) {
@@ -5,7 +5,7 @@ interface CreateFileParams {
5
5
  }
6
6
  declare const toFileName: (value: string) => string;
7
7
  declare const toAppName: (value: string) => string;
8
- declare const toAppId: (value: string) => string;
8
+ declare const toAppId: (value: string | undefined) => string;
9
9
  declare const toFunctionFileName: (value: string) => string;
10
10
  declare const toCollectionName: (value: string) => string;
11
11
  declare const toCollectionLabel: (value: string) => string;
@@ -4,9 +4,11 @@ const toFileName = (value) => dasherize(underscore(value.split('.')[0].replace('
4
4
  // Example: 'my-things' => 'My Things'
5
5
  const toAppName = (value) => pluralize(titleize(value).replace('-', ' '));
6
6
  // Example: 'My App' => 'my_app'
7
- const toAppId = (value) => value
8
- .replace(/[^a-z0-9]+/gi, '_')
9
- .replace(/^\_|\_$/g, '')
7
+ const toAppId = (value) => String(value || '')
8
+ .replace(/[^a-zA-Z0-9\-_\s:\.\/]/g, '')
9
+ .replace(/[_\s-:\.\/]+/g, '_')
10
+ .replace(/^[_]+|[_]+$/g, '')
11
+ .replace(/([a-z])([A-Z])/g, '$1_$2')
10
12
  .toLowerCase();
11
13
  // Example: 'My Thing' => 'my-thing'
12
14
  // And: 'myThing' => 'myThing'
@@ -1,11 +1,11 @@
1
1
  import { inflect } from 'inflection';
2
- import snakeCase from 'lodash/snakeCase.js';
3
2
  import * as fs from 'node:fs';
4
3
  import * as path from 'node:path';
5
4
  import ora from 'ora';
6
5
  import { AppCommand } from './app-command.js';
7
6
  import { appConfigFileExists, readRcFile, writeRcFile, } from './lib/app-config.js';
8
7
  import { FunctionProcessingError, IgnoringFileError, allConfigFilesPaths, appConfigFromFile, appLogoIcon, batchAppConfigsByType, configFilePath, isAppLogoIcon, } from './lib/apps/index.js';
8
+ import { toAppId } from './lib/create/index.js';
9
9
  import { default as swellConfig } from './lib/config.js';
10
10
  import { getLoginHost } from './lib/constants.js';
11
11
  import style from './lib/style.js';
@@ -64,7 +64,7 @@ export class RemoteAppCommand extends AppCommand {
64
64
  this.error(`App ${style.appConfigName('id')} is not defined in swell.json.`);
65
65
  }
66
66
  if (privateId !== appConfigId) {
67
- this.error(`App ${style.appConfigName('id')} must be defined in snake_case: ${style.appConfigValue(appConfigId)}.`);
67
+ this.error(`App ${style.appConfigName('id')} must be declared in snake_case: ${style.appConfigValue(appConfigId)}.`);
68
68
  }
69
69
  appId = privateId;
70
70
  }
@@ -97,7 +97,7 @@ export class RemoteAppCommand extends AppCommand {
97
97
  : errorJson.error.message;
98
98
  this.error(errorMessage);
99
99
  }
100
- if (swellId) {
100
+ if (swellId && swellId !== id && swellId !== this.app?.id) {
101
101
  app = await this.getAppWithConfig(swellId);
102
102
  }
103
103
  }
@@ -113,7 +113,9 @@ export class RemoteAppCommand extends AppCommand {
113
113
  // when posting to the API
114
114
  id: undefined,
115
115
  logo_icon: null,
116
- private_id: this.app?.private_id,
116
+ ...(this.appConfig.store.id
117
+ ? { private_id: this.appConfig.store.id }
118
+ : undefined),
117
119
  ...(remoteApp?.id ? { source_id: remoteApp.id } : undefined),
118
120
  };
119
121
  const logoIcon = appLogoIcon(this.appPath);
@@ -126,9 +128,15 @@ export class RemoteAppCommand extends AppCommand {
126
128
  let appCreated = false;
127
129
  if (!app.id) {
128
130
  // May already have a dev instance
129
- const existingDevApp = await this.api.get({
130
- adminPath: `/apps/${this.app?.private_id}`,
131
- });
131
+ let existingDevApp;
132
+ try {
133
+ existingDevApp = await this.api.get({
134
+ adminPath: `/apps/${this.appConfig.store.id}`,
135
+ });
136
+ }
137
+ catch (err) {
138
+ // noop
139
+ }
132
140
  spinner.start(`Creating app...`);
133
141
  if (existingDevApp) {
134
142
  app = await this.handleRequestErrors(async () => this.api.put({ adminPath: `/apps/${existingDevApp.id}` }, { body }), () => spinner.fail('Error creating app'));
@@ -327,8 +335,9 @@ export class RemoteAppCommand extends AppCommand {
327
335
  }
328
336
  }
329
337
  if (this.appConfig.get('id')) {
338
+ // use the same formula as the backend api
330
339
  // eslint-disable-next-line camelcase
331
- remoteApp.private_id = snakeCase(this.appConfig.get('id'));
340
+ remoteApp.private_id = toAppId(this.appConfig.get('id'));
332
341
  }
333
342
  return remoteApp;
334
343
  }
@@ -1081,5 +1081,5 @@
1081
1081
  ]
1082
1082
  }
1083
1083
  },
1084
- "version": "2.0.1-alpha.3"
1084
+ "version": "2.0.1-alpha.5"
1085
1085
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swell/cli",
3
- "version": "2.0.1-alpha.3",
3
+ "version": "2.0.1-alpha.5",
4
4
  "type": "module",
5
5
  "description": "Swell's command line interface/utility",
6
6
  "keywords": [