@aerogel/cli 0.0.0-next.13b88f634a31caf3669d61e53e7d3fa95e20488c → 0.0.0-next.1cf8c4f815a37b577f7a1c1e2538b0d08f4e585c

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 (90) hide show
  1. package/bin/gel +1 -1
  2. package/dist/aerogel-cli.d.ts +1 -1
  3. package/dist/aerogel-cli.js +790 -0
  4. package/dist/aerogel-cli.js.map +1 -0
  5. package/package.json +21 -33
  6. package/src/cli.ts +9 -11
  7. package/src/commands/Command.ts +3 -3
  8. package/src/commands/create.test.ts +2 -25
  9. package/src/commands/create.ts +15 -19
  10. package/src/commands/generate-component.test.ts +1 -61
  11. package/src/commands/generate-component.ts +14 -90
  12. package/src/commands/generate-model.test.ts +1 -1
  13. package/src/commands/generate-model.ts +11 -11
  14. package/src/commands/generate-service.test.ts +1 -1
  15. package/src/commands/generate-service.ts +14 -14
  16. package/src/commands/info.ts +7 -6
  17. package/src/commands/install.test.ts +63 -14
  18. package/src/commands/install.ts +29 -15
  19. package/src/lib/App.ts +50 -48
  20. package/src/lib/Editor.ts +3 -4
  21. package/src/lib/File.mock.ts +12 -6
  22. package/src/lib/File.ts +32 -2
  23. package/src/lib/Log.mock.ts +3 -3
  24. package/src/lib/Log.test.ts +4 -4
  25. package/src/lib/Log.ts +6 -6
  26. package/src/lib/Shell.mock.ts +5 -1
  27. package/src/lib/Shell.ts +1 -1
  28. package/src/lib/Template.ts +19 -16
  29. package/src/lib/utils/app.ts +2 -2
  30. package/src/lib/utils/edit.ts +2 -2
  31. package/src/lib/utils/paths.ts +19 -7
  32. package/src/plugins/LocalFirst.ts +9 -0
  33. package/src/plugins/Plugin.ts +37 -39
  34. package/src/plugins/Solid.ts +15 -22
  35. package/src/plugins/Soukai.ts +8 -7
  36. package/src/testing/setup.ts +34 -26
  37. package/src/utils/package.ts +23 -0
  38. package/.prettierignore +0 -1
  39. package/dist/aerogel-cli.cjs.js +0 -2
  40. package/dist/aerogel-cli.cjs.js.map +0 -1
  41. package/dist/aerogel-cli.esm.js +0 -2
  42. package/dist/aerogel-cli.esm.js.map +0 -1
  43. package/src/commands/generate-overrides.ts +0 -85
  44. package/src/plugins/Histoire.ts +0 -113
  45. package/templates/app/.github/workflows/ci.yml +0 -29
  46. package/templates/app/.gitignore.template +0 -2
  47. package/templates/app/.nvmrc +0 -1
  48. package/templates/app/.vscode/launch.json +0 -16
  49. package/templates/app/.vscode/settings.json +0 -10
  50. package/templates/app/cypress/cypress.config.ts +0 -14
  51. package/templates/app/cypress/e2e/app.cy.ts +0 -9
  52. package/templates/app/cypress/support/e2e.ts +0 -1
  53. package/templates/app/cypress/tsconfig.json +0 -14
  54. package/templates/app/index.html +0 -13
  55. package/templates/app/package.json +0 -67
  56. package/templates/app/postcss.config.js +0 -6
  57. package/templates/app/src/App.vue +0 -12
  58. package/templates/app/src/assets/css/styles.css +0 -3
  59. package/templates/app/src/assets/public/robots.txt +0 -2
  60. package/templates/app/src/lang/en.yaml +0 -3
  61. package/templates/app/src/main.test.ts +0 -9
  62. package/templates/app/src/main.ts +0 -13
  63. package/templates/app/src/types/globals.d.ts +0 -2
  64. package/templates/app/src/types/shims.d.ts +0 -7
  65. package/templates/app/src/types/ts-reset.d.ts +0 -1
  66. package/templates/app/tailwind.config.js +0 -5
  67. package/templates/app/tsconfig.json +0 -19
  68. package/templates/app/vite.config.ts +0 -30
  69. package/templates/component-button/[component.name].vue +0 -42
  70. package/templates/component-button-story/[component.name].story.vue +0 -77
  71. package/templates/component-checkbox/[component.name].vue +0 -34
  72. package/templates/component-checkbox-story/[component.name].story.vue +0 -63
  73. package/templates/component-input/[component.name].vue +0 -17
  74. package/templates/component-input-story/[component.name].story.vue +0 -63
  75. package/templates/component-story/[component.name].story.vue +0 -7
  76. package/templates/histoire/histoire.config.ts +0 -7
  77. package/templates/histoire/patches/histoire+0.17.6.patch +0 -13
  78. package/templates/histoire/src/main.histoire.ts +0 -8
  79. package/templates/overrides/components/index.ts +0 -15
  80. package/templates/overrides/components/overrides/AlertModal.vue +0 -11
  81. package/templates/overrides/components/overrides/ConfirmModal.vue +0 -20
  82. package/templates/overrides/components/overrides/ErrorReportModal.vue +0 -35
  83. package/templates/overrides/components/overrides/LoadingModal.vue +0 -12
  84. package/templates/overrides/components/overrides/ModalWrapper.vue +0 -22
  85. package/templates/overrides/components/overrides/SnackbarNotification.vue +0 -34
  86. package/templates/overrides-story/Overrides.story.vue +0 -86
  87. package/templates/postcss-pseudo-classes/postcss.config.js +0 -15
  88. package/tsconfig.json +0 -11
  89. package/vite.config.ts +0 -14
  90. /package/src/{main.ts → index.ts} +0 -0
@@ -1,15 +1,14 @@
1
- import { arrayFilter, arrayFrom, stringToSlug } from '@noeldemartin/utils';
1
+ import { 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';
13
12
 
14
13
  export interface Options {
15
14
  button?: boolean;
@@ -20,58 +19,27 @@ export interface Options {
20
19
 
21
20
  export class GenerateComponentCommand extends Command {
22
21
 
23
- protected static command: string = 'generate:component';
24
- protected static description: string = 'Generate an AerogelJS Component';
25
- protected static parameters: [string, string][] = [
22
+ protected static override command: string = 'generate:component';
23
+ protected static override description: string = 'Generate an AerogelJS Component';
24
+ protected static override parameters: [string, string][] = [
26
25
  ['path', 'Component path (relative to components folder; extension not necessary)'],
27
26
  ];
28
27
 
29
- protected static 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
- },
42
- story: {
43
- description: 'Create component story using Histoire',
44
- type: 'boolean',
45
- },
46
- };
47
-
48
28
  private path: string;
49
- private options: Options;
50
29
 
51
- constructor(path: string, options: Options = {}) {
30
+ constructor(path: string) {
52
31
  super();
53
32
 
54
33
  this.path = path;
55
- this.options = options;
56
- }
57
-
58
- protected 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
34
  }
65
35
 
66
- protected async run(): Promise<void> {
36
+ protected override async run(): Promise<void> {
67
37
  this.assertAerogelOrDirectory('src/components');
68
- this.assertHistoireInstalled();
69
38
 
70
39
  const files = new Set<string>();
71
40
  const [directoryName, componentName] = this.parsePathComponents();
72
41
 
73
42
  await this.createComponent(directoryName, componentName, files);
74
- await this.createStory(directoryName, componentName, files);
75
43
  await this.declareComponents();
76
44
 
77
45
  const filesList = arrayFrom(files)
@@ -81,33 +49,13 @@ export class GenerateComponentCommand extends Command {
81
49
  Log.info(`${componentName} component created successfully! The following files were created:\n\n${filesList}`);
82
50
  }
83
51
 
84
- protected assertHistoireInstalled(): void {
85
- if (!this.options.story) {
86
- return;
87
- }
88
-
89
- if (!File.contains('package.json', '"histoire"') && !File.contains('package.json', '"@aerogel/histoire"')) {
90
- Log.fail(`
91
- Histoire is not installed yet! You can install it running:
92
- npx gel install histoire
93
- `);
94
- }
95
- }
96
-
97
52
  protected async createComponent(directoryName: string, componentName: string, files: Set<string>): Promise<void> {
98
53
  await Log.animate('Creating component', async () => {
99
54
  if (File.exists(`src/components/${this.path}.vue`)) {
100
55
  Log.fail(`${this.path} component already exists!`);
101
56
  }
102
57
 
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}`, {
58
+ const componentFiles = Template.instantiate(templatePath('component'), `src/components/${directoryName}`, {
111
59
  component: {
112
60
  name: componentName,
113
61
  slug: stringToSlug(componentName),
@@ -118,30 +66,6 @@ export class GenerateComponentCommand extends Command {
118
66
  });
119
67
  }
120
68
 
121
- protected async createStory(directoryName: string, componentName: string, files: Set<string>): Promise<void> {
122
- if (!this.options.story) {
123
- return;
124
- }
125
-
126
- await Log.animate('Creating story', async () => {
127
- const templateName = this.options.input
128
- ? 'component-input-story'
129
- : this.options.button
130
- ? 'component-button-story'
131
- : this.options.checkbox
132
- ? 'component-checkbox-story'
133
- : 'component-story';
134
- const storyFiles = Template.instantiate(templatePath(templateName), `src/components/${directoryName}`, {
135
- component: {
136
- name: componentName,
137
- slug: stringToSlug(componentName),
138
- },
139
- });
140
-
141
- storyFiles.forEach((file) => files.add(file));
142
- });
143
- }
144
-
145
69
  protected async declareComponents(): Promise<void> {
146
70
  if (!editFiles()) {
147
71
  return;
@@ -1,7 +1,7 @@
1
1
  import { describe, it } from 'vitest';
2
2
  import { formatCodeBlock } from '@noeldemartin/utils';
3
3
 
4
- import FileMock from '@/lib/File.mock';
4
+ import FileMock from '@aerogel/cli/lib/File.mock';
5
5
 
6
6
  import { GenerateModelCommand } from './generate-model';
7
7
 
@@ -1,11 +1,11 @@
1
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 type { CommandOptions } from '@/commands/Command';
3
+ import Command from '@aerogel/cli/commands/Command';
4
+ import File from '@aerogel/cli/lib/File';
5
+ import Log from '@aerogel/cli/lib/Log';
6
+ import Template from '@aerogel/cli/lib/Template';
7
+ import { templatePath } from '@aerogel/cli/lib/utils/paths';
8
+ import type { CommandOptions } from '@aerogel/cli/commands/Command';
9
9
 
10
10
  interface Options {
11
11
  fields?: string;
@@ -13,10 +13,10 @@ interface Options {
13
13
 
14
14
  export class GenerateModelCommand extends Command {
15
15
 
16
- 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 = {
16
+ protected static override command: string = 'generate:model';
17
+ protected static override description: string = 'Generate an AerogelJS Model';
18
+ protected static override parameters: [string, string][] = [['name', 'Model name']];
19
+ protected static override options: CommandOptions = {
20
20
  fields: 'Create model with the given fields',
21
21
  };
22
22
 
@@ -30,7 +30,7 @@ export class GenerateModelCommand extends Command {
30
30
  this.options = options;
31
31
  }
32
32
 
33
- protected async run(): Promise<void> {
33
+ protected override async run(): Promise<void> {
34
34
  this.assertAerogelOrDirectory('src/models');
35
35
 
36
36
  if (File.exists(`src/models/${this.name}.ts`)) {
@@ -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
 
@@ -2,20 +2,20 @@ import { arrayFrom, formatCodeBlock, stringToCamelCase } from '@noeldemartin/uti
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 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';
13
13
 
14
14
  export class GenerateServiceCommand extends Command {
15
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']];
16
+ protected static override command: string = 'generate:service';
17
+ protected static override description: string = 'Generate an AerogelJS Service';
18
+ protected static override parameters: [string, string][] = [['name', 'Service name']];
19
19
 
20
20
  private name: string;
21
21
 
@@ -25,7 +25,7 @@ export class GenerateServiceCommand extends Command {
25
25
  this.name = name;
26
26
  }
27
27
 
28
- protected async run(): Promise<void> {
28
+ protected override async run(): Promise<void> {
29
29
  this.assertAerogelOrDirectory('src/services');
30
30
 
31
31
  const files = new Set<string>();
@@ -95,8 +95,8 @@ export class GenerateServiceCommand extends Command {
95
95
 
96
96
  export type AppServices = typeof services;
97
97
 
98
- declare module '@vue/runtime-core' {
99
- interface ComponentCustomProperties extends AppServices {}
98
+ declare module '@aerogel/core' {
99
+ interface Services extends AppServices {}
100
100
  }
101
101
  `),
102
102
  );
@@ -1,14 +1,15 @@
1
- import Command from '@/commands/Command';
2
- import Log from '@/lib/Log';
1
+ import { URL, fileURLToPath } from 'node:url';
3
2
 
3
+ import Command from '@aerogel/cli/commands/Command';
4
+ import Log from '@aerogel/cli/lib/Log';
4
5
  export class InfoCommand extends Command {
5
6
 
6
- protected static command: string = 'info';
7
- protected static description: string = 'Show debugging information about the CLI';
7
+ protected static override command: string = 'info';
8
+ protected static override description: string = 'Show debugging information about the CLI';
8
9
 
9
- protected async run(): Promise<void> {
10
+ protected override async run(): Promise<void> {
10
11
  Log.info('[AerogelJS CLI info]');
11
- Log.info('Installation directory: ' + __dirname);
12
+ Log.info('Installation directory: ' + fileURLToPath(new URL(/* @vite-ignore */ './', import.meta.url)));
12
13
  }
13
14
 
14
15
  }
@@ -1,41 +1,90 @@
1
- import { describe, it } from 'vitest';
1
+ import { describe, expect, it } from 'vitest';
2
2
 
3
- import FileMock from '@/lib/File.mock';
4
- import ShellMock from '@/lib/Shell.mock';
3
+ import ShellMock from '@aerogel/cli/lib/Shell.mock';
4
+ import FileMock from '@aerogel/cli/lib/File.mock';
5
5
 
6
6
  import { InstallCommand } from './install';
7
7
 
8
8
  describe('Install plugin command', () => {
9
9
 
10
10
  it('installs solid', async () => {
11
+ // Arrange
12
+ stubPackageJson();
13
+
11
14
  // Act
12
15
  await InstallCommand.run('solid');
13
16
 
14
17
  // Assert
15
- ShellMock.expectRan('npm install soukai-solid@next --save-exact');
16
- ShellMock.expectRan('npm install @aerogel/plugin-solid@next --save-exact');
18
+ ShellMock.expectRan('pnpm install --no-save');
19
+
20
+ expectPackageJson({
21
+ dependencies: {
22
+ '@aerogel/core': 'next',
23
+ '@aerogel/plugin-solid': 'next',
24
+ '@noeldemartin/solid-utils': 'next',
25
+ 'soukai-solid': 'next',
26
+ 'vue': '^3.5.13',
27
+ },
28
+ });
17
29
  });
18
30
 
19
31
  it('installs soukai', async () => {
32
+ // Arrange
33
+ stubPackageJson();
34
+
20
35
  // Act
21
- await InstallCommand.run('soukai');
36
+ await InstallCommand.run('soukai', { skipInstall: true });
22
37
 
23
38
  // Assert
24
- ShellMock.expectRan('npm install soukai@next --save-exact');
25
- ShellMock.expectRan('npm install @aerogel/plugin-soukai@next --save-exact');
39
+ ShellMock.expectNotRan('pnpm install --no-save');
40
+
41
+ expectPackageJson({
42
+ dependencies: {
43
+ '@aerogel/core': 'next',
44
+ '@aerogel/plugin-soukai': 'next',
45
+ 'soukai': 'next',
46
+ 'vue': '^3.5.13',
47
+ },
48
+ });
26
49
  });
27
50
 
28
- it('installs histoire', async () => {
51
+ it('installs local-first', async () => {
29
52
  // Arrange
30
- FileMock.stub('package.json', '"@aerogel/core"');
53
+ stubPackageJson();
31
54
 
32
55
  // Act
33
- await InstallCommand.run('histoire');
56
+ await InstallCommand.run('local-first');
34
57
 
35
58
  // Assert
36
- ShellMock.expectRan('npm install histoire@0.17.6 --save-dev');
37
- ShellMock.expectRan('npm install @aerogel/histoire@next --save-exact --save-dev');
38
- ShellMock.expectRan('npm install patch-package --save-dev');
59
+ ShellMock.expectRan('pnpm install --no-save');
60
+
61
+ expectPackageJson({
62
+ dependencies: {
63
+ '@aerogel/core': 'next',
64
+ '@aerogel/plugin-local-first': 'next',
65
+ 'vue': '^3.5.13',
66
+ },
67
+ });
39
68
  });
40
69
 
41
70
  });
71
+
72
+ function stubPackageJson(): void {
73
+ FileMock.stub(
74
+ 'package.json',
75
+ JSON.stringify(
76
+ {
77
+ dependencies: {
78
+ '@aerogel/core': 'next',
79
+ 'vue': '^3.5.13',
80
+ },
81
+ },
82
+ null,
83
+ 2,
84
+ ),
85
+ );
86
+ }
87
+
88
+ function expectPackageJson(packageJson: object): void {
89
+ expect(JSON.parse(FileMock.read('package.json') ?? '{}')).toEqual(packageJson);
90
+ }
@@ -1,33 +1,47 @@
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(
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
+ import type { CommandOptions } from '@aerogel/cli/commands/Command';
8
+
9
+ const plugins = [new Soukai(), new Solid(), new LocalFirst()].reduce(
9
10
  (pluginsObject, plugin) => Object.assign(pluginsObject, { [plugin.name]: plugin }),
10
11
  {} as Record<string, Plugin>,
11
12
  );
13
+ export interface Options {
14
+ skipInstall?: boolean;
15
+ }
12
16
 
13
17
  export class InstallCommand extends Command {
14
18
 
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
+ protected static override command: string = 'install';
20
+ protected static override description: string = 'Install an AerogelJS plugin';
21
+ protected static override parameters: [string, string][] = [['plugin', 'Plugin to install']];
22
+ protected static override options: CommandOptions = {
23
+ skipInstall: {
24
+ type: 'boolean',
25
+ description: 'Skip installing dependencies, just add them to package.json',
26
+ },
27
+ };
28
+
29
+ private options: Options;
19
30
  private plugin: Plugin;
20
31
 
21
- constructor(plugin: string) {
32
+ constructor(plugin: string, options: Options = {}) {
22
33
  super();
23
34
 
35
+ this.options = options;
24
36
  this.plugin =
25
37
  plugins[plugin] ??
26
38
  Log.fail(`Plugin '${plugin}' doesn't exist. Available plugins: ${Object.keys(plugins).join(', ')}`);
27
39
  }
28
40
 
29
- protected async run(): Promise<void> {
30
- await this.plugin.install();
41
+ protected override async run(): Promise<void> {
42
+ await this.plugin.install({
43
+ skipInstall: this.options.skipInstall,
44
+ });
31
45
  }
32
46
 
33
47
  }
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,47 @@ 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',
27
+ // Clone repository
28
+ await simpleGit().clone('https://github.com/NoelDeMartin/aerogel-template.git', path, {
29
+ '--depth': 1,
41
30
  });
31
+
32
+ File.delete(resolve(path, '.git'));
33
+
34
+ // Apply replacements
35
+ const dependencies = this.getDependencies();
36
+
37
+ File.replace(
38
+ resolve(path, 'vite.config.ts'),
39
+ 'Aerogel({ name: \'Aerogel\' })',
40
+ `Aerogel({ name: '${this.name}' })`,
41
+ );
42
+
43
+ File.replace(resolve(path, 'src/lang/en.yaml'), 'title: \'App\'', `title: '${this.name}'`);
44
+
45
+ for (const [name, version] of Object.entries(dependencies)) {
46
+ File.replace(resolve(path, 'package.json'), new RegExp(`"${name}": ".*?"`, 'g'), `"${name}": "${version}"`);
47
+ }
48
+
49
+ // Copy template
50
+ Template.instantiate(templatePath('app'), path, { app: { name: this.name } });
42
51
  }
43
52
 
44
53
  public edit(): Editor {
45
54
  return new Editor();
46
55
  }
47
56
 
48
- protected getDependencies(): Dependencies {
57
+ protected getDependencies(): Record<string, string> {
49
58
  const withFilePrefix = <T extends Record<string, string>>(paths: T) =>
50
59
  Object.entries(paths).reduce(
51
60
  (pathsWithFile, [name, path]) => Object.assign(pathsWithFile, { [name]: `file:${path}` }) as T,
@@ -54,34 +63,27 @@ export default class App {
54
63
 
55
64
  if (this.options.linkedLocal) {
56
65
  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'),
66
+ '@aerogel/cli': packagePath('cli'),
67
+ '@aerogel/core': packagePath('core'),
68
+ '@aerogel/cypress': packagePath('cypress'),
69
+ '@aerogel/plugin-i18n': packagePath('plugin-i18n'),
70
+ '@aerogel/plugin-soukai': packagePath('plugin-soukai'),
71
+ '@aerogel/vite': packagePath('vite'),
63
72
  });
64
73
  }
65
74
 
66
75
  if (this.options.local) {
67
76
  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'),
77
+ '@aerogel/cli': packagePackPath('cli') ?? packNotFound('cli'),
78
+ '@aerogel/core': packagePackPath('core') ?? packNotFound('core'),
79
+ '@aerogel/cypress': packagePackPath('cypress') ?? packNotFound('cypress'),
80
+ '@aerogel/plugin-i18n': packagePackPath('plugin-i18n') ?? packNotFound('plugin-i18n'),
81
+ '@aerogel/plugin-soukai': packagePackPath('plugin-soukai') ?? packNotFound('plugin-soukai'),
82
+ '@aerogel/vite': packagePackPath('vite') ?? packNotFound('vite'),
74
83
  });
75
84
  }
76
85
 
77
- return {
78
- aerogelCli: 'next',
79
- aerogelCore: 'next',
80
- aerogelCypress: 'next',
81
- aerogelPluginI18n: 'next',
82
- aerogelPluginSoukai: 'next',
83
- aerogelVite: 'next',
84
- };
86
+ return {};
85
87
  }
86
88
 
87
89
  }
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
  }
@@ -8,28 +8,34 @@ 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 delete(path: string): void {
12
+ if (path in this.virtualFilesystem) {
13
+ delete this.virtualFilesystem[path];
14
+ }
15
+ }
16
+
17
+ public override exists(path: string): boolean {
12
18
  return super.exists(path) || path in this.virtualFilesystem;
13
19
  }
14
20
 
15
- public isDirectory(path: string): boolean {
21
+ public override isDirectory(path: string): boolean {
16
22
  return (
17
23
  super.isDirectory(path) ||
18
24
  (path in this.virtualFilesystem && typeof this.virtualFilesystem[path] === 'object')
19
25
  );
20
26
  }
21
27
 
22
- public isFile(path: string): boolean {
28
+ public override isFile(path: string): boolean {
23
29
  return (
24
30
  super.isFile(path) || (path in this.virtualFilesystem && typeof this.virtualFilesystem[path] === 'string')
25
31
  );
26
32
  }
27
33
 
28
- public makeDirectory(path: string): void {
34
+ public override makeDirectory(path: string): void {
29
35
  this.virtualFilesystem[path] = { directory: true };
30
36
  }
31
37
 
32
- public read(path: string): string | null {
38
+ public override read(path: string): string | null {
33
39
  if (path in this.virtualFilesystem && typeof this.virtualFilesystem[path] === 'string') {
34
40
  return this.virtualFilesystem[path] as string;
35
41
  }
@@ -37,7 +43,7 @@ export class FileMockService extends FileService {
37
43
  return super.read(path);
38
44
  }
39
45
 
40
- public write(path: string, contents: string): void {
46
+ public override write(path: string, contents: string): void {
41
47
  this.virtualFilesystem[path] = contents;
42
48
  }
43
49