Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 3fc59ce

Browse files
authored
Merge pull request #4 from uicrooks/dev
v0.5.0
2 parents 7352f42 + 3ba34f7 commit 3fc59ce

File tree

5 files changed

+36
-23
lines changed

5 files changed

+36
-23
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ $ npx themelab create <directory-name>
3838
$ npx themelab create <directory-name> --preset
3939
```
4040

41-
**Create a local development environment from a git repo:**
42-
```sh
43-
$ npx themelab create <directory-name> --repo https://github.com/user/repo
44-
```
45-
4641
**Initialize a remote Shopify theme and create a local config file:**
4742
> Run in the root directory of your Shopify Theme Lab project!
4843
```sh
@@ -55,6 +50,12 @@ $ npx themelab shopify:init --password [your-api-password] --store [your-store.m
5550
$ npx themelab shopify:init --password [your-api-password] --store [your-store.myshopify.com] --env [dev or live] --id [theme-id]
5651
```
5752

53+
**Create a local config file for a published/main theme:**
54+
> Run in the root directory of your Shopify Theme Lab project!
55+
```sh
56+
$ npx themelab shopify:init --password [your-api-password] --store [your-store.myshopify.com] --env [dev or live] --main
57+
```
58+
5859
**Display help:**
5960
```sh
6061
$ npx themelab --help

bin/themelab.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ program
2929
.description('initialize theme on remote Shopify store and a local config')
3030
.requiredOption('-p, --password <password>', 'Shopify plugin API password')
3131
.requiredOption('-s, --store <store>', '[your-store].myshopify.com')
32-
.option('-e, --env <env>', 'Environment [dev] or [live]', 'dev')
33-
.option('-n, --name <name>', 'Theme name', 'Shopify Theme Lab')
34-
.option('-i, --id <id>', 'If you provide a theme id, the command only creates a local config')
32+
.option('-e, --env <env>', 'environment [dev] or [live]', 'dev')
33+
.option('-n, --name <name>', 'theme name', 'Shopify Theme Lab')
34+
.option('-i, --id <id>', 'if you provide a theme id, the command only creates a local config')
35+
.option('-m, --main', 'create a local config for the currently published theme')
3536
.action((options, cmd) => {
3637
require('../lib/shopify-init')(cmd)
3738
})

lib/shopify-init.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,28 @@ module.exports = async (cmd) => {
2626
* initialize local config and a remote Shopify theme
2727
*/
2828
const initTheme = async () => {
29-
// initialize empty theme on shopify store
3029
if (!options.id) {
3130
try {
32-
const response = await axios.post(
33-
`https://${options.store}/admin/api/2021-01/themes.json`,
34-
{ theme: { name: options.name } },
35-
{ headers: { 'X-Shopify-Access-Token': options.password } }
36-
)
31+
const api = `https://${options.store}/admin/api/2021-01/themes.json`
3732

38-
// assign theme id
39-
themeId = response.data.theme.id.toString()
33+
if (options.main) {
34+
// get all themes from the provided shopify store
35+
const response = await axios.get(
36+
api,
37+
{ headers: { 'X-Shopify-Access-Token': options.password } }
38+
)
39+
40+
themeId = response.data.themes.find(theme => theme.role === 'main').id.toString()
41+
} else {
42+
// initialize empty theme on shopify store
43+
const response = await axios.post(
44+
api,
45+
{ theme: { name: options.name } },
46+
{ headers: { 'X-Shopify-Access-Token': options.password } }
47+
)
48+
49+
themeId = response.data.theme.id.toString()
50+
}
4051
} catch (e) {
4152
console.error(chalk`{red Error: ${e}}`)
4253
process.exit()
@@ -64,7 +75,7 @@ module.exports = async (cmd) => {
6475
process.exit()
6576
}
6677

67-
if (!options.id) {
78+
if (!options.id && !options.main) {
6879
// write settings_data.json to shopify/config
6980
try {
7081
const settingsData = {

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "themelab",
33
"description": "Shopify Theme Lab CLI",
44
"author": "Sergej Samsonenko <contact@sergej.codes>",
5-
"version": "0.4.0",
5+
"version": "0.5.0",
66
"license": "MIT",
77
"keywords": [
88
"shopify",
@@ -27,7 +27,7 @@
2727
"@shopify/themekit": "^1.1.7",
2828
"axios": "^0.21.1",
2929
"chalk": "^4.1.0",
30-
"commander": "^7.0.0",
30+
"commander": "^7.1.0",
3131
"fs-extra": "^9.1.0",
3232
"git-clone": "^0.1.0",
3333
"inquirer": "^7.3.3",

0 commit comments

Comments
 (0)