@aerogel/cli 0.0.0-next.0be1479064cfd43fb6eafa2552cb7f8775554d93
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/.eslintrc.js +7 -0
- package/bin/ag +4 -0
- package/dist/aerogel-cli.cjs.js +2 -0
- package/dist/aerogel-cli.cjs.js.map +1 -0
- package/dist/aerogel-cli.d.ts +10 -0
- package/dist/aerogel-cli.esm.js +2 -0
- package/dist/aerogel-cli.esm.js.map +1 -0
- package/noeldemartin.config.js +14 -0
- package/package.json +47 -0
- package/src/cli.ts +27 -0
- package/src/commands/Command.ts +59 -0
- package/src/commands/create.test.ts +34 -0
- package/src/commands/create.ts +84 -0
- package/src/commands/generate-component.test.ts +44 -0
- package/src/commands/generate-component.ts +174 -0
- package/src/commands/generate-model.test.ts +45 -0
- package/src/commands/generate-model.ts +99 -0
- package/src/commands/generate-service.test.ts +21 -0
- package/src/commands/generate-service.ts +152 -0
- package/src/commands/install.test.ts +18 -0
- package/src/commands/install.ts +32 -0
- package/src/lib/App.ts +87 -0
- package/src/lib/Editor.ts +51 -0
- package/src/lib/File.mock.ts +66 -0
- package/src/lib/File.ts +76 -0
- package/src/lib/Log.mock.ts +37 -0
- package/src/lib/Log.test.ts +37 -0
- package/src/lib/Log.ts +95 -0
- package/src/lib/Shell.mock.ts +20 -0
- package/src/lib/Shell.ts +28 -0
- package/src/lib/Template.ts +56 -0
- package/src/lib/utils/app.ts +15 -0
- package/src/lib/utils/edit.ts +44 -0
- package/src/lib/utils/format.test.ts +33 -0
- package/src/lib/utils/format.ts +38 -0
- package/src/lib/utils/paths.ts +34 -0
- package/src/main.ts +3 -0
- package/src/plugins/Plugin.ts +125 -0
- package/src/plugins/Solid.ts +65 -0
- package/src/plugins/Soukai.ts +19 -0
- package/src/testing/setup.ts +74 -0
- package/src/types/ts-reset.d.ts +1 -0
- package/templates/app/.eslintrc.js +3 -0
- package/templates/app/.github/workflows/ci.yml +17 -0
- package/templates/app/.gitignore.template +2 -0
- package/templates/app/.nvmrc +1 -0
- package/templates/app/.vscode/launch.json +16 -0
- package/templates/app/.vscode/settings.json +10 -0
- package/templates/app/cypress/e2e/app.cy.ts +9 -0
- package/templates/app/cypress/support/e2e.ts +3 -0
- package/templates/app/cypress/tsconfig.json +12 -0
- package/templates/app/cypress.config.ts +12 -0
- package/templates/app/index.html +12 -0
- package/templates/app/package.json +54 -0
- package/templates/app/postcss.config.js +6 -0
- package/templates/app/prettier.config.js +5 -0
- package/templates/app/src/App.vue +12 -0
- package/templates/app/src/assets/styles.css +3 -0
- package/templates/app/src/lang/en.yaml +3 -0
- package/templates/app/src/main.test.ts +9 -0
- package/templates/app/src/main.ts +13 -0
- package/templates/app/src/types/globals.d.ts +2 -0
- package/templates/app/src/types/shims.d.ts +7 -0
- package/templates/app/src/types/ts-reset.d.ts +1 -0
- package/templates/app/tailwind.config.js +5 -0
- package/templates/app/tsconfig.json +18 -0
- package/templates/app/vite.config.ts +23 -0
- package/templates/component/[component.name].vue +3 -0
- package/templates/component-story/[component.name].story.vue +7 -0
- package/templates/model/[model.name].schema.ts +7 -0
- package/templates/model/[model.name].ts +3 -0
- package/templates/service/[service.name].ts +8 -0
- package/tsconfig.json +11 -0
- package/vite.config.ts +14 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { bold, hex } from 'chalk';
|
|
2
|
+
import { describe, it } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import LogMock from '@/lib/Log.mock';
|
|
5
|
+
|
|
6
|
+
import Log from './Log';
|
|
7
|
+
|
|
8
|
+
const info = hex('#00ffff');
|
|
9
|
+
|
|
10
|
+
describe('Log', () => {
|
|
11
|
+
|
|
12
|
+
it('renders markdown bold', () => {
|
|
13
|
+
// Act
|
|
14
|
+
Log.info('Foo **bar**');
|
|
15
|
+
|
|
16
|
+
// Assert
|
|
17
|
+
LogMock.expectLogged(info(`Foo ${bold('bar')}`));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('renders multiline messages', () => {
|
|
21
|
+
// Act
|
|
22
|
+
Log.info(`
|
|
23
|
+
This is multiline,
|
|
24
|
+
but the indentation should be respected.
|
|
25
|
+
|
|
26
|
+
As well as the new lines.
|
|
27
|
+
`);
|
|
28
|
+
|
|
29
|
+
// Assert
|
|
30
|
+
LogMock.expectLogLength(4);
|
|
31
|
+
LogMock.expectLogged(info('This is multiline,'));
|
|
32
|
+
LogMock.expectLogged(info(' but the indentation should be respected.'));
|
|
33
|
+
LogMock.expectLogged(info(''));
|
|
34
|
+
LogMock.expectLogged(info('As well as the new lines.'));
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
});
|
package/src/lib/Log.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { facade, stringMatchAll } from '@noeldemartin/utils';
|
|
2
|
+
import { bold, hex } from 'chalk';
|
|
3
|
+
import { clearLine, cursorTo } from 'readline';
|
|
4
|
+
|
|
5
|
+
export class LogService {
|
|
6
|
+
|
|
7
|
+
protected renderInfo = hex('#00ffff');
|
|
8
|
+
protected renderSuccess = hex('#00ff00');
|
|
9
|
+
protected renderError = hex('#ff0000');
|
|
10
|
+
|
|
11
|
+
public async animate<T>(message: string, operation: () => Promise<T>): Promise<T> {
|
|
12
|
+
const updateStdout = (end: string = '', done: boolean = false) => {
|
|
13
|
+
const progress =
|
|
14
|
+
this.renderInfo(this.renderMarkdown(message) + (done ? '...' : '.'.repeat(frame % 4))) + end;
|
|
15
|
+
|
|
16
|
+
this.stdout(progress);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
let frame = 0;
|
|
20
|
+
|
|
21
|
+
updateStdout();
|
|
22
|
+
|
|
23
|
+
const interval = setInterval(() => (frame++, updateStdout()), 1000);
|
|
24
|
+
const result = await operation();
|
|
25
|
+
|
|
26
|
+
clearInterval(interval);
|
|
27
|
+
updateStdout('\n', true);
|
|
28
|
+
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public info(message: string): void {
|
|
33
|
+
this.log(this.renderMarkdown(message), this.renderInfo);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public error(message: string): void {
|
|
37
|
+
this.log(this.renderMarkdown(message), this.renderError);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
+
public fail<T = any>(message: string): T {
|
|
42
|
+
this.error(message);
|
|
43
|
+
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public success(message: string): void {
|
|
48
|
+
this.log(this.renderMarkdown(message), this.renderSuccess);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
protected renderMarkdown(message: string): string {
|
|
52
|
+
const matches = stringMatchAll<2>(message, /\*\*(.*)\*\*/g);
|
|
53
|
+
|
|
54
|
+
for (const match of matches) {
|
|
55
|
+
message = message.replace(match[0], bold(match[1]));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return message;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected log(message: string, formatMessage?: (message: string) => string): void {
|
|
62
|
+
this.formatMessage(message).forEach((line) => {
|
|
63
|
+
this.logLine(formatMessage ? formatMessage(line) : line);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
protected formatMessage(message: string): string[] {
|
|
68
|
+
if (message[0] === '\n') {
|
|
69
|
+
message = message.slice(1).trimEnd();
|
|
70
|
+
|
|
71
|
+
const lines = message.split('\n');
|
|
72
|
+
const firstLetter = message.trim()[0] ?? '';
|
|
73
|
+
const indentation = lines.find((line) => line.trim().length > 0)?.indexOf(firstLetter) ?? 0;
|
|
74
|
+
|
|
75
|
+
return lines.map((line) => line.slice(indentation));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return [message];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
protected logLine(line: string): void {
|
|
82
|
+
// eslint-disable-next-line no-console
|
|
83
|
+
console.log(line);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
protected stdout(message: string): void {
|
|
87
|
+
cursorTo(process.stdout, 0);
|
|
88
|
+
clearLine(process.stdout, 0);
|
|
89
|
+
|
|
90
|
+
process.stdout.write(message);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export default facade(new LogService());
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { expect } from 'vitest';
|
|
2
|
+
import { facade } from '@noeldemartin/utils';
|
|
3
|
+
|
|
4
|
+
import { ShellService } from './Shell';
|
|
5
|
+
|
|
6
|
+
export class ShellServiceMock extends ShellService {
|
|
7
|
+
|
|
8
|
+
private history: string[] = [];
|
|
9
|
+
|
|
10
|
+
public async run(command: string): Promise<void> {
|
|
11
|
+
this.history.push(command);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public expectRan(command: string): void {
|
|
15
|
+
expect(this.history, `expected '${command}' command to have been executed`).toContain(command);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default facade(new ShellServiceMock());
|
package/src/lib/Shell.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { exec } from 'child_process';
|
|
2
|
+
import { facade } from '@noeldemartin/utils';
|
|
3
|
+
|
|
4
|
+
export class ShellService {
|
|
5
|
+
|
|
6
|
+
private cwd: string | null = null;
|
|
7
|
+
|
|
8
|
+
public setWorkingDirectory(cwd: string): void {
|
|
9
|
+
this.cwd = cwd;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public async run(command: string): Promise<void> {
|
|
13
|
+
await new Promise<void>((resolve, reject) => {
|
|
14
|
+
exec(command, { cwd: this.cwd ?? undefined }, (error) => {
|
|
15
|
+
if (error) {
|
|
16
|
+
reject(error);
|
|
17
|
+
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
resolve();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default facade(new ShellService());
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { render } from 'mustache';
|
|
3
|
+
import { toString } from '@noeldemartin/utils';
|
|
4
|
+
|
|
5
|
+
import File from '@/lib/File';
|
|
6
|
+
|
|
7
|
+
export default class Template {
|
|
8
|
+
|
|
9
|
+
public static instantiate(path: string, destination: string, replacements: Record<string, unknown>): string[] {
|
|
10
|
+
const template = new Template(path);
|
|
11
|
+
|
|
12
|
+
return template.instantiate(destination, replacements);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
constructor(public path: string) {}
|
|
16
|
+
|
|
17
|
+
public instantiate(destination: string, replacements: Record<string, unknown> = {}): string[] {
|
|
18
|
+
const filenameReplacements = this.getFilenameReplacements(replacements);
|
|
19
|
+
const files: string[] = [];
|
|
20
|
+
destination = `${destination}/`.replace(/\/\//, '/');
|
|
21
|
+
|
|
22
|
+
for (const file of File.getFiles(this.path)) {
|
|
23
|
+
const relativePath = Object.entries(filenameReplacements).reduce(
|
|
24
|
+
(path, [match, replacement]) => path.replaceAll(match, replacement),
|
|
25
|
+
file.substring(this.path.length + 1),
|
|
26
|
+
);
|
|
27
|
+
const fileContents = readFileSync(file).toString();
|
|
28
|
+
const filePath =
|
|
29
|
+
destination + (relativePath.endsWith('.template') ? relativePath.slice(0, -9) : relativePath);
|
|
30
|
+
|
|
31
|
+
File.write(filePath, render(fileContents, replacements, undefined, ['<%', '%>']));
|
|
32
|
+
files.push(filePath);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return files;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
protected getFilenameReplacements(
|
|
39
|
+
replacements: Record<string, unknown>,
|
|
40
|
+
prefix: string = '',
|
|
41
|
+
): Record<string, string> {
|
|
42
|
+
return Object.entries(replacements).reduce((filenameReplacements, [key, value]) => {
|
|
43
|
+
if (typeof value === 'object') {
|
|
44
|
+
Object.assign(
|
|
45
|
+
filenameReplacements,
|
|
46
|
+
this.getFilenameReplacements(value as Record<string, unknown>, `${key}.`),
|
|
47
|
+
);
|
|
48
|
+
} else {
|
|
49
|
+
filenameReplacements[`[${prefix}${key}]`] = toString(value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return filenameReplacements;
|
|
53
|
+
}, {} as Record<string, string>);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import App from '@/lib/App';
|
|
2
|
+
import File from '@/lib/File';
|
|
3
|
+
|
|
4
|
+
export function app(): App {
|
|
5
|
+
// TODO parse app name
|
|
6
|
+
return new App('');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function isLocalApp(): boolean {
|
|
10
|
+
return File.contains('package.json', 'file');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function isLinkedLocalApp(): boolean {
|
|
14
|
+
return File.isSymlink('node_modules/@aerogel/core');
|
|
15
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { arrayFrom } from '@noeldemartin/utils';
|
|
2
|
+
import type { Node, SyntaxKind } from 'ts-morph';
|
|
3
|
+
|
|
4
|
+
export function editFiles(): boolean {
|
|
5
|
+
// TODO mock editor instead of relying on this for unit tests
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function findDescendant<T extends Node>(
|
|
10
|
+
node: Node | undefined,
|
|
11
|
+
options: {
|
|
12
|
+
guard?: (node: Node | undefined) => node is T;
|
|
13
|
+
validate?: (node: T) => boolean;
|
|
14
|
+
skip?: SyntaxKind | SyntaxKind[];
|
|
15
|
+
} = {},
|
|
16
|
+
): T | undefined {
|
|
17
|
+
if (!node) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const guard = options.guard ?? (() => true);
|
|
22
|
+
const validate = options.validate ?? (() => true);
|
|
23
|
+
const skipKinds = arrayFrom(options.skip ?? []);
|
|
24
|
+
|
|
25
|
+
return node.forEachDescendant((descendant, traversal) => {
|
|
26
|
+
if (guard(descendant) && validate(descendant)) {
|
|
27
|
+
return descendant;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const descendantKind = descendant.getKind();
|
|
31
|
+
|
|
32
|
+
if (skipKinds.includes(descendantKind)) {
|
|
33
|
+
traversal.skip();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function when<T extends Node>(node: Node | undefined, assertion: (node: Node) => node is T): T | undefined {
|
|
39
|
+
if (!node || !assertion(node)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return node as T;
|
|
44
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { formatCodeBlock } from './format';
|
|
4
|
+
|
|
5
|
+
describe('Format utils', () => {
|
|
6
|
+
|
|
7
|
+
it('Formats code blocks', () => {
|
|
8
|
+
// Arrange
|
|
9
|
+
const raw = `
|
|
10
|
+
|
|
11
|
+
const foo = 'bar';
|
|
12
|
+
|
|
13
|
+
if (foo) {
|
|
14
|
+
doSomething();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
`;
|
|
18
|
+
const formatted = [
|
|
19
|
+
'const foo = \'bar\';', //
|
|
20
|
+
'', //
|
|
21
|
+
'if (foo) {', //
|
|
22
|
+
' doSomething();', //
|
|
23
|
+
'}', //
|
|
24
|
+
].join('\n');
|
|
25
|
+
|
|
26
|
+
// Act
|
|
27
|
+
const actual = formatCodeBlock(raw);
|
|
28
|
+
|
|
29
|
+
// Assert
|
|
30
|
+
expect(actual).toEqual(formatted);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface FormatCodeBlockOptions {
|
|
2
|
+
indent?: number;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function formatCodeBlock(code: string, options: FormatCodeBlockOptions = {}): string {
|
|
6
|
+
const lines = code.split('\n');
|
|
7
|
+
const indent = options.indent ?? 0;
|
|
8
|
+
let originalIndent = 0;
|
|
9
|
+
let formatted = '';
|
|
10
|
+
|
|
11
|
+
for (const line of lines) {
|
|
12
|
+
const trimmedLine = line.trim();
|
|
13
|
+
const isEmptyLine = trimmedLine.length === 0;
|
|
14
|
+
|
|
15
|
+
if (formatted.length === 0) {
|
|
16
|
+
if (isEmptyLine) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
originalIndent = line.indexOf(trimmedLine[0] ?? '');
|
|
21
|
+
formatted += `${' '.repeat(indent)}${trimmedLine}\n`;
|
|
22
|
+
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (isEmptyLine) {
|
|
27
|
+
formatted += '\n';
|
|
28
|
+
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const lineIndent = line.indexOf(trimmedLine[0] ?? '');
|
|
33
|
+
|
|
34
|
+
formatted += `${' '.repeat(indent + lineIndent - originalIndent)}${trimmedLine}\n`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return formatted.trimEnd();
|
|
38
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { stringMatch } from '@noeldemartin/utils';
|
|
3
|
+
|
|
4
|
+
import File from '@/lib/File';
|
|
5
|
+
import Log from '@/lib/Log';
|
|
6
|
+
|
|
7
|
+
export function basePath(path: string = ''): string {
|
|
8
|
+
if (File.contains(resolve(__dirname, '../../../package.json'), '"name": "aerogel"')) {
|
|
9
|
+
return cliBasePath(path);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const packageJson = File.read(resolve(__dirname, '../../../../package.json'));
|
|
13
|
+
const matches = stringMatch<2>(packageJson ?? '', /"@aerogel\/cli": "file:(.*)\/aerogel-cli-[\d.]*\.tgz"/);
|
|
14
|
+
const cliPath = matches?.[1] ?? Log.fail<string>('Could not determine base path');
|
|
15
|
+
|
|
16
|
+
return resolve(cliPath, path);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function cliBasePath(path: string = ''): string {
|
|
20
|
+
return resolve(__dirname, '../', path);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
+
export function packNotFound(packageName: string): any {
|
|
25
|
+
return Log.fail(`Could not find ${packageName} pack file, did you run 'npm pack'?`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function packagePackPath(packageName: string): string | null {
|
|
29
|
+
return File.getFiles(packagePath(packageName)).find((file) => file.endsWith('.tgz')) ?? null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function packagePath(packageName: string): string {
|
|
33
|
+
return basePath(`../${packageName}`);
|
|
34
|
+
}
|
package/src/main.ts
ADDED
|
@@ -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
|
+
}
|