@madebyseed/seed-cli-tools 1.2.5 → 1.3.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.
@@ -11,17 +11,22 @@ var _debug = _interopRequireDefault(require("debug"));
11
11
 
12
12
  var _config = _interopRequireDefault(require("../config"));
13
13
 
14
+ var _utils = require("../utils");
15
+
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
17
 
16
18
  var logger = (0, _debug["default"])("seed-tools:deploy");
17
19
 
18
20
  function _default(program) {
19
- program.command("deploy").alias("d").description("Runs a full deploy of your theme's code to a Shopify store specified in seed.config.js. This runs shopify theme push with the --nodelete flag, so that files aren't deleted.").option("-e, --env <environment>[,<environment>...]", "Shopify store(s) to deploy code to (specified in seed.config.js)", "development").option("-s, --skip-optimizations", "Skips asset optimization steps such as compression, minification and purging.", false).action(function () {
21
+ program.command("deploy").alias("d").description("Runs a full deploy of your theme's code to a Shopify store specified in seed.config.js. This runs shopify theme push with the --nodelete flag, so that files aren't deleted.").option("-e, --env <environment>[,<environment>...]", "Shopify store(s) to deploy code to (specified in seed.config.js)", "development").option("-n, --no-dev", "Skips pulling theme settings from local development theme", false).option("-s, --skip-optimizations", "Skips asset optimization steps such as compression, minification and purging.", false).option("-d, --delete", "By default seed deploy runs 'shopify theme push --nodelete'. With this option it will leave out the --no-delete flag, allowind files to be delete in store theme.", false).action(function () {
20
22
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
21
23
  logger("--gulpfile ".concat(_config["default"].gulpFile));
22
24
  logger("--cwd ".concat(_config["default"].themeRoot));
23
- var args = ["deploy", "--environment", options.env];
24
- if (options.skipOptimizations) args.push("--skip-optimization");else process.env.NODE_ENV = "production";
25
+ if (!(0, _utils.login)()) return;
26
+ var args = [options.dev ? "deploy" : "deploy:no-sync", "--environment", options.env];
27
+ if (options.skipOptimizations) args.push('--skip-optimizations');
28
+ if (options["delete"]) args.push('--delete');
29
+ if (!options.skipOptimizations) process.env.NODE_ENV = "production";
25
30
  (0, _crossSpawn["default"])(_config["default"].gulp, args.concat(["--gulpfile", _config["default"].gulpFile, "--cwd", _config["default"].themeRoot]), {
26
31
  detached: false,
27
32
  stdio: "inherit"
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = _default;
7
+
8
+ var _crossSpawn = _interopRequireDefault(require("cross-spawn"));
9
+
10
+ var _debug = _interopRequireDefault(require("debug"));
11
+
12
+ var _config = _interopRequireDefault(require("../config"));
13
+
14
+ var _utils = require("../utils");
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
17
+
18
+ var logger = (0, _debug["default"])("seed-tools:deploy");
19
+
20
+ function _default(program) {
21
+ program.command("pull").alias("p").description("Pulls the specified theme into your src folder. By default, it only pulls theme settings, if you want to pull all files use the --all flag.").option("-e, --env <environment>[,<environment>...]", "Shopify store(s) to deploy code to (specified in seed.config.js)", "development").option("-a, --all", "Pulls all files from specified theme", false).option("-d, --delete", "By default seed pull doesn't delete any files in you src folder, with this options it will delete any files that diverge from the pulled theme.", false).action(function () {
22
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
23
+ logger("--gulpfile ".concat(_config["default"].gulpFile));
24
+ logger("--cwd ".concat(_config["default"].themeRoot));
25
+ if (!(0, _utils.login)()) return;
26
+ var args = [options.all ? "pull" : "pull:settings", "--environment", options.env];
27
+ if (options.all) args.push('--all');
28
+ if (options["delete"]) args.push('--delete');
29
+ (0, _crossSpawn["default"])(_config["default"].gulp, args.concat(["--gulpfile", _config["default"].gulpFile, "--cwd", _config["default"].themeRoot]), {
30
+ detached: false,
31
+ stdio: "inherit"
32
+ });
33
+ });
34
+ }
@@ -5,10 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports["default"] = _default;
7
7
 
8
- var _chalk = require("chalk");
9
-
10
- var _figures = _interopRequireDefault(require("figures"));
11
-
12
8
  var _crossSpawn = _interopRequireDefault(require("cross-spawn"));
13
9
 
14
10
  var _debug = _interopRequireDefault(require("debug"));
@@ -26,27 +22,7 @@ function _default(program) {
26
22
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
27
23
  logger("--gulpfile ".concat(_config["default"].gulpFile));
28
24
  logger("--cwd ".concat(_config["default"].themeRoot));
29
- var store = (0, _utils.getStoreName)(_config["default"].themeRoot);
30
-
31
- if (!store) {
32
- console.log("");
33
- console.log((0, _chalk.red)(" ".concat(_figures["default"].cross, " no store field in seed.config.js")));
34
- console.log(" Add 'store: <store.myshopify.com>' to your project seed.config.js");
35
- console.log("");
36
- return;
37
- }
38
-
39
- console.log("Logging into ".concat((0, _chalk.yellow)(store), " with Shopify CLI..."));
40
-
41
- var loginProcess = _utils.shopifyCLI.login(store);
42
-
43
- if (loginProcess.error) {
44
- console.log("");
45
- console.log((0, _chalk.red)(" ".concat(_figures["default"].cross, " Failed logging into ").concat(store, ", are you sure you're using the correct account?")));
46
- console.log("");
47
- return;
48
- }
49
-
25
+ if (!(0, _utils.login)()) return;
50
26
  var gulpArgs = ["watch", "--gulpfile", _config["default"].gulpFile, "--cwd", _config["default"].themeRoot, "--environment", options.env];
51
27
  if (!options.optimize) gulpArgs.push("--skip-optimizations");
52
28
  process.env.NODE_ENV = options.optimize ? 'production' : 'development';
package/lib/gulpfile.js CHANGED
@@ -45,9 +45,29 @@ gulp.task("sync-settings", gulp.series("generate:tmp", "shopify:pull:dev:tmp", "
45
45
 
46
46
  gulp.task("watch", gulp.series("build", gulp.parallel("watch:src", "watch:dist", "shopify:serve:dist")));
47
47
  /**
48
- * Does a full (re)build followed by a full deploy, cleaning existing files on
49
- * the remote server and replacing them with the full set of files pushed to
50
- * `dist` in the build
48
+ *
49
+ * @summary pulls theme from specified environment theme into src
50
+ * @function deploy
51
+ * @memberof slate-cli.tasks.deploy
52
+ * @static
53
+ */
54
+
55
+ gulp.task("pull", gulp.series("shopify:pull:origin:src"));
56
+ /**
57
+ * Does a full (re)build and push dist files into specified theme environment,
58
+ * theme using shopify theme push, by default with the --no-delete flag
59
+ *
60
+ * @summary pulls theme settings from specified environment theme into src
61
+ * @function deploy
62
+ * @memberof slate-cli.tasks.deploy
63
+ * @static
64
+ */
65
+
66
+ gulp.task("pull:settings", gulp.series("generate:tmp", "shopify:pull:origin:tmp", "sync-settings:tmp:src"));
67
+ /**
68
+ * Syncronizes src folder theme settings with local development theme settings,
69
+ * then proceeds to do a full (re)build and push files into specified theme
70
+ * environment theme using shopify theme push, by default with the --no-delete flag
51
71
  *
52
72
  * @summary Deploy your built files to the Shopify Store set in
53
73
  * `slate-cli.config`
@@ -56,4 +76,16 @@ gulp.task("watch", gulp.series("build", gulp.parallel("watch:src", "watch:dist",
56
76
  * @static
57
77
  */
58
78
 
59
- gulp.task("deploy", gulp.series("sync-settings", "build", "shopify:push:dist"));
79
+ gulp.task("deploy", gulp.series("sync-settings", "build", "shopify:push:dist"));
80
+ /**
81
+ * Does a full (re)build and push dist files into specified theme environment,
82
+ * theme using shopify theme push, by default with the --no-delete flag
83
+ *
84
+ * @summary Deploy your built files to the Shopify Store set in
85
+ * `slate-cli.config`
86
+ * @function deploy
87
+ * @memberof slate-cli.tasks.deploy:no-sync
88
+ * @static
89
+ */
90
+
91
+ gulp.task("deploy:no-sync", gulp.series("build", "shopify:push:dist"));
@@ -88,6 +88,7 @@ gulp.task("generate:tmp", function () {
88
88
  */
89
89
 
90
90
  gulp.task("sync-settings:tmp:src", function () {
91
+ messages.logProcessFiles('Syncronizing /tmp theme settings with /src');
91
92
  return copyFiles(themeSettingsAssets, {
92
93
  base: config.tmp.root
93
94
  }, config.src.root);
@@ -40,6 +40,10 @@ try {
40
40
  * @memberof seed-cli
41
41
  * @summary Configuring seed-cli
42
42
  * @prop {String} environment - development | staging | production
43
+ * @prop {Boolean} optimize - whether optimize assets or not
44
+ * @prop {Boolean} nodelete - run shopiy cli commands with --no-delete flag
45
+ * @prop {String} tailwindConfig - tailwind config filename
46
+ * @prop {String} seedConfig - seed config filename
43
47
  * @prop {String} deployLog - path to deploy log file
44
48
  * @prop {String} src - globs (multi-filename matching patterns) for various source files
45
49
  * @prop {String} tmp - globs (multi-filename matching patterns) for various tmp files
@@ -52,6 +56,7 @@ try {
52
56
  var config = {
53
57
  environment: argv.environment === "undefined" ? "development" : argv.environment,
54
58
  optimize: !argv["skip-optimizations"],
59
+ nodelete: !argv["delete"],
55
60
  themeRoot: themeRoot,
56
61
  packageJson: pkg,
57
62
  tailwindConfig: tailwindConfig,
@@ -13,6 +13,8 @@ var _require = require("../utils"),
13
13
  var config = require("./includes/config");
14
14
 
15
15
  var messages = require("./includes/messages");
16
+
17
+ var environment = config.environment.split(/\s*,\s*|\s+/)[0];
16
18
  /**
17
19
  * Initiates shopify's cli command 'shopify theme serve' on the dist folder,
18
20
  * watching files and uploading them to development store
@@ -22,7 +24,6 @@ var messages = require("./includes/messages");
22
24
  * @static
23
25
  */
24
26
 
25
-
26
27
  gulp.task("shopify:serve:dist", function () {
27
28
  messages.logChildProcess("'shopify theme serve' on dist...");
28
29
  var childProcess = shopifyCLI.serve({
@@ -45,7 +46,7 @@ gulp.task("shopify:pull:dev", function (done) {
45
46
  messages.logChildProcess("'shopify theme pull' on development theme...");
46
47
  var devThemeId = getDevThemeID(config.themeRoot);
47
48
 
48
- if (!devThemeId) {
49
+ if (!devThemeId || devThemeId === 'false') {
49
50
  return done();
50
51
  }
51
52
 
@@ -63,12 +64,36 @@ gulp.task("shopify:pull:dev:tmp", function (done) {
63
64
  messages.logChildProcess("'shopify theme pull' on tmp folder...");
64
65
  var devThemeId = getDevThemeID(config.themeRoot);
65
66
 
66
- if (!devThemeId) {
67
+ if (!devThemeId || devThemeId === 'false') {
67
68
  return done();
68
69
  }
69
70
 
70
71
  return shopifyCLI.pull(devThemeId, config.tmp.root);
71
72
  });
73
+ /**
74
+ * Pulls theme files from the seed config theme enviroment into src
75
+ *
76
+ * @function shopify:pull:dev
77
+ * @memberof seed-cli.tasks.deploy
78
+ * @static
79
+ */
80
+
81
+ gulp.task("shopify:pull:origin:tmp", function () {
82
+ messages.logChildProcess("'shopify theme pull ".concat(environment).concat(config.nodelete ? ' --nodelete' : '', "' into tmp..."));
83
+ return shopifyCLI.pull(getThemeID(config.themeRoot, environment), config.tmp.root);
84
+ });
85
+ /**
86
+ * Pulls theme files from the seed config theme enviroment into src
87
+ *
88
+ * @function shopify:pull:dev
89
+ * @memberof seed-cli.tasks.deploy
90
+ * @static
91
+ */
92
+
93
+ gulp.task("shopify:pull:origin:src", function () {
94
+ messages.logChildProcess("'shopify theme pull ".concat(environment).concat(config.nodelete ? ' --nodelete' : '', "' into src..."));
95
+ return shopifyCLI.pull(getThemeID(config.themeRoot, environment), config.tmp.src, config.nodelete);
96
+ });
72
97
  /**
73
98
  * Initiates shopify's cli command 'shopify theme push' on the dist folder,
74
99
  * pushing it to stores theme
@@ -79,8 +104,8 @@ gulp.task("shopify:pull:dev:tmp", function (done) {
79
104
  */
80
105
 
81
106
  gulp.task("shopify:push:dist", function () {
82
- messages.logChildProcess("'shopify theme push' on dist folder...");
83
- return shopifyCLI.push(getThemeID(config.themeRoot, config.environment));
107
+ messages.logChildProcess("'shopify theme push".concat(config.nodelete ? ' --nodelete' : '', "' on dist folder..."));
108
+ return shopifyCLI.push(getThemeID(config.themeRoot, config.environment), config.nodelete);
84
109
  });
85
110
  /**
86
111
  * Takes the output of shopify cli serve, extracts dev theme ID and persists
@@ -23,7 +23,7 @@ var cache = utils.createEventCache();
23
23
  */
24
24
 
25
25
  gulp.task("watch:src", function () {
26
- return gulp.parallel("watch:css", "watch:js", "watch:assets", "watch:svg")();
26
+ return gulp.parallel("watch:css", "watch:js", "watch:vendor-js", "watch:assets", "watch:svg")();
27
27
  });
28
28
  /**
29
29
  * Watches for changes in the `./dist` folder and passes event data to the
package/lib/utils.js CHANGED
@@ -10,8 +10,14 @@ exports.getDevThemeID = getDevThemeID;
10
10
  exports.extractThemeId = extractThemeId;
11
11
  exports.logChildProcessOutput = logChildProcessOutput;
12
12
  exports.setDevThemeID = setDevThemeID;
13
+ exports.login = login;
14
+ exports.storeErrorMessage = storeErrorMessage;
13
15
  exports.shopifyCLI = void 0;
14
16
 
17
+ var _chalk = require("chalk");
18
+
19
+ var _figures = _interopRequireDefault(require("figures"));
20
+
15
21
  var _crossSpawn = _interopRequireDefault(require("cross-spawn"));
16
22
 
17
23
  var _path = require("path");
@@ -41,25 +47,23 @@ var shopifyCLI = {
41
47
  *
42
48
  * @memberof seed-cli.shopifyCLI
43
49
  * @param {string} store - store's myshopify domain name
44
- * @param {boolean} async - login asynchronously
45
- *
46
50
  * @returns {object} - spawnSync object or, node's <ChildProcess> object if async
47
51
  */
48
52
  login: function login(store) {
49
- var async = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
50
53
  var args = ["login", "--store", store];
51
54
  var options = {
52
55
  env: process.env,
53
56
  stdio: "inherit",
54
57
  shell: true
55
58
  };
56
- if (async) return (0, _crossSpawn["default"])("shopify", args, options);else return _crossSpawn["default"].sync("shopify", args, options);
59
+ return _crossSpawn["default"].sync("shopify", args, options);
57
60
  },
58
61
 
59
62
  /**
60
63
  * shopify theme serve
61
64
  *
62
65
  * @memberof seed-cli.shopifyCLI
66
+ * @param {object} options - node spawn options
63
67
  * @returns {object} - node's ChildProcess
64
68
  */
65
69
  serve: function serve() {
@@ -76,13 +80,18 @@ var shopifyCLI = {
76
80
  * shopify theme push
77
81
  *
78
82
  * @memberof seed-cli.shopifyCLI
83
+ * @param {string} themeId - shopify theme id to pull from
84
+ * @param {string} dir - directory to pull into
85
+ * @param {boolean} [nodelete = true] - run command with --no-delete flag
79
86
  * @returns {object} - node's ChildProcess
80
87
  */
81
88
  pull: function pull() {
82
89
  var themeId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
83
90
  var dir = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "./src";
91
+ var nodelete = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
84
92
  var args = ["pull"];
85
93
  if (themeId) args = args.concat(["--themeid", themeId, dir]);
94
+ if (nodelete) args.push('--nodelete');
86
95
  return (0, _crossSpawn["default"])("shopify theme", args, {
87
96
  env: process.env,
88
97
  stdio: "inherit",
@@ -94,12 +103,16 @@ var shopifyCLI = {
94
103
  * shopify theme push
95
104
  *
96
105
  * @memberof seed-cli.shopifyCLI
106
+ * @param {string} themeId - shopify theme id to push into
107
+ * @param {boolean} [nodelete = true] - run command with --no-delete flag
97
108
  * @returns {object} - node's ChildProcess
98
109
  */
99
110
  push: function push() {
100
111
  var themeId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
101
- var args = ["push", "--nodelete"];
112
+ var nodelete = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
113
+ var args = ["push"];
102
114
  if (themeId) args = args.concat(["--themeid", themeId]);
115
+ if (nodelete) args.push('--nodelete');
103
116
  return (0, _crossSpawn["default"])("shopify theme", args, {
104
117
  cwd: _config["default"].themeRoot + "/dist",
105
118
  env: process.env,
@@ -192,4 +205,42 @@ function setDevThemeID(themeID) {
192
205
  data = data.split(_config["default"].seedConfigDelimiter);
193
206
  data[1] = "\n __developmentThemeId: '".concat(themeID, "'") + "\n};";
194
207
  (0, _fs.writeFileSync)(_config["default"].seedConfig, data.join(_config["default"].seedConfigDelimiter));
208
+ }
209
+ /**
210
+ * Logs into seed config shopify store while logging useful messages
211
+ * and handling errors.
212
+ * @returns {boolean} whether login was succesful or not
213
+ */
214
+
215
+
216
+ function login() {
217
+ var store = getStoreName(_config["default"].themeRoot);
218
+
219
+ if (!store) {
220
+ storeErrorMessage();
221
+ return false;
222
+ }
223
+
224
+ console.log("Logging into ".concat((0, _chalk.yellow)(store), " with Shopify CLI..."));
225
+ var loginProcess = shopifyCLI.login(store);
226
+
227
+ if (loginProcess.error) {
228
+ console.log("");
229
+ console.log((0, _chalk.red)(" ".concat(_figures["default"].cross, " Failed logging into ").concat(store, ", are you sure you're using the correct account?")));
230
+ console.log("");
231
+ return false;
232
+ }
233
+
234
+ return true;
235
+ }
236
+ /**
237
+ * Outputs error message if there's no store field in seed config
238
+ */
239
+
240
+
241
+ function storeErrorMessage() {
242
+ console.log("");
243
+ console.log((0, _chalk.red)(" ".concat(_figures["default"].cross, " no store field in seed.config.js")));
244
+ console.log(" Add 'store: <store.myshopify.com>' to your project seed.config.js");
245
+ console.log("");
195
246
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@madebyseed/seed-cli-tools",
3
- "version": "1.2.5",
3
+ "version": "1.3.1",
4
4
  "description": "Seed CLI Tools",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -52,5 +52,5 @@
52
52
  "vinyl-paths": "^3.0.1",
53
53
  "yargs": "^17.0.1"
54
54
  },
55
- "gitHead": "8c7eb999d4fdd1fa2ab54e591c56a82f64ccf07d"
55
+ "gitHead": "f0dc909fb1b212491332caeb86a4a971c5405e61"
56
56
  }
@@ -1,6 +1,7 @@
1
1
  import spawn from "cross-spawn";
2
2
  import debug from "debug";
3
3
  import config from "../config";
4
+ import { login } from "../utils";
4
5
 
5
6
  const logger = debug("seed-tools:deploy");
6
7
 
@@ -16,19 +17,37 @@ export default function (program) {
16
17
  "Shopify store(s) to deploy code to (specified in seed.config.js)",
17
18
  "development"
18
19
  )
20
+ .option(
21
+ "-n, --no-dev",
22
+ "Skips pulling theme settings from local development theme",
23
+ false
24
+ )
19
25
  .option(
20
26
  "-s, --skip-optimizations",
21
27
  "Skips asset optimization steps such as compression, minification and purging.",
22
28
  false
23
29
  )
30
+ .option(
31
+ "-d, --delete",
32
+ "By default seed deploy runs 'shopify theme push --nodelete'. With this option it will leave out the --no-delete flag, allowind files to be delete in store theme.",
33
+ false
34
+ )
24
35
  .action((options = {}) => {
25
36
  logger(`--gulpfile ${config.gulpFile}`);
26
37
  logger(`--cwd ${config.themeRoot}`);
27
38
 
28
- const args = ["deploy", "--environment", options.env];
39
+ if (!login()) return;
40
+
41
+ const args = [
42
+ options.dev ? "deploy" : "deploy:no-sync",
43
+ "--environment", options.env,
44
+ ];
45
+
46
+ if (options.skipOptimizations) args.push('--skip-optimizations')
47
+ if (options.delete) args.push('--delete')
29
48
 
30
- if (options.skipOptimizations) args.push("--skip-optimization");
31
- else process.env.NODE_ENV = "production";
49
+ if (!options.skipOptimizations)
50
+ process.env.NODE_ENV = "production";
32
51
 
33
52
  spawn(
34
53
  config.gulp,
@@ -0,0 +1,53 @@
1
+ import spawn from "cross-spawn";
2
+ import debug from "debug";
3
+ import config from "../config";
4
+ import { login } from "../utils";
5
+
6
+ const logger = debug("seed-tools:deploy");
7
+
8
+ export default function (program) {
9
+ program
10
+ .command("pull")
11
+ .alias("p")
12
+ .description(
13
+ "Pulls the specified theme into your src folder. By default, it only pulls theme settings, if you want to pull all files use the --all flag."
14
+ )
15
+ .option(
16
+ "-e, --env <environment>[,<environment>...]",
17
+ "Shopify store(s) to deploy code to (specified in seed.config.js)",
18
+ "development"
19
+ )
20
+ .option(
21
+ "-a, --all",
22
+ "Pulls all files from specified theme",
23
+ false
24
+ )
25
+ .option(
26
+ "-d, --delete",
27
+ "By default seed pull doesn't delete any files in you src folder, with this options it will delete any files that diverge from the pulled theme.",
28
+ false
29
+ )
30
+ .action((options = {}) => {
31
+ logger(`--gulpfile ${config.gulpFile}`);
32
+ logger(`--cwd ${config.themeRoot}`);
33
+ if (!login()) return;
34
+
35
+
36
+ const args = [
37
+ options.all ? "pull" : "pull:settings",
38
+ "--environment", options.env
39
+ ];
40
+
41
+ if (options.all) args.push('--all')
42
+ if (options.delete) args.push('--delete')
43
+
44
+ spawn(
45
+ config.gulp,
46
+ args.concat(["--gulpfile", config.gulpFile, "--cwd", config.themeRoot]),
47
+ {
48
+ detached: false,
49
+ stdio: "inherit",
50
+ }
51
+ );
52
+ });
53
+ }
@@ -1,9 +1,7 @@
1
- import { red, yellow } from "chalk";
2
- import figures from "figures";
3
1
  import spawn from "cross-spawn";
4
2
  import debug from "debug";
5
3
  import config from "../config";
6
- import { getStoreName, shopifyCLI } from "../utils";
4
+ import { login } from "../utils";
7
5
 
8
6
  const logger = debug("seed-tools:watch");
9
7
 
@@ -23,31 +21,8 @@ export default function (program) {
23
21
  .action((options = {}) => {
24
22
  logger(`--gulpfile ${config.gulpFile}`);
25
23
  logger(`--cwd ${config.themeRoot}`);
26
- const store = getStoreName(config.themeRoot);
27
24
 
28
- if (!store) {
29
- console.log("");
30
- console.log(
31
- red(` ${figures.cross} no store field in seed.config.js`)
32
- );
33
- console.log(
34
- " Add 'store: <store.myshopify.com>' to your project seed.config.js"
35
- );
36
- console.log("");
37
- return;
38
- }
39
-
40
- console.log(`Logging into ${yellow(store)} with Shopify CLI...`)
41
- const loginProcess = shopifyCLI.login(store);
42
- if (loginProcess.error) {
43
- console.log("");
44
- console.log(
45
- red(` ${figures.cross} Failed logging into ${store}, are you sure you're using the correct account?`)
46
- );
47
- console.log("");
48
-
49
- return;
50
- }
25
+ if (!login()) return;
51
26
 
52
27
  const gulpArgs = [
53
28
  "watch",
package/src/config.js CHANGED
@@ -2,6 +2,7 @@ import { join, normalize } from "path";
2
2
  import { existsSync } from "fs";
3
3
  import findRoot from "find-root";
4
4
 
5
+
5
6
  const workingDirectory = process.cwd();
6
7
  const currentDirectory = __dirname;
7
8
 
package/src/gulpfile.js CHANGED
@@ -63,10 +63,32 @@ gulp.task(
63
63
  )
64
64
  );
65
65
 
66
+
66
67
  /**
67
- * Does a full (re)build followed by a full deploy, cleaning existing files on
68
- * the remote server and replacing them with the full set of files pushed to
69
- * `dist` in the build
68
+ *
69
+ * @summary pulls theme from specified environment theme into src
70
+ * @function deploy
71
+ * @memberof slate-cli.tasks.deploy
72
+ * @static
73
+ */
74
+ gulp.task("pull", gulp.series("shopify:pull:origin:src"));
75
+
76
+ /**
77
+ * Does a full (re)build and push dist files into specified theme environment,
78
+ * theme using shopify theme push, by default with the --no-delete flag
79
+ *
80
+ * @summary pulls theme settings from specified environment theme into src
81
+ * @function deploy
82
+ * @memberof slate-cli.tasks.deploy
83
+ * @static
84
+ */
85
+ gulp.task("pull:settings", gulp.series("generate:tmp", "shopify:pull:origin:tmp", "sync-settings:tmp:src"));
86
+
87
+
88
+ /**
89
+ * Syncronizes src folder theme settings with local development theme settings,
90
+ * then proceeds to do a full (re)build and push files into specified theme
91
+ * environment theme using shopify theme push, by default with the --no-delete flag
70
92
  *
71
93
  * @summary Deploy your built files to the Shopify Store set in
72
94
  * `slate-cli.config`
@@ -75,3 +97,16 @@ gulp.task(
75
97
  * @static
76
98
  */
77
99
  gulp.task("deploy", gulp.series("sync-settings", "build", "shopify:push:dist"));
100
+
101
+ /**
102
+ * Does a full (re)build and push dist files into specified theme environment,
103
+ * theme using shopify theme push, by default with the --no-delete flag
104
+ *
105
+ * @summary Deploy your built files to the Shopify Store set in
106
+ * `slate-cli.config`
107
+ * @function deploy
108
+ * @memberof slate-cli.tasks.deploy:no-sync
109
+ * @static
110
+ */
111
+ gulp.task("deploy:no-sync", gulp.series("build", "shopify:push:dist"));
112
+
@@ -86,6 +86,7 @@ gulp.task("generate:tmp", () => {
86
86
  * @static
87
87
  */
88
88
  gulp.task("sync-settings:tmp:src", () => {
89
+ messages.logProcessFiles('Syncronizing /tmp theme settings with /src')
89
90
  return copyFiles(
90
91
  themeSettingsAssets,
91
92
  { base: config.tmp.root },
@@ -33,6 +33,10 @@ try {
33
33
  * @memberof seed-cli
34
34
  * @summary Configuring seed-cli
35
35
  * @prop {String} environment - development | staging | production
36
+ * @prop {Boolean} optimize - whether optimize assets or not
37
+ * @prop {Boolean} nodelete - run shopiy cli commands with --no-delete flag
38
+ * @prop {String} tailwindConfig - tailwind config filename
39
+ * @prop {String} seedConfig - seed config filename
36
40
  * @prop {String} deployLog - path to deploy log file
37
41
  * @prop {String} src - globs (multi-filename matching patterns) for various source files
38
42
  * @prop {String} tmp - globs (multi-filename matching patterns) for various tmp files
@@ -43,6 +47,7 @@ try {
43
47
  const config = {
44
48
  environment: argv.environment === "undefined" ? "development" : argv.environment,
45
49
  optimize: !argv["skip-optimizations"],
50
+ nodelete: !argv["delete"],
46
51
  themeRoot,
47
52
  packageJson: pkg,
48
53
 
@@ -50,7 +55,6 @@ const config = {
50
55
 
51
56
  seedConfig: "seed.config.js",
52
57
 
53
-
54
58
  src: {
55
59
  root: "src/",
56
60
  js: "src/scripts/**/*.{js,js.liquid}",
@@ -10,6 +10,8 @@ const {
10
10
  } = require("../utils");
11
11
  const config = require("./includes/config");
12
12
  const messages = require("./includes/messages")
13
+ const environment = config.environment.split(/\s*,\s*|\s+/)[0];
14
+
13
15
 
14
16
  /**
15
17
  * Initiates shopify's cli command 'shopify theme serve' on the dist folder,
@@ -40,7 +42,7 @@ gulp.task("shopify:serve:dist", () => {
40
42
  gulp.task("shopify:pull:dev", (done) => {
41
43
  messages.logChildProcess("'shopify theme pull' on development theme...");
42
44
  const devThemeId = getDevThemeID(config.themeRoot);
43
- if (!devThemeId) {
45
+ if (!devThemeId || devThemeId === 'false') {
44
46
  return done();
45
47
  }
46
48
 
@@ -57,7 +59,7 @@ gulp.task("shopify:pull:dev", (done) => {
57
59
  gulp.task("shopify:pull:dev:tmp", (done) => {
58
60
  messages.logChildProcess("'shopify theme pull' on tmp folder...");
59
61
  const devThemeId = getDevThemeID(config.themeRoot);
60
- if (!devThemeId) {
62
+ if (!devThemeId || devThemeId === 'false') {
61
63
  return done();
62
64
  }
63
65
 
@@ -67,6 +69,37 @@ gulp.task("shopify:pull:dev:tmp", (done) => {
67
69
  );
68
70
  });
69
71
 
72
+ /**
73
+ * Pulls theme files from the seed config theme enviroment into src
74
+ *
75
+ * @function shopify:pull:dev
76
+ * @memberof seed-cli.tasks.deploy
77
+ * @static
78
+ */
79
+ gulp.task("shopify:pull:origin:tmp", () => {
80
+ messages.logChildProcess(`'shopify theme pull ${environment}${config.nodelete ? ' --nodelete' : ''}' into tmp...`);
81
+ return shopifyCLI.pull(
82
+ getThemeID(config.themeRoot, environment),
83
+ config.tmp.root
84
+ );
85
+ });
86
+
87
+ /**
88
+ * Pulls theme files from the seed config theme enviroment into src
89
+ *
90
+ * @function shopify:pull:dev
91
+ * @memberof seed-cli.tasks.deploy
92
+ * @static
93
+ */
94
+ gulp.task("shopify:pull:origin:src", () => {
95
+ messages.logChildProcess(`'shopify theme pull ${environment}${config.nodelete ? ' --nodelete' : ''}' into src...`);
96
+ return shopifyCLI.pull(
97
+ getThemeID(config.themeRoot, environment),
98
+ config.tmp.src,
99
+ config.nodelete
100
+ );
101
+ });
102
+
70
103
  /**
71
104
  * Initiates shopify's cli command 'shopify theme push' on the dist folder,
72
105
  * pushing it to stores theme
@@ -76,8 +109,8 @@ gulp.task("shopify:pull:dev:tmp", (done) => {
76
109
  * @static
77
110
  */
78
111
  gulp.task("shopify:push:dist", () => {
79
- messages.logChildProcess("'shopify theme push' on dist folder...");
80
- return shopifyCLI.push(getThemeID(config.themeRoot, config.environment));
112
+ messages.logChildProcess(`'shopify theme push${config.nodelete ? ' --nodelete' : ''}' on dist folder...`);
113
+ return shopifyCLI.push(getThemeID(config.themeRoot, config.environment), config.nodelete);
81
114
  });
82
115
 
83
116
  /**
@@ -18,7 +18,13 @@ const cache = utils.createEventCache();
18
18
  * @static
19
19
  */
20
20
  gulp.task("watch:src", () => {
21
- return gulp.parallel("watch:css", "watch:js", "watch:assets", "watch:svg")();
21
+ return gulp.parallel(
22
+ "watch:css",
23
+ "watch:js",
24
+ "watch:vendor-js",
25
+ "watch:assets",
26
+ "watch:svg"
27
+ )();
22
28
  });
23
29
 
24
30
  /**
package/src/utils.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { red, yellow } from "chalk";
2
+ import figures from "figures";
1
3
  import spawn from "cross-spawn";
2
4
  import { join } from "path";
3
5
  import { readFileSync, writeFileSync } from "fs";
@@ -16,11 +18,9 @@ export const shopifyCLI = {
16
18
  *
17
19
  * @memberof seed-cli.shopifyCLI
18
20
  * @param {string} store - store's myshopify domain name
19
- * @param {boolean} async - login asynchronously
20
- *
21
21
  * @returns {object} - spawnSync object or, node's <ChildProcess> object if async
22
22
  */
23
- login: (store, async = false) => {
23
+ login: (store) => {
24
24
  const args = ["login", "--store", store];
25
25
  const options = {
26
26
  env: process.env,
@@ -28,14 +28,14 @@ export const shopifyCLI = {
28
28
  shell: true,
29
29
  };
30
30
 
31
- if (async) return spawn("shopify", args, options);
32
- else return spawn.sync("shopify", args, options);
31
+ return spawn.sync("shopify", args, options);
33
32
  },
34
33
 
35
34
  /**
36
35
  * shopify theme serve
37
36
  *
38
37
  * @memberof seed-cli.shopifyCLI
38
+ * @param {object} options - node spawn options
39
39
  * @returns {object} - node's ChildProcess
40
40
  */
41
41
  serve: (options = {}) => {
@@ -52,12 +52,17 @@ export const shopifyCLI = {
52
52
  * shopify theme push
53
53
  *
54
54
  * @memberof seed-cli.shopifyCLI
55
+ * @param {string} themeId - shopify theme id to pull from
56
+ * @param {string} dir - directory to pull into
57
+ * @param {boolean} [nodelete = true] - run command with --no-delete flag
55
58
  * @returns {object} - node's ChildProcess
56
59
  */
57
- pull: (themeId = null, dir = "./src") => {
60
+ pull: (themeId = null, dir = "./src", nodelete = true) => {
58
61
  let args = ["pull"];
59
62
  if (themeId) args = args.concat(["--themeid", themeId, dir]);
60
63
 
64
+ if (nodelete) args.push('--nodelete')
65
+
61
66
  return spawn("shopify theme", args, {
62
67
  env: process.env,
63
68
  stdio: "inherit",
@@ -69,12 +74,16 @@ export const shopifyCLI = {
69
74
  * shopify theme push
70
75
  *
71
76
  * @memberof seed-cli.shopifyCLI
77
+ * @param {string} themeId - shopify theme id to push into
78
+ * @param {boolean} [nodelete = true] - run command with --no-delete flag
72
79
  * @returns {object} - node's ChildProcess
73
80
  */
74
- push: (themeId = null) => {
75
- let args = ["push", "--nodelete"];
81
+ push: (themeId = null, nodelete = true) => {
82
+ let args = ["push"];
76
83
  if (themeId) args = args.concat(["--themeid", themeId]);
77
84
 
85
+ if (nodelete) args.push('--nodelete')
86
+
78
87
  return spawn("shopify theme", args, {
79
88
  cwd: config.themeRoot + "/dist",
80
89
  env: process.env,
@@ -158,3 +167,46 @@ export function setDevThemeID(themeID) {
158
167
  data[1] = `\n __developmentThemeId: '${themeID}'` + "\n};";
159
168
  writeFileSync(config.seedConfig, data.join(config.seedConfigDelimiter));
160
169
  }
170
+
171
+
172
+ /**
173
+ * Logs into seed config shopify store while logging useful messages
174
+ * and handling errors.
175
+ * @returns {boolean} whether login was succesful or not
176
+ */
177
+ export function login() {
178
+ const store = getStoreName(config.themeRoot);
179
+
180
+ if (!store) {
181
+ storeErrorMessage();
182
+ return false;
183
+ }
184
+
185
+ console.log(`Logging into ${yellow(store)} with Shopify CLI...`)
186
+ const loginProcess = shopifyCLI.login(store);
187
+ if (loginProcess.error) {
188
+ console.log("");
189
+ console.log(
190
+ red(` ${figures.cross} Failed logging into ${store}, are you sure you're using the correct account?`)
191
+ );
192
+ console.log("");
193
+ return false;
194
+ }
195
+
196
+ return true;
197
+ }
198
+
199
+
200
+ /**
201
+ * Outputs error message if there's no store field in seed config
202
+ */
203
+ export function storeErrorMessage() {
204
+ console.log("");
205
+ console.log(
206
+ red(` ${figures.cross} no store field in seed.config.js`)
207
+ );
208
+ console.log(
209
+ " Add 'store: <store.myshopify.com>' to your project seed.config.js"
210
+ );
211
+ console.log("");
212
+ }