Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowed users to specify podModulePrefix (ember-app) #7

Merged
merged 8 commits into from
Jul 25, 2022
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ npx ember-codemod-pod-to-octane --root=<your/project/path>
</details>


<details>
<summary>Optional: Specify the pod path</summary>

Pass `--pod-path` if `podModulePrefix` is set in `config/environment.js` and has a different value than `modulePrefix`. "Subtract" `modulePrefix` from `podModulePrefix` to get the pod path.

```sh
# If modulePrefix is 'my-app' and podModulePrefix is 'my-app/pods'
npx ember-codemod-pod-to-octane --pod-path=pods
```

</details>


### Limitations

The codemod is designed to cover typical uses of an Ember app, addon, and engine. It is not designed to cover one-off cases.
Expand Down
6 changes: 6 additions & 0 deletions bin/ember-codemod-pod-to-octane.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ process.title = 'ember-codemod-pod-to-octane';

// Set codemod options
const { argv } = yargs(hideBin(process.argv))
.option('pod-path', {
default: '',
describe: 'Namespace used for the pod layout',
type: 'string',
})
.option('root', {
describe: 'Location of your Ember project',
type: 'string',
Expand All @@ -28,6 +33,7 @@ const { argv } = yargs(hideBin(process.argv))
});

const options = {
podPath: argv['pod-path'],
projectRoot: argv['root'] ?? process.cwd(),
projectType: argv['type'],
testRun: argv['test'],
Expand Down
4 changes: 3 additions & 1 deletion src/migration/ember-addon/addon/component-classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import glob from 'glob';

import { mapPaths } from '../../../utils/map-paths.js';

export function migrationStrategyForComponentClasses(projectRoot) {
export function migrationStrategyForComponentClasses(options) {
const { projectRoot } = options;

const oldPaths = glob.sync('addon/components/**/component.{d.ts,js,ts}', {
cwd: projectRoot,
});
Expand Down
4 changes: 3 additions & 1 deletion src/migration/ember-addon/addon/component-stylesheets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import glob from 'glob';

import { mapPaths } from '../../../utils/map-paths.js';

export function migrationStrategyForComponentStylesheets(projectRoot) {
export function migrationStrategyForComponentStylesheets(options) {
const { projectRoot } = options;

const oldPaths = glob.sync('addon/components/**/styles.{css,scss}', {
cwd: projectRoot,
});
Expand Down
4 changes: 3 additions & 1 deletion src/migration/ember-addon/addon/component-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import glob from 'glob';

import { mapPaths } from '../../../utils/map-paths.js';

export function migrationStrategyForComponentTemplates(projectRoot) {
export function migrationStrategyForComponentTemplates(options) {
const { projectRoot } = options;

const oldPaths = glob.sync('addon/components/**/template.hbs', {
cwd: projectRoot,
});
Expand Down
8 changes: 4 additions & 4 deletions src/migration/ember-addon/addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { migrationStrategyForComponentClasses } from './component-classes.js';
import { migrationStrategyForComponentStylesheets } from './component-stylesheets.js';
import { migrationStrategyForComponentTemplates } from './component-templates.js';

export function migrationStrategyForAddonFolder(projectRoot) {
export function migrationStrategyForAddonFolder(options) {
return new Map([
...migrationStrategyForComponentClasses(projectRoot),
...migrationStrategyForComponentStylesheets(projectRoot),
...migrationStrategyForComponentTemplates(projectRoot),
...migrationStrategyForComponentClasses(options),
...migrationStrategyForComponentStylesheets(options),
...migrationStrategyForComponentTemplates(options),
]);
}
4 changes: 3 additions & 1 deletion src/migration/ember-addon/app/component-classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import glob from 'glob';

import { mapPaths } from '../../../utils/map-paths.js';

export function migrationStrategyForComponentClasses(projectRoot) {
export function migrationStrategyForComponentClasses(options) {
const { projectRoot } = options;

const oldPaths = glob.sync('app/components/**/component.js', {
cwd: projectRoot,
});
Expand Down
4 changes: 3 additions & 1 deletion src/migration/ember-addon/app/component-stylesheets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import glob from 'glob';

import { mapPaths } from '../../../utils/map-paths.js';

export function migrationStrategyForComponentStylesheets(projectRoot) {
export function migrationStrategyForComponentStylesheets(options) {
const { projectRoot } = options;

const oldPaths = glob.sync('app/components/**/styles.js', {
cwd: projectRoot,
});
Expand Down
4 changes: 3 additions & 1 deletion src/migration/ember-addon/app/component-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import glob from 'glob';

import { mapPaths } from '../../../utils/map-paths.js';

export function migrationStrategyForComponentTemplates(projectRoot) {
export function migrationStrategyForComponentTemplates(options) {
const { projectRoot } = options;

const oldPaths = glob.sync('app/components/**/template.js', {
cwd: projectRoot,
});
Expand Down
8 changes: 4 additions & 4 deletions src/migration/ember-addon/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { migrationStrategyForComponentClasses } from './component-classes.js';
import { migrationStrategyForComponentStylesheets } from './component-stylesheets.js';
import { migrationStrategyForComponentTemplates } from './component-templates.js';

export function migrationStrategyForAppFolder(projectRoot) {
export function migrationStrategyForAppFolder(options) {
return new Map([
...migrationStrategyForComponentClasses(projectRoot),
...migrationStrategyForComponentStylesheets(projectRoot),
...migrationStrategyForComponentTemplates(projectRoot),
...migrationStrategyForComponentClasses(options),
...migrationStrategyForComponentStylesheets(options),
...migrationStrategyForComponentTemplates(options),
]);
}
32 changes: 8 additions & 24 deletions src/migration/ember-addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import { migrationStrategyForAppFolder } from './app/index.js';
import { migrationStrategyForTestsFolder } from './tests/index.js';

export function migrateEmberAddon(options) {
const { projectRoot, testRun } = options;
const migrationStrategyAddon = migrationStrategyForAddonFolder(options);
const migrationStrategyApp = migrationStrategyForAppFolder(options);
const migrationStrategyTests = migrationStrategyForTestsFolder(options);

const migrationStrategyAddon = migrationStrategyForAddonFolder(projectRoot);
const migrationStrategyApp = migrationStrategyForAppFolder(projectRoot);
const migrationStrategyTests = migrationStrategyForTestsFolder(projectRoot);

if (testRun) {
if (options.testRun) {
console.log({
migrationStrategyAddon,
migrationStrategyApp,
Expand All @@ -21,23 +19,9 @@ export function migrateEmberAddon(options) {
return;
}

moveFiles({
migrationStrategy: migrationStrategyAddon,
projectRoot,
});

moveFiles({
migrationStrategy: migrationStrategyApp,
projectRoot,
});

moveFiles({
migrationStrategy: migrationStrategyTests,
projectRoot,
});
moveFiles(migrationStrategyAddon, options);
moveFiles(migrationStrategyApp, options);
moveFiles(migrationStrategyTests, options);

updatePaths({
migrationStrategy: migrationStrategyApp,
projectRoot,
});
updatePaths(migrationStrategyApp, options);
}
4 changes: 3 additions & 1 deletion src/migration/ember-addon/tests/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import glob from 'glob';

import { mapPaths } from '../../../utils/map-paths.js';

export function migrationStrategyForComponents(projectRoot) {
export function migrationStrategyForComponents(options) {
const { projectRoot } = options;

const oldPaths = glob.sync(
'tests/integration/components/**/component-test.{js,ts}',
{
Expand Down
4 changes: 2 additions & 2 deletions src/migration/ember-addon/tests/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { migrationStrategyForComponents } from './components.js';

export function migrationStrategyForTestsFolder(projectRoot) {
return new Map([...migrationStrategyForComponents(projectRoot)]);
export function migrationStrategyForTestsFolder(options) {
return new Map([...migrationStrategyForComponents(options)]);
}
20 changes: 13 additions & 7 deletions src/migration/ember-app/app/component-classes.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import glob from 'glob';
import { join } from 'node:path';

import { mapPaths } from '../../../utils/map-paths.js';

export function migrationStrategyForComponentClasses(projectRoot) {
const oldPaths = glob.sync('app/components/**/component.{d.ts,js,ts}', {
cwd: projectRoot,
});
export function migrationStrategyForComponentClasses(options) {
const { podPath, projectRoot } = options;

const oldPaths = glob.sync(
join('app', podPath, 'components', '**', 'component.{d.ts,js,ts}'),
{
cwd: projectRoot,
}
);

return oldPaths.map((oldPath) => {
if (oldPath.endsWith('.d.ts')) {
return mapPaths(oldPath, {
find: {
directory: 'app/components',
directory: join('app', podPath, 'components'),
file: 'component.d.ts',
},
replace(key) {
Expand All @@ -23,7 +29,7 @@ export function migrationStrategyForComponentClasses(projectRoot) {
if (oldPath.endsWith('.ts')) {
return mapPaths(oldPath, {
find: {
directory: 'app/components',
directory: join('app', podPath, 'components'),
file: 'component.ts',
},
replace(key) {
Expand All @@ -34,7 +40,7 @@ export function migrationStrategyForComponentClasses(projectRoot) {

return mapPaths(oldPath, {
find: {
directory: 'app/components',
directory: join('app', podPath, 'components'),
file: 'component.js',
},
replace(key) {
Expand Down
18 changes: 12 additions & 6 deletions src/migration/ember-app/app/component-stylesheets.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import glob from 'glob';
import { join } from 'node:path';

import { mapPaths } from '../../../utils/map-paths.js';

export function migrationStrategyForComponentStylesheets(projectRoot) {
const oldPaths = glob.sync('app/components/**/styles.{css,scss}', {
cwd: projectRoot,
});
export function migrationStrategyForComponentStylesheets(options) {
const { podPath, projectRoot } = options;

const oldPaths = glob.sync(
join('app', podPath, 'components', '**', 'styles.{css,scss}'),
{
cwd: projectRoot,
}
);

return oldPaths.map((oldPath) => {
if (oldPath.endsWith('.scss')) {
return mapPaths(oldPath, {
find: {
directory: 'app/components',
directory: join('app', podPath, 'components'),
file: 'styles.scss',
},
replace(key) {
Expand All @@ -22,7 +28,7 @@ export function migrationStrategyForComponentStylesheets(projectRoot) {

return mapPaths(oldPath, {
find: {
directory: 'app/components',
directory: join('app', podPath, 'components'),
file: 'styles.css',
},
replace(key) {
Expand Down
16 changes: 11 additions & 5 deletions src/migration/ember-app/app/component-templates.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import glob from 'glob';
import { join } from 'node:path';

import { mapPaths } from '../../../utils/map-paths.js';

export function migrationStrategyForComponentTemplates(projectRoot) {
const oldPaths = glob.sync('app/components/**/template.hbs', {
cwd: projectRoot,
});
export function migrationStrategyForComponentTemplates(options) {
const { podPath, projectRoot } = options;

const oldPaths = glob.sync(
join('app', podPath, 'components', '**', 'template.hbs'),
{
cwd: projectRoot,
}
);

return oldPaths.map((oldPath) => {
return mapPaths(oldPath, {
find: {
directory: 'app/components',
directory: join('app', podPath, 'components'),
file: 'template.hbs',
},
replace(key) {
Expand Down
24 changes: 12 additions & 12 deletions src/migration/ember-app/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import { migrationStrategyForRouteStylesheets } from './route-stylesheets.js';
import { migrationStrategyForRouteTemplates } from './route-templates.js';
import { migrationStrategyForServices } from './services.js';

export function migrationStrategyForAppFolder(projectRoot) {
export function migrationStrategyForAppFolder(options) {
return new Map([
...migrationStrategyForComponentClasses(projectRoot),
...migrationStrategyForComponentStylesheets(projectRoot),
...migrationStrategyForComponentTemplates(projectRoot),
...migrationStrategyForRouteAdapters(projectRoot),
...migrationStrategyForRouteControllers(projectRoot),
...migrationStrategyForRouteModels(projectRoot),
...migrationStrategyForRouteRoutes(projectRoot),
...migrationStrategyForRouteSerializers(projectRoot),
...migrationStrategyForRouteStylesheets(projectRoot),
...migrationStrategyForRouteTemplates(projectRoot),
...migrationStrategyForServices(projectRoot),
...migrationStrategyForComponentClasses(options),
...migrationStrategyForComponentStylesheets(options),
...migrationStrategyForComponentTemplates(options),
...migrationStrategyForRouteAdapters(options),
...migrationStrategyForRouteControllers(options),
...migrationStrategyForRouteModels(options),
...migrationStrategyForRouteRoutes(options),
...migrationStrategyForRouteSerializers(options),
...migrationStrategyForRouteStylesheets(options),
...migrationStrategyForRouteTemplates(options),
...migrationStrategyForServices(options),
]);
}
11 changes: 7 additions & 4 deletions src/migration/ember-app/app/route-adapters.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import glob from 'glob';
import { join } from 'node:path';

import { mapPaths } from '../../../utils/map-paths.js';

export function migrationStrategyForRouteAdapters(projectRoot) {
const oldPaths = glob.sync('app/**/adapter.{js,ts}', {
export function migrationStrategyForRouteAdapters(options) {
const { podPath, projectRoot } = options;

const oldPaths = glob.sync(join('app', podPath, '**', 'adapter.{js,ts}'), {
cwd: projectRoot,
});

return oldPaths.map((oldPath) => {
if (oldPath.endsWith('.ts')) {
return mapPaths(oldPath, {
find: {
directory: 'app',
directory: join('app', podPath),
file: 'adapter.ts',
},
replace(key) {
Expand All @@ -22,7 +25,7 @@ export function migrationStrategyForRouteAdapters(projectRoot) {

return mapPaths(oldPath, {
find: {
directory: 'app',
directory: join('app', podPath),
file: 'adapter.js',
},
replace(key) {
Expand Down