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

ThemeKit 1.1.2, support section themes #1071

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
28 changes: 28 additions & 0 deletions packages/slate-config/common/paths.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ module.exports = {
'paths.theme.src.snippets': (config) =>
path.join(config.get('paths.theme.src'), 'snippets'),

// Source frame directory
'paths.theme.src.frame': (config) =>
path.join(config.get('paths.theme.src'), 'frame'),

// Source content directory
'paths.theme.src.content': (config) =>
path.join(config.get('paths.theme.src'), 'content'),

// Source pages directory
'paths.theme.src.pages': (config) =>
path.join(config.get('paths.theme.src'), 'pages'),

// Source pages directory
'paths.theme.src.pages.customers': (config) =>
path.join(config.get('paths.theme.src.pages'), 'customers'),

// Static asset directory for files that statically copied to paths.theme.dist.assets
'paths.theme.src.sections': (config) =>
path.join(config.get('paths.theme.src'), 'sections'),
Expand Down Expand Up @@ -82,6 +98,18 @@ module.exports = {
'paths.theme.dist.templates': (config) =>
path.join(config.get('paths.theme.dist'), 'templates'),

// Distribution frame directory
'paths.theme.dist.frame': (config) =>
path.join(config.get('paths.theme.dist'), 'frame'),

// Distribution content directory
'paths.theme.dist.content': (config) =>
path.join(config.get('paths.theme.dist'), 'content'),

// Distribution pages directory
'paths.theme.dist.pages': (config) =>
path.join(config.get('paths.theme.dist'), 'pages'),

// Directory for storing all temporary and/or cache files
'paths.theme.cache': (config) =>
path.join(config.get('paths.theme'), '.cache'),
Expand Down
4 changes: 3 additions & 1 deletion packages/slate-sections-plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ module.exports = class sectionsPlugin {
}

apply(compiler) {
compiler.hooks.emit.tapPromise(PLUGIN_NAME, this.addLocales.bind(this));
if (fs.existsSync(this.options.from)) {
compiler.hooks.emit.tapPromise(PLUGIN_NAME, this.addLocales.bind(this));
}
}

async addLocales(compilation) {
Expand Down
100 changes: 42 additions & 58 deletions packages/slate-sync/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function maybeDeploy() {
if (filesToDeploy.length) {
const files = [...filesToDeploy];
filesToDeploy = [];
return deploy('upload', files);
return deploy('deploy', false, files);
}

return Promise.resolve();
Expand All @@ -45,26 +45,27 @@ 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();
}

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

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

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

return flags;
Expand All @@ -77,11 +78,9 @@ function _generateIgnoreFlags() {
* @param files Array An array of files to deploy
* @return Promise
*/
async function deploy(cmd = '', files = []) {
if (!['upload', 'replace'].includes(cmd)) {
throw new Error(
'shopify-deploy.deploy() first argument must be either "upload", "replace"',
);
async function deploy(cmd = '', replace = false, files = []) {
if (!cmd === 'deploy') {
throw new Error(`shopify-deploy.deploy() first argument must be "deploy"`);
}

deploying = true;
Expand All @@ -90,7 +89,7 @@ async function deploy(cmd = '', files = []) {

try {
await promiseThemekitConfig();
await promiseThemekitDeploy(cmd, files);
await promiseThemekitDeploy(cmd, replace, files);
} catch (error) {
console.error('My Error', error);
}
Expand All @@ -100,49 +99,34 @@ 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();
}
},
);
});
async function promiseThemekitConfig() {
const configure = await themekit(
'configure',
{
..._generateConfigFlags(),
ignoredFiles: _generateIgnoreFlags(),
},
{
cwd: config.get('paths.theme.dist'),
},
);
return configure;
}

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();
}
},
);
});
async function promiseThemekitDeploy(cmd, replace, files) {
const deployment = await themekit(
cmd,
{
noUpdateNotifier: true,
..._generateConfigFlags(),
files: [...files],
noDelete: !replace,
},
{
cwd: config.get('paths.theme.dist'),
},
);
return deployment;
}

/**
Expand Down Expand Up @@ -233,11 +217,11 @@ module.exports = {
},

replace() {
return deploy('replace');
return deploy('deploy', true);
},

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

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.1.2",
"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.19",
"@shopify/theme-lint": "^2.0.0",
"@shopify/themekit": "0.6.12",
"@shopify/themekit": "1.1.2",
"archiver": "^2.1.0",
"array-flatten": "^2.1.1",
"autoprefixer": "6.7.7",
Expand Down
15 changes: 15 additions & 0 deletions packages/slate-tools/tools/webpack/config/parts/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,20 @@ module.exports = {
from: config.get('paths.theme.src.sections'),
to: config.get('paths.theme.dist.sections'),
}),

new SlateSectionsPlugin({
from: config.get('paths.theme.src.frame'),
to: config.get('paths.theme.dist.frame'),
}),

new SlateSectionsPlugin({
from: config.get('paths.theme.src.content'),
to: config.get('paths.theme.dist.content'),
}),

new SlateSectionsPlugin({
from: config.get('paths.theme.src.pages'),
to: config.get('paths.theme.dist.pages'),
}),
],
};
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.1.2":
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