@syncify/cli 0.1.0-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,125 @@
1
+ import { Bundle } from '.';
2
+ import { File } from './file';
3
+ import { Config, Transforms } from '../config';
4
+ import { WebSocketServer } from 'ws';
5
+ import { Merge } from 'type-fest';
6
+
7
+ /* -------------------------------------------- */
8
+ /* PLUGIN SCOPE */
9
+ /* -------------------------------------------- */
10
+
11
+ export type PluginScope = Merge<Bundle, {
12
+ log: {
13
+ info: (...message: string[]) => void;
14
+ warn: (...message: string[]) => void;
15
+ error: (...message: string[]) => void;
16
+ }
17
+ }>
18
+
19
+ /* -------------------------------------------- */
20
+ /* PLUGIN HOOKS */
21
+ /* -------------------------------------------- */
22
+
23
+ export interface PluginHooks {
24
+ /**
25
+ * The plugin name
26
+ */
27
+ name: Lowercase<string>;
28
+ /**
29
+ * Optionally infer the required transformer
30
+ */
31
+ transforms?: Array<keyof Transforms>
32
+ /**
33
+ * Executes at runtime in the final cycle
34
+ * and before modes are invoked (like _watch_).
35
+ */
36
+ onInit?: (this: PluginScope, config: Config) => void;
37
+ /**
38
+ * Executes before a transform begins when running
39
+ * _build_ mode. The function only fires in build mode.
40
+ */
41
+ onBuild?: (this: PluginScope, file: File) => void;
42
+ /**
43
+ * Executes before the chokidar watch process
44
+ * has began. Allows you add additional files
45
+ * to be watched and monitored for changes.
46
+ */
47
+ onWatch?:(this: PluginScope, wss: WebSocketServer) => void | string[];
48
+ /**
49
+ * Executes before transform begins and after file
50
+ * context has been created.
51
+ *
52
+ * **NOTE**
53
+ *
54
+ * _File context might augment during transform._
55
+ */
56
+ onChange?: (this: PluginScope, file: File) => void;
57
+ /**
58
+ * Executes before hooks and after transform.
59
+ * File content can be transformed and request
60
+ * can be re-routed.
61
+ */
62
+ onTransform?:(this: PluginScope, file: File) => void | {
63
+ /**
64
+ * Change the Shopify output key
65
+ */
66
+ key?: Pick<File, 'key'>;
67
+ /**
68
+ * Sourcemap (optional)
69
+ */
70
+ map?: Buffer | object | string;
71
+ /**
72
+ * Return the file content.
73
+ */
74
+ value: Buffer;
75
+ };
76
+ /**
77
+ * Executes on a HOT reload and before
78
+ * the theme preview is updated. You can augment
79
+ * the dom before reload.
80
+ */
81
+ onReload?: (dom: Document) => void | Document
82
+
83
+ }
84
+
85
+ /* -------------------------------------------- */
86
+ /* BUNDLE REFERENCE */
87
+ /* -------------------------------------------- */
88
+
89
+ export interface Plugins {
90
+ /**
91
+ * Plugins executing onBuild
92
+ */
93
+ onBuild: [
94
+ pluginName: string,
95
+ pluginHook: PluginHooks['onBuild']
96
+ ][]
97
+ /**
98
+ * Plugins executing onWatch
99
+ */
100
+ onWatch: [
101
+ pluginName: string,
102
+ pluginHook: PluginHooks['onWatch']
103
+ ][]
104
+ /**
105
+ * Plugins executing onChange
106
+ */
107
+ onChange: [
108
+ pluginName: string,
109
+ pluginHook: PluginHooks['onChange']
110
+ ][]
111
+ /**
112
+ * Plugins executing onTransform
113
+ */
114
+ onTransform: [
115
+ pluginName: string,
116
+ pluginHook: PluginHooks['onTransform']
117
+ ][]
118
+ /**
119
+ * Plugins executing onReload
120
+ */
121
+ onReload: [
122
+ pluginName: string,
123
+ pluginHook: PluginHooks['onReload']
124
+ ][]
125
+ }
package/types/cli.d.ts ADDED
@@ -0,0 +1,523 @@
1
+ /* -------------------------------------------- */
2
+ /* LOGGER */
3
+ /* -------------------------------------------- */
4
+
5
+ import { LiteralUnion } from 'type-fest';
6
+
7
+ export type Group = LiteralUnion<
8
+ | 'Syncify'
9
+ | 'Asset'
10
+ | 'Spawn'
11
+ | 'SVG'
12
+ | 'Snippet'
13
+ | 'Layout'
14
+ | 'Section'
15
+ | 'Page'
16
+ | 'Locale'
17
+ | 'Config'
18
+ | 'Template'
19
+ | 'Metafield'
20
+ , string
21
+ >
22
+
23
+ /* -------------------------------------------- */
24
+ /* CLI OPTIONS */
25
+ /* -------------------------------------------- */
26
+
27
+ export interface Commands {
28
+ /**
29
+ * First command is a store or comma separated list of stores. When
30
+ * a comma list is supplied it is converted to an array. You can use
31
+ * use the store target name as a --flag to cherry pick specific themes
32
+ * from that store.
33
+ *
34
+ * ---
35
+ *
36
+ * Example:
37
+ *
38
+ * ```bash
39
+ * $ syncify store-name
40
+ * $ syncify store1,store2,store3
41
+ * ```
42
+ */
43
+ _?: string[];
44
+ /**
45
+ * Whether or not syncify was called via the cli
46
+ *
47
+ * @default true
48
+ */
49
+ cli?: boolean;
50
+ /**
51
+ * The current working directory, this a reference to `process.cwd()`
52
+ */
53
+ cwd?: string;
54
+ /**
55
+ * The `package.json` url path, this is written post-command parse
56
+ */
57
+ pkg?: string;
58
+ /**
59
+ * The post-parse temp storage reference to stores
60
+ */
61
+ store?: string | string[];
62
+ /**
63
+ * An optional config path to the `syncify.config.js` file.
64
+ *
65
+ * ---
66
+ *
67
+ * Example:
68
+ *
69
+ * ```bash
70
+ * $ syncify store_1 -c path/to/file
71
+ * $ syncify store_1 --config path/to/file
72
+ * $ syncify store_1 --config=path/to/file
73
+ * ```
74
+ */
75
+ config?: string;
76
+ /**
77
+ * Run in production mode
78
+ *
79
+ * ---
80
+ *
81
+ * Example:
82
+ *
83
+ * ```bash
84
+ * $ syncify --prod
85
+ * $ syncify --production
86
+ * ```
87
+ */
88
+ prod?: boolean;
89
+ /**
90
+ * Run in development mode (default build mode) and can be omitted
91
+ *
92
+ * ---
93
+ *
94
+ * Example:
95
+ *
96
+ * ```bash
97
+ * $ syncify
98
+ * $ syncify --dev
99
+ * $ syncify --development
100
+ * ```
101
+ */
102
+ dev?: boolean;
103
+ /**
104
+ * Run minification on resources. This acts similar to `--prod`
105
+ * but allows for invocation in an isolated manner.
106
+ *
107
+ * ---
108
+ *
109
+ * Example:
110
+ *
111
+ * ```bash
112
+ * $ syncify --minify
113
+ * ```
114
+ */
115
+ minify?: boolean
116
+ /**
117
+ * Show the command prompt interactive shell
118
+ *
119
+ * ---
120
+ *
121
+ * Example:
122
+ *
123
+ * ```bash
124
+ * $ syncify --prompt
125
+ * ```
126
+ */
127
+ prompt?: boolean;
128
+ /**
129
+ * Run in watch mode (chokidar). This requires a store target be passed.
130
+ *
131
+ * ---
132
+ *
133
+ * Example:
134
+ *
135
+ * ```bash
136
+ * $ syncify store_1 -w
137
+ * $ syncify store_1 --watch
138
+ * ```
139
+ */
140
+ watch?: boolean;
141
+ /**
142
+ * Run in build mode, this is default trigger when no arguments provided.
143
+ * It can optionally be triggered along other flags like `-u` (`--upload`).
144
+ *
145
+ * ---
146
+ *
147
+ * Example:
148
+ *
149
+ * ```bash
150
+ * $ syncify
151
+ * $ syncify -b
152
+ * $ syncify store_1 --clean --build --theme=prod_theme -u
153
+ *
154
+ * # Short version for brevity
155
+ * $ syncify store_1 -t prod_theme -u -b --clean
156
+ * ```
157
+ */
158
+ build?: boolean;
159
+ /**
160
+ * Run in upload mode, this will trigger a full theme upload. Requires a store
161
+ * target and theme target (theme target is optional but recommended).
162
+ *
163
+ * ---
164
+ *
165
+ * Example:
166
+ *
167
+ * ```bash
168
+ * $ syncify store_1 -t dev_theme -u
169
+ * $ syncify store_1 -t dev_theme --upload
170
+ * ```
171
+ */
172
+ upload?: boolean;
173
+ /**
174
+ * Exports the theme and generates a `.zip` compressed directory.
175
+ *
176
+ * ---
177
+ *
178
+ * Example:
179
+ *
180
+ * ```bash
181
+ * $ syncify --export
182
+ * ```
183
+ */
184
+ export?: boolean;
185
+ /**
186
+ * Download a theme from a store. Will be place in `import` driectory. Requires a store
187
+ * target and theme target to be passed.
188
+ *
189
+ * ---
190
+ *
191
+ * Example:
192
+ *
193
+ * ```bash
194
+ * $ syncify store_1 -t dev_theme -d
195
+ * $ syncify store_1 -t dev_theme --download
196
+ * ```
197
+ */
198
+ download?: boolean;
199
+ /**
200
+ * Triggers the metafields resource, presents the interactive shell with list of
201
+ * options to choose from. Requires a store target to be passed.
202
+ *
203
+ * ---
204
+ *
205
+ * Example:
206
+ *
207
+ * ```bash
208
+ * $ syncify store_1 -m
209
+ * $ syncify store_1 --metafields
210
+ * ```
211
+ */
212
+ metafields?: boolean;
213
+ /**
214
+ * Triggers the pages resource, presents the interactive shell with list of
215
+ * options to choose from. Requires a store target to be passed.
216
+ *
217
+ * ---
218
+ *
219
+ * Example:
220
+ *
221
+ * ```bash
222
+ * $ syncify store_1 -p
223
+ * $ syncify store_1 --pages
224
+ * ```
225
+ */
226
+ pages?: boolean;
227
+ /**
228
+ * Triggers the redirects resource, presents the interactive shell with list of
229
+ * options to choose from. Requires a store target to be passed.
230
+ *
231
+ * ---
232
+ *
233
+ * Example:
234
+ *
235
+ * ```bash
236
+ * $ syncify store_1 -r
237
+ * $ syncify store_1 --redirects
238
+ * ```
239
+ */
240
+ redirects?: boolean;
241
+ /**
242
+ * Pull data reference from a store target resource. Queries the store API. Used to
243
+ * populate local setup with remote data like `metafields` and `pages`
244
+ *
245
+ * ---
246
+ *
247
+ * Example:
248
+ *
249
+ * ```bash
250
+ * $ syncify store_1 -m --pull
251
+ * $ syncify store_1 -p --pull
252
+ * ```
253
+ */
254
+ pull?: boolean;
255
+ /**
256
+ * Pushes a resource from local to remote shop. This is different from `-u` or `--upload`
257
+ * flags as it can be used to push targets assets, files or resources and can be used
258
+ * together with the `-f` filter flag.
259
+ *
260
+ * ---
261
+ *
262
+ * Example:
263
+ *
264
+ * ```bash
265
+ * $ syncify store_1 -t dev_theme -f assets/file --push
266
+ * $ syncify store_1 -f metafields/namespace/*.json --push
267
+ * ```
268
+ */
269
+ push?: boolean;
270
+ /**
271
+ * Generator flag for automatically applying JSON schema specifications
272
+ * for VS Code users.
273
+ *
274
+ * ---
275
+ *
276
+ * Example:
277
+ *
278
+ * ```bash
279
+ * $ syncify --vsc
280
+ * ```
281
+ */
282
+ vsc?: boolean;
283
+ /**
284
+ * Filter targeting of resources, assets or files. This can be used together
285
+ * with several different flags, like `-u`, `-d` and even `-b`. Filters a
286
+ * glob pattern or specific file.
287
+ *
288
+ * ---
289
+ *
290
+ * Example:
291
+ *
292
+ * ```bash
293
+ * # Uploads only .css assets
294
+ * $ syncify store_1 -t dev_theme -f assets/*.css --push
295
+ *
296
+ * # Builds locales in production mode
297
+ * $ syncify -f locales/*.json --prod
298
+ *
299
+ * # Uploads specific page
300
+ * $ syncify store_1 -u -f pages/shipping-info.md --prod --push
301
+ * ```
302
+ */
303
+ filter?: string;
304
+ /**
305
+ * Triggers a clean of the output directory. When provided, this will be
306
+ * executed at the initial run (or before any else). Use together with
307
+ * production builds.
308
+ *
309
+ * ---
310
+ *
311
+ * Example:
312
+ *
313
+ * ```bash
314
+ * $ syncify --clean --prod
315
+ * $ syncify -b --clean --prod # Using with build
316
+ * ```
317
+ */
318
+ clean?: boolean;
319
+ /**
320
+ * Show command-line help information. Also prints a disclaimer informing
321
+ * users that Centra is a better e-commerce platform than Shopify for shits
322
+ * and giggles (it actually is though).
323
+ *
324
+ * ---
325
+ *
326
+ * Example:
327
+ *
328
+ * ```bash
329
+ * $ syncify -h
330
+ * $ syncify --help
331
+ * ```
332
+ */
333
+ help?: boolean;
334
+ /**
335
+ * Hides logs from being printed (shows errors though)
336
+ *
337
+ * ---
338
+ *
339
+ * Example:
340
+ *
341
+ * ```bash
342
+ * $ syncify --silent
343
+ * ```
344
+ */
345
+ silent?: boolean;
346
+ /**
347
+ * Initializes hot-reloading in watch mode. Can only be used when
348
+ * targeting a single store and theme.
349
+ *
350
+ * ---
351
+ *
352
+ * Example:
353
+ *
354
+ * ```bash
355
+ * $ syncify store_1 -w -h
356
+ * $ syncify store_1 -w --hot
357
+ * $ syncify store_1 --watch -h
358
+ * $ syncify store_1 --watch --hot
359
+ * ```
360
+ */
361
+ hot?: boolean;
362
+ /**
363
+ * Pulls in a Syncify theme strap environment.
364
+ *
365
+ * ---
366
+ *
367
+ * Example:
368
+ *
369
+ * ```bash
370
+ * $ syncify --strap dusk
371
+ * $ syncify --strap silk
372
+ * ```
373
+ */
374
+ strap?: string;
375
+ /**
376
+ * Deletes a resource, file or asset from the remote store. Requires a store
377
+ * target be passed and if need be a theme target too. Does not delete local
378
+ * copies, do that manually for now.
379
+ *
380
+ * ---
381
+ *
382
+ * Example:
383
+ *
384
+ * ```bash
385
+ * $ syncify -del assets/image-name.jpg
386
+ * ```
387
+ */
388
+ del?: string;
389
+ /**
390
+ * Trigger a spawn, isolating it so it will run as if it were a node script.
391
+ *
392
+ * ---
393
+ *
394
+ * Example:
395
+ *
396
+ * ```bash
397
+ * $ syncify -s spawn-name
398
+ * $ syncify -s spawn-name,some-other-spawn
399
+ *
400
+ * # OR
401
+
402
+ * $ syncify --spawn spawn-name
403
+ * $ syncify --spawn spawn-name,some-other-spawn
404
+ * ```
405
+ */
406
+ spawn?: string;
407
+ /**
408
+ * Themes within stores to target. This argument requires a store target/s
409
+ * be passed and accept a comma separated list of target names as per the users
410
+ * Syncify configuration. Users can pass wildcard `--flags` to reference different
411
+ * stores when multiple store target are passed.
412
+ *
413
+ * ---
414
+ *
415
+ * Example:
416
+ *
417
+ * ```bash
418
+ * $ syncify store_1 -t theme_1
419
+ * $ syncify store_1,store_2 --store_1 dev,prod --store_2 foo_theme
420
+ * $ syncify store_1 --theme=dev,prod,test
421
+ * ```
422
+ */
423
+ theme?: string[];
424
+ /**
425
+ * An optional input base directory path. This will overwrite and configuration predefined
426
+ * in settings.
427
+ *
428
+ * ---
429
+ *
430
+ * Example:
431
+ *
432
+ * ```bash
433
+ * $ syncify --clean -b -i some/directory
434
+ * ```
435
+ */
436
+ input?: string;
437
+ /**
438
+ * An optional output path. This will overwrite the configuration predefined
439
+ * in settings.
440
+ *
441
+ * ---
442
+ *
443
+ * Example:
444
+ *
445
+ * ```bash
446
+ * $ syncify --clean -b -o some/directory
447
+ * ```
448
+ */
449
+ output?: string;
450
+ /**
451
+ * Version control. The bump flag accepts 3 different arguments.
452
+ * Passing `--bump major` bumps main version, eg: `1.0.0` > `2.0,0`
453
+ * Passing `--bump minor` bumps minor version, eg: `1.0.0` > `1.1.0`
454
+ * Passing `--bump patch` bumps patch version, eg: `1.0.0` > `1.0.1`
455
+ *
456
+ * ---
457
+ *
458
+ * Example:
459
+ *
460
+ * ```bash
461
+ * $ syncify --bump major
462
+ * $ syncify --bump minor
463
+ * $ syncify --bump patch
464
+ * ```
465
+ */
466
+ bump?: string;
467
+ /**
468
+ * Runs the script transform only
469
+ * ---
470
+ *
471
+ * Example:
472
+ *
473
+ * ```bash
474
+ * $ syncify --script # executes build
475
+ * $ syncify -w --script # executes in watch mode
476
+ * $ syncify --script --prod # executes build with minify
477
+ * $ syncify --script --minify # executes build with minify
478
+ * ```
479
+ */
480
+ script?: boolean;
481
+ /**
482
+ * Runs the style transform only
483
+ * ---
484
+ *
485
+ * Example:
486
+ *
487
+ * ```bash
488
+ * $ syncify --style # executes build
489
+ * $ syncify -w --style # executes in watch mode
490
+ * $ syncify --style --prod # executes build with minify
491
+ * $ syncify --style --minify # executes build with minify
492
+ * ```
493
+ */
494
+ style?: boolean;
495
+ /**
496
+ * Runs the svg transform only
497
+ * ---
498
+ *
499
+ * Example:
500
+ *
501
+ * ```bash
502
+ * $ syncify --svg # executes build
503
+ * $ syncify -w --svg # executes in watch mode
504
+ * $ syncify --svg --prod # executes build with minify
505
+ * $ syncify --svg --minify # executes build with minify
506
+ * ```
507
+ */
508
+ svg?: boolean;
509
+ /**
510
+ * Runs the image transform only
511
+ * ---
512
+ *
513
+ * Example:
514
+ *
515
+ * ```bash
516
+ * $ syncify --image # executes build
517
+ * $ syncify -w --image # executes in watch mode
518
+ * $ syncify --image --prod # executes build with minify
519
+ * $ syncify --image --minify # executes build with minify
520
+ * ```
521
+ */
522
+ image?: boolean;
523
+ }