Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Update Themekit version and themekit-node API #1058

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 26 additions & 69 deletions packages/slate-sync/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const chalk = require('chalk');
const figures = require('figures');
const https = require('https');
const themekit = require('@shopify/themekit').command;
const themekit = require('@shopify/themekit');
const slateEnv = require('@shopify/slate-env');
const SlateConfig = require('@shopify/slate-config');

Expand All @@ -18,7 +18,7 @@ function maybeDeploy() {
if (filesToDeploy.length) {
const files = [...filesToDeploy];
filesToDeploy = [];
return deploy('upload', files);
return deploy('deploy', files);
}

return Promise.resolve();
Expand All @@ -45,28 +45,19 @@ function _generateConfigFlags() {
_validateEnvValues();

const flags = {
'--password': slateEnv.getPasswordValue(),
'--themeid': slateEnv.getThemeIdValue(),
'--store': slateEnv.getStoreValue(),
'--env': slateEnv.getEnvNameValue(),
password: slateEnv.getPasswordValue(),
themeid: slateEnv.getThemeIdValue(),
store: slateEnv.getStoreValue(),
env: slateEnv.getEnvNameValue(),
};
if (slateEnv.getTimeoutValue()) {
flags['--timeout'] = slateEnv.getTimeoutValue();
flags.timeout = slateEnv.getTimeoutValue();
}
if (slateEnv.getIgnoreFilesValue()) {
flags.ignoredFiles = slateEnv.getIgnoreFilesValue().split(':');
}

// Convert object to key value pairs and flatten the array
return Array.prototype.concat(...Object.entries(flags));
}

function _generateIgnoreFlags() {
const ignoreFiles = slateEnv.getIgnoreFilesValue().split(':');
const flags = [];

ignoreFiles.forEach((pattern) => {
flags.push('--ignored-file');
flags.push(pattern);
});

return flags;
}

Expand All @@ -78,9 +69,9 @@ function _generateIgnoreFlags() {
* @return Promise
*/
async function deploy(cmd = '', files = []) {
if (!['upload', 'replace'].includes(cmd)) {
if (!['deploy', 'replace'].includes(cmd)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like replace doesn't exist anymore? And has been replaced by deploy. And that upload has been replaced by deploy --nodelete?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right. I'll update the the commands and documentation to reflect this when I get a chance

throw new Error(
'shopify-deploy.deploy() first argument must be either "upload", "replace"',
'shopify-deploy.deploy() first argument must be either "deploy", "replace"',
);
}

Expand All @@ -89,8 +80,19 @@ async function deploy(cmd = '', files = []) {
console.log(chalk.magenta(`\n${figures.arrowUp} Uploading to Shopify...\n`));

try {
await promiseThemekitConfig();
await promiseThemekitDeploy(cmd, files);
await themekit.command('configure', _generateConfigFlags(), {
cwd: config.get('paths.theme.dist'),
});
await themekit.command(
cmd,
{
..._generateConfigFlags(),
files,
},
{
cwd: config.get('paths.theme.dist'),
},
);
} catch (error) {
console.error('My Error', error);
}
Expand All @@ -100,51 +102,6 @@ async function deploy(cmd = '', files = []) {
return maybeDeploy;
}

function promiseThemekitConfig() {
return new Promise((resolve, reject) => {
themekit(
{
args: [
'configure',
..._generateConfigFlags(),
..._generateIgnoreFlags(),
],
cwd: config.get('paths.theme.dist'),
},
(err) => {
if (err) {
reject(err);
} else {
resolve();
}
},
);
});
}

function promiseThemekitDeploy(cmd, files) {
return new Promise((resolve, reject) => {
themekit(
{
args: [
cmd,
'--no-update-notifier',
..._generateConfigFlags(),
...files,
],
cwd: config.get('paths.theme.dist'),
},
(err) => {
if (err) {
reject(err);
} else {
resolve();
}
},
);
});
}

/**
* Fetch the main theme ID from Shopify
*
Expand Down Expand Up @@ -237,7 +194,7 @@ module.exports = {
},

upload() {
return deploy('upload');
return deploy('deploy');
},

fetchMainThemeId,
Expand Down
2 changes: 1 addition & 1 deletion packages/slate-sync/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@shopify/slate-analytics": "1.0.0-beta.16",
"@shopify/slate-config": "1.0.0-beta.14",
"@shopify/slate-env": "1.0.0-beta.16",
"@shopify/themekit": "0.6.12",
"@shopify/themekit": "^1.0.1",
"array-flatten": "^2.1.1",
"chalk": "2.3.2",
"figures": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/slate-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@shopify/slate-tag-webpack-plugin": "1.0.0-beta.14",
"@shopify/slate-translations": "1.0.0-beta.18",
"@shopify/theme-lint": "^2.0.0",
"@shopify/themekit": "0.6.12",
"@shopify/themekit": "^1.0.1",
"archiver": "^2.1.0",
"array-flatten": "^2.1.1",
"autoprefixer": "6.7.7",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1173,10 +1173,10 @@
htmllint "^0.6.0"
lodash "^4.15.0"

"@shopify/themekit@0.6.12":
version "0.6.12"
resolved "https://registry.yarnpkg.com/@shopify/themekit/-/themekit-0.6.12.tgz#7cf86175b3b62ef7f405f068fd6f7c0cc8fd30bc"
integrity sha512-8yzAoXACUvAJEZU7vpcIGZcMayHcvwMqEc2XKKSSqZN7HHD1VMbogepMb/8h6jZ0xFUHH0IQSpT0sKZfAKDMrw==
"@shopify/themekit@^1.0.1":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@shopify/themekit/-/themekit-1.1.2.tgz#658a54a9b933ffb13015f5e4eae8a10b4d704bd7"
integrity sha512-+/iu/U4UHDM0VmPfx0dgj7mtjSD5QS09JOnS1Lz9iitxzKl/YdZ0GwnJK0plmt5TxqRpzFK5hYbM9DYBnto9Bg==
dependencies:
bin-wrapper "3.0.2"
minimist "1.2.0"
Expand Down