@swell/cli 2.0.1-alpha.9 → 2.0.2

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 (102) 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 +4 -4
  13. package/dist/commands/app/install.js +36 -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 +64 -138
  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 +63 -42
  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 +143 -137
  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 +38 -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/env.d.ts +12 -0
  37. package/dist/commands/env.js +31 -0
  38. package/dist/commands/login.d.ts +1 -1
  39. package/dist/commands/login.js +18 -24
  40. package/dist/commands/logs.js +0 -1
  41. package/dist/commands/theme/dev.d.ts +21 -0
  42. package/dist/commands/theme/dev.js +164 -0
  43. package/dist/commands/theme/init.d.ts +9 -0
  44. package/dist/commands/theme/init.js +15 -0
  45. package/dist/commands/theme/pull.d.ts +20 -0
  46. package/dist/commands/theme/pull.js +65 -0
  47. package/dist/commands/theme/push.d.ts +19 -0
  48. package/dist/commands/theme/push.js +89 -0
  49. package/dist/create-app-command.d.ts +20 -0
  50. package/dist/create-app-command.js +253 -0
  51. package/dist/create-collection-command.d.ts +9 -9
  52. package/dist/create-collection-command.js +23 -23
  53. package/dist/{create-command.d.ts → create-config-command.d.ts} +1 -1
  54. package/dist/{create-command.js → create-config-command.js} +7 -7
  55. package/dist/env/local.d.ts +8 -0
  56. package/dist/env/local.js +7 -0
  57. package/dist/env/production.d.ts +8 -0
  58. package/dist/env/production.js +7 -0
  59. package/dist/env/review.d.ts +8 -0
  60. package/dist/env/review.js +7 -0
  61. package/dist/env/staging.d.ts +8 -0
  62. package/dist/env/staging.js +7 -0
  63. package/dist/lib/api.d.ts +4 -2
  64. package/dist/lib/api.js +50 -21
  65. package/dist/lib/app-config.d.ts +13 -5
  66. package/dist/lib/app-config.js +62 -24
  67. package/dist/lib/apps/app-config.d.ts +17 -3
  68. package/dist/lib/apps/app-config.js +194 -66
  69. package/dist/lib/apps/index.d.ts +93 -12
  70. package/dist/lib/apps/index.js +155 -50
  71. package/dist/lib/apps/paths.d.ts +14 -7
  72. package/dist/lib/apps/paths.js +73 -28
  73. package/dist/lib/bundle.js +15 -3
  74. package/dist/lib/config.d.ts +9 -2
  75. package/dist/lib/config.js +49 -1
  76. package/dist/lib/constants.d.ts +5 -0
  77. package/dist/lib/constants.js +24 -6
  78. package/dist/lib/create/content.d.ts +2 -2
  79. package/dist/lib/create/content.js +1 -1
  80. package/dist/lib/create/function.d.ts +2 -2
  81. package/dist/lib/create/function.js +2 -2
  82. package/dist/lib/create/index.d.ts +1 -1
  83. package/dist/lib/create/index.js +11 -7
  84. package/dist/lib/create/model.d.ts +2 -2
  85. package/dist/lib/create/notification.d.ts +2 -2
  86. package/dist/lib/info.js +2 -2
  87. package/dist/lib/logs/index.js +1 -1
  88. package/dist/lib/sessions.js +2 -2
  89. package/dist/lib/stores.d.ts +9 -4
  90. package/dist/lib/stores.js +13 -8
  91. package/dist/lib/style.d.ts +2 -0
  92. package/dist/lib/style.js +2 -0
  93. package/dist/lib/swell-function-wrapper.d.ts +40 -1
  94. package/dist/lib/swell-function-wrapper.js +107 -22
  95. package/dist/push-app-command.d.ts +73 -0
  96. package/dist/push-app-command.js +743 -0
  97. package/dist/remote-app-command.d.ts +37 -11
  98. package/dist/remote-app-command.js +432 -169
  99. package/oclif.manifest.json +872 -123
  100. package/package.json +14 -1
  101. package/dist/commands/app/_pull.d.ts +0 -8
  102. package/dist/commands/app/_pull.js +0 -45
@@ -1,11 +1,6 @@
1
1
  import { Flags } from '@oclif/core';
2
- import * as fs from 'node:fs';
3
- import * as path from 'node:path';
4
- import { appConfigFileExists } from '../../lib/app-config.js';
5
- import { appConfigFromFile, findAppConfig, getConfigTypeFromPath, hasAllowedFileExtension, } from '../../lib/apps/index.js';
6
- import style from '../../lib/style.js';
7
- import { RemoteAppCommand } from '../../remote-app-command.js';
8
- export default class AppWatch extends RemoteAppCommand {
2
+ import { PushAppCommand } from '../../push-app-command.js';
3
+ export default class AppWatch extends PushAppCommand {
9
4
  static description = `Watches configuration files including functions, and automatically pushes
10
5
  to the remote store.
11
6
 
@@ -26,85 +21,10 @@ Optionally synchronize all configs on change.`;
26
21
  env: 'test',
27
22
  };
28
23
  static summary = 'Watch for changes and push app configurations.';
29
- watchListener = async (eventType, filename) => {
30
- const configFile = filename;
31
- const pathParsed = path.parse(configFile);
32
- const fileDirs = pathParsed.dir.split(path.sep);
33
- // only the first directory is relevant for us
34
- const configDir = fileDirs[0];
35
- // we only want to watch files in the root of the app directory
36
- // and with the allowed extensions
37
- if (!configDir ||
38
- fileDirs.length > 1 ||
39
- !hasAllowedFileExtension(configFile)) {
40
- return;
41
- }
42
- const configType = getConfigTypeFromPath(configDir);
43
- if (!configType) {
44
- this.debug(`watchListener: ${filename} is not a valid config type`);
45
- return;
46
- }
47
- let watchFileEvent;
48
- // per node docs:
49
- //
50
- // On most platforms, 'rename' is emitted whenever a filename appears
51
- // or disappears in the directory.
52
- //
53
- // we want however to identify delete file events so we can send the
54
- // correct API request
55
- if (eventType === 'rename') {
56
- watchFileEvent = 'new';
57
- if (!appConfigFileExists(path.join(this.appPath, configFile))) {
58
- watchFileEvent = 'deleted';
59
- }
60
- }
61
- else {
62
- watchFileEvent = 'change';
63
- }
64
- try {
65
- await this.handleFileChange(configFile, configType, watchFileEvent);
66
- }
67
- catch (error) {
68
- // we don't want to break the watcher if an error is thrown while
69
- // handling a file change
70
- this.debug(error);
71
- // for tests though, we want to break the watcher
72
- if (process.env.NODE_ENV === 'test') {
73
- // throwing does not break the test so we need to hard exit and log
74
- // the error
75
- console.error(style.error(error));
76
- // eslint-disable-next-line no-process-exit, unicorn/no-process-exit
77
- process.exit(1);
78
- }
79
- }
80
- // refetch app to get updated configs
81
- this.app = await this.getAppWithConfig(this.app.id);
82
- };
83
24
  async run() {
84
25
  const { flags } = await this.parse(AppWatch);
85
26
  this.app = await this.getAppWithConfig();
86
27
  this.log('Watching for changes...');
87
- if (flags['sync-all']) {
88
- await this.syncAppConfigs();
89
- fs.watch(this.appPath, { recursive: true }, async (eventType, filename) => {
90
- if (filename && hasAllowedFileExtension(filename)) {
91
- await this.syncAppConfigs();
92
- }
93
- });
94
- return;
95
- }
96
- fs.watch(this.appPath, { recursive: true }, this.watchListener);
97
- }
98
- async handleFileChange(configFile, configType, event) {
99
- if (event === 'deleted') {
100
- const appConfig = findAppConfig(this.app, configFile, configType);
101
- if (!appConfig) {
102
- return;
103
- }
104
- return this.removeConfig(appConfig);
105
- }
106
- const appConfig = appConfigFromFile(path.join(this.appPath, configFile), configType);
107
- const result = await this.pushConfigFile(appConfig);
108
- this.debug(`handleFileChange: ${configFile} pushed`, result);
28
+ await this.watchForChanges({ syncAll: flags['sync-all'] });
109
29
  }
110
30
  }
@@ -1,21 +1,45 @@
1
- import { SwellCommand } from '../../swell-command.js';
2
- export default class CreateApp extends SwellCommand {
1
+ import { CreateAppCommand } from '../../create-app-command.js';
2
+ export default class CreateApp extends CreateAppCommand {
3
3
  static args: {
4
4
  id: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
5
5
  };
6
- static flags: {
7
- pkg: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
8
- yes: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
9
- };
10
6
  static description: string;
11
7
  static examples: {
12
8
  command: string;
13
9
  description: string;
14
10
  }[];
11
+ static flags: any;
12
+ appType: string;
13
+ createSwellConfig({ allowOverwrite, inputId, inputStorefrontApp, inputType, inputYes, nestedPath, }: {
14
+ allowOverwrite?: boolean;
15
+ inputId: string;
16
+ inputStorefrontApp?: string;
17
+ inputType?: string;
18
+ inputYes?: boolean;
19
+ nestedPath?: boolean;
20
+ }): Promise<{
21
+ appId: string;
22
+ config: any;
23
+ installedStorefrontApp: any;
24
+ swellConfigJson: {
25
+ theme: {
26
+ storefront: {
27
+ app: string;
28
+ };
29
+ };
30
+ description: string;
31
+ id: string;
32
+ name: string;
33
+ type: string;
34
+ version: string;
35
+ } | {
36
+ permissions: never[];
37
+ description: string;
38
+ id: string;
39
+ name: string;
40
+ type: string;
41
+ version: string;
42
+ };
43
+ } | undefined>;
15
44
  run(): Promise<void>;
16
- private tryPackageSetup;
17
- private setupPackage;
18
- private findPackageManager;
19
- private doesPackageManagerExist;
20
- private createAppConfigFolders;
21
45
  }
@@ -1,35 +1,19 @@
1
- import path from 'path';
2
- import { exec } from 'child_process';
3
- import { promisify } from 'util';
4
1
  import { confirm, input, select } from '@inquirer/prompts';
5
2
  import { Args, Flags } from '@oclif/core';
3
+ import path from 'node:path';
6
4
  import ora from 'ora';
7
- import { appConfigFileExists, newConfig } from '../../lib/app-config.js';
5
+ import { CreateAppCommand } from '../../create-app-command.js';
6
+ import { newConfig, swellConfigFileExists } from '../../lib/app-config.js';
7
+ import { toAppId, toAppName } from '../../lib/create/index.js';
8
8
  import style from '../../lib/style.js';
9
- import { SwellCommand } from '../../swell-command.js';
10
- import { toAppName, toAppId } from '../../lib/create/index.js';
11
- import { getAllConfigPaths, writeJsonFile } from '../../lib/apps/index.js';
12
- const execAsync = promisify(exec);
13
- export default class CreateApp extends SwellCommand {
9
+ export default class CreateApp extends CreateAppCommand {
14
10
  static args = {
15
11
  id: Args.string({
16
12
  default: '',
17
13
  description: `id of the app to create`,
18
14
  }),
19
15
  };
20
- static flags = {
21
- pkg: Flags.string({
22
- char: 'p',
23
- default: 'npm',
24
- description: `use npm or yarn to install default dependencies, or none to disable`,
25
- options: ['npm', 'yarn', 'none'],
26
- }),
27
- yes: Flags.boolean({
28
- char: 'y',
29
- description: `accept all default values`,
30
- }),
31
- };
32
- static description = 'Initialize an app with config file and folder structure.';
16
+ static description = 'Create an app.';
33
17
  static examples = [
34
18
  {
35
19
  command: 'swell create app',
@@ -48,63 +32,130 @@ export default class CreateApp extends SwellCommand {
48
32
  description: 'Create app without installing TypeScript bindings, etc.',
49
33
  },
50
34
  ];
51
- async run() {
52
- const { args, flags } = await this.parse(CreateApp);
53
- const { id } = args;
54
- const { pkg, yes } = flags;
55
- let confirmYes = yes && id;
35
+ static flags = {
36
+ pkg: Flags.string({
37
+ char: 'p',
38
+ default: 'npm',
39
+ description: `use npm or yarn to install default dependencies, or none to disable`,
40
+ options: ['npm', 'yarn', 'none'],
41
+ }),
42
+ type: Flags.string({
43
+ char: 't',
44
+ description: `create a specific app type`,
45
+ options: ['admin', 'integration', 'storefront', 'theme'],
46
+ }),
47
+ };
48
+ appType = '';
49
+ async createSwellConfig({ allowOverwrite = true, inputId, inputStorefrontApp, inputType, inputYes, nestedPath = true, }) {
50
+ let confirmYes = inputYes;
51
+ const type = inputType ||
52
+ (confirmYes
53
+ ? 'admin'
54
+ : await select({
55
+ choices: [
56
+ { name: 'Admin', value: 'admin' },
57
+ { name: 'Integration', value: 'integration' },
58
+ { name: 'Storefront', value: 'storefront' },
59
+ { name: 'Theme', value: 'theme' },
60
+ ],
61
+ message: `What is the primary purpose of the app?`,
62
+ }));
63
+ const typeLabel = type === 'theme' ? 'theme' : 'app';
64
+ const typeLabelTitle = type === 'theme' ? 'Theme' : 'App';
56
65
  const name = confirmYes
57
- ? toAppName(id)
66
+ ? toAppName(inputId)
58
67
  : await input({
59
- message: 'App name',
60
- default: id ? toAppName(id) : '',
68
+ default: inputId ? toAppName(inputId) : '',
69
+ message: `${typeLabelTitle} name`,
61
70
  validate: (answer) => answer.length > 2,
62
71
  });
63
- let appId = toAppId(id || '');
72
+ let appId = toAppId(inputId || '');
64
73
  if (!appId) {
65
74
  appId = await input({
66
- message: 'App ID',
67
75
  default: toAppId(name),
76
+ message: `${typeLabelTitle} ID`,
68
77
  validate: (answer) => answer.length > 2,
69
78
  });
70
79
  appId = toAppId(appId);
71
- confirmYes = yes && appId;
80
+ confirmYes = Boolean(inputYes && appId);
72
81
  }
82
+ const version = confirmYes
83
+ ? '1.0.0'
84
+ : await input({
85
+ default: '1.0.0',
86
+ message: `${typeLabelTitle} version`,
87
+ });
73
88
  const description = confirmYes
74
89
  ? ''
75
90
  : await input({
76
- message: 'Describe what the app does',
77
91
  default: 'Something special',
92
+ message: `Describe your ${typeLabel}`,
78
93
  });
79
- const type = confirmYes
80
- ? 'admin'
81
- : await select({
82
- message: 'What is the primary purpose of the app?',
83
- choices: [
84
- { name: 'Admin', value: 'admin' },
85
- { name: 'Integration', value: 'integration' },
86
- { name: 'Storefront', value: 'storefront' },
87
- ],
88
- });
89
- const appConfigJson = {
94
+ let storefrontInstalledApps;
95
+ let storefrontAppId;
96
+ let installedStorefrontApp;
97
+ if (type === 'theme') {
98
+ storefrontInstalledApps = await this.getInstalledStorefrontApps();
99
+ if (storefrontInstalledApps === false) {
100
+ return;
101
+ }
102
+ storefrontAppId =
103
+ inputStorefrontApp ||
104
+ (storefrontInstalledApps.length > 1
105
+ ? await select({
106
+ choices: storefrontInstalledApps.map(({ app, id }) => ({
107
+ name: app.name,
108
+ value: id,
109
+ })),
110
+ message: `Which storefront app is your theme for?`,
111
+ })
112
+ : storefrontInstalledApps[0].id);
113
+ installedStorefrontApp = storefrontInstalledApps.find((installedApp) => inputStorefrontApp
114
+ ? inputStorefrontApp === installedApp.app_private_id ||
115
+ inputStorefrontApp === installedApp.app_public_id ||
116
+ inputStorefrontApp === installedApp.app_id ||
117
+ inputStorefrontApp === toAppId(installedApp.app_private_id)
118
+ : installedApp.id === storefrontAppId);
119
+ if (!installedStorefrontApp) {
120
+ this.error(`Could not find an installed storefront app by id: ${storefrontAppId}`);
121
+ }
122
+ }
123
+ const swellConfigJson = {
124
+ description,
90
125
  id: appId,
91
- version: '1.0.0',
92
126
  name,
93
- description,
94
127
  type,
95
- permissions: [],
128
+ version,
129
+ ...(type === 'theme'
130
+ ? {
131
+ theme: {
132
+ storefront: {
133
+ app: toAppId(installedStorefrontApp.app_private_id),
134
+ },
135
+ },
136
+ }
137
+ : {
138
+ permissions: [],
139
+ }),
96
140
  };
97
- const config = newConfig(appId);
98
- if (!confirmYes && appConfigFileExists(config.path)) {
99
- const continueCreateApp = await confirm({
100
- message: `An app already exists in the target folder ${appId}. Overwrite?`,
101
- });
102
- if (!continueCreateApp) {
103
- return;
141
+ const appPath = path.join(process.cwd(), appId);
142
+ if (swellConfigFileExists(appPath)) {
143
+ if (allowOverwrite) {
144
+ if (!confirmYes) {
145
+ const continueCreateApp = await confirm({
146
+ message: `An app already exists in the target path ${appPath}. Overwrite?`,
147
+ });
148
+ if (!continueCreateApp) {
149
+ return;
150
+ }
151
+ }
152
+ }
153
+ else {
154
+ this.error(`An app already exists in the target path ${appPath}.`);
104
155
  }
105
156
  }
106
- this.log(`\nCreating app ${style.appConfigValue(name)} in ${config.path}`);
107
- this.log(`\n${JSON.stringify(appConfigJson, null, 4)}\n`);
157
+ this.log(`\nCreating ${this.appType === 'theme' ? 'theme' : 'app'} ${style.appConfigValue(name)} in ${appPath}/swell.json`);
158
+ this.log(`\n${JSON.stringify(swellConfigJson, null, 2)}\n`);
108
159
  const confirmCreateApp = confirmYes
109
160
  ? true
110
161
  : await confirm({
@@ -113,98 +164,53 @@ export default class CreateApp extends SwellCommand {
113
164
  if (!confirmCreateApp) {
114
165
  return;
115
166
  }
167
+ const config = newConfig(nestedPath ? appId : '');
168
+ config.clear();
169
+ config.set(swellConfigJson);
170
+ return { appId, config, installedStorefrontApp, swellConfigJson };
171
+ }
172
+ async run() {
173
+ const { args, flags } = await this.parse(CreateApp);
174
+ const { id } = args;
175
+ const { pkg, yes } = flags;
176
+ const confirmYes = Boolean(yes && id);
177
+ const createParams = await this.createSwellConfig({
178
+ inputId: id,
179
+ inputStorefrontApp: flags['storefront-app'],
180
+ inputType: flags.type,
181
+ inputYes: confirmYes,
182
+ });
183
+ if (!createParams) {
184
+ return;
185
+ }
186
+ const { appId, config, installedStorefrontApp } = createParams;
116
187
  !confirmYes && this.log();
117
188
  const spinner = ora();
118
189
  spinner.start('Creating app...');
119
- config.clear();
120
- config.set(appConfigJson);
121
190
  if (pkg !== 'none') {
122
191
  await this.tryPackageSetup(appId, config, pkg);
123
192
  }
124
193
  await this.createAppConfigFolders(config);
125
- spinner.succeed(`${style.appConfigValue(name)} app created.`);
126
- this.log('\nNext steps:');
127
- this.log(`Run ${style.command('swell app push')} to push configurations to your test store.`);
128
- this.log(`Run ${style.command('swell app install')} to install the app in another store or environment.`);
129
- }
130
- async tryPackageSetup(name, config, pkg) {
131
- try {
132
- await this.setupPackage(name, config, pkg);
194
+ spinner.succeed(`${style.appConfigValue(config.get('name'))} app created.\n`);
195
+ let createdFrontend;
196
+ let createdTheme;
197
+ if (installedStorefrontApp) {
198
+ createdTheme = await this.createThemeApp(config, flags, installedStorefrontApp);
133
199
  }
134
- catch (err) {
135
- this.log(`There was an error setting up the package manager: ${err.message}`);
136
- }
137
- }
138
- async setupPackage(name, config, pkg) {
139
- const execAsync = promisify(exec);
140
- const packageJson = {
141
- name,
142
- version: config.get('version'),
143
- description: config.get('description'),
144
- scripts: {},
145
- devDependencies: {
146
- '@swell/app-types': '^1.0.5',
147
- },
148
- };
149
- const tsConfig = {
150
- compilerOptions: {
151
- target: 'esnext',
152
- module: 'esnext',
153
- lib: ['esnext', 'webworker'],
154
- types: ['@swell/app-types'],
155
- },
156
- include: ['**/*.ts'],
157
- exclude: ['node_modules'],
158
- };
159
- await writeJsonFile(path.join(path.dirname(config.path), 'package.json'), packageJson);
160
- await writeJsonFile(path.join(path.dirname(config.path), 'tsconfig.json'), tsConfig);
161
- try {
162
- const packageManager = await this.findPackageManager(pkg);
163
- await execAsync(`${packageManager} install`, {
164
- cwd: path.dirname(config.path),
165
- });
166
- }
167
- catch (err) {
168
- this.error(err.message);
169
- }
170
- }
171
- async findPackageManager(pkg) {
172
- let packageManager = pkg ? pkg : '';
173
- // Determine if system has yarn or npm install
174
- if (packageManager) {
175
- if (await this.doesPackageManagerExist(packageManager)) {
176
- return packageManager;
177
- }
200
+ else if (config.get('type') === 'storefront') {
201
+ createdFrontend = await this.createStorefrontApp(config, flags);
178
202
  }
179
203
  else {
180
- if (await this.doesPackageManagerExist('npm')) {
181
- return 'npm';
182
- }
183
- else if (await this.doesPackageManagerExist('yarn')) {
184
- return 'yarn';
185
- }
204
+ createdFrontend = await this.createFrontendApp(config, flags);
186
205
  }
187
- }
188
- async doesPackageManagerExist(packageManager) {
189
- try {
190
- await execAsync(`${packageManager} --version`);
191
- return true;
192
- }
193
- catch (err) {
194
- this.debug(`Could not find ${packageManager} on your system. Please install ${packageManager} and try again.`);
195
- return false;
206
+ this.log('\nNext steps:');
207
+ this.log(`Run ${style.command('swell app push')} to push configurations to your test store.`);
208
+ this.log(`Run ${style.command('swell app install')} to install the app in another store or environment.`);
209
+ if (createdFrontend) {
210
+ this.log(`Run ${style.command('swell app frontend dev')} to start a local dev server for your frontend app.`);
196
211
  }
197
- }
198
- async createAppConfigFolders(config) {
199
- for (const type of getAllConfigPaths()) {
200
- // Create a config folder
201
- await execAsync(`mkdir -p ${type}`, {
202
- cwd: path.dirname(config.path),
203
- });
204
- // Create gitkeep file
205
- await execAsync(`touch ${path.join(type, '.gitkeep')}`, {
206
- cwd: path.dirname(config.path),
207
- });
212
+ else if (createdTheme) {
213
+ this.log(`Run ${style.command('swell app theme dev')} to start a local dev server for your theme.`);
208
214
  }
209
215
  }
210
216
  }
@@ -7,11 +7,11 @@ export default class CreateContent extends CreateCollectionCommand {
7
7
  description: string;
8
8
  }[];
9
9
  static flags: {
10
- label: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
10
  description: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
12
11
  fields: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
13
- views: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
12
+ label: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
14
13
  overwrite: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
14
+ views: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
15
15
  };
16
16
  static summary: string;
17
17
  createType: ConfigType;
@@ -25,11 +25,6 @@ export default class CreateContent extends CreateCollectionCommand {
25
25
  },
26
26
  ];
27
27
  static flags = {
28
- label: Flags.string({
29
- char: 'l',
30
- default: '',
31
- description: 'content model label',
32
- }),
33
28
  description: Flags.string({
34
29
  char: 'd',
35
30
  default: '',
@@ -40,21 +35,26 @@ export default class CreateContent extends CreateCollectionCommand {
40
35
  default: '',
41
36
  description: 'list of content model fields delimited by commas',
42
37
  }),
43
- views: Flags.string({
44
- char: 'v',
38
+ label: Flags.string({
39
+ char: 'l',
45
40
  default: '',
46
- description: 'list of content model views delimited by commas, i.e. list,edit,new',
41
+ description: 'content model label',
47
42
  }),
48
43
  overwrite: Flags.boolean({
49
44
  default: false,
50
45
  description: 'overwrite existing content model configuration file',
51
46
  }),
47
+ views: Flags.string({
48
+ char: 'v',
49
+ default: '',
50
+ description: 'list of content model views delimited by commas, i.e. list,edit,new',
51
+ }),
52
52
  };
53
53
  static summary = 'Initialize a content UI model config file with properties in the content folder.';
54
54
  createType = ConfigType.CONTENT;
55
55
  async run() {
56
56
  const { flags } = await this.parse(CreateContent);
57
- const { label, description, collection } = await this.promptCollection();
57
+ const { collection, description, label } = await this.promptCollection();
58
58
  const fileName = toFileName(collection);
59
59
  const fileBody = {
60
60
  collection,
@@ -70,12 +70,12 @@ export default class CreateContent extends CreateCollectionCommand {
70
70
  }
71
71
  else {
72
72
  const viewsInput = await checkbox({
73
- message: 'Which views does your content have?',
74
73
  choices: [
75
74
  { name: 'List view', value: 'list' },
76
75
  { name: 'Edit view', value: 'edit' },
77
76
  { name: 'New view', value: 'new' },
78
77
  ],
78
+ message: 'Which views does your content have?',
79
79
  });
80
80
  fileBody.views = parseViews(viewsInput);
81
81
  }
@@ -0,0 +1,12 @@
1
+ import { CreateAppCommand } from '../../create-app-command.js';
2
+ export default class CreateFrontend extends CreateAppCommand {
3
+ static description: string;
4
+ static examples: {
5
+ command: string;
6
+ description: string;
7
+ }[];
8
+ static flags: {
9
+ pkg: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
+ };
11
+ run(): Promise<void>;
12
+ }
@@ -0,0 +1,38 @@
1
+ import { Flags } from '@oclif/core';
2
+ import ora from 'ora';
3
+ import { CreateAppCommand } from '../../create-app-command.js';
4
+ import swellConfig from '../../lib/app-config.js';
5
+ export default class CreateFrontend extends CreateAppCommand {
6
+ static description = 'Initialize a frontend app framework and folder structure.';
7
+ static examples = [
8
+ {
9
+ command: 'swell create frontend',
10
+ description: 'Create frontend app following command prompts.',
11
+ },
12
+ {
13
+ command: 'swell create frontend -y',
14
+ description: 'Create frontend app and accept all default values.',
15
+ },
16
+ ];
17
+ static flags = {
18
+ pkg: Flags.string({
19
+ char: 'p',
20
+ default: 'npm',
21
+ description: `use npm or yarn to install default dependencies, or none to disable`,
22
+ options: ['npm', 'yarn', 'none'],
23
+ }),
24
+ };
25
+ async run() {
26
+ const { flags } = await this.parse(CreateFrontend);
27
+ const newSwellConfig = swellConfig();
28
+ const appType = newSwellConfig?.get('type');
29
+ const spinner = ora();
30
+ if (appType === 'theme') {
31
+ spinner.fail(`You can't create app frontend in a theme.`);
32
+ return;
33
+ }
34
+ await (appType === 'storefront'
35
+ ? this.createStorefrontApp(newSwellConfig, flags, true)
36
+ : this.createFrontendApp(newSwellConfig, flags, true));
37
+ }
38
+ }
@@ -1,6 +1,6 @@
1
- import { CreateCommand } from '../../create-command.js';
1
+ import { CreateConfigCommand } from '../../create-config-command.js';
2
2
  import { ConfigType } from '../../lib/apps/index.js';
3
- export default class CreateFunction extends CreateCommand {
3
+ export default class CreateFunction extends CreateConfigCommand {
4
4
  static args: {
5
5
  functionName: import("@oclif/core/lib/interfaces/parser.js").Arg<string | undefined, Record<string, unknown>>;
6
6
  trigger: import("@oclif/core/lib/interfaces/parser.js").Arg<string | undefined, Record<string, unknown>>;
@@ -13,9 +13,9 @@ export default class CreateFunction extends CreateCommand {
13
13
  static flags: {
14
14
  description: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
15
15
  events: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
16
+ overwrite: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
16
17
  route: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
17
18
  schedule: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
18
- overwrite: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
19
19
  };
20
20
  static summary: string;
21
21
  createType: ConfigType;