@aerogel/cli 0.0.0-next.a56c0f4966eb71571173f8502f3f36d357ceebc7 → 0.0.0-next.a5b6ecb68fdca29d00c8b8906d00aa5bf64a9d7c
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 +2 -2
- package/src/commands/Command.ts +15 -7
- package/src/commands/create.test.ts +12 -4
- package/src/commands/create.ts +5 -5
- package/src/commands/generate-component.test.ts +59 -6
- package/src/commands/generate-component.ts +49 -14
- package/src/commands/generate-model.test.ts +10 -2
- package/src/commands/generate-model.ts +5 -5
- package/src/commands/generate-service.test.ts +10 -2
- package/src/commands/generate-service.ts +4 -4
- package/src/commands/install.test.ts +34 -3
- package/src/commands/install.ts +6 -5
- package/src/lib/Editor.ts +7 -5
- 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 +6 -42
- package/src/testing/stubs/ProgramStub.ts +35 -0
- package/src/testing/utils.ts +14 -0
- 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/bin/{ag → gel} +0 -0
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
import { describe, it } from 'vitest';
|
|
1
|
+
import { beforeEach, describe, it } from 'vitest';
|
|
2
2
|
|
|
3
3
|
import FileMock from '@/lib/File.mock';
|
|
4
4
|
import ShellMock from '@/lib/Shell.mock';
|
|
5
|
+
import { stubCommandRunner } from '@/testing/utils';
|
|
6
|
+
import type { StubCommandRunner } from '@/testing/utils';
|
|
5
7
|
|
|
6
8
|
import { CreateCommand } from './create';
|
|
7
9
|
|
|
8
10
|
describe('Create command', () => {
|
|
9
11
|
|
|
12
|
+
let run: StubCommandRunner<typeof CreateCommand>;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
run = stubCommandRunner(CreateCommand);
|
|
16
|
+
});
|
|
17
|
+
|
|
10
18
|
it('creates apps', async () => {
|
|
11
19
|
// Act
|
|
12
|
-
await
|
|
20
|
+
await run('./app', { name: 'My App' });
|
|
13
21
|
|
|
14
22
|
// Assert
|
|
15
23
|
FileMock.expectCreated('./app/.gitignore').toContain('node_modules');
|
|
@@ -26,7 +34,7 @@ describe('Create command', () => {
|
|
|
26
34
|
|
|
27
35
|
it('creates apps for local core development', async () => {
|
|
28
36
|
// Act
|
|
29
|
-
await
|
|
37
|
+
await run('./app', { name: 'My App', local: true });
|
|
30
38
|
|
|
31
39
|
// Assert
|
|
32
40
|
FileMock.expectCreated('./app/package.json').toMatch(/"@aerogel\/core": "file:[^"]+\/packages\/core"/);
|
|
@@ -34,7 +42,7 @@ describe('Create command', () => {
|
|
|
34
42
|
|
|
35
43
|
it('infers app name from path', async () => {
|
|
36
44
|
// Act
|
|
37
|
-
await
|
|
45
|
+
await run('./my-app');
|
|
38
46
|
|
|
39
47
|
// Assert
|
|
40
48
|
FileMock.expectCreated('./my-app/package.json').toContain('"name": "my-app"');
|
package/src/commands/create.ts
CHANGED
|
@@ -15,10 +15,10 @@ export interface Options {
|
|
|
15
15
|
|
|
16
16
|
export class CreateCommand extends Command {
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
protected static command: string = 'create';
|
|
19
|
+
protected static description: string = 'Create AerogelJS app';
|
|
20
|
+
protected static parameters: [string, string][] = [['path', 'Application path']];
|
|
21
|
+
protected static options: CommandOptions = {
|
|
22
22
|
name: 'Application name',
|
|
23
23
|
local: {
|
|
24
24
|
type: 'boolean',
|
|
@@ -40,7 +40,7 @@ export class CreateCommand extends Command {
|
|
|
40
40
|
this.options = options;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
protected async run(): Promise<void> {
|
|
44
44
|
const path = this.path;
|
|
45
45
|
const name = this.options.name ?? stringToTitleCase(basename(path));
|
|
46
46
|
|
|
@@ -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 { GenerateComponentCommand } from './generate-component';
|
|
6
8
|
|
|
7
9
|
describe('Generate Component command', () => {
|
|
8
10
|
|
|
11
|
+
let run: StubCommandRunner<typeof GenerateComponentCommand>;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
run = stubCommandRunner(GenerateComponentCommand);
|
|
15
|
+
});
|
|
16
|
+
|
|
9
17
|
it('generates components', 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/components/FooBar.vue').toContain('<div>FooBar</div>');
|
|
@@ -22,7 +30,7 @@ describe('Generate Component command', () => {
|
|
|
22
30
|
FileMock.stub('package.json', '@aerogel/core');
|
|
23
31
|
|
|
24
32
|
// Act
|
|
25
|
-
await
|
|
33
|
+
await run('module/FooBar');
|
|
26
34
|
|
|
27
35
|
// Assert
|
|
28
36
|
FileMock.expectCreated('src/components/module/FooBar.vue').toContain('<div>FooBar</div>');
|
|
@@ -30,15 +38,60 @@ describe('Generate Component command', () => {
|
|
|
30
38
|
|
|
31
39
|
it('generates components with stories', async () => {
|
|
32
40
|
// Arrange
|
|
33
|
-
FileMock.stub(
|
|
34
|
-
|
|
41
|
+
FileMock.stub(
|
|
42
|
+
'package.json',
|
|
43
|
+
`
|
|
44
|
+
"@aerogel/core": "*",
|
|
45
|
+
"histoire": "*"
|
|
46
|
+
`,
|
|
47
|
+
);
|
|
35
48
|
|
|
36
49
|
// Act
|
|
37
|
-
await
|
|
50
|
+
await run('FooBar', { story: true });
|
|
38
51
|
|
|
39
52
|
// Assert
|
|
40
53
|
FileMock.expectCreated('src/components/FooBar.vue').toContain('<div>FooBar</div>');
|
|
41
54
|
FileMock.expectCreated('src/components/FooBar.story.vue').toContain('<FooBar />');
|
|
42
55
|
});
|
|
43
56
|
|
|
57
|
+
it('generates input components with stories', async () => {
|
|
58
|
+
// Arrange
|
|
59
|
+
FileMock.stub(
|
|
60
|
+
'package.json',
|
|
61
|
+
`
|
|
62
|
+
"@aerogel/core": "*",
|
|
63
|
+
"histoire": "*"
|
|
64
|
+
`,
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// Act
|
|
68
|
+
await run('FooBar', { input: true, story: true });
|
|
69
|
+
|
|
70
|
+
// Assert
|
|
71
|
+
FileMock.expectCreated('src/components/FooBar.vue').toContain('<AGHeadlessInputInput v-bind="attrs" />');
|
|
72
|
+
FileMock.expectCreated('src/components/FooBar.story.vue').toContain('.story-foobar .variant-playground');
|
|
73
|
+
FileMock.expectCreated('src/components/FooBar.story.vue').toContain(
|
|
74
|
+
'<FooBar name="food" :label="label" :placeholder="placeholder" />',
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('generates button components with stories', async () => {
|
|
79
|
+
// Arrange
|
|
80
|
+
FileMock.stub(
|
|
81
|
+
'package.json',
|
|
82
|
+
`
|
|
83
|
+
"@aerogel/core": "*",
|
|
84
|
+
"histoire": "*"
|
|
85
|
+
`,
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
// Act
|
|
89
|
+
await run('FooBar', { button: true, story: true });
|
|
90
|
+
|
|
91
|
+
// Assert
|
|
92
|
+
FileMock.expectCreated('src/components/FooBar.vue').toContain('<AGHeadlessButton :class="colorClasses">');
|
|
93
|
+
FileMock.expectCreated('src/components/FooBar.story.vue').toContain('.story-foobar .variant-playground');
|
|
94
|
+
FileMock.expectCreated('src/components/FooBar.story.vue').toContain('<FooBar :color="color">');
|
|
95
|
+
});
|
|
96
|
+
|
|
44
97
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { arrayFrom } from '@noeldemartin/utils';
|
|
1
|
+
import { arrayFrom, stringToSlug } from '@noeldemartin/utils';
|
|
2
2
|
import { Node, SyntaxKind } from 'ts-morph';
|
|
3
3
|
import type { ArrayLiteralExpression, CallExpression, SourceFile } from 'ts-morph';
|
|
4
4
|
|
|
@@ -12,18 +12,28 @@ import { templatePath } from '@/lib/utils/paths';
|
|
|
12
12
|
import type { CommandOptions } from '@/commands/Command';
|
|
13
13
|
|
|
14
14
|
export interface Options {
|
|
15
|
+
button?: boolean;
|
|
16
|
+
input?: boolean;
|
|
15
17
|
story?: boolean;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
export class GenerateComponentCommand extends Command {
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
protected static command: string = 'generate:component';
|
|
23
|
+
protected static description: string = 'Generate an AerogelJS Component';
|
|
24
|
+
protected static parameters: [string, string][] = [
|
|
23
25
|
['path', 'Component path (relative to components folder; extension not necessary)'],
|
|
24
26
|
];
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
protected static options: CommandOptions = {
|
|
29
|
+
button: {
|
|
30
|
+
description: 'Create a custom button',
|
|
31
|
+
type: 'boolean',
|
|
32
|
+
},
|
|
33
|
+
input: {
|
|
34
|
+
description: 'Create a custom input',
|
|
35
|
+
type: 'boolean',
|
|
36
|
+
},
|
|
27
37
|
story: {
|
|
28
38
|
description: 'Create component story using Histoire',
|
|
29
39
|
type: 'boolean',
|
|
@@ -40,7 +50,13 @@ export class GenerateComponentCommand extends Command {
|
|
|
40
50
|
this.options = options;
|
|
41
51
|
}
|
|
42
52
|
|
|
43
|
-
|
|
53
|
+
protected async validate(): Promise<void> {
|
|
54
|
+
if (this.options.button && this.options.input) {
|
|
55
|
+
Log.fail('Cannot use both \'button\' and \'input\' flags!');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
protected async run(): Promise<void> {
|
|
44
60
|
this.assertAerogelOrDirectory('src/components');
|
|
45
61
|
this.assertHistoireInstalled();
|
|
46
62
|
|
|
@@ -48,7 +64,7 @@ export class GenerateComponentCommand extends Command {
|
|
|
48
64
|
const [directoryName, componentName] = this.parsePathComponents();
|
|
49
65
|
|
|
50
66
|
await this.createComponent(directoryName, componentName, files);
|
|
51
|
-
await this.createStory(componentName, files);
|
|
67
|
+
await this.createStory(directoryName, componentName, files);
|
|
52
68
|
await this.declareComponents();
|
|
53
69
|
|
|
54
70
|
const filesList = arrayFrom(files)
|
|
@@ -63,8 +79,11 @@ export class GenerateComponentCommand extends Command {
|
|
|
63
79
|
return;
|
|
64
80
|
}
|
|
65
81
|
|
|
66
|
-
if (!File.
|
|
67
|
-
Log.fail(
|
|
82
|
+
if (!File.contains('package.json', '"histoire"') && !File.contains('package.json', '"@aerogel/histoire"')) {
|
|
83
|
+
Log.fail(`
|
|
84
|
+
Histoire is not installed yet! You can install it running:
|
|
85
|
+
npx ag install histoire
|
|
86
|
+
`);
|
|
68
87
|
}
|
|
69
88
|
}
|
|
70
89
|
|
|
@@ -74,22 +93,38 @@ export class GenerateComponentCommand extends Command {
|
|
|
74
93
|
Log.fail(`${this.path} component already exists!`);
|
|
75
94
|
}
|
|
76
95
|
|
|
77
|
-
const
|
|
78
|
-
component
|
|
96
|
+
const templateName = this.options.input
|
|
97
|
+
? 'component-input'
|
|
98
|
+
: this.options.button
|
|
99
|
+
? 'component-button'
|
|
100
|
+
: 'component';
|
|
101
|
+
const componentFiles = Template.instantiate(templatePath(templateName), `src/components/${directoryName}`, {
|
|
102
|
+
component: {
|
|
103
|
+
name: componentName,
|
|
104
|
+
slug: stringToSlug(componentName),
|
|
105
|
+
},
|
|
79
106
|
});
|
|
80
107
|
|
|
81
108
|
componentFiles.forEach((file) => files.add(file));
|
|
82
109
|
});
|
|
83
110
|
}
|
|
84
111
|
|
|
85
|
-
protected async createStory(componentName: string, files: Set<string>): Promise<void> {
|
|
112
|
+
protected async createStory(directoryName: string, componentName: string, files: Set<string>): Promise<void> {
|
|
86
113
|
if (!this.options.story) {
|
|
87
114
|
return;
|
|
88
115
|
}
|
|
89
116
|
|
|
90
117
|
await Log.animate('Creating story', async () => {
|
|
91
|
-
const
|
|
92
|
-
component
|
|
118
|
+
const templateName = this.options.input
|
|
119
|
+
? 'component-input-story'
|
|
120
|
+
: this.options.button
|
|
121
|
+
? 'component-button-story'
|
|
122
|
+
: 'component-story';
|
|
123
|
+
const storyFiles = Template.instantiate(templatePath(templateName), `src/components/${directoryName}`, {
|
|
124
|
+
component: {
|
|
125
|
+
name: componentName,
|
|
126
|
+
slug: stringToSlug(componentName),
|
|
127
|
+
},
|
|
93
128
|
});
|
|
94
129
|
|
|
95
130
|
storyFiles.forEach((file) => files.add(file));
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import { describe, it } from 'vitest';
|
|
1
|
+
import { beforeEach, describe, it } from 'vitest';
|
|
2
2
|
import { formatCodeBlock } from '@noeldemartin/utils';
|
|
3
3
|
|
|
4
4
|
import FileMock from '@/lib/File.mock';
|
|
5
|
+
import { stubCommandRunner } from '@/testing/utils';
|
|
6
|
+
import type { StubCommandRunner } from '@/testing/utils';
|
|
5
7
|
|
|
6
8
|
import { GenerateModelCommand } from './generate-model';
|
|
7
9
|
|
|
8
10
|
describe('Generate Model command', () => {
|
|
9
11
|
|
|
12
|
+
let run: StubCommandRunner<typeof GenerateModelCommand>;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
run = stubCommandRunner(GenerateModelCommand);
|
|
16
|
+
});
|
|
17
|
+
|
|
10
18
|
it('generates models', async () => {
|
|
11
19
|
// Arrange
|
|
12
20
|
FileMock.stub(
|
|
@@ -20,7 +28,7 @@ describe('Generate Model command', () => {
|
|
|
20
28
|
);
|
|
21
29
|
|
|
22
30
|
// Act
|
|
23
|
-
await
|
|
31
|
+
await run('FooBar', {
|
|
24
32
|
fields: 'name:string:required,age:number,birth:Date',
|
|
25
33
|
});
|
|
26
34
|
|
|
@@ -13,10 +13,10 @@ interface Options {
|
|
|
13
13
|
|
|
14
14
|
export class GenerateModelCommand extends Command {
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 = {
|
|
20
20
|
fields: 'Create model with the given fields',
|
|
21
21
|
};
|
|
22
22
|
|
|
@@ -30,7 +30,7 @@ export class GenerateModelCommand extends Command {
|
|
|
30
30
|
this.options = options;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
protected async run(): Promise<void> {
|
|
34
34
|
this.assertAerogelOrDirectory('src/models');
|
|
35
35
|
|
|
36
36
|
if (File.exists(`src/models/${this.name}.ts`)) {
|
|
@@ -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');
|
|
@@ -13,9 +13,9 @@ import type { Editor } from '@/lib/Editor';
|
|
|
13
13
|
|
|
14
14
|
export class GenerateServiceCommand extends Command {
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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']];
|
|
19
19
|
|
|
20
20
|
private name: string;
|
|
21
21
|
|
|
@@ -25,7 +25,7 @@ export class GenerateServiceCommand extends Command {
|
|
|
25
25
|
this.name = name;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
protected async run(): Promise<void> {
|
|
29
29
|
this.assertAerogelOrDirectory('src/services');
|
|
30
30
|
|
|
31
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 () => {
|
|
10
19
|
// Act
|
|
11
|
-
await
|
|
20
|
+
await run('solid');
|
|
12
21
|
|
|
13
22
|
// Assert
|
|
14
23
|
ShellMock.expectRan('npm install soukai-solid@next --save-exact');
|
|
15
24
|
ShellMock.expectRan('npm install @aerogel/plugin-solid@next --save-exact');
|
|
16
25
|
});
|
|
17
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
|
+
|
|
40
|
+
// Act
|
|
41
|
+
await run('histoire');
|
|
42
|
+
|
|
43
|
+
// Assert
|
|
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');
|
|
47
|
+
});
|
|
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
|
@@ -33,13 +33,15 @@ export class Editor {
|
|
|
33
33
|
await Log.animate('Formatting modified files', async () => {
|
|
34
34
|
const usingPrettier = File.exists('prettier.config.js') || File.contains('package.json', '"prettier": {');
|
|
35
35
|
const usingESLint = File.exists('.eslintrc.js') || File.contains('package.json', '"eslintConfig"');
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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) => {
|
|
39
40
|
usingPrettier && (await Shell.run(`npx prettier ${file} --write`));
|
|
40
41
|
file.match(/\.(ts|js|vue)$/) && usingESLint && (await Shell.run(`npx eslint ${file} --fix`));
|
|
41
|
-
}
|
|
42
|
-
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
await Promise.all(arrayFrom(this.modifiedFiles).map(async (file) => formatFile(file)));
|
|
43
45
|
});
|
|
44
46
|
}
|
|
45
47
|
|
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
|
+
}
|