@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
@@ -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,5 +1,5 @@
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
  };
@@ -8,14 +8,38 @@ export default class CreateApp extends SwellCommand {
8
8
  command: string;
9
9
  description: string;
10
10
  }[];
11
- static flags: {
12
- pkg: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
13
- yes: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
14
- };
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 createAppConfigFolders;
17
- private doesPackageManagerExist;
18
- private findPackageManager;
19
- private setupPackage;
20
- private tryPackageSetup;
21
45
  }
@@ -1,23 +1,19 @@
1
1
  import { confirm, input, select } from '@inquirer/prompts';
2
2
  import { Args, Flags } from '@oclif/core';
3
- import { exec } from 'node:child_process';
4
3
  import path from 'node:path';
5
- import { promisify } from 'node:util';
6
4
  import ora from 'ora';
7
- import { appConfigFileExists, newConfig } from '../../lib/app-config.js';
8
- import { getAllConfigPaths, writeJsonFile } from '../../lib/apps/index.js';
5
+ import { CreateAppCommand } from '../../create-app-command.js';
6
+ import { newConfig, swellConfigFileExists } from '../../lib/app-config.js';
9
7
  import { toAppId, toAppName } from '../../lib/create/index.js';
10
8
  import style from '../../lib/style.js';
11
- import { SwellCommand } from '../../swell-command.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 description = 'Initialize an app with config file and folder structure.';
16
+ static description = 'Create an app.';
21
17
  static examples = [
22
18
  {
23
19
  command: 'swell create app',
@@ -43,69 +39,123 @@ export default class CreateApp extends SwellCommand {
43
39
  description: `use npm or yarn to install default dependencies, or none to disable`,
44
40
  options: ['npm', 'yarn', 'none'],
45
41
  }),
46
- yes: Flags.boolean({
47
- char: 'y',
48
- description: `accept all default values`,
42
+ type: Flags.string({
43
+ char: 't',
44
+ description: `create a specific app type`,
45
+ options: ['admin', 'integration', 'storefront', 'theme'],
49
46
  }),
50
47
  };
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;
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
- default: id ? toAppName(id) : '',
60
- message: 'App name',
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
75
  default: toAppId(name),
67
- message: 'App ID',
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
91
  default: 'Something special',
77
- message: 'Describe what the app does',
92
+ message: `Describe your ${typeLabel}`,
78
93
  });
79
- const type = confirmYes
80
- ? 'admin'
81
- : await select({
82
- choices: [
83
- { name: 'Admin', value: 'admin' },
84
- { name: 'Integration', value: 'integration' },
85
- { name: 'Storefront', value: 'storefront' },
86
- ],
87
- message: 'What is the primary purpose of the app?',
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 = {
90
124
  description,
91
125
  id: appId,
92
- integrations: [],
93
126
  name,
94
- permissions: [],
95
127
  type,
96
- version: '1.0.0',
128
+ version,
129
+ ...(type === 'theme'
130
+ ? {
131
+ theme: {
132
+ storefront: {
133
+ app: toAppId(installedStorefrontApp.app_private_id),
134
+ },
135
+ },
136
+ }
137
+ : {
138
+ permissions: [],
139
+ }),
97
140
  };
98
- const config = newConfig(appId);
99
- if (!confirmYes && appConfigFileExists(config.path)) {
100
- const continueCreateApp = await confirm({
101
- message: `An app already exists in the target folder ${appId}. Overwrite?`,
102
- });
103
- if (!continueCreateApp) {
104
- 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}.`);
105
155
  }
106
156
  }
107
- this.log(`\nCreating app ${style.appConfigValue(name)} in ${config.path}`);
108
- 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`);
109
159
  const confirmCreateApp = confirmYes
110
160
  ? true
111
161
  : await confirm({
@@ -114,100 +164,53 @@ export default class CreateApp extends SwellCommand {
114
164
  if (!confirmCreateApp) {
115
165
  return;
116
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;
117
187
  !confirmYes && this.log();
118
188
  const spinner = ora();
119
189
  spinner.start('Creating app...');
120
- config.clear();
121
- config.set(appConfigJson);
122
190
  if (pkg !== 'none') {
123
191
  await this.tryPackageSetup(appId, config, pkg);
124
192
  }
125
193
  await this.createAppConfigFolders(config);
126
- spinner.succeed(`${style.appConfigValue(name)} app created.`);
127
- this.log('\nNext steps:');
128
- this.log(`Run ${style.command('swell app push')} to push configurations to your test store.`);
129
- this.log(`Run ${style.command('swell app install')} to install the app in another store or environment.`);
130
- }
131
- async createAppConfigFolders(config) {
132
- for (const type of getAllConfigPaths()) {
133
- // Create a config folder
134
- // eslint-disable-next-line no-await-in-loop
135
- await execAsync(`mkdir -p ${type}`, {
136
- cwd: path.dirname(config.path),
137
- });
138
- // Create gitkeep file
139
- // eslint-disable-next-line no-await-in-loop
140
- await execAsync(`touch ${path.join(type, '.gitkeep')}`, {
141
- cwd: path.dirname(config.path),
142
- });
143
- }
144
- }
145
- async doesPackageManagerExist(packageManager) {
146
- try {
147
- await execAsync(`${packageManager} --version`);
148
- return true;
149
- }
150
- catch {
151
- this.debug(`Could not find ${packageManager} on your system. Please install ${packageManager} and try again.`);
152
- return false;
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);
153
199
  }
154
- }
155
- async findPackageManager(pkg = '') {
156
- const packageManager = pkg;
157
- // Determine if system has yarn or npm install
158
- if (packageManager) {
159
- if (await this.doesPackageManagerExist(packageManager)) {
160
- return packageManager;
161
- }
200
+ else if (config.get('type') === 'storefront') {
201
+ createdFrontend = await this.createStorefrontApp(config, flags);
162
202
  }
163
203
  else {
164
- if (await this.doesPackageManagerExist('npm')) {
165
- return 'npm';
166
- }
167
- if (await this.doesPackageManagerExist('yarn')) {
168
- return 'yarn';
169
- }
204
+ createdFrontend = await this.createFrontendApp(config, flags);
170
205
  }
171
- }
172
- async setupPackage(name, config, pkg) {
173
- const execAsync = promisify(exec);
174
- const packageJson = {
175
- description: config.get('description'),
176
- devDependencies: {
177
- '@swell/app-types': '^1.0.5',
178
- },
179
- name,
180
- scripts: {},
181
- version: config.get('version'),
182
- };
183
- const tsConfig = {
184
- compilerOptions: {
185
- lib: ['esnext', 'webworker'],
186
- module: 'esnext',
187
- target: 'esnext',
188
- types: ['@swell/app-types'],
189
- },
190
- exclude: ['node_modules'],
191
- include: ['**/*.ts'],
192
- };
193
- await writeJsonFile(path.join(path.dirname(config.path), 'package.json'), packageJson);
194
- await writeJsonFile(path.join(path.dirname(config.path), 'tsconfig.json'), tsConfig);
195
- try {
196
- const packageManager = await this.findPackageManager(pkg);
197
- await execAsync(`${packageManager} install`, {
198
- cwd: path.dirname(config.path),
199
- });
200
- }
201
- catch (error) {
202
- this.error(error.message);
203
- }
204
- }
205
- async tryPackageSetup(name, config, pkg) {
206
- try {
207
- await this.setupPackage(name, config, pkg);
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.`);
208
211
  }
209
- catch (error) {
210
- this.log(`There was an error setting up the package manager: ${error.message}`);
212
+ else if (createdTheme) {
213
+ this.log(`Run ${style.command('swell app theme dev')} to start a local dev server for your theme.`);
211
214
  }
212
215
  }
213
216
  }
@@ -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>>;
@@ -1,11 +1,11 @@
1
1
  import { input, select } from '@inquirer/prompts';
2
2
  import { Args, Flags } from '@oclif/core';
3
- import { CreateCommand } from '../../create-command.js';
3
+ import { CreateConfigCommand } from '../../create-config-command.js';
4
4
  import { ConfigType } from '../../lib/apps/index.js';
5
5
  import { getFunctionTemplate, } from '../../lib/create/function.js';
6
6
  import { toFunctionFileName } from '../../lib/create/index.js';
7
7
  const PERMITTED_TRIGGERS = ['cron', 'model', 'route'];
8
- export default class CreateFunction extends CreateCommand {
8
+ export default class CreateFunction extends CreateConfigCommand {
9
9
  static args = {
10
10
  functionName: Args.string({
11
11
  description: 'function name, used in an http route if applicable',
@@ -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 CreateNotification extends CreateCommand {
3
+ export default class CreateNotification extends CreateConfigCommand {
4
4
  static args: {
5
5
  model: import("@oclif/core/lib/interfaces/parser.js").Arg<string | undefined, Record<string, unknown>>;
6
6
  name: import("@oclif/core/lib/interfaces/parser.js").Arg<string | undefined, Record<string, unknown>>;
@@ -1,10 +1,10 @@
1
1
  import { input, select } from '@inquirer/prompts';
2
2
  import { Args, Flags } from '@oclif/core';
3
3
  import { capitalize, singularize } from 'inflection';
4
- import { CreateCommand } from '../../create-command.js';
4
+ import { CreateConfigCommand } from '../../create-config-command.js';
5
5
  import { ConfigType } from '../../lib/apps/index.js';
6
6
  import { toFileName, toNotificationLabel } from '../../lib/create/index.js';
7
- export default class CreateNotification extends CreateCommand {
7
+ export default class CreateNotification extends CreateConfigCommand {
8
8
  static args = {
9
9
  model: Args.string({
10
10
  description: 'data model to trigger the notification by',
@@ -0,0 +1,12 @@
1
+ import { Config } from '@oclif/core';
2
+ import { SwellCommand } from '../swell-command.js';
3
+ export default class Env extends SwellCommand {
4
+ static args: {
5
+ name: import("@oclif/core/lib/interfaces/parser.js").Arg<string | undefined, Record<string, unknown>>;
6
+ reviewBranch: import("@oclif/core/lib/interfaces/parser.js").Arg<string | undefined, Record<string, unknown>>;
7
+ };
8
+ static description: string;
9
+ static hidden: boolean;
10
+ constructor(argv: string[], config: Config);
11
+ run(): Promise<void>;
12
+ }
@@ -0,0 +1,31 @@
1
+ import { Args } from '@oclif/core';
2
+ import { env, setEnv } from '../lib/config.js';
3
+ import style from '../lib/style.js';
4
+ import { SwellCommand } from '../swell-command.js';
5
+ export default class Env extends SwellCommand {
6
+ static args = {
7
+ name: Args.string({
8
+ description: 'name of the environment (production, staging, local, review)',
9
+ }),
10
+ reviewBranch: Args.string({
11
+ description: 'name of a review branch',
12
+ }),
13
+ };
14
+ static description = `Internal: Display the current environment configuration.`;
15
+ static hidden = true;
16
+ constructor(argv, config) {
17
+ super(argv, config);
18
+ this.requiresAuth = false;
19
+ }
20
+ async run() {
21
+ const { args } = await this.parse(Env);
22
+ const { name, reviewBranch } = args;
23
+ if (name) {
24
+ const newEnv = setEnv(name, reviewBranch);
25
+ this.log(`Environment set to ${style.appEnv(name)}:`, JSON.stringify(newEnv, null, 2));
26
+ }
27
+ else {
28
+ this.log('Current environment:', JSON.stringify(env.store, null, 2));
29
+ }
30
+ }
31
+ }