@madebyseed/seed-cli-tools 1.0.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/.babelrc +3 -0
- package/.eslintrc +7 -0
- package/lib/commands/deploy.js +29 -0
- package/lib/commands/watch.js +56 -0
- package/lib/config.js +28 -0
- package/lib/gulpfile.js +48 -0
- package/lib/tasks/build-assets.js +89 -0
- package/lib/tasks/build-css.js +58 -0
- package/lib/tasks/build-js.js +52 -0
- package/lib/tasks/build-svg.js +94 -0
- package/lib/tasks/build-utils.js +43 -0
- package/lib/tasks/deploy.js +19 -0
- package/lib/tasks/includes/config.js +96 -0
- package/lib/tasks/includes/messages.js +77 -0
- package/lib/tasks/includes/utilities.js +222 -0
- package/lib/tasks/watchers.js +44 -0
- package/lib/utils.js +96 -0
- package/package.json +57 -0
- package/src/commands/deploy.js +25 -0
- package/src/commands/watch.js +62 -0
- package/src/config.js +22 -0
- package/src/gulpfile.js +61 -0
- package/src/tasks/build-assets.js +93 -0
- package/src/tasks/build-css.js +54 -0
- package/src/tasks/build-js.js +53 -0
- package/src/tasks/build-svg.js +89 -0
- package/src/tasks/build-utils.js +37 -0
- package/src/tasks/deploy.js +15 -0
- package/src/tasks/includes/config.js +95 -0
- package/src/tasks/includes/messages.js +116 -0
- package/src/tasks/includes/utilities.js +211 -0
- package/src/tasks/watchers.js +48 -0
- package/src/utils.js +90 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var chalk = require("chalk");
|
|
4
|
+
|
|
5
|
+
var log = require("fancy-log");
|
|
6
|
+
/**
|
|
7
|
+
* Separates filename and directory from a path string. Returns an object containing both.
|
|
8
|
+
*
|
|
9
|
+
* @param path {String} - a string representing the path to a file
|
|
10
|
+
* @returns {Object} - an object with separated `file` (the filename) and `dir` (path minus filename) properties
|
|
11
|
+
* @private
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
function separatePath(path) {
|
|
16
|
+
var tmp = path.split('/');
|
|
17
|
+
return {
|
|
18
|
+
file: tmp.pop(),
|
|
19
|
+
dir: tmp.join('/')
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var messages = {
|
|
24
|
+
logFileEvent: function logFileEvent(event, path) {
|
|
25
|
+
var pathObject = separatePath(path);
|
|
26
|
+
log('change in', chalk.magenta(pathObject.dir), chalk.white('-'), chalk.cyan(event), chalk.yellow(pathObject.file));
|
|
27
|
+
},
|
|
28
|
+
logTransferDone: function logTransferDone() {
|
|
29
|
+
log('Transfer Complete:', chalk.green('File changes successfully synced to store'));
|
|
30
|
+
},
|
|
31
|
+
logTransferFailed: function logTransferFailed(errMsg) {
|
|
32
|
+
log('Transfer Failed:', chalk.yellow("".concat(typeof errMsg === 'string' ? errMsg : 'File(s) failed to upload to store. See log notes in deploy.log')));
|
|
33
|
+
},
|
|
34
|
+
logProcessFiles: function logProcessFiles(processName) {
|
|
35
|
+
log('running task', chalk.white('-'), chalk.cyan(processName));
|
|
36
|
+
},
|
|
37
|
+
logChildProcess: function logChildProcess(cmd) {
|
|
38
|
+
log('running task', chalk.bold('[child process]'), chalk.white('-'), chalk.cyan('theme', cmd));
|
|
39
|
+
},
|
|
40
|
+
logDeploys: function logDeploys(cmd, files) {
|
|
41
|
+
var timestamp = "Deploy complete @ ".concat(new Date(), ". ");
|
|
42
|
+
var action = cmd === 'upload' ? 'added/changed ' : 'removed ';
|
|
43
|
+
var amount = "".concat(files.length, " file(s): ");
|
|
44
|
+
var fileList = "".concat(files.join(', '), ".\n");
|
|
45
|
+
return timestamp + action + amount + fileList;
|
|
46
|
+
},
|
|
47
|
+
logDeployErrors: function logDeployErrors(cmd, files, err) {
|
|
48
|
+
var timestamp = "Deploy error @ ".concat(new Date(), ". ");
|
|
49
|
+
var action = cmd === 'upload' ? 'added/changed ' : 'removed ';
|
|
50
|
+
var amount = "".concat(files.length, " file(s): ");
|
|
51
|
+
var fileList = "".concat(files.join(', '), ".\n");
|
|
52
|
+
var errMsg = "".concat(err, " \n");
|
|
53
|
+
return timestamp + action + amount + fileList + errMsg;
|
|
54
|
+
},
|
|
55
|
+
logBundleJs: function logBundleJs() {
|
|
56
|
+
log('Updating JS Bundle...');
|
|
57
|
+
},
|
|
58
|
+
configChange: function configChange() {
|
|
59
|
+
return 'Changes to ThemeKit Config Detected: You may need to quit <slate watch>' + ' and run a full <slate deploy> as a result.';
|
|
60
|
+
},
|
|
61
|
+
translationsFailed: function translationsFailed() {
|
|
62
|
+
return 'Translation errors detected.';
|
|
63
|
+
},
|
|
64
|
+
invalidThemeId: function invalidThemeId(themeId, env) {
|
|
65
|
+
log('Invalid theme id for', chalk.cyan("".concat(env, ": ").concat(themeId)), chalk.yellow('`theme_id` must be an integer or "live".'));
|
|
66
|
+
},
|
|
67
|
+
configError: function configError() {
|
|
68
|
+
log('File missing:', chalk.yellow('`config.yml` does not exist. You need to add a config file before you can make changes to your Shopify store.'));
|
|
69
|
+
},
|
|
70
|
+
deployTo: function deployTo(environment) {
|
|
71
|
+
log('Initiating deploy to', chalk.bold(environment));
|
|
72
|
+
},
|
|
73
|
+
allDeploysComplete: function allDeploysComplete() {
|
|
74
|
+
log('Multiple environments:', chalk.green('Deploy completed for all environments in series'));
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
module.exports = messages;
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _this = void 0;
|
|
4
|
+
|
|
5
|
+
var chalk = require("chalk");
|
|
6
|
+
|
|
7
|
+
var log = require("fancy-log");
|
|
8
|
+
|
|
9
|
+
var _ = require('lodash');
|
|
10
|
+
|
|
11
|
+
var Promise = require('bluebird');
|
|
12
|
+
|
|
13
|
+
var _require = require("../../utils"),
|
|
14
|
+
shopifyCLI = _require.shopifyCLI;
|
|
15
|
+
|
|
16
|
+
var errors = [];
|
|
17
|
+
/**
|
|
18
|
+
* Utility and reusable functions used by our Gulp Tasks
|
|
19
|
+
*
|
|
20
|
+
* @summary a set of utility functions used within the gulp tasks of seed-cli
|
|
21
|
+
* @namespace seed-cli.utilities
|
|
22
|
+
* @memberof seed-cli
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
var utilities = {
|
|
26
|
+
/**
|
|
27
|
+
* Launches shopify theme serve command to serve files on ./dist folder
|
|
28
|
+
*
|
|
29
|
+
* @memberof seed-cli.utilities
|
|
30
|
+
* @returns {object} - ChildProcess
|
|
31
|
+
*/
|
|
32
|
+
serveDist: function serveDist() {
|
|
33
|
+
return shopifyCLI.serve();
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Launches shopify theme push command to deploy files on ./dist folder
|
|
38
|
+
* to a store's theme
|
|
39
|
+
*
|
|
40
|
+
* @memberof seed-cli.utilities
|
|
41
|
+
* @returns {object} - ChildProcess
|
|
42
|
+
*/
|
|
43
|
+
deployDist: function deployDist() {
|
|
44
|
+
return shopifyCLI.push();
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Handles the output for any errors that might have been captured
|
|
49
|
+
* during the build and zip Gulp tasks.
|
|
50
|
+
*
|
|
51
|
+
* @memberof seed-cli.utilities
|
|
52
|
+
*/
|
|
53
|
+
outputErrors: function outputErrors() {
|
|
54
|
+
if (!errors.length) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
log(chalk.red("There were errors during the build:\n"));
|
|
59
|
+
errors.forEach(function (err) {
|
|
60
|
+
log(chalk.red(err));
|
|
61
|
+
});
|
|
62
|
+
errors = [];
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Generic error handler for streams called in `watch` tasks (used by gulp-plumber).
|
|
67
|
+
* Any error that is thrown inside of a task is added to the errors array.
|
|
68
|
+
*
|
|
69
|
+
* @memberof seed-cli.utilities
|
|
70
|
+
* @param {Error} err
|
|
71
|
+
*/
|
|
72
|
+
errorHandler: function errorHandler(err) {
|
|
73
|
+
log(chalk.red(err));
|
|
74
|
+
errors.push(err);
|
|
75
|
+
|
|
76
|
+
_this.emit('end');
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Executes an array of promises in series
|
|
81
|
+
*
|
|
82
|
+
* @param promiseArrayFactory {Function} - an array of promise factories
|
|
83
|
+
* @returns {Promise} - promise.all() style array of results from each promise
|
|
84
|
+
*/
|
|
85
|
+
promiseSeries: function promiseSeries(promiseArrayFactory) {
|
|
86
|
+
var results = [];
|
|
87
|
+
return Promise.each(promiseArrayFactory, function (factory) {
|
|
88
|
+
var result = factory();
|
|
89
|
+
results.push(result);
|
|
90
|
+
return result;
|
|
91
|
+
}).thenReturn(results).all();
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Function passed to cheerio.run - adds aria tags & other accessibility
|
|
96
|
+
* based information to each svg element's markup...
|
|
97
|
+
*
|
|
98
|
+
* @memberof seed-cli.utilities
|
|
99
|
+
* @param {Function} $ - jQuery reference
|
|
100
|
+
* @param {fs} file - reference to current icon file?
|
|
101
|
+
*/
|
|
102
|
+
processSvg: function processSvg($, file) {
|
|
103
|
+
var $svg = $('svg'); // eslint-disable-line no-var
|
|
104
|
+
|
|
105
|
+
var $newSvg = $('<svg aria-hidden="true" focusable="false" role="presentation" class="icon" />'); // eslint-disable-line no-var
|
|
106
|
+
|
|
107
|
+
var fileName = file.relative.replace('.svg', ''); // eslint-disable-line no-var
|
|
108
|
+
|
|
109
|
+
var viewBoxAttr = $svg.attr('viewbox'); // eslint-disable-line no-var
|
|
110
|
+
// Add necessary attributes
|
|
111
|
+
|
|
112
|
+
if (viewBoxAttr) {
|
|
113
|
+
var width = parseInt(viewBoxAttr.split(' ')[2], 10); // eslint-disable-line no-var
|
|
114
|
+
|
|
115
|
+
var height = parseInt(viewBoxAttr.split(' ')[3], 10); // eslint-disable-line no-var
|
|
116
|
+
|
|
117
|
+
var widthToHeightRatio = width / height; // eslint-disable-line no-var
|
|
118
|
+
|
|
119
|
+
if (widthToHeightRatio >= 1.5) {
|
|
120
|
+
$newSvg.addClass('icon--wide');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
$newSvg.attr('viewBox', viewBoxAttr);
|
|
124
|
+
} // Add required classes to full color icons
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
if (file.relative.indexOf('-full-color') >= 0) {
|
|
128
|
+
$newSvg.addClass('icon--full-color');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
$newSvg.addClass(fileName).append($svg.contents());
|
|
132
|
+
$newSvg.append($svg.contents());
|
|
133
|
+
$svg.after($newSvg);
|
|
134
|
+
$svg.remove();
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Factory for creating an event cache - used with a short debounce to batch any
|
|
139
|
+
* file changes that occur in rapid succession during Watch tasks.
|
|
140
|
+
*
|
|
141
|
+
* @memberof seed-cli.utilities
|
|
142
|
+
* @param {Object} options
|
|
143
|
+
* @returns {eventCache} see type definition for more robust documentation
|
|
144
|
+
*/
|
|
145
|
+
createEventCache: function createEventCache(options) {
|
|
146
|
+
_.defaults(options = options || {}, {
|
|
147
|
+
// eslint-disable-line no-param-reassign
|
|
148
|
+
changeEvents: ['add', 'change'],
|
|
149
|
+
unlinkEvents: ['unlink']
|
|
150
|
+
});
|
|
151
|
+
/**
|
|
152
|
+
* A cache object used for caching `[chokidar]{@link https://github.com/paulmillr/chokidar}`
|
|
153
|
+
* events - used with a short `debounce` to batch any file changes that occur in rapid
|
|
154
|
+
* succession during Watch tasks.
|
|
155
|
+
*
|
|
156
|
+
* @typedef {Object} eventCache
|
|
157
|
+
* @prop {Array} change - an array for caching `add` and `change` events
|
|
158
|
+
* @prop {Array} unlink - an array for caching `unlink` events
|
|
159
|
+
* @prop {Function} addEvent - a function to push events to the appropriate `cache` array
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
change: [],
|
|
165
|
+
unlink: [],
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Pushes events to upload & remove caches for later batch deployment
|
|
169
|
+
*
|
|
170
|
+
* @function addEvent
|
|
171
|
+
* @memberof eventCache
|
|
172
|
+
* @param {String} event - chokidar event type - only cares about `(add|change|unlink)`
|
|
173
|
+
* @param {String} path - relative path to file passed via event
|
|
174
|
+
*/
|
|
175
|
+
addEvent: function addEvent(event, path) {
|
|
176
|
+
var _this2 = this;
|
|
177
|
+
|
|
178
|
+
_.each(options.changeEvents, function (eventType) {
|
|
179
|
+
if (event === eventType) {
|
|
180
|
+
_this2.change.push(path);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
_.each(options.unlinkEvents, function (eventType) {
|
|
185
|
+
if (event === eventType) {
|
|
186
|
+
_this2.unlink.push(path);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
},
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Debounced (320ms) delegator function passing an {@link eventCache} object
|
|
195
|
+
* through to a pair of custom functions for processing batch add/change or unlink events.
|
|
196
|
+
* Clears the appropriate cache array after a change/delete function has been
|
|
197
|
+
* called.
|
|
198
|
+
*
|
|
199
|
+
* Example:
|
|
200
|
+
* ```javascript
|
|
201
|
+
* // TODO:
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* @memberof seed-cli.utilities
|
|
205
|
+
* @method
|
|
206
|
+
* @param {eventCache} cache - a specific cache object for tracking file events
|
|
207
|
+
* @param {Function} changeFn - a custom function to process the set of files that have changed
|
|
208
|
+
* @param {Function} delFn - a custom function to remove the set of files that have changed from the `dist` directory
|
|
209
|
+
*/
|
|
210
|
+
processCache: _.debounce(function (cache, changeFn, delFn) {
|
|
211
|
+
if (cache.change.length) {
|
|
212
|
+
changeFn(cache.change);
|
|
213
|
+
cache.change = [];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (cache.unlink.length) {
|
|
217
|
+
delFn(cache.unlink);
|
|
218
|
+
cache.unlink = [];
|
|
219
|
+
}
|
|
220
|
+
}, 320)
|
|
221
|
+
};
|
|
222
|
+
module.exports = utilities;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// const { yellow } = require('chalk');
|
|
4
|
+
var gulp = require('gulp'); // const runSequence = require('gulp4-run-sequence');
|
|
5
|
+
// const _ = require('lodash');
|
|
6
|
+
// const debug = require('debug')('seed-tools:watchers');
|
|
7
|
+
// const chokidar = require('chokidar');
|
|
8
|
+
// const fs = require('fs');
|
|
9
|
+
// const themekit = require('@shopify/themekit');
|
|
10
|
+
// const Promise = require('bluebird');
|
|
11
|
+
// const config = require('./includes/config.js');
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var utils = require('./includes/utilities.js'); // const messages = require('./includes/messages.js');
|
|
15
|
+
// const cache = utils.createEventCache();
|
|
16
|
+
// const environment = config.environment.split(/\s*,\s*|\s+/)[0];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Aggregate task watching for file changes in `src` and
|
|
20
|
+
* building/cleaning/updating `dist` accordingly. *Made up of individual tasks
|
|
21
|
+
* referenced in other files
|
|
22
|
+
*
|
|
23
|
+
* @function watch:src
|
|
24
|
+
* @memberof seed-cli.tasks.watch
|
|
25
|
+
* @static
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
gulp.task('watch:src', function () {
|
|
30
|
+
return gulp.parallel('watch:css', 'watch:js', 'watch:assets', 'watch:svg')();
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Initiates shopify's cli command 'shopify theme serve' on the dist folder,
|
|
34
|
+
* watching files and uploading them to development store
|
|
35
|
+
*
|
|
36
|
+
* @function watch:dist
|
|
37
|
+
* @memberof seed-cli.tasks.watch
|
|
38
|
+
* @static
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
gulp.task('watch:dist', function () {
|
|
42
|
+
console.log("Running Shopify theme serve...");
|
|
43
|
+
return utils.serveDist();
|
|
44
|
+
});
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSeedConfig = getSeedConfig;
|
|
7
|
+
exports.getStoreName = getStoreName;
|
|
8
|
+
exports.shopifyCLI = void 0;
|
|
9
|
+
|
|
10
|
+
var _crossSpawn = _interopRequireDefault(require("cross-spawn"));
|
|
11
|
+
|
|
12
|
+
var _path = require("path");
|
|
13
|
+
|
|
14
|
+
var _config = _interopRequireDefault(require("./config"));
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Wrappers for Shopify CLI commands
|
|
20
|
+
*
|
|
21
|
+
* @summary a set of utility functions used to wrap shopify's CLI
|
|
22
|
+
* @namespace seed-cli.shopifyCLI
|
|
23
|
+
* @memberof seed-cli
|
|
24
|
+
*/
|
|
25
|
+
var shopifyCLI = {
|
|
26
|
+
/**
|
|
27
|
+
* shopify login
|
|
28
|
+
*
|
|
29
|
+
* @memberof seed-cli.shopifyCLI
|
|
30
|
+
* @param {string} store - store's myshopify domain name
|
|
31
|
+
* @param {boolean} async - login asynchronously
|
|
32
|
+
*
|
|
33
|
+
* @returns {object} - spawnSync object or, node's <ChildProcess> object if async
|
|
34
|
+
*/
|
|
35
|
+
login: function login(store) {
|
|
36
|
+
var async = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
37
|
+
var args = ['login', '--store', store];
|
|
38
|
+
var options = {
|
|
39
|
+
env: process.env,
|
|
40
|
+
stdio: "inherit",
|
|
41
|
+
shell: true
|
|
42
|
+
};
|
|
43
|
+
if (async) return (0, _crossSpawn["default"])('shopify', args, options);else return _crossSpawn["default"].sync('shopify', args, options);
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* shopify theme serve
|
|
48
|
+
*
|
|
49
|
+
* @memberof seed-cli.shopifyCLI
|
|
50
|
+
* @returns {object} - node's ChildProcess
|
|
51
|
+
*/
|
|
52
|
+
serve: function serve() {
|
|
53
|
+
return (0, _crossSpawn["default"])('shopify theme', ['serve'], {
|
|
54
|
+
cwd: _config["default"].themeRoot + '/dist',
|
|
55
|
+
env: process.env,
|
|
56
|
+
stdio: "inherit",
|
|
57
|
+
shell: true
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* shopify theme push
|
|
63
|
+
*
|
|
64
|
+
* @memberof seed-cli.shopifyCLI
|
|
65
|
+
* @returns {object} - node's ChildProcess
|
|
66
|
+
*/
|
|
67
|
+
push: function push() {
|
|
68
|
+
return (0, _crossSpawn["default"])('shopify theme', ['push'], {
|
|
69
|
+
cwd: _config["default"].themeRoot + '/dist',
|
|
70
|
+
env: process.env,
|
|
71
|
+
stdio: "inherit",
|
|
72
|
+
shell: true
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Get seed.config.js from project root dir
|
|
78
|
+
*
|
|
79
|
+
* @param {string} themeRoot - the path to theme root dir
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
exports.shopifyCLI = shopifyCLI;
|
|
83
|
+
|
|
84
|
+
function getSeedConfig(themeRoot) {
|
|
85
|
+
return require((0, _path.join)(themeRoot, 'seed.config.js'));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get store name from seed.config.js
|
|
89
|
+
*
|
|
90
|
+
* @param {string} themeRoot - the path to theme root dir
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
function getStoreName(themeRoot) {
|
|
95
|
+
return getSeedConfig(themeRoot).store;
|
|
96
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@madebyseed/seed-cli-tools",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Seed CLI Tools",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"clean": "rm -rf lib/",
|
|
8
|
+
"start": "npm run clean && babel -w -d lib/ src/",
|
|
9
|
+
"test": "npm run lint",
|
|
10
|
+
"prepublish": "npm test && npm run clean && babel -d lib/ src/",
|
|
11
|
+
"lint": "eslint --max-warnings 0 src/",
|
|
12
|
+
"lint-allow-warning": "eslint src/"
|
|
13
|
+
},
|
|
14
|
+
"author": "SeedCMS",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@babel/cli": "^7.14.8",
|
|
18
|
+
"@babel/core": "^7.14.8",
|
|
19
|
+
"@babel/preset-env": "^7.14.8",
|
|
20
|
+
"@babel/register": "^7.14.5",
|
|
21
|
+
"babel-eslint": "^10.1.0",
|
|
22
|
+
"eslint": "^7.31.0"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@shopify/themekit": "^1.1.9",
|
|
26
|
+
"autoprefixer": "^10.3.1",
|
|
27
|
+
"bluebird": "^3.7.2",
|
|
28
|
+
"chalk": "^4.1.1",
|
|
29
|
+
"chokidar": "^3.5.2",
|
|
30
|
+
"cross-spawn": "^7.0.3",
|
|
31
|
+
"debug": "^4.3.2",
|
|
32
|
+
"del": "^6.0.0",
|
|
33
|
+
"fancy-log": "^1.3.3",
|
|
34
|
+
"figures": "^3.2.0",
|
|
35
|
+
"find-root": "^1.1.0",
|
|
36
|
+
"gulp": "^4.0.2",
|
|
37
|
+
"gulp-cheerio": "^1.0.0",
|
|
38
|
+
"gulp-cssimport": "^7.0.0",
|
|
39
|
+
"gulp-ext-replace": "^0.3.0",
|
|
40
|
+
"gulp-include": "^2.4.1",
|
|
41
|
+
"gulp-plumber": "^1.2.1",
|
|
42
|
+
"gulp-postcss": "^9.0.0",
|
|
43
|
+
"gulp-sass": "^5.0.0",
|
|
44
|
+
"gulp-size": "^4.0.1",
|
|
45
|
+
"gulp-svgmin": "^4.0.1",
|
|
46
|
+
"gulp-uglify": "^3.0.2",
|
|
47
|
+
"gulp-zip": "^5.1.0",
|
|
48
|
+
"gulp4-run-sequence": "^1.0.1",
|
|
49
|
+
"postcss": "^8.3.6",
|
|
50
|
+
"require-directory": "^2.1.1",
|
|
51
|
+
"sass": "^1.36.0",
|
|
52
|
+
"tailwindcss": "^2.2.7",
|
|
53
|
+
"vinyl-paths": "^3.0.1",
|
|
54
|
+
"yargs": "^17.0.1"
|
|
55
|
+
},
|
|
56
|
+
"gitHead": "c8014098190f878e6bd6623c69c9164a1d94001c"
|
|
57
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import spawn from 'cross-spawn';
|
|
2
|
+
import debug from 'debug';
|
|
3
|
+
import config from '../config';
|
|
4
|
+
|
|
5
|
+
const logger = debug('slate-tools:deploy');
|
|
6
|
+
|
|
7
|
+
export default function(program) {
|
|
8
|
+
program
|
|
9
|
+
.command('deploy')
|
|
10
|
+
.alias('d')
|
|
11
|
+
.description('Runs a full deploy of your theme\'s code to a Shopify store specified in config.yml. Existing files will be overwritten.')
|
|
12
|
+
.option('-e, --env <environment>[,<environment>...]', 'Shopify store(s) to deploy code to (specified in config.yml - default: development)', 'development')
|
|
13
|
+
.option('-m, --manual', 'outputs the compiled theme files to <theme>/upload/<theme>.zip for manual deployment')
|
|
14
|
+
.action((options = {}) => {
|
|
15
|
+
logger(`--gulpfile ${config.gulpFile}`);
|
|
16
|
+
logger(`--cwd ${config.themeRoot}`);
|
|
17
|
+
|
|
18
|
+
const args = ['deploy', '--environment', options.env];
|
|
19
|
+
|
|
20
|
+
spawn(config.gulp, args.concat(['--gulpfile', config.gulpFile, '--cwd', config.themeRoot]), {
|
|
21
|
+
detached: false,
|
|
22
|
+
stdio: 'inherit',
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { red, yellow } from "chalk";
|
|
2
|
+
import figures from "figures";
|
|
3
|
+
import spawn from "cross-spawn";
|
|
4
|
+
import debug from "debug";
|
|
5
|
+
import config from "../config";
|
|
6
|
+
import { getStoreName, shopifyCLI } from "../utils";
|
|
7
|
+
|
|
8
|
+
const logger = debug("seed-tools:watch");
|
|
9
|
+
|
|
10
|
+
export default function (program) {
|
|
11
|
+
program
|
|
12
|
+
.command("watch")
|
|
13
|
+
.alias("w")
|
|
14
|
+
.description(
|
|
15
|
+
"Watches files for code changes and immediately deploys updates to dev theme as they occur. " +
|
|
16
|
+
"This uses shopify theme serve under the hood."
|
|
17
|
+
)
|
|
18
|
+
.action((options = {}) => {
|
|
19
|
+
logger(`--gulpfile ${config.gulpFile}`);
|
|
20
|
+
logger(`--cwd ${config.themeRoot}`);
|
|
21
|
+
const store = getStoreName(config.themeRoot);
|
|
22
|
+
|
|
23
|
+
if (!store) {
|
|
24
|
+
console.log("");
|
|
25
|
+
console.log(
|
|
26
|
+
red(` ${figures.cross} no store field in seed.config.js`)
|
|
27
|
+
);
|
|
28
|
+
console.log(
|
|
29
|
+
" Add 'store: <store.myshopify.com>' to your project seed.config.js"
|
|
30
|
+
);
|
|
31
|
+
console.log("");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
console.log(`Logging into ${yellow(store)} with Shopify CLI...`)
|
|
36
|
+
const loginProcess = shopifyCLI.login(store);
|
|
37
|
+
if (loginProcess.error) {
|
|
38
|
+
console.log("");
|
|
39
|
+
console.log(
|
|
40
|
+
red(` ${figures.cross} Failed logging into ${store}, are you sure you're using the correct account?`)
|
|
41
|
+
);
|
|
42
|
+
console.log("");
|
|
43
|
+
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const gulpArgs = [
|
|
48
|
+
"watch",
|
|
49
|
+
"--gulpfile",
|
|
50
|
+
config.gulpFile,
|
|
51
|
+
"--cwd",
|
|
52
|
+
config.themeRoot,
|
|
53
|
+
"--environment",
|
|
54
|
+
options.env,
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
spawn(config.gulp, gulpArgs, {
|
|
58
|
+
detached: false,
|
|
59
|
+
stdio: "inherit",
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
package/src/config.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { join, normalize } from "path";
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
|
+
import findRoot from "find-root";
|
|
4
|
+
|
|
5
|
+
const workingDirectory = process.cwd();
|
|
6
|
+
const currentDirectory = __dirname;
|
|
7
|
+
|
|
8
|
+
const themeRoot = findRoot(workingDirectory);
|
|
9
|
+
const defaultGulpPath = join(themeRoot, normalize("node_modules/.bin/gulp"));
|
|
10
|
+
// Legacy path for older versions of Node.
|
|
11
|
+
const legacyGulpPath = join(
|
|
12
|
+
themeRoot,
|
|
13
|
+
normalize("node_modules/seed-cli-tools/node_modules/.bin/gulp")
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const config = {
|
|
17
|
+
gulpFile: join(currentDirectory, "gulpfile.js"),
|
|
18
|
+
gulp: existsSync(defaultGulpPath) ? defaultGulpPath : legacyGulpPath,
|
|
19
|
+
themeRoot,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default config;
|
package/src/gulpfile.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const gulp = require('gulp');
|
|
2
|
+
// const argv = require('yargs').argv;
|
|
3
|
+
const runSequence = require('gulp4-run-sequence');
|
|
4
|
+
|
|
5
|
+
// imports gulp tasks from the `tasks` directory
|
|
6
|
+
require('require-directory')(module, './tasks');
|
|
7
|
+
|
|
8
|
+
gulp.task('build', gulp.series(
|
|
9
|
+
'clean',
|
|
10
|
+
gulp.parallel('build:js', 'build:vendor-js', 'build:css', 'build:assets', 'build:svg')
|
|
11
|
+
))
|
|
12
|
+
|
|
13
|
+
gulp.task('build:zip', gulp.series(
|
|
14
|
+
'clean',
|
|
15
|
+
gulp.parallel('build:js', 'build:vendor-js', 'build:css', 'build:assets', 'build:svg')
|
|
16
|
+
))
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Does a full clean/rebuild of your theme and creates a `.zip` compatible with
|
|
20
|
+
* shopify.
|
|
21
|
+
*
|
|
22
|
+
* @function zip
|
|
23
|
+
* @memberof slate-cli.tasks
|
|
24
|
+
* @static
|
|
25
|
+
*/
|
|
26
|
+
gulp.task('zip', (done) => {
|
|
27
|
+
runSequence('build:zip', 'compress', done);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Simple wrapper around src & dist watchers
|
|
33
|
+
*
|
|
34
|
+
* @summary Monitor your codebase for file changes and take the appropriate
|
|
35
|
+
* action
|
|
36
|
+
* @function watch
|
|
37
|
+
* @memberof slate-cli.tasks.watch
|
|
38
|
+
* @static
|
|
39
|
+
*/
|
|
40
|
+
gulp.task('watch', gulp.series(
|
|
41
|
+
'build',
|
|
42
|
+
gulp.parallel('watch:src', 'watch:dist')
|
|
43
|
+
));
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Does a full (re)build followed by a full deploy, cleaning existing files on
|
|
48
|
+
* the remote server and replacing them with the full set of files pushed to
|
|
49
|
+
* `dist` in the build
|
|
50
|
+
*
|
|
51
|
+
* @summary Deploy your built files to the Shopify Store set in
|
|
52
|
+
* `slate-cli.config`
|
|
53
|
+
* @function deploy:manual
|
|
54
|
+
* @memberof slate-cli.tasks.deploy
|
|
55
|
+
* @static
|
|
56
|
+
*/
|
|
57
|
+
gulp.task('deploy', gulp.series(
|
|
58
|
+
'build',
|
|
59
|
+
'deploy:dist'
|
|
60
|
+
));
|
|
61
|
+
|