@aerogel/cli 0.0.0-next.59bf5f7cc06e728d0cf6c00de28f1da48d7d6b8e → 0.0.0-next.60462e474474f4e52d52d457f9150df63c117214

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 (75) hide show
  1. package/bin/gel +4 -0
  2. package/dist/aerogel-cli.d.ts +2 -2
  3. package/dist/aerogel-cli.js +793 -0
  4. package/dist/aerogel-cli.js.map +1 -0
  5. package/package.json +27 -33
  6. package/src/cli.ts +28 -6
  7. package/src/commands/Command.ts +14 -9
  8. package/src/commands/create.test.ts +14 -6
  9. package/src/commands/create.ts +25 -14
  10. package/src/commands/generate-component.test.ts +51 -4
  11. package/src/commands/generate-component.ts +167 -26
  12. package/src/commands/generate-model.test.ts +3 -3
  13. package/src/commands/generate-model.ts +24 -27
  14. package/src/commands/generate-service.test.ts +21 -0
  15. package/src/commands/generate-service.ts +151 -0
  16. package/src/commands/info.ts +15 -0
  17. package/src/commands/install.test.ts +27 -0
  18. package/src/commands/install.ts +32 -0
  19. package/src/lib/App.ts +67 -9
  20. package/src/lib/Editor.ts +57 -0
  21. package/src/lib/File.mock.ts +7 -11
  22. package/src/lib/File.ts +9 -3
  23. package/src/lib/Log.mock.ts +5 -8
  24. package/src/lib/Log.test.ts +4 -4
  25. package/src/lib/Log.ts +13 -11
  26. package/src/lib/Shell.mock.ts +3 -3
  27. package/src/lib/Shell.ts +2 -2
  28. package/src/lib/Template.ts +24 -17
  29. package/src/lib/utils/app.ts +15 -0
  30. package/src/lib/utils/edit.ts +44 -0
  31. package/src/lib/utils/paths.ts +42 -0
  32. package/src/plugins/Plugin.ts +159 -0
  33. package/src/plugins/Solid.ts +71 -0
  34. package/src/plugins/Soukai.ts +19 -0
  35. package/src/testing/setup.ts +56 -27
  36. package/templates/app/.github/workflows/ci.yml +16 -4
  37. package/templates/app/.nvmrc +1 -1
  38. package/templates/app/.vscode/launch.json +17 -0
  39. package/templates/app/.vscode/settings.json +10 -0
  40. package/templates/app/README.md +3 -0
  41. package/templates/app/cypress/cypress.config.ts +14 -0
  42. package/templates/app/cypress/support/e2e.ts +1 -3
  43. package/templates/app/cypress/tsconfig.json +7 -8
  44. package/templates/app/index.html +5 -4
  45. package/templates/app/package.json +42 -19
  46. package/templates/app/src/App.vue +6 -4
  47. package/templates/app/src/assets/css/main.css +4 -0
  48. package/templates/app/src/assets/public/robots.txt +2 -0
  49. package/templates/app/src/main.ts +4 -4
  50. package/templates/app/src/types/globals.d.ts +0 -1
  51. package/templates/app/tsconfig.json +3 -9
  52. package/templates/app/vite.config.ts +15 -8
  53. package/templates/component-button/[component.name].vue +42 -0
  54. package/templates/component-button-story/[component.name].story.vue +77 -0
  55. package/templates/component-checkbox/[component.name].vue +34 -0
  56. package/templates/component-checkbox-story/[component.name].story.vue +63 -0
  57. package/templates/component-input/[component.name].vue +17 -0
  58. package/templates/component-input-story/[component.name].story.vue +63 -0
  59. package/templates/service/[service.name].ts +8 -0
  60. package/.eslintrc.js +0 -7
  61. package/bin/ag +0 -4
  62. package/dist/aerogel-cli.cjs.js +0 -2
  63. package/dist/aerogel-cli.cjs.js.map +0 -1
  64. package/dist/aerogel-cli.esm.js +0 -2
  65. package/dist/aerogel-cli.esm.js.map +0 -1
  66. package/noeldemartin.config.js +0 -4
  67. package/src/lib/utils.test.ts +0 -33
  68. package/src/lib/utils.ts +0 -44
  69. package/templates/app/cypress.config.ts +0 -8
  70. package/templates/app/postcss.config.js +0 -6
  71. package/templates/app/src/assets/styles.css +0 -3
  72. package/templates/app/tailwind.config.js +0 -5
  73. package/tsconfig.json +0 -11
  74. package/vite.config.ts +0 -14
  75. /package/src/{main.ts → index.ts} +0 -0
@@ -1,23 +1,44 @@
1
- import Command from '@/commands/Command';
2
- import File from '@/lib/File';
3
- import Log from '@/lib/Log';
4
- import Template from '@/lib/Template';
5
- import { basePath } from '@/lib/utils';
6
- import type { CommandOptions } from '@/commands/Command';
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
+
5
+ import Command from '@aerogel/cli/commands/Command';
6
+ import File from '@aerogel/cli/lib/File';
7
+ import Log from '@aerogel/cli/lib/Log';
8
+ import Template from '@aerogel/cli/lib/Template';
9
+ import { app } from '@aerogel/cli/lib/utils/app';
10
+ import { editFiles, findDescendant } from '@aerogel/cli/lib/utils/edit';
11
+ import { templatePath } from '@aerogel/cli/lib/utils/paths';
12
+ import type { CommandOptions } from '@aerogel/cli/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 override command: string = 'generate:component';
24
+ protected static override description: string = 'Generate an AerogelJS Component';
25
+ protected static override 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 override 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 override 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 override 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;
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);
66
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
- import FileMock from '@/lib/File.mock';
4
- import { formatCodeBlock } from '@/lib/utils';
4
+ import FileMock from '@aerogel/cli/lib/File.mock';
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,11 +1,11 @@
1
- import { stringToStudlyCase } from '@noeldemartin/utils';
1
+ import { formatCodeBlock, stringToStudlyCase } from '@noeldemartin/utils';
2
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 { basePath, formatCodeBlock } from '@/lib/utils';
8
- import type { CommandOptions } from '@/commands/Command';
3
+ import Command from '@aerogel/cli/commands/Command';
4
+ import File from '@aerogel/cli/lib/File';
5
+ import Log from '@aerogel/cli/lib/Log';
6
+ import Template from '@aerogel/cli/lib/Template';
7
+ import { templatePath } from '@aerogel/cli/lib/utils/paths';
8
+ import type { CommandOptions } from '@aerogel/cli/commands/Command';
9
9
 
10
10
  interface Options {
11
11
  fields?: string;
@@ -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 override command: string = 'generate:model';
17
+ protected static override description: string = 'Generate an AerogelJS Model';
18
+ protected static override parameters: [string, string][] = [['name', 'Model name']];
19
+ protected static override 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 override 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,21 @@
1
+ import { describe, it } from 'vitest';
2
+
3
+ import FileMock from '@aerogel/cli/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 '@aerogel/cli/commands/Command';
6
+ import File from '@aerogel/cli/lib/File';
7
+ import Log from '@aerogel/cli/lib/Log';
8
+ import Template from '@aerogel/cli/lib/Template';
9
+ import { app } from '@aerogel/cli/lib/utils/app';
10
+ import { templatePath } from '@aerogel/cli/lib/utils/paths';
11
+ import { editFiles, findDescendant } from '@aerogel/cli/lib/utils/edit';
12
+ import type { Editor } from '@aerogel/cli/lib/Editor';
13
+
14
+ export class GenerateServiceCommand extends Command {
15
+
16
+ protected static override command: string = 'generate:service';
17
+ protected static override description: string = 'Generate an AerogelJS Service';
18
+ protected static override 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 override 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 '@aerogel/core' {
99
+ interface Services 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,15 @@
1
+ import { URL, fileURLToPath } from 'node:url';
2
+
3
+ import Command from '@aerogel/cli/commands/Command';
4
+ import Log from '@aerogel/cli/lib/Log';
5
+ export class InfoCommand extends Command {
6
+
7
+ protected static override command: string = 'info';
8
+ protected static override description: string = 'Show debugging information about the CLI';
9
+
10
+ protected override async run(): Promise<void> {
11
+ Log.info('[AerogelJS CLI info]');
12
+ Log.info('Installation directory: ' + fileURLToPath(new URL(/* @vite-ignore */ './', import.meta.url)));
13
+ }
14
+
15
+ }
@@ -0,0 +1,27 @@
1
+ import { describe, it } from 'vitest';
2
+
3
+ import ShellMock from '@aerogel/cli/lib/Shell.mock';
4
+
5
+ import { InstallCommand } from './install';
6
+
7
+ describe('Install plugin command', () => {
8
+
9
+ it('installs solid', async () => {
10
+ // Act
11
+ await InstallCommand.run('solid');
12
+
13
+ // Assert
14
+ ShellMock.expectRan('npm install soukai-solid@next --save-exact');
15
+ ShellMock.expectRan('npm install @aerogel/plugin-solid@next --save-exact');
16
+ });
17
+
18
+ it('installs soukai', async () => {
19
+ // Act
20
+ await InstallCommand.run('soukai');
21
+
22
+ // Assert
23
+ ShellMock.expectRan('npm install soukai@next --save-exact');
24
+ ShellMock.expectRan('npm install @aerogel/plugin-soukai@next --save-exact');
25
+ });
26
+
27
+ });
@@ -0,0 +1,32 @@
1
+ import Command from '@aerogel/cli/commands/Command';
2
+ import Log from '@aerogel/cli/lib/Log';
3
+ import { Solid } from '@aerogel/cli/plugins/Solid';
4
+ import { Soukai } from '@aerogel/cli/plugins/Soukai';
5
+ import type Plugin from '@aerogel/cli/plugins/Plugin';
6
+
7
+ const plugins = [new Soukai(), new Solid()].reduce(
8
+ (pluginsObject, plugin) => Object.assign(pluginsObject, { [plugin.name]: plugin }),
9
+ {} as Record<string, Plugin>,
10
+ );
11
+
12
+ export class InstallCommand extends Command {
13
+
14
+ protected static override command: string = 'install';
15
+ protected static override description: string = 'Install an AerogelJS plugin';
16
+ protected static override parameters: [string, string][] = [['plugin', 'Plugin to install']];
17
+
18
+ private plugin: Plugin;
19
+
20
+ constructor(plugin: string) {
21
+ super();
22
+
23
+ this.plugin =
24
+ plugins[plugin] ??
25
+ Log.fail(`Plugin '${plugin}' doesn't exist. Available plugins: ${Object.keys(plugins).join(', ')}`);
26
+ }
27
+
28
+ protected override async run(): Promise<void> {
29
+ await this.plugin.install();
30
+ }
31
+
32
+ }