From 0fadb19ccb01979bcc4551d9f249ee0e62b578a5 Mon Sep 17 00:00:00 2001 From: Eric Hayes Date: Wed, 9 Dec 2020 22:47:51 -0600 Subject: [PATCH] fix(packer-config): env value live for allowing live theme deploy Signed-off-by: Eric Hayes --- CHANGELOG.md | 9 +++++ README.md | 36 ++++++++++--------- cli/commands/deploy.js | 12 +++++-- package.json | 2 +- src/env/index.js | 15 +++++++- src/env/packer-env.schema.js | 6 +++- .../prompts/continue-if-published-theme.js | 8 +++-- src/server/sync.js | 3 ++ 8 files changed, 66 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5598134..978831f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## [1.3.1](https://github.com/hayes0724/shopify-packer/compare/1.3.0...1.3.1) (2020-12-10) + + +### :bug: Bug Fixes + +* **packer-config:** env value live for allowing live theme deploy ([abd0d9f](https://github.com/hayes0724/shopify-packer/commit/abd0d9f5bc98a50eb8850e8785c5a34d50d1df72)), closes [#25](https://github.com/hayes0724/shopify-packer/issues/25) + + + # [1.3.0](https://github.com/hayes0724/shopify-packer/compare/1.2.1...1.3.0) (2020-12-10) diff --git a/README.md b/README.md index 9054458..260554a 100644 --- a/README.md +++ b/README.md @@ -249,20 +249,24 @@ Environment settings are located in ``packer.env.json``. ```json { - "themes": { "development": { "id": "74500041118", "password": "ebd6ce7f27aae8cdafb8111a5b887b9", "store": "my-store-name.myshopify.com", + "live": "false", "ignore": [ "settings_data.json" ] } - } } + ``` + By default, most commands will use development environment unless you override with the ``--env`` flag + +live - will allow deploying to published themes and skip the default prompts + ``` packer start --env=production ``` @@ -287,7 +291,7 @@ module.exports = { 'theme.dist.root': path.join(process.cwd(), 'dist'), // Change your theme source templates 'theme.src.templates': path.join(process.cwd(), 'src/templates'), - // Configure network settigns if you don't like the autoconfig + // Configure network settigns if you don't like the autoconfig 'network.ipAddress': '192.168.1.1', 'network.external': '', 'network.interface': '', @@ -307,22 +311,22 @@ interface ip address in your system. Packer can be used with existing themes or you can create a new theme. It must follow the following structure: ``` -├── .babelrc -├── .eslintrc -├── .gitignore -├── .stylelintrc -├── .prettierignore +├── .babelrc +├── .eslintrc +├── .gitignore +├── .stylelintrc +├── .prettierignore ├── .stylelintignore ├── .prettierrc.json ├── .eslintignore ├── .editorconfig -├── packer.env.json -├── packer.config.js -├── dev.config.js -├── prod.config.js -├── postcss.config.js -├── package.json -├── yarn.lock +├── packer.env.json +├── packer.config.js +├── dev.config.js +├── prod.config.js +├── postcss.config.js +├── package.json +├── yarn.lock └── src ├── assets ├── config @@ -510,7 +514,7 @@ All you need to do is include these snippets in your layout files. For example, here is what you would include in your ``layout/theme.liquid``: ``` -{% include 'style-tags' %} +{% include 'style-tags' %} {% include 'script-tags', layout: 'theme' %} ``` where the layout option value is the name of the layout. diff --git a/cli/commands/deploy.js b/cli/commands/deploy.js index c95f579..6011a87 100644 --- a/cli/commands/deploy.js +++ b/cli/commands/deploy.js @@ -2,15 +2,21 @@ const chalk = require('chalk'); const {deploy, replace} = require('../../src/server/sync'); const promptContinueIfPublishedTheme = require('../../src/server/prompts/continue-if-published-theme'); -const {getThemeIdValue, assign} = require('../../src/env'); +const { + getThemeIdValue, + getAllowLiveValue, + setAllowLiveValue, + assign, +} = require('../../src/env'); -module.exports = (args) => { +module.exports = async (args) => { assign(args.env); - promptContinueIfPublishedTheme(getThemeIdValue()) + await promptContinueIfPublishedTheme(getThemeIdValue(), getAllowLiveValue()) .then((answer) => { if (!answer) { process.exit(0); } + setAllowLiveValue('true'); if (args.nodelete) { return deploy(); } diff --git a/package.json b/package.json index 40e0078..0a563e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hayes0724/shopify-packer", - "version": "1.3.0", + "version": "1.3.1", "bin": { "packer": "cli/index.js" }, diff --git a/src/env/index.js b/src/env/index.js index 40f16b7..1899e83 100644 --- a/src/env/index.js +++ b/src/env/index.js @@ -8,6 +8,7 @@ const PACKER_ENV_VARS = [ config.get('env.keys.password'), config.get('env.keys.id'), config.get('env.keys.ignore'), + config.get('env.keys.live'), ]; const DEFAULT_ENV_VARS = [ @@ -15,6 +16,7 @@ const DEFAULT_ENV_VARS = [ config.get('env.keys.password'), config.get('env.keys.id'), config.get('env.keys.ignore'), + config.get('env.keys.live'), ]; function assign(envName = undefined) { @@ -56,7 +58,7 @@ function getEnvNameValue() { return process.env[config.get('env.keys.name')]; } -// Returns the configurable environment varible that reference the store URL +// Returns the configurable environment variable that reference the store URL function getStoreValue() { const value = process.env[config.get('env.keys.store')]; return typeof value === 'undefined' ? '' : value; @@ -72,11 +74,20 @@ function getThemeIdValue() { return typeof value === 'undefined' ? '' : value; } +function getAllowLiveValue() { + const value = process.env[config.get('env.keys.live')]; + return value === 'true'; +} + function getIgnoreFilesValue() { const value = process.env[config.get('env.keys.ignore')]; return typeof value === 'undefined' ? '' : value; } +function setAllowLiveValue(value) { + process.env[config.get('env.keys.live')] = value; +} + function validate() { const errors = [].concat( _validateStore(), @@ -168,6 +179,8 @@ module.exports = { clear, getPackerEnv, getEmptyPackerEnv, + getAllowLiveValue, + setAllowLiveValue, getEnvNameValue, getStoreValue, getPasswordValue, diff --git a/src/env/packer-env.schema.js b/src/env/packer-env.schema.js index 5e1aa2c..28cf686 100644 --- a/src/env/packer-env.schema.js +++ b/src/env/packer-env.schema.js @@ -5,7 +5,7 @@ module.exports = { // The environment variable key which contains the name of the environment // Packer is running in - 'env.keys.name': 'ENV_NAME', + 'env.keys.name': 'PACKER_ENV', // The environment variable key which contains the myshopify.com URL to your // Shopify store @@ -22,4 +22,8 @@ module.exports = { // The environment variable key which contains a list of file patterns to // ignore, with each list item separated by ':' 'env.keys.ignore': 'PACKER_IGNORE', + + // The environment variable key which contains a list of file patterns to + // allow deployment to live themes + 'env.keys.live': 'PACKER_LIVE', }; diff --git a/src/server/prompts/continue-if-published-theme.js b/src/server/prompts/continue-if-published-theme.js index 689be7f..a0e68b8 100644 --- a/src/server/prompts/continue-if-published-theme.js +++ b/src/server/prompts/continue-if-published-theme.js @@ -17,10 +17,12 @@ const question = { * Prompt the user to confirm if they are about to deploy to the main theme * * @return Promise Reason for abort or empty resolve - * @param themeID + * @param {String} themeID + * @param {Boolean} allowLive [false] + * */ -module.exports = async function continueIfPublishedTheme(themeID) { - if (argv.skipPrompts) { +module.exports = async function continueIfPublishedTheme(themeID, allowLive = false) { + if (argv.skipPrompts || allowLive) { return question.default; } diff --git a/src/server/sync.js b/src/server/sync.js index b79af76..05855ac 100644 --- a/src/server/sync.js +++ b/src/server/sync.js @@ -11,6 +11,7 @@ const { getStoreValue, getThemeIdValue, getIgnoreFilesValue, + getAllowLiveValue, } = require('../env'); const PackerConfig = require('../config'); const config = new PackerConfig(require('../../packer.schema')); @@ -58,6 +59,7 @@ function _generateConfigFlags() { store: getStoreValue(), env: getEnvNameValue(), ignoredFiles: getIgnoreFilesValue().split(':'), + allowLive: getAllowLiveValue(), }; } @@ -83,6 +85,7 @@ async function deploy(cmd = '', files = [], replace = true) { await promiseThemekitDeploy(cmd, files, replace); } catch (error) { console.log(chalk.red(`- ${error}`)); + process.exit(1); } deploying = false;