Skip to content

Commit

Permalink
Merged v1-addon and engine (#65)
Browse files Browse the repository at this point in the history
* breaking: Ignored styles.js in an addon's app folder

* feature: Handled controllers, routes, services, and route templates in v1 addons

* refactor: Used migrateV1Addon() to migrate engines

* breaking: Removed engine as a possible option for --type

* refactor: Removed unused code

---------

Co-authored-by: ijlee2 <[email protected]>
  • Loading branch information
ijlee2 and ijlee2 authored Oct 11, 2024
1 parent 83c47d7 commit a3c6fc0
Show file tree
Hide file tree
Showing 51 changed files with 101 additions and 595 deletions.
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ Step 3. Update references originating from, as well as pointing to, the moved fi
You must pass `--type` to indicate what type of project you have.

```sh
# For classic apps
npx ember-codemod-pod-to-octane --type app

# For v1 addons (including engines)
npx ember-codemod-pod-to-octane --type v1-addon
npx ember-codemod-pod-to-octane --type engine
```


Expand Down Expand Up @@ -103,16 +105,7 @@ To account for a bug (found when Ember CLI is combined with Ember Data), the cod

<summary>Addons</summary>

The codemod assumes that an addon is used to define components (not models or routes).

</details>


<details>

<summary>Engines</summary>

The codemod assumes that an engine is used to define routes and route-specific components.
The codemod doesn't consider things related to Ember Data (i.e. adapters, models, and serializers).

</details>

Expand Down
2 changes: 1 addition & 1 deletion bin/ember-codemod-pod-to-octane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const argv = yargs(hideBin(process.argv))
type: 'boolean',
})
.option('type', {
choices: ['app', 'engine', 'v1-addon'] as const,
choices: ['app', 'v1-addon'] as const,
demandOption: true,
describe: 'Type of your Ember project',
type: 'string',
Expand Down
11 changes: 1 addition & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
migrateApp,
migrateEngine,
migrateV1Addon,
} from './migration/index.js';
import { migrateApp, migrateV1Addon } from './migration/index.js';
import type { CodemodOptions } from './types/index.js';

export function runCodemod(codemodOptions: CodemodOptions): void {
Expand All @@ -12,11 +8,6 @@ export function runCodemod(codemodOptions: CodemodOptions): void {
break;
}

case 'engine': {
migrateEngine(codemodOptions);
break;
}

case 'v1-addon': {
migrateV1Addon(codemodOptions);
break;
Expand Down
20 changes: 0 additions & 20 deletions src/migration/engine/index.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/migration/engine/steps/create-file-path-maps.ts

This file was deleted.

20 changes: 0 additions & 20 deletions src/migration/engine/steps/create-file-path-maps/addon/index.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/migration/engine/steps/create-file-path-maps/tests/index.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/migration/engine/steps/create-options.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/migration/engine/steps/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/migration/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './app/index.js';
export * from './engine/index.js';
export * from './v1-addon/index.js';
10 changes: 10 additions & 0 deletions src/migration/v1-addon/steps/create-file-path-maps/addon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ import type { FilePathMap, Options } from '../../../../../types/index.js';
import { mapComponentClasses } from './map-component-classes.js';
import { mapComponentStylesheets } from './map-component-stylesheets.js';
import { mapComponentTemplates } from './map-component-templates.js';
import { mapRouteControllers } from './map-route-controllers.js';
import { mapRouteRoutes } from './map-route-routes.js';
import { mapRouteStylesheets } from './map-route-stylesheets.js';
import { mapRouteTemplates } from './map-route-templates.js';
import { mapServices } from './map-services.js';

export function mapAddonFolder(options: Options): FilePathMap {
return new Map([
...mapComponentClasses(options),
...mapComponentStylesheets(options),
...mapComponentTemplates(options),
...mapRouteControllers(options),
...mapRouteRoutes(options),
...mapRouteStylesheets(options),
...mapRouteTemplates(options),
...mapServices(options),
]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import type {
} from '../../../../../types/index.js';
import { renamePodPath } from '../../../../../utils/files/index.js';

export function mapComponentStylesheets(options: Options): FilePathMapEntries {
export function mapServices(options: Options): FilePathMapEntries {
const { projectRoot } = options;

const filePaths = findFiles('app/components/**/styles.js', {
const filePaths = findFiles('addon/**/service.{js,ts}', {
projectRoot,
});

return filePaths.map((oldFilePath) => {
const newFilePath = renamePodPath(oldFilePath, {
entityDir: 'app/components',
entityDir: 'addon',
replace: (key: string) => {
return `app/components/${key}`;
return `addon/services/${key}`;
},
});

Expand Down
10 changes: 8 additions & 2 deletions src/migration/v1-addon/steps/create-file-path-maps/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import type { FilePathMap, Options } from '../../../../../types/index.js';
import { mapComponentClasses } from './map-component-classes.js';
import { mapComponentStylesheets } from './map-component-stylesheets.js';
import { mapComponentTemplates } from './map-component-templates.js';
import { mapRouteControllers } from './map-route-controllers.js';
import { mapRouteRoutes } from './map-route-routes.js';
import { mapRouteTemplates } from './map-route-templates.js';
import { mapServices } from './map-services.js';

export function mapAppFolder(options: Options): FilePathMap {
return new Map([
...mapComponentClasses(options),
...mapComponentStylesheets(options),
...mapComponentTemplates(options),
...mapRouteControllers(options),
...mapRouteRoutes(options),
...mapRouteTemplates(options),
...mapServices(options),
]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import type {
} from '../../../../../types/index.js';
import { renamePodPath } from '../../../../../utils/files/index.js';

export function mapComponentClasses(options: Options): FilePathMapEntries {
export function mapRouteControllers(options: Options): FilePathMapEntries {
const { projectRoot } = options;

const filePaths = findFiles('addon/components/**/component.{d.ts,js,ts}', {
const filePaths = findFiles('app/**/controller.js', {
projectRoot,
});

return filePaths.map((oldFilePath) => {
const newFilePath = renamePodPath(oldFilePath, {
entityDir: 'addon/components',
entityDir: 'app',
replace: (key: string) => {
return `addon/components/${key}`;
return `app/controllers/${key}`;
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import type {
} from '../../../../../types/index.js';
import { renamePodPath } from '../../../../../utils/files/index.js';

export function mapComponentStylesheets(options: Options): FilePathMapEntries {
export function mapRouteRoutes(options: Options): FilePathMapEntries {
const { projectRoot } = options;

const filePaths = findFiles('addon/components/**/styles.{css,scss}', {
const filePaths = findFiles('app/**/route.js', {
projectRoot,
});

return filePaths.map((oldFilePath) => {
const newFilePath = renamePodPath(oldFilePath, {
entityDir: 'addon/components',
entityDir: 'app',
replace: (key: string) => {
return `addon/components/${key}`;
return `app/routes/${key}`;
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import type {
} from '../../../../../types/index.js';
import { renamePodPath } from '../../../../../utils/files/index.js';

export function mapComponentTemplates(options: Options): FilePathMapEntries {
export function mapRouteTemplates(options: Options): FilePathMapEntries {
const { projectRoot } = options;

const filePaths = findFiles('addon/components/**/template.hbs', {
const filePaths = findFiles('app/!(components)/**/template.js', {
projectRoot,
});

return filePaths.map((oldFilePath) => {
const newFilePath = renamePodPath(oldFilePath, {
entityDir: 'addon/components',
entityDir: 'app',
replace: (key: string) => {
return `addon/components/${key}`;
return `app/templates/${key}`;
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { findFiles } from '@codemod-utils/files';

import type {
FilePathMapEntries,
Options,
} from '../../../../../types/index.js';
import { renamePodPath } from '../../../../../utils/files/index.js';

export function mapServices(options: Options): FilePathMapEntries {
const { projectRoot } = options;

const filePaths = findFiles('app/**/service.js', {
projectRoot,
});

return filePaths.map((oldFilePath) => {
const newFilePath = renamePodPath(oldFilePath, {
entityDir: 'app',
replace: (key: string) => {
return `app/services/${key}`;
},
});

return [oldFilePath, newFilePath];
});
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import type { FilePathMap, Options } from '../../../../../types/index.js';
import { mapComponents } from './map-components.js';
import { mapRouteControllers } from './map-route-controllers.js';
import { mapRouteRoutes } from './map-route-routes.js';
import { mapServices } from './map-services.js';

export function mapTestsFolder(options: Options): FilePathMap {
return new Map([...mapComponents(options)]);
return new Map([
...mapComponents(options),
...mapRouteControllers(options),
...mapRouteRoutes(options),
...mapServices(options),
]);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { join } from 'node:path';

import { findFiles } from '@codemod-utils/files';

import type {
Expand All @@ -6,21 +8,21 @@ import type {
} from '../../../../../types/index.js';
import { renamePodPath } from '../../../../../utils/files/index.js';

export function mapComponents(options: Options): FilePathMapEntries {
export function mapServices(options: Options): FilePathMapEntries {
const { projectRoot } = options;

const filePaths = findFiles(
'tests/integration/components/**/component-test.{js,ts}',
join('tests/unit/!(services)/**/service-test.{js,ts}'),
{
projectRoot,
},
);

return filePaths.map((oldFilePath) => {
const newFilePath = renamePodPath(oldFilePath, {
entityDir: 'tests/integration/components',
entityDir: 'tests/unit',
replace: (key: string) => {
return `tests/integration/components/${key}-test`;
return `tests/unit/services/${key}-test`;
},
});

Expand Down
4 changes: 2 additions & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { FilePath, FilePathMap } from '@codemod-utils/files';
type CodemodOptions = {
podPath: string;
projectRoot: string;
projectType: 'app' | 'engine' | 'v1-addon';
projectType: 'app' | 'v1-addon';
testRun: boolean;
};

Expand All @@ -12,7 +12,7 @@ type FilePathMapEntries = [FilePath, FilePath][];
type Options = {
podPath: string;
projectRoot: string;
projectType: 'app' | 'engine' | 'v1-addon';
projectType: 'app' | 'v1-addon';
testRun: boolean;
};

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit a3c6fc0

Please sign in to comment.