ember-codemod-pod-to-octane 1.0.1 → 1.1.1

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 (52) hide show
  1. package/README.md +14 -7
  2. package/bin/ember-codemod-pod-to-octane.js +2 -2
  3. package/package.json +14 -12
  4. package/src/index.js +6 -6
  5. package/src/migration/ember-addon/addon/component-classes.js +2 -4
  6. package/src/migration/ember-addon/addon/component-stylesheets.js +2 -4
  7. package/src/migration/ember-addon/addon/component-templates.js +2 -4
  8. package/src/migration/ember-addon/app/component-classes.js +2 -4
  9. package/src/migration/ember-addon/app/component-stylesheets.js +2 -4
  10. package/src/migration/ember-addon/app/component-templates.js +2 -4
  11. package/src/migration/ember-addon/index.js +6 -3
  12. package/src/migration/ember-addon/steps/create-options.js +46 -0
  13. package/src/migration/ember-addon/steps/index.js +1 -0
  14. package/src/migration/ember-addon/tests/components.js +3 -5
  15. package/src/migration/ember-app/app/component-classes.js +3 -5
  16. package/src/migration/ember-app/app/component-stylesheets.js +3 -5
  17. package/src/migration/ember-app/app/component-templates.js +3 -5
  18. package/src/migration/ember-app/app/route-adapters.js +2 -4
  19. package/src/migration/ember-app/app/route-controllers.js +2 -4
  20. package/src/migration/ember-app/app/route-models.js +2 -4
  21. package/src/migration/ember-app/app/route-routes.js +2 -4
  22. package/src/migration/ember-app/app/route-serializers.js +2 -4
  23. package/src/migration/ember-app/app/route-stylesheets.js +3 -5
  24. package/src/migration/ember-app/app/route-templates.js +3 -5
  25. package/src/migration/ember-app/app/services.js +2 -4
  26. package/src/migration/ember-app/index.js +4 -1
  27. package/src/migration/ember-app/steps/create-options.js +46 -0
  28. package/src/migration/ember-app/steps/index.js +1 -0
  29. package/src/migration/ember-app/tests/components.js +4 -6
  30. package/src/migration/ember-app/tests/route-controllers.js +6 -8
  31. package/src/migration/ember-app/tests/route-routes.js +5 -7
  32. package/src/migration/ember-app/tests/services.js +3 -5
  33. package/src/migration/ember-engine/addon/component-classes.js +2 -4
  34. package/src/migration/ember-engine/addon/component-stylesheets.js +2 -4
  35. package/src/migration/ember-engine/addon/component-templates.js +2 -4
  36. package/src/migration/ember-engine/addon/route-controllers.js +2 -4
  37. package/src/migration/ember-engine/addon/route-routes.js +2 -4
  38. package/src/migration/ember-engine/addon/route-stylesheets.js +2 -4
  39. package/src/migration/ember-engine/addon/route-templates.js +2 -4
  40. package/src/migration/ember-engine/index.js +23 -5
  41. package/src/migration/ember-engine/steps/create-options.js +46 -0
  42. package/src/migration/ember-engine/steps/index.js +4 -0
  43. package/src/migration/ember-engine/steps/update-absolute-paths.js +102 -0
  44. package/src/migration/ember-engine/steps/use-absolute-paths.js +58 -0
  45. package/src/migration/ember-engine/steps/use-relative-paths.js +110 -0
  46. package/src/migration/ember-engine/tests/components.js +3 -5
  47. package/src/migration/ember-engine/tests/route-controllers.js +5 -7
  48. package/src/migration/ember-engine/tests/route-routes.js +3 -5
  49. package/src/utils/ember-addon/app/components.js +1 -1
  50. package/src/utils/files/find-files.js +28 -0
  51. package/src/utils/files/map-file-path.js +1 -1
  52. package/src/utils/files.js +1 -0
package/README.md CHANGED
@@ -5,6 +5,12 @@
5
5
  _Codemod to un-pod Ember apps, addons, and engines_
6
6
 
7
7
 
8
+ ## Features
9
+
10
+ - Preserves your code whenever possible
11
+ - Supports [`ember-css-modules`](https://github.com/salsify/ember-css-modules)
12
+
13
+
8
14
  ## Usage
9
15
 
10
16
  Step 1. Quickly return to [default Octane](https://cli.emberjs.com/release/advanced-use/project-layouts/#classiclayout).<sup>1</sup>
@@ -35,7 +41,7 @@ npx ember-codemod-pod-to-octane --type=engine
35
41
  <details>
36
42
  <summary>Optional: Do a test run</summary>
37
43
 
38
- Pass `--test` to preview how the codemod will move files around.
44
+ Pass `--test` to preview how the codemod will move files.
39
45
 
40
46
  ```sh
41
47
  npx ember-codemod-pod-to-octane --test
@@ -47,7 +53,7 @@ npx ember-codemod-pod-to-octane --test
47
53
  <details>
48
54
  <summary>Optional: Specify the project root</summary>
49
55
 
50
- Pass `--root` to run the codemod against a project somewhere else.
56
+ Pass `--root` to run the codemod on a project somewhere else (i.e. not in the current directory).
51
57
 
52
58
  ```sh
53
59
  npx ember-codemod-pod-to-octane --root=<your/project/path>
@@ -105,23 +111,24 @@ The codemod assumes that an engine is used to define routes and route-specific c
105
111
  </details>
106
112
 
107
113
 
108
- To better meet your needs, consider forking the repo and running the codemod locally.
114
+ To better meet your needs, consider cloning the repo and running the codemod locally.
109
115
 
110
116
  ```sh
111
- cd <your/forked/repo>
112
- ./bin/ember-codemod-pod-to-octane.js <arguments>
117
+ cd <your/cloned/repo>
118
+ ./bin/ember-codemod-pod-to-octane.js --root=<your/project/path>
113
119
  ```
114
120
 
115
121
 
116
122
  ## Compatibility
117
123
 
118
124
  * Node.js v16 or above
119
- * [`ember-css-modules`](https://github.com/salsify/ember-css-modules)
120
125
 
121
126
 
122
127
  ## Contributing
123
128
 
124
- To provide feedback, you can reach out to me on [Discord](https://discord.gg/emberjs) at `ijlee2`. Please star this project so that I can gauge its importance to you and the Ember community. ⭐
129
+ See the [Contributing](CONTRIBUTING.md) guide for details.
130
+
131
+ If you have an open-sourced app or addon that I can use as a reference, reach out to me on [Discord](https://discord.gg/emberjs) at `ijlee2`. Please star this project so that I can gauge its importance to you and the Ember community. ⭐
125
132
 
126
133
 
127
134
  ## Credits
@@ -32,11 +32,11 @@ const { argv } = yargs(hideBin(process.argv))
32
32
  type: 'string',
33
33
  });
34
34
 
35
- const options = {
35
+ const codemodOptions = {
36
36
  podPath: argv['pod-path'],
37
37
  projectRoot: argv['root'] ?? process.cwd(),
38
38
  projectType: argv['type'],
39
39
  testRun: argv['test'],
40
40
  };
41
41
 
42
- runCodemod(options);
42
+ runCodemod(codemodOptions);
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "ember-codemod-pod-to-octane",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "description": "Codemod to un-pod Ember apps, addons, and engines",
5
5
  "keywords": [
6
+ "codemod",
6
7
  "ember-codemod",
7
8
  "ember-octane",
8
9
  "emberjs"
@@ -25,26 +26,27 @@
25
26
  ],
26
27
  "scripts": {
27
28
  "changelog": "lerna-changelog",
28
- "lint": "eslint . --cache --ext=.cjs,.js",
29
- "lint:fix": "eslint . --ext=.cjs,.js --fix",
30
- "start": "node ./src/index.js",
29
+ "lint": "eslint . --cache",
30
+ "lint:fix": "eslint . --fix",
31
31
  "test": "mt tests --quiet"
32
32
  },
33
33
  "dependencies": {
34
- "@babel/core": "^7.20.12",
35
- "@babel/eslint-parser": "^7.19.1",
36
- "glob": "^8.1.0",
37
- "yargs": "^17.6.2"
34
+ "glob": "~10.1.0",
35
+ "yargs": "^17.7.2"
38
36
  },
39
37
  "devDependencies": {
38
+ "@babel/core": "^7.21.8",
39
+ "@babel/eslint-parser": "^7.21.8",
40
40
  "@sondr3/minitest": "^0.1.1",
41
- "eslint": "^8.32.0",
42
- "eslint-config-prettier": "^8.6.0",
41
+ "eslint": "^8.39.0",
42
+ "eslint-config-prettier": "^8.8.0",
43
+ "eslint-plugin-import": "^2.27.5",
44
+ "eslint-plugin-n": "^15.7.0",
43
45
  "eslint-plugin-prettier": "^4.2.1",
44
- "eslint-plugin-simple-import-sort": "^9.0.0",
46
+ "eslint-plugin-simple-import-sort": "^10.0.0",
45
47
  "fixturify": "^3.0.0",
46
48
  "lerna-changelog": "^2.2.0",
47
- "prettier": "^2.8.3"
49
+ "prettier": "^2.8.8"
48
50
  },
49
51
  "engines": {
50
52
  "node": ">= 16"
package/src/index.js CHANGED
@@ -4,25 +4,25 @@ import {
4
4
  migrateEmberEngine,
5
5
  } from './migration/index.js';
6
6
 
7
- export function runCodemod(options) {
8
- switch (options.projectType) {
7
+ export function runCodemod(codemodOptions) {
8
+ switch (codemodOptions.projectType) {
9
9
  case 'addon': {
10
- migrateEmberAddon(options);
10
+ migrateEmberAddon(codemodOptions);
11
11
  break;
12
12
  }
13
13
 
14
14
  case 'app': {
15
- migrateEmberApp(options);
15
+ migrateEmberApp(codemodOptions);
16
16
  break;
17
17
  }
18
18
 
19
19
  case 'engine': {
20
- migrateEmberEngine(options);
20
+ migrateEmberEngine(codemodOptions);
21
21
  break;
22
22
  }
23
23
 
24
24
  default: {
25
- console.error(`Unknown project type: ${options.projectType}`);
25
+ console.error(`Unknown project type: ${codemodOptions.projectType}`);
26
26
  }
27
27
  }
28
28
  }
@@ -1,11 +1,9 @@
1
- import glob from 'glob';
2
-
3
- import { mapFilePath } from '../../../utils/files.js';
1
+ import { findFiles, mapFilePath } from '../../../utils/files.js';
4
2
 
5
3
  export function migrationStrategyForComponentClasses(options) {
6
4
  const { projectRoot } = options;
7
5
 
8
- const oldPaths = glob.sync('addon/components/**/component.{d.ts,js,ts}', {
6
+ const oldPaths = findFiles('addon/components/**/component.{d.ts,js,ts}', {
9
7
  cwd: projectRoot,
10
8
  });
11
9
 
@@ -1,11 +1,9 @@
1
- import glob from 'glob';
2
-
3
- import { mapFilePath } from '../../../utils/files.js';
1
+ import { findFiles, mapFilePath } from '../../../utils/files.js';
4
2
 
5
3
  export function migrationStrategyForComponentStylesheets(options) {
6
4
  const { projectRoot } = options;
7
5
 
8
- const oldPaths = glob.sync('addon/components/**/styles.{css,scss}', {
6
+ const oldPaths = findFiles('addon/components/**/styles.{css,scss}', {
9
7
  cwd: projectRoot,
10
8
  });
11
9
 
@@ -1,11 +1,9 @@
1
- import glob from 'glob';
2
-
3
- import { mapFilePath } from '../../../utils/files.js';
1
+ import { findFiles, mapFilePath } from '../../../utils/files.js';
4
2
 
5
3
  export function migrationStrategyForComponentTemplates(options) {
6
4
  const { projectRoot } = options;
7
5
 
8
- const oldPaths = glob.sync('addon/components/**/template.hbs', {
6
+ const oldPaths = findFiles('addon/components/**/template.hbs', {
9
7
  cwd: projectRoot,
10
8
  });
11
9
 
@@ -1,11 +1,9 @@
1
- import glob from 'glob';
2
-
3
- import { mapFilePath } from '../../../utils/files.js';
1
+ import { findFiles, mapFilePath } from '../../../utils/files.js';
4
2
 
5
3
  export function migrationStrategyForComponentClasses(options) {
6
4
  const { projectRoot } = options;
7
5
 
8
- const oldPaths = glob.sync('app/components/**/component.js', {
6
+ const oldPaths = findFiles('app/components/**/component.js', {
9
7
  cwd: projectRoot,
10
8
  });
11
9
 
@@ -1,11 +1,9 @@
1
- import glob from 'glob';
2
-
3
- import { mapFilePath } from '../../../utils/files.js';
1
+ import { findFiles, mapFilePath } from '../../../utils/files.js';
4
2
 
5
3
  export function migrationStrategyForComponentStylesheets(options) {
6
4
  const { projectRoot } = options;
7
5
 
8
- const oldPaths = glob.sync('app/components/**/styles.js', {
6
+ const oldPaths = findFiles('app/components/**/styles.js', {
9
7
  cwd: projectRoot,
10
8
  });
11
9
 
@@ -1,11 +1,9 @@
1
- import glob from 'glob';
2
-
3
- import { mapFilePath } from '../../../utils/files.js';
1
+ import { findFiles, mapFilePath } from '../../../utils/files.js';
4
2
 
5
3
  export function migrationStrategyForComponentTemplates(options) {
6
4
  const { projectRoot } = options;
7
5
 
8
- const oldPaths = glob.sync('app/components/**/template.js', {
6
+ const oldPaths = findFiles('app/components/**/template.js', {
9
7
  cwd: projectRoot,
10
8
  });
11
9
 
@@ -1,10 +1,13 @@
1
- import { updatePaths } from '../../utils/ember-addon/app/components.js';
1
+ import { updatePathsInAppFolder } from '../../utils/ember-addon/app/components.js';
2
2
  import { moveFiles } from '../../utils/files.js';
3
3
  import { migrationStrategyForAddonFolder } from './addon/index.js';
4
4
  import { migrationStrategyForAppFolder } from './app/index.js';
5
+ import { createOptions } from './steps/index.js';
5
6
  import { migrationStrategyForTestsFolder } from './tests/index.js';
6
7
 
7
- export function migrateEmberAddon(options) {
8
+ export function migrateEmberAddon(codemodOptions) {
9
+ const options = createOptions(codemodOptions);
10
+
8
11
  const migrationStrategyAddon = migrationStrategyForAddonFolder(options);
9
12
  const migrationStrategyApp = migrationStrategyForAppFolder(options);
10
13
  const migrationStrategyTests = migrationStrategyForTestsFolder(options);
@@ -23,5 +26,5 @@ export function migrateEmberAddon(options) {
23
26
  moveFiles(migrationStrategyApp, options);
24
27
  moveFiles(migrationStrategyTests, options);
25
28
 
26
- updatePaths(migrationStrategyApp, options);
29
+ updatePathsInAppFolder(migrationStrategyApp, options);
27
30
  }
@@ -0,0 +1,46 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+
4
+ function analyzePackageJson(codemodOptions) {
5
+ const { projectRoot } = codemodOptions;
6
+
7
+ try {
8
+ const packageJsonFile = readFileSync(
9
+ join(projectRoot, 'package.json'),
10
+ 'utf8',
11
+ );
12
+
13
+ const { name } = JSON.parse(packageJsonFile);
14
+
15
+ if (!name) {
16
+ throw new SyntaxError('Package name is missing.');
17
+ }
18
+
19
+ if (name.includes('/')) {
20
+ // eslint-disable-next-line no-unused-vars
21
+ const [scope, packageName] = name.split('/');
22
+
23
+ if (!packageName) {
24
+ throw new SyntaxError('Package name is missing.');
25
+ }
26
+ }
27
+
28
+ return name;
29
+ } catch (e) {
30
+ throw new SyntaxError(
31
+ `ERROR: package.json is missing or is not valid. (${e.message})\n`,
32
+ );
33
+ }
34
+ }
35
+
36
+ export function createOptions(codemodOptions) {
37
+ const projectName = analyzePackageJson(codemodOptions);
38
+
39
+ return {
40
+ podPath: codemodOptions.podPath,
41
+ projectName,
42
+ projectRoot: codemodOptions.projectRoot,
43
+ projectType: codemodOptions.projectType,
44
+ testRun: codemodOptions.testRun,
45
+ };
46
+ }
@@ -0,0 +1 @@
1
+ export * from './create-options.js';
@@ -1,15 +1,13 @@
1
- import glob from 'glob';
2
-
3
- import { mapFilePath } from '../../../utils/files.js';
1
+ import { findFiles, mapFilePath } from '../../../utils/files.js';
4
2
 
5
3
  export function migrationStrategyForComponents(options) {
6
4
  const { projectRoot } = options;
7
5
 
8
- const oldPaths = glob.sync(
6
+ const oldPaths = findFiles(
9
7
  'tests/integration/components/**/component-test.{js,ts}',
10
8
  {
11
9
  cwd: projectRoot,
12
- }
10
+ },
13
11
  );
14
12
 
15
13
  return oldPaths.map((oldPath) => {
@@ -1,17 +1,15 @@
1
1
  import { join } from 'node:path';
2
2
 
3
- import glob from 'glob';
4
-
5
- import { mapFilePath } from '../../../utils/files.js';
3
+ import { findFiles, mapFilePath } from '../../../utils/files.js';
6
4
 
7
5
  export function migrationStrategyForComponentClasses(options) {
8
6
  const { podPath, projectRoot } = options;
9
7
 
10
- const oldPaths = glob.sync(
8
+ const oldPaths = findFiles(
11
9
  join('app', podPath, 'components', '**', 'component.{d.ts,js,ts}'),
12
10
  {
13
11
  cwd: projectRoot,
14
- }
12
+ },
15
13
  );
16
14
 
17
15
  return oldPaths.map((oldPath) => {
@@ -1,17 +1,15 @@
1
1
  import { join } from 'node:path';
2
2
 
3
- import glob from 'glob';
4
-
5
- import { mapFilePath } from '../../../utils/files.js';
3
+ import { findFiles, mapFilePath } from '../../../utils/files.js';
6
4
 
7
5
  export function migrationStrategyForComponentStylesheets(options) {
8
6
  const { podPath, projectRoot } = options;
9
7
 
10
- const oldPaths = glob.sync(
8
+ const oldPaths = findFiles(
11
9
  join('app', podPath, 'components', '**', 'styles.{css,scss}'),
12
10
  {
13
11
  cwd: projectRoot,
14
- }
12
+ },
15
13
  );
16
14
 
17
15
  return oldPaths.map((oldPath) => {
@@ -1,17 +1,15 @@
1
1
  import { join } from 'node:path';
2
2
 
3
- import glob from 'glob';
4
-
5
- import { mapFilePath } from '../../../utils/files.js';
3
+ import { findFiles, mapFilePath } from '../../../utils/files.js';
6
4
 
7
5
  export function migrationStrategyForComponentTemplates(options) {
8
6
  const { podPath, projectRoot } = options;
9
7
 
10
- const oldPaths = glob.sync(
8
+ const oldPaths = findFiles(
11
9
  join('app', podPath, 'components', '**', 'template.hbs'),
12
10
  {
13
11
  cwd: projectRoot,
14
- }
12
+ },
15
13
  );
16
14
 
17
15
  return oldPaths.map((oldPath) => {
@@ -1,13 +1,11 @@
1
1
  import { join } from 'node:path';
2
2
 
3
- import glob from 'glob';
4
-
5
- import { mapFilePath } from '../../../utils/files.js';
3
+ import { findFiles, mapFilePath } from '../../../utils/files.js';
6
4
 
7
5
  export function migrationStrategyForRouteAdapters(options) {
8
6
  const { podPath, projectRoot } = options;
9
7
 
10
- const oldPaths = glob.sync(join('app', podPath, '**', 'adapter.{js,ts}'), {
8
+ const oldPaths = findFiles(join('app', podPath, '**', 'adapter.{js,ts}'), {
11
9
  cwd: projectRoot,
12
10
  });
13
11
 
@@ -1,13 +1,11 @@
1
1
  import { join } from 'node:path';
2
2
 
3
- import glob from 'glob';
4
-
5
- import { mapFilePath } from '../../../utils/files.js';
3
+ import { findFiles, mapFilePath } from '../../../utils/files.js';
6
4
 
7
5
  export function migrationStrategyForRouteControllers(options) {
8
6
  const { podPath, projectRoot } = options;
9
7
 
10
- const oldPaths = glob.sync(join('app', podPath, '**', 'controller.{js,ts}'), {
8
+ const oldPaths = findFiles(join('app', podPath, '**', 'controller.{js,ts}'), {
11
9
  cwd: projectRoot,
12
10
  });
13
11
 
@@ -1,13 +1,11 @@
1
1
  import { join } from 'node:path';
2
2
 
3
- import glob from 'glob';
4
-
5
- import { mapFilePath } from '../../../utils/files.js';
3
+ import { findFiles, mapFilePath } from '../../../utils/files.js';
6
4
 
7
5
  export function migrationStrategyForRouteModels(options) {
8
6
  const { podPath, projectRoot } = options;
9
7
 
10
- const oldPaths = glob.sync(join('app', podPath, '**', 'model.{js,ts}'), {
8
+ const oldPaths = findFiles(join('app', podPath, '**', 'model.{js,ts}'), {
11
9
  cwd: projectRoot,
12
10
  });
13
11
 
@@ -1,13 +1,11 @@
1
1
  import { join } from 'node:path';
2
2
 
3
- import glob from 'glob';
4
-
5
- import { mapFilePath } from '../../../utils/files.js';
3
+ import { findFiles, mapFilePath } from '../../../utils/files.js';
6
4
 
7
5
  export function migrationStrategyForRouteRoutes(options) {
8
6
  const { podPath, projectRoot } = options;
9
7
 
10
- const oldPaths = glob.sync(join('app', podPath, '**', 'route.{js,ts}'), {
8
+ const oldPaths = findFiles(join('app', podPath, '**', 'route.{js,ts}'), {
11
9
  cwd: projectRoot,
12
10
  });
13
11
 
@@ -1,13 +1,11 @@
1
1
  import { join } from 'node:path';
2
2
 
3
- import glob from 'glob';
4
-
5
- import { mapFilePath } from '../../../utils/files.js';
3
+ import { findFiles, mapFilePath } from '../../../utils/files.js';
6
4
 
7
5
  export function migrationStrategyForRouteSerializers(options) {
8
6
  const { podPath, projectRoot } = options;
9
7
 
10
- const oldPaths = glob.sync(join('app', podPath, '**', 'serializer.{js,ts}'), {
8
+ const oldPaths = findFiles(join('app', podPath, '**', 'serializer.{js,ts}'), {
11
9
  cwd: projectRoot,
12
10
  });
13
11
 
@@ -1,17 +1,15 @@
1
1
  import { join } from 'node:path';
2
2
 
3
- import glob from 'glob';
4
-
5
- import { mapFilePath } from '../../../utils/files.js';
3
+ import { findFiles, mapFilePath } from '../../../utils/files.js';
6
4
 
7
5
  export function migrationStrategyForRouteStylesheets(options) {
8
6
  const { podPath, projectRoot } = options;
9
7
 
10
- const oldPaths = glob.sync(
8
+ const oldPaths = findFiles(
11
9
  join('app', podPath, '!(components)', '**', 'styles.{css,scss}'),
12
10
  {
13
11
  cwd: projectRoot,
14
- }
12
+ },
15
13
  );
16
14
 
17
15
  return oldPaths.map((oldPath) => {
@@ -1,17 +1,15 @@
1
1
  import { join } from 'node:path';
2
2
 
3
- import glob from 'glob';
4
-
5
- import { mapFilePath } from '../../../utils/files.js';
3
+ import { findFiles, mapFilePath } from '../../../utils/files.js';
6
4
 
7
5
  export function migrationStrategyForRouteTemplates(options) {
8
6
  const { podPath, projectRoot } = options;
9
7
 
10
- const oldPaths = glob.sync(
8
+ const oldPaths = findFiles(
11
9
  join('app', podPath, '!(components)', '**', 'template.hbs'),
12
10
  {
13
11
  cwd: projectRoot,
14
- }
12
+ },
15
13
  );
16
14
 
17
15
  return oldPaths.map((oldPath) => {
@@ -1,13 +1,11 @@
1
1
  import { join } from 'node:path';
2
2
 
3
- import glob from 'glob';
4
-
5
- import { mapFilePath } from '../../../utils/files.js';
3
+ import { findFiles, mapFilePath } from '../../../utils/files.js';
6
4
 
7
5
  export function migrationStrategyForServices(options) {
8
6
  const { podPath, projectRoot } = options;
9
7
 
10
- const oldPaths = glob.sync(join('app', podPath, '**', 'service.{js,ts}'), {
8
+ const oldPaths = findFiles(join('app', podPath, '**', 'service.{js,ts}'), {
11
9
  cwd: projectRoot,
12
10
  });
13
11
 
@@ -1,8 +1,11 @@
1
1
  import { moveFiles } from '../../utils/files.js';
2
2
  import { migrationStrategyForAppFolder } from './app/index.js';
3
+ import { createOptions } from './steps/index.js';
3
4
  import { migrationStrategyForTestsFolder } from './tests/index.js';
4
5
 
5
- export function migrateEmberApp(options) {
6
+ export function migrateEmberApp(codemodOptions) {
7
+ const options = createOptions(codemodOptions);
8
+
6
9
  const migrationStrategyApp = migrationStrategyForAppFolder(options);
7
10
  const migrationStrategyTests = migrationStrategyForTestsFolder(options);
8
11
 
@@ -0,0 +1,46 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+
4
+ function analyzePackageJson(codemodOptions) {
5
+ const { projectRoot } = codemodOptions;
6
+
7
+ try {
8
+ const packageJsonFile = readFileSync(
9
+ join(projectRoot, 'package.json'),
10
+ 'utf8',
11
+ );
12
+
13
+ const { name } = JSON.parse(packageJsonFile);
14
+
15
+ if (!name) {
16
+ throw new SyntaxError('Package name is missing.');
17
+ }
18
+
19
+ if (name.includes('/')) {
20
+ // eslint-disable-next-line no-unused-vars
21
+ const [scope, packageName] = name.split('/');
22
+
23
+ if (!packageName) {
24
+ throw new SyntaxError('Package name is missing.');
25
+ }
26
+ }
27
+
28
+ return name;
29
+ } catch (e) {
30
+ throw new SyntaxError(
31
+ `ERROR: package.json is missing or is not valid. (${e.message})\n`,
32
+ );
33
+ }
34
+ }
35
+
36
+ export function createOptions(codemodOptions) {
37
+ const projectName = analyzePackageJson(codemodOptions);
38
+
39
+ return {
40
+ podPath: codemodOptions.podPath,
41
+ projectName,
42
+ projectRoot: codemodOptions.projectRoot,
43
+ projectType: codemodOptions.projectType,
44
+ testRun: codemodOptions.testRun,
45
+ };
46
+ }
@@ -0,0 +1 @@
1
+ export * from './create-options.js';
@@ -1,23 +1,21 @@
1
1
  import { join } from 'node:path';
2
2
 
3
- import glob from 'glob';
4
-
5
- import { mapFilePath } from '../../../utils/files.js';
3
+ import { findFiles, mapFilePath } from '../../../utils/files.js';
6
4
 
7
5
  export function migrationStrategyForComponents(options) {
8
6
  const { podPath, projectRoot } = options;
9
7
 
10
- const oldPaths = glob.sync(
8
+ const oldPaths = findFiles(
11
9
  join(
12
10
  'tests/integration',
13
11
  podPath,
14
12
  'components',
15
13
  '**',
16
- 'component-test.{js,ts}'
14
+ 'component-test.{js,ts}',
17
15
  ),
18
16
  {
19
17
  cwd: projectRoot,
20
- }
18
+ },
21
19
  );
22
20
 
23
21
  return oldPaths.map((oldPath) => {