@aerogel/cli 0.0.0-next.0be1479064cfd43fb6eafa2552cb7f8775554d93 → 0.0.0-next.0d1cf82f9dfbe1d3e7ec5644f85f97a43c8c2334

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 (83) hide show
  1. package/bin/gel +4 -0
  2. package/dist/aerogel-cli.d.ts +2 -2
  3. package/dist/aerogel-cli.js +847 -0
  4. package/dist/aerogel-cli.js.map +1 -0
  5. package/package.json +25 -32
  6. package/src/cli.ts +28 -8
  7. package/src/commands/Command.ts +14 -9
  8. package/src/commands/create.test.ts +12 -3
  9. package/src/commands/create.ts +15 -12
  10. package/src/commands/generate-component.test.ts +50 -3
  11. package/src/commands/generate-component.ts +69 -25
  12. package/src/commands/generate-model.test.ts +2 -2
  13. package/src/commands/generate-model.ts +14 -15
  14. package/src/commands/generate-overrides.ts +85 -0
  15. package/src/commands/generate-service.test.ts +2 -2
  16. package/src/commands/generate-service.ts +17 -18
  17. package/src/commands/info.ts +15 -0
  18. package/src/commands/install.test.ts +13 -4
  19. package/src/commands/install.ts +9 -9
  20. package/src/lib/App.ts +10 -7
  21. package/src/lib/Editor.ts +19 -12
  22. package/src/lib/File.mock.ts +7 -11
  23. package/src/lib/File.ts +3 -3
  24. package/src/lib/Log.mock.ts +4 -8
  25. package/src/lib/Log.test.ts +4 -4
  26. package/src/lib/Log.ts +7 -7
  27. package/src/lib/Shell.mock.ts +3 -3
  28. package/src/lib/Shell.ts +2 -2
  29. package/src/lib/Template.ts +24 -17
  30. package/src/lib/utils/app.ts +3 -3
  31. package/src/lib/utils/edit.ts +2 -2
  32. package/src/lib/utils/paths.ts +19 -11
  33. package/src/plugins/Plugin.ts +65 -12
  34. package/src/plugins/Solid.ts +55 -41
  35. package/src/plugins/Soukai.ts +5 -5
  36. package/src/testing/setup.ts +35 -36
  37. package/templates/app/.github/workflows/ci.yml +16 -4
  38. package/templates/app/.nvmrc +1 -1
  39. package/templates/app/.vscode/launch.json +1 -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 +3 -2
  45. package/templates/app/package.json +24 -12
  46. package/templates/app/postcss.config.js +1 -1
  47. package/templates/app/src/App.vue +2 -2
  48. package/templates/app/src/assets/public/robots.txt +2 -0
  49. package/templates/app/src/main.ts +4 -4
  50. package/templates/app/tsconfig.json +3 -9
  51. package/templates/app/vite.config.ts +15 -7
  52. package/templates/component-button/[component.name].vue +42 -0
  53. package/templates/component-button-story/[component.name].story.vue +77 -0
  54. package/templates/component-checkbox/[component.name].vue +34 -0
  55. package/templates/component-checkbox-story/[component.name].story.vue +63 -0
  56. package/templates/component-input/[component.name].vue +17 -0
  57. package/templates/component-input-story/[component.name].story.vue +63 -0
  58. package/templates/overrides/components/index.ts +15 -0
  59. package/templates/overrides/components/overrides/AlertModal.vue +11 -0
  60. package/templates/overrides/components/overrides/ConfirmModal.vue +20 -0
  61. package/templates/overrides/components/overrides/ErrorReportModal.vue +35 -0
  62. package/templates/overrides/components/overrides/LoadingModal.vue +12 -0
  63. package/templates/overrides/components/overrides/ModalWrapper.vue +22 -0
  64. package/templates/overrides/components/overrides/SnackbarNotification.vue +34 -0
  65. package/templates/overrides-story/Overrides.story.vue +86 -0
  66. package/templates/postcss-pseudo-classes/postcss.config.js +15 -0
  67. package/templates/service/[service.name].ts +1 -1
  68. package/.eslintrc.js +0 -7
  69. package/bin/ag +0 -4
  70. package/dist/aerogel-cli.cjs.js +0 -2
  71. package/dist/aerogel-cli.cjs.js.map +0 -1
  72. package/dist/aerogel-cli.esm.js +0 -2
  73. package/dist/aerogel-cli.esm.js.map +0 -1
  74. package/noeldemartin.config.js +0 -14
  75. package/src/lib/utils/format.test.ts +0 -33
  76. package/src/lib/utils/format.ts +0 -38
  77. package/templates/app/.eslintrc.js +0 -3
  78. package/templates/app/cypress.config.ts +0 -12
  79. package/templates/app/prettier.config.js +0 -5
  80. package/tsconfig.json +0 -11
  81. package/vite.config.ts +0 -14
  82. /package/src/{main.ts → index.ts} +0 -0
  83. /package/templates/app/src/assets/{styles.css → css/main.css} +0 -0
@@ -1,29 +1,44 @@
1
- import { arrayFrom } from '@noeldemartin/utils';
1
+ import { arrayFilter, arrayFrom, stringToSlug } from '@noeldemartin/utils';
2
2
  import { Node, SyntaxKind } from 'ts-morph';
3
3
  import type { ArrayLiteralExpression, CallExpression, SourceFile } from 'ts-morph';
4
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 { editFiles, findDescendant } from '@/lib/utils/edit';
11
- import { basePath } from '@/lib/utils/paths';
12
- import type { CommandOptions } from '@/commands/Command';
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';
13
13
 
14
14
  export interface Options {
15
+ button?: boolean;
16
+ checkbox?: boolean;
17
+ input?: boolean;
15
18
  story?: boolean;
16
19
  }
17
20
 
18
21
  export class GenerateComponentCommand extends Command {
19
22
 
20
- public static command: string = 'generate:component';
21
- public static description: string = 'Generate an AerogelJS Component';
22
- 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][] = [
23
26
  ['path', 'Component path (relative to components folder; extension not necessary)'],
24
27
  ];
25
28
 
26
- 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
+ },
27
42
  story: {
28
43
  description: 'Create component story using Histoire',
29
44
  type: 'boolean',
@@ -40,7 +55,15 @@ export class GenerateComponentCommand extends Command {
40
55
  this.options = options;
41
56
  }
42
57
 
43
- public async run(): Promise<void> {
58
+ protected override async validate(): Promise<void> {
59
+ const components = arrayFilter([this.options.button, this.options.input, this.options.checkbox]).length;
60
+
61
+ if (components > 1) {
62
+ Log.fail('Can only use one of \'button\', \'input\', or \'checkbox\' flags!');
63
+ }
64
+ }
65
+
66
+ protected override async run(): Promise<void> {
44
67
  this.assertAerogelOrDirectory('src/components');
45
68
  this.assertHistoireInstalled();
46
69
 
@@ -48,7 +71,7 @@ export class GenerateComponentCommand extends Command {
48
71
  const [directoryName, componentName] = this.parsePathComponents();
49
72
 
50
73
  await this.createComponent(directoryName, componentName, files);
51
- await this.createStory(componentName, files);
74
+ await this.createStory(directoryName, componentName, files);
52
75
  await this.declareComponents();
53
76
 
54
77
  const filesList = arrayFrom(files)
@@ -63,8 +86,11 @@ export class GenerateComponentCommand extends Command {
63
86
  return;
64
87
  }
65
88
 
66
- if (!File.exists('src/main.histoire.ts')) {
67
- Log.fail('Histoire is not installed yet!');
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
+ `);
68
94
  }
69
95
  }
70
96
 
@@ -74,24 +100,42 @@ export class GenerateComponentCommand extends Command {
74
100
  Log.fail(`${this.path} component already exists!`);
75
101
  }
76
102
 
77
- const componentFiles = Template.instantiate(
78
- basePath('templates/component'),
79
- `src/components/${directoryName}`,
80
- { component: { name: componentName } },
81
- );
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
+ });
82
116
 
83
117
  componentFiles.forEach((file) => files.add(file));
84
118
  });
85
119
  }
86
120
 
87
- protected async createStory(componentName: string, files: Set<string>): Promise<void> {
121
+ protected async createStory(directoryName: string, componentName: string, files: Set<string>): Promise<void> {
88
122
  if (!this.options.story) {
89
123
  return;
90
124
  }
91
125
 
92
126
  await Log.animate('Creating story', async () => {
93
- const storyFiles = Template.instantiate(basePath('templates/component-story'), 'src/components', {
94
- component: { name: componentName },
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
+ },
95
139
  });
96
140
 
97
141
  storyFiles.forEach((file) => files.add(file));
@@ -1,7 +1,7 @@
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/format';
4
+ import FileMock from '@aerogel/cli/lib/File.mock';
5
5
 
6
6
  import { GenerateModelCommand } from './generate-model';
7
7
 
@@ -1,12 +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 } from '@/lib/utils/paths';
8
- import { formatCodeBlock } from '@/lib/utils/format';
9
- 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';
10
9
 
11
10
  interface Options {
12
11
  fields?: string;
@@ -14,10 +13,10 @@ interface Options {
14
13
 
15
14
  export class GenerateModelCommand extends Command {
16
15
 
17
- public static command: string = 'generate:model';
18
- public static description: string = 'Generate an AerogelJS Model';
19
- public static parameters: [string, string][] = [['name', 'Model name']];
20
- 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 = {
21
20
  fields: 'Create model with the given fields',
22
21
  };
23
22
 
@@ -31,7 +30,7 @@ export class GenerateModelCommand extends Command {
31
30
  this.options = options;
32
31
  }
33
32
 
34
- public async run(): Promise<void> {
33
+ protected override async run(): Promise<void> {
35
34
  this.assertAerogelOrDirectory('src/models');
36
35
 
37
36
  if (File.exists(`src/models/${this.name}.ts`)) {
@@ -41,7 +40,7 @@ export class GenerateModelCommand extends Command {
41
40
  this.assertSoukaiInstalled();
42
41
 
43
42
  const filesList = await Log.animate('Creating model', async () => {
44
- const files = Template.instantiate(basePath('templates/model'), 'src/models', {
43
+ const files = Template.instantiate(templatePath('model'), 'src/models', {
45
44
  model: {
46
45
  name: this.name,
47
46
  fieldsDefinition: this.getFieldsDefinition(),
@@ -91,7 +90,7 @@ export class GenerateModelCommand extends Command {
91
90
  if (!File.contains('package.json', '"soukai"') && !File.contains('package.json', '"@aerogel/plugin-soukai"')) {
92
91
  Log.fail(`
93
92
  Soukai is not installed yet! You can install it running:
94
- npx ag install soukai
93
+ npx gel install soukai
95
94
  `);
96
95
  }
97
96
  }
@@ -0,0 +1,85 @@
1
+ import { arrayFrom } from '@noeldemartin/utils';
2
+
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
+
10
+ export interface Options {
11
+ story?: boolean;
12
+ }
13
+
14
+ export class GenerateOverridesCommand extends Command {
15
+
16
+ protected static override command: string = 'generate:overrides';
17
+ protected static override description: string = 'Generate AerogelJS component overrides';
18
+
19
+ protected static override 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 override 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
+ }
@@ -1,6 +1,6 @@
1
1
  import { describe, it } from 'vitest';
2
2
 
3
- import FileMock from '@/lib/File.mock';
3
+ import FileMock from '@aerogel/cli/lib/File.mock';
4
4
 
5
5
  import { GenerateServiceCommand } from './generate-service';
6
6
 
@@ -15,7 +15,7 @@ describe('Generate Service command', () => {
15
15
 
16
16
  // Assert
17
17
  FileMock.expectCreated('src/services/FooBar.ts').toContain('class FooBarService extends Service');
18
- FileMock.expectCreated('src/services/FooBar.ts').toContain('export default facade(new FooBarService());');
18
+ FileMock.expectCreated('src/services/FooBar.ts').toContain('export default facade(FooBarService);');
19
19
  });
20
20
 
21
21
  });
@@ -1,22 +1,21 @@
1
- import { arrayFrom, stringToCamelCase } from '@noeldemartin/utils';
1
+ import { arrayFrom, formatCodeBlock, stringToCamelCase } from '@noeldemartin/utils';
2
2
  import { Node, SyntaxKind } from 'ts-morph';
3
3
  import type { ObjectLiteralExpression, SourceFile } from 'ts-morph';
4
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 { basePath } from '@/lib/utils/paths';
11
- import { editFiles, findDescendant } from '@/lib/utils/edit';
12
- import { formatCodeBlock } from '@/lib/utils/format';
13
- import type { Editor } from '@/lib/Editor';
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';
14
13
 
15
14
  export class GenerateServiceCommand extends Command {
16
15
 
17
- public static command: string = 'generate:service';
18
- public static description: string = 'Generate an AerogelJS Service';
19
- public static parameters: [string, string][] = [['name', 'Service name']];
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']];
20
19
 
21
20
  private name: string;
22
21
 
@@ -26,7 +25,7 @@ export class GenerateServiceCommand extends Command {
26
25
  this.name = name;
27
26
  }
28
27
 
29
- public async run(): Promise<void> {
28
+ protected override async run(): Promise<void> {
30
29
  this.assertAerogelOrDirectory('src/services');
31
30
 
32
31
  const files = new Set<string>();
@@ -52,7 +51,7 @@ export class GenerateServiceCommand extends Command {
52
51
  Log.fail(`${this.name} service already exists!`);
53
52
  }
54
53
 
55
- const serviceFiles = Template.instantiate(basePath('templates/service'), 'src/services', {
54
+ const serviceFiles = Template.instantiate(templatePath('service'), 'src/services', {
56
55
  service: {
57
56
  name: this.name,
58
57
  },
@@ -96,8 +95,8 @@ export class GenerateServiceCommand extends Command {
96
95
 
97
96
  export type AppServices = typeof services;
98
97
 
99
- declare module '@vue/runtime-core' {
100
- interface ComponentCustomProperties extends AppServices {}
98
+ declare module '@aerogel/core' {
99
+ interface Services extends AppServices {}
101
100
  }
102
101
  `),
103
102
  );
@@ -123,7 +122,7 @@ export class GenerateServiceCommand extends Command {
123
122
  protected getBootstrapOptions(mainConfig: SourceFile): ObjectLiteralExpression | null {
124
123
  const bootstrapAppCall = findDescendant(mainConfig, {
125
124
  guard: Node.isCallExpression,
126
- validate: (callExpression) => callExpression.getExpression().getText() === 'bootstrapApplication',
125
+ validate: (callExpression) => callExpression.getExpression().getText() === 'bootstrap',
127
126
  skip: SyntaxKind.ImportDeclaration,
128
127
  });
129
128
  const bootstrapOptions = bootstrapAppCall?.getArguments()[1];
@@ -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
+ }
@@ -1,18 +1,27 @@
1
1
  import { describe, it } from 'vitest';
2
2
 
3
- import ShellMock from '@/lib/Shell.mock';
3
+ import ShellMock from '@aerogel/cli/lib/Shell.mock';
4
4
 
5
5
  import { InstallCommand } from './install';
6
6
 
7
7
  describe('Install plugin command', () => {
8
8
 
9
- it('installs plugins', async () => {
9
+ it('installs solid', async () => {
10
10
  // Act
11
11
  await InstallCommand.run('solid');
12
12
 
13
13
  // Assert
14
- ShellMock.expectRan('npm install soukai-solid@next');
15
- ShellMock.expectRan('npm install @aerogel/plugin-solid@next');
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');
16
25
  });
17
26
 
18
27
  });
@@ -1,8 +1,8 @@
1
- import Command from '@/commands/Command';
2
- import Log from '@/lib/Log';
3
- import { Solid } from '@/plugins/Solid';
4
- import { Soukai } from '@/plugins/Soukai';
5
- import type Plugin from '@/plugins/Plugin';
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
6
 
7
7
  const plugins = [new Soukai(), new Solid()].reduce(
8
8
  (pluginsObject, plugin) => Object.assign(pluginsObject, { [plugin.name]: plugin }),
@@ -11,9 +11,9 @@ const plugins = [new Soukai(), new Solid()].reduce(
11
11
 
12
12
  export class InstallCommand extends Command {
13
13
 
14
- public static command: string = 'install';
15
- public static description: string = 'Install an AerogelJS plugin';
16
- public static parameters: [string, string][] = [['plugin', 'Plugin to install']];
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
17
 
18
18
  private plugin: Plugin;
19
19
 
@@ -25,7 +25,7 @@ export class InstallCommand extends Command {
25
25
  Log.fail(`Plugin '${plugin}' doesn't exist. Available plugins: ${Object.keys(plugins).join(', ')}`);
26
26
  }
27
27
 
28
- public async run(): Promise<void> {
28
+ protected override async run(): Promise<void> {
29
29
  await this.plugin.install();
30
30
  }
31
31
 
package/src/lib/App.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { stringToSlug } from '@noeldemartin/utils';
2
2
 
3
- import File from '@/lib/File';
4
- import Log from '@/lib/Log';
5
- import Template from '@/lib/Template';
6
- import { cliBasePath, packNotFound, packagePackPath, packagePath } from '@/lib/utils/paths';
7
- import { Editor } from '@/lib/Editor';
3
+ import File from '@aerogel/cli/lib/File';
4
+ import Log from '@aerogel/cli/lib/Log';
5
+ import Template from '@aerogel/cli/lib/Template';
6
+ import { packNotFound, packagePackPath, packagePath, templatePath } from '@aerogel/cli/lib/utils/paths';
7
+ import { Editor } from '@aerogel/cli/lib/Editor';
8
8
 
9
9
  interface Dependencies {
10
10
  aerogelCli: string;
@@ -22,14 +22,17 @@ export interface Options {
22
22
 
23
23
  export default class App {
24
24
 
25
- constructor(protected name: string, protected options: Options = {}) {}
25
+ constructor(
26
+ protected name: string,
27
+ protected options: Options = {},
28
+ ) {}
26
29
 
27
30
  public create(path: string): void {
28
31
  if (File.exists(path) && (!File.isDirectory(path) || !File.isEmptyDirectory(path))) {
29
32
  Log.fail(`Folder at '${path}' already exists!`);
30
33
  }
31
34
 
32
- Template.instantiate(cliBasePath('templates/app'), path, {
35
+ Template.instantiate(templatePath('app'), path, {
33
36
  app: {
34
37
  name: this.name,
35
38
  slug: stringToSlug(this.name),
package/src/lib/Editor.ts CHANGED
@@ -2,9 +2,9 @@ import { arrayFrom } from '@noeldemartin/utils';
2
2
  import { Project } from 'ts-morph';
3
3
  import type { SourceFile } from 'ts-morph';
4
4
 
5
- import File from '@/lib/File';
6
- import Log from '@/lib/Log';
7
- import Shell from '@/lib/Shell';
5
+ import File from '@aerogel/cli/lib/File';
6
+ import Log from '@aerogel/cli/lib/Log';
7
+ import Shell from '@aerogel/cli/lib/Shell';
8
8
 
9
9
  export class Editor {
10
10
 
@@ -18,6 +18,7 @@ export class Editor {
18
18
  this.project.addSourceFilesAtPaths('src/**/*.ts');
19
19
  this.project.addSourceFilesAtPaths('tailwind.config.js');
20
20
  this.project.addSourceFilesAtPaths('vite.config.ts');
21
+ this.project.addSourceFilesAtPaths('package.json');
21
22
  }
22
23
 
23
24
  public addSourceFile(path: string): void {
@@ -30,22 +31,28 @@ export class Editor {
30
31
 
31
32
  public async format(): Promise<void> {
32
33
  await Log.animate('Formatting modified files', async () => {
33
- const usingPrettier = File.exists('prettier.config.js');
34
- const usingESLint = File.exists('.eslintrc.js');
35
-
36
- await Promise.all(
37
- arrayFrom(this.modifiedFiles).map(async (file) => {
34
+ const usingPrettier = File.exists('prettier.config.js') || File.contains('package.json', '"prettier": {');
35
+ const usingESLint = File.exists('.eslintrc.js') || File.contains('package.json', '"eslintConfig"');
36
+ const usingPrettierESLint = File.contains('package.json', '"prettier-eslint-cli"');
37
+ const formatFile = usingPrettierESLint
38
+ ? (file: string) => Shell.run(`npx prettier-eslint ${file} --write`)
39
+ : async (file: string) => {
38
40
  usingPrettier && (await Shell.run(`npx prettier ${file} --write`));
39
- usingESLint && (await Shell.run(`npx eslint ${file} --fix`));
40
- }),
41
- );
41
+ file.match(/\.(ts|js|vue)$/) && usingESLint && (await Shell.run(`npx eslint ${file} --fix`));
42
+ };
43
+
44
+ await Promise.all(arrayFrom(this.modifiedFiles).map(async (file) => formatFile(file)));
42
45
  });
43
46
  }
44
47
 
45
48
  public async save(file: SourceFile): Promise<void> {
46
49
  await file.save();
47
50
 
48
- this.modifiedFiles.add(file.getFilePath());
51
+ this.addModifiedFile(file.getFilePath());
52
+ }
53
+
54
+ public addModifiedFile(path: string): void {
55
+ this.modifiedFiles.add(path);
49
56
  }
50
57
 
51
58
  }
@@ -8,28 +8,28 @@ export class FileMockService extends FileService {
8
8
 
9
9
  private virtualFilesystem: Record<string, string | { directory: true }> = {};
10
10
 
11
- public exists(path: string): boolean {
11
+ public override exists(path: string): boolean {
12
12
  return super.exists(path) || path in this.virtualFilesystem;
13
13
  }
14
14
 
15
- public isDirectory(path: string): boolean {
15
+ public override isDirectory(path: string): boolean {
16
16
  return (
17
17
  super.isDirectory(path) ||
18
18
  (path in this.virtualFilesystem && typeof this.virtualFilesystem[path] === 'object')
19
19
  );
20
20
  }
21
21
 
22
- public isFile(path: string): boolean {
22
+ public override isFile(path: string): boolean {
23
23
  return (
24
24
  super.isFile(path) || (path in this.virtualFilesystem && typeof this.virtualFilesystem[path] === 'string')
25
25
  );
26
26
  }
27
27
 
28
- public makeDirectory(path: string): void {
28
+ public override makeDirectory(path: string): void {
29
29
  this.virtualFilesystem[path] = { directory: true };
30
30
  }
31
31
 
32
- public read(path: string): string | null {
32
+ public override read(path: string): string | null {
33
33
  if (path in this.virtualFilesystem && typeof this.virtualFilesystem[path] === 'string') {
34
34
  return this.virtualFilesystem[path] as string;
35
35
  }
@@ -37,14 +37,10 @@ export class FileMockService extends FileService {
37
37
  return super.read(path);
38
38
  }
39
39
 
40
- public write(path: string, contents: string): void {
40
+ public override write(path: string, contents: string): void {
41
41
  this.virtualFilesystem[path] = contents;
42
42
  }
43
43
 
44
- public reset(): void {
45
- this.virtualFilesystem = {};
46
- }
47
-
48
44
  public expectCreated(path: string, expectContent?: (contents: string) => void): Assertion<string> {
49
45
  expect(typeof this.virtualFilesystem[path] === 'string', `expected '${path}' file to have been created`).toBe(
50
46
  true,
@@ -63,4 +59,4 @@ export class FileMockService extends FileService {
63
59
 
64
60
  }
65
61
 
66
- export default facade(new FileMockService());
62
+ export default facade(FileMockService);
package/src/lib/File.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'fs';
1
+ import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
2
2
  import { facade } from '@noeldemartin/utils';
3
- import { dirname, resolve } from 'path';
3
+ import { dirname, resolve } from 'node:path';
4
4
 
5
5
  export class FileService {
6
6
 
@@ -73,4 +73,4 @@ export class FileService {
73
73
 
74
74
  }
75
75
 
76
- export default facade(new FileService());
76
+ export default facade(FileService);