@aerogel/cli 0.0.0-next.59bf5f7cc06e728d0cf6c00de28f1da48d7d6b8e → 0.0.0-next.6c02970f90d4e979a72530f1fa0c650785d6538f

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.
Files changed (80) hide show
  1. package/.prettierignore +1 -0
  2. package/dist/aerogel-cli.cjs.js +1 -1
  3. package/dist/aerogel-cli.cjs.js.map +1 -1
  4. package/dist/aerogel-cli.d.ts +2 -2
  5. package/dist/aerogel-cli.esm.js +1 -1
  6. package/dist/aerogel-cli.esm.js.map +1 -1
  7. package/package.json +12 -5
  8. package/src/cli.ts +27 -3
  9. package/src/commands/Command.ts +11 -6
  10. package/src/commands/create.test.ts +12 -4
  11. package/src/commands/create.ts +20 -9
  12. package/src/commands/generate-component.test.ts +50 -3
  13. package/src/commands/generate-component.ts +162 -21
  14. package/src/commands/generate-model.test.ts +2 -2
  15. package/src/commands/generate-model.ts +19 -22
  16. package/src/commands/generate-overrides.ts +85 -0
  17. package/src/commands/generate-service.test.ts +21 -0
  18. package/src/commands/generate-service.ts +151 -0
  19. package/src/commands/info.ts +14 -0
  20. package/src/commands/install.test.ts +41 -0
  21. package/src/commands/install.ts +33 -0
  22. package/src/lib/App.ts +60 -5
  23. package/src/lib/Editor.ts +58 -0
  24. package/src/lib/File.mock.ts +1 -5
  25. package/src/lib/File.ts +7 -1
  26. package/src/lib/Log.mock.ts +3 -6
  27. package/src/lib/Log.ts +7 -5
  28. package/src/lib/Shell.mock.ts +2 -2
  29. package/src/lib/Shell.ts +1 -1
  30. package/src/lib/Template.ts +5 -1
  31. package/src/lib/utils/app.ts +15 -0
  32. package/src/lib/utils/edit.ts +44 -0
  33. package/src/lib/utils/paths.ts +34 -0
  34. package/src/plugins/Histoire.ts +113 -0
  35. package/src/plugins/Plugin.ts +178 -0
  36. package/src/plugins/Solid.ts +79 -0
  37. package/src/plugins/Soukai.ts +19 -0
  38. package/src/testing/setup.ts +39 -12
  39. package/templates/app/.github/workflows/ci.yml +16 -4
  40. package/templates/app/.vscode/launch.json +16 -0
  41. package/templates/app/.vscode/settings.json +10 -0
  42. package/templates/app/README.md +3 -0
  43. package/templates/app/cypress/cypress.config.ts +14 -0
  44. package/templates/app/cypress/support/e2e.ts +1 -3
  45. package/templates/app/cypress/tsconfig.json +3 -1
  46. package/templates/app/index.html +4 -3
  47. package/templates/app/package.json +34 -11
  48. package/templates/app/src/App.vue +5 -3
  49. package/templates/app/src/assets/public/robots.txt +2 -0
  50. package/templates/app/src/main.ts +4 -4
  51. package/templates/app/src/types/globals.d.ts +0 -1
  52. package/templates/app/tailwind.config.js +1 -1
  53. package/templates/app/tsconfig.json +1 -0
  54. package/templates/app/vite.config.ts +10 -5
  55. package/templates/component-button/[component.name].vue +42 -0
  56. package/templates/component-button-story/[component.name].story.vue +77 -0
  57. package/templates/component-checkbox/[component.name].vue +34 -0
  58. package/templates/component-checkbox-story/[component.name].story.vue +63 -0
  59. package/templates/component-input/[component.name].vue +17 -0
  60. package/templates/component-input-story/[component.name].story.vue +63 -0
  61. package/templates/histoire/histoire.config.ts +7 -0
  62. package/templates/histoire/patches/histoire+0.17.6.patch +13 -0
  63. package/templates/histoire/src/main.histoire.ts +8 -0
  64. package/templates/overrides/components/index.ts +15 -0
  65. package/templates/overrides/components/overrides/AlertModal.vue +11 -0
  66. package/templates/overrides/components/overrides/ConfirmModal.vue +20 -0
  67. package/templates/overrides/components/overrides/ErrorReportModal.vue +35 -0
  68. package/templates/overrides/components/overrides/LoadingModal.vue +12 -0
  69. package/templates/overrides/components/overrides/ModalWrapper.vue +22 -0
  70. package/templates/overrides/components/overrides/SnackbarNotification.vue +34 -0
  71. package/templates/overrides-story/Overrides.story.vue +86 -0
  72. package/templates/postcss-pseudo-classes/postcss.config.js +15 -0
  73. package/templates/service/[service.name].ts +8 -0
  74. package/.eslintrc.js +0 -7
  75. package/noeldemartin.config.js +0 -4
  76. package/src/lib/utils.test.ts +0 -33
  77. package/src/lib/utils.ts +0 -44
  78. package/templates/app/cypress.config.ts +0 -8
  79. /package/bin/{ag → gel} +0 -0
  80. /package/templates/app/src/assets/{styles.css → css/styles.css} +0 -0
@@ -1,23 +1,44 @@
1
+ import { arrayFilter, arrayFrom, stringToSlug } from '@noeldemartin/utils';
2
+ import { Node, SyntaxKind } from 'ts-morph';
3
+ import type { ArrayLiteralExpression, CallExpression, SourceFile } from 'ts-morph';
4
+
1
5
  import Command from '@/commands/Command';
2
6
  import File from '@/lib/File';
3
7
  import Log from '@/lib/Log';
4
8
  import Template from '@/lib/Template';
5
- import { basePath } from '@/lib/utils';
9
+ import { app } from '@/lib/utils/app';
10
+ import { editFiles, findDescendant } from '@/lib/utils/edit';
11
+ import { templatePath } from '@/lib/utils/paths';
6
12
  import type { CommandOptions } from '@/commands/Command';
7
13
 
8
14
  export interface Options {
15
+ button?: boolean;
16
+ checkbox?: boolean;
17
+ input?: boolean;
9
18
  story?: boolean;
10
19
  }
11
20
 
12
21
  export class GenerateComponentCommand extends Command {
13
22
 
14
- public static command: string = 'generate:component';
15
- public static description: string = 'Generate an AerogelJS component';
16
- public static parameters: [string, string][] = [
23
+ protected static command: string = 'generate:component';
24
+ protected static description: string = 'Generate an AerogelJS Component';
25
+ protected static parameters: [string, string][] = [
17
26
  ['path', 'Component path (relative to components folder; extension not necessary)'],
18
27
  ];
19
28
 
20
- public static options: CommandOptions = {
29
+ protected static options: CommandOptions = {
30
+ button: {
31
+ description: 'Create a custom button',
32
+ type: 'boolean',
33
+ },
34
+ checkbox: {
35
+ description: 'Create a custom checkbox',
36
+ type: 'boolean',
37
+ },
38
+ input: {
39
+ description: 'Create a custom input',
40
+ type: 'boolean',
41
+ },
21
42
  story: {
22
43
  description: 'Create component story using Histoire',
23
44
  type: 'boolean',
@@ -34,36 +55,156 @@ export class GenerateComponentCommand extends Command {
34
55
  this.options = options;
35
56
  }
36
57
 
37
- public async run(): Promise<void> {
38
- this.assertAerogelOrDirectory('src/components');
39
- this.options.story && this.assertHistoireInstalled();
58
+ protected async validate(): Promise<void> {
59
+ const components = arrayFilter([this.options.button, this.options.input, this.options.checkbox]).length;
40
60
 
41
- if (File.exists(`src/components/${this.path}.vue`)) {
42
- Log.fail(`${this.path} component already exists!`);
61
+ if (components > 1) {
62
+ Log.fail('Can only use one of \'button\', \'input\', or \'checkbox\' flags!');
43
63
  }
64
+ }
65
+
66
+ protected async run(): Promise<void> {
67
+ this.assertAerogelOrDirectory('src/components');
68
+ this.assertHistoireInstalled();
44
69
 
70
+ const files = new Set<string>();
45
71
  const [directoryName, componentName] = this.parsePathComponents();
46
- const files = Template.instantiate(basePath('templates/component'), `src/components/${directoryName}`, {
47
- component: { name: componentName },
72
+
73
+ await this.createComponent(directoryName, componentName, files);
74
+ await this.createStory(directoryName, componentName, files);
75
+ await this.declareComponents();
76
+
77
+ const filesList = arrayFrom(files)
78
+ .map((file) => `- ${file}`)
79
+ .join('\n');
80
+
81
+ Log.info(`${componentName} component created successfully! The following files were created:\n\n${filesList}`);
82
+ }
83
+
84
+ protected assertHistoireInstalled(): void {
85
+ if (!this.options.story) {
86
+ return;
87
+ }
88
+
89
+ if (!File.contains('package.json', '"histoire"') && !File.contains('package.json', '"@aerogel/histoire"')) {
90
+ Log.fail(`
91
+ Histoire is not installed yet! You can install it running:
92
+ npx gel install histoire
93
+ `);
94
+ }
95
+ }
96
+
97
+ protected async createComponent(directoryName: string, componentName: string, files: Set<string>): Promise<void> {
98
+ await Log.animate('Creating component', async () => {
99
+ if (File.exists(`src/components/${this.path}.vue`)) {
100
+ Log.fail(`${this.path} component already exists!`);
101
+ }
102
+
103
+ const templateName = this.options.input
104
+ ? 'component-input'
105
+ : this.options.button
106
+ ? 'component-button'
107
+ : this.options.checkbox
108
+ ? 'component-checkbox'
109
+ : 'component';
110
+ const componentFiles = Template.instantiate(templatePath(templateName), `src/components/${directoryName}`, {
111
+ component: {
112
+ name: componentName,
113
+ slug: stringToSlug(componentName),
114
+ },
115
+ });
116
+
117
+ componentFiles.forEach((file) => files.add(file));
48
118
  });
119
+ }
49
120
 
50
- if (this.options.story) {
51
- const storyFiles = Template.instantiate(basePath('templates/component-story'), 'src/components', {
52
- component: { name: componentName },
121
+ protected async createStory(directoryName: string, componentName: string, files: Set<string>): Promise<void> {
122
+ if (!this.options.story) {
123
+ return;
124
+ }
125
+
126
+ await Log.animate('Creating story', async () => {
127
+ const templateName = this.options.input
128
+ ? 'component-input-story'
129
+ : this.options.button
130
+ ? 'component-button-story'
131
+ : this.options.checkbox
132
+ ? 'component-checkbox-story'
133
+ : 'component-story';
134
+ const storyFiles = Template.instantiate(templatePath(templateName), `src/components/${directoryName}`, {
135
+ component: {
136
+ name: componentName,
137
+ slug: stringToSlug(componentName),
138
+ },
53
139
  });
54
140
 
55
- files.push(...storyFiles);
141
+ storyFiles.forEach((file) => files.add(file));
142
+ });
143
+ }
144
+
145
+ protected async declareComponents(): Promise<void> {
146
+ if (!editFiles()) {
147
+ return;
56
148
  }
57
149
 
58
- const filesList = files.map((file) => `- ${file}`).join('\n');
150
+ const editor = app().edit();
151
+ const viteConfig = editor.requireSourceFile('vite.config.ts');
152
+ const componentDirsArray = this.getComponentDirsArray(viteConfig);
59
153
 
60
- Log.info(`${componentName} component created successfully! The following files were created:\n\n${filesList}`);
154
+ if (!componentDirsArray) {
155
+ return Log.fail('Could not find component dirs declaration in vite config!');
156
+ }
157
+
158
+ if (
159
+ componentDirsArray
160
+ .getDescendantsOfKind(SyntaxKind.StringLiteral)
161
+ .some((literal) => literal.getText() === '\'src/components\'')
162
+ ) {
163
+ return;
164
+ }
165
+
166
+ await Log.animate('Updating vite config', async () => {
167
+ componentDirsArray.addElement('\'src/components\'');
168
+
169
+ await editor.save(viteConfig);
170
+ });
171
+
172
+ await editor.format();
61
173
  }
62
174
 
63
- protected assertHistoireInstalled(): void {
64
- if (!File.exists('src/main.histoire.ts')) {
65
- Log.fail('Histoire is not installed yet!');
175
+ protected getComponentDirsArray(viteConfig: SourceFile): ArrayLiteralExpression | null {
176
+ const pluginCall = findDescendant(viteConfig, {
177
+ guard: Node.isCallExpression,
178
+ validate: (callExpression) => callExpression.getText().startsWith('Components('),
179
+ skip: SyntaxKind.ImportDeclaration,
180
+ });
181
+
182
+ if (!pluginCall) {
183
+ return null;
66
184
  }
185
+
186
+ const dirsAssignment = findDescendant(pluginCall, {
187
+ guard: Node.isPropertyAssignment,
188
+ validate: (propertyAssignment) => propertyAssignment.getName() === 'dirs',
189
+ });
190
+
191
+ const dirsArray = dirsAssignment?.getInitializer();
192
+
193
+ if (!Node.isArrayLiteralExpression(dirsArray)) {
194
+ return this.declareComponentDirsArray(pluginCall);
195
+ }
196
+
197
+ return dirsArray;
198
+ }
199
+
200
+ protected declareComponentDirsArray(pluginCall: CallExpression): ArrayLiteralExpression | null {
201
+ const pluginOptions = findDescendant(pluginCall, { guard: Node.isObjectLiteralExpression });
202
+ const dirsAssignment = pluginOptions?.addPropertyAssignment({
203
+ name: 'dirs',
204
+ initializer: '[]',
205
+ });
206
+
207
+ return (dirsAssignment?.getInitializer() as ArrayLiteralExpression) ?? null;
67
208
  }
68
209
 
69
210
  protected parsePathComponents(): [string, string] {
@@ -1,11 +1,11 @@
1
1
  import { describe, it } from 'vitest';
2
+ import { formatCodeBlock } from '@noeldemartin/utils';
2
3
 
3
4
  import FileMock from '@/lib/File.mock';
4
- import { formatCodeBlock } from '@/lib/utils';
5
5
 
6
6
  import { GenerateModelCommand } from './generate-model';
7
7
 
8
- describe('Generate model command', () => {
8
+ describe('Generate Model command', () => {
9
9
 
10
10
  it('generates models', async () => {
11
11
  // Arrange
@@ -1,10 +1,10 @@
1
- import { stringToStudlyCase } from '@noeldemartin/utils';
1
+ import { formatCodeBlock, stringToStudlyCase } from '@noeldemartin/utils';
2
2
 
3
3
  import Command from '@/commands/Command';
4
4
  import File from '@/lib/File';
5
5
  import Log from '@/lib/Log';
6
6
  import Template from '@/lib/Template';
7
- import { basePath, formatCodeBlock } from '@/lib/utils';
7
+ import { templatePath } from '@/lib/utils/paths';
8
8
  import type { CommandOptions } from '@/commands/Command';
9
9
 
10
10
  interface Options {
@@ -13,10 +13,10 @@ interface Options {
13
13
 
14
14
  export class GenerateModelCommand extends Command {
15
15
 
16
- public static command: string = 'generate:model';
17
- public static description: string = 'Generate an AerogelJS model';
18
- public static parameters: [string, string][] = [['name', 'Model name']];
19
- public static options: CommandOptions = {
16
+ protected static command: string = 'generate:model';
17
+ protected static description: string = 'Generate an AerogelJS Model';
18
+ protected static parameters: [string, string][] = [['name', 'Model name']];
19
+ protected static options: CommandOptions = {
20
20
  fields: 'Create model with the given fields',
21
21
  };
22
22
 
@@ -30,7 +30,7 @@ export class GenerateModelCommand extends Command {
30
30
  this.options = options;
31
31
  }
32
32
 
33
- public async run(): Promise<void> {
33
+ protected async run(): Promise<void> {
34
34
  this.assertAerogelOrDirectory('src/models');
35
35
 
36
36
  if (File.exists(`src/models/${this.name}.ts`)) {
@@ -39,15 +39,17 @@ export class GenerateModelCommand extends Command {
39
39
 
40
40
  this.assertSoukaiInstalled();
41
41
 
42
- const files = Template.instantiate(basePath('templates/model'), 'src/models', {
43
- model: {
44
- name: this.name,
45
- fieldsDefinition: this.getFieldsDefinition(),
46
- },
47
- soukaiImports: this.options.fields ? 'FieldType, defineModelSchema' : 'defineModelSchema',
48
- });
42
+ const filesList = await Log.animate('Creating model', async () => {
43
+ const files = Template.instantiate(templatePath('model'), 'src/models', {
44
+ model: {
45
+ name: this.name,
46
+ fieldsDefinition: this.getFieldsDefinition(),
47
+ },
48
+ soukaiImports: this.options.fields ? 'FieldType, defineModelSchema' : 'defineModelSchema',
49
+ });
49
50
 
50
- const filesList = files.map((file) => `- ${file}`).join('\n');
51
+ return files.map((file) => `- ${file}`).join('\n');
52
+ });
51
53
 
52
54
  Log.info(`${this.name} model created successfully! The following files were created:\n\n${filesList}`);
53
55
  }
@@ -87,13 +89,8 @@ export class GenerateModelCommand extends Command {
87
89
  protected assertSoukaiInstalled(): void {
88
90
  if (!File.contains('package.json', '"soukai"') && !File.contains('package.json', '"@aerogel/plugin-soukai"')) {
89
91
  Log.fail(`
90
- Soukai is not installed yet! You can install it doing the following:
91
-
92
- 1. Run the following command:
93
- npm install soukai @aerogel/plugin-soukai@next
94
-
95
- 2. Add this to your plugins array in src/main.ts:
96
- soukai({ models: import.meta.glob('@/models/*', { eager: true }) })
92
+ Soukai is not installed yet! You can install it running:
93
+ npx gel install soukai
97
94
  `);
98
95
  }
99
96
  }
@@ -0,0 +1,85 @@
1
+ import { arrayFrom } from '@noeldemartin/utils';
2
+
3
+ import Command from '@/commands/Command';
4
+ import File from '@/lib/File';
5
+ import Log from '@/lib/Log';
6
+ import Template from '@/lib/Template';
7
+ import { templatePath } from '@/lib/utils/paths';
8
+ import type { CommandOptions } from '@/commands/Command';
9
+
10
+ export interface Options {
11
+ story?: boolean;
12
+ }
13
+
14
+ export class GenerateOverridesCommand extends Command {
15
+
16
+ protected static command: string = 'generate:overrides';
17
+ protected static description: string = 'Generate AerogelJS component overrides';
18
+
19
+ protected static options: CommandOptions = {
20
+ story: {
21
+ description: 'Create overrides story using Histoire',
22
+ type: 'boolean',
23
+ },
24
+ };
25
+
26
+ private options: Options;
27
+
28
+ constructor(options: Options = {}) {
29
+ super();
30
+
31
+ this.options = options;
32
+ }
33
+
34
+ protected async run(): Promise<void> {
35
+ this.assertAerogelOrDirectory('src/components');
36
+ this.assertHistoireInstalled();
37
+
38
+ const files = new Set<string>();
39
+
40
+ await this.createComponents(files);
41
+ await this.createStory(files);
42
+
43
+ const filesList = arrayFrom(files)
44
+ .map((file) => `- ${file}`)
45
+ .join('\n');
46
+
47
+ Log.info(`Overrides created successfully! The following files were created:\n\n${filesList}`);
48
+ Log.info('\nRemember to declare your components in main.ts and main.histoire.ts!');
49
+ }
50
+
51
+ protected assertHistoireInstalled(): void {
52
+ if (!this.options.story) {
53
+ return;
54
+ }
55
+
56
+ if (!File.contains('package.json', '"histoire"') && !File.contains('package.json', '"@aerogel/histoire"')) {
57
+ Log.fail(`
58
+ Histoire is not installed yet! You can install it running:
59
+ npx gel install histoire
60
+ `);
61
+ }
62
+ }
63
+
64
+ protected async createComponents(files: Set<string>): Promise<void> {
65
+ await Log.animate('Creating components', async () => {
66
+ if (File.exists('src/components/ModalWrapper.vue')) {
67
+ Log.fail('ModalWrapper component already exists!');
68
+ }
69
+
70
+ Template.instantiate(templatePath('overrides'), 'src').forEach((file) => files.add(file));
71
+ });
72
+ }
73
+
74
+ protected async createStory(files: Set<string>): Promise<void> {
75
+ if (!this.options.story) {
76
+ return;
77
+ }
78
+
79
+ await Log.animate('Creating story', async () => {
80
+ Template.instantiate(templatePath('overrides-story'), 'src/components/overrides/').forEach((file) =>
81
+ files.add(file));
82
+ });
83
+ }
84
+
85
+ }
@@ -0,0 +1,21 @@
1
+ import { describe, it } from 'vitest';
2
+
3
+ import FileMock from '@/lib/File.mock';
4
+
5
+ import { GenerateServiceCommand } from './generate-service';
6
+
7
+ describe('Generate Service command', () => {
8
+
9
+ it('generates services', async () => {
10
+ // Arrange
11
+ FileMock.stub('package.json', '@aerogel/core');
12
+
13
+ // Act
14
+ await GenerateServiceCommand.run('FooBar');
15
+
16
+ // Assert
17
+ FileMock.expectCreated('src/services/FooBar.ts').toContain('class FooBarService extends Service');
18
+ FileMock.expectCreated('src/services/FooBar.ts').toContain('export default facade(FooBarService);');
19
+ });
20
+
21
+ });
@@ -0,0 +1,151 @@
1
+ import { arrayFrom, formatCodeBlock, stringToCamelCase } from '@noeldemartin/utils';
2
+ import { Node, SyntaxKind } from 'ts-morph';
3
+ import type { ObjectLiteralExpression, SourceFile } from 'ts-morph';
4
+
5
+ import Command from '@/commands/Command';
6
+ import File from '@/lib/File';
7
+ import Log from '@/lib/Log';
8
+ import Template from '@/lib/Template';
9
+ import { app } from '@/lib/utils/app';
10
+ import { templatePath } from '@/lib/utils/paths';
11
+ import { editFiles, findDescendant } from '@/lib/utils/edit';
12
+ import type { Editor } from '@/lib/Editor';
13
+
14
+ export class GenerateServiceCommand extends Command {
15
+
16
+ protected static command: string = 'generate:service';
17
+ protected static description: string = 'Generate an AerogelJS Service';
18
+ protected static parameters: [string, string][] = [['name', 'Service name']];
19
+
20
+ private name: string;
21
+
22
+ constructor(name: string) {
23
+ super();
24
+
25
+ this.name = name;
26
+ }
27
+
28
+ protected async run(): Promise<void> {
29
+ this.assertAerogelOrDirectory('src/services');
30
+
31
+ const files = new Set<string>();
32
+ const editor = app().edit();
33
+
34
+ await this.createService(files);
35
+
36
+ if (editFiles()) {
37
+ await this.registerService(editor);
38
+ await editor.format();
39
+ }
40
+
41
+ const filesList = arrayFrom(files)
42
+ .map((file) => `- ${file}`)
43
+ .join('\n');
44
+
45
+ Log.info(`${this.name} service created successfully! The following files were created:\n\n${filesList}`);
46
+ }
47
+
48
+ protected async createService(files: Set<string>): Promise<void> {
49
+ await Log.animate('Creating service', async () => {
50
+ if (File.exists(`src/services/${this.name}.ts`)) {
51
+ Log.fail(`${this.name} service already exists!`);
52
+ }
53
+
54
+ const serviceFiles = Template.instantiate(templatePath('service'), 'src/services', {
55
+ service: {
56
+ name: this.name,
57
+ },
58
+ });
59
+
60
+ serviceFiles.forEach((file) => files.add(file));
61
+ });
62
+ }
63
+
64
+ protected async registerService(editor: Editor): Promise<void> {
65
+ await Log.animate('Registering service', async () => {
66
+ if (!File.exists('src/services/index.ts')) {
67
+ await this.createServicesIndex(editor);
68
+ }
69
+
70
+ const servicesIndex = editor.requireSourceFile('src/services/index.ts');
71
+ const servicesObject = this.getServicesObject(servicesIndex);
72
+
73
+ if (!servicesObject) {
74
+ return Log.fail('Could not find services object in services config, please add it manually.');
75
+ }
76
+
77
+ servicesIndex.addImportDeclaration({
78
+ defaultImport: this.name,
79
+ moduleSpecifier: `./${this.name}`,
80
+ });
81
+ servicesObject.addPropertyAssignment({
82
+ name: `$${stringToCamelCase(this.name)}`,
83
+ initializer: this.name,
84
+ });
85
+
86
+ await editor.save(servicesIndex);
87
+ });
88
+ }
89
+
90
+ protected async createServicesIndex(editor: Editor): Promise<void> {
91
+ File.write(
92
+ 'src/services/index.ts',
93
+ formatCodeBlock(`
94
+ export const services = {};
95
+
96
+ export type AppServices = typeof services;
97
+
98
+ declare module '@vue/runtime-core' {
99
+ interface ComponentCustomProperties extends AppServices {}
100
+ }
101
+ `),
102
+ );
103
+
104
+ editor.addSourceFile('src/services/index.ts');
105
+
106
+ const mainConfig = editor.requireSourceFile('src/main.ts');
107
+ const bootstrapOptions = this.getBootstrapOptions(mainConfig);
108
+
109
+ if (!bootstrapOptions) {
110
+ return Log.fail('Could not find options object in bootstrap config, please add the services manually.');
111
+ }
112
+
113
+ bootstrapOptions.insertShorthandPropertyAssignment(0, { name: 'services' });
114
+ mainConfig.addImportDeclaration({
115
+ namedImports: ['services'],
116
+ moduleSpecifier: './services',
117
+ });
118
+
119
+ await editor.save(mainConfig);
120
+ }
121
+
122
+ protected getBootstrapOptions(mainConfig: SourceFile): ObjectLiteralExpression | null {
123
+ const bootstrapAppCall = findDescendant(mainConfig, {
124
+ guard: Node.isCallExpression,
125
+ validate: (callExpression) => callExpression.getExpression().getText() === 'bootstrap',
126
+ skip: SyntaxKind.ImportDeclaration,
127
+ });
128
+ const bootstrapOptions = bootstrapAppCall?.getArguments()[1];
129
+
130
+ if (!Node.isObjectLiteralExpression(bootstrapOptions)) {
131
+ return null;
132
+ }
133
+
134
+ return bootstrapOptions;
135
+ }
136
+
137
+ protected getServicesObject(servicesIndex: SourceFile): ObjectLiteralExpression | null {
138
+ const servicesDeclaration = findDescendant(servicesIndex, {
139
+ guard: Node.isVariableDeclaration,
140
+ validate: (variableDeclaration) => variableDeclaration.getName() === 'services',
141
+ });
142
+ const servicesObject = servicesDeclaration?.getInitializer();
143
+
144
+ if (!Node.isObjectLiteralExpression(servicesObject)) {
145
+ return null;
146
+ }
147
+
148
+ return servicesObject;
149
+ }
150
+
151
+ }
@@ -0,0 +1,14 @@
1
+ import Command from '@/commands/Command';
2
+ import Log from '@/lib/Log';
3
+
4
+ export class InfoCommand extends Command {
5
+
6
+ protected static command: string = 'info';
7
+ protected static description: string = 'Show debugging information about the CLI';
8
+
9
+ protected async run(): Promise<void> {
10
+ Log.info('[AerogelJS CLI info]');
11
+ Log.info('Installation directory: ' + __dirname);
12
+ }
13
+
14
+ }
@@ -0,0 +1,41 @@
1
+ import { describe, it } from 'vitest';
2
+
3
+ import FileMock from '@/lib/File.mock';
4
+ import ShellMock from '@/lib/Shell.mock';
5
+
6
+ import { InstallCommand } from './install';
7
+
8
+ describe('Install plugin command', () => {
9
+
10
+ it('installs solid', async () => {
11
+ // Act
12
+ await InstallCommand.run('solid');
13
+
14
+ // Assert
15
+ ShellMock.expectRan('npm install soukai-solid@next --save-exact');
16
+ ShellMock.expectRan('npm install @aerogel/plugin-solid@next --save-exact');
17
+ });
18
+
19
+ it('installs soukai', async () => {
20
+ // Act
21
+ await InstallCommand.run('soukai');
22
+
23
+ // Assert
24
+ ShellMock.expectRan('npm install soukai@next --save-exact');
25
+ ShellMock.expectRan('npm install @aerogel/plugin-soukai@next --save-exact');
26
+ });
27
+
28
+ it('installs histoire', async () => {
29
+ // Arrange
30
+ FileMock.stub('package.json', '"@aerogel/core"');
31
+
32
+ // Act
33
+ await InstallCommand.run('histoire');
34
+
35
+ // Assert
36
+ ShellMock.expectRan('npm install histoire@0.17.6 --save-dev');
37
+ ShellMock.expectRan('npm install @aerogel/histoire@next --save-exact --save-dev');
38
+ ShellMock.expectRan('npm install patch-package --save-dev');
39
+ });
40
+
41
+ });
@@ -0,0 +1,33 @@
1
+ import Command from '@/commands/Command';
2
+ import Log from '@/lib/Log';
3
+ import { Histoire } from '@/plugins/Histoire';
4
+ import { Solid } from '@/plugins/Solid';
5
+ import { Soukai } from '@/plugins/Soukai';
6
+ import type Plugin from '@/plugins/Plugin';
7
+
8
+ const plugins = [new Soukai(), new Solid(), new Histoire()].reduce(
9
+ (pluginsObject, plugin) => Object.assign(pluginsObject, { [plugin.name]: plugin }),
10
+ {} as Record<string, Plugin>,
11
+ );
12
+
13
+ export class InstallCommand extends Command {
14
+
15
+ protected static command: string = 'install';
16
+ protected static description: string = 'Install an AerogelJS plugin';
17
+ protected static parameters: [string, string][] = [['plugin', 'Plugin to install']];
18
+
19
+ private plugin: Plugin;
20
+
21
+ constructor(plugin: string) {
22
+ super();
23
+
24
+ this.plugin =
25
+ plugins[plugin] ??
26
+ Log.fail(`Plugin '${plugin}' doesn't exist. Available plugins: ${Object.keys(plugins).join(', ')}`);
27
+ }
28
+
29
+ protected async run(): Promise<void> {
30
+ await this.plugin.install();
31
+ }
32
+
33
+ }