@madebyseed/seed-cli-tools 1.0.0 → 1.2.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/lib/commands/deploy.js +6 -5
- package/lib/commands/watch.js +3 -1
- package/lib/commands/zip.js +27 -0
- package/lib/config.js +3 -1
- package/lib/gulpfile.js +26 -13
- package/lib/tasks/build-js.js +4 -3
- package/lib/tasks/build-utils.js +58 -13
- package/lib/tasks/includes/config.js +66 -39
- package/lib/tasks/includes/utilities.js +14 -38
- package/lib/tasks/shopify-cli.js +97 -0
- package/lib/tasks/watchers.js +24 -15
- package/lib/utils.js +113 -14
- package/package.json +3 -1
- package/src/commands/deploy.js +32 -15
- package/src/commands/watch.js +10 -0
- package/src/commands/zip.js +27 -0
- package/src/config.js +2 -0
- package/src/gulpfile.js +45 -27
- package/src/tasks/build-js.js +2 -1
- package/src/tasks/build-utils.js +76 -15
- package/src/tasks/includes/config.js +67 -41
- package/src/tasks/includes/utilities.js +24 -45
- package/src/tasks/shopify-cli.js +96 -0
- package/src/tasks/watchers.js +22 -21
- package/src/utils.js +99 -29
- package/lib/tasks/deploy.js +0 -19
- package/src/tasks/deploy.js +0 -15
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
const join = require(
|
|
2
|
-
const logger = require(
|
|
3
|
-
const findRoot = require(
|
|
4
|
-
const autoprefixer = require(
|
|
5
|
-
const tailwindcss = require(
|
|
6
|
-
const
|
|
1
|
+
const join = require("path").join;
|
|
2
|
+
const logger = require("debug")("seed-tools");
|
|
3
|
+
const findRoot = require("find-root");
|
|
4
|
+
const autoprefixer = require("autoprefixer");
|
|
5
|
+
const tailwindcss = require("tailwindcss");
|
|
6
|
+
const cssnano = require("cssnano");
|
|
7
|
+
const argv = require("minimist")(process.argv.slice(2));
|
|
7
8
|
const themeRoot = findRoot(process.cwd());
|
|
9
|
+
const tailwindConfig = 'tailwind.config.js'
|
|
8
10
|
|
|
9
11
|
let pkg = {};
|
|
10
12
|
|
|
11
13
|
try {
|
|
12
|
-
pkg = require(join(themeRoot,
|
|
14
|
+
pkg = require(join(themeRoot, "package.json"));
|
|
13
15
|
} catch (err) {
|
|
14
16
|
logger(err);
|
|
15
17
|
}
|
|
@@ -31,65 +33,89 @@ try {
|
|
|
31
33
|
* @memberof seed-cli
|
|
32
34
|
* @summary Configuring seed-cli
|
|
33
35
|
* @prop {String} environment - development | staging | production
|
|
34
|
-
* @prop {String} tkconfig - path to themekit config file
|
|
35
|
-
* @prop {String} scssLintConfig - path to scss-lint config file
|
|
36
36
|
* @prop {String} deployLog - path to deploy log file
|
|
37
37
|
* @prop {String} src - globs (multi-filename matching patterns) for various source files
|
|
38
|
+
* @prop {String} tmp - globs (multi-filename matching patterns) for various tmp files
|
|
38
39
|
* @prop {Object} dist - paths to relevant folder locations in the distributable directory
|
|
39
40
|
* @prop {Object} roots - array of "root" (entry point) JS & CSS files
|
|
40
41
|
* @prop {Object} plugins - configuration objects passed to various plugins used in the task interface
|
|
41
42
|
*/
|
|
42
43
|
const config = {
|
|
43
|
-
environment: argv.
|
|
44
|
+
environment: argv.environment || "development",
|
|
45
|
+
optimize: !argv["skip-optimization"],
|
|
44
46
|
themeRoot,
|
|
45
47
|
packageJson: pkg,
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
tailwindConfig,
|
|
50
|
+
|
|
51
|
+
seedConfig: "seed.config.js",
|
|
52
|
+
|
|
49
53
|
|
|
50
54
|
src: {
|
|
51
|
-
root:
|
|
52
|
-
js:
|
|
53
|
-
vendorJs:
|
|
54
|
-
json:
|
|
55
|
-
css:
|
|
56
|
-
cssLint:
|
|
57
|
-
vendorCss:
|
|
58
|
-
assets:
|
|
59
|
-
icons:
|
|
60
|
-
templates:
|
|
61
|
-
snippets:
|
|
62
|
-
sections:
|
|
63
|
-
locales:
|
|
64
|
-
config:
|
|
65
|
-
layout:
|
|
55
|
+
root: "src/",
|
|
56
|
+
js: "src/scripts/**/*.{js,js.liquid}",
|
|
57
|
+
vendorJs: "src/scripts/vendor/*.js",
|
|
58
|
+
json: "src/**/*.json",
|
|
59
|
+
css: "src/styles/**/*.{css,scss,scss.liquid}",
|
|
60
|
+
cssLint: "src/styles/**/*.{css,scss}",
|
|
61
|
+
vendorCss: "src/styles/vendor/*.{css,scss}",
|
|
62
|
+
assets: "src/assets/**/*",
|
|
63
|
+
icons: "src/icons/**/*.svg",
|
|
64
|
+
templates: "src/templates/**/*",
|
|
65
|
+
snippets: "src/snippets/*",
|
|
66
|
+
sections: "src/sections/*",
|
|
67
|
+
locales: "src/locales/*",
|
|
68
|
+
config: "src/config/*",
|
|
69
|
+
layout: "src/layout/*",
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
tmp: {
|
|
73
|
+
root: "tmp/",
|
|
74
|
+
js: "tmp/scripts/**/*.{js,js.liquid}",
|
|
75
|
+
vendorJs: "tmp/scripts/vendor/*.js",
|
|
76
|
+
json: "tmp/**/*.json",
|
|
77
|
+
css: "tmp/styles/**/*.{css,scss,scss.liquid}",
|
|
78
|
+
cssLint: "tmp/styles/**/*.{css,scss}",
|
|
79
|
+
vendorCss: "tmp/styles/vendor/*.{css,scss}",
|
|
80
|
+
assets: "tmp/assets/**/*",
|
|
81
|
+
icons: "tmp/icons/**/*.svg",
|
|
82
|
+
templates: "tmp/templates/**/*",
|
|
83
|
+
snippets: "tmp/snippets/*",
|
|
84
|
+
sections: "tmp/sections/*",
|
|
85
|
+
locales: "tmp/locales/*",
|
|
86
|
+
config: "tmp/config/*",
|
|
87
|
+
layout: "tmp/layout/*",
|
|
66
88
|
},
|
|
67
89
|
|
|
68
90
|
dist: {
|
|
69
|
-
root:
|
|
70
|
-
assets:
|
|
71
|
-
snippets:
|
|
72
|
-
sections:
|
|
73
|
-
layout:
|
|
74
|
-
templates:
|
|
75
|
-
locales:
|
|
91
|
+
root: "dist/",
|
|
92
|
+
assets: "dist/assets/",
|
|
93
|
+
snippets: "dist/snippets/",
|
|
94
|
+
sections: "dist/sections/",
|
|
95
|
+
layout: "dist/layout/",
|
|
96
|
+
templates: "dist/templates/",
|
|
97
|
+
locales: "dist/locales/",
|
|
76
98
|
},
|
|
77
99
|
|
|
78
100
|
roots: {
|
|
79
|
-
js:
|
|
80
|
-
vendorJs:
|
|
81
|
-
css:
|
|
101
|
+
js: "src/scripts/*.{js,js.liquid}",
|
|
102
|
+
vendorJs: "src/scripts/vendor.js",
|
|
103
|
+
css: "src/styles/*.{css,scss}",
|
|
82
104
|
},
|
|
83
105
|
|
|
84
106
|
plugins: {
|
|
85
107
|
cheerio: {
|
|
86
|
-
run: require(
|
|
108
|
+
run: require("./utilities.js").processSvg,
|
|
87
109
|
},
|
|
88
110
|
postcss: [
|
|
89
|
-
tailwindcss({ config: join(themeRoot,
|
|
90
|
-
autoprefixer(),
|
|
91
|
-
]
|
|
111
|
+
tailwindcss({ config: join(themeRoot, tailwindConfig) }),
|
|
112
|
+
autoprefixer(),
|
|
113
|
+
],
|
|
92
114
|
},
|
|
93
115
|
};
|
|
94
116
|
|
|
117
|
+
if (config.optimize) {
|
|
118
|
+
config.plugins.postcss.push((cssnano({ preset: "default" })))
|
|
119
|
+
}
|
|
120
|
+
|
|
95
121
|
module.exports = config;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
const chalk = require("chalk");
|
|
2
2
|
const log = require("fancy-log");
|
|
3
|
-
const _ = require(
|
|
4
|
-
const Promise = require(
|
|
5
|
-
const { shopifyCLI } = require("../../utils");
|
|
6
|
-
|
|
3
|
+
const _ = require("lodash");
|
|
4
|
+
const Promise = require("bluebird");
|
|
7
5
|
|
|
8
6
|
let errors = [];
|
|
9
7
|
|
|
@@ -15,28 +13,6 @@ let errors = [];
|
|
|
15
13
|
* @memberof seed-cli
|
|
16
14
|
*/
|
|
17
15
|
const utilities = {
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Launches shopify theme serve command to serve files on ./dist folder
|
|
21
|
-
*
|
|
22
|
-
* @memberof seed-cli.utilities
|
|
23
|
-
* @returns {object} - ChildProcess
|
|
24
|
-
*/
|
|
25
|
-
serveDist: () => {
|
|
26
|
-
return shopifyCLI.serve();
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Launches shopify theme push command to deploy files on ./dist folder
|
|
31
|
-
* to a store's theme
|
|
32
|
-
*
|
|
33
|
-
* @memberof seed-cli.utilities
|
|
34
|
-
* @returns {object} - ChildProcess
|
|
35
|
-
*/
|
|
36
|
-
deployDist: () => {
|
|
37
|
-
return shopifyCLI.push();
|
|
38
|
-
},
|
|
39
|
-
|
|
40
16
|
/**
|
|
41
17
|
* Handles the output for any errors that might have been captured
|
|
42
18
|
* during the build and zip Gulp tasks.
|
|
@@ -68,7 +44,7 @@ const utilities = {
|
|
|
68
44
|
log(chalk.red(err));
|
|
69
45
|
errors.push(err);
|
|
70
46
|
|
|
71
|
-
this.emit(
|
|
47
|
+
this.emit("end");
|
|
72
48
|
},
|
|
73
49
|
|
|
74
50
|
/**
|
|
@@ -84,7 +60,9 @@ const utilities = {
|
|
|
84
60
|
const result = factory();
|
|
85
61
|
results.push(result);
|
|
86
62
|
return result;
|
|
87
|
-
})
|
|
63
|
+
})
|
|
64
|
+
.thenReturn(results)
|
|
65
|
+
.all();
|
|
88
66
|
},
|
|
89
67
|
|
|
90
68
|
/**
|
|
@@ -96,30 +74,30 @@ const utilities = {
|
|
|
96
74
|
* @param {fs} file - reference to current icon file?
|
|
97
75
|
*/
|
|
98
76
|
processSvg: ($, file) => {
|
|
99
|
-
var $svg = $(
|
|
100
|
-
var $newSvg = $(
|
|
101
|
-
|
|
102
|
-
|
|
77
|
+
var $svg = $("svg"); // eslint-disable-line no-var
|
|
78
|
+
var $newSvg = $(
|
|
79
|
+
'<svg aria-hidden="true" focusable="false" role="presentation" class="icon" />'
|
|
80
|
+
); // eslint-disable-line no-var
|
|
81
|
+
var fileName = file.relative.replace(".svg", ""); // eslint-disable-line no-var
|
|
82
|
+
var viewBoxAttr = $svg.attr("viewbox"); // eslint-disable-line no-var
|
|
103
83
|
|
|
104
84
|
// Add necessary attributes
|
|
105
85
|
if (viewBoxAttr) {
|
|
106
|
-
var width = parseInt(viewBoxAttr.split(
|
|
107
|
-
var height = parseInt(viewBoxAttr.split(
|
|
86
|
+
var width = parseInt(viewBoxAttr.split(" ")[2], 10); // eslint-disable-line no-var
|
|
87
|
+
var height = parseInt(viewBoxAttr.split(" ")[3], 10); // eslint-disable-line no-var
|
|
108
88
|
var widthToHeightRatio = width / height; // eslint-disable-line no-var
|
|
109
89
|
if (widthToHeightRatio >= 1.5) {
|
|
110
|
-
$newSvg.addClass(
|
|
90
|
+
$newSvg.addClass("icon--wide");
|
|
111
91
|
}
|
|
112
|
-
$newSvg.attr(
|
|
92
|
+
$newSvg.attr("viewBox", viewBoxAttr);
|
|
113
93
|
}
|
|
114
94
|
|
|
115
95
|
// Add required classes to full color icons
|
|
116
|
-
if (file.relative.indexOf(
|
|
117
|
-
$newSvg.addClass(
|
|
96
|
+
if (file.relative.indexOf("-full-color") >= 0) {
|
|
97
|
+
$newSvg.addClass("icon--full-color");
|
|
118
98
|
}
|
|
119
99
|
|
|
120
|
-
$newSvg
|
|
121
|
-
.addClass(fileName)
|
|
122
|
-
.append($svg.contents());
|
|
100
|
+
$newSvg.addClass(fileName).append($svg.contents());
|
|
123
101
|
|
|
124
102
|
$newSvg.append($svg.contents());
|
|
125
103
|
$svg.after($newSvg);
|
|
@@ -135,9 +113,10 @@ const utilities = {
|
|
|
135
113
|
* @returns {eventCache} see type definition for more robust documentation
|
|
136
114
|
*/
|
|
137
115
|
createEventCache: (options) => {
|
|
138
|
-
_.defaults(options = options || {}, {
|
|
139
|
-
|
|
140
|
-
|
|
116
|
+
_.defaults((options = options || {}), {
|
|
117
|
+
// eslint-disable-line no-param-reassign
|
|
118
|
+
changeEvents: ["add", "change"],
|
|
119
|
+
unlinkEvents: ["unlink"],
|
|
141
120
|
});
|
|
142
121
|
|
|
143
122
|
/**
|
|
@@ -162,7 +141,7 @@ const utilities = {
|
|
|
162
141
|
* @param {String} event - chokidar event type - only cares about `(add|change|unlink)`
|
|
163
142
|
* @param {String} path - relative path to file passed via event
|
|
164
143
|
*/
|
|
165
|
-
addEvent: function(event, path) {
|
|
144
|
+
addEvent: function (event, path) {
|
|
166
145
|
_.each(options.changeEvents, (eventType) => {
|
|
167
146
|
if (event === eventType) {
|
|
168
147
|
this.change.push(path);
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const gulp = require("gulp");
|
|
2
|
+
// const path = require("path");
|
|
3
|
+
const {
|
|
4
|
+
shopifyCLI,
|
|
5
|
+
extractThemeId,
|
|
6
|
+
logChildProcessOutput,
|
|
7
|
+
getDevThemeID,
|
|
8
|
+
setDevThemeID,
|
|
9
|
+
getThemeID,
|
|
10
|
+
} = require("../utils");
|
|
11
|
+
const config = require("./includes/config");
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Initiates shopify's cli command 'shopify theme serve' on the dist folder,
|
|
15
|
+
* watching files and uploading them to development store
|
|
16
|
+
*
|
|
17
|
+
* @function shopify:serve:dist
|
|
18
|
+
* @memberof seed-cli.tasks.watch
|
|
19
|
+
* @static
|
|
20
|
+
*/
|
|
21
|
+
gulp.task("shopify:serve:dist", () => {
|
|
22
|
+
console.log("Running Shopify theme serve...");
|
|
23
|
+
const childProcess = shopifyCLI.serve({
|
|
24
|
+
stdio: ["inherit", "pipe", "inherit"],
|
|
25
|
+
});
|
|
26
|
+
childProcess.stdout.setEncoding("utf8");
|
|
27
|
+
logChildProcessOutput(childProcess);
|
|
28
|
+
persistDevThemeID(childProcess);
|
|
29
|
+
return childProcess;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Pulls theme files from the development theme specified in seed config into src
|
|
34
|
+
*
|
|
35
|
+
* @function shopify:pull:dev
|
|
36
|
+
* @memberof seed-cli.tasks.deploy
|
|
37
|
+
* @static
|
|
38
|
+
*/
|
|
39
|
+
gulp.task("shopify:pull:dev", (done) => {
|
|
40
|
+
const devThemeId = getDevThemeID(config.themeRoot);
|
|
41
|
+
if (!devThemeId) {
|
|
42
|
+
return done();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return shopifyCLI.pull(devThemeId);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Pulls theme files from the development theme specified in seed config into tmp
|
|
50
|
+
*
|
|
51
|
+
* @function shopify:pull:dev:tmp
|
|
52
|
+
* @memberof seed-cli.tasks.deploy
|
|
53
|
+
* @static
|
|
54
|
+
*/
|
|
55
|
+
gulp.task("shopify:pull:dev:tmp", (done) => {
|
|
56
|
+
const devThemeId = getDevThemeID(config.themeRoot);
|
|
57
|
+
if (!devThemeId) {
|
|
58
|
+
return done();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return shopifyCLI.pull(
|
|
62
|
+
devThemeId,
|
|
63
|
+
config.tmp.root
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Initiates shopify's cli command 'shopify theme push' on the dist folder,
|
|
69
|
+
* pushing it to stores theme
|
|
70
|
+
*
|
|
71
|
+
* @function deploy:dist
|
|
72
|
+
* @memberof seed-cli.tasks.deploy
|
|
73
|
+
* @static
|
|
74
|
+
*/
|
|
75
|
+
gulp.task("shopify:push:dist", () => {
|
|
76
|
+
return shopifyCLI.push(getThemeID(config.themeRoot, config.environment));
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Takes the output of shopify cli serve, extracts dev theme ID and persists
|
|
81
|
+
* in seed.config.js
|
|
82
|
+
*
|
|
83
|
+
* @param {child_process} serveProcess shopify cli serve spawned child process
|
|
84
|
+
*/
|
|
85
|
+
function persistDevThemeID(serveProcess) {
|
|
86
|
+
serveProcess.stdout.on("data", (data) => {
|
|
87
|
+
const devThemeId = extractThemeId(data.toString());
|
|
88
|
+
const currentDevThemeId = getDevThemeID(config.themeRoot);
|
|
89
|
+
|
|
90
|
+
// If we already have latest dev theme ID, we got nothing left to do
|
|
91
|
+
if (devThemeId === currentDevThemeId) return;
|
|
92
|
+
|
|
93
|
+
// Else, write dev theme ID into seed.config.js
|
|
94
|
+
setDevThemeID(devThemeId);
|
|
95
|
+
});
|
|
96
|
+
}
|
package/src/tasks/watchers.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
1
|
+
const gulp = require("gulp");
|
|
2
|
+
const config = require("./includes/config");
|
|
3
|
+
const chokidar = require("chokidar");
|
|
4
|
+
const utils = require("./includes/utilities");
|
|
3
5
|
// const runSequence = require('gulp4-run-sequence');
|
|
4
6
|
// const _ = require('lodash');
|
|
5
7
|
// const debug = require('debug')('seed-tools:watchers');
|
|
6
|
-
// const chokidar = require('chokidar');
|
|
7
8
|
// const fs = require('fs');
|
|
8
9
|
// const themekit = require('@shopify/themekit');
|
|
9
10
|
// const Promise = require('bluebird');
|
|
10
11
|
|
|
11
|
-
|
|
12
12
|
// const config = require('./includes/config.js');
|
|
13
|
-
const
|
|
14
|
-
// const messages = require('./includes/messages.js');
|
|
13
|
+
const messages = require("./includes/messages.js");
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
const cache = utils.createEventCache();
|
|
17
16
|
// const environment = config.environment.split(/\s*,\s*|\s+/)[0];
|
|
18
17
|
|
|
19
18
|
/**
|
|
@@ -25,24 +24,26 @@ const utils = require('./includes/utilities.js');
|
|
|
25
24
|
* @memberof seed-cli.tasks.watch
|
|
26
25
|
* @static
|
|
27
26
|
*/
|
|
28
|
-
gulp.task(
|
|
29
|
-
return gulp.parallel(
|
|
30
|
-
'watch:css',
|
|
31
|
-
'watch:js',
|
|
32
|
-
'watch:assets',
|
|
33
|
-
'watch:svg'
|
|
34
|
-
)()
|
|
27
|
+
gulp.task("watch:src", () => {
|
|
28
|
+
return gulp.parallel("watch:css", "watch:js", "watch:assets", "watch:svg")();
|
|
35
29
|
});
|
|
36
30
|
|
|
37
31
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
32
|
+
* Watches for changes in the `./dist` folder and passes event data to the
|
|
33
|
+
* `cache` via {@link pushToCache}.
|
|
41
34
|
* @function watch:dist
|
|
42
35
|
* @memberof seed-cli.tasks.watch
|
|
43
36
|
* @static
|
|
44
37
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
gulp.task("watch:dist", () => {
|
|
39
|
+
const watcher = chokidar.watch(["./"], {
|
|
40
|
+
cwd: config.dist.root,
|
|
41
|
+
ignored: /(^|[/\\])\../,
|
|
42
|
+
ignoreInitial: true,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
watcher.on("all", (event, path) => {
|
|
46
|
+
messages.logFileEvent(event, path);
|
|
47
|
+
cache.addEvent(event, path);
|
|
48
|
+
});
|
|
49
|
+
});
|
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
|
|
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 = [
|
|
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
|
-
|
|
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(
|
|
45
|
-
cwd: config.themeRoot +
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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,
|
|
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
|
+
}
|
package/lib/tasks/deploy.js
DELETED
|
@@ -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
|
-
});
|
package/src/tasks/deploy.js
DELETED
|
@@ -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
|
-
})
|