@springmicro/cli 0.2.0-alpha.3 → 0.2.1

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.
package/README.md CHANGED
@@ -12,6 +12,11 @@ Command line utilities for SpringMicroHost.
12
12
  * [Commands](#commands)
13
13
  * [Development](#development)
14
14
  <!-- tocstop -->
15
+ * [@springmicro/cli](#springmicrocli)
16
+ * [Usage](#usage)
17
+ * [Commands](#commands)
18
+ * [Development](#development)
19
+ <!-- tocstop -->
15
20
 
16
21
  - [@springmicro/cli](#springmicrocli)
17
22
  - [Usage](#usage)
@@ -26,13 +31,25 @@ $ npm install -g @springmicro/cli
26
31
  $ springmicro COMMAND
27
32
  running command...
28
33
  $ springmicro (--version)
29
- @springmicro/cli/0.2.0-alpha.3 win32-x64 node-v20.15.0
34
+ @springmicro/cli/0.2.1 win32-x64 node-v20.15.0
30
35
  $ springmicro --help [COMMAND]
31
36
  USAGE
32
37
  $ springmicro COMMAND
33
38
  ...
34
39
  ```
35
40
  <!-- usagestop -->
41
+ ```sh-session
42
+ $ npm install -g @springmicro/cli
43
+ $ springmicro COMMAND
44
+ running command...
45
+ $ springmicro (--version)
46
+ @springmicro/cli/0.2.0-alpha.3 win32-x64 node-v20.15.0
47
+ $ springmicro --help [COMMAND]
48
+ USAGE
49
+ $ springmicro COMMAND
50
+ ...
51
+ ```
52
+ <!-- usagestop -->
36
53
 
37
54
  ```sh-session
38
55
  $ npm install -g @springmicro/cli
@@ -52,6 +69,7 @@ USAGE
52
69
 
53
70
  <!-- commands -->
54
71
  * [`springmicro add auth`](#springmicro-add-auth)
72
+ * [`springmicro add form`](#springmicro-add-form)
55
73
  * [`springmicro help [COMMAND]`](#springmicro-help-command)
56
74
  * [`springmicro init PROJECTTYPE`](#springmicro-init-projecttype)
57
75
  * [`springmicro init astro`](#springmicro-init-astro)
@@ -81,7 +99,27 @@ EXAMPLES
81
99
  $ springmicro add auth
82
100
  ```
83
101
 
84
- _See code: [src/commands/add/auth.ts](https://github.com/SpringMicro1/springmicrohost-js/blob/v0.2.0-alpha.3/src/commands/add/auth.ts)_
102
+ _See code: [src/commands/add/auth.ts](https://github.com/SpringMicro1/springmicrohost-js/blob/v0.2.1/src/commands/add/auth.ts)_
103
+
104
+ ## `springmicro add form`
105
+
106
+ add a form to your project
107
+
108
+ ```
109
+ USAGE
110
+ $ springmicro add form [-t <value>]
111
+
112
+ FLAGS
113
+ -t, --template=<value> form template (contact|quote)
114
+
115
+ DESCRIPTION
116
+ add a form to your project
117
+
118
+ EXAMPLES
119
+ $ springmicro add form
120
+ ```
121
+
122
+ _See code: [src/commands/add/form.ts](https://github.com/SpringMicro1/springmicrohost-js/blob/v0.2.1/src/commands/add/form.ts)_
85
123
 
86
124
  ## `springmicro help [COMMAND]`
87
125
 
@@ -101,7 +139,7 @@ DESCRIPTION
101
139
  Display help for springmicro.
102
140
  ```
103
141
 
104
- _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.5/src/commands/help.ts)_
142
+ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.7/src/commands/help.ts)_
105
143
 
106
144
  ## `springmicro init PROJECTTYPE`
107
145
 
@@ -124,7 +162,7 @@ EXAMPLES
124
162
  $ springmicro init astro -n example
125
163
  ```
126
164
 
127
- _See code: [src/commands/init/index.ts](https://github.com/SpringMicro1/springmicrohost-js/blob/v0.2.0-alpha.3/src/commands/init/index.ts)_
165
+ _See code: [src/commands/init/index.ts](https://github.com/SpringMicro1/springmicrohost-js/blob/v0.2.1/src/commands/init/index.ts)_
128
166
 
129
167
  ## `springmicro init astro`
130
168
 
@@ -144,7 +182,7 @@ EXAMPLES
144
182
  $ springmicro init astro -n <project-name>
145
183
  ```
146
184
 
147
- _See code: [src/commands/init/astro.ts](https://github.com/SpringMicro1/springmicrohost-js/blob/v0.2.0-alpha.3/src/commands/init/astro.ts)_
185
+ _See code: [src/commands/init/astro.ts](https://github.com/SpringMicro1/springmicrohost-js/blob/v0.2.1/src/commands/init/astro.ts)_
148
186
 
149
187
  ## `springmicro plugins`
150
188
 
@@ -167,7 +205,7 @@ EXAMPLES
167
205
  $ springmicro plugins
168
206
  ```
169
207
 
170
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.4/src/commands/plugins/index.ts)_
208
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.9/src/commands/plugins/index.ts)_
171
209
 
172
210
  ## `springmicro plugins add PLUGIN`
173
211
 
@@ -241,7 +279,7 @@ EXAMPLES
241
279
  $ springmicro plugins inspect myplugin
242
280
  ```
243
281
 
244
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.4/src/commands/plugins/inspect.ts)_
282
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.9/src/commands/plugins/inspect.ts)_
245
283
 
246
284
  ## `springmicro plugins install PLUGIN`
247
285
 
@@ -290,7 +328,7 @@ EXAMPLES
290
328
  $ springmicro plugins install someuser/someplugin
291
329
  ```
292
330
 
293
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.4/src/commands/plugins/install.ts)_
331
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.9/src/commands/plugins/install.ts)_
294
332
 
295
333
  ## `springmicro plugins link PATH`
296
334
 
@@ -320,7 +358,7 @@ EXAMPLES
320
358
  $ springmicro plugins link myplugin
321
359
  ```
322
360
 
323
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.4/src/commands/plugins/link.ts)_
361
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.9/src/commands/plugins/link.ts)_
324
362
 
325
363
  ## `springmicro plugins remove [PLUGIN]`
326
364
 
@@ -361,7 +399,7 @@ FLAGS
361
399
  --reinstall Reinstall all plugins after uninstalling.
362
400
  ```
363
401
 
364
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.4/src/commands/plugins/reset.ts)_
402
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.9/src/commands/plugins/reset.ts)_
365
403
 
366
404
  ## `springmicro plugins uninstall [PLUGIN]`
367
405
 
@@ -389,7 +427,7 @@ EXAMPLES
389
427
  $ springmicro plugins uninstall myplugin
390
428
  ```
391
429
 
392
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.4/src/commands/plugins/uninstall.ts)_
430
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.9/src/commands/plugins/uninstall.ts)_
393
431
 
394
432
  ## `springmicro plugins unlink [PLUGIN]`
395
433
 
@@ -433,7 +471,391 @@ DESCRIPTION
433
471
  Update installed plugins.
434
472
  ```
435
473
 
436
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.4/src/commands/plugins/update.ts)_
474
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.9/src/commands/plugins/update.ts)_
475
+ <!-- commandsstop -->
476
+ * [`springmicro add auth`](#springmicro-add-auth)
477
+ * [`springmicro help [COMMAND]`](#springmicro-help-command)
478
+ * [`springmicro init PROJECTTYPE`](#springmicro-init-projecttype)
479
+ * [`springmicro init astro`](#springmicro-init-astro)
480
+ * [`springmicro plugins`](#springmicro-plugins)
481
+ * [`springmicro plugins add PLUGIN`](#springmicro-plugins-add-plugin)
482
+ * [`springmicro plugins:inspect PLUGIN...`](#springmicro-pluginsinspect-plugin)
483
+ * [`springmicro plugins install PLUGIN`](#springmicro-plugins-install-plugin)
484
+ * [`springmicro plugins link PATH`](#springmicro-plugins-link-path)
485
+ * [`springmicro plugins remove [PLUGIN]`](#springmicro-plugins-remove-plugin)
486
+ * [`springmicro plugins reset`](#springmicro-plugins-reset)
487
+ * [`springmicro plugins uninstall [PLUGIN]`](#springmicro-plugins-uninstall-plugin)
488
+ * [`springmicro plugins unlink [PLUGIN]`](#springmicro-plugins-unlink-plugin)
489
+ * [`springmicro plugins update`](#springmicro-plugins-update)
490
+
491
+ ## `springmicro add auth`
492
+
493
+ describe the command here
494
+
495
+ ```
496
+ USAGE
497
+ $ springmicro add auth
498
+
499
+ DESCRIPTION
500
+ describe the command here
501
+
502
+ EXAMPLES
503
+ $ springmicro add auth
504
+ ```
505
+
506
+ _See code: [src/commands/add/auth.ts](https://github.com/SpringMicro1/springmicrohost-js/blob/v0.2.0-alpha.3/src/commands/add/auth.ts)_
507
+
508
+ ## `springmicro help [COMMAND]`
509
+
510
+ Display help for springmicro.
511
+
512
+ ```
513
+ USAGE
514
+ $ springmicro help [COMMAND...] [-n]
515
+
516
+ ARGUMENTS
517
+ COMMAND... Command to show help for.
518
+
519
+ FLAGS
520
+ -n, --nested-commands Include all nested commands in the output.
521
+
522
+ DESCRIPTION
523
+ Display help for springmicro.
524
+ ```
525
+
526
+ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.5/src/commands/help.ts)_
527
+
528
+ ## `springmicro init PROJECTTYPE`
529
+
530
+ Initialize a JavaScript framework project according to SpringMicroHost's specifications.
531
+
532
+ ```
533
+ USAGE
534
+ $ springmicro init PROJECTTYPE -n <value>
535
+
536
+ ARGUMENTS
537
+ PROJECTTYPE Project type (astro)
538
+
539
+ FLAGS
540
+ -n, --name=<value> (required) Project name
541
+
542
+ DESCRIPTION
543
+ Initialize a JavaScript framework project according to SpringMicroHost's specifications.
544
+
545
+ EXAMPLES
546
+ $ springmicro init astro -n example
547
+ ```
548
+
549
+ _See code: [src/commands/init/index.ts](https://github.com/SpringMicro1/springmicrohost-js/blob/v0.2.0-alpha.3/src/commands/init/index.ts)_
550
+
551
+ ## `springmicro init astro`
552
+
553
+ Initialize a Astro project according to SpringMicroHost's specifications.
554
+
555
+ ```
556
+ USAGE
557
+ $ springmicro init astro -n <value>
558
+
559
+ FLAGS
560
+ -n, --name=<value> (required) Project name
561
+
562
+ DESCRIPTION
563
+ Initialize a Astro project according to SpringMicroHost's specifications.
564
+
565
+ EXAMPLES
566
+ $ springmicro init astro -n <project-name>
567
+ ```
568
+
569
+ _See code: [src/commands/init/astro.ts](https://github.com/SpringMicro1/springmicrohost-js/blob/v0.2.0-alpha.3/src/commands/init/astro.ts)_
570
+
571
+ ## `springmicro plugins`
572
+
573
+ List installed plugins.
574
+
575
+ ```
576
+ USAGE
577
+ $ springmicro plugins [--json] [--core]
578
+
579
+ FLAGS
580
+ --core Show core plugins.
581
+
582
+ GLOBAL FLAGS
583
+ --json Format output as json.
584
+
585
+ DESCRIPTION
586
+ List installed plugins.
587
+
588
+ EXAMPLES
589
+ $ springmicro plugins
590
+ ```
591
+
592
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.4/src/commands/plugins/index.ts)_
593
+
594
+ ## `springmicro plugins add PLUGIN`
595
+
596
+ Installs a plugin into springmicro.
597
+
598
+ ```
599
+ USAGE
600
+ $ springmicro plugins add PLUGIN... [--json] [-f] [-h] [-s | -v]
601
+
602
+ ARGUMENTS
603
+ PLUGIN... Plugin to install.
604
+
605
+ FLAGS
606
+ -f, --force Force npm to fetch remote resources even if a local copy exists on disk.
607
+ -h, --help Show CLI help.
608
+ -s, --silent Silences npm output.
609
+ -v, --verbose Show verbose npm output.
610
+
611
+ GLOBAL FLAGS
612
+ --json Format output as json.
613
+
614
+ DESCRIPTION
615
+ Installs a plugin into springmicro.
616
+
617
+ Uses npm to install plugins.
618
+
619
+ Installation of a user-installed plugin will override a core plugin.
620
+
621
+ Use the SPRINGMICRO_NPM_LOG_LEVEL environment variable to set the npm loglevel.
622
+ Use the SPRINGMICRO_NPM_REGISTRY environment variable to set the npm registry.
623
+
624
+ ALIASES
625
+ $ springmicro plugins add
626
+
627
+ EXAMPLES
628
+ Install a plugin from npm registry.
629
+
630
+ $ springmicro plugins add myplugin
631
+
632
+ Install a plugin from a github url.
633
+
634
+ $ springmicro plugins add https://github.com/someuser/someplugin
635
+
636
+ Install a plugin from a github slug.
637
+
638
+ $ springmicro plugins add someuser/someplugin
639
+ ```
640
+
641
+ ## `springmicro plugins:inspect PLUGIN...`
642
+
643
+ Displays installation properties of a plugin.
644
+
645
+ ```
646
+ USAGE
647
+ $ springmicro plugins inspect PLUGIN...
648
+
649
+ ARGUMENTS
650
+ PLUGIN... [default: .] Plugin to inspect.
651
+
652
+ FLAGS
653
+ -h, --help Show CLI help.
654
+ -v, --verbose
655
+
656
+ GLOBAL FLAGS
657
+ --json Format output as json.
658
+
659
+ DESCRIPTION
660
+ Displays installation properties of a plugin.
661
+
662
+ EXAMPLES
663
+ $ springmicro plugins inspect myplugin
664
+ ```
665
+
666
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.4/src/commands/plugins/inspect.ts)_
667
+
668
+ ## `springmicro plugins install PLUGIN`
669
+
670
+ Installs a plugin into springmicro.
671
+
672
+ ```
673
+ USAGE
674
+ $ springmicro plugins install PLUGIN... [--json] [-f] [-h] [-s | -v]
675
+
676
+ ARGUMENTS
677
+ PLUGIN... Plugin to install.
678
+
679
+ FLAGS
680
+ -f, --force Force npm to fetch remote resources even if a local copy exists on disk.
681
+ -h, --help Show CLI help.
682
+ -s, --silent Silences npm output.
683
+ -v, --verbose Show verbose npm output.
684
+
685
+ GLOBAL FLAGS
686
+ --json Format output as json.
687
+
688
+ DESCRIPTION
689
+ Installs a plugin into springmicro.
690
+
691
+ Uses npm to install plugins.
692
+
693
+ Installation of a user-installed plugin will override a core plugin.
694
+
695
+ Use the SPRINGMICRO_NPM_LOG_LEVEL environment variable to set the npm loglevel.
696
+ Use the SPRINGMICRO_NPM_REGISTRY environment variable to set the npm registry.
697
+
698
+ ALIASES
699
+ $ springmicro plugins add
700
+
701
+ EXAMPLES
702
+ Install a plugin from npm registry.
703
+
704
+ $ springmicro plugins install myplugin
705
+
706
+ Install a plugin from a github url.
707
+
708
+ $ springmicro plugins install https://github.com/someuser/someplugin
709
+
710
+ Install a plugin from a github slug.
711
+
712
+ $ springmicro plugins install someuser/someplugin
713
+ ```
714
+
715
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.4/src/commands/plugins/install.ts)_
716
+
717
+ ## `springmicro plugins link PATH`
718
+
719
+ Links a plugin into the CLI for development.
720
+
721
+ ```
722
+ USAGE
723
+ $ springmicro plugins link PATH [-h] [--install] [-v]
724
+
725
+ ARGUMENTS
726
+ PATH [default: .] path to plugin
727
+
728
+ FLAGS
729
+ -h, --help Show CLI help.
730
+ -v, --verbose
731
+ --[no-]install Install dependencies after linking the plugin.
732
+
733
+ DESCRIPTION
734
+ Links a plugin into the CLI for development.
735
+ Installation of a linked plugin will override a user-installed or core plugin.
736
+
737
+ e.g. If you have a user-installed or core plugin that has a 'hello' command, installing a linked plugin with a 'hello'
738
+ command will override the user-installed or core plugin implementation. This is useful for development work.
739
+
740
+
741
+ EXAMPLES
742
+ $ springmicro plugins link myplugin
743
+ ```
744
+
745
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.4/src/commands/plugins/link.ts)_
746
+
747
+ ## `springmicro plugins remove [PLUGIN]`
748
+
749
+ Removes a plugin from the CLI.
750
+
751
+ ```
752
+ USAGE
753
+ $ springmicro plugins remove [PLUGIN...] [-h] [-v]
754
+
755
+ ARGUMENTS
756
+ PLUGIN... plugin to uninstall
757
+
758
+ FLAGS
759
+ -h, --help Show CLI help.
760
+ -v, --verbose
761
+
762
+ DESCRIPTION
763
+ Removes a plugin from the CLI.
764
+
765
+ ALIASES
766
+ $ springmicro plugins unlink
767
+ $ springmicro plugins remove
768
+
769
+ EXAMPLES
770
+ $ springmicro plugins remove myplugin
771
+ ```
772
+
773
+ ## `springmicro plugins reset`
774
+
775
+ Remove all user-installed and linked plugins.
776
+
777
+ ```
778
+ USAGE
779
+ $ springmicro plugins reset [--hard] [--reinstall]
780
+
781
+ FLAGS
782
+ --hard Delete node_modules and package manager related files in addition to uninstalling plugins.
783
+ --reinstall Reinstall all plugins after uninstalling.
784
+ ```
785
+
786
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.4/src/commands/plugins/reset.ts)_
787
+
788
+ ## `springmicro plugins uninstall [PLUGIN]`
789
+
790
+ Removes a plugin from the CLI.
791
+
792
+ ```
793
+ USAGE
794
+ $ springmicro plugins uninstall [PLUGIN...] [-h] [-v]
795
+
796
+ ARGUMENTS
797
+ PLUGIN... plugin to uninstall
798
+
799
+ FLAGS
800
+ -h, --help Show CLI help.
801
+ -v, --verbose
802
+
803
+ DESCRIPTION
804
+ Removes a plugin from the CLI.
805
+
806
+ ALIASES
807
+ $ springmicro plugins unlink
808
+ $ springmicro plugins remove
809
+
810
+ EXAMPLES
811
+ $ springmicro plugins uninstall myplugin
812
+ ```
813
+
814
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.4/src/commands/plugins/uninstall.ts)_
815
+
816
+ ## `springmicro plugins unlink [PLUGIN]`
817
+
818
+ Removes a plugin from the CLI.
819
+
820
+ ```
821
+ USAGE
822
+ $ springmicro plugins unlink [PLUGIN...] [-h] [-v]
823
+
824
+ ARGUMENTS
825
+ PLUGIN... plugin to uninstall
826
+
827
+ FLAGS
828
+ -h, --help Show CLI help.
829
+ -v, --verbose
830
+
831
+ DESCRIPTION
832
+ Removes a plugin from the CLI.
833
+
834
+ ALIASES
835
+ $ springmicro plugins unlink
836
+ $ springmicro plugins remove
837
+
838
+ EXAMPLES
839
+ $ springmicro plugins unlink myplugin
840
+ ```
841
+
842
+ ## `springmicro plugins update`
843
+
844
+ Update installed plugins.
845
+
846
+ ```
847
+ USAGE
848
+ $ springmicro plugins update [-h] [-v]
849
+
850
+ FLAGS
851
+ -h, --help Show CLI help.
852
+ -v, --verbose
853
+
854
+ DESCRIPTION
855
+ Update installed plugins.
856
+ ```
857
+
858
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.3.4/src/commands/plugins/update.ts)_
437
859
  <!-- commandsstop -->
438
860
 
439
861
  - [`springmicro help [COMMAND]`](#springmicro-help-command)
@@ -0,0 +1,12 @@
1
+ import { Command } from '@oclif/core';
2
+ import forms from '../../data/form/index.js';
3
+ export default class Form extends Command {
4
+ static description: string;
5
+ static examples: string[];
6
+ static flags: {
7
+ template: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ };
9
+ extractEnvVars(formString: string): string[];
10
+ writeForm(template: keyof typeof forms): void;
11
+ run(): Promise<void>;
12
+ }
@@ -0,0 +1,51 @@
1
+ import { Command, Flags } from '@oclif/core';
2
+ import forms from '../../data/form/index.js';
3
+ import { checkUnixShellAndSpawn } from '../../utils/shell.js';
4
+ import path from 'node:path';
5
+ import fs from 'node:fs';
6
+ import chalk from 'chalk';
7
+ export default class Form extends Command {
8
+ // static override args = {
9
+ // file: Args.string({description: 'file to read'}),
10
+ // }
11
+ static description = 'add a form to your project';
12
+ static examples = ['<%= config.bin %> <%= command.id %>'];
13
+ static flags = {
14
+ // flag with a value (-t, --template=VALUE)
15
+ template: Flags.string({ char: 't', description: 'form template (contact|quote)' }),
16
+ };
17
+ extractEnvVars(formString) {
18
+ const envVarRegex = /import\.meta\.env\.(\w+)/g;
19
+ let match;
20
+ const envVars = [];
21
+ while ((match = envVarRegex.exec(formString)) !== null) {
22
+ envVars.push(match[1]);
23
+ }
24
+ return envVars;
25
+ }
26
+ writeForm(template) {
27
+ const baseDir = path.posix.join('src', 'components', 'forms');
28
+ const baseDirApi = path.posix.join('src', 'pages', 'api', 'forms');
29
+ fs.mkdirSync(baseDir, { recursive: true });
30
+ fs.mkdirSync(baseDirApi, { recursive: true });
31
+ const filePath = path.posix.join(baseDir, forms[template].name + '.tsx');
32
+ fs.writeFileSync(filePath, forms[template].tsx);
33
+ const filePathApi = path.posix.join(baseDirApi, forms[template].name.toLowerCase() + '.ts');
34
+ fs.writeFileSync(filePathApi, forms[template].api);
35
+ this.log('');
36
+ this.log(chalk.bgCyan.black('FINISHED!'));
37
+ const envVars = this.extractEnvVars(forms[template].api);
38
+ if (envVars.length > 0) {
39
+ this.log('');
40
+ this.log(chalk.cyan('Make sure to set the following environment variables:'));
41
+ envVars.forEach((v) => this.log(chalk.cyan(`- ${v}`)));
42
+ }
43
+ }
44
+ async run() {
45
+ const { args, flags } = await this.parse(Form);
46
+ const template = flags.template ?? 'contact';
47
+ if (Object.keys(forms).includes(template)) {
48
+ await checkUnixShellAndSpawn('sh', [path.posix.join(this.config.root, 'dist', 'scripts', 'forms.sh')], path.join(this.config.root, 'dist', 'scripts', 'forms.bat'), [], () => this.writeForm(template));
49
+ }
50
+ }
51
+ }
@@ -47,6 +47,8 @@ export default class Astro extends Command {
47
47
  tsConfig['compilerOptions'] = {
48
48
  ...tsConfig['compilerOptions'],
49
49
  baseUrl: '.',
50
+ // allow implicit type imports
51
+ verbatimModuleSyntax: false,
50
52
  paths: {
51
53
  '@/*': ['./src/*'],
52
54
  },
@@ -0,0 +1,10 @@
1
+ type FormStrings = {
2
+ tsx: string;
3
+ name: string;
4
+ api: string;
5
+ };
6
+ declare const _default: {
7
+ contact: FormStrings;
8
+ quote: FormStrings;
9
+ };
10
+ export default _default;
@@ -0,0 +1,274 @@
1
+ const contact = {
2
+ name: 'Contact',
3
+ tsx: `import { zodResolver } from "@hookform/resolvers/zod";
4
+ import { useForm } from "react-hook-form";
5
+ import { z } from "zod";
6
+ import { Button } from "@/components/ui/button";
7
+ import { toast } from "sonner";
8
+ import {
9
+ Form,
10
+ FormControl,
11
+ FormDescription,
12
+ FormField,
13
+ FormItem,
14
+ FormLabel,
15
+ FormMessage,
16
+ } from "@/components/ui/form";
17
+ import { Input } from "@/components/ui/input";
18
+ import { Textarea } from "@/components/ui/textarea"; // Assume you have a Textarea component
19
+
20
+ const formSchema = z.object({
21
+ name: z.string().min(1, {
22
+ message: "Name is required.",
23
+ }),
24
+ email: z.string().email({
25
+ message: "Invalid email address.",
26
+ }),
27
+ message: z.string().min(1, {
28
+ message: "Message is required.",
29
+ }),
30
+ });
31
+
32
+ export function ContactForm() {
33
+ // 1. Define your form.
34
+ const form = useForm<z.infer<typeof formSchema>>({
35
+ resolver: zodResolver(formSchema),
36
+ defaultValues: {
37
+ name: "",
38
+ email: "",
39
+ message: "",
40
+ },
41
+ });
42
+
43
+ // 2. Define a submit handler.
44
+ async function onSubmit(values: z.infer<typeof formSchema>) {
45
+ // Do something with the form values.
46
+ console.log(values);
47
+ const res = await fetch("/api/forms/contact", {
48
+ method: "POST",
49
+ body: JSON.stringify(values),
50
+ headers: { "Content-Type": "application/json" },
51
+ });
52
+ if (res.ok) {
53
+ // success toast
54
+ toast("Form submitted!");
55
+ } else {
56
+ // error toast
57
+ toast("Error submitting form, refresh and try again.");
58
+ }
59
+ }
60
+
61
+ return (
62
+ <Form {...form}>
63
+ <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
64
+ <FormField
65
+ control={form.control}
66
+ name="name"
67
+ render={({ field }) => (
68
+ <FormItem>
69
+ <FormLabel>Name</FormLabel>
70
+ <FormControl>
71
+ <Input placeholder="Your Name" {...field} />
72
+ </FormControl>
73
+ <FormMessage />
74
+ </FormItem>
75
+ )}
76
+ />
77
+ <FormField
78
+ control={form.control}
79
+ name="email"
80
+ render={({ field }) => (
81
+ <FormItem>
82
+ <FormLabel>Email</FormLabel>
83
+ <FormControl>
84
+ <Input
85
+ type="email"
86
+ placeholder="your.email@example.com"
87
+ {...field}
88
+ />
89
+ </FormControl>
90
+ <FormMessage />
91
+ </FormItem>
92
+ )}
93
+ />
94
+ <FormField
95
+ control={form.control}
96
+ name="message"
97
+ render={({ field }) => (
98
+ <FormItem>
99
+ <FormLabel>Message</FormLabel>
100
+ <FormControl>
101
+ <Textarea rows={4} placeholder="Your message" {...field} />
102
+ </FormControl>
103
+ <FormMessage />
104
+ </FormItem>
105
+ )}
106
+ />
107
+ <Button type="submit">Submit</Button>
108
+ </form>
109
+ </Form>
110
+ );
111
+ }
112
+
113
+ `,
114
+ api: `import { emailOnlySGJSON } from "@springmicro/forms";
115
+ import type { APIRoute } from "astro";
116
+
117
+ export const POST: APIRoute = async ({ params, request }) => {
118
+ const subject = "Contact Form Submission";
119
+ const json = await request.json();
120
+ const to: string[] = [json.email];
121
+ const cc: string[] = [];
122
+ const bcc: string[] = [];
123
+
124
+ const res = await emailOnlySGJSON(
125
+ import.meta.env.SENDGRID_API_KEY,
126
+ subject,
127
+ json,
128
+ to,
129
+ cc,
130
+ bcc
131
+ );
132
+ return res;
133
+ };
134
+ `,
135
+ };
136
+ const quote = {
137
+ name: 'Quote',
138
+ tsx: `import { zodResolver } from "@hookform/resolvers/zod";
139
+ import { useForm } from "react-hook-form";
140
+ import { z } from "zod";
141
+ import { Button } from "@/components/ui/button";
142
+ import { toast } from "sonner";
143
+ import {
144
+ Form,
145
+ FormControl,
146
+ FormDescription,
147
+ FormField,
148
+ FormItem,
149
+ FormLabel,
150
+ FormMessage,
151
+ } from "@/components/ui/form";
152
+ import { Input } from "@/components/ui/input";
153
+ import { Textarea } from "@/components/ui/textarea"; // Assume you have a Textarea component
154
+
155
+ const formSchema = z.object({
156
+ name: z.string().min(1, {
157
+ message: "Name is required.",
158
+ }),
159
+ email: z.string().email({
160
+ message: "Invalid email address.",
161
+ }),
162
+ message: z.string().min(1, {
163
+ message: "Message is required.",
164
+ }),
165
+ });
166
+
167
+ export function QuoteForm() {
168
+ // 1. Define your form.
169
+ const form = useForm<z.infer<typeof formSchema>>({
170
+ resolver: zodResolver(formSchema),
171
+ defaultValues: {
172
+ name: "",
173
+ email: "",
174
+ message: "",
175
+ },
176
+ });
177
+
178
+ // 2. Define a submit handler.
179
+ async function onSubmit(values: z.infer<typeof formSchema>) {
180
+ // Do something with the form values.
181
+ console.log(values);
182
+ const res = await fetch("/api/forms/quote", {
183
+ method: "POST",
184
+ body: JSON.stringify(values),
185
+ headers: { "Content-Type": "application/json" },
186
+ });
187
+ if (res.ok) {
188
+ // success toast
189
+ toast("Form submitted!");
190
+ } else {
191
+ // error toast
192
+ toast("Error submitting form, refresh and try again.");
193
+ }
194
+ }
195
+
196
+ return (
197
+ <Form {...form}>
198
+ <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
199
+ <FormField
200
+ control={form.control}
201
+ name="name"
202
+ render={({ field }) => (
203
+ <FormItem>
204
+ <FormLabel>Name</FormLabel>
205
+ <FormControl>
206
+ <Input placeholder="Your Name" {...field} />
207
+ </FormControl>
208
+ <FormMessage />
209
+ </FormItem>
210
+ )}
211
+ />
212
+ <FormField
213
+ control={form.control}
214
+ name="email"
215
+ render={({ field }) => (
216
+ <FormItem>
217
+ <FormLabel>Email</FormLabel>
218
+ <FormControl>
219
+ <Input
220
+ type="email"
221
+ placeholder="your.email@example.com"
222
+ {...field}
223
+ />
224
+ </FormControl>
225
+ <FormMessage />
226
+ </FormItem>
227
+ )}
228
+ />
229
+ <FormField
230
+ control={form.control}
231
+ name="message"
232
+ render={({ field }) => (
233
+ <FormItem>
234
+ <FormLabel>Message</FormLabel>
235
+ <FormControl>
236
+ <Textarea rows={4} placeholder="Your message" {...field} />
237
+ </FormControl>
238
+ <FormMessage />
239
+ </FormItem>
240
+ )}
241
+ />
242
+ <Button type="submit">Submit</Button>
243
+ </form>
244
+ </Form>
245
+ );
246
+ }
247
+
248
+ `,
249
+ api: `import { emailOnlySGJSON } from "@springmicro/forms";
250
+ import type { APIRoute } from "astro";
251
+
252
+ export const POST: APIRoute = async ({ params, request }) => {
253
+ const subject = "Request a Quote Submission";
254
+ const json = await request.json();
255
+ const to: string[] = [json.email];
256
+ const cc: string[] = [];
257
+ const bcc: string[] = [];
258
+
259
+ const res = await emailOnlySGJSON(
260
+ import.meta.env.SENDGRID_API_KEY,
261
+ subject,
262
+ json,
263
+ to,
264
+ cc,
265
+ bcc
266
+ );
267
+ return res;
268
+ };
269
+ `,
270
+ };
271
+ export default {
272
+ contact,
273
+ quote,
274
+ };
@@ -0,0 +1,10 @@
1
+ @echo off
2
+
3
+ REM Use PowerShell to simulate 'yes no' command and pipe to pnpm
4
+ powershell -Command "while ($true) { Write-Output 'n' }" | pnpm dlx shadcn-ui@latest add form
5
+ powershell -Command "while ($true) { Write-Output 'n' }" | pnpm dlx shadcn-ui@latest add button
6
+ powershell -Command "while ($true) { Write-Output 'n' }" | pnpm dlx shadcn-ui@latest add textarea
7
+ powershell -Command "while ($true) { Write-Output 'n' }" | pnpm dlx shadcn-ui@latest add label
8
+ powershell -Command "while ($true) { Write-Output 'n' }" | pnpm dlx shadcn-ui@latest add input
9
+ powershell -Command "while ($true) { Write-Output 'n' }" | pnpm dlx shadcn-ui@latest add sonner
10
+ pnpm add @springmicro/forms
@@ -0,0 +1,8 @@
1
+ # no to overwriting shadcn components that have already been installed
2
+ yes no | pnpm dlx shadcn-ui@latest add form
3
+ yes no | pnpm dlx shadcn-ui@latest add button
4
+ yes no | pnpm dlx shadcn-ui@latest add textarea
5
+ yes no | pnpm dlx shadcn-ui@latest add label
6
+ yes no | pnpm dlx shadcn-ui@latest add input
7
+ yes no | pnpm dlx shadcn-ui@latest add sonner
8
+ pnpm add @springmicro/forms
@@ -24,6 +24,39 @@
24
24
  "auth.js"
25
25
  ]
26
26
  },
27
+ "add:form": {
28
+ "aliases": [],
29
+ "args": {},
30
+ "description": "add a form to your project",
31
+ "examples": [
32
+ "<%= config.bin %> <%= command.id %>"
33
+ ],
34
+ "flags": {
35
+ "template": {
36
+ "char": "t",
37
+ "description": "form template (contact|quote)",
38
+ "name": "template",
39
+ "hasDynamicHelp": false,
40
+ "multiple": false,
41
+ "type": "option"
42
+ }
43
+ },
44
+ "hasDynamicHelp": false,
45
+ "hiddenAliases": [],
46
+ "id": "add:form",
47
+ "pluginAlias": "@springmicro/cli",
48
+ "pluginName": "@springmicro/cli",
49
+ "pluginType": "core",
50
+ "strict": true,
51
+ "enableJsonFlag": false,
52
+ "isESM": true,
53
+ "relativePath": [
54
+ "dist",
55
+ "commands",
56
+ "add",
57
+ "form.js"
58
+ ]
59
+ },
27
60
  "init:astro": {
28
61
  "aliases": [],
29
62
  "args": {},
@@ -101,5 +134,5 @@
101
134
  ]
102
135
  }
103
136
  },
104
- "version": "0.2.0-alpha.3"
137
+ "version": "0.2.1"
105
138
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@springmicro/cli",
3
3
  "description": "A new CLI generated with oclif",
4
- "version": "0.2.0-alpha.3",
4
+ "version": "0.2.1",
5
5
  "author": "David Buckley",
6
6
  "private": false,
7
7
  "publishConfig": {
@@ -76,5 +76,5 @@
76
76
  "version": "oclif readme && git add README.md"
77
77
  },
78
78
  "types": "dist/index.d.ts",
79
- "gitHead": "0854b518932e657d4c08fb5877c725a9425b36e9"
79
+ "gitHead": "5060bfe477b5be4d15de32991fb8ebc839143430"
80
80
  }