@aerogel/cli 0.0.0-next.926bde19326fe7b6b24b277666936862b64d8295 → 0.0.0-next.b85327579d32f21c6a9fa21142f0165cdd320d7e

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 (42) hide show
  1. package/dist/aerogel-cli.cjs.js +1 -1
  2. package/dist/aerogel-cli.esm.js +1 -1
  3. package/noeldemartin.config.js +11 -1
  4. package/package.json +3 -2
  5. package/src/cli.ts +4 -0
  6. package/src/commands/create.test.ts +12 -4
  7. package/src/commands/create.ts +16 -2
  8. package/src/commands/generate-component.test.ts +12 -1
  9. package/src/commands/generate-component.ts +128 -19
  10. package/src/commands/generate-model.test.ts +7 -4
  11. package/src/commands/generate-model.ts +30 -20
  12. package/src/commands/generate-service.test.ts +21 -0
  13. package/src/commands/generate-service.ts +152 -0
  14. package/src/commands/install.test.ts +18 -0
  15. package/src/commands/install.ts +32 -0
  16. package/src/lib/App.ts +64 -2
  17. package/src/lib/Editor.ts +51 -0
  18. package/src/lib/File.ts +6 -0
  19. package/src/lib/Log.mock.ts +2 -1
  20. package/src/lib/Log.ts +6 -4
  21. package/src/lib/utils/app.ts +15 -0
  22. package/src/lib/utils/edit.ts +44 -0
  23. package/src/lib/{utils.test.ts → utils/format.test.ts} +2 -2
  24. package/src/lib/{utils.ts → utils/format.ts} +0 -6
  25. package/src/lib/utils/paths.ts +30 -0
  26. package/src/plugins/Plugin.ts +125 -0
  27. package/src/plugins/Solid.ts +65 -0
  28. package/src/plugins/Soukai.ts +19 -0
  29. package/src/testing/setup.ts +31 -6
  30. package/templates/app/.eslintrc.js +3 -0
  31. package/templates/app/.vscode/launch.json +16 -0
  32. package/templates/app/.vscode/settings.json +10 -0
  33. package/templates/app/cypress.config.ts +4 -0
  34. package/templates/app/index.html +1 -1
  35. package/templates/app/package.json +19 -7
  36. package/templates/app/prettier.config.js +5 -0
  37. package/templates/app/src/App.vue +3 -1
  38. package/templates/app/src/main.ts +5 -1
  39. package/templates/app/src/types/globals.d.ts +0 -1
  40. package/templates/app/tailwind.config.js +1 -1
  41. package/templates/app/vite.config.ts +5 -3
  42. package/templates/service/[service.name].ts +8 -0
@@ -0,0 +1,125 @@
1
+ import { Node, SyntaxKind } from 'ts-morph';
2
+ import type { ArrayLiteralExpression, ImportDeclarationStructure, OptionalKind, SourceFile } from 'ts-morph';
3
+
4
+ import Log from '@/lib/Log';
5
+ import Shell from '@/lib/Shell';
6
+ import File from '@/lib/File';
7
+ import { app, isLinkedLocalApp, isLocalApp } from '@/lib/utils/app';
8
+ import { editFiles, findDescendant, when } from '@/lib/utils/edit';
9
+ import { packNotFound, packagePackPath, packagePath } from '@/lib/utils/paths';
10
+ import type { Editor } from '@/lib/Editor';
11
+
12
+ export default abstract class Plugin {
13
+
14
+ public readonly name: string;
15
+
16
+ constructor(name: string) {
17
+ this.name = name;
18
+ }
19
+
20
+ public async install(): Promise<void> {
21
+ this.assertNotInstalled();
22
+
23
+ await this.installDependencies();
24
+
25
+ if (editFiles()) {
26
+ const editor = app().edit();
27
+
28
+ await this.updateFiles(editor);
29
+ await editor.format();
30
+ }
31
+
32
+ Log.info(`Plugin ${this.name} installed!`);
33
+ }
34
+
35
+ protected assertNotInstalled(): void {
36
+ if (File.contains('package.json', `"${this.getNpmPackageName()}"`)) {
37
+ Log.fail(`${this.name} is already installed!`);
38
+ }
39
+ }
40
+
41
+ protected async installDependencies(): Promise<void> {
42
+ await Log.animate('Installing plugin dependencies', async () => {
43
+ await this.installNpmDependencies();
44
+ });
45
+ }
46
+
47
+ protected async updateFiles(editor: Editor): Promise<void> {
48
+ await this.updateBootstrapConfig(editor);
49
+ }
50
+
51
+ protected async installNpmDependencies(): Promise<void> {
52
+ if (isLinkedLocalApp()) {
53
+ await Shell.run(`npm install file:${packagePath(this.getLocalPackageName())}`);
54
+
55
+ return;
56
+ }
57
+
58
+ if (isLocalApp()) {
59
+ const packPath = packagePackPath(this.getLocalPackageName()) ?? packNotFound(this.getLocalPackageName());
60
+
61
+ await Shell.run(`npm install file:${packPath}`);
62
+
63
+ return;
64
+ }
65
+
66
+ await Shell.run(`npm install ${this.getNpmPackageName()}@next`);
67
+ }
68
+
69
+ protected async updateBootstrapConfig(editor: Editor): Promise<void> {
70
+ await Log.animate('Injecting plugin in bootstrap configuration', async () => {
71
+ const mainConfig = editor.requireSourceFile('src/main.ts');
72
+ const pluginsArray = this.getBootstrapPluginsDeclaration(mainConfig);
73
+
74
+ if (!pluginsArray) {
75
+ return Log.fail(`
76
+ Could not find plugins array in bootstrap config, please add the following manually:
77
+
78
+ ${this.getBootstrapConfig()}
79
+ `);
80
+ }
81
+
82
+ mainConfig.addImportDeclaration(this.getBootstrapImport());
83
+ pluginsArray.addElement(this.getBootstrapConfig());
84
+
85
+ await editor.save(mainConfig);
86
+ });
87
+ }
88
+
89
+ protected getBootstrapPluginsDeclaration(mainConfig: SourceFile): ArrayLiteralExpression | null {
90
+ const bootstrapAppCall = findDescendant(mainConfig, {
91
+ guard: Node.isCallExpression,
92
+ validate: (callExpression) => callExpression.getExpression().getText() === 'bootstrapApplication',
93
+ skip: SyntaxKind.ImportDeclaration,
94
+ });
95
+ const bootstrapOptions = bootstrapAppCall?.getArguments()[1];
96
+ const pluginsOption = when(bootstrapOptions, Node.isObjectLiteralExpression)?.getProperty('plugins');
97
+ const pluginsArray = when(pluginsOption, Node.isPropertyAssignment)?.getInitializer();
98
+
99
+ if (!Node.isArrayLiteralExpression(pluginsArray)) {
100
+ return null;
101
+ }
102
+
103
+ return pluginsArray;
104
+ }
105
+
106
+ protected getBootstrapImport(): OptionalKind<ImportDeclarationStructure> {
107
+ return {
108
+ defaultImport: this.name,
109
+ moduleSpecifier: `@aerogel/plugin-${this.name}`,
110
+ };
111
+ }
112
+
113
+ protected getNpmPackageName(): string {
114
+ return `@aerogel/${this.getLocalPackageName()}`;
115
+ }
116
+
117
+ protected getLocalPackageName(): string {
118
+ return `plugin-${this.name}`;
119
+ }
120
+
121
+ protected getBootstrapConfig(): string {
122
+ return `${this.name}()`;
123
+ }
124
+
125
+ }
@@ -0,0 +1,65 @@
1
+ import { Node, SyntaxKind } from 'ts-morph';
2
+ import type { ArrayLiteralExpression, SourceFile } from 'ts-morph';
3
+
4
+ import Plugin from '@/plugins/Plugin';
5
+ import Shell from '@/lib/Shell';
6
+ import Log from '@/lib/Log';
7
+ import { findDescendant } from '@/lib/utils/edit';
8
+ import { isLinkedLocalApp } from '@/lib/utils/app';
9
+ import { packagePath } from '@/lib/utils/paths';
10
+ import type { Editor } from '@/lib/Editor';
11
+
12
+ export class Solid extends Plugin {
13
+
14
+ constructor() {
15
+ super('solid');
16
+ }
17
+
18
+ protected async updateFiles(editor: Editor): Promise<void> {
19
+ await this.updateTailwindConfig(editor);
20
+ await super.updateFiles(editor);
21
+ }
22
+
23
+ protected async installNpmDependencies(): Promise<void> {
24
+ await Shell.run('npm install soukai-solid@next');
25
+ await super.installNpmDependencies();
26
+ }
27
+
28
+ protected async updateTailwindConfig(editor: Editor): Promise<void> {
29
+ await Log.animate('Updating tailwind configuration', async () => {
30
+ const tailwindConfig = editor.requireSourceFile('tailwind.config.js');
31
+ const contentArray = this.getTailwindContentArray(tailwindConfig);
32
+ const contentValue = isLinkedLocalApp()
33
+ ? `'${packagePath('plugin-solid')}/dist/**/*.js'`
34
+ : '\'./node_modules/@aerogel/plugin-solid/dist/**/*.js\'';
35
+
36
+ if (!contentArray) {
37
+ return Log.fail(`
38
+ Could not find content array in tailwind config, please add the following manually:
39
+
40
+ ${contentValue}
41
+ `);
42
+ }
43
+
44
+ contentArray.addElement(contentValue);
45
+
46
+ await editor.save(tailwindConfig);
47
+ });
48
+ }
49
+
50
+ protected getTailwindContentArray(tailwindConfig: SourceFile): ArrayLiteralExpression | null {
51
+ const contentAssignment = findDescendant(tailwindConfig, {
52
+ guard: Node.isPropertyAssignment,
53
+ validate: (propertyAssignment) => propertyAssignment.getName() === 'content',
54
+ skip: SyntaxKind.JSDoc,
55
+ });
56
+ const contentArray = contentAssignment?.getInitializer();
57
+
58
+ if (!Node.isArrayLiteralExpression(contentArray)) {
59
+ return null;
60
+ }
61
+
62
+ return contentArray;
63
+ }
64
+
65
+ }
@@ -0,0 +1,19 @@
1
+ import Plugin from '@/plugins/Plugin';
2
+ import Shell from '@/lib/Shell';
3
+
4
+ export class Soukai extends Plugin {
5
+
6
+ constructor() {
7
+ super('soukai');
8
+ }
9
+
10
+ protected async installNpmDependencies(): Promise<void> {
11
+ await Shell.run('npm install soukai@next');
12
+ await super.installNpmDependencies();
13
+ }
14
+
15
+ protected getBootstrapConfig(): string {
16
+ return 'soukai({ models: import.meta.glob(\'@/models/*\', { eager: true }) })';
17
+ }
18
+
19
+ }
@@ -24,16 +24,41 @@ beforeEach(() => {
24
24
  Shell.mock();
25
25
  });
26
26
 
27
+ vi.mock('@/lib/utils/app', async () => {
28
+ const original = (await vi.importActual('@/lib/utils/app')) as object;
29
+
30
+ return {
31
+ ...original,
32
+ isLocalApp: () => false,
33
+ isLinkedLocalApp: () => false,
34
+ };
35
+ });
36
+
37
+ vi.mock('@/lib/utils/edit', async () => {
38
+ const original = (await vi.importActual('@/lib/utils/edit')) as object;
39
+
40
+ return {
41
+ ...original,
42
+ editFiles: () => false,
43
+ };
44
+ });
45
+
27
46
  // TODO find out why these need to be mocked
47
+ vi.mock('@/lib/utils/paths', async () => {
48
+ const original = (await vi.importActual('@/lib/utils/paths')) as object;
49
+
50
+ function basePath(path: string = '') {
51
+ return resolve(__dirname, '../../', path);
52
+ }
28
53
 
29
- vi.mock('@/lib/utils', async () => {
30
- const utils = (await vi.importActual('@/lib/utils')) as object;
54
+ function packagePath(packageName: string) {
55
+ return basePath(`../${packageName}`);
56
+ }
31
57
 
32
58
  return {
33
- ...utils,
34
- basePath(path: string) {
35
- return resolve(__dirname, '../../', path);
36
- },
59
+ ...original,
60
+ basePath,
61
+ packagePath,
37
62
  };
38
63
  });
39
64
 
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ extends: ['@noeldemartin/eslint-config-vue'],
3
+ };
@@ -0,0 +1,16 @@
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "type": "node",
6
+ "request": "launch",
7
+ "name": "Debug Current Test File",
8
+ "autoAttachChildProcesses": true,
9
+ "skipFiles": ["<node_internals>/**", "**/node_modules/**"],
10
+ "program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
11
+ "args": ["run", "${fileBasenameNoExtension}"],
12
+ "smartStep": true,
13
+ "console": "integratedTerminal"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "emeraldwalk.runonsave": {
3
+ "commands": [
4
+ {
5
+ "match": ".*",
6
+ "cmd": "npx prettier-eslint ${file} --write"
7
+ }
8
+ ]
9
+ }
10
+ }
@@ -1,8 +1,12 @@
1
+ import install from '@aerogel/cypress/dist/plugin';
1
2
  import { defineConfig } from 'cypress';
2
3
 
3
4
  export default defineConfig({
4
5
  e2e: {
5
6
  baseUrl: 'http://localhost:5001',
6
7
  video: false,
8
+ setupNodeEvents(on) {
9
+ install(on);
10
+ },
7
11
  },
8
12
  });
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title><% app.name %></title>
7
7
  </head>
8
- <body class="h-full w-full">
8
+ <body class="h-full w-full text-base font-normal leading-tight text-gray-900 antialiased">
9
9
  <div id="app" class="h-full"></div>
10
10
  <script type="module" src="./src/main.ts"></script>
11
11
  </body>
@@ -8,6 +8,8 @@
8
8
  "cy:open": "cypress open --e2e --browser chromium",
9
9
  "cy:run": "cypress run",
10
10
  "cy:test": "start-server-and-test test:serve-app http-get://localhost:5001 cy:run",
11
+ "cy:test-snapshots": "docker run -it -u `id -u ${whoami}` -e CYPRESS_SNAPSHOTS=true -v ./:/app -w /app cypress/base:18.16.0 sh -c \"npx cypress install && npm run cy:test\"",
12
+ "cy:test-snapshots:ci": "docker run -e CYPRESS_SNAPSHOTS=true -v ./:/app -w /app cypress/base:18.16.0 sh -c \"npx cypress install && npm run cy:test\"",
11
13
  "dev": "vite",
12
14
  "lint": "noeldemartin-lint src",
13
15
  "test": "vitest --run",
@@ -15,28 +17,38 @@
15
17
  "test:serve-app": "vite --port 5001"
16
18
  },
17
19
  "dependencies": {
18
- "@aerogel/core": "next",
19
- "@aerogel/plugin-i18n": "next",
20
+ "@aerogel/core": "<% &dependencies.aerogelCore %>",
21
+ "@aerogel/plugin-i18n": "<% &dependencies.aerogelPluginI18n %>",
22
+ "@aerogel/plugin-soukai": "<% &dependencies.aerogelPluginSoukai %>",
20
23
  "@intlify/unplugin-vue-i18n": "^0.12.2",
24
+ "@noeldemartin/utils": "next",
21
25
  "@tailwindcss/forms": "^0.5.3",
22
26
  "@tailwindcss/typography": "^0.5.9",
27
+ "soukai": "next",
23
28
  "tailwindcss": "^3.3.2",
24
29
  "vue": "^3.3.0",
25
30
  "vue-i18n": "9.3.0-beta.19"
26
31
  },
27
32
  "devDependencies": {
28
- "@aerogel/cli": "next",
29
- "@aerogel/cypress": "next",
30
- "@aerogel/vite": "next",
31
- "@noeldemartin/utils": "0.4.0-next.ac00beaecf32bb02ed8e335225d7948d946d73bd",
33
+ "@aerogel/cli": "<% &dependencies.aerogelCli %>",
34
+ "@aerogel/cypress": "<% &dependencies.aerogelCypress %>",
35
+ "@aerogel/vite": "<% &dependencies.aerogelVite %>",
36
+ "@noeldemartin/eslint-config-vue": "next",
37
+ "@noeldemartin/scripts": "next",
32
38
  "@total-typescript/ts-reset": "^0.4.2",
33
39
  "@types/node": "^20.3.1",
34
40
  "autoprefixer": "^10.4.14",
35
41
  "concurrently": "^8.2.0",
36
42
  "cypress": "^12.17.0",
43
+ "eslint": "^8.40.0",
44
+ "prettier": "^2.8.8",
45
+ "prettier-eslint-cli": "^7.1.0",
46
+ "prettier-plugin-tailwindcss": "^0.2.8",
37
47
  "start-server-and-test": "^2.0.0",
48
+ "unplugin-icons": "^0.16.3",
38
49
  "unplugin-vue-components": "^0.24.1",
39
50
  "vite": "^4.3.0",
40
- "vitest": "^0.33.0"
51
+ "vitest": "^0.33.0",
52
+ "vue-tsc": "^1.8.15"
41
53
  }
42
54
  }
@@ -0,0 +1,5 @@
1
+ /** @type {import('prettier').Config} */
2
+ module.exports = {
3
+ plugins: [require('prettier-plugin-tailwindcss')],
4
+ printWidth: 120,
5
+ };
@@ -1,7 +1,9 @@
1
1
  <template>
2
2
  <AGAppLayout>
3
3
  <main class="flex flex-grow flex-col items-center justify-center bg-blue-50">
4
- <h1 class="text-4xl font-semibold">{{ $t('home.title') }}</h1>
4
+ <h1 class="text-4xl font-semibold">
5
+ {{ $t('home.title') }}
6
+ </h1>
5
7
  <a href="https://aerogel.js.org" target="_blank" class="mt-2 underline opacity-75 hover:opacity-100">
6
8
  {{ $t('home.getStarted') }}
7
9
  </a>
@@ -1,9 +1,13 @@
1
1
  import i18n from '@aerogel/plugin-i18n';
2
+ import soukai from '@aerogel/plugin-soukai';
2
3
  import { bootstrapApplication } from '@aerogel/core';
3
4
 
4
5
  import './assets/styles.css';
5
6
  import App from './App.vue';
6
7
 
7
8
  bootstrapApplication(App, {
8
- plugins: [i18n({ messages: import.meta.glob('@/lang/*.yaml') })],
9
+ plugins: [
10
+ i18n({ messages: import.meta.glob('@/lang/*.yaml') }),
11
+ soukai({ models: import.meta.glob('@/models/*', { eager: true }) }),
12
+ ],
9
13
  });
@@ -1,3 +1,2 @@
1
1
  /// <reference types="vite/client" />
2
- /// <reference types="vue-router" />
3
2
  /// <reference types="vue-i18n" />
@@ -1,5 +1,5 @@
1
1
  /** @type {import('tailwindcss').Config} */
2
2
  module.exports = {
3
- content: ['./index.html', './src/**/*.{vue,ts}', './node_modules/@aerogel/core/dist/**/*.js'],
3
+ content: ['./index.html', './src/**/*.{vue,ts}', '<% &contentPath %>'],
4
4
  plugins: [require('@tailwindcss/forms'), require('@tailwindcss/typography')],
5
5
  };
@@ -1,17 +1,19 @@
1
1
  import Aerogel, { AerogelResolver } from '@aerogel/vite';
2
2
  import Components from 'unplugin-vue-components/vite';
3
3
  import I18n from '@intlify/unplugin-vue-i18n/vite';
4
+ import Icons from 'unplugin-icons/vite';
5
+ import IconsResolver from 'unplugin-icons/resolver';
4
6
  import { resolve } from 'path';
5
7
 
6
8
  export default {
7
9
  plugins: [
8
- I18n({ include: resolve(__dirname, './src/lang/**/*.yaml') }),
9
10
  Aerogel(),
10
11
  Components({
11
- dirs: ['src/pages'],
12
12
  dts: false,
13
- resolvers: [AerogelResolver()],
13
+ resolvers: [AerogelResolver(), IconsResolver()],
14
14
  }),
15
+ I18n({ include: resolve(__dirname, './src/lang/**/*.yaml') }),
16
+ Icons(),
15
17
  ],
16
18
  resolve: {
17
19
  alias: {
@@ -0,0 +1,8 @@
1
+ import { Service } from '@aerogel/core';
2
+ import { facade } from '@noeldemartin/utils';
3
+
4
+ export class <% service.name %>Service extends Service {
5
+
6
+ }
7
+
8
+ export default facade(new <% service.name %>Service());