Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge wilr/master into zxventures/master #3

Open
wants to merge 18 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
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# grunt-shopify

> Grunt plug-in for publishing Shopify theme assets
> :warning: **Note that this was written prior to ThemeKit. Newer projects should use ThemeKit which is supported by Shopify https://github.com/Shopify/themekit**

[![dependencies](https://img.shields.io/david/wilr/grunt-shopify.svg?style=flat-square)](https://david-dm.org/wilr/grunt-shopify)
[![npm version](https://img.shields.io/npm/v/grunt-shopify.svg?style=flat-square)](https://npmjs.org/package/grunt-shopify)

**Grunt plug-in for publishing Shopify theme assets**

This plug-in handles publishing file changes, uploading new files and removing
deleted files from your local filesystem to a Shopify account in real time.
Expand Down Expand Up @@ -47,6 +52,8 @@ As mentioned, for secure environments use environment variables instead of hard
coding this information.

```js
const grunt = require('grunt');

grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-shopify');

Expand All @@ -66,6 +73,8 @@ Step 2. Add a section named `watch` to describe what files and directories you
want to sync to shopify.

```js
const grunt = require('grunt');

grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-shopify');

Expand All @@ -91,6 +100,8 @@ before being uploaded to the shopify store, use watch to have the coffee
tasks run on `.coffee` files and have shopify watch the resulting `.js` files.

```js
const grunt = require('grunt');

grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-shopify');

Expand Down Expand Up @@ -132,6 +143,14 @@ file, use the `--no-json` option:
grunt shopify:upload --no-json
```

### Downloading the latest

To download the latest files (in case of changes via the shopify editor) run

```shell
grunt shopify:download
```

### Options

#### api_key
Expand Down Expand Up @@ -176,6 +195,14 @@ Default value: `''`
If you've got your shopify files stored in a subdirectory locally (e.g in a
shop/ folder), base should the name of the folder with the trailing slash (i.e shop/).

#### upload_patterns

Type: `array`
Default value: `['assets/*.*','config/*.*','layout/*.*','locales/*.*','snippets/*.*','templates/*.*','templates/customers/*.*']`

Defines the [globbing patterns](http://gruntjs.com/api/grunt.file#globbing-patterns) to filter and select the files to
be uploaded.

#### disable_growl_notifications

Type: `Boolean`
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-shopify",
"description": "Grunt plug-in for publishing Shopify theme templates and assets.",
"version": "0.6.7",
"version": "1.0.2",
"homepage": "https://github.com/wilr/grunt-shopify",
"author": {
"name": "Will Rossiter",
Expand All @@ -26,9 +26,9 @@
"node": ">= 0.8.0"
},
"peerDependencies": {
"grunt-contrib-watch": ">=0.4.4",
"grunt": ">=0.4.0",
"growl": "~1.7"
"grunt-contrib-watch": ">=1.0.0",
"grunt": ">=1.0.0",
"growl": "~1.9.2"
},
"devDependancies": {
"grunt-contrib-jshint": "~0.1.1"
Expand All @@ -38,11 +38,11 @@
"shopify"
],
"dependencies": {
"async": "~0.2.9",
"isbinaryfile": "~2.0.0",
"shopify-api": "~0.2.2"
"async": "2.1.2",
"isbinaryfile": "3.0.1",
"shopify-api": "~0.2.3"
},
"devDependencies": {
"grunt-release": "~0.7.0"
"grunt-release": "~0.14.0"
}
}
55 changes: 34 additions & 21 deletions tasks/lib/shopify.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var path = require('path'),
module.exports = function(grunt) {
var shopify = {};
shopify._api = false;
shopify._uploadPatterns = false;
shopify._basePath = false;

/*
Expand Down Expand Up @@ -68,6 +69,35 @@ module.exports = function(grunt) {
return shopify._api;
};

/*
* Get the file patterns
*
* @return {array}
*/
shopify._getUploadPatterns = function() {
if (!shopify._uploadPatterns) {
var config = grunt.config('shopify');

var defaultConfig = [
'assets/*.*',
'config/*.*',
'layout/*.*',
'locales/*.*',
'sections/*.*',
'snippets/*.*',
'templates/*.*',
'templates/customers/*.*'
];

var options = ('upload_patterns' in config.options) ? config.options.upload_patterns : defaultConfig;

shopify._uploadPatterns = options;
}

return shopify._uploadPatterns;
}


/*
* Get the base path.
*
Expand Down Expand Up @@ -135,7 +165,7 @@ module.exports = function(grunt) {
shopify._isWhitelistedPath = function(filepath) {
filepath = shopify._makePathRelative(filepath);

return filepath.match(/^(assets|config|layout|snippets|templates|locales)\//i);
return filepath.match(/^(assets|config|layout|snippets|sections|templates|locales)\//i);
};

/*
Expand Down Expand Up @@ -293,7 +323,7 @@ module.exports = function(grunt) {
var api = shopify._getApi(),
themeId = shopify._getThemeId(),
key = shopify._makeAssetKey(filepath),
isBinary = isBinaryFile(filepath),
isBinary = isBinaryFile.sync(filepath),
props = {
asset: {
key: key
Expand Down Expand Up @@ -336,15 +366,7 @@ module.exports = function(grunt) {
var c = grunt.config('shopify');

var basePath = shopify._getBasePath();
var filepaths = grunt.file.expand({ cwd: basePath }, [
'assets/*.*',
'config/*.*',
'layout/*.*',
'locales/*.*',
'snippets/*.*',
'templates/*.*',
'templates/customers/*.*'
]);
var filepaths = grunt.file.expand({ cwd: basePath }, shopify._getUploadPatterns());

if (options.noJson) {
var index = filepaths.indexOf('config/settings_data.json');
Expand Down Expand Up @@ -509,16 +531,7 @@ module.exports = function(grunt) {
};
}

var filepaths = grunt.file.expand({cwd: basePath}, [
'assets/*.*',
'config/*.*',
'layout/*.*',
'locales/*.*',
'snippets/*.*',
'templates/*.*',
'templates/customers/*.*'
]);

var filepaths = grunt.file.expand({cwd: basePath}, shopify._getUploadPatterns());
var filesToUpdate = [];

for (var i = 0; i < filepaths.length; i++) {
Expand Down
3 changes: 2 additions & 1 deletion tasks/shopify.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ module.exports = function(grunt) {
var done = this.async();
var options = {
noJson: grunt.option('no-json')
}
};

if (p) {
shopify.upload(p, done);
} else {
Expand Down