Skip to content

Commit 224d447

Browse files
rdlabogithub-actions[bot]
authored andcommitted
chore: prettier formatting
1 parent c33b19d commit 224d447

File tree

9 files changed

+86
-43
lines changed

9 files changed

+86
-43
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ This project is based [ionic-team/ionic-angular-standalone-codemods](https://git
1414
> [!WARNING]
1515
> This project is experimental. Review all changes before committing them to your project.
1616
17-
1817
## Initialize
1918

20-
__This is beta version.__
19+
**This is beta version.**
2120

2221
```bash
2322
npm install @rdlabo/ionic-angular-collect-icons@beta --save-dev
@@ -72,7 +71,7 @@ npx @rdlabo/ionic-angular-collect-icons
7271

7372
### Let's automate run
7473

75-
It is inefficient to run commands each time before running a production build, so put them in an npm script to automate the process. Example:
74+
It is inefficient to run commands each time before running a production build, so put them in an npm script to automate the process. Example:
7675

7776
```diff
7877
"scripts": {
@@ -109,7 +108,7 @@ If you want to initialize `addIcons` automatically, you can use the `--initializ
109108
enableProdMode();
110109
}
111110

112-
+ addIcons(environment.production ? useIcons : allIcons);
111+
+ addIcons(environment.production ? useIcons : allIcons);
113112
```
114113

115114
the CLI will add lines at the file that has `enableProdMode()`. Of course, it can also be set manually.
@@ -131,13 +130,14 @@ npx @rdlabo/ionic-angular-collect-icons --initialize true
131130

132131
### --project-path [string]
133132

134-
If you want to specify the path to the project, you can use the `--project-path` flag. The default is the current directory. 
133+
If you want to specify the path to the project, you can use the `--project-path` flag. The default is the current directory.
135134

136135
```bash
137136
npx @rdlabo/ionic-angular-collect-icons --project-path /path/to/project
138137
```
139138

140139
Target files are under the `src` directory from the specified path.
140+
141141
- path/to/project + `src/**/*.ts`
142142
- path/to/project + `src/**/*.html`
143143
- path/to/project + `src/**/*.scss`

packages/cli/src/angular/migrations/standalone/0000-initialize-add-icons.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Project } from "ts-morph";
33
import { dedent } from "ts-dedent";
44

55
import { initializeAddIcons } from "./0000-initialize-add-icons";
6-
import {cwd} from 'node:process';
6+
import { cwd } from "node:process";
77

88
describe("initializeAddIcons", () => {
99
it("initialize add icons to file", async () => {
@@ -28,7 +28,13 @@ describe("initializeAddIcons", () => {
2828
`),
2929
);
3030

31-
await initializeAddIcons(project, { dryRun: false, iconPath: "src/use-icons.ts", projectPath: cwd(), interactive: false, initialize: false });
31+
await initializeAddIcons(project, {
32+
dryRun: false,
33+
iconPath: "src/use-icons.ts",
34+
projectPath: cwd(),
35+
interactive: false,
36+
initialize: false,
37+
});
3238

3339
expect(dedent(appModuleSourceFile.getText())).toBe(
3440
dedent(`
@@ -49,6 +55,7 @@ describe("initializeAddIcons", () => {
4955
provideRouter(routes),
5056
],
5157
});
52-
`));
58+
`),
59+
);
5360
});
5461
});

packages/cli/src/angular/migrations/standalone/0000-initialize-add-icons.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,28 @@ import { Project, SyntaxKind, ts } from "ts-morph";
22
import { CliOptions } from "../../../types/cli-options";
33

44
import { saveFileChanges } from "../../utils/log-utils";
5-
import {addExportToFile, addImportToClass, addImportToFile} from '../../utils/typescript-utils';
6-
import {getRelativePath} from '../../utils/cli-utils';
5+
import {
6+
addExportToFile,
7+
addImportToClass,
8+
addImportToFile,
9+
} from "../../utils/typescript-utils";
10+
import { getRelativePath } from "../../utils/cli-utils";
711

812
export const initializeAddIcons = async (
913
project: Project,
1014
cliOptions: CliOptions,
1115
) => {
12-
const prodModeSource = project.getSourceFile("app.config.ts") || project.getSourceFile("main.ts");
16+
const prodModeSource =
17+
project.getSourceFile("app.config.ts") || project.getSourceFile("main.ts");
1318

1419
if (prodModeSource === undefined) {
1520
// If the project does not base angular standalone structured, do nothing.
1621
return;
1722
}
1823

19-
const enableProdMode = prodModeSource.getStatements().find((source) => source.getFullText().includes('enableProdMode()'));
24+
const enableProdMode = prodModeSource
25+
.getStatements()
26+
.find((source) => source.getFullText().includes("enableProdMode()"));
2027
if (!enableProdMode) {
2128
// If the project does not base angular standalone structured, do nothing.
2229
return;
@@ -45,17 +52,23 @@ export const initializeAddIcons = async (
4552

4653
addImportToFile(prodModeSource, "addIcons", "ionicons");
4754
prodModeSource.addImportDeclaration({
48-
defaultImport: '* as allIcons',
49-
moduleSpecifier: 'ionicons/icons'
55+
defaultImport: "* as allIcons",
56+
moduleSpecifier: "ionicons/icons",
5057
});
5158

52-
const path = getRelativePath(prodModeSource.getFilePath(), [cliOptions.projectPath, cliOptions.iconPath].join('/'));
59+
const path = getRelativePath(
60+
prodModeSource.getFilePath(),
61+
[cliOptions.projectPath, cliOptions.iconPath].join("/"),
62+
);
5363
prodModeSource.addImportDeclaration({
54-
defaultImport: '* as useIcons',
55-
moduleSpecifier: path.replace('.ts', ''),
64+
defaultImport: "* as useIcons",
65+
moduleSpecifier: path.replace(".ts", ""),
5666
});
5767

58-
prodModeSource.insertStatements(enableProdMode.getChildIndex() + 1, `addIcons(environment.production ? useIcons : allIcons);`);
68+
prodModeSource.insertStatements(
69+
enableProdMode.getChildIndex() + 1,
70+
`addIcons(environment.production ? useIcons : allIcons);`,
71+
);
5972

6073
return await saveFileChanges(prodModeSource, cliOptions);
6174
};

packages/cli/src/angular/migrations/standalone/0001-remove-add-icons.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Project } from "ts-morph";
33
import { dedent } from "ts-dedent";
44

55
import { removeAddIcons } from "./0001-remove-add-icons";
6-
import {cwd} from 'node:process';
6+
import { cwd } from "node:process";
77

88
describe("migrateAppModule", () => {
99
it("should remove addIcons method", async () => {
@@ -31,7 +31,13 @@ describe("migrateAppModule", () => {
3131
dedent(component),
3232
);
3333

34-
await removeAddIcons(project, { dryRun: false, iconPath: "src/use-icons.ts", projectPath: cwd(), interactive: false, initialize: false });
34+
await removeAddIcons(project, {
35+
dryRun: false,
36+
iconPath: "src/use-icons.ts",
37+
projectPath: cwd(),
38+
interactive: false,
39+
initialize: false,
40+
});
3541

3642
expect(dedent(componentSourceFile.getText())).toBe(
3743
dedent(`

packages/cli/src/angular/migrations/standalone/0002-generate-use-icons.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ describe("migrateComponents", () => {
2525

2626
const useIconFile = project.createSourceFile("use-icons.ts", dedent(``));
2727

28-
await generateUseIcons(project, { dryRun: false, iconPath: "src/use-icons.ts", projectPath: cwd(), interactive: false, initialize: false });
28+
await generateUseIcons(project, {
29+
dryRun: false,
30+
iconPath: "src/use-icons.ts",
31+
projectPath: cwd(),
32+
interactive: false,
33+
initialize: false,
34+
});
2935

3036
expect(dedent(useIconFile.getText())).toBe(
3137
dedent(`export { logoIonic, closeOutline } from "ionicons/icons";`),

packages/cli/src/angular/migrations/standalone/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { generateUseIcons } from "./0002-generate-use-icons";
55

66
import { group, confirm, log, spinner } from "@clack/prompts";
77
import { getActualPackageVersion } from "../../utils/package-utils";
8-
import {initializeAddIcons} from './0000-initialize-add-icons';
8+
import { initializeAddIcons } from "./0000-initialize-add-icons";
99

1010
interface StandaloneMigrationOptions {
1111
/**

packages/cli/src/angular/utils/cli-utils.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@ import {
99
import { Project } from "ts-morph";
1010

1111
import { dedent } from "ts-dedent";
12-
import {getOptionsFromArgv, getRelativePath} from './cli-utils';
12+
import { getOptionsFromArgv, getRelativePath } from "./cli-utils";
1313

1414
describe("getRelativePath", () => {
1515
it("should return relative path", () => {
16-
const path = getRelativePath('/Users/sakakibara/dev/ionic-angular-collect-icons/src/app/example.ts', '/Users/sakakibara/dev/ionic-angular-collect-icons/use-icons.ts');
17-
expect(path).toStrictEqual('../../use-icons.ts');
16+
const path = getRelativePath(
17+
"/Users/sakakibara/dev/ionic-angular-collect-icons/src/app/example.ts",
18+
"/Users/sakakibara/dev/ionic-angular-collect-icons/use-icons.ts",
19+
);
20+
expect(path).toStrictEqual("../../use-icons.ts");
1821
});
1922
});
2023

2124
describe("getOptionsFromArgv", () => {
2225
it("should return object options", () => {
23-
const sourceArgv = ['--dry-run', 'true', '--interactive'];
26+
const sourceArgv = ["--dry-run", "true", "--interactive"];
2427

2528
expect(getOptionsFromArgv(sourceArgv)).toStrictEqual({
2629
dryRun: true,

packages/cli/src/angular/utils/cli-utils.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import { CliOptions } from '../../types/cli-options';
2-
import {kebabCaseToCamelCase, kebabCaseToPascalCase} from './string-utils';
3-
import * as path from 'path';
1+
import { CliOptions } from "../../types/cli-options";
2+
import { kebabCaseToCamelCase, kebabCaseToPascalCase } from "./string-utils";
3+
import * as path from "path";
44

5-
export function getRelativePath(importFilePath: string, targetPath: string): string {
5+
export function getRelativePath(
6+
importFilePath: string,
7+
targetPath: string,
8+
): string {
69
return path.relative(path.dirname(importFilePath), targetPath);
710
}
811

912
export function getOptionsFromArgv(argv: string[]): Partial<CliOptions> {
10-
const options = {}
13+
const options = {};
1114
for (let i = 0; i < argv.length; i++) {
1215
const arg = argv[i];
1316
if (!arg) {
@@ -16,12 +19,15 @@ export function getOptionsFromArgv(argv: string[]): Partial<CliOptions> {
1619

1720
if (arg.startsWith("--")) {
1821
const key = kebabCaseToCamelCase(arg.replace("--", ""));
19-
const value = argv[i + 1] === undefined || argv[i + 1].startsWith("--") ? true
20-
: ['true', 'false'].includes(argv[i + 1]) ? argv[i + 1] === 'true'
22+
const value =
23+
argv[i + 1] === undefined || argv[i + 1].startsWith("--")
24+
? true
25+
: ["true", "false"].includes(argv[i + 1])
26+
? argv[i + 1] === "true"
2127
: argv[i + 1];
2228
Object.assign(options, {
2329
[key]: value,
24-
})
30+
});
2531
}
2632
}
2733
return options as CliOptions;

packages/cli/src/index.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,16 @@ import { existsSync } from "node:fs";
1616

1717
import { cwd } from "node:process";
1818
import { runStandaloneMigration } from "./angular/migrations/standalone";
19-
import {getOptionsFromArgv} from './angular/utils/cli-utils';
20-
import {CliOptions} from './types/cli-options';
19+
import { getOptionsFromArgv } from "./angular/utils/cli-utils";
20+
import { CliOptions } from "./types/cli-options";
2121

2222
const IONIC_REPOSITORY_ISSUES_URL =
2323
"https://github.com/rdlabo-team/ionic-angular-collect-icons/issues";
2424

2525
const cliOptions = getOptionsFromArgv(process.argv);
2626

2727
const isInteractive = (): boolean =>
28-
TERMINAL_INFO.tty &&
29-
!TERMINAL_INFO.ci &&
30-
cliOptions.interactive === true
28+
TERMINAL_INFO.tty && !TERMINAL_INFO.ci && cliOptions.interactive === true;
3129

3230
async function main() {
3331
console.clear();
@@ -64,10 +62,14 @@ async function main() {
6462
projectPath: cwd(),
6563
});
6664

67-
const cli = Object.assign(_cli, {
68-
initialize: false,
69-
iconPath: "src/use-icons.ts",
70-
}, cliOptions) as CliOptions;
65+
const cli = Object.assign(
66+
_cli,
67+
{
68+
initialize: false,
69+
iconPath: "src/use-icons.ts",
70+
},
71+
cliOptions,
72+
) as CliOptions;
7173

7274
if (typeof cli.dryRun !== "boolean") {
7375
// User aborted the prompt

0 commit comments

Comments
 (0)