@aerogel/cli 0.0.0-next.b58141fee5d2fe7d25debdbca6b1d2bf1c13e48e → 0.0.0-next.bf95405357e75d2e8b0268a5e8ce7b2b7dd0c895

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 (81) hide show
  1. package/bin/gel +4 -0
  2. package/dist/aerogel-cli.d.ts +2 -2
  3. package/dist/aerogel-cli.js +833 -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 +3 -4
  9. package/src/commands/create.ts +11 -11
  10. package/src/commands/generate-component.test.ts +50 -3
  11. package/src/commands/generate-component.ts +68 -22
  12. package/src/commands/generate-model.test.ts +2 -2
  13. package/src/commands/generate-model.ts +13 -14
  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 +16 -17
  17. package/src/commands/info.ts +15 -0
  18. package/src/commands/install.test.ts +11 -2
  19. package/src/commands/install.ts +9 -9
  20. package/src/lib/App.ts +9 -6
  21. package/src/lib/Editor.ts +12 -11
  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 +16 -8
  33. package/src/plugins/Plugin.ts +46 -12
  34. package/src/plugins/Solid.ts +15 -58
  35. package/src/plugins/Soukai.ts +4 -4
  36. package/src/testing/setup.ts +30 -31
  37. package/templates/app/.github/workflows/ci.yml +4 -4
  38. package/templates/app/.nvmrc +1 -1
  39. package/templates/app/.vscode/launch.json +1 -0
  40. package/templates/app/{cypress.config.ts → cypress/cypress.config.ts} +2 -4
  41. package/templates/app/cypress/support/e2e.ts +1 -3
  42. package/templates/app/cypress/tsconfig.json +7 -8
  43. package/templates/app/index.html +5 -4
  44. package/templates/app/package.json +27 -15
  45. package/templates/app/src/App.vue +2 -2
  46. package/templates/app/src/assets/css/main.css +4 -0
  47. package/templates/app/src/assets/public/robots.txt +2 -0
  48. package/templates/app/src/main.ts +4 -4
  49. package/templates/app/tsconfig.json +3 -10
  50. package/templates/app/vite.config.ts +7 -4
  51. package/templates/component-button/[component.name].vue +42 -0
  52. package/templates/component-button-story/[component.name].story.vue +77 -0
  53. package/templates/component-checkbox/[component.name].vue +34 -0
  54. package/templates/component-checkbox-story/[component.name].story.vue +63 -0
  55. package/templates/component-input/[component.name].vue +17 -0
  56. package/templates/component-input-story/[component.name].story.vue +63 -0
  57. package/templates/overrides/components/index.ts +15 -0
  58. package/templates/overrides/components/overrides/AlertModal.vue +11 -0
  59. package/templates/overrides/components/overrides/ConfirmModal.vue +20 -0
  60. package/templates/overrides/components/overrides/ErrorReportModal.vue +35 -0
  61. package/templates/overrides/components/overrides/LoadingModal.vue +12 -0
  62. package/templates/overrides/components/overrides/ModalWrapper.vue +22 -0
  63. package/templates/overrides/components/overrides/SnackbarNotification.vue +34 -0
  64. package/templates/overrides-story/Overrides.story.vue +86 -0
  65. package/templates/service/[service.name].ts +1 -1
  66. package/.eslintrc.js +0 -7
  67. package/bin/ag +0 -4
  68. package/dist/aerogel-cli.cjs.js +0 -2
  69. package/dist/aerogel-cli.cjs.js.map +0 -1
  70. package/dist/aerogel-cli.esm.js +0 -2
  71. package/dist/aerogel-cli.esm.js.map +0 -1
  72. package/src/lib/utils/format.test.ts +0 -33
  73. package/src/lib/utils/format.ts +0 -38
  74. package/templates/app/.eslintrc.js +0 -3
  75. package/templates/app/postcss.config.js +0 -6
  76. package/templates/app/prettier.config.js +0 -5
  77. package/templates/app/src/assets/styles.css +0 -3
  78. package/templates/app/tailwind.config.js +0 -5
  79. package/tsconfig.json +0 -11
  80. package/vite.config.ts +0 -14
  81. /package/src/{main.ts → index.ts} +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 { templatePath } 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,22 +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(templatePath('component'), `src/components/${directoryName}`, {
78
- component: { name: componentName },
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
+ },
79
115
  });
80
116
 
81
117
  componentFiles.forEach((file) => files.add(file));
82
118
  });
83
119
  }
84
120
 
85
- protected async createStory(componentName: string, files: Set<string>): Promise<void> {
121
+ protected async createStory(directoryName: string, componentName: string, files: Set<string>): Promise<void> {
86
122
  if (!this.options.story) {
87
123
  return;
88
124
  }
89
125
 
90
126
  await Log.animate('Creating story', async () => {
91
- const storyFiles = Template.instantiate(templatePath('component-story'), 'src/components', {
92
- 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
+ },
93
139
  });
94
140
 
95
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 { templatePath } 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`)) {
@@ -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 { templatePath } 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>();
@@ -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,12 +1,12 @@
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
 
@@ -15,4 +15,13 @@ describe('Install plugin command', () => {
15
15
  ShellMock.expectRan('npm install @aerogel/plugin-solid@next --save-exact');
16
16
  });
17
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
+
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 { packNotFound, packagePackPath, packagePath, templatePath } 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,7 +22,10 @@ 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))) {
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
 
@@ -16,7 +16,6 @@ export class Editor {
16
16
  this.modifiedFiles = new Set();
17
17
 
18
18
  this.project.addSourceFilesAtPaths('src/**/*.ts');
19
- this.project.addSourceFilesAtPaths('tailwind.config.js');
20
19
  this.project.addSourceFilesAtPaths('vite.config.ts');
21
20
  this.project.addSourceFilesAtPaths('package.json');
22
21
  }
@@ -31,15 +30,17 @@ export class Editor {
31
30
 
32
31
  public async format(): Promise<void> {
33
32
  await Log.animate('Formatting modified files', async () => {
34
- const usingPrettier = File.exists('prettier.config.js');
35
- const usingESLint = File.exists('.eslintrc.js');
36
-
37
- await Promise.all(
38
- arrayFrom(this.modifiedFiles).map(async (file) => {
33
+ const usingPrettier = File.exists('prettier.config.js') || File.contains('package.json', '"prettier": {');
34
+ const usingESLint = File.exists('.eslintrc.js') || File.contains('package.json', '"eslintConfig"');
35
+ const usingPrettierESLint = File.contains('package.json', '"prettier-eslint-cli"');
36
+ const formatFile = usingPrettierESLint
37
+ ? (file: string) => Shell.run(`npx prettier-eslint ${file} --write`)
38
+ : async (file: string) => {
39
39
  usingPrettier && (await Shell.run(`npx prettier ${file} --write`));
40
40
  file.match(/\.(ts|js|vue)$/) && usingESLint && (await Shell.run(`npx eslint ${file} --fix`));
41
- }),
42
- );
41
+ };
42
+
43
+ await Promise.all(arrayFrom(this.modifiedFiles).map(async (file) => formatFile(file)));
43
44
  });
44
45
  }
45
46
 
@@ -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);
@@ -15,23 +15,19 @@ export class LogServiceMock extends LogService {
15
15
  expect(this.logs, `Expected log to have length ${count}`).toHaveLength(count);
16
16
  }
17
17
 
18
- protected logLine(message: string): void {
18
+ protected override logLine(message: string): void {
19
19
  this.logs.push(message);
20
20
  }
21
21
 
22
22
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
- public fail<T = any>(message: string): T {
23
+ public override fail<T = any>(message: string): T {
24
24
  throw new Error(`Fail: ${message}`);
25
25
  }
26
26
 
27
- public reset(): void {
28
- this.logs = [];
29
- }
30
-
31
- protected stdout(): void {
27
+ protected override stdout(): void {
32
28
  //
33
29
  }
34
30
 
35
31
  }
36
32
 
37
- export default facade(new LogServiceMock());
33
+ export default facade(LogServiceMock);
@@ -1,11 +1,11 @@
1
- import { bold, hex } from 'chalk';
1
+ import chalk from 'chalk';
2
2
  import { describe, it } from 'vitest';
3
3
 
4
- import LogMock from '@/lib/Log.mock';
4
+ import LogMock from '@aerogel/cli/lib/Log.mock';
5
5
 
6
6
  import Log from './Log';
7
7
 
8
- const info = hex('#00ffff');
8
+ const info = chalk.hex('#00ffff');
9
9
 
10
10
  describe('Log', () => {
11
11
 
@@ -14,7 +14,7 @@ describe('Log', () => {
14
14
  Log.info('Foo **bar**');
15
15
 
16
16
  // Assert
17
- LogMock.expectLogged(info(`Foo ${bold('bar')}`));
17
+ LogMock.expectLogged(info(`Foo ${chalk.bold('bar')}`));
18
18
  });
19
19
 
20
20
  it('renders multiline messages', () => {