@madebyseed/seed-cli-tools 1.0.1 → 1.2.1

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/src/utils.js CHANGED
@@ -1,6 +1,7 @@
1
- import spawn from "cross-spawn";
1
+ import spawn from "cross-spawn";
2
2
  import { join } from "path";
3
- import config from "./config"
3
+ import { readFileSync, writeFileSync } from "fs";
4
+ import config from "./config";
4
5
 
5
6
  /**
6
7
  * Wrappers for Shopify CLI commands
@@ -10,81 +11,150 @@ import config from "./config"
10
11
  * @memberof seed-cli
11
12
  */
12
13
  export const shopifyCLI = {
13
-
14
14
  /**
15
15
  * shopify login
16
- *
16
+ *
17
17
  * @memberof seed-cli.shopifyCLI
18
18
  * @param {string} store - store's myshopify domain name
19
19
  * @param {boolean} async - login asynchronously
20
- *
20
+ *
21
21
  * @returns {object} - spawnSync object or, node's <ChildProcess> object if async
22
22
  */
23
23
  login: (store, async = false) => {
24
- const args = ['login', '--store', store];
24
+ const args = ["login", "--store", store];
25
25
  const options = {
26
26
  env: process.env,
27
27
  stdio: "inherit",
28
28
  shell: true,
29
- }
30
-
31
- if (async)
32
- return spawn('shopify', args, options);
33
- else
34
- return spawn.sync('shopify', args, options);
29
+ };
30
+
31
+ if (async) return spawn("shopify", args, options);
32
+ else return spawn.sync("shopify", args, options);
35
33
  },
36
34
 
37
35
  /**
38
36
  * shopify theme serve
39
- *
37
+ *
40
38
  * @memberof seed-cli.shopifyCLI
41
39
  * @returns {object} - node's ChildProcess
42
40
  */
43
- serve: () => {
44
- return spawn('shopify theme', ['serve'], {
45
- cwd: config.themeRoot + '/dist',
41
+ serve: (options = {}) => {
42
+ return spawn("shopify theme", ["serve"], {
43
+ cwd: config.themeRoot + "/dist",
46
44
  env: process.env,
47
45
  stdio: "inherit",
48
46
  shell: true,
49
- })
47
+ ...options,
48
+ });
50
49
  },
51
50
 
52
51
  /**
53
52
  * shopify theme push
54
- *
53
+ *
55
54
  * @memberof seed-cli.shopifyCLI
56
55
  * @returns {object} - node's ChildProcess
57
56
  */
58
- push: () => {
59
- return spawn('shopify theme', ['push'], {
60
- cwd: config.themeRoot + '/dist',
57
+ pull: (themeId = null, dir = "./src") => {
58
+ let args = ["pull"];
59
+ if (themeId) args = args.concat(["--themeid", themeId, dir]);
60
+
61
+ return spawn("shopify theme", args, {
61
62
  env: process.env,
62
63
  stdio: "inherit",
63
64
  shell: true,
64
- })
65
- }
66
- }
65
+ });
66
+ },
67
+
68
+ /**
69
+ * shopify theme push
70
+ *
71
+ * @memberof seed-cli.shopifyCLI
72
+ * @returns {object} - node's ChildProcess
73
+ */
74
+ push: (themeId = null) => {
75
+ let args = ["push", "--nodelete"];
76
+ if (themeId) args = args.concat(["--themeid", themeId]);
77
+
78
+ return spawn("shopify theme", args, {
79
+ cwd: config.themeRoot + "/dist",
80
+ env: process.env,
81
+ stdio: "inherit",
82
+ shell: true,
83
+ });
84
+ },
85
+ };
67
86
 
68
87
  /**
69
88
  * Get seed.config.js from project root dir
70
- *
89
+ *
71
90
  * @param {string} themeRoot - the path to theme root dir
72
91
  */
73
92
  export function getSeedConfig(themeRoot) {
74
- return require(join(themeRoot, 'seed.config.js'));
93
+ return require(join(themeRoot, "seed.config.js"));
75
94
  }
76
95
 
77
96
  /**
78
- * Get store name from seed.config.js
79
- *
97
+ * Get store name from seed.config.js
98
+ *
80
99
  * @param {string} themeRoot - the path to theme root dir
81
100
  */
82
101
  export function getStoreName(themeRoot) {
83
102
  return getSeedConfig(themeRoot).store;
84
103
  }
85
104
 
105
+ /**
106
+ * Get theme ID from seed.config.js
107
+ *
108
+ * @param {string} themeRoot - the path to theme root dir
109
+ * @param {string} environment - theme name/environment
110
+ * @returns {string} themeID
111
+ */
112
+ export function getThemeID(themeRoot, environment) {
113
+ return getSeedConfig(themeRoot).themes[environment];
114
+ }
86
115
 
116
+ /**
117
+ * Get dev theme ID from seed.config.js
118
+ *
119
+ * @param {string} themeRoot - the path to theme root dir
120
+ * @returns {string} - development store theme ID
121
+ */
122
+ export function getDevThemeID(themeRoot) {
123
+ return getSeedConfig(themeRoot).developmentThemeId;
124
+ }
87
125
 
126
+ /**
127
+ * Given a string, finds the first themeID and returns it, if no themeID found
128
+ * returns false.
129
+ *
130
+ * @param {string} string - string to extract theme id from
131
+ * @return {string|boolean} - themeID or false if not found
132
+ */
133
+ export function extractThemeId(string) {
134
+ const regex = /\d{12}/;
135
+ const match = string.match(regex);
136
+ return match && match.length ? match[0] : false;
137
+ }
88
138
 
139
+ /**
140
+ * Logs out to terminal the output of a piped child process
141
+ *
142
+ * @param {child_process} serveProcess shopify cli serve spawned child process
143
+ */
144
+ export function logChildProcessOutput(process) {
145
+ process.stdout.on("data", (data) => {
146
+ console.log(data);
147
+ });
148
+ }
89
149
 
90
-
150
+ /**
151
+ * Writes the development theme ID as a key to seed config file
152
+ *
153
+ * @param {string} themeID - development theme ID
154
+ */
155
+ export function setDevThemeID(themeID) {
156
+ let data = readFileSync(config.seedConfig, { encoding: "utf8" });
157
+ data = data.split(config.seedConfigDelimiter);
158
+ data[1] = `\n developmentThemeId: '${themeID}'` + "\n};";
159
+ writeFileSync(config.seedConfig, data.join(config.seedConfigDelimiter));
160
+ }
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- var gulp = require('gulp');
4
-
5
- var utils = require('./includes/utilities.js');
6
- /**
7
- * Initiates shopify's cli command 'shopify theme push' on the dist folder,
8
- * pushing it to stores theme
9
- *
10
- * @function deploy:dist
11
- * @memberof seed-cli.tasks.deploy
12
- * @static
13
- */
14
-
15
-
16
- gulp.task('deploy:dist', function () {
17
- console.log("Running Shopify theme push on ./dist...");
18
- return utils.deployDist();
19
- });
@@ -1,15 +0,0 @@
1
- const gulp = require('gulp');
2
- const utils = require('./includes/utilities.js');
3
-
4
- /**
5
- * Initiates shopify's cli command 'shopify theme push' on the dist folder,
6
- * pushing it to stores theme
7
- *
8
- * @function deploy:dist
9
- * @memberof seed-cli.tasks.deploy
10
- * @static
11
- */
12
- gulp.task('deploy:dist', () => {
13
- console.log("Running Shopify theme push on ./dist...")
14
- return utils.deployDist();
15
- })