@ordergroove/smi-serve 1.7.4 → 1.8.0

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,31 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.8.0](https://github.com/ordergroove/plush-toys/compare/@ordergroove/smi-serve@1.7.5...@ordergroove/smi-serve@1.8.0) (2024-04-25)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * default to latest template if configs not found ([cf94386](https://github.com/ordergroove/plush-toys/commit/cf943860ac1738e1ba8196efdd11769654ba2dc1))
12
+ * do not crash dev server on error ([7742204](https://github.com/ordergroove/plush-toys/commit/7742204b14fb9ae9ecfff46b9773f12e524f4390))
13
+
14
+
15
+ ### Features
16
+
17
+ * allow running smi-serve on local smi-templates ([c1bf5f7](https://github.com/ordergroove/plush-toys/commit/c1bf5f7002afc1284e65daa79b46acfc1fc97887))
18
+
19
+
20
+
21
+
22
+
23
+ ## [1.7.5](https://github.com/ordergroove/plush-toys/compare/@ordergroove/smi-serve@1.7.4...@ordergroove/smi-serve@1.7.5) (2024-04-22)
24
+
25
+ **Note:** Version bump only for package @ordergroove/smi-serve
26
+
27
+
28
+
29
+
30
+
6
31
  ## [1.7.4](https://github.com/ordergroove/plush-toys/compare/@ordergroove/smi-serve@1.7.3...@ordergroove/smi-serve@1.7.4) (2024-04-22)
7
32
 
8
33
 
package/LOCAL_DEV.md ADDED
@@ -0,0 +1,27 @@
1
+ This document contains instructions for development of the smi-serve tool itself, since the main README.md is intended for external users of the tool.
2
+
3
+ ## Testing changes to smi-serve
4
+
5
+ Inside the `/packages/smi-serve` directory in plush-toys, run `npm link`. This should make your local version of the package available across your system.
6
+
7
+ In a new directory outside of plush-toys, run `npx @ordergroove/smi-serve init` or whatever command you want to test. This should use your local version of smi-serve. You can verify that it is working correctly by adding a console.log message inside `smi-serve.js`. You can also verify by running `npm ls --global @ordergroove/smi-serve` - it should point to your local plush-toys directory:
8
+
9
+ ```
10
+ /Users/username/node/v18.18.2/lib
11
+ └── @ordergroove/smi-serve@1.7.5 -> ./../../../../../code/plush-toys/packages/smi-serve
12
+ ```
13
+
14
+ ## Unlinking smi-serve
15
+
16
+ If you want to use the published version of the package instead, you will need to uninstall the package globally. Since smi-serve is not added as a project dependency, it is installed in the global npm scope.
17
+
18
+ To remove the link to your local package, run `npm uninstall @ordergroove/smi-serve -g`. You can verify that the command succeeded by running `npm ls --global @ordergroove/smi-serve`. It should show something like:
19
+
20
+ ```
21
+ /Users/username/node/v18.18.2/lib
22
+ └── (empty)
23
+ ```
24
+
25
+ ## Debugging
26
+
27
+ After linking to your local version of smi-serve, you can debug the tool inside VS Code. First, add a `debugger` statement inside the smi-serve code you are running. Then, inside your test project directory, open the [JavaScript debug terminal](https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_javascript-debug-terminal) and run the command you want to debug. VS Code's debugger should launch and automatically break when it gets to that statement. You can then set breakpoints in the code and inspect the running process.
package/README.md CHANGED
@@ -1,73 +1,66 @@
1
1
  # @ordergroove/smi-serve
2
2
 
3
- This README document provides an overview and usage instructions for the `smi-serve` program.
4
-
5
- ## Overview
6
-
7
- `smi-serve` is a command-line tool designed to manage authentication credentials, initialize directories for use with Ordergroove's services, and start a development server.
3
+ `smi-serve` is a CLI tool to scaffold and run a local dev environment for Ordergroove's Subscription Manager templates.
8
4
 
9
5
  ## Installation
10
6
 
11
- Before using `smi-serve`, ensure you have Node.js installed on your system. If not, you can download and install it from [nodejs.org](https://nodejs.org/).
7
+ Before using `smi-serve`, ensure you have Node.js installed on your system. If not, you can download and install it from [nodejs.org](https://nodejs.org/). The smi-serve tool requires Node 18 or later.
8
+
9
+ ## Getting started
12
10
 
13
- ## Usage
11
+ To initialize the current directory for local Subscription Manager development, run `npx @ordergroove/smi-serve init`. This will authenticate you with Ordergroove, retrieve your current Subscription Manager assets, and start a dev server.
14
12
 
15
- To use `smi-serve` via `npx`, follow the instructions below:
13
+ After initialization, you can restart the dev server with `npx @ordergroove/smi-serve`.
16
14
 
17
- ### 1\. Initialization
15
+ When you are ready to push your changes to production, run `npx @ordergroove/smi-serve deploy` to deploy your changes to Ordergroove.
18
16
 
19
- To initialize the current directory with assets from Ordergroove RC3 and start the development server, use:
17
+ ## Configuration file
20
18
 
21
- `npx @ordergroove/smi-serve init`
19
+ This tool generates a `.ogrc.json` file to store authentication information. This file should not be committed to source control.
22
20
 
23
- This command initializes the current directory with assets from Ordergroove RC3 and starts a development server for serving the initialized assets. Any initialization errors will be displayed.
24
- Options:
21
+ ## Command reference
25
22
 
26
- - `-y` Answer all prompts as yes and silent the prompts
27
- - `--force` or `-f` Force override local files if present
23
+ You can run each command with `npx @ordergroove/smi-serve [command]`, e.g. `npx @ordergroove/smi-serve init`.
28
24
 
29
- ### 2\. Start the Development Server
25
+ To see all available commands and flags, run `npx @ordergroove/smi-serve --help`. For documentation specific to individual commands, run `npx @ordergroove/smi-serve [command] --help`.
30
26
 
31
- If no command is specified, the default behavior is to start the development server. This can also be explicitly invoked using:
27
+ ### init
32
28
 
33
- `npx @ordergroove/smi-serve serve`
29
+ Initializes the current directory with the assets from your live Subscription Manager theme and starts a dev server. This only needs to be run when you need to retrieve the latest assets from Ordergroove; otherwise you can start the dev server directly with `npx @ordergroove/smi-serve serve`.
34
30
 
35
- This command starts the development server and serves assets. The server's behavior can be modified using various options.
31
+ ### serve
36
32
 
37
- ### 3\. Deploy Changes to Ordergroove
33
+ Starts a development server. This is the default command, so it can also be run by entering `npx @ordergroove/smi-serve`.
38
34
 
39
- To deploy changes to Ordergroove, use the deploy command:
35
+ By default it will choose a random available port, but you can customize this with the `--port` flag.
40
36
 
41
- `npx @ordergroove/smi-serve deploy`
37
+ ### deploy
42
38
 
43
- This command deploys changes to Ordergroove based on the configured settings. Ensure you have the necessary authentication and configuration set up.
39
+ Publishes your template changes to your live Subscription Manager theme. Before publishing, it will summarize which files have changed and ask for confirmation.
44
40
 
45
- ### 4\. Select a new merchant
41
+ ### select-merchant
46
42
 
47
- If you have access to multiple merchants, you can use the `select-merchant` command to switch to a new merchant. This can be useful if you manage multiple merchant accounts and would like to deploy changes from one merchant to another merchant.
43
+ If you have access to multiple merchants, this lets you select a new merchant to be used by the other commands. This can be useful if you manage multiple merchant accounts.
48
44
 
49
- `npx @ordergroove/smi-serve select-merchant`
45
+ ## FAQs
50
46
 
51
- This command allows you to select a new merchant from those available with your Ordergroove credentials.
47
+ ### How do I run commands against Ordergroove's staging environment?
52
48
 
53
- #### Options
49
+ You can use the flag `--env staging` to make requests against Ordergroove's staging environment. For example, run `npx @ordergroove/smi-serve init --env staging` to initialize with assets from staging.
54
50
 
55
- You can use a configuration file (.ogrc.json by default) to store settings from the command line. The following option is available:
51
+ Keep in mind that if you use this flag, _every command_ you run must also include it.
56
52
 
57
- --configFile or -c: Specify the path to the Ordergroove configuration file. Defaults to .ogrc.json.
53
+ ### How do I integrate with source control?
58
54
 
59
- This config is auto generated when you login and placed into the current working directory.
55
+ Once you run the `init` command, you can initialize the folder as a Git repository with `git init` and push to the source control provider of your choice. When you are ready to deploy the changes, run `npx @ordergroove/smi-serve deploy`.
60
56
 
61
- ---
57
+ Make sure to commit the autogenerated `.gitignore`, which prevents you from committing the `.ogrc.json` file to source control. The `ogrc` file contains authentication tokens and should not be committed.
62
58
 
63
- The program provides several options to customize its behavior:
59
+ ### How do I merge in updates that have been made via the Subscription Manager editor in RC3?
64
60
 
65
- - `--verbose` or `-v`: Enable verbose logging.
66
- - `--outdir` or `-o`: Specify the output directory for build artifacts. Defaults to `node_modules/.smi-serve-build`.
67
- - `--port` or `-p`: Specify the HTTP port for the development server. Defaults to an available free port.
68
- - `--env` or `-e`: Specify the Ordergroove environment: prod or staging. Defaults to prod.
69
- - `--impersonate` or `-i`: Enable customer impersonation.
61
+ Ordergroove regularly makes updates to its Subscription Manager templates to fix bugs and add new features. To compare the latest changes with your current template files, first initialize the repo with a source control provider like Git and commit your current template files. You can then re-run the `init` command with the `-f` flag to overwrite your files with the latest Subscription Manager template. Use Git's diff tools to compare what has changed and add back any customizations as necessary.
70
62
 
71
- Example usage with options:
63
+ ## Limitations
72
64
 
73
- `npx @ordergroove/smi-serve serve --verbose --port 8080 --production`
65
+ - smi-serve only reads and writes from your currently published Subscription Manager theme. Draft themes are not currently supported.
66
+ - SSO users and My Organization admins are not currently supported.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ordergroove/smi-serve",
3
- "version": "1.7.4",
4
- "description": "Utility to serve a SMI template locally",
3
+ "version": "1.8.0",
4
+ "description": "Utility to serve a Subscription Manager template locally",
5
5
  "keywords": [],
6
6
  "author": "Eugenio Lattanzio <eugenio.lattanzio@ordergroove.com>",
7
7
  "license": "ISC",
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "memfs": "^4.8.2"
37
37
  },
38
- "gitHead": "150aa71aa473d76c6738352fafef37970aab7e36"
38
+ "gitHead": "3e6249c8cad48b89a413586ebfcbd82378873c1e"
39
39
  }
package/smi-serve.js CHANGED
@@ -10,7 +10,7 @@ const figures = require('figures');
10
10
  const { getcwd, getNetFreePort, readRcEnv } = require('./src/utils');
11
11
  const { cliCallSelectMerchant } = require('./src/select-merchant');
12
12
  const { deploy } = require('./src/deploy');
13
- const { init, DirNotEmpty } = require('./src/init');
13
+ const { init, DirNotEmpty, OG_RC_FILE } = require('./src/init');
14
14
  const { serve } = require('./src/serve');
15
15
 
16
16
  function box(text) {
@@ -63,7 +63,6 @@ Platform: ${merchant.ecommerce_platform}
63
63
  Alterations, additions, or deletions to the Subscription Manager will be visible to your customers
64
64
  in real-time after you deploy.\n`);
65
65
 
66
- if (args.verbose) console.log(args);
67
66
  try {
68
67
  await fn(args);
69
68
  console.log(`${figures.tick} SUCCESS`);
@@ -71,8 +70,8 @@ Platform: ${merchant.ecommerce_platform}
71
70
  if (err instanceof DirNotEmpty) {
72
71
  console.error(`${figures.cross} ERROR`);
73
72
  console.error(`\
74
- The directory is not empty and fetching will override your local changes
75
- try force fetch by using -f modifier
73
+ The directory is not empty and fetching will override your local changes.
74
+ To overwrite your local changes, re-run the command with "-f".
76
75
  `);
77
76
  } else {
78
77
  throw err;
@@ -82,88 +81,92 @@ try force fetch by using -f modifier
82
81
  }
83
82
 
84
83
  async function program() {
85
- return yargs(hideBin(process.argv))
86
- .command({
87
- command: 'select-merchant',
88
- describe: 'Select a different Ordergroove merchant',
89
- handler: wrapHandler(cliCallSelectMerchant)
90
- })
91
- .command({
92
- command: 'init',
93
- alias: ['fetch'],
94
- describe: 'Initialize the current directory with smi assets from og rc3',
95
- builder: y =>
96
- y
97
- .option('overwrite', {
98
- alias: 'f',
99
- type: 'boolean',
100
- description: 'Overwrite files if exists locally'
101
- })
102
- .option('entrypoint', {
103
- type: 'boolean',
104
- description: 'generate entrypoint.js'
105
- })
106
- .option('yes', {
107
- alias: 'y',
108
- type: 'boolean',
109
- description: 'Initilizes it with rc3 config, otherwise it prompts'
110
- }),
84
+ return (
85
+ yargs(hideBin(process.argv))
86
+ .command({
87
+ command: 'init',
88
+ alias: ['fetch'],
89
+ describe: 'Initialize the current directory with the assets from your live Subscription Manager theme',
90
+ builder: y =>
91
+ y
92
+ .option('overwrite', {
93
+ alias: 'f',
94
+ type: 'boolean',
95
+ description: 'Allow overwriting existing files'
96
+ })
97
+ .option('yes', {
98
+ alias: 'y',
99
+ type: 'boolean',
100
+ description: 'Skip prompts and initialize with your live theme'
101
+ }),
111
102
 
112
- handler: wrapHandler(init)
113
- })
114
- .command({
115
- command: 'deploy',
116
- describe: 'Deploy changes to ordergroove',
117
- handler: wrapHandler(deploy)
118
- })
119
- .command({
120
- command: '$0',
121
- alias: ['serve'],
122
- describe: 'Start the dev server',
123
- handler: wrapHandler(initOrServe)
124
- })
125
- .option('verbose', {
126
- alias: 'v',
127
- type: 'boolean',
128
- description: 'Run with verbose logging'
129
- })
130
- .option('outdir', {
131
- alias: 'o',
132
- type: 'string',
133
- default: 'node_modules/.smi-serve-build',
134
- description: 'Output directory'
135
- })
136
- .option('configFile', {
137
- alias: ['c', 'config-file'],
138
- type: 'string',
139
- default: '.ogrc.json',
140
- description: 'Ordergroove configuration file'
141
- })
142
- .option('cwd', {
143
- alias: ['w', 'working-dir'],
144
- type: 'string',
145
- default: '.',
146
- description: 'Sets the current working directory'
147
- })
148
- .option('port', {
149
- alias: 'p',
150
- type: 'number',
151
- description: 'http port',
152
- default: await getNetFreePort()
153
- })
154
- .option('impersonate', {
155
- alias: 'i',
156
- type: 'string',
157
- description: 'Enable customer impersonation'
158
- })
159
- .option('env', {
160
- alias: 'e',
161
- type: 'string',
162
- choices: ['prod', 'staging', 'local'],
163
- default: 'prod',
164
- description: 'Ordergroove enviromnet staging/prod'
165
- })
166
- .parse();
103
+ handler: wrapHandler(init)
104
+ })
105
+ .command({
106
+ command: '$0',
107
+ alias: ['serve'],
108
+ describe: 'Start the dev server',
109
+ handler: wrapHandler(initOrServe)
110
+ })
111
+ .command({
112
+ command: 'deploy',
113
+ describe: 'Publish your template changes to your live theme',
114
+ handler: wrapHandler(deploy)
115
+ })
116
+ .command({
117
+ command: 'select-merchant',
118
+ describe: 'Select a different Ordergroove merchant',
119
+ handler: wrapHandler(cliCallSelectMerchant)
120
+ })
121
+ .option('verbose', {
122
+ alias: 'v',
123
+ type: 'boolean',
124
+ description: 'Enable verbose logging'
125
+ })
126
+ .option('outdir', {
127
+ alias: 'o',
128
+ type: 'string',
129
+ default: 'node_modules/.smi-serve-build',
130
+ description: 'Where to output the bundle for local dev'
131
+ })
132
+ .option('configFile', {
133
+ alias: ['c', 'config-file'],
134
+ type: 'string',
135
+ default: OG_RC_FILE,
136
+ description: 'Name of the Ordergroove configuration file'
137
+ })
138
+ .option('cwd', {
139
+ alias: ['w', 'working-dir'],
140
+ type: 'string',
141
+ default: '.',
142
+ description: 'Path to the working directory. The directory must already exist.'
143
+ })
144
+ .option('port', {
145
+ alias: 'p',
146
+ type: 'number',
147
+ description: 'Which local port to run the dev server on',
148
+ default: await getNetFreePort()
149
+ })
150
+ .option('impersonate', {
151
+ alias: 'i',
152
+ type: 'string'
153
+ })
154
+ // impersonate only works for superusers; hide it from help for now
155
+ .hide('impersonate')
156
+ .option('env', {
157
+ alias: 'e',
158
+ type: 'string',
159
+ choices: ['prod', 'staging', 'local'],
160
+ default: 'prod',
161
+ description: 'Which Ordergroove environment to use'
162
+ })
163
+ .option('local-assets', {
164
+ type: 'boolean',
165
+ description: 'Use local SM packages'
166
+ })
167
+ .hide('local-assets')
168
+ .parse()
169
+ );
167
170
  }
168
171
 
169
172
  if (require.main === module) program();
package/smi-serve.spec.js CHANGED
@@ -62,8 +62,8 @@ describe('smi-serve', () => {
62
62
  },
63
63
  '/package.json': {
64
64
  author: '',
65
- description: 'Ordergroove SMI for test merchant on shopify platform (yum-id)}',
66
- keywords: ['Ordergroove SMI', 'test merchant', 'yum-id'],
65
+ description: 'Ordergroove Subscription Manager for test merchant on shopify platform (yum-id)}',
66
+ keywords: ['Ordergroove Subscription Manager', 'test merchant', 'yum-id'],
67
67
  main: 'views/main.liquid',
68
68
  ordergroove: {
69
69
  coreVersion: '0.31.6',
package/src/deploy.js CHANGED
@@ -135,7 +135,7 @@ async function deploy(args) {
135
135
  }
136
136
  );
137
137
  if (response.status === 201) {
138
- console.log('SMI changes deployed');
138
+ console.log('Subscription Manager changes deployed');
139
139
  } else {
140
140
  console.error(response.status, await response.text());
141
141
  }
@@ -65,10 +65,10 @@ async function impersonate(args) {
65
65
  console.log(`\
66
66
 
67
67
  -------------------------------------------------------------------------------
68
- Browsing SMI for customer: ${customer.first_name} ${customer.last_name} (${customer.email})
68
+ Browsing Subscription Manager for customer: ${customer.first_name} ${customer.last_name} (${customer.email})
69
69
 
70
70
  Please note:
71
- This tool browses the live SMI of the customer you are impersonating.
71
+ This tool browses the live Subscription Manager of the customer you are impersonating.
72
72
  Do not make any changes to orders/subscriptions as they will actually
73
73
  take effect. This tool is intended for troubleshooting and previewing
74
74
  only. Please use the CSA to edit order/subscription data.
package/src/init.js CHANGED
@@ -3,7 +3,7 @@ const fetch = require('node-fetch');
3
3
  const path = require('path');
4
4
  const inquirer = require('inquirer');
5
5
 
6
- const { chooseMerchant, getRC3Url } = require('./auth');
6
+ const { getRC3Url } = require('./auth');
7
7
  const {
8
8
  getcwd,
9
9
  exec,
@@ -16,7 +16,6 @@ const { serve } = require('./serve');
16
16
  const { getValidSettings } = require('./select-merchant');
17
17
 
18
18
  const SUBSCRIPTION_MANAGEMENT_ENDPOINT = 'msi';
19
- const SMI_CORE_NAME = '@ordergroove/smi-core';
20
19
  const SMI_TEMPLATES_NAME = '@ordergroove/smi-templates';
21
20
  const OG_RC_FILE = '.ogrc.json';
22
21
 
@@ -95,23 +94,32 @@ async function init(args) {
95
94
 
96
95
  let smiVersion = meta_fields?.dependencies['@ordergroove/smi-core'] || 'latest';
97
96
 
98
- const { useMerchantSpecific } = args.yes
99
- ? { useMerchantSpecific: true }
100
- : await inquirer.prompt([
101
- {
102
- type: 'list',
103
- name: 'useMerchantSpecific',
104
- message: 'What templates do you want to initialize it with?',
105
- choices: [
106
- { value: true, name: `Pull "${merchant.name}" templates stored in ${getRC3Url(args)}` },
107
- { value: false, name: 'Fresh install latest version of @ordergroove/smi-templates' }
108
- ]
109
- }
110
- ]);
97
+ const hasConfigs = msiConfigs.smi && msiConfigs.smi.files;
98
+ let useMerchantSpecific = true;
99
+
100
+ if (hasConfigs) {
101
+ let result = args.yes
102
+ ? { useMerchantSpecific: true }
103
+ : await inquirer.prompt([
104
+ {
105
+ type: 'list',
106
+ name: 'useMerchantSpecific',
107
+ message: 'Which templates do you want to use?',
108
+ choices: [
109
+ { value: true, name: `Pull the live theme for "${merchant.name}" from Ordergroove` },
110
+ { value: false, name: 'Use the latest files from the default Subscription Manager template' }
111
+ ]
112
+ }
113
+ ]);
114
+ ({ useMerchantSpecific } = result);
115
+ } else {
116
+ console.log('Configs not found, defaulting to latest Subscription Manager template.');
117
+ useMerchantSpecific = false;
118
+ }
111
119
 
112
120
  let smiTemplateVersion;
113
121
 
114
- if (useMerchantSpecific && msiConfigs.smi && msiConfigs.smi.files) {
122
+ if (useMerchantSpecific) {
115
123
  if (msiConfigs.provisioned_with && SMI_TEMPLATES_NAME in msiConfigs.provisioned_with) {
116
124
  smiTemplateVersion = msiConfigs.provisioned_with[SMI_TEMPLATES_NAME];
117
125
  }
@@ -124,8 +132,6 @@ async function init(args) {
124
132
 
125
133
  console.log('Templates initialized');
126
134
  } else {
127
- console.log('Configs not found, defaulting to latest.');
128
-
129
135
  smiTemplateVersion = await getMerchantTemplatesVersion(smiVersion);
130
136
 
131
137
  await downloadAndExtract(
@@ -140,34 +146,6 @@ async function init(args) {
140
146
  smiVersion = 'latest';
141
147
  }
142
148
 
143
- // skip this for now
144
- const installEntrypoint = args.entrypoint;
145
-
146
- // this auth_config will be the one in rc, since sos will update
147
- // it with whatever is on subscription-settings endpoint
148
- //
149
- // const { configs: merchantSettings } = await getConfigs(SUBSCRIPTION_SETTINGS_ENDPOINT, merchant, token);
150
- // const auth_config = {
151
- // auth_url: merchantSettings.authUrl,
152
- // env: merchantSettings.env
153
- // };
154
-
155
- const auth_config = {};
156
-
157
- //
158
- if (installEntrypoint) {
159
- // put some runtime config with merchant id
160
- fs.writeFileSync(
161
- './runtime-config.js',
162
- `\
163
- export const merchant_id = ${JSON.stringify(merchant.public_id)};
164
- export const auth_config = ${JSON.stringify(auth_config)};
165
- `
166
- );
167
-
168
- fs.writeFileSync('entrypoint.js', fs.readFileSync(`${__dirname}/../entrypoint.js`, 'utf8'));
169
- }
170
-
171
149
  // write a .gitignore just in case
172
150
  fs.writeFileSync(
173
151
  path.join(args.cwd, '.gitignore'),
@@ -182,10 +160,10 @@ node_modules/
182
160
  start: 'smi-serve',
183
161
  deploy: 'smi-serve deploy'
184
162
  },
185
- description: `Ordergroove SMI for ${merchant.name} on ${merchant.ecommerce_platform} platform (${merchant.public_id})}`,
163
+ description: `Ordergroove Subscription Manager for ${merchant.name} on ${merchant.ecommerce_platform} platform (${merchant.public_id})}`,
186
164
  author: getAuthorNameFromToken(token),
187
- main: installEntrypoint ? 'entrypoint.js' : 'views/main.liquid',
188
- keywords: ['Ordergroove SMI', merchant.name, merchant.public_id],
165
+ main: 'views/main.liquid',
166
+ keywords: ['Ordergroove Subscription Manager', merchant.name, merchant.public_id],
189
167
  [packageJsonKeys.OG_SECTION]: {
190
168
  [packageJsonKeys.CORE_VERSION]: smiVersion,
191
169
  [packageJsonKeys.TEMPLATES_VERSION]: smiTemplateVersion
@@ -1,5 +1,5 @@
1
1
  // virtual JSON file containing build-time variables
2
- import { OG_ENV, OG_MERCHANT_ID, OG_HMAC_AUTH, OG_SMI_CORE_VERSION } from 'virtual:globals.json';
2
+ import { OG_ENV, OG_MERCHANT_ID, OG_HMAC_AUTH, OG_SMI_CORE_VERSION, OG_LOCAL_ASSETS } from 'virtual:globals.json';
3
3
 
4
4
  const params = new URLSearchParams(window.location.search);
5
5
 
@@ -17,3 +17,5 @@ export const auth_config = params.has('auth')
17
17
  : null;
18
18
 
19
19
  export const smi_core_version = OG_SMI_CORE_VERSION;
20
+
21
+ export const use_local_assets = OG_LOCAL_ASSETS;
@@ -1,16 +1,18 @@
1
1
  // ~/ refers to the working directory of the project using smi-serve
2
2
  import mainTemplate from '~/views/main.liquid';
3
3
 
4
- import { merchant_id, auth_config, smi_core_version } from './devmode';
4
+ import { merchant_id, auth_config, smi_core_version, use_local_assets } from './devmode';
5
+
6
+ const baseUrl = use_local_assets
7
+ ? 'http://localhost:8080'
8
+ : `https://static.ordergroove.com/@ordergroove/smi-core/${smi_core_version}/dist`;
5
9
 
6
10
  // only run on initial load, not hot reload
7
11
  if (!window.og?.smi) {
8
12
  if (auth_config && merchant_id) {
9
- waitForScriptToLoad(`https://static.ordergroove.com/@ordergroove/smi-core/${smi_core_version}/dist/smi.js`).then(
10
- () => {
11
- window.og.smi.bootstrap({ merchant_id, ...auth_config }, mainTemplate);
12
- }
13
- );
13
+ waitForScriptToLoad(`${baseUrl}/smi.js`).then(() => {
14
+ window.og.smi.bootstrap({ merchant_id, ...auth_config }, mainTemplate);
15
+ });
14
16
  } else {
15
17
  waitForScriptToLoad(`https://static.ordergroove.com/@ordergroove/smi-preview/latest/`).then(() => {
16
18
  const smiPreview = window.og['smi-preview'];
@@ -1,6 +1,6 @@
1
1
  <html>
2
2
  <head>
3
- <title>SMI Demo Page</title>
3
+ <title>Subscription Manager Demo Page</title>
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
6
  <link rel="stylesheet" href="/main.css" />
package/src/serve.js CHANGED
@@ -27,7 +27,8 @@ async function getGlobals(argv) {
27
27
  OG_MERCHANT_ID: merchant ? merchant.public_id : '',
28
28
  OG_HMAC_AUTH: hmacAuth,
29
29
  OG_ENV: argv.env,
30
- OG_SMI_CORE_VERSION: smiCoreVersion
30
+ OG_SMI_CORE_VERSION: smiCoreVersion,
31
+ OG_LOCAL_ASSETS: !!argv.localAssets
31
32
  };
32
33
  }
33
34
 
@@ -50,13 +51,25 @@ const smiDevModePlugin = (globals, args) => {
50
51
  }))
51
52
  );
52
53
 
53
- const contents = await precompile(fileList);
54
-
55
- return {
56
- watchFiles: files,
57
- contents: `export default ${contents}`,
58
- loader: 'js'
59
- };
54
+ try {
55
+ const contents = await precompile(fileList);
56
+ return {
57
+ watchFiles: files,
58
+ contents: `export default ${contents}`,
59
+ loader: 'js'
60
+ };
61
+ } catch (e) {
62
+ return {
63
+ watchFiles: files,
64
+ errors: [
65
+ {
66
+ text: e.toString(),
67
+ detail: e
68
+ }
69
+ ],
70
+ loader: 'js'
71
+ };
72
+ }
60
73
  });
61
74
 
62
75
  // allow importing a non-existent 'virtual:globals.json' file containing build-time variables
@@ -90,14 +103,14 @@ async function serve(argv) {
90
103
  await getValidLoginAndCurrentMerchant(argv);
91
104
  const { port, outdir, verbose } = argv;
92
105
 
93
- const [mainLiquid] = await glob('**/main.liquid');
94
- const [mainLess] = await glob('**/main.@(less|css)');
106
+ const cwd = getcwd(argv);
107
+ const [mainLiquid] = await glob('**/main.liquid', { cwd });
108
+ const [mainLess] = await glob('**/main.@(less|css)', { cwd });
95
109
 
96
110
  if (!mainLiquid) {
97
- throw new Error('main.liquid not found, please create a main.liquid file under src/views/main.liquid');
111
+ throw new Error('You need a main.liquid file in the /views folder to run the Subscription Manager.');
98
112
  }
99
113
 
100
- const cwd = getcwd(argv);
101
114
  fs.mkdirSync(path.join(cwd, outdir), { recursive: true });
102
115
 
103
116
  const smiIndexFile = path.join(cwd, outdir, 'index.html');
@@ -108,7 +121,7 @@ async function serve(argv) {
108
121
 
109
122
  /** @type {import('esbuild').BuildOptions} */
110
123
  const buildConf = {
111
- entryPoints: [path.join(__dirname, 'partials', 'entrypoint.js'), mainLess],
124
+ entryPoints: [path.join(__dirname, 'partials', 'entrypoint.js'), path.join(cwd, mainLess)],
112
125
  entryNames: '[name]',
113
126
 
114
127
  logLevel: verbose ? 'verbose' : 'error',
@@ -127,7 +140,7 @@ async function serve(argv) {
127
140
  };
128
141
 
129
142
  if (!mainLess) {
130
- console.warn('styles not found, you can create a main.less file under src/styles/main.less');
143
+ console.warn('No styles found. To apply CSS, create a main.less file inside the /styles folder.');
131
144
  }
132
145
 
133
146
  const ctx = await esbuild.context(buildConf);
@@ -136,23 +149,10 @@ async function serve(argv) {
136
149
 
137
150
  const { port: actualPort, host: actualHost } = await ctx.serve({
138
151
  servedir: path.join(cwd, outdir),
139
- // host,
140
152
  port
141
153
  });
142
154
 
143
155
  console.log(`Dev server listening on http://${actualHost}:${actualPort}`);
144
156
  open(`http://${actualHost}:${actualPort}`);
145
-
146
- const result = await esbuild.build({
147
- metafile: true,
148
- ...buildConf
149
- });
150
-
151
- const text = await esbuild.analyzeMetafile(result.metafile, {
152
- verbose: true
153
- });
154
- fs.writeFileSync(path.join(cwd, outdir, 'bundle-report.html'), `<pre id="esbuild-metadata">${text}</pre>`);
155
-
156
- return result;
157
157
  }
158
158
  exports.serve = serve;