@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.
- package/bin/gel +4 -0
- package/dist/aerogel-cli.d.ts +2 -2
- package/dist/aerogel-cli.js +754 -0
- package/dist/aerogel-cli.js.map +1 -0
- package/package.json +26 -32
- package/src/cli.ts +26 -8
- package/src/commands/Command.ts +14 -9
- package/src/commands/create.test.ts +3 -17
- package/src/commands/create.ts +19 -20
- package/src/commands/generate-component.test.ts +1 -14
- package/src/commands/generate-component.ts +20 -50
- package/src/commands/generate-model.test.ts +2 -2
- package/src/commands/generate-model.ts +13 -14
- package/src/commands/generate-service.test.ts +2 -2
- package/src/commands/generate-service.ts +16 -17
- package/src/commands/info.ts +15 -0
- package/src/commands/install.test.ts +21 -4
- package/src/commands/install.ts +12 -11
- package/src/lib/App.ts +45 -49
- package/src/lib/Editor.ts +19 -13
- package/src/lib/File.mock.ts +7 -11
- package/src/lib/File.ts +14 -3
- package/src/lib/Log.mock.ts +4 -8
- package/src/lib/Log.test.ts +4 -4
- package/src/lib/Log.ts +7 -7
- package/src/lib/Shell.mock.ts +3 -3
- package/src/lib/Shell.ts +2 -2
- package/src/lib/Template.ts +24 -17
- package/src/lib/utils/app.ts +3 -3
- package/src/lib/utils/edit.ts +2 -2
- package/src/lib/utils/paths.ts +16 -8
- package/src/plugins/LocalFirst.ts +9 -0
- package/src/plugins/Plugin.ts +49 -14
- package/src/plugins/Solid.ts +48 -42
- package/src/plugins/Soukai.ts +6 -6
- package/src/testing/setup.ts +36 -31
- package/templates/app/README.md +3 -0
- package/templates/service/[service.name].ts +1 -1
- package/.eslintrc.js +0 -7
- package/bin/ag +0 -4
- package/dist/aerogel-cli.cjs.js +0 -2
- package/dist/aerogel-cli.cjs.js.map +0 -1
- package/dist/aerogel-cli.esm.js +0 -2
- package/dist/aerogel-cli.esm.js.map +0 -1
- package/noeldemartin.config.js +0 -14
- package/src/lib/utils/format.test.ts +0 -33
- package/src/lib/utils/format.ts +0 -38
- package/templates/app/.eslintrc.js +0 -3
- package/templates/app/.github/workflows/ci.yml +0 -17
- package/templates/app/.gitignore.template +0 -2
- package/templates/app/.nvmrc +0 -1
- package/templates/app/.vscode/launch.json +0 -16
- package/templates/app/.vscode/settings.json +0 -10
- package/templates/app/cypress/e2e/app.cy.ts +0 -9
- package/templates/app/cypress/support/e2e.ts +0 -3
- package/templates/app/cypress/tsconfig.json +0 -12
- package/templates/app/cypress.config.ts +0 -12
- package/templates/app/index.html +0 -12
- package/templates/app/package.json +0 -54
- package/templates/app/postcss.config.js +0 -6
- package/templates/app/prettier.config.js +0 -5
- package/templates/app/src/App.vue +0 -12
- package/templates/app/src/assets/styles.css +0 -3
- package/templates/app/src/lang/en.yaml +0 -3
- package/templates/app/src/main.test.ts +0 -9
- package/templates/app/src/main.ts +0 -13
- package/templates/app/src/types/globals.d.ts +0 -2
- package/templates/app/src/types/shims.d.ts +0 -7
- package/templates/app/src/types/ts-reset.d.ts +0 -1
- package/templates/app/tailwind.config.js +0 -5
- package/templates/app/tsconfig.json +0 -18
- package/templates/app/vite.config.ts +0 -23
- package/templates/component-story/[component.name].story.vue +0 -7
- package/tsconfig.json +0 -11
- package/vite.config.ts +0 -14
- /package/src/{main.ts → index.ts} +0 -0
package/src/lib/Template.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import Mustache from 'mustache';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
3
|
import { toString } from '@noeldemartin/utils';
|
|
4
4
|
|
|
5
|
-
import File from '
|
|
5
|
+
import File from '@aerogel/cli/lib/File';
|
|
6
6
|
|
|
7
7
|
export default class Template {
|
|
8
8
|
|
|
9
|
-
public static instantiate(
|
|
9
|
+
public static instantiate(
|
|
10
|
+
path: string,
|
|
11
|
+
destination: string = './',
|
|
12
|
+
replacements: Record<string, unknown> = {},
|
|
13
|
+
): string[] {
|
|
10
14
|
const template = new Template(path);
|
|
11
15
|
|
|
12
16
|
return template.instantiate(destination, replacements);
|
|
@@ -28,7 +32,7 @@ export default class Template {
|
|
|
28
32
|
const filePath =
|
|
29
33
|
destination + (relativePath.endsWith('.template') ? relativePath.slice(0, -9) : relativePath);
|
|
30
34
|
|
|
31
|
-
File.write(filePath, render(fileContents, replacements, undefined, ['<%', '%>']));
|
|
35
|
+
File.write(filePath, Mustache.render(fileContents, replacements, undefined, ['<%', '%>']));
|
|
32
36
|
files.push(filePath);
|
|
33
37
|
}
|
|
34
38
|
|
|
@@ -39,18 +43,21 @@ export default class Template {
|
|
|
39
43
|
replacements: Record<string, unknown>,
|
|
40
44
|
prefix: string = '',
|
|
41
45
|
): Record<string, string> {
|
|
42
|
-
return Object.entries(replacements).reduce(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
return Object.entries(replacements).reduce(
|
|
47
|
+
(filenameReplacements, [key, value]) => {
|
|
48
|
+
if (typeof value === 'object') {
|
|
49
|
+
Object.assign(
|
|
50
|
+
filenameReplacements,
|
|
51
|
+
this.getFilenameReplacements(value as Record<string, unknown>, `${key}.`),
|
|
52
|
+
);
|
|
53
|
+
} else {
|
|
54
|
+
filenameReplacements[`[${prefix}${key}]`] = toString(value);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return filenameReplacements;
|
|
58
|
+
},
|
|
59
|
+
{} as Record<string, string>,
|
|
60
|
+
);
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
}
|
package/src/lib/utils/app.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import App from '
|
|
2
|
-
import File from '
|
|
1
|
+
import App from '@aerogel/cli/lib/App';
|
|
2
|
+
import File from '@aerogel/cli/lib/File';
|
|
3
3
|
|
|
4
4
|
export function app(): App {
|
|
5
5
|
// TODO parse app name
|
|
@@ -7,7 +7,7 @@ export function app(): App {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export function isLocalApp(): boolean {
|
|
10
|
-
return File.contains('package.json', 'file');
|
|
10
|
+
return File.contains('package.json', '"@aerogel/core": "file:');
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function isLinkedLocalApp(): boolean {
|
package/src/lib/utils/edit.ts
CHANGED
|
@@ -23,8 +23,8 @@ export function findDescendant<T extends Node>(
|
|
|
23
23
|
const skipKinds = arrayFrom(options.skip ?? []);
|
|
24
24
|
|
|
25
25
|
return node.forEachDescendant((descendant, traversal) => {
|
|
26
|
-
if (guard(descendant) && validate(descendant)) {
|
|
27
|
-
return descendant;
|
|
26
|
+
if (guard(descendant) && validate(descendant as T)) {
|
|
27
|
+
return descendant as T;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const descendantKind = descendant.getKind();
|
package/src/lib/utils/paths.ts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { URL, fileURLToPath } from 'node:url';
|
|
2
2
|
import { stringMatch } from '@noeldemartin/utils';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
3
4
|
|
|
4
|
-
import File from '
|
|
5
|
-
import Log from '
|
|
5
|
+
import File from '@aerogel/cli/lib/File';
|
|
6
|
+
import Log from '@aerogel/cli/lib/Log';
|
|
6
7
|
|
|
7
8
|
export function basePath(path: string = ''): string {
|
|
8
|
-
if (
|
|
9
|
-
|
|
9
|
+
if (
|
|
10
|
+
File.contains(
|
|
11
|
+
fileURLToPath(new URL(/* @vite-ignore */ '../../../package.json', import.meta.url)),
|
|
12
|
+
'"packages/create-aerogel"',
|
|
13
|
+
)
|
|
14
|
+
) {
|
|
15
|
+
return resolve(fileURLToPath(new URL(/* @vite-ignore */ '../', import.meta.url)), path);
|
|
10
16
|
}
|
|
11
17
|
|
|
12
|
-
const packageJson = File.read(
|
|
13
|
-
|
|
18
|
+
const packageJson = File.read(
|
|
19
|
+
fileURLToPath(new URL(/* @vite-ignore */ '../../../../package.json', import.meta.url)),
|
|
20
|
+
);
|
|
21
|
+
const matches = stringMatch<2>(packageJson ?? '', /"@aerogel\/core": "file:(.*)\/aerogel-core-[\d.]*\.tgz"/);
|
|
14
22
|
const cliPath = matches?.[1] ?? Log.fail<string>('Could not determine base path');
|
|
15
23
|
|
|
16
24
|
return resolve(cliPath, path);
|
|
@@ -30,5 +38,5 @@ export function packagePath(packageName: string): string {
|
|
|
30
38
|
}
|
|
31
39
|
|
|
32
40
|
export function templatePath(name: string): string {
|
|
33
|
-
return
|
|
41
|
+
return fileURLToPath(new URL(/* @vite-ignore */ `../templates/${name}`, import.meta.url));
|
|
34
42
|
}
|
package/src/plugins/Plugin.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Node, SyntaxKind } from 'ts-morph';
|
|
2
|
+
import { stringToCamelCase } from '@noeldemartin/utils';
|
|
2
3
|
import type { ArrayLiteralExpression, ImportDeclarationStructure, OptionalKind, SourceFile } from 'ts-morph';
|
|
3
4
|
|
|
4
|
-
import Log from '
|
|
5
|
-
import Shell from '
|
|
6
|
-
import File from '
|
|
7
|
-
import { app, isLinkedLocalApp, isLocalApp } from '
|
|
8
|
-
import { editFiles, findDescendant, when } from '
|
|
9
|
-
import { packNotFound, packagePackPath, packagePath } from '
|
|
10
|
-
import type { Editor } from '
|
|
5
|
+
import Log from '@aerogel/cli/lib/Log';
|
|
6
|
+
import Shell from '@aerogel/cli/lib/Shell';
|
|
7
|
+
import File from '@aerogel/cli/lib/File';
|
|
8
|
+
import { app, isLinkedLocalApp, isLocalApp } from '@aerogel/cli/lib/utils/app';
|
|
9
|
+
import { editFiles, findDescendant, when } from '@aerogel/cli/lib/utils/edit';
|
|
10
|
+
import { packNotFound, packagePackPath, packagePath } from '@aerogel/cli/lib/utils/paths';
|
|
11
|
+
import type { Editor } from '@aerogel/cli/lib/Editor';
|
|
11
12
|
|
|
12
13
|
export default abstract class Plugin {
|
|
13
14
|
|
|
@@ -20,6 +21,7 @@ export default abstract class Plugin {
|
|
|
20
21
|
public async install(): Promise<void> {
|
|
21
22
|
this.assertNotInstalled();
|
|
22
23
|
|
|
24
|
+
await this.beforeInstall();
|
|
23
25
|
await this.installDependencies();
|
|
24
26
|
|
|
25
27
|
if (editFiles()) {
|
|
@@ -29,6 +31,8 @@ export default abstract class Plugin {
|
|
|
29
31
|
await editor.format();
|
|
30
32
|
}
|
|
31
33
|
|
|
34
|
+
await this.afterInstall();
|
|
35
|
+
|
|
32
36
|
Log.info(`Plugin ${this.name} installed!`);
|
|
33
37
|
}
|
|
34
38
|
|
|
@@ -38,6 +42,14 @@ export default abstract class Plugin {
|
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
|
|
45
|
+
protected async beforeInstall(): Promise<void> {
|
|
46
|
+
// Placeholder for overrides, don't place any functionality here.
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
protected async afterInstall(): Promise<void> {
|
|
50
|
+
// Placeholder for overrides, don't place any functionality here.
|
|
51
|
+
}
|
|
52
|
+
|
|
41
53
|
protected async installDependencies(): Promise<void> {
|
|
42
54
|
await Log.animate('Installing plugin dependencies', async () => {
|
|
43
55
|
await this.installNpmDependencies();
|
|
@@ -45,12 +57,16 @@ export default abstract class Plugin {
|
|
|
45
57
|
}
|
|
46
58
|
|
|
47
59
|
protected async updateFiles(editor: Editor): Promise<void> {
|
|
48
|
-
|
|
60
|
+
if (!this.isForDevelopment()) {
|
|
61
|
+
await this.updateBootstrapConfig(editor);
|
|
62
|
+
}
|
|
49
63
|
}
|
|
50
64
|
|
|
51
65
|
protected async installNpmDependencies(): Promise<void> {
|
|
66
|
+
const flags = this.isForDevelopment() ? '--save-dev' : '';
|
|
67
|
+
|
|
52
68
|
if (isLinkedLocalApp()) {
|
|
53
|
-
await Shell.run(`npm install file:${packagePath(this.getLocalPackageName())}`);
|
|
69
|
+
await Shell.run(`npm install file:${packagePath(this.getLocalPackageName())} ${flags}`);
|
|
54
70
|
|
|
55
71
|
return;
|
|
56
72
|
}
|
|
@@ -58,12 +74,12 @@ export default abstract class Plugin {
|
|
|
58
74
|
if (isLocalApp()) {
|
|
59
75
|
const packPath = packagePackPath(this.getLocalPackageName()) ?? packNotFound(this.getLocalPackageName());
|
|
60
76
|
|
|
61
|
-
await Shell.run(`npm install file:${packPath}`);
|
|
77
|
+
await Shell.run(`npm install file:${packPath} ${flags}`);
|
|
62
78
|
|
|
63
79
|
return;
|
|
64
80
|
}
|
|
65
81
|
|
|
66
|
-
await Shell.run(`npm install ${this.getNpmPackageName()}@next`);
|
|
82
|
+
await Shell.run(`npm install ${this.getNpmPackageName()}@next --save-exact ${flags}`);
|
|
67
83
|
}
|
|
68
84
|
|
|
69
85
|
protected async updateBootstrapConfig(editor: Editor): Promise<void> {
|
|
@@ -89,7 +105,7 @@ export default abstract class Plugin {
|
|
|
89
105
|
protected getBootstrapPluginsDeclaration(mainConfig: SourceFile): ArrayLiteralExpression | null {
|
|
90
106
|
const bootstrapAppCall = findDescendant(mainConfig, {
|
|
91
107
|
guard: Node.isCallExpression,
|
|
92
|
-
validate: (callExpression) => callExpression.getExpression().getText() === '
|
|
108
|
+
validate: (callExpression) => callExpression.getExpression().getText() === 'bootstrap',
|
|
93
109
|
skip: SyntaxKind.ImportDeclaration,
|
|
94
110
|
});
|
|
95
111
|
const bootstrapOptions = bootstrapAppCall?.getArguments()[1];
|
|
@@ -103,9 +119,24 @@ export default abstract class Plugin {
|
|
|
103
119
|
return pluginsArray;
|
|
104
120
|
}
|
|
105
121
|
|
|
122
|
+
protected getTailwindContentArray(tailwindConfig: SourceFile): ArrayLiteralExpression | null {
|
|
123
|
+
const contentAssignment = findDescendant(tailwindConfig, {
|
|
124
|
+
guard: Node.isPropertyAssignment,
|
|
125
|
+
validate: (propertyAssignment) => propertyAssignment.getName() === 'content',
|
|
126
|
+
skip: SyntaxKind.JSDoc,
|
|
127
|
+
});
|
|
128
|
+
const contentArray = contentAssignment?.getInitializer();
|
|
129
|
+
|
|
130
|
+
if (!Node.isArrayLiteralExpression(contentArray)) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return contentArray;
|
|
135
|
+
}
|
|
136
|
+
|
|
106
137
|
protected getBootstrapImport(): OptionalKind<ImportDeclarationStructure> {
|
|
107
138
|
return {
|
|
108
|
-
defaultImport: this.name,
|
|
139
|
+
defaultImport: stringToCamelCase(this.name),
|
|
109
140
|
moduleSpecifier: `@aerogel/plugin-${this.name}`,
|
|
110
141
|
};
|
|
111
142
|
}
|
|
@@ -118,8 +149,12 @@ export default abstract class Plugin {
|
|
|
118
149
|
return `plugin-${this.name}`;
|
|
119
150
|
}
|
|
120
151
|
|
|
152
|
+
protected isForDevelopment(): boolean {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
|
|
121
156
|
protected getBootstrapConfig(): string {
|
|
122
|
-
return `${this.name}()`;
|
|
157
|
+
return `${stringToCamelCase(this.name)}()`;
|
|
123
158
|
}
|
|
124
159
|
|
|
125
160
|
}
|
package/src/plugins/Solid.ts
CHANGED
|
@@ -1,65 +1,71 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import File from '@aerogel/cli/lib/File';
|
|
2
|
+
import Log from '@aerogel/cli/lib/Log';
|
|
3
|
+
import Plugin from '@aerogel/cli/plugins/Plugin';
|
|
4
|
+
import Shell from '@aerogel/cli/lib/Shell';
|
|
5
|
+
import type { Editor } from '@aerogel/cli/lib/Editor';
|
|
3
6
|
|
|
4
|
-
|
|
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 {
|
|
7
|
+
export default class Solid extends Plugin {
|
|
13
8
|
|
|
14
9
|
constructor() {
|
|
15
10
|
super('solid');
|
|
16
11
|
}
|
|
17
12
|
|
|
18
|
-
protected async updateFiles(editor: Editor): Promise<void> {
|
|
19
|
-
await this.
|
|
13
|
+
protected override async updateFiles(editor: Editor): Promise<void> {
|
|
14
|
+
await this.updateNpmScripts(editor);
|
|
15
|
+
await this.updateGitIgnore();
|
|
20
16
|
await super.updateFiles(editor);
|
|
21
17
|
}
|
|
22
18
|
|
|
23
|
-
protected async installNpmDependencies(): Promise<void> {
|
|
24
|
-
await Shell.run('npm install soukai-solid@next');
|
|
19
|
+
protected override async installNpmDependencies(): Promise<void> {
|
|
20
|
+
await Shell.run('npm install soukai-solid@next --save-exact');
|
|
21
|
+
await Shell.run('npm install @noeldemartin/solid-utils@next --save-exact');
|
|
22
|
+
await Shell.run('npm install @solid/community-server@7.1.6 --save-dev -E');
|
|
25
23
|
await super.installNpmDependencies();
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
protected async
|
|
29
|
-
|
|
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\'';
|
|
26
|
+
protected async updateNpmScripts(editor: Editor): Promise<void> {
|
|
27
|
+
Log.info('Updating npm scripts...');
|
|
35
28
|
|
|
36
|
-
|
|
37
|
-
return Log.fail(`
|
|
38
|
-
Could not find content array in tailwind config, please add the following manually:
|
|
29
|
+
const packageJson = File.read('package.json');
|
|
39
30
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
if (!packageJson) {
|
|
32
|
+
return Log.fail('Could not find package.json file');
|
|
33
|
+
}
|
|
43
34
|
|
|
44
|
-
|
|
35
|
+
File.write(
|
|
36
|
+
'package.json',
|
|
37
|
+
packageJson
|
|
38
|
+
.replace(
|
|
39
|
+
'"cy:dev": "concurrently --kill-others \\"npm run test:serve-app\\" \\"npm run cy:open\\"",',
|
|
40
|
+
'"cy:dev": "concurrently --kill-others ' +
|
|
41
|
+
'\\"npm run test:serve-app\\" \\"npm run test:serve-pod\\" \\"npm run cy:open\\"",',
|
|
42
|
+
)
|
|
43
|
+
.replace(
|
|
44
|
+
'"cy:test": "start-server-and-test test:serve-app http-get://localhost:5001 cy:run",',
|
|
45
|
+
'"cy:test": "start-server-and-test ' +
|
|
46
|
+
'test:serve-app http-get://localhost:5001 test:serve-pod http-get://localhost:3000 cy:run",',
|
|
47
|
+
)
|
|
48
|
+
.replace(
|
|
49
|
+
'"dev": "vite",',
|
|
50
|
+
'"dev": "vite",\n' +
|
|
51
|
+
'"dev:serve-pod": "community-solid-server -c @css:config/file.json -f ./solid",',
|
|
52
|
+
)
|
|
53
|
+
.replace(
|
|
54
|
+
'"test:serve-app": "vite --port 5001 --mode testing"',
|
|
55
|
+
'"test:serve-app": "vite --port 5001 --mode testing",\n' +
|
|
56
|
+
'"test:serve-pod": "community-solid-server -l warn"',
|
|
57
|
+
),
|
|
58
|
+
);
|
|
45
59
|
|
|
46
|
-
|
|
47
|
-
});
|
|
60
|
+
editor.addModifiedFile('package.json');
|
|
48
61
|
}
|
|
49
62
|
|
|
50
|
-
protected
|
|
51
|
-
|
|
52
|
-
guard: Node.isPropertyAssignment,
|
|
53
|
-
validate: (propertyAssignment) => propertyAssignment.getName() === 'content',
|
|
54
|
-
skip: SyntaxKind.JSDoc,
|
|
55
|
-
});
|
|
56
|
-
const contentArray = contentAssignment?.getInitializer();
|
|
63
|
+
protected async updateGitIgnore(): Promise<void> {
|
|
64
|
+
Log.info('Updating .gitignore');
|
|
57
65
|
|
|
58
|
-
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
66
|
+
const gitignore = File.read('.gitignore') ?? '';
|
|
61
67
|
|
|
62
|
-
|
|
68
|
+
File.write('.gitignore', `${gitignore}/solid\n`);
|
|
63
69
|
}
|
|
64
70
|
|
|
65
71
|
}
|
package/src/plugins/Soukai.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import Plugin from '
|
|
2
|
-
import Shell from '
|
|
1
|
+
import Plugin from '@aerogel/cli/plugins/Plugin';
|
|
2
|
+
import Shell from '@aerogel/cli/lib/Shell';
|
|
3
3
|
|
|
4
|
-
export class Soukai extends Plugin {
|
|
4
|
+
export default class Soukai extends Plugin {
|
|
5
5
|
|
|
6
6
|
constructor() {
|
|
7
7
|
super('soukai');
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
protected async installNpmDependencies(): Promise<void> {
|
|
11
|
-
await Shell.run('npm install soukai@next');
|
|
10
|
+
protected override async installNpmDependencies(): Promise<void> {
|
|
11
|
+
await Shell.run('npm install soukai@next --save-exact');
|
|
12
12
|
await super.installNpmDependencies();
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
protected getBootstrapConfig(): string {
|
|
15
|
+
protected override getBootstrapConfig(): string {
|
|
16
16
|
return 'soukai({ models: import.meta.glob(\'@/models/*\', { eager: true }) })';
|
|
17
17
|
}
|
|
18
18
|
|
package/src/testing/setup.ts
CHANGED
|
@@ -1,31 +1,36 @@
|
|
|
1
|
-
import { beforeEach, vi } from 'vitest';
|
|
2
|
-
import { resolve } from 'path';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { beforeAll, beforeEach, vi } from 'vitest';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { setupFacadeMocks } from '@noeldemartin/testing';
|
|
4
|
+
|
|
5
|
+
import ShellMock from '@aerogel/cli/lib/Shell.mock';
|
|
6
|
+
import File from '@aerogel/cli/lib/File';
|
|
7
|
+
import FileMock from '@aerogel/cli/lib/File.mock';
|
|
8
|
+
import Log from '@aerogel/cli/lib/Log';
|
|
9
|
+
import LogMock from '@aerogel/cli/lib/Log.mock';
|
|
10
|
+
import Shell from '@aerogel/cli/lib/Shell';
|
|
11
|
+
|
|
12
|
+
beforeAll(() => {
|
|
13
|
+
File.setMockFacade(FileMock);
|
|
14
|
+
Log.setMockFacade(LogMock);
|
|
15
|
+
Shell.setMockFacade(ShellMock);
|
|
16
|
+
});
|
|
17
17
|
|
|
18
18
|
beforeEach(() => {
|
|
19
|
-
FileMock.reset();
|
|
20
|
-
LogMock.reset();
|
|
21
|
-
|
|
22
19
|
File.mock();
|
|
23
20
|
Log.mock();
|
|
24
21
|
Shell.mock();
|
|
25
22
|
});
|
|
26
23
|
|
|
27
|
-
vi.mock('
|
|
28
|
-
const original = (await vi.importActual('
|
|
24
|
+
vi.mock('@noeldemartin/utils', async () => {
|
|
25
|
+
const original = (await vi.importActual('@noeldemartin/utils')) as object;
|
|
26
|
+
|
|
27
|
+
setupFacadeMocks();
|
|
28
|
+
|
|
29
|
+
return original;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
vi.mock('@aerogel/cli/lib/utils/app', async () => {
|
|
33
|
+
const original = (await vi.importActual('@aerogel/cli/lib/utils/app')) as object;
|
|
29
34
|
|
|
30
35
|
return {
|
|
31
36
|
...original,
|
|
@@ -34,8 +39,8 @@ vi.mock('@/lib/utils/app', async () => {
|
|
|
34
39
|
};
|
|
35
40
|
});
|
|
36
41
|
|
|
37
|
-
vi.mock('
|
|
38
|
-
const original = (await vi.importActual('
|
|
42
|
+
vi.mock('@aerogel/cli/lib/utils/edit', async () => {
|
|
43
|
+
const original = (await vi.importActual('@aerogel/cli/lib/utils/edit')) as object;
|
|
39
44
|
|
|
40
45
|
return {
|
|
41
46
|
...original,
|
|
@@ -43,9 +48,15 @@ vi.mock('@/lib/utils/edit', async () => {
|
|
|
43
48
|
};
|
|
44
49
|
});
|
|
45
50
|
|
|
51
|
+
vi.mock('simple-git', () => ({
|
|
52
|
+
simpleGit: () => ({
|
|
53
|
+
clone: () => Promise.resolve(),
|
|
54
|
+
}),
|
|
55
|
+
}));
|
|
56
|
+
|
|
46
57
|
// TODO find out why these need to be mocked
|
|
47
|
-
vi.mock('
|
|
48
|
-
const original = (await vi.importActual('
|
|
58
|
+
vi.mock('@aerogel/cli/lib/utils/paths', async () => {
|
|
59
|
+
const original = (await vi.importActual('@aerogel/cli/lib/utils/paths')) as object;
|
|
49
60
|
|
|
50
61
|
function basePath(path: string = '') {
|
|
51
62
|
return resolve(__dirname, '../../', path);
|
|
@@ -66,9 +77,3 @@ vi.mock('@/lib/utils/paths', async () => {
|
|
|
66
77
|
templatePath,
|
|
67
78
|
};
|
|
68
79
|
});
|
|
69
|
-
|
|
70
|
-
vi.mock('mustache', async () => {
|
|
71
|
-
const mustache = (await vi.importActual('mustache')) as { default: unknown };
|
|
72
|
-
|
|
73
|
-
return mustache.default;
|
|
74
|
-
});
|
package/.eslintrc.js
DELETED
package/bin/ag
DELETED
package/dist/aerogel-cli.cjs.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("commander"),t=require("@babel/runtime/helpers/defineProperty");require("core-js/modules/esnext.async-iterator.reduce.js"),require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.reduce.js");var i=require("@noeldemartin/utils"),s=require("fs"),n=require("path");require("core-js/modules/esnext.async-iterator.for-each.js"),require("core-js/modules/esnext.iterator.for-each.js"),require("core-js/modules/esnext.async-iterator.find.js"),require("core-js/modules/esnext.iterator.find.js"),require("core-js/modules/esnext.async-iterator.map.js"),require("core-js/modules/esnext.iterator.map.js");var r=require("chalk"),a=require("readline"),o=require("mustache");require("core-js/modules/esnext.set.add-all.js"),require("core-js/modules/esnext.set.delete-all.js"),require("core-js/modules/esnext.set.difference.js"),require("core-js/modules/esnext.set.every.js"),require("core-js/modules/esnext.set.filter.js"),require("core-js/modules/esnext.set.find.js"),require("core-js/modules/esnext.set.intersection.js"),require("core-js/modules/esnext.set.is-disjoint-from.js"),require("core-js/modules/esnext.set.is-subset-of.js"),require("core-js/modules/esnext.set.is-superset-of.js"),require("core-js/modules/esnext.set.join.js"),require("core-js/modules/esnext.set.map.js"),require("core-js/modules/esnext.set.reduce.js"),require("core-js/modules/esnext.set.some.js"),require("core-js/modules/esnext.set.symmetric-difference.js"),require("core-js/modules/esnext.set.union.js");var l=require("ts-morph"),c=require("child_process");function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("core-js/modules/esnext.async-iterator.some.js"),require("core-js/modules/esnext.iterator.some.js");var u=d(t);var p=i.facade(new class{contains(e,t){return!!this.read(e)?.includes(t)}exists(e){return s.existsSync(e)}isSymlink(e){return s.lstatSync(e).isSymbolicLink()}read(e){return this.isFile(e)?s.readFileSync(e).toString():null}getFiles(e){const t=s.readdirSync(e,{withFileTypes:!0}),i=[];for(const s of t){const t=n.resolve(e,s.name);s.isDirectory()?i.push(...this.getFiles(t)):i.push(t)}return i}isDirectory(e){return this.exists(e)&&s.lstatSync(e).isDirectory()}isFile(e){return this.exists(e)&&s.lstatSync(e).isFile()}isEmptyDirectory(e){return!!this.isDirectory(e)&&0===this.getFiles(e).length}makeDirectory(e){s.mkdirSync(e,{recursive:!0})}write(e,t){s.existsSync(n.dirname(e))||s.mkdirSync(n.dirname(e),{recursive:!0}),s.writeFileSync(e,t)}});var m=i.facade(new class{constructor(){u.default(this,"renderInfo",r.hex("#00ffff")),u.default(this,"renderSuccess",r.hex("#00ff00")),u.default(this,"renderError",r.hex("#ff0000"))}async animate(e,t){var i=this;const s=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const r=i.renderInfo(i.renderMarkdown(e)+(s?"...":".".repeat(n%4)))+t;i.stdout(r)};let n=0;s();const r=setInterval((()=>(n++,s())),1e3),a=await t();return clearInterval(r),s("\n",!0),a}info(e){this.log(this.renderMarkdown(e),this.renderInfo)}error(e){this.log(this.renderMarkdown(e),this.renderError)}fail(e){this.error(e),process.exit(1)}success(e){this.log(this.renderMarkdown(e),this.renderSuccess)}renderMarkdown(e){const t=i.stringMatchAll(e,/\*\*(.*)\*\*/g);for(const i of t)e=e.replace(i[0],r.bold(i[1]));return e}log(e,t){this.formatMessage(e).forEach((e=>{this.logLine(t?t(e):e)}))}formatMessage(e){if("\n"===e[0]){const t=(e=e.slice(1).trimEnd()).split("\n"),i=e.trim()[0]??"",s=t.find((e=>e.trim().length>0))?.indexOf(i)??0;return t.map((e=>e.slice(s)))}return[e]}logLine(e){console.log(e)}stdout(e){a.cursorTo(process.stdout,0),a.clearLine(process.stdout,0),process.stdout.write(e)}});class g{static instantiate(e,t,i){return new g(e).instantiate(t,i)}constructor(e){u.default(this,"path",void 0),this.path=e}instantiate(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=this.getFilenameReplacements(t),n=[];e=`${e}/`.replace(/\/\//,"/");for(const r of p.getFiles(this.path)){const a=Object.entries(i).reduce(((e,t)=>{let[i,s]=t;return e.replaceAll(i,s)}),r.substring(this.path.length+1)),l=s.readFileSync(r).toString(),c=e+(a.endsWith(".template")?a.slice(0,-9):a);p.write(c,o.render(l,t,void 0,["<%","%>"])),n.push(c)}return n}getFilenameReplacements(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return Object.entries(e).reduce(((e,s)=>{let[n,r]=s;return"object"==typeof r?Object.assign(e,this.getFilenameReplacements(r,`${n}.`)):e[`[${t}${n}]`]=i.toString(r),e}),{})}}function f(e){return m.fail(`Could not find ${e} pack file, did you run 'npm pack'?`)}function h(e){return p.getFiles(y(e)).find((e=>e.endsWith(".tgz")))??null}function y(e){return function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";if(p.contains(n.resolve(__dirname,"../../../package.json"),'"name": "aerogel"'))return n.resolve(__dirname,"../",e);const t=p.read(n.resolve(__dirname,"../../../../package.json")),s=i.stringMatch(t??"",/"@aerogel\/cli": "file:(.*)\/aerogel-cli-[\d.]*\.tgz"/),r=s?.[1]??m.fail("Could not determine base path");return n.resolve(r,e)}(`../${e}`)}function v(e){return n.resolve(__dirname,`../templates/${e}`)}var w=i.facade(new class{constructor(){u.default(this,"cwd",null)}setWorkingDirectory(e){this.cwd=e}async run(e){await new Promise(((t,i)=>{c.exec(e,{cwd:this.cwd??void 0},(e=>{e?i(e):t()}))}))}});class x{constructor(){u.default(this,"project",void 0),u.default(this,"modifiedFiles",void 0),this.project=new l.Project({tsConfigFilePath:"tsconfig.json"}),this.modifiedFiles=new Set,this.project.addSourceFilesAtPaths("src/**/*.ts"),this.project.addSourceFilesAtPaths("tailwind.config.js"),this.project.addSourceFilesAtPaths("vite.config.ts")}addSourceFile(e){this.project.addSourceFilesAtPaths(e)}requireSourceFile(e){return this.project.getSourceFileOrThrow(e)}async format(){await m.animate("Formatting modified files",(async()=>{const e=p.exists("prettier.config.js"),t=p.exists(".eslintrc.js");await Promise.all(i.arrayFrom(this.modifiedFiles).map((async i=>{e&&await w.run(`npx prettier ${i} --write`),t&&await w.run(`npx eslint ${i} --fix`)})))}))}async save(e){await e.save(),this.modifiedFiles.add(e.getFilePath())}}class j{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};u.default(this,"name",void 0),u.default(this,"options",void 0),this.name=e,this.options=t}create(e){!p.exists(e)||p.isDirectory(e)&&p.isEmptyDirectory(e)||m.fail(`Folder at '${e}' already exists!`),g.instantiate(v("app"),e,{app:{name:this.name,slug:i.stringToSlug(this.name)},dependencies:this.getDependencies(),contentPath:this.options.linkedLocal?`${y("core")}/dist/**/*.js`:"./node_modules/@aerogel/core/dist/**/*.js"})}edit(){return new x}getDependencies(){const e=e=>Object.entries(e).reduce(((e,t)=>{let[i,s]=t;return Object.assign(e,{[i]:`file:${s}`})}),{});return this.options.linkedLocal?e({aerogelCli:y("cli"),aerogelCore:y("core"),aerogelCypress:y("cypress"),aerogelPluginI18n:y("plugin-i18n"),aerogelPluginSoukai:y("plugin-soukai"),aerogelVite:y("vite")}):this.options.local?e({aerogelCli:h("cli")??f("cli"),aerogelCore:h("core")??f("core"),aerogelCypress:h("cypress")??f("cypress"),aerogelPluginI18n:h("plugin-i18n")??f("plugin-i18n"),aerogelPluginSoukai:h("plugin-soukai")??f("plugin-soukai"),aerogelVite:h("vite")??f("vite")}):{aerogelCli:"next",aerogelCore:"next",aerogelCypress:"next",aerogelPluginI18n:"next",aerogelPluginSoukai:"next",aerogelVite:"next"}}}class S{static define(e){var t=this;e=e.command(this.command).description(this.description);for(const[t,i]of this.parameters)e=e.argument(`<${t}>`,i);for(const[t,i]of Object.entries(this.options)){const s="string"==typeof i?i:i.description,n="string"==typeof i?"string":i.type??"string";e=e.option("boolean"===n?`--${t}`:`--${t} <${n}>`,s)}e=e.action((function(){for(var e=arguments.length,i=new Array(e),s=0;s<e;s++)i[s]=arguments[s];return t.run.call(t,...i)}))}static async run(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];const s=new this(...t);await s.run()}async run(){}assertAerogelOrDirectory(e){const t=p.read("package.json");if(t?.includes("@aerogel/core"))return;if(e&&p.isDirectory(e))return;const i=e?`${e} folder does not exist.`:"package.json does not contain @aerogel/core.";m.fail(`${i} Are you sure this is an Aerogel app?`)}}u.default(S,"command",""),u.default(S,"description",""),u.default(S,"parameters",[]),u.default(S,"options",{});class $ extends S{constructor(e,t){super(),u.default(this,"path",void 0),u.default(this,"options",void 0),this.path=e,this.options=t}async run(){const e=this.path,t=this.options.name??"Aerogel App";w.setWorkingDirectory(e),await this.createApp(t,e),await this.installDependencies(),await this.initializeGit(),m.success(`\n\n That's it! You can start working on **${t}** doing the following:\n\n cd ${e}\n npm run dev\n\n Have fun!\n `)}async createApp(e,t){m.info(`Creating **${e}**...`),new j(e,{local:this.options.local,linkedLocal:this.options.local&&!this.options.copy}).create(t)}async installDependencies(){await m.animate("Installing dependencies",(async()=>{await w.run("npm install")}))}async initializeGit(){await m.animate("Initializing git",(async()=>{await w.run("git init"),await w.run("git add ."),await w.run('git commit -m "Start"')}))}}function k(){return new j("")}function C(){return p.isSymlink("node_modules/@aerogel/core")}function A(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e)return;const s=t.guard??(()=>!0),n=t.validate??(()=>!0),r=i.arrayFrom(t.skip??[]);return e.forEachDescendant(((e,t)=>{if(s(e)&&n(e))return e;const i=e.getKind();r.includes(i)&&t.skip()}))}function F(e,t){if(e&&t(e))return e}u.default($,"command","create"),u.default($,"description","Create AerogelJS app"),u.default($,"parameters",[["path","Application path"]]),u.default($,"options",{name:"Application name",local:{type:"boolean",description:"Whether to create an app using local Aerogel packages (used for core development)"},copy:{type:"boolean",description:"Whether to create an app linked to local Aerogel packages (used in CI)"}});class q extends S{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),u.default(this,"path",void 0),u.default(this,"options",void 0),this.path=e,this.options=t}async run(){this.assertAerogelOrDirectory("src/components"),this.assertHistoireInstalled();const e=new Set,[t,s]=this.parsePathComponents();await this.createComponent(t,s,e),await this.createStory(s,e),await this.declareComponents();const n=i.arrayFrom(e).map((e=>`- ${e}`)).join("\n");m.info(`${s} component created successfully! The following files were created:\n\n${n}`)}assertHistoireInstalled(){this.options.story&&(p.exists("src/main.histoire.ts")||m.fail("Histoire is not installed yet!"))}async createComponent(e,t,i){await m.animate("Creating component",(async()=>{p.exists(`src/components/${this.path}.vue`)&&m.fail(`${this.path} component already exists!`);g.instantiate(v("component"),`src/components/${e}`,{component:{name:t}}).forEach((e=>i.add(e)))}))}async createStory(e,t){this.options.story&&await m.animate("Creating story",(async()=>{g.instantiate(v("component-story"),"src/components",{component:{name:e}}).forEach((e=>t.add(e)))}))}async declareComponents(){const e=k().edit(),t=e.requireSourceFile("vite.config.ts"),i=this.getComponentDirsArray(t);if(!i)return m.fail("Could not find component dirs declaration in vite config!");i.getDescendantsOfKind(l.SyntaxKind.StringLiteral).some((e=>"'src/components'"===e.getText()))||(await m.animate("Updating vite config",(async()=>{i.addElement("'src/components'"),await e.save(t)})),await e.format())}getComponentDirsArray(e){const t=A(e,{guard:l.Node.isCallExpression,validate:e=>e.getText().startsWith("Components("),skip:l.SyntaxKind.ImportDeclaration});if(!t)return null;const i=A(t,{guard:l.Node.isPropertyAssignment,validate:e=>"dirs"===e.getName()}),s=i?.getInitializer();return l.Node.isArrayLiteralExpression(s)?s:this.declareComponentDirsArray(t)}declareComponentDirsArray(e){const t=A(e,{guard:l.Node.isObjectLiteralExpression}),i=t?.addPropertyAssignment({name:"dirs",initializer:"[]"});return i?.getInitializer()??null}parsePathComponents(){const e=this.path.lastIndexOf("/");return-1===e?["",this.path]:[this.path.substring(0,e),this.path.substring(e+1)]}}function D(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=e.split("\n"),s=t.indent??0;let n=0,r="";for(const e of i){const t=e.trim(),i=0===t.length;if(0===r.length){if(i)continue;n=e.indexOf(t[0]??""),r+=`${" ".repeat(s)}${t}\n`;continue}if(i){r+="\n";continue}const a=e.indexOf(t[0]??"");r+=`${" ".repeat(s+a-n)}${t}\n`}return r.trimEnd()}u.default(q,"command","generate:component"),u.default(q,"description","Generate an AerogelJS Component"),u.default(q,"parameters",[["path","Component path (relative to components folder; extension not necessary)"]]),u.default(q,"options",{story:{description:"Create component story using Histoire",type:"boolean"}});class I extends S{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),u.default(this,"name",void 0),u.default(this,"options",void 0),this.name=e,this.options=t}async run(){this.assertAerogelOrDirectory("src/models"),p.exists(`src/models/${this.name}.ts`)&&m.fail(`${this.name} model already exists!`),this.assertSoukaiInstalled();const e=await m.animate("Creating model",(async()=>g.instantiate(v("model"),"src/models",{model:{name:this.name,fieldsDefinition:this.getFieldsDefinition()},soukaiImports:this.options.fields?"FieldType, defineModelSchema":"defineModelSchema"}).map((e=>`- ${e}`)).join("\n")));m.info(`${this.name} model created successfully! The following files were created:\n\n${e}`)}getFieldsDefinition(){if(!this.options.fields)return" //";const e=this.options.fields.split(",").map((e=>{const[t,s,n]=e.split(":");return{name:t,type:i.stringToStudlyCase(s??"string"),required:"required"===n}})).reduce(((e,t)=>e+`\n${t.required?D(`\n ${t.name}: {\n type: FieldType.${t.type},\n required: true,\n }\n `):`${t.name}: FieldType.${t.type}`},`),"");return D(e,{indent:8})}assertSoukaiInstalled(){p.contains("package.json",'"soukai"')||p.contains("package.json",'"@aerogel/plugin-soukai"')||m.fail("\n Soukai is not installed yet! You can install it running:\n npx ag install soukai\n ")}}u.default(I,"command","generate:model"),u.default(I,"description","Generate an AerogelJS Model"),u.default(I,"parameters",[["name","Model name"]]),u.default(I,"options",{fields:"Create model with the given fields"});class P extends S{constructor(e){super(),u.default(this,"name",void 0),this.name=e}async run(){this.assertAerogelOrDirectory("src/services");const e=new Set,t=k().edit();await this.createService(e),await this.registerService(t),await t.format();const s=i.arrayFrom(e).map((e=>`- ${e}`)).join("\n");m.info(`${this.name} service created successfully! The following files were created:\n\n${s}`)}async createService(e){await m.animate("Creating service",(async()=>{p.exists(`src/services/${this.name}.ts`)&&m.fail(`${this.name} service already exists!`);g.instantiate(v("service"),"src/services",{service:{name:this.name}}).forEach((t=>e.add(t)))}))}async registerService(e){await m.animate("Registering service",(async()=>{p.exists("src/services/index.ts")||await this.createServicesIndex(e);const t=e.requireSourceFile("src/services/index.ts"),s=this.getServicesObject(t);if(!s)return m.fail("Could not find services object in services config, please add it manually.");t.addImportDeclaration({defaultImport:this.name,moduleSpecifier:`./${this.name}`}),s.addPropertyAssignment({name:`$${i.stringToCamelCase(this.name)}`,initializer:this.name}),await e.save(t)}))}async createServicesIndex(e){p.write("src/services/index.ts",D("\n export const services = {};\n\n export type AppServices = typeof services;\n\n declare module '@vue/runtime-core' {\n interface ComponentCustomProperties extends AppServices {}\n }\n ")),e.addSourceFile("src/services/index.ts");const t=e.requireSourceFile("src/main.ts"),i=this.getBootstrapOptions(t);if(!i)return m.fail("Could not find options object in bootstrap config, please add the services manually.");i.insertShorthandPropertyAssignment(0,{name:"services"}),t.addImportDeclaration({namedImports:["services"],moduleSpecifier:"./services"}),await e.save(t)}getBootstrapOptions(e){const t=A(e,{guard:l.Node.isCallExpression,validate:e=>"bootstrapApplication"===e.getExpression().getText(),skip:l.SyntaxKind.ImportDeclaration}),i=t?.getArguments()[1];return l.Node.isObjectLiteralExpression(i)?i:null}getServicesObject(e){const t=A(e,{guard:l.Node.isVariableDeclaration,validate:e=>"services"===e.getName()}),i=t?.getInitializer();return l.Node.isObjectLiteralExpression(i)?i:null}}u.default(P,"command","generate:service"),u.default(P,"description","Generate an AerogelJS Service"),u.default(P,"parameters",[["name","Service name"]]);class b{constructor(e){u.default(this,"name",void 0),this.name=e}async install(){this.assertNotInstalled(),await this.installDependencies();{const e=k().edit();await this.updateFiles(e),await e.format()}m.info(`Plugin ${this.name} installed!`)}assertNotInstalled(){p.contains("package.json",`"${this.getNpmPackageName()}"`)&&m.fail(`${this.name} is already installed!`)}async installDependencies(){await m.animate("Installing plugin dependencies",(async()=>{await this.installNpmDependencies()}))}async updateFiles(e){await this.updateBootstrapConfig(e)}async installNpmDependencies(){if(C())await w.run(`npm install file:${y(this.getLocalPackageName())}`);else if(p.contains("package.json","file")){const e=h(this.getLocalPackageName())??f(this.getLocalPackageName());await w.run(`npm install file:${e}`)}else await w.run(`npm install ${this.getNpmPackageName()}@next`)}async updateBootstrapConfig(e){await m.animate("Injecting plugin in bootstrap configuration",(async()=>{const t=e.requireSourceFile("src/main.ts"),i=this.getBootstrapPluginsDeclaration(t);if(!i)return m.fail(`\n Could not find plugins array in bootstrap config, please add the following manually:\n\n ${this.getBootstrapConfig()}\n `);t.addImportDeclaration(this.getBootstrapImport()),i.addElement(this.getBootstrapConfig()),await e.save(t)}))}getBootstrapPluginsDeclaration(e){const t=A(e,{guard:l.Node.isCallExpression,validate:e=>"bootstrapApplication"===e.getExpression().getText(),skip:l.SyntaxKind.ImportDeclaration}),i=t?.getArguments()[1],s=F(i,l.Node.isObjectLiteralExpression)?.getProperty("plugins"),n=F(s,l.Node.isPropertyAssignment)?.getInitializer();return l.Node.isArrayLiteralExpression(n)?n:null}getBootstrapImport(){return{defaultImport:this.name,moduleSpecifier:`@aerogel/plugin-${this.name}`}}getNpmPackageName(){return`@aerogel/${this.getLocalPackageName()}`}getLocalPackageName(){return`plugin-${this.name}`}getBootstrapConfig(){return`${this.name}()`}}const N=[new class extends b{constructor(){super("soukai")}async installNpmDependencies(){await w.run("npm install soukai@next"),await super.installNpmDependencies()}getBootstrapConfig(){return"soukai({ models: import.meta.glob('@/models/*', { eager: true }) })"}},new class extends b{constructor(){super("solid")}async updateFiles(e){await this.updateTailwindConfig(e),await super.updateFiles(e)}async installNpmDependencies(){await w.run("npm install soukai-solid@next"),await super.installNpmDependencies()}async updateTailwindConfig(e){await m.animate("Updating tailwind configuration",(async()=>{const t=e.requireSourceFile("tailwind.config.js"),i=this.getTailwindContentArray(t),s=C()?`'${y("plugin-solid")}/dist/**/*.js'`:"'./node_modules/@aerogel/plugin-solid/dist/**/*.js'";if(!i)return m.fail(`\n Could not find content array in tailwind config, please add the following manually:\n\n ${s}\n `);i.addElement(s),await e.save(t)}))}getTailwindContentArray(e){const t=A(e,{guard:l.Node.isPropertyAssignment,validate:e=>"content"===e.getName(),skip:l.SyntaxKind.JSDoc}),i=t?.getInitializer();return l.Node.isArrayLiteralExpression(i)?i:null}}].reduce(((e,t)=>Object.assign(e,{[t.name]:t})),{});class O extends S{constructor(e){super(),u.default(this,"plugin",void 0),this.plugin=N[e]??m.fail(`Plugin '${e}' doesn't exist. Available plugins: ${Object.keys(N).join(", ")}`)}async run(){await this.plugin.install()}}u.default(O,"command","install"),u.default(O,"description","Install an AerogelJS plugin"),u.default(O,"parameters",[["plugin","Plugin to install"]]);var E=i.facade(new class{run(t){const i=new e.Command;i.name("ag").description("AerogelJS CLI").version("0.0.0"),$.define(i),q.define(i),I.define(i),P.define(i),O.define(i),i.parse(t)}});exports.CLI=E;
|
|
2
|
-
//# sourceMappingURL=aerogel-cli.cjs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aerogel-cli.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|