@aerogel/cli 0.0.0-next.926bde19326fe7b6b24b277666936862b64d8295 → 0.0.0-next.a5b6ecb68fdca29d00c8b8906d00aa5bf64a9d7c

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