Skip to content

Commit

Permalink
fix(packer-config): env value live for allowing live theme deploy
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Hayes <eric@hayesmarketing.io>
  • Loading branch information
hayes0724 authored and Eric Hayes committed Dec 10, 2020
1 parent 34e030a commit 0fadb19
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 25 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
36 changes: 20 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -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': '',
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 9 additions & 3 deletions cli/commands/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hayes0724/shopify-packer",
"version": "1.3.0",
"version": "1.3.1",
"bin": {
"packer": "cli/index.js"
},
Expand Down
15 changes: 14 additions & 1 deletion src/env/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ 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 = [
config.get('env.keys.store'),
config.get('env.keys.password'),
config.get('env.keys.id'),
config.get('env.keys.ignore'),
config.get('env.keys.live'),
];

function assign(envName = undefined) {
Expand Down Expand Up @@ -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;
Expand All @@ -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(),
Expand Down Expand Up @@ -168,6 +179,8 @@ module.exports = {
clear,
getPackerEnv,
getEmptyPackerEnv,
getAllowLiveValue,
setAllowLiveValue,
getEnvNameValue,
getStoreValue,
getPasswordValue,
Expand Down
6 changes: 5 additions & 1 deletion src/env/packer-env.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
};
8 changes: 5 additions & 3 deletions src/server/prompts/continue-if-published-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions src/server/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
getStoreValue,
getThemeIdValue,
getIgnoreFilesValue,
getAllowLiveValue,
} = require('../env');
const PackerConfig = require('../config');
const config = new PackerConfig(require('../../packer.schema'));
Expand Down Expand Up @@ -58,6 +59,7 @@ function _generateConfigFlags() {
store: getStoreValue(),
env: getEnvNameValue(),
ignoredFiles: getIgnoreFilesValue().split(':'),
allowLive: getAllowLiveValue(),
};
}

Expand All @@ -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;
Expand Down

0 comments on commit 0fadb19

Please sign in to comment.