@ordergroove/smi-serve 1.9.5 → 1.9.6

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,14 @@
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.9.6](https://github.com/ordergroove/plush-toys/compare/@ordergroove/smi-serve@1.9.5...@ordergroove/smi-serve@1.9.6) (2024-11-13)
7
+
8
+ **Note:** Version bump only for package @ordergroove/smi-serve
9
+
10
+
11
+
12
+
13
+
6
14
  ## [1.9.5](https://github.com/ordergroove/plush-toys/compare/@ordergroove/smi-serve@1.9.4...@ordergroove/smi-serve@1.9.5) (2024-11-13)
7
15
 
8
16
  **Note:** Version bump only for package @ordergroove/smi-serve
package/README.md CHANGED
@@ -12,7 +12,7 @@ To initialize the current directory for local Subscription Manager development,
12
12
 
13
13
  After initialization, you can restart the dev server with `npx @ordergroove/smi-serve`.
14
14
 
15
- When you are ready to push your changes to production, run `npx @ordergroove/smi-serve deploy` to deploy your changes to Ordergroove.
15
+ When you are ready to push your changes, run `npx @ordergroove/smi-serve push-theme` to deploy your changes to Ordergroove. If the theme you're pushing is live, your changes will be published immediately!
16
16
 
17
17
  ## Configuration file
18
18
 
@@ -26,7 +26,7 @@ To see all available commands and flags, run `npx @ordergroove/smi-serve --help`
26
26
 
27
27
  ### init
28
28
 
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`.
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`. To pull new assets, use the `pull-theme` command.
30
30
 
31
31
  ### serve
32
32
 
@@ -34,9 +34,13 @@ Starts a development server. This is the default command, so it can also be run
34
34
 
35
35
  By default it will choose a random available port, but you can customize this with the `--port` flag.
36
36
 
37
- ### deploy
37
+ ### pull-theme
38
38
 
39
- Publishes your template changes to your live Subscription Manager theme. Before publishing, it will summarize which files have changed and ask for confirmation.
39
+ Presents you with a list of your Subscription Manager themes including your live theme. Selecting a theme will overwrite the files in your present working directory.
40
+
41
+ ### push-theme
42
+
43
+ Publishes your template changes to your selected Subscription Manager theme. If the theme you're pushing is your live theme, your changes will be published to your live site immediately!
40
44
 
41
45
  ### select-merchant
42
46
 
@@ -52,7 +56,7 @@ Keep in mind that if you use this flag, _every command_ you run must also includ
52
56
 
53
57
  ### How do I integrate with source control?
54
58
 
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`.
59
+ 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 push-theme`.
56
60
 
57
61
  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.
58
62
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ordergroove/smi-serve",
3
- "version": "1.9.5",
3
+ "version": "1.9.6",
4
4
  "description": "Utility to serve a Subscription Manager template locally",
5
5
  "keywords": [],
6
6
  "author": "Eugenio Lattanzio <eugenio.lattanzio@ordergroove.com>",
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "memfs": "^4.8.2"
37
37
  },
38
- "gitHead": "650556b3c6597053a1d8040bad47986358c84bf6"
38
+ "gitHead": "c521e348e2da6908ba2e6daab6c6fe204a3953d6"
39
39
  }
package/smi-serve.js CHANGED
@@ -10,7 +10,6 @@ const figures = require('figures');
10
10
  const { getcwd, getNetFreePort, readRcEnv } = require('./src/utils');
11
11
  const { cliCallSelectMerchant } = require('./src/select-merchant');
12
12
  const { cliPullTheme, getMerchantThemes } = require('./src/pull-theme');
13
- const { deploy } = require('./src/deploy');
14
13
  const { cliPushTheme } = require('./src/push-theme');
15
14
  const { init, DirNotEmpty, OG_RC_FILE } = require('./src/init');
16
15
  const { serve } = require('./src/serve');
@@ -110,11 +109,6 @@ async function program() {
110
109
  describe: 'Start the dev server',
111
110
  handler: wrapHandler(initOrServe)
112
111
  })
113
- .command({
114
- command: 'deploy',
115
- describe: 'Publish your template changes to your live theme',
116
- handler: wrapHandler(deploy)
117
- })
118
112
  .command({
119
113
  command: 'select-merchant',
120
114
  describe: 'Select a different Ordergroove merchant',
package/smi-serve.spec.js CHANGED
@@ -87,7 +87,6 @@ describe('smi-serve', () => {
87
87
  templatesVersion: '0.40.1'
88
88
  },
89
89
  scripts: {
90
- deploy: 'smi-serve deploy',
91
90
  start: 'smi-serve'
92
91
  }
93
92
  },
package/src/init.js CHANGED
@@ -159,8 +159,7 @@ node_modules/
159
159
 
160
160
  await updateJsonFile(path.join(args.cwd, 'package.json'), {
161
161
  scripts: {
162
- start: 'smi-serve',
163
- deploy: 'smi-serve deploy'
162
+ start: 'smi-serve'
164
163
  },
165
164
  description: `Ordergroove Subscription Manager for ${merchant.name} on ${merchant.ecommerce_platform} platform (${merchant.public_id})}`,
166
165
  author: getAuthorNameFromToken(token),
package/src/deploy.js DELETED
@@ -1,143 +0,0 @@
1
- const fs = require('fs');
2
- const fetch = require('node-fetch');
3
- const util = require('util');
4
- const inquirer = require('inquirer');
5
- const glob = util.promisify(require('glob'));
6
- const { getRC3Url } = require('./auth');
7
- const { getcwd, readPackageJson, packageJsonKeys } = require('./utils');
8
- const { getValidSettings } = require('./select-merchant');
9
-
10
- function reportDiffFiles(original, newRequest) {
11
- const originalFiles =
12
- ((original.configs && original.configs.smi && original.configs.smi.files) || []).reduce(
13
- (acc, cur) => ({ ...acc, [cur.name]: cur.content }),
14
- {}
15
- ) || {};
16
-
17
- const newFiles =
18
- ((newRequest.configs && newRequest.configs.smi && newRequest.configs.smi.files) || []).reduce(
19
- (acc, cur) => ({ ...acc, [cur.name]: cur.content }),
20
- {}
21
- ) || {};
22
-
23
- const diff = [...new Set([...Object.keys(newFiles), ...Object.keys(originalFiles)])].filter(
24
- key => newFiles[key] !== originalFiles[key]
25
- );
26
-
27
- if (diff.length === 0) {
28
- console.log('Nothing to push');
29
- return;
30
- }
31
-
32
- const status = name => {
33
- if (originalFiles[name] && newFiles[name]) {
34
- return '[CHANGED]';
35
- }
36
- if (originalFiles[name]) {
37
- return '[REMOVED]';
38
- }
39
- if (newFiles[name]) {
40
- return '[ADDED]';
41
- }
42
- return '';
43
- };
44
-
45
- process.stdout.write(`\
46
- The following changed files will be pushed:
47
- `);
48
-
49
- diff.forEach(name =>
50
- process.stdout.write(`\
51
- - ${name.padEnd(60, '.')} ${status(name)}
52
- `)
53
- );
54
- }
55
- async function deploy(args) {
56
- let { token, merchant } = await getValidSettings(args);
57
-
58
- const ignoreFiles = [
59
- '**/node_modules/**',
60
- 'node_modules/**',
61
- '**/README.md',
62
- '**/package.json',
63
- '**/package-lock.json'
64
- ];
65
-
66
- const files = await glob(`${getcwd(args)}/**/*.*`, { ignore: ignoreFiles });
67
-
68
- const fileList = await Promise.all(
69
- files.map(async file => ({
70
- name: file.substring(getcwd(args).length),
71
- content: await fs.promises.readFile(file, 'utf8')
72
- }))
73
- );
74
-
75
- let original;
76
-
77
- try {
78
- const res = await fetch(
79
- `${getRC3Url(args)}configs/msi/?${new URLSearchParams([['merchant_public_id', merchant.public_id]])}`,
80
- {
81
- headers: { Authorization: `Bearer ${token}` }
82
- }
83
- );
84
- if (res.status === 200) {
85
- original = await res.json().catch(() => ({ configs: {} }));
86
- } else {
87
- original = { configs: {} };
88
- }
89
- } catch (err) {
90
- console.log(err);
91
- }
92
-
93
- const packageJson = readPackageJson(getcwd(args));
94
- const smiTemplatesVersion = packageJson[packageJsonKeys.OG_SECTION]?.[packageJsonKeys.TEMPLATES_VERSION];
95
-
96
- const newRequest = {
97
- ...original,
98
- configs: {
99
- ...original.configs,
100
- smi: {
101
- ...((original.configs && original.configs.smi) || {}),
102
- files: fileList
103
- },
104
- ...(smiTemplatesVersion && { provisioned_with: { '@ordergroove/smi-templates': smiTemplatesVersion } })
105
- }
106
- };
107
-
108
- reportDiffFiles(original, newRequest);
109
-
110
- const { ok } = args.yes
111
- ? { ok: true }
112
- : await inquirer.prompt([
113
- {
114
- type: 'list',
115
- name: 'ok',
116
- message: 'Do you want to proceed?',
117
- choices: [
118
- { value: true, name: `Yes` },
119
- { value: false, name: 'No' }
120
- ]
121
- }
122
- ]);
123
-
124
- if (!ok) return;
125
-
126
- const response = await fetch(
127
- `${getRC3Url(args)}/configs/msi/?${new URLSearchParams([['merchant_public_id', merchant.public_id]])}`,
128
- {
129
- method: 'post',
130
- headers: {
131
- Authorization: `Bearer ${token}`,
132
- 'Content-Type': 'application/json'
133
- },
134
- body: JSON.stringify(newRequest)
135
- }
136
- );
137
- if (response.status === 201) {
138
- console.log('Subscription Manager changes deployed');
139
- } else {
140
- console.error(response.status, await response.text());
141
- }
142
- }
143
- exports.deploy = deploy;