@aerogel/cli 0.0.0-next.7e89f52eb37d9154f4879a5ccd058d27d476dada → 0.0.0-next.7f369b50c025aaa1a8024b6e53c659a6d7d617b5

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 (76) hide show
  1. package/bin/gel +4 -0
  2. package/dist/aerogel-cli.d.ts +2 -2
  3. package/dist/aerogel-cli.js +754 -0
  4. package/dist/aerogel-cli.js.map +1 -0
  5. package/package.json +26 -32
  6. package/src/cli.ts +26 -8
  7. package/src/commands/Command.ts +14 -9
  8. package/src/commands/create.test.ts +3 -17
  9. package/src/commands/create.ts +19 -20
  10. package/src/commands/generate-component.test.ts +1 -14
  11. package/src/commands/generate-component.ts +20 -50
  12. package/src/commands/generate-model.test.ts +2 -2
  13. package/src/commands/generate-model.ts +13 -14
  14. package/src/commands/generate-service.test.ts +2 -2
  15. package/src/commands/generate-service.ts +16 -17
  16. package/src/commands/info.ts +15 -0
  17. package/src/commands/install.test.ts +21 -4
  18. package/src/commands/install.ts +12 -11
  19. package/src/lib/App.ts +45 -49
  20. package/src/lib/Editor.ts +19 -13
  21. package/src/lib/File.mock.ts +7 -11
  22. package/src/lib/File.ts +14 -3
  23. package/src/lib/Log.mock.ts +4 -8
  24. package/src/lib/Log.test.ts +4 -4
  25. package/src/lib/Log.ts +7 -7
  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 +3 -3
  30. package/src/lib/utils/edit.ts +2 -2
  31. package/src/lib/utils/paths.ts +16 -8
  32. package/src/plugins/LocalFirst.ts +9 -0
  33. package/src/plugins/Plugin.ts +49 -14
  34. package/src/plugins/Solid.ts +48 -42
  35. package/src/plugins/Soukai.ts +6 -6
  36. package/src/testing/setup.ts +36 -31
  37. package/templates/app/README.md +3 -0
  38. package/templates/service/[service.name].ts +1 -1
  39. package/.eslintrc.js +0 -7
  40. package/bin/ag +0 -4
  41. package/dist/aerogel-cli.cjs.js +0 -2
  42. package/dist/aerogel-cli.cjs.js.map +0 -1
  43. package/dist/aerogel-cli.esm.js +0 -2
  44. package/dist/aerogel-cli.esm.js.map +0 -1
  45. package/noeldemartin.config.js +0 -14
  46. package/src/lib/utils/format.test.ts +0 -33
  47. package/src/lib/utils/format.ts +0 -38
  48. package/templates/app/.eslintrc.js +0 -3
  49. package/templates/app/.github/workflows/ci.yml +0 -17
  50. package/templates/app/.gitignore.template +0 -2
  51. package/templates/app/.nvmrc +0 -1
  52. package/templates/app/.vscode/launch.json +0 -16
  53. package/templates/app/.vscode/settings.json +0 -10
  54. package/templates/app/cypress/e2e/app.cy.ts +0 -9
  55. package/templates/app/cypress/support/e2e.ts +0 -3
  56. package/templates/app/cypress/tsconfig.json +0 -12
  57. package/templates/app/cypress.config.ts +0 -12
  58. package/templates/app/index.html +0 -12
  59. package/templates/app/package.json +0 -54
  60. package/templates/app/postcss.config.js +0 -6
  61. package/templates/app/prettier.config.js +0 -5
  62. package/templates/app/src/App.vue +0 -12
  63. package/templates/app/src/assets/styles.css +0 -3
  64. package/templates/app/src/lang/en.yaml +0 -3
  65. package/templates/app/src/main.test.ts +0 -9
  66. package/templates/app/src/main.ts +0 -13
  67. package/templates/app/src/types/globals.d.ts +0 -2
  68. package/templates/app/src/types/shims.d.ts +0 -7
  69. package/templates/app/src/types/ts-reset.d.ts +0 -1
  70. package/templates/app/tailwind.config.js +0 -5
  71. package/templates/app/tsconfig.json +0 -18
  72. package/templates/app/vite.config.ts +0 -23
  73. package/templates/component-story/[component.name].story.vue +0 -7
  74. package/tsconfig.json +0 -11
  75. package/vite.config.ts +0 -14
  76. /package/src/{main.ts → index.ts} +0 -0
@@ -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
  }
@@ -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,18 +1,35 @@
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');
25
+ });
26
+
27
+ it('installs local-first', async () => {
28
+ // Act
29
+ await InstallCommand.run('local-first');
30
+
31
+ // Assert
32
+ ShellMock.expectRan('npm install @aerogel/plugin-local-first@next --save-exact');
16
33
  });
17
34
 
18
35
  });
@@ -1,19 +1,20 @@
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';
6
-
7
- const plugins = [new Soukai(), new Solid()].reduce(
1
+ import Command from '@aerogel/cli/commands/Command';
2
+ import LocalFirst from '@aerogel/cli/plugins/LocalFirst';
3
+ import Log from '@aerogel/cli/lib/Log';
4
+ import Solid from '@aerogel/cli/plugins/Solid';
5
+ import Soukai from '@aerogel/cli/plugins/Soukai';
6
+ import type Plugin from '@aerogel/cli/plugins/Plugin';
7
+
8
+ const plugins = [new Soukai(), new Solid(), new LocalFirst()].reduce(
8
9
  (pluginsObject, plugin) => Object.assign(pluginsObject, { [plugin.name]: plugin }),
9
10
  {} as Record<string, Plugin>,
10
11
  );
11
12
 
12
13
  export class InstallCommand extends Command {
13
14
 
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']];
15
+ protected static override command: string = 'install';
16
+ protected static override description: string = 'Install an AerogelJS plugin';
17
+ protected static override parameters: [string, string][] = [['plugin', 'Plugin to install']];
17
18
 
18
19
  private plugin: Plugin;
19
20
 
@@ -25,7 +26,7 @@ export class InstallCommand extends Command {
25
26
  Log.fail(`Plugin '${plugin}' doesn't exist. Available plugins: ${Object.keys(plugins).join(', ')}`);
26
27
  }
27
28
 
28
- public async run(): Promise<void> {
29
+ protected override async run(): Promise<void> {
29
30
  await this.plugin.install();
30
31
  }
31
32
 
package/src/lib/App.ts CHANGED
@@ -1,19 +1,11 @@
1
- import { stringToSlug } from '@noeldemartin/utils';
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';
8
-
9
- interface Dependencies {
10
- aerogelCli: string;
11
- aerogelCore: string;
12
- aerogelCypress: string;
13
- aerogelPluginI18n: string;
14
- aerogelPluginSoukai: string;
15
- aerogelVite: string;
16
- }
1
+ import { resolve } from 'node:path';
2
+
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
+ import { simpleGit } from 'simple-git';
17
9
 
18
10
  export interface Options {
19
11
  local?: boolean;
@@ -22,30 +14,41 @@ export interface Options {
22
14
 
23
15
  export default class App {
24
16
 
25
- constructor(protected name: string, protected options: Options = {}) {}
17
+ constructor(
18
+ protected name: string,
19
+ protected options: Options = {},
20
+ ) {}
26
21
 
27
- public create(path: string): void {
22
+ public async create(path: string): Promise<void> {
28
23
  if (File.exists(path) && (!File.isDirectory(path) || !File.isEmptyDirectory(path))) {
29
24
  Log.fail(`Folder at '${path}' already exists!`);
30
25
  }
31
26
 
32
- Template.instantiate(templatePath('app'), path, {
33
- app: {
34
- name: this.name,
35
- slug: stringToSlug(this.name),
36
- },
37
- dependencies: this.getDependencies(),
38
- contentPath: this.options.linkedLocal
39
- ? `${packagePath('core')}/dist/**/*.js`
40
- : './node_modules/@aerogel/core/dist/**/*.js',
41
- });
27
+ // Clone repository
28
+ await simpleGit().clone('https://github.com/NoelDeMartin/aerogel-template.git', path);
29
+
30
+ // Apply replacements
31
+ const dependencies = this.getDependencies();
32
+
33
+ File.replace(
34
+ resolve(path, 'vite.config.ts'),
35
+ 'Aerogel({ name: \'Aerogel\' })',
36
+ `Aerogel({ name: '${this.name}' })`,
37
+ );
38
+
39
+ for (const [name, version] of Object.entries(dependencies)) {
40
+ File.replace(resolve(path, 'package.json'), new RegExp(`"${name}": ".*?"`, 'g'), `"${name}": "${version}"`);
41
+ }
42
+
43
+ // Copy template
44
+ Template.instantiate(templatePath('app'), path, { app: { name: this.name } });
42
45
  }
43
46
 
44
47
  public edit(): Editor {
45
48
  return new Editor();
46
49
  }
47
50
 
48
- protected getDependencies(): Dependencies {
51
+ protected getDependencies(): Record<string, string> {
49
52
  const withFilePrefix = <T extends Record<string, string>>(paths: T) =>
50
53
  Object.entries(paths).reduce(
51
54
  (pathsWithFile, [name, path]) => Object.assign(pathsWithFile, { [name]: `file:${path}` }) as T,
@@ -54,34 +57,27 @@ export default class App {
54
57
 
55
58
  if (this.options.linkedLocal) {
56
59
  return withFilePrefix({
57
- aerogelCli: packagePath('cli'),
58
- aerogelCore: packagePath('core'),
59
- aerogelCypress: packagePath('cypress'),
60
- aerogelPluginI18n: packagePath('plugin-i18n'),
61
- aerogelPluginSoukai: packagePath('plugin-soukai'),
62
- aerogelVite: packagePath('vite'),
60
+ '@aerogel/cli': packagePath('cli'),
61
+ '@aerogel/core': packagePath('core'),
62
+ '@aerogel/cypress': packagePath('cypress'),
63
+ '@aerogel/plugin-i18n': packagePath('plugin-i18n'),
64
+ '@aerogel/plugin-soukai': packagePath('plugin-soukai'),
65
+ '@aerogel/vite': packagePath('vite'),
63
66
  });
64
67
  }
65
68
 
66
69
  if (this.options.local) {
67
70
  return withFilePrefix({
68
- aerogelCli: packagePackPath('cli') ?? packNotFound('cli'),
69
- aerogelCore: packagePackPath('core') ?? packNotFound('core'),
70
- aerogelCypress: packagePackPath('cypress') ?? packNotFound('cypress'),
71
- aerogelPluginI18n: packagePackPath('plugin-i18n') ?? packNotFound('plugin-i18n'),
72
- aerogelPluginSoukai: packagePackPath('plugin-soukai') ?? packNotFound('plugin-soukai'),
73
- aerogelVite: packagePackPath('vite') ?? packNotFound('vite'),
71
+ '@aerogel/cli': packagePackPath('cli') ?? packNotFound('cli'),
72
+ '@aerogel/core': packagePackPath('core') ?? packNotFound('core'),
73
+ '@aerogel/cypress': packagePackPath('cypress') ?? packNotFound('cypress'),
74
+ '@aerogel/plugin-i18n': packagePackPath('plugin-i18n') ?? packNotFound('plugin-i18n'),
75
+ '@aerogel/plugin-soukai': packagePackPath('plugin-soukai') ?? packNotFound('plugin-soukai'),
76
+ '@aerogel/vite': packagePackPath('vite') ?? packNotFound('vite'),
74
77
  });
75
78
  }
76
79
 
77
- return {
78
- aerogelCli: 'next',
79
- aerogelCore: 'next',
80
- aerogelCypress: 'next',
81
- aerogelPluginI18n: 'next',
82
- aerogelPluginSoukai: 'next',
83
- aerogelVite: 'next',
84
- };
80
+ return {};
85
81
  }
86
82
 
87
83
  }
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,8 +16,8 @@ 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');
20
+ this.project.addSourceFilesAtPaths('package.json');
21
21
  }
22
22
 
23
23
  public addSourceFile(path: string): void {
@@ -30,22 +30,28 @@ export class Editor {
30
30
 
31
31
  public async format(): Promise<void> {
32
32
  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) => {
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) => {
38
39
  usingPrettier && (await Shell.run(`npx prettier ${file} --write`));
39
- usingESLint && (await Shell.run(`npx eslint ${file} --fix`));
40
- }),
41
- );
40
+ file.match(/\.(ts|js|vue)$/) && usingESLint && (await Shell.run(`npx eslint ${file} --fix`));
41
+ };
42
+
43
+ await Promise.all(arrayFrom(this.modifiedFiles).map(async (file) => formatFile(file)));
42
44
  });
43
45
  }
44
46
 
45
47
  public async save(file: SourceFile): Promise<void> {
46
48
  await file.save();
47
49
 
48
- this.modifiedFiles.add(file.getFilePath());
50
+ this.addModifiedFile(file.getFilePath());
51
+ }
52
+
53
+ public addModifiedFile(path: string): void {
54
+ this.modifiedFiles.add(path);
49
55
  }
50
56
 
51
57
  }
@@ -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,7 @@
1
- import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'fs';
1
+ import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
2
+ import { dirname, resolve } from 'node:path';
3
+
2
4
  import { facade } from '@noeldemartin/utils';
3
- import { dirname, resolve } from 'path';
4
5
 
5
6
  export class FileService {
6
7
 
@@ -26,6 +27,16 @@ export class FileService {
26
27
  return readFileSync(path).toString();
27
28
  }
28
29
 
30
+ public replace(path: string, search: string | RegExp, replacement: string): void {
31
+ const contents = this.read(path);
32
+
33
+ if (!contents) {
34
+ return;
35
+ }
36
+
37
+ this.write(path, contents.replaceAll(search, replacement));
38
+ }
39
+
29
40
  public getFiles(directoryPath: string): string[] {
30
41
  const children = readdirSync(directoryPath, { withFileTypes: true });
31
42
  const files: string[] = [];
@@ -73,4 +84,4 @@ export class FileService {
73
84
 
74
85
  }
75
86
 
76
- export default facade(new FileService());
87
+ 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', () => {
package/src/lib/Log.ts CHANGED
@@ -1,12 +1,12 @@
1
+ import chalk from 'chalk';
2
+ import { clearLine, cursorTo } from 'node:readline';
1
3
  import { facade, stringMatchAll } from '@noeldemartin/utils';
2
- import { bold, hex } from 'chalk';
3
- import { clearLine, cursorTo } from 'readline';
4
4
 
5
5
  export class LogService {
6
6
 
7
- protected renderInfo = hex('#00ffff');
8
- protected renderSuccess = hex('#00ff00');
9
- protected renderError = hex('#ff0000');
7
+ protected renderInfo = chalk.hex('#00ffff');
8
+ protected renderSuccess = chalk.hex('#00ff00');
9
+ protected renderError = chalk.hex('#ff0000');
10
10
 
11
11
  public async animate<T>(message: string, operation: () => Promise<T>): Promise<T> {
12
12
  const updateStdout = (end: string = '', done: boolean = false) => {
@@ -52,7 +52,7 @@ export class LogService {
52
52
  const matches = stringMatchAll<2>(message, /\*\*(.*)\*\*/g);
53
53
 
54
54
  for (const match of matches) {
55
- message = message.replace(match[0], bold(match[1]));
55
+ message = message.replace(match[0], chalk.bold(match[1]));
56
56
  }
57
57
 
58
58
  return message;
@@ -92,4 +92,4 @@ export class LogService {
92
92
 
93
93
  }
94
94
 
95
- export default facade(new LogService());
95
+ export default facade(LogService);
@@ -7,8 +7,8 @@ export class ShellServiceMock extends ShellService {
7
7
 
8
8
  private history: string[] = [];
9
9
 
10
- public async run(command: string): Promise<void> {
11
- this.history.push(command);
10
+ public override async run(command: string): Promise<void> {
11
+ this.history.push(command.trim());
12
12
  }
13
13
 
14
14
  public expectRan(command: string): void {
@@ -17,4 +17,4 @@ export class ShellServiceMock extends ShellService {
17
17
 
18
18
  }
19
19
 
20
- export default facade(new ShellServiceMock());
20
+ export default facade(ShellServiceMock);
package/src/lib/Shell.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { exec } from 'child_process';
1
+ import { exec } from 'node:child_process';
2
2
  import { facade } from '@noeldemartin/utils';
3
3
 
4
4
  export class ShellService {
@@ -25,4 +25,4 @@ export class ShellService {
25
25
 
26
26
  }
27
27
 
28
- export default facade(new ShellService());
28
+ export default facade(ShellService);