From 479c840a566976c013b6560ebc298e19d63eeb65 Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 7 Nov 2019 18:26:07 -0500 Subject: [PATCH 1/2] Update themekit to 1.1.2, support section themes --- packages/slate-config/common/paths.schema.js | 28 ++++++ packages/slate-sync/index.js | 92 ++++++++----------- packages/slate-sync/package.json | 2 +- packages/slate-tools/package.json | 2 +- .../tools/webpack/config/parts/core.js | 12 +++ yarn.lock | 8 +- 6 files changed, 82 insertions(+), 62 deletions(-) diff --git a/packages/slate-config/common/paths.schema.js b/packages/slate-config/common/paths.schema.js index 881387717..44fcf5b94 100644 --- a/packages/slate-config/common/paths.schema.js +++ b/packages/slate-config/common/paths.schema.js @@ -39,6 +39,22 @@ module.exports = { 'paths.theme.src.snippets': (config) => path.join(config.get('paths.theme.src'), 'snippets'), + // Source snippets directory + 'paths.theme.src.frame': (config) => + path.join(config.get('paths.theme.src'), 'frame'), + + // Source snippets directory + 'paths.theme.src.content': (config) => + path.join(config.get('paths.theme.src'), 'content'), + + // Source snippets directory + 'paths.theme.src.pages': (config) => + path.join(config.get('paths.theme.src'), 'pages'), + + // Source snippets 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'), @@ -82,6 +98,18 @@ module.exports = { 'paths.theme.dist.templates': (config) => path.join(config.get('paths.theme.dist'), 'templates'), + // Source snippets directory + 'paths.theme.dist.frame': (config) => + path.join(config.get('paths.theme.dist'), 'frame'), + + // Source snippets directory + 'paths.theme.dist.content': (config) => + path.join(config.get('paths.theme.dist'), 'content'), + + // Source snippets 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'), diff --git a/packages/slate-sync/index.js b/packages/slate-sync/index.js index e3fab15e5..1cf9633c0 100755 --- a/packages/slate-sync/index.js +++ b/packages/slate-sync/index.js @@ -18,7 +18,7 @@ function maybeDeploy() { if (filesToDeploy.length) { const files = [...filesToDeploy]; filesToDeploy = []; - return deploy('upload', files); + return deploy('deploy', files); } return Promise.resolve(); @@ -45,27 +45,25 @@ 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); - }); + const flags = { + ignoredFiles: ignoreFiles + }; return flags; } @@ -78,7 +76,7 @@ function _generateIgnoreFlags() { * @return Promise */ async function deploy(cmd = '', files = []) { - if (!['upload', 'replace'].includes(cmd)) { + if (!['upload', 'replace', 'deploy'].includes(cmd)) { throw new Error( 'shopify-deploy.deploy() first argument must be either "upload", "replace"', ); @@ -100,49 +98,31 @@ 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() { + return await themekit( + 'configure', + { + ..._generateConfigFlags(), + ..._generateIgnoreFlags(), + }, + { + cwd: config.get('paths.theme.dist') + }, + ) } -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, files) { + return await themekit( + cmd, + { + noUpdateNotifier: true, + ..._generateConfigFlags(), + files: [...files] + }, + { + cwd: config.get('paths.theme.dist') + }, + ); } /** @@ -233,11 +213,11 @@ module.exports = { }, replace() { - return deploy('replace'); + return deploy('deploy'); }, upload() { - return deploy('upload'); + return deploy('deploy'); }, fetchMainThemeId, diff --git a/packages/slate-sync/package.json b/packages/slate-sync/package.json index 815b1f250..bdba75e01 100755 --- a/packages/slate-sync/package.json +++ b/packages/slate-sync/package.json @@ -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", diff --git a/packages/slate-tools/package.json b/packages/slate-tools/package.json index 8119733fe..d599ec7a2 100755 --- a/packages/slate-tools/package.json +++ b/packages/slate-tools/package.json @@ -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", diff --git a/packages/slate-tools/tools/webpack/config/parts/core.js b/packages/slate-tools/tools/webpack/config/parts/core.js index 8aaf3b6ec..c1e80cc1b 100755 --- a/packages/slate-tools/tools/webpack/config/parts/core.js +++ b/packages/slate-tools/tools/webpack/config/parts/core.js @@ -105,6 +105,18 @@ module.exports = { from: config.get('paths.theme.src.templates'), to: config.get('paths.theme.dist.templates'), }, + { + from: config.get('paths.theme.src.pages'), + to: config.get('paths.theme.dist.pages'), + }, + { + from: config.get('paths.theme.src.content'), + to: config.get('paths.theme.dist.content'), + }, + { + from: config.get('paths.theme.src.frame'), + to: config.get('paths.theme.dist.frame'), + }, ]), new SlateSectionsPlugin({ diff --git a/yarn.lock b/yarn.lock index e1f14d5f0..2439277be 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" From f6300b7640d6b4de70e8d875fd612ec5ce01fb9c Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 11 Nov 2019 14:00:17 -0500 Subject: [PATCH 2/2] Upgrade themekit, support for sections everywhere --- packages/slate-config/common/paths.schema.js | 24 ++++----- packages/slate-sections-plugin/index.js | 4 +- packages/slate-sync/index.js | 54 ++++++++++--------- .../tools/webpack/config/parts/core.js | 27 +++++----- 4 files changed, 59 insertions(+), 50 deletions(-) diff --git a/packages/slate-config/common/paths.schema.js b/packages/slate-config/common/paths.schema.js index 44fcf5b94..1f13d29c7 100644 --- a/packages/slate-config/common/paths.schema.js +++ b/packages/slate-config/common/paths.schema.js @@ -39,19 +39,19 @@ module.exports = { 'paths.theme.src.snippets': (config) => path.join(config.get('paths.theme.src'), 'snippets'), - // Source snippets directory + // Source frame directory 'paths.theme.src.frame': (config) => path.join(config.get('paths.theme.src'), 'frame'), - // Source snippets directory + // Source content directory 'paths.theme.src.content': (config) => path.join(config.get('paths.theme.src'), 'content'), - // Source snippets directory + // Source pages directory 'paths.theme.src.pages': (config) => path.join(config.get('paths.theme.src'), 'pages'), - // Source snippets directory + // Source pages directory 'paths.theme.src.pages.customers': (config) => path.join(config.get('paths.theme.src.pages'), 'customers'), @@ -98,17 +98,17 @@ module.exports = { 'paths.theme.dist.templates': (config) => path.join(config.get('paths.theme.dist'), 'templates'), - // Source snippets directory + // Distribution frame directory 'paths.theme.dist.frame': (config) => - path.join(config.get('paths.theme.dist'), 'frame'), - - // Source snippets directory + path.join(config.get('paths.theme.dist'), 'frame'), + + // Distribution content directory 'paths.theme.dist.content': (config) => - path.join(config.get('paths.theme.dist'), 'content'), - - // Source snippets directory + path.join(config.get('paths.theme.dist'), 'content'), + + // Distribution pages directory 'paths.theme.dist.pages': (config) => - path.join(config.get('paths.theme.dist'), 'pages'), + path.join(config.get('paths.theme.dist'), 'pages'), // Directory for storing all temporary and/or cache files 'paths.theme.cache': (config) => diff --git a/packages/slate-sections-plugin/index.js b/packages/slate-sections-plugin/index.js index e4bd8122e..569852a5f 100644 --- a/packages/slate-sections-plugin/index.js +++ b/packages/slate-sections-plugin/index.js @@ -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) { diff --git a/packages/slate-sync/index.js b/packages/slate-sync/index.js index 1cf9633c0..cbbf1a09f 100755 --- a/packages/slate-sync/index.js +++ b/packages/slate-sync/index.js @@ -18,7 +18,7 @@ function maybeDeploy() { if (filesToDeploy.length) { const files = [...filesToDeploy]; filesToDeploy = []; - return deploy('deploy', files); + return deploy('deploy', false, files); } return Promise.resolve(); @@ -45,13 +45,13 @@ 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 @@ -60,10 +60,13 @@ function _generateConfigFlags() { function _generateIgnoreFlags() { const ignoreFiles = slateEnv.getIgnoreFilesValue().split(':'); + const flags = []; - const flags = { - ignoredFiles: ignoreFiles - }; + ignoreFiles.forEach((pattern) => { + if (pattern.length > 0) { + flags.push(pattern); + } + }); return flags; } @@ -75,11 +78,9 @@ function _generateIgnoreFlags() { * @param files Array An array of files to deploy * @return Promise */ -async function deploy(cmd = '', files = []) { - if (!['upload', 'replace', 'deploy'].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; @@ -88,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); } @@ -99,30 +100,33 @@ async function deploy(cmd = '', files = []) { } async function promiseThemekitConfig() { - return await themekit( + const configure = await themekit( 'configure', { ..._generateConfigFlags(), - ..._generateIgnoreFlags(), + ignoredFiles: _generateIgnoreFlags(), }, { - cwd: config.get('paths.theme.dist') + cwd: config.get('paths.theme.dist'), }, - ) + ); + return configure; } -async function promiseThemekitDeploy(cmd, files) { - return await themekit( +async function promiseThemekitDeploy(cmd, replace, files) { + const deployment = await themekit( cmd, { noUpdateNotifier: true, ..._generateConfigFlags(), - files: [...files] + files: [...files], + noDelete: !replace, }, { - cwd: config.get('paths.theme.dist') + cwd: config.get('paths.theme.dist'), }, ); + return deployment; } /** @@ -213,11 +217,11 @@ module.exports = { }, replace() { - return deploy('deploy'); + return deploy('deploy', true); }, upload() { - return deploy('deploy'); + return deploy('deploy', false); }, fetchMainThemeId, diff --git a/packages/slate-tools/tools/webpack/config/parts/core.js b/packages/slate-tools/tools/webpack/config/parts/core.js index c1e80cc1b..48249f2a9 100755 --- a/packages/slate-tools/tools/webpack/config/parts/core.js +++ b/packages/slate-tools/tools/webpack/config/parts/core.js @@ -105,23 +105,26 @@ module.exports = { from: config.get('paths.theme.src.templates'), to: config.get('paths.theme.dist.templates'), }, - { - from: config.get('paths.theme.src.pages'), - to: config.get('paths.theme.dist.pages'), - }, - { - from: config.get('paths.theme.src.content'), - to: config.get('paths.theme.dist.content'), - }, - { - from: config.get('paths.theme.src.frame'), - to: config.get('paths.theme.dist.frame'), - }, ]), new SlateSectionsPlugin({ 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'), + }), ], };