@aerogel/cli 0.0.0-next.47ed8ee3c048720794026e45140e9b700cb428b9 → 0.0.0-next.5953e1862a7c89a8fc80da087467d67d4f4e8c73

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 (58) hide show
  1. package/dist/aerogel-cli.cjs.js +1 -1
  2. package/dist/aerogel-cli.cjs.js.map +1 -1
  3. package/dist/aerogel-cli.esm.js +1 -1
  4. package/dist/aerogel-cli.esm.js.map +1 -1
  5. package/package.json +11 -4
  6. package/src/cli.ts +4 -0
  7. package/src/commands/create.test.ts +22 -5
  8. package/src/commands/create.ts +30 -12
  9. package/src/commands/generate-component.test.ts +40 -3
  10. package/src/commands/generate-component.ts +143 -20
  11. package/src/commands/generate-model.test.ts +7 -4
  12. package/src/commands/generate-model.ts +32 -15
  13. package/src/commands/generate-service.test.ts +21 -0
  14. package/src/commands/generate-service.ts +151 -0
  15. package/src/commands/install.test.ts +41 -0
  16. package/src/commands/install.ts +33 -0
  17. package/src/lib/App.ts +65 -3
  18. package/src/lib/Editor.ts +58 -0
  19. package/src/lib/File.ts +6 -0
  20. package/src/lib/Log.mock.ts +13 -4
  21. package/src/lib/Log.test.ts +19 -3
  22. package/src/lib/Log.ts +36 -20
  23. package/src/lib/Shell.mock.ts +1 -1
  24. package/src/lib/Template.ts +5 -1
  25. package/src/lib/utils/app.ts +15 -0
  26. package/src/lib/utils/edit.ts +44 -0
  27. package/src/lib/utils/paths.ts +34 -0
  28. package/src/plugins/Histoire.ts +93 -0
  29. package/src/plugins/Plugin.ts +178 -0
  30. package/src/plugins/Solid.ts +78 -0
  31. package/src/plugins/Soukai.ts +19 -0
  32. package/src/testing/setup.ts +38 -6
  33. package/templates/app/.github/workflows/ci.yml +14 -2
  34. package/templates/app/.vscode/launch.json +16 -0
  35. package/templates/app/.vscode/settings.json +10 -0
  36. package/templates/app/README.md +3 -0
  37. package/templates/app/cypress/cypress.config.ts +16 -0
  38. package/templates/app/index.html +4 -3
  39. package/templates/app/package.json +34 -12
  40. package/templates/app/src/App.vue +5 -3
  41. package/templates/app/src/assets/public/robots.txt +2 -0
  42. package/templates/app/src/main.ts +6 -2
  43. package/templates/app/src/types/globals.d.ts +0 -1
  44. package/templates/app/tailwind.config.js +1 -1
  45. package/templates/app/tsconfig.json +1 -0
  46. package/templates/app/vite.config.ts +14 -6
  47. package/templates/component-input/[component.name].vue +16 -0
  48. package/templates/component-input-story/[component.name].story.vue +63 -0
  49. package/templates/histoire/histoire.config.ts +7 -0
  50. package/templates/histoire/patches/histoire+0.17.6.patch +13 -0
  51. package/templates/histoire/src/main.histoire.ts +8 -0
  52. package/templates/service/[service.name].ts +8 -0
  53. package/.eslintrc.js +0 -7
  54. package/noeldemartin.config.js +0 -4
  55. package/src/lib/utils.test.ts +0 -33
  56. package/src/lib/utils.ts +0 -44
  57. package/templates/app/cypress.config.ts +0 -8
  58. /package/templates/app/src/assets/{styles.css → css/styles.css} +0 -0
@@ -0,0 +1,151 @@
1
+ import { arrayFrom, formatCodeBlock, stringToCamelCase } from '@noeldemartin/utils';
2
+ import { Node, SyntaxKind } from 'ts-morph';
3
+ import type { ObjectLiteralExpression, SourceFile } from 'ts-morph';
4
+
5
+ import Command from '@/commands/Command';
6
+ import File from '@/lib/File';
7
+ import Log from '@/lib/Log';
8
+ import Template from '@/lib/Template';
9
+ import { app } from '@/lib/utils/app';
10
+ import { templatePath } from '@/lib/utils/paths';
11
+ import { editFiles, findDescendant } from '@/lib/utils/edit';
12
+ import type { Editor } from '@/lib/Editor';
13
+
14
+ export class GenerateServiceCommand extends Command {
15
+
16
+ public static command: string = 'generate:service';
17
+ public static description: string = 'Generate an AerogelJS Service';
18
+ public static parameters: [string, string][] = [['name', 'Service name']];
19
+
20
+ private name: string;
21
+
22
+ constructor(name: string) {
23
+ super();
24
+
25
+ this.name = name;
26
+ }
27
+
28
+ public async run(): Promise<void> {
29
+ this.assertAerogelOrDirectory('src/services');
30
+
31
+ const files = new Set<string>();
32
+ const editor = app().edit();
33
+
34
+ await this.createService(files);
35
+
36
+ if (editFiles()) {
37
+ await this.registerService(editor);
38
+ await editor.format();
39
+ }
40
+
41
+ const filesList = arrayFrom(files)
42
+ .map((file) => `- ${file}`)
43
+ .join('\n');
44
+
45
+ Log.info(`${this.name} service created successfully! The following files were created:\n\n${filesList}`);
46
+ }
47
+
48
+ protected async createService(files: Set<string>): Promise<void> {
49
+ await Log.animate('Creating service', async () => {
50
+ if (File.exists(`src/services/${this.name}.ts`)) {
51
+ Log.fail(`${this.name} service already exists!`);
52
+ }
53
+
54
+ const serviceFiles = Template.instantiate(templatePath('service'), 'src/services', {
55
+ service: {
56
+ name: this.name,
57
+ },
58
+ });
59
+
60
+ serviceFiles.forEach((file) => files.add(file));
61
+ });
62
+ }
63
+
64
+ protected async registerService(editor: Editor): Promise<void> {
65
+ await Log.animate('Registering service', async () => {
66
+ if (!File.exists('src/services/index.ts')) {
67
+ await this.createServicesIndex(editor);
68
+ }
69
+
70
+ const servicesIndex = editor.requireSourceFile('src/services/index.ts');
71
+ const servicesObject = this.getServicesObject(servicesIndex);
72
+
73
+ if (!servicesObject) {
74
+ return Log.fail('Could not find services object in services config, please add it manually.');
75
+ }
76
+
77
+ servicesIndex.addImportDeclaration({
78
+ defaultImport: this.name,
79
+ moduleSpecifier: `./${this.name}`,
80
+ });
81
+ servicesObject.addPropertyAssignment({
82
+ name: `$${stringToCamelCase(this.name)}`,
83
+ initializer: this.name,
84
+ });
85
+
86
+ await editor.save(servicesIndex);
87
+ });
88
+ }
89
+
90
+ protected async createServicesIndex(editor: Editor): Promise<void> {
91
+ File.write(
92
+ 'src/services/index.ts',
93
+ formatCodeBlock(`
94
+ export const services = {};
95
+
96
+ export type AppServices = typeof services;
97
+
98
+ declare module '@vue/runtime-core' {
99
+ interface ComponentCustomProperties extends AppServices {}
100
+ }
101
+ `),
102
+ );
103
+
104
+ editor.addSourceFile('src/services/index.ts');
105
+
106
+ const mainConfig = editor.requireSourceFile('src/main.ts');
107
+ const bootstrapOptions = this.getBootstrapOptions(mainConfig);
108
+
109
+ if (!bootstrapOptions) {
110
+ return Log.fail('Could not find options object in bootstrap config, please add the services manually.');
111
+ }
112
+
113
+ bootstrapOptions.insertShorthandPropertyAssignment(0, { name: 'services' });
114
+ mainConfig.addImportDeclaration({
115
+ namedImports: ['services'],
116
+ moduleSpecifier: './services',
117
+ });
118
+
119
+ await editor.save(mainConfig);
120
+ }
121
+
122
+ protected getBootstrapOptions(mainConfig: SourceFile): ObjectLiteralExpression | null {
123
+ const bootstrapAppCall = findDescendant(mainConfig, {
124
+ guard: Node.isCallExpression,
125
+ validate: (callExpression) => callExpression.getExpression().getText() === 'bootstrapApplication',
126
+ skip: SyntaxKind.ImportDeclaration,
127
+ });
128
+ const bootstrapOptions = bootstrapAppCall?.getArguments()[1];
129
+
130
+ if (!Node.isObjectLiteralExpression(bootstrapOptions)) {
131
+ return null;
132
+ }
133
+
134
+ return bootstrapOptions;
135
+ }
136
+
137
+ protected getServicesObject(servicesIndex: SourceFile): ObjectLiteralExpression | null {
138
+ const servicesDeclaration = findDescendant(servicesIndex, {
139
+ guard: Node.isVariableDeclaration,
140
+ validate: (variableDeclaration) => variableDeclaration.getName() === 'services',
141
+ });
142
+ const servicesObject = servicesDeclaration?.getInitializer();
143
+
144
+ if (!Node.isObjectLiteralExpression(servicesObject)) {
145
+ return null;
146
+ }
147
+
148
+ return servicesObject;
149
+ }
150
+
151
+ }
@@ -0,0 +1,41 @@
1
+ import { describe, it } from 'vitest';
2
+
3
+ import FileMock from '@/lib/File.mock';
4
+ import ShellMock from '@/lib/Shell.mock';
5
+
6
+ import { InstallCommand } from './install';
7
+
8
+ describe('Install plugin command', () => {
9
+
10
+ it('installs solid', async () => {
11
+ // Act
12
+ await InstallCommand.run('solid');
13
+
14
+ // Assert
15
+ ShellMock.expectRan('npm install soukai-solid@next --save-exact');
16
+ ShellMock.expectRan('npm install @aerogel/plugin-solid@next --save-exact');
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
+
41
+ });
@@ -0,0 +1,33 @@
1
+ import Command from '@/commands/Command';
2
+ import Log from '@/lib/Log';
3
+ import { Histoire } from '@/plugins/Histoire';
4
+ import { Solid } from '@/plugins/Solid';
5
+ import { Soukai } from '@/plugins/Soukai';
6
+ import type Plugin from '@/plugins/Plugin';
7
+
8
+ const plugins = [new Soukai(), new Solid(), new Histoire()].reduce(
9
+ (pluginsObject, plugin) => Object.assign(pluginsObject, { [plugin.name]: plugin }),
10
+ {} as Record<string, Plugin>,
11
+ );
12
+
13
+ export class InstallCommand extends Command {
14
+
15
+ public static command: string = 'install';
16
+ public static description: string = 'Install an AerogelJS plugin';
17
+ public static parameters: [string, string][] = [['plugin', 'Plugin to install']];
18
+
19
+ private plugin: Plugin;
20
+
21
+ constructor(plugin: string) {
22
+ super();
23
+
24
+ this.plugin =
25
+ plugins[plugin] ??
26
+ Log.fail(`Plugin '${plugin}' doesn't exist. Available plugins: ${Object.keys(plugins).join(', ')}`);
27
+ }
28
+
29
+ public async run(): Promise<void> {
30
+ await this.plugin.install();
31
+ }
32
+
33
+ }
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 { basePath } from '@/lib/utils';
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(public name: string) {}
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(basePath('templates/app'), path, {
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,58 @@
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') || 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) => {
40
+ usingPrettier && (await Shell.run(`npx prettier ${file} --write`));
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)));
45
+ });
46
+ }
47
+
48
+ public async save(file: SourceFile): Promise<void> {
49
+ await file.save();
50
+
51
+ this.addModifiedFile(file.getFilePath());
52
+ }
53
+
54
+ public addModifiedFile(path: string): void {
55
+ this.modifiedFiles.add(path);
56
+ }
57
+
58
+ }
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;
@@ -1,5 +1,5 @@
1
1
  import { expect } from 'vitest';
2
- import { arrayFrom, facade } from '@noeldemartin/utils';
2
+ import { facade } from '@noeldemartin/utils';
3
3
 
4
4
  import { LogService } from './Log';
5
5
 
@@ -11,14 +11,23 @@ export class LogServiceMock extends LogService {
11
11
  expect(this.logs, `Expected message "${message}" to have been logged`).toContain(message);
12
12
  }
13
13
 
14
- protected log(messages: string | string[]): void {
15
- this.logs.push(...arrayFrom(messages));
14
+ public expectLogLength(count: number): void {
15
+ expect(this.logs, `Expected log to have length ${count}`).toHaveLength(count);
16
16
  }
17
17
 
18
- public fail(message: string): void {
18
+ protected logLine(message: string): void {
19
+ this.logs.push(message);
20
+ }
21
+
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
+ public fail<T = any>(message: string): T {
19
24
  throw new Error(`Fail: ${message}`);
20
25
  }
21
26
 
27
+ public reset(): void {
28
+ this.logs = [];
29
+ }
30
+
22
31
  protected stdout(): void {
23
32
  //
24
33
  }
@@ -5,12 +5,11 @@ import LogMock from '@/lib/Log.mock';
5
5
 
6
6
  import Log from './Log';
7
7
 
8
+ const info = hex('#00ffff');
9
+
8
10
  describe('Log', () => {
9
11
 
10
12
  it('renders markdown bold', () => {
11
- // Arrange
12
- const info = hex('#00ffff');
13
-
14
13
  // Act
15
14
  Log.info('Foo **bar**');
16
15
 
@@ -18,4 +17,21 @@ describe('Log', () => {
18
17
  LogMock.expectLogged(info(`Foo ${bold('bar')}`));
19
18
  });
20
19
 
20
+ it('renders multiline messages', () => {
21
+ // Act
22
+ Log.info(`
23
+ This is multiline,
24
+ but the indentation should be respected.
25
+
26
+ As well as the new lines.
27
+ `);
28
+
29
+ // Assert
30
+ LogMock.expectLogLength(4);
31
+ LogMock.expectLogged(info('This is multiline,'));
32
+ LogMock.expectLogged(info(' but the indentation should be respected.'));
33
+ LogMock.expectLogged(info(''));
34
+ LogMock.expectLogged(info('As well as the new lines.'));
35
+ });
36
+
21
37
  });
package/src/lib/Log.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { arrayFrom, facade, stringMatchAll } from '@noeldemartin/utils';
1
+ import { facade, stringMatchAll } from '@noeldemartin/utils';
2
2
  import { bold, hex } from 'chalk';
3
3
  import { clearLine, cursorTo } from 'readline';
4
4
 
@@ -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 = this.renderInfo(this.renderMarkdown(message) + '.'.repeat(frame % 4)) + end;
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,33 +24,28 @@ 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
  }
30
31
 
31
- public info(messages: string | string[]): void {
32
- arrayFrom(messages).forEach((message) => {
33
- this.log(this.renderInfo(this.renderMarkdown(message)));
34
- });
32
+ public info(message: string): void {
33
+ this.log(this.renderMarkdown(message), this.renderInfo);
35
34
  }
36
35
 
37
- public error(messages: string | string[]): void {
38
- arrayFrom(messages).forEach((message) => {
39
- this.log(this.renderError(this.renderMarkdown(message)));
40
- });
36
+ public error(message: string): void {
37
+ this.log(this.renderMarkdown(message), this.renderError);
41
38
  }
42
39
 
43
- public fail(messages: string | string[]): void {
44
- this.error(messages);
40
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
+ public fail<T = any>(message: string): T {
42
+ this.error(message);
45
43
 
46
44
  process.exit(1);
47
45
  }
48
46
 
49
- public success(messages: string | string[]): void {
50
- arrayFrom(messages).forEach((message) => {
51
- this.log(this.renderSuccess(this.renderMarkdown(message)));
52
- });
47
+ public success(message: string): void {
48
+ this.log(this.renderMarkdown(message), this.renderSuccess);
53
49
  }
54
50
 
55
51
  protected renderMarkdown(message: string): string {
@@ -62,9 +58,29 @@ export class LogService {
62
58
  return message;
63
59
  }
64
60
 
65
- protected log(messages: string | string[]): void {
61
+ protected log(message: string, formatMessage?: (message: string) => string): void {
62
+ this.formatMessage(message).forEach((line) => {
63
+ this.logLine(formatMessage ? formatMessage(line) : line);
64
+ });
65
+ }
66
+
67
+ protected formatMessage(message: string): string[] {
68
+ if (message[0] === '\n') {
69
+ message = message.slice(1).trimEnd();
70
+
71
+ const lines = message.split('\n');
72
+ const firstLetter = message.trim()[0] ?? '';
73
+ const indentation = lines.find((line) => line.trim().length > 0)?.indexOf(firstLetter) ?? 0;
74
+
75
+ return lines.map((line) => line.slice(indentation));
76
+ }
77
+
78
+ return [message];
79
+ }
80
+
81
+ protected logLine(line: string): void {
66
82
  // eslint-disable-next-line no-console
67
- arrayFrom(messages).forEach((message) => console.log(message));
83
+ console.log(line);
68
84
  }
69
85
 
70
86
  protected stdout(message: string): void {
@@ -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 {
@@ -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);
@@ -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', '"@aerogel/core": "file:');
11
+ }
12
+
13
+ export function isLinkedLocalApp(): boolean {
14
+ return File.isSymlink('node_modules/@aerogel/core');
15
+ }
@@ -0,0 +1,44 @@
1
+ import { arrayFrom } from '@noeldemartin/utils';
2
+ import type { Node, SyntaxKind } from 'ts-morph';
3
+
4
+ export function editFiles(): boolean {
5
+ // TODO mock editor instead of relying on this for unit tests
6
+ return true;
7
+ }
8
+
9
+ export function findDescendant<T extends Node>(
10
+ node: Node | undefined,
11
+ options: {
12
+ guard?: (node: Node | undefined) => node is T;
13
+ validate?: (node: T) => boolean;
14
+ skip?: SyntaxKind | SyntaxKind[];
15
+ } = {},
16
+ ): T | undefined {
17
+ if (!node) {
18
+ return;
19
+ }
20
+
21
+ const guard = options.guard ?? (() => true);
22
+ const validate = options.validate ?? (() => true);
23
+ const skipKinds = arrayFrom(options.skip ?? []);
24
+
25
+ return node.forEachDescendant((descendant, traversal) => {
26
+ if (guard(descendant) && validate(descendant)) {
27
+ return descendant;
28
+ }
29
+
30
+ const descendantKind = descendant.getKind();
31
+
32
+ if (skipKinds.includes(descendantKind)) {
33
+ traversal.skip();
34
+ }
35
+ });
36
+ }
37
+
38
+ export function when<T extends Node>(node: Node | undefined, assertion: (node: Node) => node is T): T | undefined {
39
+ if (!node || !assertion(node)) {
40
+ return;
41
+ }
42
+
43
+ return node as T;
44
+ }
@@ -0,0 +1,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\/core": "file:(.*)\/aerogel-core-[\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
+ }