@aerogel/cli 0.0.0 → 0.1.0
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/bin/gel +4 -0
- package/dist/aerogel-cli.d.ts +2 -2
- package/dist/aerogel-cli.js +790 -0
- package/dist/aerogel-cli.js.map +1 -0
- package/package.json +28 -33
- package/src/cli.ts +28 -6
- package/src/commands/Command.ts +14 -9
- package/src/commands/create.test.ts +4 -9
- package/src/commands/create.ts +40 -26
- package/src/commands/generate-component.test.ts +5 -7
- package/src/commands/generate-component.ts +114 -37
- package/src/commands/generate-model.test.ts +17 -6
- package/src/commands/generate-model.ts +47 -22
- package/src/commands/generate-service.test.ts +21 -0
- package/src/commands/generate-service.ts +151 -0
- package/src/commands/info.ts +15 -0
- package/src/commands/install.test.ts +90 -0
- package/src/commands/install.ts +47 -0
- package/src/lib/App.ts +76 -12
- package/src/lib/Editor.ts +57 -0
- package/src/lib/File.mock.ts +13 -11
- package/src/lib/File.ts +43 -3
- package/src/lib/Log.mock.ts +11 -6
- package/src/lib/Log.test.ts +22 -6
- package/src/lib/Log.ts +43 -27
- package/src/lib/Shell.mock.ts +7 -3
- package/src/lib/Shell.ts +2 -2
- package/src/lib/Template.ts +27 -19
- package/src/lib/utils/app.ts +15 -0
- package/src/lib/utils/edit.ts +44 -0
- package/src/lib/utils/paths.ts +46 -0
- package/src/plugins/LocalFirst.ts +9 -0
- package/src/plugins/Plugin.ts +176 -0
- package/src/plugins/Solid.ts +72 -0
- package/src/plugins/Soukai.ts +20 -0
- package/src/testing/setup.ts +62 -25
- package/src/utils/package.ts +23 -0
- package/templates/app/README.md +3 -0
- package/templates/service/[service.name].ts +8 -0
- package/.eslintrc.js +0 -7
- package/bin/ag +0 -4
- package/dist/aerogel-cli.cjs.js +0 -2
- package/dist/aerogel-cli.cjs.js.map +0 -1
- package/dist/aerogel-cli.esm.js +0 -2
- package/dist/aerogel-cli.esm.js.map +0 -1
- package/noeldemartin.config.js +0 -4
- package/src/lib/utils.test.ts +0 -33
- package/src/lib/utils.ts +0 -44
- package/templates/app/.github/workflows/ci.yml +0 -17
- package/templates/app/.nvmrc +0 -1
- package/templates/app/cypress/e2e/app.cy.ts +0 -9
- package/templates/app/cypress/support/e2e.ts +0 -3
- package/templates/app/cypress/tsconfig.json +0 -12
- package/templates/app/cypress.config.ts +0 -8
- package/templates/app/index.html +0 -12
- package/templates/app/package.json +0 -44
- package/templates/app/postcss.config.js +0 -6
- package/templates/app/src/App.vue +0 -10
- package/templates/app/src/assets/styles.css +0 -3
- package/templates/app/src/lang/en.yaml +0 -3
- package/templates/app/src/main.test.ts +0 -9
- package/templates/app/src/main.ts +0 -9
- package/templates/app/src/types/globals.d.ts +0 -3
- package/templates/app/src/types/shims.d.ts +0 -7
- package/templates/app/src/types/ts-reset.d.ts +0 -1
- package/templates/app/tailwind.config.js +0 -5
- package/templates/app/tsconfig.json +0 -18
- package/templates/app/vite.config.ts +0 -21
- package/templates/component-story/[component.name].story.vue +0 -7
- package/tsconfig.json +0 -11
- package/vite.config.ts +0 -14
- /package/src/{main.ts → index.ts} +0 -0
package/src/lib/App.ts
CHANGED
|
@@ -1,25 +1,89 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
2
|
|
|
3
|
-
import File from '
|
|
4
|
-
import Log from '
|
|
5
|
-
import Template from '
|
|
6
|
-
import {
|
|
3
|
+
import File from '@aerogel/cli/lib/File';
|
|
4
|
+
import Log from '@aerogel/cli/lib/Log';
|
|
5
|
+
import Template from '@aerogel/cli/lib/Template';
|
|
6
|
+
import { packNotFound, packagePackPath, packagePath, templatePath } from '@aerogel/cli/lib/utils/paths';
|
|
7
|
+
import { Editor } from '@aerogel/cli/lib/Editor';
|
|
8
|
+
import { simpleGit } from 'simple-git';
|
|
9
|
+
|
|
10
|
+
export interface Options {
|
|
11
|
+
local?: boolean;
|
|
12
|
+
linkedLocal?: boolean;
|
|
13
|
+
}
|
|
7
14
|
|
|
8
15
|
export default class App {
|
|
9
16
|
|
|
10
|
-
constructor(
|
|
17
|
+
constructor(
|
|
18
|
+
protected name: string,
|
|
19
|
+
protected options: Options = {},
|
|
20
|
+
) {}
|
|
11
21
|
|
|
12
|
-
public create(path: string): void {
|
|
22
|
+
public async create(path: string): Promise<void> {
|
|
13
23
|
if (File.exists(path) && (!File.isDirectory(path) || !File.isEmptyDirectory(path))) {
|
|
14
24
|
Log.fail(`Folder at '${path}' already exists!`);
|
|
15
25
|
}
|
|
16
26
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
slug: stringToSlug(this.name),
|
|
21
|
-
},
|
|
27
|
+
// Clone repository
|
|
28
|
+
await simpleGit().clone('https://github.com/NoelDeMartin/aerogel-template.git', path, {
|
|
29
|
+
'--depth': 1,
|
|
22
30
|
});
|
|
31
|
+
|
|
32
|
+
File.delete(resolve(path, '.git'));
|
|
33
|
+
|
|
34
|
+
// Apply replacements
|
|
35
|
+
const dependencies = this.getDependencies();
|
|
36
|
+
|
|
37
|
+
File.replace(
|
|
38
|
+
resolve(path, 'vite.config.ts'),
|
|
39
|
+
'Aerogel({ name: \'Aerogel\' })',
|
|
40
|
+
`Aerogel({ name: '${this.name}' })`,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
File.replace(resolve(path, 'src/lang/en.yaml'), 'title: \'App\'', `title: '${this.name}'`);
|
|
44
|
+
|
|
45
|
+
for (const [name, version] of Object.entries(dependencies)) {
|
|
46
|
+
File.replace(resolve(path, 'package.json'), new RegExp(`"${name}": ".*?"`, 'g'), `"${name}": "${version}"`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Copy template
|
|
50
|
+
Template.instantiate(templatePath('app'), path, { app: { name: this.name } });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public edit(): Editor {
|
|
54
|
+
return new Editor();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
protected getDependencies(): Record<string, string> {
|
|
58
|
+
const withFilePrefix = <T extends Record<string, string>>(paths: T) =>
|
|
59
|
+
Object.entries(paths).reduce(
|
|
60
|
+
(pathsWithFile, [name, path]) => Object.assign(pathsWithFile, { [name]: `file:${path}` }) as T,
|
|
61
|
+
{} as T,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
if (this.options.linkedLocal) {
|
|
65
|
+
return withFilePrefix({
|
|
66
|
+
'@aerogel/cli': packagePath('cli'),
|
|
67
|
+
'@aerogel/core': packagePath('core'),
|
|
68
|
+
'@aerogel/cypress': packagePath('cypress'),
|
|
69
|
+
'@aerogel/plugin-i18n': packagePath('plugin-i18n'),
|
|
70
|
+
'@aerogel/plugin-soukai': packagePath('plugin-soukai'),
|
|
71
|
+
'@aerogel/vite': packagePath('vite'),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (this.options.local) {
|
|
76
|
+
return withFilePrefix({
|
|
77
|
+
'@aerogel/cli': packagePackPath('cli') ?? packNotFound('cli'),
|
|
78
|
+
'@aerogel/core': packagePackPath('core') ?? packNotFound('core'),
|
|
79
|
+
'@aerogel/cypress': packagePackPath('cypress') ?? packNotFound('cypress'),
|
|
80
|
+
'@aerogel/plugin-i18n': packagePackPath('plugin-i18n') ?? packNotFound('plugin-i18n'),
|
|
81
|
+
'@aerogel/plugin-soukai': packagePackPath('plugin-soukai') ?? packNotFound('plugin-soukai'),
|
|
82
|
+
'@aerogel/vite': packagePackPath('vite') ?? packNotFound('vite'),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return {};
|
|
23
87
|
}
|
|
24
88
|
|
|
25
89
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { arrayFrom } from '@noeldemartin/utils';
|
|
2
|
+
import { Project } from 'ts-morph';
|
|
3
|
+
import type { SourceFile } from 'ts-morph';
|
|
4
|
+
|
|
5
|
+
import File from '@aerogel/cli/lib/File';
|
|
6
|
+
import Log from '@aerogel/cli/lib/Log';
|
|
7
|
+
import Shell from '@aerogel/cli/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('vite.config.ts');
|
|
20
|
+
this.project.addSourceFilesAtPaths('package.json');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public addSourceFile(path: string): void {
|
|
24
|
+
this.project.addSourceFilesAtPaths(path);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public requireSourceFile(path: string): SourceFile {
|
|
28
|
+
return this.project.getSourceFileOrThrow(path);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public async format(): Promise<void> {
|
|
32
|
+
await Log.animate('Formatting modified files', async () => {
|
|
33
|
+
const usingPrettier = File.exists('prettier.config.js') || File.contains('package.json', '"prettier": {');
|
|
34
|
+
const usingESLint = File.exists('.eslintrc.js') || File.contains('package.json', '"eslintConfig"');
|
|
35
|
+
const usingPrettierESLint = File.contains('package.json', '"prettier-eslint-cli"');
|
|
36
|
+
const formatFile = usingPrettierESLint
|
|
37
|
+
? (file: string) => Shell.run(`npx prettier-eslint ${file} --write`)
|
|
38
|
+
: async (file: string) => {
|
|
39
|
+
usingPrettier && (await Shell.run(`npx prettier ${file} --write`));
|
|
40
|
+
file.match(/\.(ts|js|vue)$/) && usingESLint && (await Shell.run(`npx eslint ${file} --fix`));
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
await Promise.all(arrayFrom(this.modifiedFiles).map(async (file) => formatFile(file)));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public async save(file: SourceFile): Promise<void> {
|
|
48
|
+
await file.save();
|
|
49
|
+
|
|
50
|
+
this.addModifiedFile(file.getFilePath());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public addModifiedFile(path: string): void {
|
|
54
|
+
this.modifiedFiles.add(path);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
package/src/lib/File.mock.ts
CHANGED
|
@@ -8,28 +8,34 @@ export class FileMockService extends FileService {
|
|
|
8
8
|
|
|
9
9
|
private virtualFilesystem: Record<string, string | { directory: true }> = {};
|
|
10
10
|
|
|
11
|
-
public
|
|
11
|
+
public override delete(path: string): void {
|
|
12
|
+
if (path in this.virtualFilesystem) {
|
|
13
|
+
delete this.virtualFilesystem[path];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public override exists(path: string): boolean {
|
|
12
18
|
return super.exists(path) || path in this.virtualFilesystem;
|
|
13
19
|
}
|
|
14
20
|
|
|
15
|
-
public isDirectory(path: string): boolean {
|
|
21
|
+
public override isDirectory(path: string): boolean {
|
|
16
22
|
return (
|
|
17
23
|
super.isDirectory(path) ||
|
|
18
24
|
(path in this.virtualFilesystem && typeof this.virtualFilesystem[path] === 'object')
|
|
19
25
|
);
|
|
20
26
|
}
|
|
21
27
|
|
|
22
|
-
public isFile(path: string): boolean {
|
|
28
|
+
public override isFile(path: string): boolean {
|
|
23
29
|
return (
|
|
24
30
|
super.isFile(path) || (path in this.virtualFilesystem && typeof this.virtualFilesystem[path] === 'string')
|
|
25
31
|
);
|
|
26
32
|
}
|
|
27
33
|
|
|
28
|
-
public makeDirectory(path: string): void {
|
|
34
|
+
public override makeDirectory(path: string): void {
|
|
29
35
|
this.virtualFilesystem[path] = { directory: true };
|
|
30
36
|
}
|
|
31
37
|
|
|
32
|
-
public read(path: string): string | null {
|
|
38
|
+
public override read(path: string): string | null {
|
|
33
39
|
if (path in this.virtualFilesystem && typeof this.virtualFilesystem[path] === 'string') {
|
|
34
40
|
return this.virtualFilesystem[path] as string;
|
|
35
41
|
}
|
|
@@ -37,14 +43,10 @@ export class FileMockService extends FileService {
|
|
|
37
43
|
return super.read(path);
|
|
38
44
|
}
|
|
39
45
|
|
|
40
|
-
public write(path: string, contents: string): void {
|
|
46
|
+
public override write(path: string, contents: string): void {
|
|
41
47
|
this.virtualFilesystem[path] = contents;
|
|
42
48
|
}
|
|
43
49
|
|
|
44
|
-
public reset(): void {
|
|
45
|
-
this.virtualFilesystem = {};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
50
|
public expectCreated(path: string, expectContent?: (contents: string) => void): Assertion<string> {
|
|
49
51
|
expect(typeof this.virtualFilesystem[path] === 'string', `expected '${path}' file to have been created`).toBe(
|
|
50
52
|
true,
|
|
@@ -63,4 +65,4 @@ export class FileMockService extends FileService {
|
|
|
63
65
|
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
export default facade(
|
|
68
|
+
export default facade(FileMockService);
|
package/src/lib/File.ts
CHANGED
|
@@ -1,13 +1,43 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
existsSync,
|
|
3
|
+
lstatSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
readFileSync,
|
|
6
|
+
readdirSync,
|
|
7
|
+
rmSync,
|
|
8
|
+
unlinkSync,
|
|
9
|
+
writeFileSync,
|
|
10
|
+
} from 'node:fs';
|
|
11
|
+
import { dirname, resolve } from 'node:path';
|
|
12
|
+
|
|
2
13
|
import { facade } from '@noeldemartin/utils';
|
|
3
|
-
import { dirname, resolve } from 'path';
|
|
4
14
|
|
|
5
15
|
export class FileService {
|
|
6
16
|
|
|
17
|
+
public contains(path: string, contents: string): boolean {
|
|
18
|
+
return !!this.read(path)?.includes(contents);
|
|
19
|
+
}
|
|
20
|
+
|
|
7
21
|
public exists(path: string): boolean {
|
|
8
22
|
return existsSync(path);
|
|
9
23
|
}
|
|
10
24
|
|
|
25
|
+
public delete(path: string): void {
|
|
26
|
+
if (this.isDirectory(path)) {
|
|
27
|
+
rmSync(path, { recursive: true });
|
|
28
|
+
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
unlinkSync(path);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public isSymlink(path: string): boolean {
|
|
36
|
+
const stats = lstatSync(path);
|
|
37
|
+
|
|
38
|
+
return stats.isSymbolicLink();
|
|
39
|
+
}
|
|
40
|
+
|
|
11
41
|
public read(path: string): string | null {
|
|
12
42
|
if (!this.isFile(path)) {
|
|
13
43
|
return null;
|
|
@@ -16,6 +46,16 @@ export class FileService {
|
|
|
16
46
|
return readFileSync(path).toString();
|
|
17
47
|
}
|
|
18
48
|
|
|
49
|
+
public replace(path: string, search: string | RegExp, replacement: string): void {
|
|
50
|
+
const contents = this.read(path);
|
|
51
|
+
|
|
52
|
+
if (!contents) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
this.write(path, contents.replaceAll(search, replacement));
|
|
57
|
+
}
|
|
58
|
+
|
|
19
59
|
public getFiles(directoryPath: string): string[] {
|
|
20
60
|
const children = readdirSync(directoryPath, { withFileTypes: true });
|
|
21
61
|
const files: string[] = [];
|
|
@@ -63,4 +103,4 @@ export class FileService {
|
|
|
63
103
|
|
|
64
104
|
}
|
|
65
105
|
|
|
66
|
-
export default facade(
|
|
106
|
+
export default facade(FileService);
|
package/src/lib/Log.mock.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expect } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import { facade } from '@noeldemartin/utils';
|
|
3
3
|
|
|
4
4
|
import { LogService } from './Log';
|
|
5
5
|
|
|
@@ -11,18 +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
|
-
|
|
15
|
-
this.logs.
|
|
14
|
+
public expectLogLength(count: number): void {
|
|
15
|
+
expect(this.logs, `Expected log to have length ${count}`).toHaveLength(count);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
protected override logLine(message: string): void {
|
|
19
|
+
this.logs.push(message);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
public override fail<T = any>(message: string): T {
|
|
19
24
|
throw new Error(`Fail: ${message}`);
|
|
20
25
|
}
|
|
21
26
|
|
|
22
|
-
protected stdout(): void {
|
|
27
|
+
protected override stdout(): void {
|
|
23
28
|
//
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
export default facade(
|
|
33
|
+
export default facade(LogServiceMock);
|
package/src/lib/Log.test.ts
CHANGED
|
@@ -1,21 +1,37 @@
|
|
|
1
|
-
import
|
|
1
|
+
import chalk from 'chalk';
|
|
2
2
|
import { describe, it } from 'vitest';
|
|
3
3
|
|
|
4
|
-
import LogMock from '
|
|
4
|
+
import LogMock from '@aerogel/cli/lib/Log.mock';
|
|
5
5
|
|
|
6
6
|
import Log from './Log';
|
|
7
7
|
|
|
8
|
+
const info = chalk.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
|
|
|
17
16
|
// Assert
|
|
18
|
-
LogMock.expectLogged(info(`Foo ${bold('bar')}`));
|
|
17
|
+
LogMock.expectLogged(info(`Foo ${chalk.bold('bar')}`));
|
|
18
|
+
});
|
|
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.'));
|
|
19
35
|
});
|
|
20
36
|
|
|
21
37
|
});
|
package/src/lib/Log.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { clearLine, cursorTo } from 'node:readline';
|
|
3
|
+
import { facade, stringMatchAll } from '@noeldemartin/utils';
|
|
4
4
|
|
|
5
5
|
export class LogService {
|
|
6
6
|
|
|
7
|
-
protected renderInfo = hex('#00ffff');
|
|
8
|
-
protected renderSuccess = hex('#00ff00');
|
|
9
|
-
protected renderError = hex('#ff0000');
|
|
7
|
+
protected renderInfo = chalk.hex('#00ffff');
|
|
8
|
+
protected renderSuccess = chalk.hex('#00ff00');
|
|
9
|
+
protected renderError = chalk.hex('#ff0000');
|
|
10
10
|
|
|
11
11
|
public async animate<T>(message: string, operation: () => Promise<T>): Promise<T> {
|
|
12
|
-
const updateStdout = (end: string = '') => {
|
|
13
|
-
const progress =
|
|
12
|
+
const updateStdout = (end: string = '', done: boolean = false) => {
|
|
13
|
+
const progress =
|
|
14
|
+
this.renderInfo(this.renderMarkdown(message) + (done ? '...' : '.'.repeat(frame % 4))) + end;
|
|
14
15
|
|
|
15
16
|
this.stdout(progress);
|
|
16
17
|
};
|
|
@@ -23,48 +24,63 @@ 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(
|
|
32
|
-
|
|
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(
|
|
38
|
-
|
|
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
|
-
|
|
44
|
-
|
|
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(
|
|
50
|
-
|
|
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 {
|
|
56
52
|
const matches = stringMatchAll<2>(message, /\*\*(.*)\*\*/g);
|
|
57
53
|
|
|
58
54
|
for (const match of matches) {
|
|
59
|
-
message = message.replace(match[0], bold(match[1]));
|
|
55
|
+
message = message.replace(match[0], chalk.bold(match[1]));
|
|
60
56
|
}
|
|
61
57
|
|
|
62
58
|
return message;
|
|
63
59
|
}
|
|
64
60
|
|
|
65
|
-
protected log(
|
|
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
|
-
|
|
83
|
+
console.log(line);
|
|
68
84
|
}
|
|
69
85
|
|
|
70
86
|
protected stdout(message: string): void {
|
|
@@ -76,4 +92,4 @@ export class LogService {
|
|
|
76
92
|
|
|
77
93
|
}
|
|
78
94
|
|
|
79
|
-
export default facade(
|
|
95
|
+
export default facade(LogService);
|
package/src/lib/Shell.mock.ts
CHANGED
|
@@ -7,14 +7,18 @@ export class ShellServiceMock extends ShellService {
|
|
|
7
7
|
|
|
8
8
|
private history: string[] = [];
|
|
9
9
|
|
|
10
|
-
public async run(command: string): Promise<void> {
|
|
11
|
-
this.history.push(command);
|
|
10
|
+
public override async run(command: string): Promise<void> {
|
|
11
|
+
this.history.push(command.trim());
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
public expectRan(command: string): void {
|
|
15
15
|
expect(this.history, `expected '${command}' command to have been executed`).toContain(command);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
public expectNotRan(command: string): void {
|
|
19
|
+
expect(this.history, `expected '${command}' command to not have been executed`).not.toContain(command);
|
|
20
|
+
}
|
|
21
|
+
|
|
18
22
|
}
|
|
19
23
|
|
|
20
|
-
export default facade(
|
|
24
|
+
export default facade(ShellServiceMock);
|
package/src/lib/Shell.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { exec } from 'child_process';
|
|
1
|
+
import { exec } from 'node:child_process';
|
|
2
2
|
import { facade } from '@noeldemartin/utils';
|
|
3
3
|
|
|
4
4
|
export class ShellService {
|
|
@@ -25,4 +25,4 @@ export class ShellService {
|
|
|
25
25
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export default facade(
|
|
28
|
+
export default facade(ShellService);
|
package/src/lib/Template.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import Mustache from 'mustache';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
3
|
import { toString } from '@noeldemartin/utils';
|
|
4
4
|
|
|
5
|
-
import File from '
|
|
5
|
+
import File from '@aerogel/cli/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);
|
|
@@ -25,10 +29,11 @@ export default class Template {
|
|
|
25
29
|
file.substring(this.path.length + 1),
|
|
26
30
|
);
|
|
27
31
|
const fileContents = readFileSync(file).toString();
|
|
32
|
+
const filePath =
|
|
33
|
+
destination + (relativePath.endsWith('.template') ? relativePath.slice(0, -9) : relativePath);
|
|
28
34
|
|
|
29
|
-
File.write(
|
|
30
|
-
|
|
31
|
-
files.push(destination + relativePath);
|
|
35
|
+
File.write(filePath, Mustache.render(fileContents, replacements, undefined, ['<%', '%>']));
|
|
36
|
+
files.push(filePath);
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
return files;
|
|
@@ -38,18 +43,21 @@ export default class Template {
|
|
|
38
43
|
replacements: Record<string, unknown>,
|
|
39
44
|
prefix: string = '',
|
|
40
45
|
): Record<string, string> {
|
|
41
|
-
return Object.entries(replacements).reduce(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
return Object.entries(replacements).reduce(
|
|
47
|
+
(filenameReplacements, [key, value]) => {
|
|
48
|
+
if (typeof value === 'object') {
|
|
49
|
+
Object.assign(
|
|
50
|
+
filenameReplacements,
|
|
51
|
+
this.getFilenameReplacements(value as Record<string, unknown>, `${key}.`),
|
|
52
|
+
);
|
|
53
|
+
} else {
|
|
54
|
+
filenameReplacements[`[${prefix}${key}]`] = toString(value);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return filenameReplacements;
|
|
58
|
+
},
|
|
59
|
+
{} as Record<string, string>,
|
|
60
|
+
);
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import App from '@aerogel/cli/lib/App';
|
|
2
|
+
import File from '@aerogel/cli/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 as T)) {
|
|
27
|
+
return descendant as T;
|
|
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
|
+
}
|