@aerogel/cli 0.0.0-next.7e89f52eb37d9154f4879a5ccd058d27d476dada → 0.0.0-next.980a397d575dcb5ff8c5a0bff769d09f938ea03c
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 +10 -4
- package/src/commands/Command.ts +15 -7
- package/src/commands/create.test.ts +21 -4
- package/src/commands/create.ts +10 -7
- package/src/commands/generate-component.test.ts +59 -6
- package/src/commands/generate-component.ts +49 -14
- package/src/commands/generate-model.test.ts +11 -3
- package/src/commands/generate-model.ts +7 -8
- package/src/commands/generate-service.test.ts +10 -2
- package/src/commands/generate-service.ts +5 -6
- package/src/commands/install.test.ts +36 -5
- package/src/commands/install.ts +6 -5
- package/src/lib/Editor.ts +16 -9
- package/src/lib/Shell.mock.ts +1 -1
- package/src/lib/Template.ts +5 -1
- package/src/lib/utils/app.ts +1 -1
- package/src/lib/utils/paths.ts +1 -1
- package/src/plugins/Histoire.ts +105 -0
- package/src/plugins/Plugin.ts +57 -4
- package/src/plugins/Solid.ts +47 -34
- package/src/plugins/Soukai.ts +1 -1
- package/src/testing/stubs/ProgramStub.ts +35 -0
- package/src/testing/utils.ts +14 -0
- package/templates/app/.github/workflows/ci.yml +14 -2
- package/templates/app/README.md +3 -0
- package/templates/app/{cypress.config.ts → cypress/cypress.config.ts} +4 -0
- package/templates/app/index.html +3 -2
- package/templates/app/package.json +14 -2
- package/templates/app/src/App.vue +2 -2
- package/templates/app/src/assets/public/robots.txt +2 -0
- package/templates/app/src/main.ts +1 -1
- package/templates/app/tsconfig.json +1 -0
- package/templates/app/vite.config.ts +10 -4
- package/templates/component-button/[component.name].vue +32 -0
- package/templates/component-button-story/[component.name].story.vue +71 -0
- package/templates/component-input/[component.name].vue +16 -0
- package/templates/component-input-story/[component.name].story.vue +63 -0
- package/templates/histoire/histoire.config.ts +7 -0
- package/templates/histoire/patches/histoire+0.17.6.patch +13 -0
- package/templates/histoire/src/main.histoire.ts +8 -0
- package/templates/postcss-pseudo-classes/postcss.config.js +15 -0
- package/.eslintrc.js +0 -7
- 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/prettier.config.js +0 -5
- /package/bin/{ag → gel} +0 -0
- /package/templates/app/src/assets/{styles.css → css/styles.css} +0 -0
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { stringToStudlyCase } from '@noeldemartin/utils';
|
|
1
|
+
import { formatCodeBlock, stringToStudlyCase } from '@noeldemartin/utils';
|
|
2
2
|
|
|
3
3
|
import Command from '@/commands/Command';
|
|
4
4
|
import File from '@/lib/File';
|
|
5
5
|
import Log from '@/lib/Log';
|
|
6
6
|
import Template from '@/lib/Template';
|
|
7
7
|
import { templatePath } from '@/lib/utils/paths';
|
|
8
|
-
import { formatCodeBlock } from '@/lib/utils/format';
|
|
9
8
|
import type { CommandOptions } from '@/commands/Command';
|
|
10
9
|
|
|
11
10
|
interface Options {
|
|
@@ -14,10 +13,10 @@ interface Options {
|
|
|
14
13
|
|
|
15
14
|
export class GenerateModelCommand extends Command {
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
protected static command: string = 'generate:model';
|
|
17
|
+
protected static description: string = 'Generate an AerogelJS Model';
|
|
18
|
+
protected static parameters: [string, string][] = [['name', 'Model name']];
|
|
19
|
+
protected static options: CommandOptions = {
|
|
21
20
|
fields: 'Create model with the given fields',
|
|
22
21
|
};
|
|
23
22
|
|
|
@@ -31,7 +30,7 @@ export class GenerateModelCommand extends Command {
|
|
|
31
30
|
this.options = options;
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
|
|
33
|
+
protected async run(): Promise<void> {
|
|
35
34
|
this.assertAerogelOrDirectory('src/models');
|
|
36
35
|
|
|
37
36
|
if (File.exists(`src/models/${this.name}.ts`)) {
|
|
@@ -91,7 +90,7 @@ export class GenerateModelCommand extends Command {
|
|
|
91
90
|
if (!File.contains('package.json', '"soukai"') && !File.contains('package.json', '"@aerogel/plugin-soukai"')) {
|
|
92
91
|
Log.fail(`
|
|
93
92
|
Soukai is not installed yet! You can install it running:
|
|
94
|
-
npx
|
|
93
|
+
npx gel install soukai
|
|
95
94
|
`);
|
|
96
95
|
}
|
|
97
96
|
}
|
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
import { describe, it } from 'vitest';
|
|
1
|
+
import { beforeEach, describe, it } from 'vitest';
|
|
2
2
|
|
|
3
3
|
import FileMock from '@/lib/File.mock';
|
|
4
|
+
import { stubCommandRunner } from '@/testing/utils';
|
|
5
|
+
import type { StubCommandRunner } from '@/testing/utils';
|
|
4
6
|
|
|
5
7
|
import { GenerateServiceCommand } from './generate-service';
|
|
6
8
|
|
|
7
9
|
describe('Generate Service command', () => {
|
|
8
10
|
|
|
11
|
+
let run: StubCommandRunner<typeof GenerateServiceCommand>;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
run = stubCommandRunner(GenerateServiceCommand);
|
|
15
|
+
});
|
|
16
|
+
|
|
9
17
|
it('generates services', async () => {
|
|
10
18
|
// Arrange
|
|
11
19
|
FileMock.stub('package.json', '@aerogel/core');
|
|
12
20
|
|
|
13
21
|
// Act
|
|
14
|
-
await
|
|
22
|
+
await run('FooBar');
|
|
15
23
|
|
|
16
24
|
// Assert
|
|
17
25
|
FileMock.expectCreated('src/services/FooBar.ts').toContain('class FooBarService extends Service');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { arrayFrom, stringToCamelCase } from '@noeldemartin/utils';
|
|
1
|
+
import { arrayFrom, formatCodeBlock, stringToCamelCase } from '@noeldemartin/utils';
|
|
2
2
|
import { Node, SyntaxKind } from 'ts-morph';
|
|
3
3
|
import type { ObjectLiteralExpression, SourceFile } from 'ts-morph';
|
|
4
4
|
|
|
@@ -9,14 +9,13 @@ import Template from '@/lib/Template';
|
|
|
9
9
|
import { app } from '@/lib/utils/app';
|
|
10
10
|
import { templatePath } from '@/lib/utils/paths';
|
|
11
11
|
import { editFiles, findDescendant } from '@/lib/utils/edit';
|
|
12
|
-
import { formatCodeBlock } from '@/lib/utils/format';
|
|
13
12
|
import type { Editor } from '@/lib/Editor';
|
|
14
13
|
|
|
15
14
|
export class GenerateServiceCommand extends Command {
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
protected static command: string = 'generate:service';
|
|
17
|
+
protected static description: string = 'Generate an AerogelJS Service';
|
|
18
|
+
protected static parameters: [string, string][] = [['name', 'Service name']];
|
|
20
19
|
|
|
21
20
|
private name: string;
|
|
22
21
|
|
|
@@ -26,7 +25,7 @@ export class GenerateServiceCommand extends Command {
|
|
|
26
25
|
this.name = name;
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
protected async run(): Promise<void> {
|
|
30
29
|
this.assertAerogelOrDirectory('src/services');
|
|
31
30
|
|
|
32
31
|
const files = new Set<string>();
|
|
@@ -1,18 +1,49 @@
|
|
|
1
|
-
import { describe, it } from 'vitest';
|
|
1
|
+
import { beforeEach, describe, it } from 'vitest';
|
|
2
2
|
|
|
3
|
+
import FileMock from '@/lib/File.mock';
|
|
3
4
|
import ShellMock from '@/lib/Shell.mock';
|
|
5
|
+
import { stubCommandRunner } from '@/testing/utils';
|
|
6
|
+
import type { StubCommandRunner } from '@/testing/utils';
|
|
4
7
|
|
|
5
8
|
import { InstallCommand } from './install';
|
|
6
9
|
|
|
7
10
|
describe('Install plugin command', () => {
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
let run: StubCommandRunner<typeof InstallCommand>;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
run = stubCommandRunner(InstallCommand);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('installs solid', async () => {
|
|
19
|
+
// Act
|
|
20
|
+
await run('solid');
|
|
21
|
+
|
|
22
|
+
// Assert
|
|
23
|
+
ShellMock.expectRan('npm install soukai-solid@next --save-exact');
|
|
24
|
+
ShellMock.expectRan('npm install @aerogel/plugin-solid@next --save-exact');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('installs soukai', async () => {
|
|
28
|
+
// Act
|
|
29
|
+
await run('soukai');
|
|
30
|
+
|
|
31
|
+
// Assert
|
|
32
|
+
ShellMock.expectRan('npm install soukai@next --save-exact');
|
|
33
|
+
ShellMock.expectRan('npm install @aerogel/plugin-soukai@next --save-exact');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('installs histoire', async () => {
|
|
37
|
+
// Arrange
|
|
38
|
+
FileMock.stub('package.json', '"@aerogel/core"');
|
|
39
|
+
|
|
10
40
|
// Act
|
|
11
|
-
await
|
|
41
|
+
await run('histoire');
|
|
12
42
|
|
|
13
43
|
// Assert
|
|
14
|
-
ShellMock.expectRan('npm install
|
|
15
|
-
ShellMock.expectRan('npm install @aerogel/
|
|
44
|
+
ShellMock.expectRan('npm install histoire@0.17.6 --save-dev');
|
|
45
|
+
ShellMock.expectRan('npm install @aerogel/histoire@next --save-exact --save-dev');
|
|
46
|
+
ShellMock.expectRan('npm install patch-package --save-dev');
|
|
16
47
|
});
|
|
17
48
|
|
|
18
49
|
});
|
package/src/commands/install.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import Command from '@/commands/Command';
|
|
2
2
|
import Log from '@/lib/Log';
|
|
3
|
+
import { Histoire } from '@/plugins/Histoire';
|
|
3
4
|
import { Solid } from '@/plugins/Solid';
|
|
4
5
|
import { Soukai } from '@/plugins/Soukai';
|
|
5
6
|
import type Plugin from '@/plugins/Plugin';
|
|
6
7
|
|
|
7
|
-
const plugins = [new Soukai(), new Solid()].reduce(
|
|
8
|
+
const plugins = [new Soukai(), new Solid(), new Histoire()].reduce(
|
|
8
9
|
(pluginsObject, plugin) => Object.assign(pluginsObject, { [plugin.name]: plugin }),
|
|
9
10
|
{} as Record<string, Plugin>,
|
|
10
11
|
);
|
|
11
12
|
|
|
12
13
|
export class InstallCommand extends Command {
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
protected static command: string = 'install';
|
|
16
|
+
protected static description: string = 'Install an AerogelJS plugin';
|
|
17
|
+
protected static parameters: [string, string][] = [['plugin', 'Plugin to install']];
|
|
17
18
|
|
|
18
19
|
private plugin: Plugin;
|
|
19
20
|
|
|
@@ -25,7 +26,7 @@ export class InstallCommand extends Command {
|
|
|
25
26
|
Log.fail(`Plugin '${plugin}' doesn't exist. Available plugins: ${Object.keys(plugins).join(', ')}`);
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
protected async run(): Promise<void> {
|
|
29
30
|
await this.plugin.install();
|
|
30
31
|
}
|
|
31
32
|
|
package/src/lib/Editor.ts
CHANGED
|
@@ -18,6 +18,7 @@ export class Editor {
|
|
|
18
18
|
this.project.addSourceFilesAtPaths('src/**/*.ts');
|
|
19
19
|
this.project.addSourceFilesAtPaths('tailwind.config.js');
|
|
20
20
|
this.project.addSourceFilesAtPaths('vite.config.ts');
|
|
21
|
+
this.project.addSourceFilesAtPaths('package.json');
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
public addSourceFile(path: string): void {
|
|
@@ -30,22 +31,28 @@ export class Editor {
|
|
|
30
31
|
|
|
31
32
|
public async format(): Promise<void> {
|
|
32
33
|
await Log.animate('Formatting modified files', async () => {
|
|
33
|
-
const usingPrettier = File.exists('prettier.config.js');
|
|
34
|
-
const usingESLint = File.exists('.eslintrc.js');
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
const usingPrettier = File.exists('prettier.config.js') || File.contains('package.json', '"prettier": {');
|
|
35
|
+
const usingESLint = File.exists('.eslintrc.js') || File.contains('package.json', '"eslintConfig"');
|
|
36
|
+
const usingPrettierESLint = File.contains('package.json', '"prettier-eslint-cli"');
|
|
37
|
+
const formatFile = usingPrettierESLint
|
|
38
|
+
? (file: string) => Shell.run(`npx prettier-eslint ${file} --write`)
|
|
39
|
+
: async (file: string) => {
|
|
38
40
|
usingPrettier && (await Shell.run(`npx prettier ${file} --write`));
|
|
39
|
-
usingESLint && (await Shell.run(`npx eslint ${file} --fix`));
|
|
40
|
-
}
|
|
41
|
-
|
|
41
|
+
file.match(/\.(ts|js|vue)$/) && usingESLint && (await Shell.run(`npx eslint ${file} --fix`));
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
await Promise.all(arrayFrom(this.modifiedFiles).map(async (file) => formatFile(file)));
|
|
42
45
|
});
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
public async save(file: SourceFile): Promise<void> {
|
|
46
49
|
await file.save();
|
|
47
50
|
|
|
48
|
-
this.
|
|
51
|
+
this.addModifiedFile(file.getFilePath());
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public addModifiedFile(path: string): void {
|
|
55
|
+
this.modifiedFiles.add(path);
|
|
49
56
|
}
|
|
50
57
|
|
|
51
58
|
}
|
package/src/lib/Shell.mock.ts
CHANGED
|
@@ -8,7 +8,7 @@ export class ShellServiceMock extends ShellService {
|
|
|
8
8
|
private history: string[] = [];
|
|
9
9
|
|
|
10
10
|
public async run(command: string): Promise<void> {
|
|
11
|
-
this.history.push(command);
|
|
11
|
+
this.history.push(command.trim());
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
public expectRan(command: string): void {
|
package/src/lib/Template.ts
CHANGED
|
@@ -6,7 +6,11 @@ import File from '@/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);
|
package/src/lib/utils/app.ts
CHANGED
package/src/lib/utils/paths.ts
CHANGED
|
@@ -10,7 +10,7 @@ export function basePath(path: string = ''): string {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const packageJson = File.read(resolve(__dirname, '../../../../package.json'));
|
|
13
|
-
const matches = stringMatch<2>(packageJson ?? '', /"@aerogel\/
|
|
13
|
+
const matches = stringMatch<2>(packageJson ?? '', /"@aerogel\/core": "file:(.*)\/aerogel-core-[\d.]*\.tgz"/);
|
|
14
14
|
const cliPath = matches?.[1] ?? Log.fail<string>('Could not determine base path');
|
|
15
15
|
|
|
16
16
|
return resolve(cliPath, path);
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import File from '@/lib/File';
|
|
2
|
+
import Log from '@/lib/Log';
|
|
3
|
+
import Plugin from '@/plugins/Plugin';
|
|
4
|
+
import Shell from '@/lib/Shell';
|
|
5
|
+
import Template from '@/lib/Template';
|
|
6
|
+
import { isLinkedLocalApp } from '@/lib/utils/app';
|
|
7
|
+
import { packagePath, templatePath } from '@/lib/utils/paths';
|
|
8
|
+
import type { Editor } from '@/lib/Editor';
|
|
9
|
+
|
|
10
|
+
export class Histoire extends Plugin {
|
|
11
|
+
|
|
12
|
+
private installedPatchPackage: boolean = false;
|
|
13
|
+
private installedPostCSSPseudoClasses: boolean = false;
|
|
14
|
+
|
|
15
|
+
constructor() {
|
|
16
|
+
super('histoire');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public async beforeInstall(): Promise<void> {
|
|
20
|
+
this.installedPatchPackage = false;
|
|
21
|
+
this.installedPostCSSPseudoClasses = false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
protected async afterInstall(): Promise<void> {
|
|
25
|
+
if (!this.installedPatchPackage) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
await Log.animate('Patching dependencies', async () => {
|
|
30
|
+
await Shell.run('npx patch-package');
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
protected async updateFiles(editor: Editor): Promise<void> {
|
|
35
|
+
await this.updateTailwindConfig(editor, {
|
|
36
|
+
content: isLinkedLocalApp()
|
|
37
|
+
? `'${packagePath('histoire')}/dist/**/*.js'`
|
|
38
|
+
: '\'./node_modules/@aerogel/histoire/dist/**/*.js\'',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
await this.updateNpmScripts(editor);
|
|
42
|
+
await this.createConfigFiles();
|
|
43
|
+
await super.updateFiles(editor);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
protected async installNpmDependencies(): Promise<void> {
|
|
47
|
+
// We need this specific version because we're patching it using patch-package
|
|
48
|
+
await Shell.run('npm install histoire@0.17.6 --save-dev');
|
|
49
|
+
|
|
50
|
+
if (!File.contains('package.json', '"patch-package"')) {
|
|
51
|
+
await Shell.run('npm install patch-package --save-dev');
|
|
52
|
+
|
|
53
|
+
this.installedPatchPackage = true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!File.contains('package.json', '"postcss-pseudo-classes"')) {
|
|
57
|
+
await Shell.run('npm install postcss-pseudo-classes --save-dev');
|
|
58
|
+
|
|
59
|
+
this.installedPostCSSPseudoClasses = true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
await super.installNpmDependencies();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
protected getLocalPackageName(): string {
|
|
66
|
+
return this.name;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
protected async updateNpmScripts(editor: Editor): Promise<void> {
|
|
70
|
+
Log.info('Updating npm scripts...');
|
|
71
|
+
|
|
72
|
+
const packageJson = File.read('package.json');
|
|
73
|
+
|
|
74
|
+
if (!packageJson) {
|
|
75
|
+
return Log.fail('Could not find package.json file');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
File.write(
|
|
79
|
+
'package.json',
|
|
80
|
+
packageJson.replace(
|
|
81
|
+
'"lint": "noeldemartin-lint src",',
|
|
82
|
+
this.installedPatchPackage
|
|
83
|
+
? '"histoire": "histoire dev", "lint": "noeldemartin-lint src", "postinstall": "patch-package",'
|
|
84
|
+
: '"histoire": "histoire dev", "lint": "noeldemartin-lint src",',
|
|
85
|
+
),
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
editor.addModifiedFile('package.json');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
protected async createConfigFiles(): Promise<void> {
|
|
92
|
+
Log.info('Creating config files...');
|
|
93
|
+
|
|
94
|
+
Template.instantiate(templatePath('histoire'));
|
|
95
|
+
|
|
96
|
+
if (this.installedPostCSSPseudoClasses) {
|
|
97
|
+
Template.instantiate(templatePath('postcss-pseudo-classes'));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
protected isForDevelopment(): boolean {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
}
|
package/src/plugins/Plugin.ts
CHANGED
|
@@ -20,6 +20,7 @@ export default abstract class Plugin {
|
|
|
20
20
|
public async install(): Promise<void> {
|
|
21
21
|
this.assertNotInstalled();
|
|
22
22
|
|
|
23
|
+
await this.beforeInstall();
|
|
23
24
|
await this.installDependencies();
|
|
24
25
|
|
|
25
26
|
if (editFiles()) {
|
|
@@ -29,6 +30,8 @@ export default abstract class Plugin {
|
|
|
29
30
|
await editor.format();
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
await this.afterInstall();
|
|
34
|
+
|
|
32
35
|
Log.info(`Plugin ${this.name} installed!`);
|
|
33
36
|
}
|
|
34
37
|
|
|
@@ -38,6 +41,14 @@ export default abstract class Plugin {
|
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
43
|
|
|
44
|
+
protected async beforeInstall(): Promise<void> {
|
|
45
|
+
// Placeholder for overrides, don't place any functionality here.
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
protected async afterInstall(): Promise<void> {
|
|
49
|
+
// Placeholder for overrides, don't place any functionality here.
|
|
50
|
+
}
|
|
51
|
+
|
|
41
52
|
protected async installDependencies(): Promise<void> {
|
|
42
53
|
await Log.animate('Installing plugin dependencies', async () => {
|
|
43
54
|
await this.installNpmDependencies();
|
|
@@ -45,12 +56,16 @@ export default abstract class Plugin {
|
|
|
45
56
|
}
|
|
46
57
|
|
|
47
58
|
protected async updateFiles(editor: Editor): Promise<void> {
|
|
48
|
-
|
|
59
|
+
if (!this.isForDevelopment()) {
|
|
60
|
+
await this.updateBootstrapConfig(editor);
|
|
61
|
+
}
|
|
49
62
|
}
|
|
50
63
|
|
|
51
64
|
protected async installNpmDependencies(): Promise<void> {
|
|
65
|
+
const flags = this.isForDevelopment() ? '--save-dev' : '';
|
|
66
|
+
|
|
52
67
|
if (isLinkedLocalApp()) {
|
|
53
|
-
await Shell.run(`npm install file:${packagePath(this.getLocalPackageName())}`);
|
|
68
|
+
await Shell.run(`npm install file:${packagePath(this.getLocalPackageName())} ${flags}`);
|
|
54
69
|
|
|
55
70
|
return;
|
|
56
71
|
}
|
|
@@ -58,12 +73,12 @@ export default abstract class Plugin {
|
|
|
58
73
|
if (isLocalApp()) {
|
|
59
74
|
const packPath = packagePackPath(this.getLocalPackageName()) ?? packNotFound(this.getLocalPackageName());
|
|
60
75
|
|
|
61
|
-
await Shell.run(`npm install file:${packPath}`);
|
|
76
|
+
await Shell.run(`npm install file:${packPath} ${flags}`);
|
|
62
77
|
|
|
63
78
|
return;
|
|
64
79
|
}
|
|
65
80
|
|
|
66
|
-
await Shell.run(`npm install ${this.getNpmPackageName()}@next`);
|
|
81
|
+
await Shell.run(`npm install ${this.getNpmPackageName()}@next --save-exact ${flags}`);
|
|
67
82
|
}
|
|
68
83
|
|
|
69
84
|
protected async updateBootstrapConfig(editor: Editor): Promise<void> {
|
|
@@ -86,6 +101,25 @@ export default abstract class Plugin {
|
|
|
86
101
|
});
|
|
87
102
|
}
|
|
88
103
|
|
|
104
|
+
protected async updateTailwindConfig(editor: Editor, options: { content: string }): Promise<void> {
|
|
105
|
+
await Log.animate('Updating tailwind configuration', async () => {
|
|
106
|
+
const tailwindConfig = editor.requireSourceFile('tailwind.config.js');
|
|
107
|
+
const contentArray = this.getTailwindContentArray(tailwindConfig);
|
|
108
|
+
|
|
109
|
+
if (!contentArray) {
|
|
110
|
+
return Log.fail(`
|
|
111
|
+
Could not find content array in tailwind config, please add the following manually:
|
|
112
|
+
|
|
113
|
+
${options.content}
|
|
114
|
+
`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
contentArray.addElement(options.content);
|
|
118
|
+
|
|
119
|
+
await editor.save(tailwindConfig);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
89
123
|
protected getBootstrapPluginsDeclaration(mainConfig: SourceFile): ArrayLiteralExpression | null {
|
|
90
124
|
const bootstrapAppCall = findDescendant(mainConfig, {
|
|
91
125
|
guard: Node.isCallExpression,
|
|
@@ -103,6 +137,21 @@ export default abstract class Plugin {
|
|
|
103
137
|
return pluginsArray;
|
|
104
138
|
}
|
|
105
139
|
|
|
140
|
+
protected getTailwindContentArray(tailwindConfig: SourceFile): ArrayLiteralExpression | null {
|
|
141
|
+
const contentAssignment = findDescendant(tailwindConfig, {
|
|
142
|
+
guard: Node.isPropertyAssignment,
|
|
143
|
+
validate: (propertyAssignment) => propertyAssignment.getName() === 'content',
|
|
144
|
+
skip: SyntaxKind.JSDoc,
|
|
145
|
+
});
|
|
146
|
+
const contentArray = contentAssignment?.getInitializer();
|
|
147
|
+
|
|
148
|
+
if (!Node.isArrayLiteralExpression(contentArray)) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return contentArray;
|
|
153
|
+
}
|
|
154
|
+
|
|
106
155
|
protected getBootstrapImport(): OptionalKind<ImportDeclarationStructure> {
|
|
107
156
|
return {
|
|
108
157
|
defaultImport: this.name,
|
|
@@ -118,6 +167,10 @@ export default abstract class Plugin {
|
|
|
118
167
|
return `plugin-${this.name}`;
|
|
119
168
|
}
|
|
120
169
|
|
|
170
|
+
protected isForDevelopment(): boolean {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
|
|
121
174
|
protected getBootstrapConfig(): string {
|
|
122
175
|
return `${this.name}()`;
|
|
123
176
|
}
|
package/src/plugins/Solid.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import File from '@/lib/File';
|
|
2
|
+
import Log from '@/lib/Log';
|
|
4
3
|
import Plugin from '@/plugins/Plugin';
|
|
5
4
|
import Shell from '@/lib/Shell';
|
|
6
|
-
import Log from '@/lib/Log';
|
|
7
|
-
import { findDescendant } from '@/lib/utils/edit';
|
|
8
5
|
import { isLinkedLocalApp } from '@/lib/utils/app';
|
|
9
6
|
import { packagePath } from '@/lib/utils/paths';
|
|
10
7
|
import type { Editor } from '@/lib/Editor';
|
|
@@ -16,50 +13,66 @@ export class Solid extends Plugin {
|
|
|
16
13
|
}
|
|
17
14
|
|
|
18
15
|
protected async updateFiles(editor: Editor): Promise<void> {
|
|
19
|
-
await this.updateTailwindConfig(editor
|
|
16
|
+
await this.updateTailwindConfig(editor, {
|
|
17
|
+
content: isLinkedLocalApp()
|
|
18
|
+
? `'${packagePath('plugin-solid')}/dist/**/*.js'`
|
|
19
|
+
: '\'./node_modules/@aerogel/plugin-solid/dist/**/*.js\'',
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
await this.updateNpmScripts(editor);
|
|
23
|
+
await this.updateGitIgnore();
|
|
20
24
|
await super.updateFiles(editor);
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
protected async installNpmDependencies(): Promise<void> {
|
|
24
|
-
await Shell.run('npm install soukai-solid@next');
|
|
28
|
+
await Shell.run('npm install soukai-solid@next --save-exact');
|
|
29
|
+
await Shell.run('npm install @solid/community-server@7 --save');
|
|
25
30
|
await super.installNpmDependencies();
|
|
26
31
|
}
|
|
27
32
|
|
|
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\'';
|
|
33
|
+
protected async updateNpmScripts(editor: Editor): Promise<void> {
|
|
34
|
+
Log.info('Updating npm scripts...');
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
return Log.fail(`
|
|
38
|
-
Could not find content array in tailwind config, please add the following manually:
|
|
36
|
+
const packageJson = File.read('package.json');
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
if (!packageJson) {
|
|
39
|
+
return Log.fail('Could not find package.json file');
|
|
40
|
+
}
|
|
43
41
|
|
|
44
|
-
|
|
42
|
+
File.write(
|
|
43
|
+
'package.json',
|
|
44
|
+
packageJson
|
|
45
|
+
.replace(
|
|
46
|
+
'"cy:dev": "concurrently --kill-others \\"npm run test:serve-app\\" \\"npm run cy:open\\"",',
|
|
47
|
+
'"cy:dev": "concurrently --kill-others ' +
|
|
48
|
+
'\\"npm run test:serve-app\\" \\"npm run test:serve-pod\\" \\"npm run cy:open\\"",',
|
|
49
|
+
)
|
|
50
|
+
.replace(
|
|
51
|
+
'"cy:test": "start-server-and-test test:serve-app http-get://localhost:5001 cy:run",',
|
|
52
|
+
'"cy:test": "start-server-and-test ' +
|
|
53
|
+
'test:serve-app http-get://localhost:5001 test:serve-pod http-get://localhost:4000 cy:run",',
|
|
54
|
+
)
|
|
55
|
+
.replace(
|
|
56
|
+
'"dev": "vite",',
|
|
57
|
+
'"dev": "vite",\n' +
|
|
58
|
+
'"dev:serve-pod": "community-solid-server -c @css:config/file.json -p 4000 -f ./solid-data",',
|
|
59
|
+
)
|
|
60
|
+
.replace(
|
|
61
|
+
'"test:serve-app": "vite --port 5001"',
|
|
62
|
+
'"test:serve-app": "vite --port 5001",\n' +
|
|
63
|
+
'"test:serve-pod": "community-solid-server -p 4000 -l warn"',
|
|
64
|
+
),
|
|
65
|
+
);
|
|
45
66
|
|
|
46
|
-
|
|
47
|
-
});
|
|
67
|
+
editor.addModifiedFile('package.json');
|
|
48
68
|
}
|
|
49
69
|
|
|
50
|
-
protected
|
|
51
|
-
|
|
52
|
-
guard: Node.isPropertyAssignment,
|
|
53
|
-
validate: (propertyAssignment) => propertyAssignment.getName() === 'content',
|
|
54
|
-
skip: SyntaxKind.JSDoc,
|
|
55
|
-
});
|
|
56
|
-
const contentArray = contentAssignment?.getInitializer();
|
|
70
|
+
protected async updateGitIgnore(): Promise<void> {
|
|
71
|
+
Log.info('Updating .gitignore');
|
|
57
72
|
|
|
58
|
-
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
73
|
+
const gitignore = File.read('.gitignore') ?? '';
|
|
61
74
|
|
|
62
|
-
|
|
75
|
+
File.write('.gitignore', `${gitignore}/solid-data\n`);
|
|
63
76
|
}
|
|
64
77
|
|
|
65
78
|
}
|
package/src/plugins/Soukai.ts
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Command as Program } from 'commander';
|
|
2
|
+
import type { Constructor } from '@noeldemartin/utils';
|
|
3
|
+
|
|
4
|
+
import type Command from '@/commands/Command';
|
|
5
|
+
|
|
6
|
+
export default class ProgramStub<T extends Constructor<Command> = Constructor<Command>> {
|
|
7
|
+
|
|
8
|
+
private runner?: (...args: ConstructorParameters<T>) => Promise<void>;
|
|
9
|
+
|
|
10
|
+
public async run(...args: ConstructorParameters<T>): Promise<void> {
|
|
11
|
+
await this.runner?.(...args);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
public command(): any {
|
|
16
|
+
return { description: () => this };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public argument(): this {
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public option(): this {
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public action(runner: Function): this {
|
|
28
|
+
this.runner = runner as (...args: ConstructorParameters<T>) => Promise<void>;
|
|
29
|
+
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default interface ProgramStub extends Program {}
|