This repository has been archived by the owner on May 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
246 lines (223 loc) · 5.59 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import Yeoman from 'yeoman-generator'
import cowsay from 'cowsay-browser'
import chalk from 'chalk'
import filesToAssert from './lib/filesToAssert'
import parrotSay from 'sync-parrot-api'
import filter from 'gulp-filter'
import prettify from 'gulp-jsbeautifier'
import updateNotifier from 'update-notifier'
const pkg = require('../../package.json')
class ShopifySkeleton extends Yeoman {
notify () {
updateNotifier({pkg}).notify()
}
vaderSays () {
const generalOverview = cowsay.say({
text: 'A few general purpose questions now...',
f: 'vader'
})
return this.log(chalk.red(generalOverview))
}
mustHavePrompts () {
return this.prompt([
{
type: 'input',
name: 'projectName',
message: 'Name of your Project?'
},
{
type: 'confirm',
name: 'npmInstall',
message: 'Want me to run npm install after we\'re done?',
default: false
}
])
.then(props => {
this.options.projectName = props.projectName
this.options.npmInstall = props.npmInstall
})
}
suchTalk () {
const dogeText = 'To set up a shop now you will need to have' + '\n' +
'private API credentials at hand see more here:' + '\n' +
'https://help.shopify.com/api/getting-started/api-credentials'
const muchWow = cowsay.think({
text: dogeText,
f: 'doge'
})
return this.options.noAnims
? this.log(chalk.magenta(muchWow))
: this.log(chalk.hex('#b69a4e')(muchWow))
}
setShopNowPrompt () {
return this.prompt([
{
type: 'confirm',
name: 'setShopNow',
message: 'Do you want to set up your shop credentials now?',
default: true
}
])
.then(props => {
this.options.setShopNow = props.setShopNow
})
}
shopifyConfigs () {
return this.options.setShopNow
? this.prompt([
{
type: 'input',
name: 'shopName',
message: 'Shop Name (Its the part that goes before the .myshopify.com bit on the admin)'
},
{
type: 'input',
name: 'shopKey',
message: 'API Key'
}, {
type: 'input',
name: 'shopPassword',
message: 'Password'
}, {
type: 'input',
name: 'shopSecret',
message: 'Shared Secret'
}, {
type: 'input',
name: 'shopThemeId',
message: 'Theme ID (Create a new theme click customize HTML/CSS and its after the themes/ part on the URL)'
}
])
.then(props => {
this.options.shopName = props.shopName
this.options.shopKey = props.shopKey
this.options.shopPassword = props.shopPassword
this.options.shopSecret = props.shopSecret
this.options.shopThemeId = props.shopThemeId
})
: false
}
copyShopifyCoreFiles () {
const {
projectName
} = this.options
const templates = {
author: 'Pixel2HTML',
projectName
}
return filesToAssert.shopifyCoreFiles.map(file => {
this.fs.copyTpl(
this.templatePath(`theme/${file}`),
this.destinationPath(`src/theme/${file}`),
templates
)
})
}
copyDotFiles () {
const {
projectName,
shopName,
shopKey,
shopPassword,
shopSecret,
shopThemeId,
setShopNow
} = this.options
const version = pkg.version
const templates = {
projectName,
shopName,
shopKey,
shopPassword,
shopSecret,
shopThemeId,
setShopNow,
version
}
return filesToAssert.dotfiles.map(file => {
this.fs.copyTpl(
this.templatePath(`base/${file}`),
this.destinationPath(`.${file}`),
templates
)
})
}
copyBaseFiles () {
const {
projectName,
shopName,
shopKey,
shopPassword,
shopSecret,
shopThemeId,
setShopNow
} = this.options
const version = pkg.version
const templates = {
projectName: projectName.split(' ').join('-'),
shopName,
shopKey,
shopPassword,
shopSecret,
shopThemeId,
setShopNow,
version
}
return filesToAssert.baseFiles.map(file => {
this.fs.copyTpl(
this.templatePath(`base/${file}`),
this.destinationPath(file),
templates
)
})
}
copyGulpFiles () {
return filesToAssert.gulpFiles.map(file => {
this.fs.copyTpl(
this.templatePath(`gulp/${file}`),
this.destinationPath(`gulp/${file}`),
{
author: 'Pixel2HTML'
}
)
})
}
copyStaticFiles () {
return filesToAssert.staticFiles.map(file => {
this.fs.copyTpl(
this.templatePath(file),
this.destinationPath(`src/${file}`),
{
author: 'Pixel2HTML'
}
)
})
}
install () {
this.options.npmInstall
? this.npmInstall()
: this.log('Skipping npm install')
}
eslintJs () {
this.log('Pretty JS and JSON 🙌')
const jsFilter = filter(['**/*.js', '**/*.json'], { restore: true })
this.registerTransformStream([
jsFilter,
prettify({
indent_size: 2
}),
jsFilter.restore
])
}
end () {
const message = this.options.setShopNow
? 'Thank you and Good Luck!'
: 'Remember to fill in the variables inside .env so gulp can run'
this.options.noAnims
? this.log(chalk.white((message)))
: this.log(parrotSay(message + ' 🦄'))
this.log('PS: use npm run code to start')
return this.log('Love, Pixel2HTML')
}
}
export default ShopifySkeleton