@aerogel/cli 0.0.0-next.926bde19326fe7b6b24b277666936862b64d8295 → 0.0.0-next.b58141fee5d2fe7d25debdbca6b1d2bf1c13e48e
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/dist/aerogel-cli.cjs.js +1 -1
- package/dist/aerogel-cli.cjs.js.map +1 -1
- package/dist/aerogel-cli.esm.js +1 -1
- package/dist/aerogel-cli.esm.js.map +1 -1
- package/package.json +4 -3
- package/src/cli.ts +4 -0
- package/src/commands/create.test.ts +22 -4
- package/src/commands/create.ts +21 -4
- package/src/commands/generate-component.test.ts +12 -1
- package/src/commands/generate-component.ts +127 -20
- package/src/commands/generate-model.test.ts +7 -4
- package/src/commands/generate-model.ts +30 -20
- 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 +65 -3
- package/src/lib/Editor.ts +56 -0
- package/src/lib/File.ts +6 -0
- package/src/lib/Log.mock.ts +2 -1
- package/src/lib/Log.ts +6 -4
- package/src/lib/utils/app.ts +15 -0
- package/src/lib/utils/edit.ts +44 -0
- package/src/lib/{utils.test.ts → utils/format.test.ts} +2 -2
- package/src/lib/{utils.ts → utils/format.ts} +0 -6
- package/src/lib/utils/paths.ts +34 -0
- package/src/plugins/Plugin.ts +125 -0
- package/src/plugins/Solid.ts +114 -0
- package/src/plugins/Soukai.ts +19 -0
- package/src/testing/setup.ts +36 -6
- package/templates/app/.eslintrc.js +3 -0
- package/templates/app/.github/workflows/ci.yml +14 -2
- package/templates/app/.vscode/launch.json +16 -0
- package/templates/app/.vscode/settings.json +10 -0
- package/templates/app/README.md +3 -0
- package/templates/app/cypress.config.ts +8 -0
- package/templates/app/index.html +1 -1
- package/templates/app/package.json +20 -7
- package/templates/app/prettier.config.js +5 -0
- package/templates/app/src/App.vue +3 -1
- package/templates/app/src/main.ts +5 -1
- package/templates/app/src/types/globals.d.ts +0 -1
- package/templates/app/tailwind.config.js +1 -1
- package/templates/app/tsconfig.json +1 -0
- package/templates/app/vite.config.ts +12 -5
- package/templates/service/[service.name].ts +8 -0
- package/noeldemartin.config.js +0 -4
package/src/lib/App.ts
CHANGED
|
@@ -3,23 +3,85 @@ import { stringToSlug } from '@noeldemartin/utils';
|
|
|
3
3
|
import File from '@/lib/File';
|
|
4
4
|
import Log from '@/lib/Log';
|
|
5
5
|
import Template from '@/lib/Template';
|
|
6
|
-
import {
|
|
6
|
+
import { packNotFound, packagePackPath, packagePath, templatePath } from '@/lib/utils/paths';
|
|
7
|
+
import { Editor } from '@/lib/Editor';
|
|
8
|
+
|
|
9
|
+
interface Dependencies {
|
|
10
|
+
aerogelCli: string;
|
|
11
|
+
aerogelCore: string;
|
|
12
|
+
aerogelCypress: string;
|
|
13
|
+
aerogelPluginI18n: string;
|
|
14
|
+
aerogelPluginSoukai: string;
|
|
15
|
+
aerogelVite: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface Options {
|
|
19
|
+
local?: boolean;
|
|
20
|
+
linkedLocal?: boolean;
|
|
21
|
+
}
|
|
7
22
|
|
|
8
23
|
export default class App {
|
|
9
24
|
|
|
10
|
-
constructor(
|
|
25
|
+
constructor(protected name: string, protected options: Options = {}) {}
|
|
11
26
|
|
|
12
27
|
public create(path: string): void {
|
|
13
28
|
if (File.exists(path) && (!File.isDirectory(path) || !File.isEmptyDirectory(path))) {
|
|
14
29
|
Log.fail(`Folder at '${path}' already exists!`);
|
|
15
30
|
}
|
|
16
31
|
|
|
17
|
-
Template.instantiate(
|
|
32
|
+
Template.instantiate(templatePath('app'), path, {
|
|
18
33
|
app: {
|
|
19
34
|
name: this.name,
|
|
20
35
|
slug: stringToSlug(this.name),
|
|
21
36
|
},
|
|
37
|
+
dependencies: this.getDependencies(),
|
|
38
|
+
contentPath: this.options.linkedLocal
|
|
39
|
+
? `${packagePath('core')}/dist/**/*.js`
|
|
40
|
+
: './node_modules/@aerogel/core/dist/**/*.js',
|
|
22
41
|
});
|
|
23
42
|
}
|
|
24
43
|
|
|
44
|
+
public edit(): Editor {
|
|
45
|
+
return new Editor();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
protected getDependencies(): Dependencies {
|
|
49
|
+
const withFilePrefix = <T extends Record<string, string>>(paths: T) =>
|
|
50
|
+
Object.entries(paths).reduce(
|
|
51
|
+
(pathsWithFile, [name, path]) => Object.assign(pathsWithFile, { [name]: `file:${path}` }) as T,
|
|
52
|
+
{} as T,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
if (this.options.linkedLocal) {
|
|
56
|
+
return withFilePrefix({
|
|
57
|
+
aerogelCli: packagePath('cli'),
|
|
58
|
+
aerogelCore: packagePath('core'),
|
|
59
|
+
aerogelCypress: packagePath('cypress'),
|
|
60
|
+
aerogelPluginI18n: packagePath('plugin-i18n'),
|
|
61
|
+
aerogelPluginSoukai: packagePath('plugin-soukai'),
|
|
62
|
+
aerogelVite: packagePath('vite'),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (this.options.local) {
|
|
67
|
+
return withFilePrefix({
|
|
68
|
+
aerogelCli: packagePackPath('cli') ?? packNotFound('cli'),
|
|
69
|
+
aerogelCore: packagePackPath('core') ?? packNotFound('core'),
|
|
70
|
+
aerogelCypress: packagePackPath('cypress') ?? packNotFound('cypress'),
|
|
71
|
+
aerogelPluginI18n: packagePackPath('plugin-i18n') ?? packNotFound('plugin-i18n'),
|
|
72
|
+
aerogelPluginSoukai: packagePackPath('plugin-soukai') ?? packNotFound('plugin-soukai'),
|
|
73
|
+
aerogelVite: packagePackPath('vite') ?? packNotFound('vite'),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
aerogelCli: 'next',
|
|
79
|
+
aerogelCore: 'next',
|
|
80
|
+
aerogelCypress: 'next',
|
|
81
|
+
aerogelPluginI18n: 'next',
|
|
82
|
+
aerogelPluginSoukai: 'next',
|
|
83
|
+
aerogelVite: 'next',
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
25
87
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { arrayFrom } from '@noeldemartin/utils';
|
|
2
|
+
import { Project } from 'ts-morph';
|
|
3
|
+
import type { SourceFile } from 'ts-morph';
|
|
4
|
+
|
|
5
|
+
import File from '@/lib/File';
|
|
6
|
+
import Log from '@/lib/Log';
|
|
7
|
+
import Shell from '@/lib/Shell';
|
|
8
|
+
|
|
9
|
+
export class Editor {
|
|
10
|
+
|
|
11
|
+
private project: Project;
|
|
12
|
+
private modifiedFiles: Set<string>;
|
|
13
|
+
|
|
14
|
+
constructor() {
|
|
15
|
+
this.project = new Project({ tsConfigFilePath: 'tsconfig.json' });
|
|
16
|
+
this.modifiedFiles = new Set();
|
|
17
|
+
|
|
18
|
+
this.project.addSourceFilesAtPaths('src/**/*.ts');
|
|
19
|
+
this.project.addSourceFilesAtPaths('tailwind.config.js');
|
|
20
|
+
this.project.addSourceFilesAtPaths('vite.config.ts');
|
|
21
|
+
this.project.addSourceFilesAtPaths('package.json');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public addSourceFile(path: string): void {
|
|
25
|
+
this.project.addSourceFilesAtPaths(path);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public requireSourceFile(path: string): SourceFile {
|
|
29
|
+
return this.project.getSourceFileOrThrow(path);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public async format(): Promise<void> {
|
|
33
|
+
await Log.animate('Formatting modified files', async () => {
|
|
34
|
+
const usingPrettier = File.exists('prettier.config.js');
|
|
35
|
+
const usingESLint = File.exists('.eslintrc.js');
|
|
36
|
+
|
|
37
|
+
await Promise.all(
|
|
38
|
+
arrayFrom(this.modifiedFiles).map(async (file) => {
|
|
39
|
+
usingPrettier && (await Shell.run(`npx prettier ${file} --write`));
|
|
40
|
+
file.match(/\.(ts|js|vue)$/) && usingESLint && (await Shell.run(`npx eslint ${file} --fix`));
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public async save(file: SourceFile): Promise<void> {
|
|
47
|
+
await file.save();
|
|
48
|
+
|
|
49
|
+
this.addModifiedFile(file.getFilePath());
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public addModifiedFile(path: string): void {
|
|
53
|
+
this.modifiedFiles.add(path);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
}
|
package/src/lib/File.ts
CHANGED
|
@@ -12,6 +12,12 @@ export class FileService {
|
|
|
12
12
|
return existsSync(path);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
public isSymlink(path: string): boolean {
|
|
16
|
+
const stats = lstatSync(path);
|
|
17
|
+
|
|
18
|
+
return stats.isSymbolicLink();
|
|
19
|
+
}
|
|
20
|
+
|
|
15
21
|
public read(path: string): string | null {
|
|
16
22
|
if (!this.isFile(path)) {
|
|
17
23
|
return null;
|
package/src/lib/Log.mock.ts
CHANGED
|
@@ -19,7 +19,8 @@ export class LogServiceMock extends LogService {
|
|
|
19
19
|
this.logs.push(message);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
public fail<T = any>(message: string): T {
|
|
23
24
|
throw new Error(`Fail: ${message}`);
|
|
24
25
|
}
|
|
25
26
|
|
package/src/lib/Log.ts
CHANGED
|
@@ -9,8 +9,9 @@ export class LogService {
|
|
|
9
9
|
protected renderError = hex('#ff0000');
|
|
10
10
|
|
|
11
11
|
public async animate<T>(message: string, operation: () => Promise<T>): Promise<T> {
|
|
12
|
-
const updateStdout = (end: string = '') => {
|
|
13
|
-
const progress =
|
|
12
|
+
const updateStdout = (end: string = '', done: boolean = false) => {
|
|
13
|
+
const progress =
|
|
14
|
+
this.renderInfo(this.renderMarkdown(message) + (done ? '...' : '.'.repeat(frame % 4))) + end;
|
|
14
15
|
|
|
15
16
|
this.stdout(progress);
|
|
16
17
|
};
|
|
@@ -23,7 +24,7 @@ export class LogService {
|
|
|
23
24
|
const result = await operation();
|
|
24
25
|
|
|
25
26
|
clearInterval(interval);
|
|
26
|
-
updateStdout('\n');
|
|
27
|
+
updateStdout('\n', true);
|
|
27
28
|
|
|
28
29
|
return result;
|
|
29
30
|
}
|
|
@@ -36,7 +37,8 @@ export class LogService {
|
|
|
36
37
|
this.log(this.renderMarkdown(message), this.renderError);
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
+
public fail<T = any>(message: string): T {
|
|
40
42
|
this.error(message);
|
|
41
43
|
|
|
42
44
|
process.exit(1);
|
|
@@ -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
|
+
}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import { resolve } from 'path';
|
|
2
|
-
|
|
3
1
|
export interface FormatCodeBlockOptions {
|
|
4
2
|
indent?: number;
|
|
5
3
|
}
|
|
6
4
|
|
|
7
|
-
export function basePath(path: string): string {
|
|
8
|
-
return resolve(__dirname, '../', path);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
5
|
export function formatCodeBlock(code: string, options: FormatCodeBlockOptions = {}): string {
|
|
12
6
|
const lines = code.split('\n');
|
|
13
7
|
const indent = options.indent ?? 0;
|
|
@@ -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 resolve(__dirname, '../', 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
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
export function packNotFound(packageName: string): any {
|
|
21
|
+
return Log.fail(`Could not find ${packageName} pack file, did you run 'npm pack'?`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function packagePackPath(packageName: string): string | null {
|
|
25
|
+
return File.getFiles(packagePath(packageName)).find((file) => file.endsWith('.tgz')) ?? null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function packagePath(packageName: string): string {
|
|
29
|
+
return basePath(`../${packageName}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function templatePath(name: string): string {
|
|
33
|
+
return resolve(__dirname, `../templates/${name}`);
|
|
34
|
+
}
|
|
@@ -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 --save-exact`);
|
|
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,114 @@
|
|
|
1
|
+
import { Node, SyntaxKind } from 'ts-morph';
|
|
2
|
+
import type { ArrayLiteralExpression, SourceFile } from 'ts-morph';
|
|
3
|
+
|
|
4
|
+
import File from '@/lib/File';
|
|
5
|
+
import Log from '@/lib/Log';
|
|
6
|
+
import Plugin from '@/plugins/Plugin';
|
|
7
|
+
import Shell from '@/lib/Shell';
|
|
8
|
+
import { findDescendant } from '@/lib/utils/edit';
|
|
9
|
+
import { isLinkedLocalApp } from '@/lib/utils/app';
|
|
10
|
+
import { packagePath } from '@/lib/utils/paths';
|
|
11
|
+
import type { Editor } from '@/lib/Editor';
|
|
12
|
+
|
|
13
|
+
export class Solid extends Plugin {
|
|
14
|
+
|
|
15
|
+
constructor() {
|
|
16
|
+
super('solid');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
protected async updateFiles(editor: Editor): Promise<void> {
|
|
20
|
+
await this.updateTailwindConfig(editor);
|
|
21
|
+
await this.updateNpmScripts(editor);
|
|
22
|
+
await this.updateGitIgnore();
|
|
23
|
+
await super.updateFiles(editor);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
protected async installNpmDependencies(): Promise<void> {
|
|
27
|
+
await Shell.run('npm install soukai-solid@next --save-exact');
|
|
28
|
+
await Shell.run('npm install @solid/community-server@7 --save');
|
|
29
|
+
await super.installNpmDependencies();
|
|
30
|
+
}
|
|
31
|
+
|
|
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
|
+
protected async updateNpmScripts(editor: Editor): Promise<void> {
|
|
55
|
+
Log.info('Updating npm scripts...');
|
|
56
|
+
|
|
57
|
+
const packageJson = File.read('package.json');
|
|
58
|
+
|
|
59
|
+
if (!packageJson) {
|
|
60
|
+
return Log.fail('Could not find package.json file');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
File.write(
|
|
64
|
+
'package.json',
|
|
65
|
+
packageJson
|
|
66
|
+
.replace(
|
|
67
|
+
'"cy:dev": "concurrently --kill-others \\"npm run test:serve-app\\" \\"npm run cy:open\\"",',
|
|
68
|
+
'"cy:dev": "concurrently --kill-others ' +
|
|
69
|
+
'\\"npm run test:serve-app\\" \\"npm run test:serve-pod\\" \\"npm run cy:open\\"",',
|
|
70
|
+
)
|
|
71
|
+
.replace(
|
|
72
|
+
'"cy:test": "start-server-and-test test:serve-app http-get://localhost:5001 cy:run",',
|
|
73
|
+
'"cy:test": "start-server-and-test ' +
|
|
74
|
+
'test:serve-app http-get://localhost:5001 test:serve-pod http-get://localhost:4000 cy:run",',
|
|
75
|
+
)
|
|
76
|
+
.replace(
|
|
77
|
+
'"dev": "vite",',
|
|
78
|
+
'"dev": "vite",\n' +
|
|
79
|
+
'"dev:serve-pod": "community-solid-server -c @css:config/file.json -p 4000 -f ./solid-data",',
|
|
80
|
+
)
|
|
81
|
+
.replace(
|
|
82
|
+
'"test:serve-app": "vite --port 5001"',
|
|
83
|
+
'"test:serve-app": "vite --port 5001",\n' +
|
|
84
|
+
'"test:serve-pod": "community-solid-server -p 4000 -l warn"',
|
|
85
|
+
),
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
editor.addModifiedFile('package.json');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
protected async updateGitIgnore(): Promise<void> {
|
|
92
|
+
Log.info('Updating .gitignore');
|
|
93
|
+
|
|
94
|
+
const gitignore = File.read('.gitignore') ?? '';
|
|
95
|
+
|
|
96
|
+
File.write('.gitignore', `${gitignore}/solid-data\n`);
|
|
97
|
+
}
|
|
98
|
+
|
|
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
|
+
}
|
|
@@ -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 --save-exact');
|
|
12
|
+
await super.installNpmDependencies();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
protected getBootstrapConfig(): string {
|
|
16
|
+
return 'soukai({ models: import.meta.glob(\'@/models/*\', { eager: true }) })';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
}
|
package/src/testing/setup.ts
CHANGED
|
@@ -24,16 +24,46 @@ 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
|
+
}
|
|
53
|
+
|
|
54
|
+
function packagePath(packageName: string) {
|
|
55
|
+
return basePath(`../${packageName}`);
|
|
56
|
+
}
|
|
28
57
|
|
|
29
|
-
|
|
30
|
-
|
|
58
|
+
function templatePath(name: string = '') {
|
|
59
|
+
return resolve(__dirname, `../../templates/${name}`);
|
|
60
|
+
}
|
|
31
61
|
|
|
32
62
|
return {
|
|
33
|
-
...
|
|
34
|
-
basePath
|
|
35
|
-
|
|
36
|
-
|
|
63
|
+
...original,
|
|
64
|
+
basePath,
|
|
65
|
+
packagePath,
|
|
66
|
+
templatePath,
|
|
37
67
|
};
|
|
38
68
|
});
|
|
39
69
|
|
|
@@ -12,6 +12,18 @@ jobs:
|
|
|
12
12
|
node-version-file: '.nvmrc'
|
|
13
13
|
- run: npm ci
|
|
14
14
|
- run: npm run lint
|
|
15
|
-
- run: npm run test:ci
|
|
16
|
-
- run: npm run cy:test
|
|
17
15
|
- run: npm run build
|
|
16
|
+
- run: npm run test:ci
|
|
17
|
+
- run: npm run cy:test-snapshots:ci
|
|
18
|
+
- name: Upload Cypress screenshots
|
|
19
|
+
uses: actions/upload-artifact@v3
|
|
20
|
+
if: ${{ failure() }}
|
|
21
|
+
with:
|
|
22
|
+
name: cypress_screenshots
|
|
23
|
+
path: cypress/screenshots
|
|
24
|
+
- name: Upload Cypress snapshots
|
|
25
|
+
uses: actions/upload-artifact@v3
|
|
26
|
+
if: ${{ failure() }}
|
|
27
|
+
with:
|
|
28
|
+
name: cypress_snapshots
|
|
29
|
+
path: cypress/snapshots
|
|
@@ -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
|
+
}
|