ember-codemod-pod-to-octane 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/LICENSE.md +9 -0
- package/README.md +112 -0
- package/bin/ember-codemod-pod-to-octane.js +36 -0
- package/package.json +62 -0
- package/src/index.js +28 -0
- package/src/migration/ember-addon/addon/component-classes.js +45 -0
- package/src/migration/ember-addon/addon/component-stylesheets.js +21 -0
- package/src/migration/ember-addon/addon/component-templates.js +21 -0
- package/src/migration/ember-addon/addon/index.js +11 -0
- package/src/migration/ember-addon/app/component-classes.js +21 -0
- package/src/migration/ember-addon/app/component-stylesheets.js +21 -0
- package/src/migration/ember-addon/app/component-templates.js +21 -0
- package/src/migration/ember-addon/app/index.js +11 -0
- package/src/migration/ember-addon/index.js +43 -0
- package/src/migration/ember-addon/tests/components.js +36 -0
- package/src/migration/ember-addon/tests/index.js +5 -0
- package/src/migration/ember-app/app/component-classes.js +45 -0
- package/src/migration/ember-app/app/component-stylesheets.js +21 -0
- package/src/migration/ember-app/app/component-templates.js +21 -0
- package/src/migration/ember-app/app/index.js +25 -0
- package/src/migration/ember-app/app/route-adapters.js +33 -0
- package/src/migration/ember-app/app/route-controllers.js +33 -0
- package/src/migration/ember-app/app/route-models.js +33 -0
- package/src/migration/ember-app/app/route-routes.js +33 -0
- package/src/migration/ember-app/app/route-serializers.js +33 -0
- package/src/migration/ember-app/app/route-stylesheets.js +21 -0
- package/src/migration/ember-app/app/route-templates.js +21 -0
- package/src/migration/ember-app/index.js +29 -0
- package/src/migration/ember-app/tests/components.js +36 -0
- package/src/migration/ember-app/tests/index.js +11 -0
- package/src/migration/ember-app/tests/route-controllers.js +75 -0
- package/src/migration/ember-app/tests/route-routes.js +69 -0
- package/src/migration/ember-engine/addon/component-classes.js +45 -0
- package/src/migration/ember-engine/addon/component-stylesheets.js +21 -0
- package/src/migration/ember-engine/addon/component-templates.js +21 -0
- package/src/migration/ember-engine/addon/index.js +19 -0
- package/src/migration/ember-engine/addon/route-controllers.js +33 -0
- package/src/migration/ember-engine/addon/route-routes.js +33 -0
- package/src/migration/ember-engine/addon/route-stylesheets.js +21 -0
- package/src/migration/ember-engine/addon/route-templates.js +21 -0
- package/src/migration/ember-engine/index.js +29 -0
- package/src/migration/ember-engine/tests/components.js +36 -0
- package/src/migration/ember-engine/tests/index.js +11 -0
- package/src/migration/ember-engine/tests/route-controllers.js +75 -0
- package/src/migration/ember-engine/tests/route-routes.js +69 -0
- package/src/migration/index.js +3 -0
- package/src/utils/ember-addon/app/components.js +17 -0
- package/src/utils/map-paths.js +15 -0
- package/src/utils/move-files.js +32 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import glob from 'glob';
|
|
2
|
+
|
|
3
|
+
import { mapPaths } from '../../../utils/map-paths.js';
|
|
4
|
+
|
|
5
|
+
export function migrationStrategyForComponents(projectRoot) {
|
|
6
|
+
const oldPaths = glob.sync(
|
|
7
|
+
'tests/integration/components/**/component-test.{js,ts}',
|
|
8
|
+
{
|
|
9
|
+
cwd: projectRoot,
|
|
10
|
+
}
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
return oldPaths.map((oldPath) => {
|
|
14
|
+
if (oldPath.endsWith('.ts')) {
|
|
15
|
+
return mapPaths(oldPath, {
|
|
16
|
+
find: {
|
|
17
|
+
directory: 'tests/integration/components',
|
|
18
|
+
file: 'component-test.ts',
|
|
19
|
+
},
|
|
20
|
+
replace(key) {
|
|
21
|
+
return `tests/integration/components/${key}-test.ts`;
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return mapPaths(oldPath, {
|
|
27
|
+
find: {
|
|
28
|
+
directory: 'tests/integration/components',
|
|
29
|
+
file: 'component-test.js',
|
|
30
|
+
},
|
|
31
|
+
replace(key) {
|
|
32
|
+
return `tests/integration/components/${key}-test.js`;
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { migrationStrategyForComponents } from './components.js';
|
|
2
|
+
import { migrationStrategyForRouteControllers } from './route-controllers.js';
|
|
3
|
+
import { migrationStrategyForRouteRoutes } from './route-routes.js';
|
|
4
|
+
|
|
5
|
+
export function migrationStrategyForTestsFolder(projectRoot) {
|
|
6
|
+
return new Map([
|
|
7
|
+
...migrationStrategyForComponents(projectRoot),
|
|
8
|
+
...migrationStrategyForRouteControllers(projectRoot),
|
|
9
|
+
...migrationStrategyForRouteRoutes(projectRoot),
|
|
10
|
+
]);
|
|
11
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import glob from 'glob';
|
|
2
|
+
|
|
3
|
+
import { mapPaths } from '../../../utils/map-paths.js';
|
|
4
|
+
|
|
5
|
+
export function migrationStrategyForRouteControllers(projectRoot) {
|
|
6
|
+
/*
|
|
7
|
+
Case 1: Didn't pass the --pod flag, but configured { usePods: true } in .ember-cli
|
|
8
|
+
*/
|
|
9
|
+
const oldPaths1 = glob.sync(
|
|
10
|
+
'tests/unit/!(controllers)/**/controller-test.{js,ts}',
|
|
11
|
+
{
|
|
12
|
+
cwd: projectRoot,
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const newPaths1 = oldPaths1.map((oldPath) => {
|
|
17
|
+
if (oldPath.endsWith('.ts')) {
|
|
18
|
+
return mapPaths(oldPath, {
|
|
19
|
+
find: {
|
|
20
|
+
directory: 'tests/unit',
|
|
21
|
+
file: 'controller-test.ts',
|
|
22
|
+
},
|
|
23
|
+
replace(key) {
|
|
24
|
+
return `tests/unit/controllers/${key}-test.ts`;
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return mapPaths(oldPath, {
|
|
30
|
+
find: {
|
|
31
|
+
directory: 'tests/unit',
|
|
32
|
+
file: 'controller-test.js',
|
|
33
|
+
},
|
|
34
|
+
replace(key) {
|
|
35
|
+
return `tests/unit/controllers/${key}-test.js`;
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
/*
|
|
41
|
+
Case 2: Passed the --pod flag to Ember CLI
|
|
42
|
+
*/
|
|
43
|
+
const oldPaths2 = glob.sync(
|
|
44
|
+
'tests/unit/controllers/**/controller-test.{js,ts}',
|
|
45
|
+
{
|
|
46
|
+
cwd: projectRoot,
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const newPaths2 = oldPaths2.map((oldPath) => {
|
|
51
|
+
if (oldPath.endsWith('.ts')) {
|
|
52
|
+
return mapPaths(oldPath, {
|
|
53
|
+
find: {
|
|
54
|
+
directory: 'tests/unit/controllers',
|
|
55
|
+
file: 'controller-test.ts',
|
|
56
|
+
},
|
|
57
|
+
replace(key) {
|
|
58
|
+
return `tests/unit/controllers/${key}-test.ts`;
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return mapPaths(oldPath, {
|
|
64
|
+
find: {
|
|
65
|
+
directory: 'tests/unit/controllers',
|
|
66
|
+
file: 'controller-test.js',
|
|
67
|
+
},
|
|
68
|
+
replace(key) {
|
|
69
|
+
return `tests/unit/controllers/${key}-test.js`;
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return [...newPaths1, ...newPaths2];
|
|
75
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import glob from 'glob';
|
|
2
|
+
|
|
3
|
+
import { mapPaths } from '../../../utils/map-paths.js';
|
|
4
|
+
|
|
5
|
+
export function migrationStrategyForRouteRoutes(projectRoot) {
|
|
6
|
+
/*
|
|
7
|
+
Case 1: Didn't pass the --pod flag, but configured { usePods: true } in .ember-cli
|
|
8
|
+
*/
|
|
9
|
+
const oldPaths1 = glob.sync('tests/unit/!(routes)/**/route-test.{js,ts}', {
|
|
10
|
+
cwd: projectRoot,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const newPaths1 = oldPaths1.map((oldPath) => {
|
|
14
|
+
if (oldPath.endsWith('.ts')) {
|
|
15
|
+
return mapPaths(oldPath, {
|
|
16
|
+
find: {
|
|
17
|
+
directory: 'tests/unit',
|
|
18
|
+
file: 'route-test.ts',
|
|
19
|
+
},
|
|
20
|
+
replace(key) {
|
|
21
|
+
return `tests/unit/routes/${key}-test.ts`;
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return mapPaths(oldPath, {
|
|
27
|
+
find: {
|
|
28
|
+
directory: 'tests/unit',
|
|
29
|
+
file: 'route-test.js',
|
|
30
|
+
},
|
|
31
|
+
replace(key) {
|
|
32
|
+
return `tests/unit/routes/${key}-test.js`;
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
Case 2: Passed the --pod flag to Ember CLI
|
|
39
|
+
*/
|
|
40
|
+
const oldPaths2 = glob.sync('tests/unit/routes/**/route-test.{js,ts}', {
|
|
41
|
+
cwd: projectRoot,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const newPaths2 = oldPaths2.map((oldPath) => {
|
|
45
|
+
if (oldPath.endsWith('.ts')) {
|
|
46
|
+
return mapPaths(oldPath, {
|
|
47
|
+
find: {
|
|
48
|
+
directory: 'tests/unit/routes',
|
|
49
|
+
file: 'route-test.ts',
|
|
50
|
+
},
|
|
51
|
+
replace(key) {
|
|
52
|
+
return `tests/unit/routes/${key}-test.ts`;
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return mapPaths(oldPath, {
|
|
58
|
+
find: {
|
|
59
|
+
directory: 'tests/unit/routes',
|
|
60
|
+
file: 'route-test.js',
|
|
61
|
+
},
|
|
62
|
+
replace(key) {
|
|
63
|
+
return `tests/unit/routes/${key}-test.js`;
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return [...newPaths1, ...newPaths2];
|
|
69
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
export function updatePaths({ migrationStrategy, projectRoot }) {
|
|
5
|
+
migrationStrategy.forEach((newPath, oldPath) => {
|
|
6
|
+
// Read file
|
|
7
|
+
const newAbsolutePath = join(projectRoot, newPath);
|
|
8
|
+
const file = readFileSync(newAbsolutePath, 'utf8');
|
|
9
|
+
|
|
10
|
+
// Update file
|
|
11
|
+
const oldRelativePath = oldPath.replace(/^app\//, '').replace(/\.js$/, '');
|
|
12
|
+
const newRelativePath = newPath.replace(/^app\//, '').replace(/\.js$/, '');
|
|
13
|
+
|
|
14
|
+
const newFile = file.replace(new RegExp(oldRelativePath), newRelativePath);
|
|
15
|
+
writeFileSync(newAbsolutePath, newFile, 'utf8');
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function mapPaths(oldPath, { find, replace }) {
|
|
2
|
+
const { directory, file } = find;
|
|
3
|
+
|
|
4
|
+
if (!oldPath.endsWith(file)) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const key = oldPath
|
|
9
|
+
.replace(new RegExp(`^${directory}/`), '')
|
|
10
|
+
.replace(new RegExp(`/${file}$`), '');
|
|
11
|
+
|
|
12
|
+
const newPath = replace(key);
|
|
13
|
+
|
|
14
|
+
return [oldPath, newPath];
|
|
15
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
existsSync,
|
|
3
|
+
mkdirSync,
|
|
4
|
+
readdirSync,
|
|
5
|
+
renameSync,
|
|
6
|
+
rmSync,
|
|
7
|
+
} from 'node:fs';
|
|
8
|
+
import { dirname, join } from 'node:path';
|
|
9
|
+
|
|
10
|
+
export function moveFiles({ migrationStrategy, projectRoot }) {
|
|
11
|
+
migrationStrategy.forEach((newPath, oldPath) => {
|
|
12
|
+
const oldAbsolutePath = join(projectRoot, oldPath);
|
|
13
|
+
const oldDirectory = dirname(oldAbsolutePath);
|
|
14
|
+
|
|
15
|
+
const newAbsolutePath = join(projectRoot, newPath);
|
|
16
|
+
const newDirectory = dirname(newAbsolutePath);
|
|
17
|
+
|
|
18
|
+
// Move file
|
|
19
|
+
if (!existsSync(newDirectory)) {
|
|
20
|
+
mkdirSync(newDirectory, { recursive: true });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
renameSync(oldAbsolutePath, newAbsolutePath);
|
|
24
|
+
|
|
25
|
+
// Clean up directory
|
|
26
|
+
const numFilesLeft = readdirSync(oldDirectory).length;
|
|
27
|
+
|
|
28
|
+
if (numFilesLeft === 0) {
|
|
29
|
+
rmSync(oldDirectory, { recursive: true });
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|