@aerogel/cli 0.0.0-next.a56c0f4966eb71571173f8502f3f36d357ceebc7 → 0.0.0-next.a5b6ecb68fdca29d00c8b8906d00aa5bf64a9d7c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/aerogel-cli.cjs.js +1 -1
  2. package/dist/aerogel-cli.cjs.js.map +1 -1
  3. package/dist/aerogel-cli.esm.js +1 -1
  4. package/dist/aerogel-cli.esm.js.map +1 -1
  5. package/package.json +2 -2
  6. package/src/commands/Command.ts +15 -7
  7. package/src/commands/create.test.ts +12 -4
  8. package/src/commands/create.ts +5 -5
  9. package/src/commands/generate-component.test.ts +59 -6
  10. package/src/commands/generate-component.ts +49 -14
  11. package/src/commands/generate-model.test.ts +10 -2
  12. package/src/commands/generate-model.ts +5 -5
  13. package/src/commands/generate-service.test.ts +10 -2
  14. package/src/commands/generate-service.ts +4 -4
  15. package/src/commands/install.test.ts +34 -3
  16. package/src/commands/install.ts +6 -5
  17. package/src/lib/Editor.ts +7 -5
  18. package/src/lib/Shell.mock.ts +1 -1
  19. package/src/lib/Template.ts +5 -1
  20. package/src/lib/utils/app.ts +1 -1
  21. package/src/lib/utils/paths.ts +1 -1
  22. package/src/plugins/Histoire.ts +105 -0
  23. package/src/plugins/Plugin.ts +57 -4
  24. package/src/plugins/Solid.ts +6 -42
  25. package/src/testing/stubs/ProgramStub.ts +35 -0
  26. package/src/testing/utils.ts +14 -0
  27. package/templates/component-button/[component.name].vue +32 -0
  28. package/templates/component-button-story/[component.name].story.vue +71 -0
  29. package/templates/component-input/[component.name].vue +16 -0
  30. package/templates/component-input-story/[component.name].story.vue +63 -0
  31. package/templates/histoire/histoire.config.ts +7 -0
  32. package/templates/histoire/patches/histoire+0.17.6.patch +13 -0
  33. package/templates/histoire/src/main.histoire.ts +8 -0
  34. package/templates/postcss-pseudo-classes/postcss.config.js +15 -0
  35. /package/bin/{ag → gel} +0 -0
@@ -20,6 +20,7 @@ export default abstract class Plugin {
20
20
  public async install(): Promise<void> {
21
21
  this.assertNotInstalled();
22
22
 
23
+ await this.beforeInstall();
23
24
  await this.installDependencies();
24
25
 
25
26
  if (editFiles()) {
@@ -29,6 +30,8 @@ export default abstract class Plugin {
29
30
  await editor.format();
30
31
  }
31
32
 
33
+ await this.afterInstall();
34
+
32
35
  Log.info(`Plugin ${this.name} installed!`);
33
36
  }
34
37
 
@@ -38,6 +41,14 @@ export default abstract class Plugin {
38
41
  }
39
42
  }
40
43
 
44
+ protected async beforeInstall(): Promise<void> {
45
+ // Placeholder for overrides, don't place any functionality here.
46
+ }
47
+
48
+ protected async afterInstall(): Promise<void> {
49
+ // Placeholder for overrides, don't place any functionality here.
50
+ }
51
+
41
52
  protected async installDependencies(): Promise<void> {
42
53
  await Log.animate('Installing plugin dependencies', async () => {
43
54
  await this.installNpmDependencies();
@@ -45,12 +56,16 @@ export default abstract class Plugin {
45
56
  }
46
57
 
47
58
  protected async updateFiles(editor: Editor): Promise<void> {
48
- await this.updateBootstrapConfig(editor);
59
+ if (!this.isForDevelopment()) {
60
+ await this.updateBootstrapConfig(editor);
61
+ }
49
62
  }
50
63
 
51
64
  protected async installNpmDependencies(): Promise<void> {
65
+ const flags = this.isForDevelopment() ? '--save-dev' : '';
66
+
52
67
  if (isLinkedLocalApp()) {
53
- await Shell.run(`npm install file:${packagePath(this.getLocalPackageName())}`);
68
+ await Shell.run(`npm install file:${packagePath(this.getLocalPackageName())} ${flags}`);
54
69
 
55
70
  return;
56
71
  }
@@ -58,12 +73,12 @@ export default abstract class Plugin {
58
73
  if (isLocalApp()) {
59
74
  const packPath = packagePackPath(this.getLocalPackageName()) ?? packNotFound(this.getLocalPackageName());
60
75
 
61
- await Shell.run(`npm install file:${packPath}`);
76
+ await Shell.run(`npm install file:${packPath} ${flags}`);
62
77
 
63
78
  return;
64
79
  }
65
80
 
66
- await Shell.run(`npm install ${this.getNpmPackageName()}@next --save-exact`);
81
+ await Shell.run(`npm install ${this.getNpmPackageName()}@next --save-exact ${flags}`);
67
82
  }
68
83
 
69
84
  protected async updateBootstrapConfig(editor: Editor): Promise<void> {
@@ -86,6 +101,25 @@ export default abstract class Plugin {
86
101
  });
87
102
  }
88
103
 
104
+ protected async updateTailwindConfig(editor: Editor, options: { content: string }): Promise<void> {
105
+ await Log.animate('Updating tailwind configuration', async () => {
106
+ const tailwindConfig = editor.requireSourceFile('tailwind.config.js');
107
+ const contentArray = this.getTailwindContentArray(tailwindConfig);
108
+
109
+ if (!contentArray) {
110
+ return Log.fail(`
111
+ Could not find content array in tailwind config, please add the following manually:
112
+
113
+ ${options.content}
114
+ `);
115
+ }
116
+
117
+ contentArray.addElement(options.content);
118
+
119
+ await editor.save(tailwindConfig);
120
+ });
121
+ }
122
+
89
123
  protected getBootstrapPluginsDeclaration(mainConfig: SourceFile): ArrayLiteralExpression | null {
90
124
  const bootstrapAppCall = findDescendant(mainConfig, {
91
125
  guard: Node.isCallExpression,
@@ -103,6 +137,21 @@ export default abstract class Plugin {
103
137
  return pluginsArray;
104
138
  }
105
139
 
140
+ protected getTailwindContentArray(tailwindConfig: SourceFile): ArrayLiteralExpression | null {
141
+ const contentAssignment = findDescendant(tailwindConfig, {
142
+ guard: Node.isPropertyAssignment,
143
+ validate: (propertyAssignment) => propertyAssignment.getName() === 'content',
144
+ skip: SyntaxKind.JSDoc,
145
+ });
146
+ const contentArray = contentAssignment?.getInitializer();
147
+
148
+ if (!Node.isArrayLiteralExpression(contentArray)) {
149
+ return null;
150
+ }
151
+
152
+ return contentArray;
153
+ }
154
+
106
155
  protected getBootstrapImport(): OptionalKind<ImportDeclarationStructure> {
107
156
  return {
108
157
  defaultImport: this.name,
@@ -118,6 +167,10 @@ export default abstract class Plugin {
118
167
  return `plugin-${this.name}`;
119
168
  }
120
169
 
170
+ protected isForDevelopment(): boolean {
171
+ return false;
172
+ }
173
+
121
174
  protected getBootstrapConfig(): string {
122
175
  return `${this.name}()`;
123
176
  }
@@ -1,11 +1,7 @@
1
- import { Node, SyntaxKind } from 'ts-morph';
2
- import type { ArrayLiteralExpression, SourceFile } from 'ts-morph';
3
-
4
1
  import File from '@/lib/File';
5
2
  import Log from '@/lib/Log';
6
3
  import Plugin from '@/plugins/Plugin';
7
4
  import Shell from '@/lib/Shell';
8
- import { findDescendant } from '@/lib/utils/edit';
9
5
  import { isLinkedLocalApp } from '@/lib/utils/app';
10
6
  import { packagePath } from '@/lib/utils/paths';
11
7
  import type { Editor } from '@/lib/Editor';
@@ -17,7 +13,12 @@ export class Solid extends Plugin {
17
13
  }
18
14
 
19
15
  protected async updateFiles(editor: Editor): Promise<void> {
20
- await this.updateTailwindConfig(editor);
16
+ await this.updateTailwindConfig(editor, {
17
+ content: isLinkedLocalApp()
18
+ ? `'${packagePath('plugin-solid')}/dist/**/*.js'`
19
+ : '\'./node_modules/@aerogel/plugin-solid/dist/**/*.js\'',
20
+ });
21
+
21
22
  await this.updateNpmScripts(editor);
22
23
  await this.updateGitIgnore();
23
24
  await super.updateFiles(editor);
@@ -29,28 +30,6 @@ export class Solid extends Plugin {
29
30
  await super.installNpmDependencies();
30
31
  }
31
32
 
32
- protected async updateTailwindConfig(editor: Editor): Promise<void> {
33
- await Log.animate('Updating tailwind configuration', async () => {
34
- const tailwindConfig = editor.requireSourceFile('tailwind.config.js');
35
- const contentArray = this.getTailwindContentArray(tailwindConfig);
36
- const contentValue = isLinkedLocalApp()
37
- ? `'${packagePath('plugin-solid')}/dist/**/*.js'`
38
- : '\'./node_modules/@aerogel/plugin-solid/dist/**/*.js\'';
39
-
40
- if (!contentArray) {
41
- return Log.fail(`
42
- Could not find content array in tailwind config, please add the following manually:
43
-
44
- ${contentValue}
45
- `);
46
- }
47
-
48
- contentArray.addElement(contentValue);
49
-
50
- await editor.save(tailwindConfig);
51
- });
52
- }
53
-
54
33
  protected async updateNpmScripts(editor: Editor): Promise<void> {
55
34
  Log.info('Updating npm scripts...');
56
35
 
@@ -96,19 +75,4 @@ export class Solid extends Plugin {
96
75
  File.write('.gitignore', `${gitignore}/solid-data\n`);
97
76
  }
98
77
 
99
- protected getTailwindContentArray(tailwindConfig: SourceFile): ArrayLiteralExpression | null {
100
- const contentAssignment = findDescendant(tailwindConfig, {
101
- guard: Node.isPropertyAssignment,
102
- validate: (propertyAssignment) => propertyAssignment.getName() === 'content',
103
- skip: SyntaxKind.JSDoc,
104
- });
105
- const contentArray = contentAssignment?.getInitializer();
106
-
107
- if (!Node.isArrayLiteralExpression(contentArray)) {
108
- return null;
109
- }
110
-
111
- return contentArray;
112
- }
113
-
114
78
  }
@@ -0,0 +1,35 @@
1
+ import type { Command as Program } from 'commander';
2
+ import type { Constructor } from '@noeldemartin/utils';
3
+
4
+ import type Command from '@/commands/Command';
5
+
6
+ export default class ProgramStub<T extends Constructor<Command> = Constructor<Command>> {
7
+
8
+ private runner?: (...args: ConstructorParameters<T>) => Promise<void>;
9
+
10
+ public async run(...args: ConstructorParameters<T>): Promise<void> {
11
+ await this.runner?.(...args);
12
+ }
13
+
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ public command(): any {
16
+ return { description: () => this };
17
+ }
18
+
19
+ public argument(): this {
20
+ return this;
21
+ }
22
+
23
+ public option(): this {
24
+ return this;
25
+ }
26
+
27
+ public action(runner: Function): this {
28
+ this.runner = runner as (...args: ConstructorParameters<T>) => Promise<void>;
29
+
30
+ return this;
31
+ }
32
+
33
+ }
34
+
35
+ export default interface ProgramStub extends Program {}
@@ -0,0 +1,14 @@
1
+ import type { Constructor } from '@noeldemartin/utils';
2
+
3
+ import ProgramStub from '@/testing/stubs/ProgramStub';
4
+ import type Command from '@/commands/Command';
5
+
6
+ export type StubCommandRunner<T extends Constructor<Command>> = (...args: ConstructorParameters<T>) => Promise<void>;
7
+
8
+ export function stubCommandRunner<T extends Constructor<Command>>(commandClass: T): StubCommandRunner<T> {
9
+ const program = new ProgramStub();
10
+
11
+ (commandClass as unknown as typeof Command).define(program);
12
+
13
+ return (...args) => program.run(...args);
14
+ }
@@ -0,0 +1,32 @@
1
+ <template>
2
+ <AGHeadlessButton :class="colorClasses">
3
+ <slot />
4
+ </AGHeadlessButton>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import { Colors, enumProp } from '@aerogel/core';
9
+ import { computed } from 'vue';
10
+
11
+ const props = defineProps({
12
+ color: enumProp(Colors, Colors.Primary),
13
+ });
14
+
15
+ const colorClasses = computed(() => {
16
+ switch (props.color) {
17
+ case Colors.Secondary:
18
+ // Add your custom color classes here.
19
+ return '';
20
+ case Colors.Clear:
21
+ // Add your custom color classes here.
22
+ return '';
23
+ case Colors.Danger:
24
+ // Add your custom color classes here.
25
+ return '';
26
+ case Colors.Primary:
27
+ default:
28
+ // Add your custom color classes here.
29
+ return '';
30
+ }
31
+ });
32
+ </script>
@@ -0,0 +1,71 @@
1
+ <template>
2
+ <Story :layout="{ type: 'grid' }">
3
+ <Variant title="Playground">
4
+ <<% component.name %> :color="color">
5
+ {{ content }}
6
+ </<% component.name %>>
7
+
8
+ <template #controls>
9
+ <HstText v-model="content" title="Content" />
10
+ <HstSelect v-model="color" title="Color" :options="colorOptions" />
11
+ </template>
12
+ </Variant>
13
+
14
+ <Variant title="Default">
15
+ <<% component.name %>>
16
+ Click me!
17
+ </<% component.name %>>
18
+ </Variant>
19
+
20
+ <Variant title="Hover">
21
+ <<% component.name %> class=":hover">
22
+ Click me!
23
+ </<% component.name %>>
24
+ </Variant>
25
+
26
+ <Variant title="Focus">
27
+ <<% component.name %> class=":focus :focus-visible">
28
+ Click me!
29
+ </<% component.name %>>
30
+ </Variant>
31
+
32
+ <Variant title="Colors" :layout="{ width: '300px' }">
33
+ <div class="flex items-center gap-2">
34
+ <<% component.name %> color="primary">
35
+ Primary
36
+ </<% component.name %>>
37
+ <<% component.name %> color="secondary">
38
+ Secondary
39
+ </<% component.name %>>
40
+ <<% component.name %> color="danger">
41
+ Danger
42
+ </<% component.name %>>
43
+ <<% component.name %> color="clear">
44
+ Clear
45
+ </<% component.name %>>
46
+ </div>
47
+ </Variant>
48
+ </Story>
49
+ </template>
50
+
51
+ <script setup lang="ts">
52
+ import { Colors } from '@aerogel/core';
53
+ import { invert } from '@noeldemartin/utils';
54
+ import { ref } from 'vue';
55
+ import type { Color } from '@aerogel/core';
56
+
57
+ const content = ref('Click me!');
58
+ const color = ref<Color>(Colors.Primary);
59
+ const colorOptions = invert(Colors);
60
+ </script>
61
+
62
+ <style>
63
+ .story-<% component.slug %> {
64
+ grid-template-columns: repeat(3, 200px) !important;
65
+ }
66
+
67
+ .story-<% component.slug %> .variant-playground,
68
+ .story-<% component.slug %> .variant-colors{
69
+ grid-column: 1 / -1;
70
+ }
71
+ </style>
@@ -0,0 +1,16 @@
1
+ <template>
2
+ <AGHeadlessInput v-bind="props">
3
+ <AGHeadlessInputLabel />
4
+ <AGHeadlessInputInput v-bind="attrs" />
5
+ <AGHeadlessInputError />
6
+ </AGHeadlessInput>
7
+ </template>
8
+
9
+ <script setup lang="ts">
10
+ import { useInputAttrs, useInputProps } from '@aerogel/core';
11
+
12
+ defineOptions({ inheritAttrs: false });
13
+
14
+ const props = defineProps(useInputProps());
15
+ const [attrs] = useInputAttrs();
16
+ </script>
@@ -0,0 +1,63 @@
1
+ <template>
2
+ <Story :layout="{ type: 'grid' }">
3
+ <Variant title="Playground">
4
+ <AGForm :form="form">
5
+ <<% component.name %> name="food" :label="label" :placeholder="placeholder" />
6
+ </AGForm>
7
+
8
+ <template #controls>
9
+ <HstText v-model="label" title="Label" />
10
+ <HstText v-model="placeholder" title="Placeholder" />
11
+ <HstCheckbox v-model="hasErrors" title="Errors" />
12
+ </template>
13
+ </Variant>
14
+
15
+ <Variant title="Default">
16
+ <<% component.name %> label="What's the best food?" placeholder="Ramen" />
17
+ </Variant>
18
+
19
+ <Variant title="Hover">
20
+ <<% component.name %> label="What's the best food?" placeholder="Ramen" input-class=":hover" />
21
+ </Variant>
22
+
23
+ <Variant title="Focus">
24
+ <<% component.name %> label="What's the best food?" placeholder="Ramen" input-class=":focus :focus-visible" />
25
+ </Variant>
26
+
27
+ <Variant title="Error">
28
+ <AGForm :form="errorForm">
29
+ <<% component.name %>
30
+ name="food"
31
+ label="What's the best food?"
32
+ placeholder="Ramen"
33
+ class=":focus :focus-visible"
34
+ />
35
+ </AGForm>
36
+ </Variant>
37
+ </Story>
38
+ </template>
39
+
40
+ <script setup lang="ts">
41
+ import { requiredStringInput, useForm } from '@aerogel/core';
42
+ import { ref, watchEffect } from 'vue';
43
+
44
+ const form = useForm({ food: requiredStringInput() });
45
+ const errorForm = useForm({ food: requiredStringInput() });
46
+ const label = ref('What\'s the best food?');
47
+ const placeholder = ref('Ramen');
48
+ const hasErrors = ref(false);
49
+
50
+ errorForm.submit();
51
+
52
+ watchEffect(() => (hasErrors.value ? form.submit() : form.reset()));
53
+ </script>
54
+
55
+ <style>
56
+ .story-<% component.slug %> {
57
+ grid-template-columns: repeat(2, 300px) !important;
58
+ }
59
+
60
+ .story-<% component.slug %> .variant-playground {
61
+ grid-column: 1 / -1;
62
+ }
63
+ </style>
@@ -0,0 +1,7 @@
1
+ import HstAerogel from '@aerogel/histoire/dist/plugin';
2
+ import { defineConfig } from 'histoire';
3
+
4
+ export default defineConfig({
5
+ setupFile: '/src/main.histoire.ts',
6
+ plugins: [HstAerogel()],
7
+ });
@@ -0,0 +1,13 @@
1
+ diff --git a/node_modules/histoire/dist/node/collect/index.js b/node_modules/histoire/dist/node/collect/index.js
2
+ index 8ffd507..37be43e 100644
3
+ --- a/node_modules/histoire/dist/node/collect/index.js
4
+ +++ b/node_modules/histoire/dist/node/collect/index.js
5
+ @@ -22,7 +22,7 @@ export function useCollectStories(options, ctx) {
6
+ /vite\w*\/dist\/client\/(client|env).mjs/,
7
+ ...ctx.config.viteNodeInlineDeps ?? [],
8
+ ],
9
+ - fallbackCJS: true,
10
+ + fallbackCJS: false,
11
+ },
12
+ transformMode: ctx.config.viteNodeTransformMode,
13
+ });
@@ -0,0 +1,8 @@
1
+ import '@aerogel/histoire/dist/styles.css';
2
+ import { defineSetupAerogel } from '@aerogel/histoire';
3
+
4
+ import './assets/css/styles.css';
5
+
6
+ export const setupVue3 = defineSetupAerogel({
7
+ messages: import.meta.glob('@/lang/*.yaml'),
8
+ });
@@ -0,0 +1,15 @@
1
+ const plugins = {
2
+ tailwindcss: {},
3
+ autoprefixer: {},
4
+ };
5
+
6
+ if (process.env.NODE_ENV === 'development') {
7
+ plugins['postcss-pseudo-classes'] = {
8
+ blacklist: [],
9
+ restrictTo: ['hover', 'focus-visible', 'focus'],
10
+ allCombinations: true,
11
+ preserveBeforeAfter: false,
12
+ };
13
+ }
14
+
15
+ module.exports = { plugins };
/package/bin/{ag → gel} RENAMED
File without changes