Skip to content

Commit 23766e2

Browse files
committed
Added support for moving component classes written in TypeScript
1 parent da8cd91 commit 23766e2

File tree

5 files changed

+334
-4
lines changed

5 files changed

+334
-4
lines changed

lib/migrator.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = class Migrator {
2121

2222
findClassicComponentClasses() {
2323
const classFolderPath = path.join(this.projectRoot, 'app/components');
24-
const classFilePaths = glob.sync(`${classFolderPath}/**/*.js`);
24+
const classFilePaths = glob.sync(`${classFolderPath}/**/*.{js,ts}`);
2525

2626
return classFilePaths;
2727
}
@@ -134,11 +134,19 @@ module.exports = class Migrator {
134134
moveFile(templateFilePath, newTemplateFilePath);
135135

136136
// Build '[APP_PATH]/app/components/nested1/nested-component/index.js'
137-
const classFilePath = path.join(this.projectRoot, 'app/components', `${targetPath}.js`);
137+
const classFilePath = {
138+
js: path.join(this.projectRoot, 'app/components', `${targetPath}.js`),
139+
ts: path.join(this.projectRoot, 'app/components', `${targetPath}.ts`)
140+
};
138141

139-
if (classFilePaths.includes(classFilePath)) {
142+
if (classFilePaths.includes(classFilePath.js)) {
140143
const newClassFilePath = path.join(this.projectRoot, 'app/components', targetPath, 'index.js');
141-
moveFile(classFilePath, newClassFilePath);
144+
moveFile(classFilePath.js, newClassFilePath);
145+
146+
} else if (classFilePaths.includes(classFilePath.ts)) {
147+
const newClassFilePath = path.join(this.projectRoot, 'app/components', targetPath, 'index.ts');
148+
moveFile(classFilePath.ts, newClassFilePath);
149+
142150
}
143151
});
144152
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
module.exports = {
2+
app: {
3+
'app.js': '// app',
4+
5+
components: {
6+
// A standalone component
7+
'top-level-component.ts': '// top-level-component.ts',
8+
9+
// A nested component
10+
'parent-component.ts': '// parent-component.ts',
11+
'parent-component': {
12+
'child-component.ts': '// parent-component/child-component.ts',
13+
'child-component': {
14+
'grandchild-component.ts': '// parent-component/child-component/grandchild-component.ts'
15+
}
16+
},
17+
18+
// Another nested component
19+
nested1: {
20+
'nested-component.ts': '// nested1/nested-component.ts',
21+
nested2: {
22+
'super-nested-component.ts': '// nested1/nested2/super-nested-component.ts'
23+
}
24+
},
25+
26+
// A component with layoutName
27+
'layout-name': {
28+
'has-layout-name.ts': [
29+
'// top-level-component.ts',
30+
'Component.extend({ layoutName: "components/layout-name/layout-name-template" });'
31+
].join('\n')
32+
}
33+
},
34+
35+
templates: {
36+
'application.hbs': '{{outlet}}',
37+
38+
components: {
39+
// A standalone component
40+
'top-level-component.hbs': '{{!-- top-level-component.hbs --}}',
41+
42+
// A template-only component
43+
'template-only-component.hbs': '{{!-- template-only-component.hbs --}}',
44+
45+
// A nested component
46+
'parent-component.hbs': '{{!-- parent-component.hbs --}}',
47+
'parent-component': {
48+
'child-component.hbs': '{{!-- parent-component/child-component.hbs --}}',
49+
'child-component': {
50+
'grandchild-component.hbs': '{{!-- parent-component/child-component/grandchild-component.hbs --}}'
51+
}
52+
},
53+
54+
// Another nested component
55+
nested1: {
56+
'nested-component.hbs': '{{!-- nested1/nested-component.hbs --}}',
57+
nested2: {
58+
'super-nested-component.hbs': '{{!-- nested1/nested2/super-nested-component.hbs --}}'
59+
}
60+
},
61+
62+
// A component with layoutName
63+
'layout-name': {
64+
'layout-name-template.hbs': '{{!-- layout-name-template.hbs --}}'
65+
},
66+
67+
// A partial template
68+
'partials': {
69+
'partial-one-template.hbs': '{{!-- partial-one-template.hbs --}}',
70+
'partial-two-template.hbs': '{{!-- partial-two-template.hbs --}}',
71+
'-partial-three-template.hbs': '{{!-- partial-three-template.hbs --}}',
72+
73+
'with-partial.hbs': [
74+
'{{!-- with-partial.hbs --}}',
75+
'{{partial "components/partials/partial-one-template"}}',
76+
'{{partial "components/partials/partial-two-template"}}',
77+
'{{partial "components/partials/partial-three-template"}}'
78+
].join('\n')
79+
}
80+
}
81+
}
82+
}
83+
};
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
module.exports = {
2+
app: {
3+
'app.js': '// app',
4+
5+
components: {
6+
// A standalone component
7+
'top-level-component.hbs': '{{!-- top-level-component.hbs --}}',
8+
'top-level-component.ts': '// top-level-component.ts',
9+
10+
// A template-only component
11+
'template-only-component.hbs': '{{!-- template-only-component.hbs --}}',
12+
13+
// A nested component
14+
'parent-component.hbs': '{{!-- parent-component.hbs --}}',
15+
'parent-component.ts': '// parent-component.ts',
16+
'parent-component': {
17+
'child-component.hbs': '{{!-- parent-component/child-component.hbs --}}',
18+
'child-component.ts': '// parent-component/child-component.ts',
19+
'child-component': {
20+
'grandchild-component.hbs': '{{!-- parent-component/child-component/grandchild-component.hbs --}}',
21+
'grandchild-component.ts': '// parent-component/child-component/grandchild-component.ts'
22+
}
23+
},
24+
25+
// Another nested component
26+
nested1: {
27+
'nested-component.hbs': '{{!-- nested1/nested-component.hbs --}}',
28+
'nested-component.ts': '// nested1/nested-component.ts',
29+
nested2: {
30+
'super-nested-component.hbs': '{{!-- nested1/nested2/super-nested-component.hbs --}}',
31+
'super-nested-component.ts': '// nested1/nested2/super-nested-component.ts'
32+
}
33+
},
34+
35+
// A component with layoutName
36+
'layout-name': {
37+
'has-layout-name.ts': [
38+
'// top-level-component.ts',
39+
'Component.extend({ layoutName: "components/layout-name/layout-name-template" });'
40+
].join('\n')
41+
},
42+
43+
// A component with partial
44+
'partials': {
45+
'with-partial.hbs': [
46+
'{{!-- with-partial.hbs --}}',
47+
'{{partial "components/partials/partial-one-template"}}',
48+
'{{partial "components/partials/partial-two-template"}}',
49+
'{{partial "components/partials/partial-three-template"}}'
50+
].join('\n')
51+
}
52+
},
53+
54+
templates: {
55+
'application.hbs': '{{outlet}}',
56+
57+
components: {
58+
// A component with layoutName
59+
'layout-name': {
60+
'layout-name-template.hbs': '{{!-- layout-name-template.hbs --}}'
61+
},
62+
63+
// A partial template
64+
'partials': {
65+
'partial-one-template.hbs': '{{!-- partial-one-template.hbs --}}',
66+
'partial-two-template.hbs': '{{!-- partial-two-template.hbs --}}',
67+
'-partial-three-template.hbs': '{{!-- partial-three-template.hbs --}}'
68+
}
69+
}
70+
}
71+
},
72+
};
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
module.exports = {
2+
app: {
3+
'app.js': '// app',
4+
5+
components: {
6+
// A standalone component
7+
'top-level-component.ts': '// top-level-component.ts',
8+
9+
// A nested component
10+
'parent-component.ts': '// parent-component.ts',
11+
'parent-component': {
12+
'child-component.ts': '// parent-component/child-component.ts',
13+
'child-component': {
14+
'grandchild-component.ts': '// parent-component/child-component/grandchild-component.ts'
15+
}
16+
},
17+
18+
// Another nested component
19+
nested1: {
20+
'nested-component.ts': '// nested1/nested-component.ts',
21+
nested2: {
22+
'super-nested-component.ts': '// nested1/nested2/super-nested-component.ts'
23+
}
24+
},
25+
26+
// A component with layoutName
27+
'layout-name': {
28+
'has-layout-name.ts': [
29+
'// top-level-component.ts',
30+
'Component.extend({ layoutName: "components/layout-name/layout-name-template" });'
31+
].join('\n')
32+
}
33+
},
34+
35+
templates: {
36+
'application.hbs': '{{outlet}}',
37+
38+
components: {
39+
// A standalone component
40+
'top-level-component.hbs': '{{!-- top-level-component.hbs --}}',
41+
42+
// A template-only component
43+
'template-only-component.hbs': '{{!-- template-only-component.hbs --}}',
44+
45+
// A nested component
46+
'parent-component.hbs': '{{!-- parent-component.hbs --}}',
47+
'parent-component': {
48+
'child-component.hbs': '{{!-- parent-component/child-component.hbs --}}',
49+
'child-component': {
50+
'grandchild-component.hbs': '{{!-- parent-component/child-component/grandchild-component.hbs --}}'
51+
}
52+
},
53+
54+
// Another nested component
55+
nested1: {
56+
'nested-component.hbs': '{{!-- nested1/nested-component.hbs --}}',
57+
nested2: {
58+
'super-nested-component.hbs': '{{!-- nested1/nested2/super-nested-component.hbs --}}'
59+
}
60+
},
61+
62+
// A component with layoutName
63+
'layout-name': {
64+
'layout-name-template.hbs': '{{!-- layout-name-template.hbs --}}'
65+
},
66+
67+
// A partial template
68+
'partials': {
69+
'partial-one-template.hbs': '{{!-- partial-one-template.hbs --}}',
70+
'partial-two-template.hbs': '{{!-- partial-two-template.hbs --}}',
71+
'-partial-three-template.hbs': '{{!-- partial-three-template.hbs --}}',
72+
73+
'with-partial.hbs': [
74+
'{{!-- with-partial.hbs --}}',
75+
'{{partial "components/partials/partial-one-template"}}',
76+
'{{partial "components/partials/partial-two-template"}}',
77+
'{{partial "components/partials/partial-three-template"}}'
78+
].join('\n')
79+
}
80+
}
81+
}
82+
}
83+
};
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
module.exports = {
2+
app: {
3+
'app.js': '// app',
4+
5+
components: {
6+
// A standalone component
7+
'top-level-component': {
8+
'index.hbs': '{{!-- top-level-component.hbs --}}',
9+
'index.ts': '// top-level-component.ts',
10+
},
11+
12+
// A template-only component
13+
'template-only-component': {
14+
'index.hbs': '{{!-- template-only-component.hbs --}}'
15+
},
16+
17+
// A nested component
18+
'parent-component': {
19+
'index.hbs': '{{!-- parent-component.hbs --}}',
20+
'index.ts': '// parent-component.ts',
21+
'child-component': {
22+
'index.hbs': '{{!-- parent-component/child-component.hbs --}}',
23+
'index.ts': '// parent-component/child-component.ts',
24+
'grandchild-component': {
25+
'index.hbs': '{{!-- parent-component/child-component/grandchild-component.hbs --}}',
26+
'index.ts': '// parent-component/child-component/grandchild-component.ts'
27+
}
28+
}
29+
},
30+
31+
// Another nested component
32+
nested1: {
33+
'nested-component': {
34+
'index.hbs': '{{!-- nested1/nested-component.hbs --}}',
35+
'index.ts': '// nested1/nested-component.ts',
36+
},
37+
nested2: {
38+
'super-nested-component': {
39+
'index.hbs': '{{!-- nested1/nested2/super-nested-component.hbs --}}',
40+
'index.ts': '// nested1/nested2/super-nested-component.ts'
41+
}
42+
}
43+
},
44+
45+
// A component with layoutName
46+
'layout-name': {
47+
'has-layout-name.ts': [
48+
'// top-level-component.ts',
49+
'Component.extend({ layoutName: "components/layout-name/layout-name-template" });'
50+
].join('\n')
51+
},
52+
53+
// A component with partial
54+
'partials': {
55+
'with-partial': {
56+
'index.hbs': [
57+
'{{!-- with-partial.hbs --}}',
58+
'{{partial "components/partials/partial-one-template"}}',
59+
'{{partial "components/partials/partial-two-template"}}',
60+
'{{partial "components/partials/partial-three-template"}}'
61+
].join('\n')
62+
}
63+
}
64+
},
65+
66+
templates: {
67+
'application.hbs': '{{outlet}}',
68+
69+
components: {
70+
// A component with layoutName
71+
'layout-name': {
72+
'layout-name-template.hbs': '{{!-- layout-name-template.hbs --}}'
73+
},
74+
75+
// A partial template
76+
'partials': {
77+
'partial-one-template.hbs': '{{!-- partial-one-template.hbs --}}',
78+
'partial-two-template.hbs': '{{!-- partial-two-template.hbs --}}',
79+
'-partial-three-template.hbs': '{{!-- partial-three-template.hbs --}}'
80+
}
81+
}
82+
}
83+
},
84+
};

0 commit comments

Comments
 (0)