@aerogel/cli 0.0.0-next.f16bd1d894543c5303039c49f6f33488a1ffe931 → 0.0.0-next.f9394854509d71d644498ac087706a2f8f8eea1c

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.
Files changed (74) hide show
  1. package/.prettierignore +1 -0
  2. package/dist/aerogel-cli.cjs.js +1 -1
  3. package/dist/aerogel-cli.cjs.js.map +1 -1
  4. package/dist/aerogel-cli.d.ts +2 -2
  5. package/dist/aerogel-cli.esm.js +1 -1
  6. package/dist/aerogel-cli.esm.js.map +1 -1
  7. package/package.json +10 -4
  8. package/src/cli.ts +23 -3
  9. package/src/commands/Command.ts +11 -6
  10. package/src/commands/create.test.ts +10 -1
  11. package/src/commands/create.ts +10 -7
  12. package/src/commands/generate-component.test.ts +49 -2
  13. package/src/commands/generate-component.ts +60 -14
  14. package/src/commands/generate-model.test.ts +1 -1
  15. package/src/commands/generate-model.ts +7 -8
  16. package/src/commands/generate-overrides.ts +85 -0
  17. package/src/commands/generate-service.test.ts +1 -1
  18. package/src/commands/generate-service.ts +6 -7
  19. package/src/commands/info.ts +14 -0
  20. package/src/commands/install.test.ts +24 -1
  21. package/src/commands/install.ts +6 -5
  22. package/src/lib/Editor.ts +16 -9
  23. package/src/lib/File.mock.ts +1 -5
  24. package/src/lib/File.ts +1 -1
  25. package/src/lib/Log.mock.ts +1 -5
  26. package/src/lib/Log.ts +1 -1
  27. package/src/lib/Shell.mock.ts +2 -2
  28. package/src/lib/Shell.ts +1 -1
  29. package/src/lib/Template.ts +5 -1
  30. package/src/lib/utils/app.ts +1 -1
  31. package/src/lib/utils/paths.ts +1 -1
  32. package/src/plugins/Histoire.ts +113 -0
  33. package/src/plugins/Plugin.ts +58 -5
  34. package/src/plugins/Solid.ts +47 -33
  35. package/src/testing/setup.ts +3 -6
  36. package/templates/app/.github/workflows/ci.yml +16 -4
  37. package/templates/app/README.md +3 -0
  38. package/templates/app/cypress/cypress.config.ts +14 -0
  39. package/templates/app/cypress/support/e2e.ts +1 -3
  40. package/templates/app/cypress/tsconfig.json +3 -1
  41. package/templates/app/index.html +3 -2
  42. package/templates/app/package.json +17 -4
  43. package/templates/app/src/App.vue +2 -2
  44. package/templates/app/src/assets/public/robots.txt +2 -0
  45. package/templates/app/src/main.ts +4 -4
  46. package/templates/app/tsconfig.json +1 -0
  47. package/templates/app/vite.config.ts +8 -2
  48. package/templates/component-button/[component.name].vue +42 -0
  49. package/templates/component-button-story/[component.name].story.vue +77 -0
  50. package/templates/component-checkbox/[component.name].vue +34 -0
  51. package/templates/component-checkbox-story/[component.name].story.vue +63 -0
  52. package/templates/component-input/[component.name].vue +17 -0
  53. package/templates/component-input-story/[component.name].story.vue +63 -0
  54. package/templates/histoire/histoire.config.ts +7 -0
  55. package/templates/histoire/patches/histoire+0.17.6.patch +13 -0
  56. package/templates/histoire/src/main.histoire.ts +8 -0
  57. package/templates/overrides/components/index.ts +15 -0
  58. package/templates/overrides/components/overrides/AlertModal.vue +11 -0
  59. package/templates/overrides/components/overrides/ConfirmModal.vue +20 -0
  60. package/templates/overrides/components/overrides/ErrorReportModal.vue +35 -0
  61. package/templates/overrides/components/overrides/LoadingModal.vue +12 -0
  62. package/templates/overrides/components/overrides/ModalWrapper.vue +22 -0
  63. package/templates/overrides/components/overrides/SnackbarNotification.vue +34 -0
  64. package/templates/overrides-story/Overrides.story.vue +86 -0
  65. package/templates/postcss-pseudo-classes/postcss.config.js +15 -0
  66. package/templates/service/[service.name].ts +1 -1
  67. package/.eslintrc.js +0 -7
  68. package/src/lib/utils/format.test.ts +0 -33
  69. package/src/lib/utils/format.ts +0 -38
  70. package/templates/app/.eslintrc.js +0 -3
  71. package/templates/app/cypress.config.ts +0 -12
  72. package/templates/app/prettier.config.js +0 -5
  73. /package/bin/{ag → gel} +0 -0
  74. /package/templates/app/src/assets/{styles.css → css/main.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
- public static command: string = 'generate:model';
18
- public static description: string = 'Generate an AerogelJS Model';
19
- public static parameters: [string, string][] = [['name', 'Model name']];
20
- public static options: CommandOptions = {
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
- public async run(): Promise<void> {
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 ag install soukai
93
+ npx gel install soukai
95
94
  `);
96
95
  }
97
96
  }
@@ -0,0 +1,85 @@
1
+ import { arrayFrom } from '@noeldemartin/utils';
2
+
3
+ import Command from '@/commands/Command';
4
+ import File from '@/lib/File';
5
+ import Log from '@/lib/Log';
6
+ import Template from '@/lib/Template';
7
+ import { templatePath } from '@/lib/utils/paths';
8
+ import type { CommandOptions } from '@/commands/Command';
9
+
10
+ export interface Options {
11
+ story?: boolean;
12
+ }
13
+
14
+ export class GenerateOverridesCommand extends Command {
15
+
16
+ protected static command: string = 'generate:overrides';
17
+ protected static description: string = 'Generate AerogelJS component overrides';
18
+
19
+ protected static options: CommandOptions = {
20
+ story: {
21
+ description: 'Create overrides story using Histoire',
22
+ type: 'boolean',
23
+ },
24
+ };
25
+
26
+ private options: Options;
27
+
28
+ constructor(options: Options = {}) {
29
+ super();
30
+
31
+ this.options = options;
32
+ }
33
+
34
+ protected async run(): Promise<void> {
35
+ this.assertAerogelOrDirectory('src/components');
36
+ this.assertHistoireInstalled();
37
+
38
+ const files = new Set<string>();
39
+
40
+ await this.createComponents(files);
41
+ await this.createStory(files);
42
+
43
+ const filesList = arrayFrom(files)
44
+ .map((file) => `- ${file}`)
45
+ .join('\n');
46
+
47
+ Log.info(`Overrides created successfully! The following files were created:\n\n${filesList}`);
48
+ Log.info('\nRemember to declare your components in main.ts and main.histoire.ts!');
49
+ }
50
+
51
+ protected assertHistoireInstalled(): void {
52
+ if (!this.options.story) {
53
+ return;
54
+ }
55
+
56
+ if (!File.contains('package.json', '"histoire"') && !File.contains('package.json', '"@aerogel/histoire"')) {
57
+ Log.fail(`
58
+ Histoire is not installed yet! You can install it running:
59
+ npx gel install histoire
60
+ `);
61
+ }
62
+ }
63
+
64
+ protected async createComponents(files: Set<string>): Promise<void> {
65
+ await Log.animate('Creating components', async () => {
66
+ if (File.exists('src/components/ModalWrapper.vue')) {
67
+ Log.fail('ModalWrapper component already exists!');
68
+ }
69
+
70
+ Template.instantiate(templatePath('overrides'), 'src').forEach((file) => files.add(file));
71
+ });
72
+ }
73
+
74
+ protected async createStory(files: Set<string>): Promise<void> {
75
+ if (!this.options.story) {
76
+ return;
77
+ }
78
+
79
+ await Log.animate('Creating story', async () => {
80
+ Template.instantiate(templatePath('overrides-story'), 'src/components/overrides/').forEach((file) =>
81
+ files.add(file));
82
+ });
83
+ }
84
+
85
+ }
@@ -15,7 +15,7 @@ describe('Generate Service command', () => {
15
15
 
16
16
  // Assert
17
17
  FileMock.expectCreated('src/services/FooBar.ts').toContain('class FooBarService extends Service');
18
- FileMock.expectCreated('src/services/FooBar.ts').toContain('export default facade(new FooBarService());');
18
+ FileMock.expectCreated('src/services/FooBar.ts').toContain('export default facade(FooBarService);');
19
19
  });
20
20
 
21
21
  });
@@ -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
- public static command: string = 'generate:service';
18
- public static description: string = 'Generate an AerogelJS Service';
19
- public static parameters: [string, string][] = [['name', 'Service name']];
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
- public async run(): Promise<void> {
28
+ protected async run(): Promise<void> {
30
29
  this.assertAerogelOrDirectory('src/services');
31
30
 
32
31
  const files = new Set<string>();
@@ -123,7 +122,7 @@ export class GenerateServiceCommand extends Command {
123
122
  protected getBootstrapOptions(mainConfig: SourceFile): ObjectLiteralExpression | null {
124
123
  const bootstrapAppCall = findDescendant(mainConfig, {
125
124
  guard: Node.isCallExpression,
126
- validate: (callExpression) => callExpression.getExpression().getText() === 'bootstrapApplication',
125
+ validate: (callExpression) => callExpression.getExpression().getText() === 'bootstrap',
127
126
  skip: SyntaxKind.ImportDeclaration,
128
127
  });
129
128
  const bootstrapOptions = bootstrapAppCall?.getArguments()[1];
@@ -0,0 +1,14 @@
1
+ import Command from '@/commands/Command';
2
+ import Log from '@/lib/Log';
3
+
4
+ export class InfoCommand extends Command {
5
+
6
+ protected static command: string = 'info';
7
+ protected static description: string = 'Show debugging information about the CLI';
8
+
9
+ protected async run(): Promise<void> {
10
+ Log.info('[AerogelJS CLI info]');
11
+ Log.info('Installation directory: ' + __dirname);
12
+ }
13
+
14
+ }
@@ -1,12 +1,13 @@
1
1
  import { describe, it } from 'vitest';
2
2
 
3
+ import FileMock from '@/lib/File.mock';
3
4
  import ShellMock from '@/lib/Shell.mock';
4
5
 
5
6
  import { InstallCommand } from './install';
6
7
 
7
8
  describe('Install plugin command', () => {
8
9
 
9
- it('installs plugins', async () => {
10
+ it('installs solid', async () => {
10
11
  // Act
11
12
  await InstallCommand.run('solid');
12
13
 
@@ -15,4 +16,26 @@ describe('Install plugin command', () => {
15
16
  ShellMock.expectRan('npm install @aerogel/plugin-solid@next --save-exact');
16
17
  });
17
18
 
19
+ it('installs soukai', async () => {
20
+ // Act
21
+ await InstallCommand.run('soukai');
22
+
23
+ // Assert
24
+ ShellMock.expectRan('npm install soukai@next --save-exact');
25
+ ShellMock.expectRan('npm install @aerogel/plugin-soukai@next --save-exact');
26
+ });
27
+
28
+ it('installs histoire', async () => {
29
+ // Arrange
30
+ FileMock.stub('package.json', '"@aerogel/core"');
31
+
32
+ // Act
33
+ await InstallCommand.run('histoire');
34
+
35
+ // Assert
36
+ ShellMock.expectRan('npm install histoire@0.17.6 --save-dev');
37
+ ShellMock.expectRan('npm install @aerogel/histoire@next --save-exact --save-dev');
38
+ ShellMock.expectRan('npm install patch-package --save-dev');
39
+ });
40
+
18
41
  });
@@ -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
- public static command: string = 'install';
15
- public static description: string = 'Install an AerogelJS plugin';
16
- public static parameters: [string, string][] = [['plugin', 'Plugin to install']];
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
- public async run(): Promise<void> {
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
- await Promise.all(
37
- arrayFrom(this.modifiedFiles).map(async (file) => {
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.modifiedFiles.add(file.getFilePath());
51
+ this.addModifiedFile(file.getFilePath());
52
+ }
53
+
54
+ public addModifiedFile(path: string): void {
55
+ this.modifiedFiles.add(path);
49
56
  }
50
57
 
51
58
  }
@@ -41,10 +41,6 @@ export class FileMockService extends FileService {
41
41
  this.virtualFilesystem[path] = contents;
42
42
  }
43
43
 
44
- public reset(): void {
45
- this.virtualFilesystem = {};
46
- }
47
-
48
44
  public expectCreated(path: string, expectContent?: (contents: string) => void): Assertion<string> {
49
45
  expect(typeof this.virtualFilesystem[path] === 'string', `expected '${path}' file to have been created`).toBe(
50
46
  true,
@@ -63,4 +59,4 @@ export class FileMockService extends FileService {
63
59
 
64
60
  }
65
61
 
66
- export default facade(new FileMockService());
62
+ export default facade(FileMockService);
package/src/lib/File.ts CHANGED
@@ -73,4 +73,4 @@ export class FileService {
73
73
 
74
74
  }
75
75
 
76
- export default facade(new FileService());
76
+ export default facade(FileService);
@@ -24,14 +24,10 @@ export class LogServiceMock extends LogService {
24
24
  throw new Error(`Fail: ${message}`);
25
25
  }
26
26
 
27
- public reset(): void {
28
- this.logs = [];
29
- }
30
-
31
27
  protected stdout(): void {
32
28
  //
33
29
  }
34
30
 
35
31
  }
36
32
 
37
- export default facade(new LogServiceMock());
33
+ export default facade(LogServiceMock);
package/src/lib/Log.ts CHANGED
@@ -92,4 +92,4 @@ export class LogService {
92
92
 
93
93
  }
94
94
 
95
- export default facade(new LogService());
95
+ export default facade(LogService);
@@ -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 {
@@ -17,4 +17,4 @@ export class ShellServiceMock extends ShellService {
17
17
 
18
18
  }
19
19
 
20
- export default facade(new ShellServiceMock());
20
+ export default facade(ShellServiceMock);
package/src/lib/Shell.ts CHANGED
@@ -25,4 +25,4 @@ export class ShellService {
25
25
 
26
26
  }
27
27
 
28
- export default facade(new ShellService());
28
+ export default facade(ShellService);
@@ -6,7 +6,11 @@ import File from '@/lib/File';
6
6
 
7
7
  export default class Template {
8
8
 
9
- public static instantiate(path: string, destination: string, replacements: Record<string, unknown>): string[] {
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);
@@ -7,7 +7,7 @@ export function app(): App {
7
7
  }
8
8
 
9
9
  export function isLocalApp(): boolean {
10
- return File.contains('package.json', 'file');
10
+ return File.contains('package.json', '"@aerogel/core": "file:');
11
11
  }
12
12
 
13
13
  export function isLinkedLocalApp(): boolean {
@@ -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\/cli": "file:(.*)\/aerogel-cli-[\d.]*\.tgz"/);
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,113 @@
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
+ import { formatCodeBlock } from '@noeldemartin/utils';
10
+
11
+ export class Histoire extends Plugin {
12
+
13
+ private installedPatchPackage: boolean = false;
14
+ private installedPostCSSPseudoClasses: boolean = false;
15
+
16
+ constructor() {
17
+ super('histoire');
18
+ }
19
+
20
+ public async beforeInstall(): Promise<void> {
21
+ this.installedPatchPackage = false;
22
+ this.installedPostCSSPseudoClasses = false;
23
+ }
24
+
25
+ protected async afterInstall(): Promise<void> {
26
+ if (!this.installedPatchPackage) {
27
+ return;
28
+ }
29
+
30
+ await Log.animate('Patching dependencies', async () => {
31
+ await Shell.run('npx patch-package');
32
+ });
33
+ }
34
+
35
+ protected async updateFiles(editor: Editor): Promise<void> {
36
+ await this.updateTailwindConfig(editor, {
37
+ content: isLinkedLocalApp()
38
+ ? `'${packagePath('histoire')}/dist/**/*.js'`
39
+ : '\'./node_modules/@aerogel/histoire/dist/**/*.js\'',
40
+ });
41
+
42
+ await this.updateNpmScripts(editor);
43
+ await this.createConfigFiles();
44
+ await super.updateFiles(editor);
45
+ }
46
+
47
+ protected async installNpmDependencies(): Promise<void> {
48
+ // We need this specific version because we're patching it using patch-package
49
+ await Shell.run('npm install histoire@0.17.6 --save-dev');
50
+
51
+ if (!File.contains('package.json', '"patch-package"')) {
52
+ await Shell.run('npm install patch-package --save-dev');
53
+
54
+ this.installedPatchPackage = true;
55
+ }
56
+
57
+ if (!File.contains('package.json', '"postcss-pseudo-classes"')) {
58
+ await Shell.run('npm install postcss-pseudo-classes --save-dev');
59
+
60
+ this.installedPostCSSPseudoClasses = true;
61
+ }
62
+
63
+ await super.installNpmDependencies();
64
+ }
65
+
66
+ protected getLocalPackageName(): string {
67
+ return this.name;
68
+ }
69
+
70
+ protected async updateNpmScripts(editor: Editor): Promise<void> {
71
+ Log.info('Updating npm scripts...');
72
+
73
+ const packageJson = File.read('package.json');
74
+
75
+ if (!packageJson) {
76
+ return Log.fail('Could not find package.json file');
77
+ }
78
+
79
+ File.write(
80
+ 'package.json',
81
+ packageJson.replace(
82
+ '"lint": "noeldemartin-lint src cypress",',
83
+ this.installedPatchPackage
84
+ ? formatCodeBlock(`
85
+ "histoire": "histoire dev",
86
+ "lint": "noeldemartin-lint cypress src",
87
+ "postinstall": "patch-package",
88
+ `)
89
+ : formatCodeBlock(`
90
+ "histoire": "histoire dev",
91
+ "lint": "noeldemartin-lint cypress src",
92
+ `),
93
+ ),
94
+ );
95
+
96
+ editor.addModifiedFile('package.json');
97
+ }
98
+
99
+ protected async createConfigFiles(): Promise<void> {
100
+ Log.info('Creating config files...');
101
+
102
+ Template.instantiate(templatePath('histoire'));
103
+
104
+ if (this.installedPostCSSPseudoClasses) {
105
+ Template.instantiate(templatePath('postcss-pseudo-classes'));
106
+ }
107
+ }
108
+
109
+ protected isForDevelopment(): boolean {
110
+ return true;
111
+ }
112
+
113
+ }
@@ -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
- await this.updateBootstrapConfig(editor);
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 --save-exact`);
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,10 +101,29 @@ 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,
92
- validate: (callExpression) => callExpression.getExpression().getText() === 'bootstrapApplication',
126
+ validate: (callExpression) => callExpression.getExpression().getText() === 'bootstrap',
93
127
  skip: SyntaxKind.ImportDeclaration,
94
128
  });
95
129
  const bootstrapOptions = bootstrapAppCall?.getArguments()[1];
@@ -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
  }