Skip to content

Commit e808d5c

Browse files
authored
Merge pull request #2 from sergejcodes/dev
Theme initialization
2 parents 041f51b + 705aab7 commit e808d5c

16 files changed

+948
-70
lines changed
File renamed without changes.

.config/reloadr/reloadr.client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const options = require('../reloadr.config.js')
1+
const options = require('./reloadr.config.js')
22

33
initReloadrClient = () => {
44
const socket = new WebSocket(`ws://localhost:${options.websocketPort}`)

.config/reloadr.config.js renamed to .config/reloadr/reloadr.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const package = require('../package.json')
1+
const package = require('../../package.json')
22

33
// load values from package.json
44
module.exports = {

.config/reloadr/reloadr.server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const http = require('http')
22
const WebSocket = require('ws')
33
const chalk = require('chalk')
4-
const options = require('../reloadr.config.js')
4+
const options = require('./reloadr.config.js')
55

66
/**
77
* custom console.log

.config/sample.shopify.config.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.
File renamed without changes.

.config/shopify/shopify.init.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
const path = require('path')
2+
const fs = require('fs-extra')
3+
const commandLineArgs = require('command-line-args')
4+
const yaml = require('yaml')
5+
const axios = require('axios')
6+
const chalk = require('chalk')
7+
const themeKit = require('@shopify/themekit')
8+
9+
/**
10+
* get command line arguments
11+
*/
12+
const optionDefinitions = [
13+
{ name: 'env', alias: 'e', type: String, defaultValue: 'dev' },
14+
{ name: 'password', alias: 'p', type: String },
15+
{ name: 'store', alias: 's', type: String },
16+
{ name: 'name', alias: 'n', type: String, defaultValue: 'Shopify Starterkit' }
17+
]
18+
19+
const options = commandLineArgs(optionDefinitions)
20+
21+
// check the provided options
22+
if (Object.keys(options).length < 4) {
23+
console.error(chalk.red('not enough arguments provided for initialization'))
24+
process.exit(1)
25+
}
26+
27+
if (!options.env.match(/^dev$|^live$|^staging$/)) {
28+
console.error(chalk.red('env should be \'dev\', \'live\' or \'staging\''))
29+
process.exit(1)
30+
}
31+
32+
/**
33+
* additional variables
34+
*/
35+
const configPath = path.resolve(__dirname, `./shopify.${options.env}.yml`)
36+
let themeId // assigned after remote initialization
37+
38+
/**
39+
* function initialises local config and remote shopify theme
40+
*/
41+
const initTheme = async () => {
42+
// initialize empty theme on shopify store
43+
try {
44+
const response = await axios.post(
45+
`https://${options.store}/admin/api/2020-07/themes.json`,
46+
{ theme: { name: options.name } },
47+
{ headers: { 'X-Shopify-Access-Token': options.password } }
48+
)
49+
50+
// assign theme id
51+
themeId = response.data.theme.id.toString()
52+
} catch (e) {
53+
console.error(chalk.red(e))
54+
process.exit(1)
55+
}
56+
57+
// create yaml config
58+
const yamlConfig = yaml.stringify({
59+
[options.env]: {
60+
password: options.password,
61+
theme_id: themeId,
62+
store: options.store,
63+
directory: 'shopify',
64+
ignores: [
65+
'.config/shopify/.shopifyignore'
66+
]
67+
}
68+
})
69+
70+
// write shopify config file
71+
try{
72+
await fs.outputFile(configPath, yamlConfig)
73+
} catch (e) {
74+
console.error(chalk.red(e))
75+
process.exit(1)
76+
}
77+
78+
// write settings_data.json to shopify/config
79+
try{
80+
const settingsData = {
81+
current: 'Default',
82+
presets: {
83+
Default: {}
84+
}
85+
}
86+
87+
await fs.outputFile(path.resolve(__dirname, '../../shopify/config/settings_data.json'), JSON.stringify(settingsData))
88+
} catch (e) {
89+
console.error(chalk.red(e))
90+
process.exit(1)
91+
}
92+
93+
// upload shopify theme to remote
94+
try{
95+
await themeKit.command('deploy', {
96+
config: configPath,
97+
env: options.env
98+
})
99+
} catch (e) {
100+
console.error(chalk.red(e))
101+
process.exit(1)
102+
}
103+
104+
console.log(chalk.green('initialized remote theme'))
105+
}
106+
107+
/**
108+
* inititalise theme
109+
*/
110+
initTheme()

.config/shopify/shopify.sample.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dev:
2+
password: [your-api-password]
3+
theme_id: "[your-theme-id]"
4+
store: [your-store].myshopify.com
5+
directory: shopify
6+
ignores:
7+
- .config/shopify/.shopifyignore

.config/webpack.common.js renamed to .config/webpack/webpack.common.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ const VueLoaderPlugin = require('vue-loader/lib/plugin')
55

66
module.exports = {
77
stats: 'minimal',
8-
entry: path.resolve(__dirname, '../src/main.js'),
8+
entry: path.resolve(__dirname, '../../src/main.js'),
99
output: {
10-
path: path.resolve(__dirname, '../shopify/assets/'),
10+
path: path.resolve(__dirname, '../../shopify/assets/'),
1111
filename: 'bundle.js'
1212
},
1313
resolve: {
1414
extensions: ['*', '.js', '.vue', '.json'],
1515
alias: {
1616
'vue$': 'vue/dist/vue.esm.js',
17-
'@': path.resolve(__dirname, '../src/')
17+
'@': path.resolve(__dirname, '../../src/')
1818
}
1919
},
2020
module: {

.config/webpack.dev.js renamed to .config/webpack/webpack.dev.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const common = require('./webpack.common.js')
55
module.exports = merge(common, {
66
mode: 'development',
77
entry: [
8-
path.resolve(__dirname, '../src/main.js'),
9-
path.resolve(__dirname, './reloadr/reloadr.client.js') // add reloadr to the bundle
8+
path.resolve(__dirname, '../../src/main.js'),
9+
path.resolve(__dirname, '../reloadr/reloadr.client.js') // add reloadr to the bundle
1010
],
1111
module: {
1212
rules: [
@@ -18,7 +18,7 @@ module.exports = merge(common, {
1818
{
1919
loader: 'eslint-loader',
2020
options: {
21-
configFile: path.resolve(__dirname, '.eslintrc.js')
21+
configFile: path.resolve(__dirname, '../.eslintrc.js')
2222
}
2323
}
2424
]
@@ -31,7 +31,7 @@ module.exports = merge(common, {
3131
{
3232
loader: 'postcss-loader',
3333
options: {
34-
postcssOptions: require('./postcss.config.js')
34+
postcssOptions: require(path.resolve(__dirname, '../postcss.config.js'))
3535
}
3636
},
3737
'sass-loader'

0 commit comments

Comments
 (0)