ember-codemod-remove-ember-css-modules 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.
Files changed (48) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +222 -0
  3. package/bin/ember-codemod-remove-ember-css-modules.js +34 -0
  4. package/package.json +58 -0
  5. package/src/blueprints/ember-cli/component/javascript.js +7 -0
  6. package/src/blueprints/ember-cli/component/typescript.ts +26 -0
  7. package/src/blueprints/ember-cli/controller/javascript.js +7 -0
  8. package/src/blueprints/ember-cli/controller/typescript.ts +7 -0
  9. package/src/index.js +5 -0
  10. package/src/migration/ember-app/index.js +37 -0
  11. package/src/migration/ember-app/steps/analyze-app.js +155 -0
  12. package/src/migration/ember-app/steps/create-options.js +44 -0
  13. package/src/migration/ember-app/steps/import-styles-in-components.js +43 -0
  14. package/src/migration/ember-app/steps/import-styles-in-routes.js +39 -0
  15. package/src/migration/ember-app/steps/index.js +9 -0
  16. package/src/migration/ember-app/steps/move-stylesheets.js +51 -0
  17. package/src/migration/ember-app/steps/shared/import-styles.js +211 -0
  18. package/src/migration/ember-app/steps/shared/index.js +2 -0
  19. package/src/migration/ember-app/steps/shared/update-templates.js +437 -0
  20. package/src/migration/ember-app/steps/update-app-app-js.js +64 -0
  21. package/src/migration/ember-app/steps/update-component-templates.js +28 -0
  22. package/src/migration/ember-app/steps/update-package-json.js +58 -0
  23. package/src/migration/ember-app/steps/update-route-templates.js +22 -0
  24. package/src/migration/index.js +1 -0
  25. package/src/utils/abstract-syntax-tree/handlebars.js +20 -0
  26. package/src/utils/abstract-syntax-tree/javascript.js +109 -0
  27. package/src/utils/abstract-syntax-tree.js +2 -0
  28. package/src/utils/blueprints/blueprint-root.js +13 -0
  29. package/src/utils/blueprints/decide-version.js +25 -0
  30. package/src/utils/blueprints/process-template.js +12 -0
  31. package/src/utils/blueprints.js +3 -0
  32. package/src/utils/files/copy-files.js +19 -0
  33. package/src/utils/files/create-files.js +17 -0
  34. package/src/utils/files/find-files.js +28 -0
  35. package/src/utils/files/map-file-paths.js +25 -0
  36. package/src/utils/files/move-files.js +22 -0
  37. package/src/utils/files/remove-directory-if-empty.js +19 -0
  38. package/src/utils/files/remove-files.js +15 -0
  39. package/src/utils/files.js +7 -0
  40. package/src/utils/json/convert-to-map.js +3 -0
  41. package/src/utils/json/convert-to-object.js +5 -0
  42. package/src/utils/json.js +2 -0
  43. package/src/utils/string/ember-cli-string-utils/camelize.js +12 -0
  44. package/src/utils/string/ember-cli-string-utils/classify.js +14 -0
  45. package/src/utils/string/entity-name/classify.js +6 -0
  46. package/src/utils/string/entity-name/double-colonize.js +10 -0
  47. package/src/utils/string/entity-name/parse.js +19 -0
  48. package/src/utils/string.js +5 -0
package/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Isaac J. Lee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,222 @@
1
+ [![This project uses GitHub Actions for continuous integration.](https://github.com/ijlee2/embroider-css-modules/actions/workflows/ci.yml/badge.svg)](https://github.com/ijlee2/embroider-css-modules/actions/workflows/ci.yml)
2
+
3
+ # ember-codemod-remove-ember-css-modules
4
+
5
+ _Codemod to replace `ember-css-modules` with `embroider-css-modules`_
6
+
7
+
8
+ ## Features
9
+
10
+ - Preserves your code whenever possible
11
+ - Supports [`glint`](https://typed-ember.gitbook.io/glint/)
12
+ - Focuses on maintainability and extensibility
13
+
14
+
15
+ ## Usage
16
+
17
+ You can check [`ember-container-query`](https://github.com/ijlee2/ember-container-query/pull/167) as a reference.
18
+
19
+ Step 1. Quickly migrate to [`embroider-css-modules`](https://github.com/ijlee2/embroider-css-modules).<sup>1</sup>
20
+
21
+ ```sh
22
+ cd <your/project/path>
23
+ npx ember-codemod-remove-ember-css-modules <arguments>
24
+ ```
25
+
26
+ Step 2. Review the project.
27
+
28
+ - [x] Update the configuration files.<sup>2</sup>
29
+ - [x] Remove the remaining instances of `local-class` attributes and `{{local-class}}` helpers from `ember-css-modules`.
30
+ - [x] Confirm that you can run all scripts in `package.json`.
31
+
32
+ Step 3. Celebrate.
33
+
34
+ <sup>1. Some prerequisites for running `ember-codemod-remove-ember-css-modules`: First, migrate to the Octane layout (flat or nested). You can leverage codemods for [classic](https://github.com/ember-codemods/ember-component-template-colocation-migrator) and [pod](https://github.com/ijlee2/ember-codemod-pod-to-octane) layouts. Second, [refactor code](#how-to-refactor-code) to help the codemod update templates correctly.</sup>
35
+
36
+ <sup>2. Files such as `.eslintrc.js`, `.prettierrc.js`, `.stylelintrc.js`, `.template-lintrc.js`, `ember-cli-build.js`, `package.json`, `postcss.config.js`, `tsconfig.json`, etc.</sup>
37
+
38
+
39
+ ### Arguments
40
+
41
+ <details>
42
+ <summary>Optional: Specify the component structure</summary>
43
+
44
+ By default, an Octane projects has the flat component structure. Pass `--component-structure` to indicate otherwise.
45
+
46
+ ```sh
47
+ npx ember-codemod-remove-ember-css-modules --component-structure="nested"
48
+ ```
49
+
50
+ </details>
51
+
52
+ <details>
53
+ <summary>Optional: Specify the project root</summary>
54
+
55
+ Pass `--root` to run the codemod on a project somewhere else (i.e. not in the current directory).
56
+
57
+ ```sh
58
+ npx ember-codemod-remove-ember-css-modules --root=<your/project/path>
59
+ ```
60
+
61
+ </details>
62
+
63
+
64
+ ### Limitations
65
+
66
+ The codemod is designed to cover typical uses of `ember-css-modules`. It is not designed to cover one-off cases.
67
+
68
+ To better meet your needs, consider cloning the repo and running the codemod locally.
69
+
70
+ ```sh
71
+ cd <your/cloned/repo>
72
+ ./bin/ember-codemod-remove-ember-css-modules.js --root=<your/project/path>
73
+ ```
74
+
75
+
76
+ ## How to refactor code
77
+
78
+ ### Remove code inheritance
79
+
80
+ `ember-css-modules` allows composing (really, inheriting) CSS code in two ways:
81
+
82
+ - `{{local-class ... from="..."}}` in `*.hbs`
83
+ - `composes: ... from '...';` in `*.css`
84
+
85
+ Code inheritance can be signs of premature abstraction and incorrect component design. Ideally, you might duplicate code, then refactor it.
86
+
87
+ If short on time, you can import the relevant `styles` object in the backing class.
88
+
89
+ <details>
90
+
91
+ <summary>Before, with <code>ember-css-modules</code></summary>
92
+
93
+ Case 1:
94
+
95
+ ```hbs
96
+ {{! app/components/ui/form/textarea.hbs }}
97
+ <textarea
98
+ class={{local-class "input" from "app/components/ui/form/input.css"}}
99
+ />
100
+ ```
101
+
102
+ Case 2:
103
+
104
+ ```css
105
+ /* app/components/ui/form/textarea.css */
106
+ .textarea {
107
+ composes: input from "app/components/ui/form/input.css";
108
+ }
109
+ ```
110
+
111
+ ```hbs
112
+ {{! app/components/ui/form/textarea.hbs }}
113
+ <textarea
114
+ local-class="textarea"
115
+ />
116
+ ```
117
+
118
+ </details>
119
+
120
+ <details>
121
+
122
+ <summary>After, with <code>embroider-css-modules</code></summary>
123
+
124
+ ```ts
125
+ /* app/components/ui/form/textarea.ts */
126
+ import Component from '@glimmer/component';
127
+
128
+ import inputStyles from './input.css';
129
+ import styles from './textarea.css';
130
+
131
+ export default class UiFormTextareaComponent extends Component {
132
+ inputStyles = inputStyles;
133
+ styles = styles;
134
+ }
135
+ ```
136
+
137
+ ```hbs
138
+ {{! app/components/ui/form/textarea.hbs }}
139
+ <textarea
140
+ class={{this.inputStyles.input}}
141
+ />
142
+ ```
143
+
144
+ </details>
145
+
146
+
147
+ ### Remove complex string concatenations
148
+
149
+ In `ember-css-modules`, a string can represent multiple local class names via concatenation. In `embroider-css-modules`, each string represents exactly one.
150
+
151
+ <details>
152
+
153
+ <summary>Before, with <code>ember-css-modules</code></summary>
154
+
155
+ ```hbs
156
+ {{! app/components/ui/form/textarea.hbs }}
157
+ <textarea
158
+ local-class="
159
+ textarea
160
+ {{if (or @isDisabled @isReadOnly) 'is-disabled'}}
161
+ "
162
+ />
163
+ ```
164
+
165
+ </details>
166
+
167
+ <details>
168
+
169
+ <summary>After, with <code>embroider-css-modules</code></summary>
170
+
171
+ ```hbs
172
+ {{! app/components/ui/form/textarea.hbs }}
173
+ <textarea
174
+ class={{local-class
175
+ this.styles
176
+ "textarea"
177
+ (if (or @isDisabled @isReadOnly) "is-disabled")
178
+ }}
179
+ />
180
+ ```
181
+
182
+ </details>
183
+
184
+ The codemod is not responsible for fixing complex expressions. Refactor templates to provide hints. For example, remove nested conditionals (apply them outside the HTML element) and use the `{{concat}}` helper to group substrings.
185
+
186
+ <details>
187
+
188
+ <summary>Before refactor, with <code>ember-css-modules</code></summary>
189
+
190
+ ```hbs
191
+ {{! app/components/ui/form/phone.hbs }}
192
+ <input
193
+ local-class="input flag-{{@country}}"
194
+ type="tel"
195
+ />
196
+ ```
197
+
198
+ </details>
199
+
200
+ <details>
201
+
202
+ <summary>After refactor, with <code>ember-css-modules</code></summary>
203
+
204
+ ```hbs
205
+ {{! app/components/ui/form/phone.hbs }}
206
+ <input
207
+ local-class="input {{concat 'flag-' @country}}"
208
+ type="tel"
209
+ />
210
+ ```
211
+
212
+ </details>
213
+
214
+
215
+ ## Compatibility
216
+
217
+ * Node.js v16 or above
218
+
219
+
220
+ ## License
221
+
222
+ This project is licensed under the [MIT License](LICENSE.md).
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ import yargs from 'yargs';
5
+ import { hideBin } from 'yargs/helpers';
6
+
7
+ import { removeEmberCssModules } from '../src/index.js';
8
+
9
+ // Provide a title to the process in `ps`
10
+ process.title = 'ember-codemod-remove-ember-css-modules';
11
+
12
+ // Set codemod options
13
+ const { argv } = yargs(hideBin(process.argv))
14
+ .option('component-structure', {
15
+ choices: ['flat', 'nested'],
16
+ default: 'flat',
17
+ describe: 'Component structure (how your components are colocated)',
18
+ type: 'string',
19
+ })
20
+ .option('root', {
21
+ describe: 'Location of your Ember project',
22
+ type: 'string',
23
+ });
24
+
25
+ function castEmptyStringToUndefined(string) {
26
+ return string === '' ? undefined : string;
27
+ }
28
+
29
+ const codemodOptions = {
30
+ componentStructure: castEmptyStringToUndefined(argv['component-structure']),
31
+ projectRoot: argv['root'] ?? process.cwd(),
32
+ };
33
+
34
+ removeEmberCssModules(codemodOptions);
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "ember-codemod-remove-ember-css-modules",
3
+ "version": "0.1.0",
4
+ "description": "Codemod to replace ember-css-modules with embroider-css-modules",
5
+ "keywords": [
6
+ "codemod",
7
+ "css-modules",
8
+ "ember-codemod",
9
+ "ember-css-modules",
10
+ "emberjs",
11
+ "embroider-css-modules"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/ijlee2/embroider-css-modules.git"
16
+ },
17
+ "license": "MIT",
18
+ "author": "Isaac J. Lee",
19
+ "main": "src/index.js",
20
+ "type": "module",
21
+ "bin": "./bin/ember-codemod-remove-ember-css-modules.js",
22
+ "files": [
23
+ "bin/",
24
+ "src/"
25
+ ],
26
+ "directories": {
27
+ "test": "tests"
28
+ },
29
+ "dependencies": {
30
+ "@babel/parser": "^7.21.4",
31
+ "ember-template-recast": "^6.1.4",
32
+ "glob": "^10.0.0",
33
+ "lodash.template": "^4.5.0",
34
+ "recast": "^0.23.1",
35
+ "yargs": "^17.7.1"
36
+ },
37
+ "devDependencies": {
38
+ "@babel/core": "^7.21.4",
39
+ "@babel/eslint-parser": "^7.21.3",
40
+ "@sondr3/minitest": "^0.1.1",
41
+ "eslint": "^8.38.0",
42
+ "eslint-config-prettier": "^8.8.0",
43
+ "eslint-plugin-import": "^2.27.5",
44
+ "eslint-plugin-n": "^15.7.0",
45
+ "eslint-plugin-prettier": "^4.2.1",
46
+ "eslint-plugin-simple-import-sort": "^10.0.0",
47
+ "fixturify": "^3.0.0",
48
+ "prettier": "^2.8.7"
49
+ },
50
+ "engines": {
51
+ "node": "16.* || >= 18"
52
+ },
53
+ "scripts": {
54
+ "lint": "eslint . --cache",
55
+ "lint:fix": "eslint . --fix",
56
+ "test": "mt tests --quiet"
57
+ }
58
+ }
@@ -0,0 +1,7 @@
1
+ import Component from '@glimmer/component';
2
+
3
+ <% if (options.componentStructure === 'nested') { %>import <%= options.__styles__ %> from './index.css';<% } else { %>import <%= options.__styles__ %> from './<%= entity.fileName %>.css';<% } %>
4
+
5
+ export default class <%= entity.classifiedName %>Component extends Component {
6
+ <%= options.__styles__ %> = <%= options.__styles__ %>;
7
+ }
@@ -0,0 +1,26 @@
1
+ import Component from '@glimmer/component';
2
+
3
+ <% if (options.componentStructure === 'nested') { %>import <%= options.__styles__ %> from './index.css';<% } else { %>import <%= options.__styles__ %> from './<%= entity.fileName %>.css';<% } %>
4
+
5
+ interface <%= entity.classifiedName %>Signature {
6
+ // The arguments accepted by the component
7
+ Args: {};
8
+ // Any blocks yielded by the component
9
+ Blocks: {
10
+ default: [];
11
+ };
12
+ // The element to which `...attributes` is applied in the component template
13
+ Element: null;
14
+ }
15
+
16
+ export default class <%= entity.classifiedName %>Component extends Component<<%= entity.classifiedName %>Signature> {
17
+ <%= options.__styles__ %> = <%= options.__styles__ %>;
18
+ }
19
+ <% if (options.project.hasGlint) { %>
20
+ declare module '@glint/environment-ember-loose/registry' {
21
+ export default interface Registry {
22
+ '<%= entity.doubleColonizedName %>': typeof <%= entity.classifiedName %>Component;
23
+ '<%= entity.name %>': typeof <%= entity.classifiedName %>Component;
24
+ }
25
+ }
26
+ <% } %>
@@ -0,0 +1,7 @@
1
+ import Controller from '@ember/controller';
2
+
3
+ import <%= options.__styles__ %> from './<%= entity.fileName %>.css';
4
+
5
+ export default class <%= entity.classifiedName %>Controller extends Controller {
6
+ <%= options.__styles__ %> = <%= options.__styles__ %>;
7
+ }
@@ -0,0 +1,7 @@
1
+ import Controller from '@ember/controller';
2
+
3
+ import <%= options.__styles__ %> from './<%= entity.fileName %>.css';
4
+
5
+ export default class <%= entity.classifiedName %>Controller extends Controller {
6
+ <%= options.__styles__ %> = <%= options.__styles__ %>;
7
+ }
package/src/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { migrateEmberApp } from './migration/index.js';
2
+
3
+ export function removeEmberCssModules(codemodOptions) {
4
+ migrateEmberApp(codemodOptions);
5
+ }
@@ -0,0 +1,37 @@
1
+ import {
2
+ analyzeApp,
3
+ createOptions,
4
+ importStylesInComponents,
5
+ importStylesInRoutes,
6
+ moveStylesheets,
7
+ updateAppAppJs,
8
+ updateComponentTemplates,
9
+ updatePackageJson,
10
+ updateRouteTemplates,
11
+ } from './steps/index.js';
12
+
13
+ export function migrateEmberApp(codemodOptions) {
14
+ const options = createOptions(codemodOptions);
15
+ const { hasEmberCssModules } = options.project;
16
+
17
+ // Guarantee idempotency
18
+ if (!hasEmberCssModules) {
19
+ return;
20
+ }
21
+
22
+ // Prepare for migration
23
+ const context = analyzeApp(options);
24
+
25
+ // Import styles in classes
26
+ moveStylesheets(options);
27
+ importStylesInComponents(context, options);
28
+ importStylesInRoutes(context, options);
29
+
30
+ // Update templates
31
+ updateComponentTemplates(context, options);
32
+ updateRouteTemplates(context, options);
33
+
34
+ // Fine-tune individual files
35
+ updateAppAppJs(options);
36
+ updatePackageJson(options);
37
+ }
@@ -0,0 +1,155 @@
1
+ import { join, parse } from 'node:path';
2
+
3
+ import { findFiles, renameDirectory } from '../../../utils/files.js';
4
+
5
+ function findAndRenameFiles(findOptions, replaceOptions) {
6
+ const { globPattern, ignoreList, projectRoot } = findOptions;
7
+ const { from, to } = replaceOptions;
8
+
9
+ const filePaths = findFiles(globPattern, {
10
+ cwd: projectRoot,
11
+ ignoreList,
12
+ });
13
+
14
+ return filePaths.map((filePath) => {
15
+ return renameDirectory(filePath, { from, to });
16
+ });
17
+ }
18
+
19
+ function analyzeEntities({
20
+ classFilePaths,
21
+ stylesheetFilePaths,
22
+ templateFilePaths,
23
+ }) {
24
+ const filePaths = [
25
+ ...classFilePaths,
26
+ ...stylesheetFilePaths,
27
+ ...templateFilePaths,
28
+ ].sort();
29
+
30
+ const entities = new Map();
31
+
32
+ filePaths.forEach((filePath) => {
33
+ const { dir, ext, name } = parse(filePath);
34
+ const entityName = join(dir, name);
35
+
36
+ if (entities.has(entityName)) {
37
+ entities.get(entityName).add(ext);
38
+
39
+ return;
40
+ }
41
+
42
+ entities.set(entityName, new Set([ext]));
43
+ });
44
+
45
+ return entities;
46
+ }
47
+
48
+ function analyzeComponents(options) {
49
+ const { componentStructure, projectRoot } = options;
50
+
51
+ const classFilePaths = findAndRenameFiles(
52
+ {
53
+ globPattern: 'app/components/**/*.{js,ts}',
54
+ ignoreList: ['app/components/**/*.d.ts'],
55
+ projectRoot,
56
+ },
57
+ {
58
+ from: 'app/components',
59
+ to: '',
60
+ }
61
+ );
62
+
63
+ const stylesheetFilePaths = findAndRenameFiles(
64
+ {
65
+ globPattern: 'app/components/**/*.css',
66
+ projectRoot,
67
+ },
68
+ {
69
+ from: 'app/components',
70
+ to: '',
71
+ }
72
+ );
73
+
74
+ const templateFilePaths = findAndRenameFiles(
75
+ {
76
+ globPattern: 'app/components/**/*.hbs',
77
+ projectRoot,
78
+ },
79
+ {
80
+ from: 'app/components',
81
+ to: '',
82
+ }
83
+ );
84
+
85
+ const entities = analyzeEntities({
86
+ classFilePaths,
87
+ stylesheetFilePaths,
88
+ templateFilePaths,
89
+ });
90
+
91
+ if (componentStructure === 'nested') {
92
+ return new Map(
93
+ [...entities.entries()].map(([entityName, extensions]) => {
94
+ const newEntityName = entityName.replace(/\/index$/, '');
95
+
96
+ return [newEntityName, extensions];
97
+ })
98
+ );
99
+ }
100
+
101
+ return entities;
102
+ }
103
+
104
+ function analyzeRoutes(options) {
105
+ const { projectRoot } = options;
106
+
107
+ const classFilePaths = findAndRenameFiles(
108
+ {
109
+ globPattern: 'app/controllers/**/*.{js,ts}',
110
+ ignoreList: ['app/controllers/**/*.d.ts'],
111
+ projectRoot,
112
+ },
113
+ {
114
+ from: 'app/controllers',
115
+ to: '',
116
+ }
117
+ );
118
+
119
+ const stylesheetFilePaths = findAndRenameFiles(
120
+ {
121
+ globPattern: 'app/styles/**/*.css',
122
+ ignoreList: ['app/styles/app.css'],
123
+ projectRoot,
124
+ },
125
+ {
126
+ from: 'app/styles',
127
+ to: '',
128
+ }
129
+ );
130
+
131
+ const templateFilePaths = findAndRenameFiles(
132
+ {
133
+ globPattern: 'app/templates/**/*.hbs',
134
+ ignoreList: ['app/templates/components/**/*'],
135
+ projectRoot,
136
+ },
137
+ {
138
+ from: 'app/templates',
139
+ to: '',
140
+ }
141
+ );
142
+
143
+ return analyzeEntities({
144
+ classFilePaths,
145
+ stylesheetFilePaths,
146
+ templateFilePaths,
147
+ });
148
+ }
149
+
150
+ export function analyzeApp(options) {
151
+ return {
152
+ components: analyzeComponents(options),
153
+ routes: analyzeRoutes(options),
154
+ };
155
+ }
@@ -0,0 +1,44 @@
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 { dependencies, devDependencies } = JSON.parse(packageJsonFile);
14
+
15
+ const projectDependencies = new Map([
16
+ ...Object.entries(dependencies ?? {}),
17
+ ...Object.entries(devDependencies ?? {}),
18
+ ]);
19
+
20
+ return {
21
+ dependencies: projectDependencies,
22
+ hasEmberCssModules: projectDependencies.has('ember-css-modules'),
23
+ hasGlint: projectDependencies.has('@glint/core'),
24
+ hasTypeScript: projectDependencies.has('typescript'),
25
+ };
26
+ } catch (e) {
27
+ throw new SyntaxError(
28
+ `ERROR: package.json is missing or is not valid. (${e.message})\n`
29
+ );
30
+ }
31
+ }
32
+
33
+ export function createOptions(codemodOptions) {
34
+ const project = analyzePackageJson(codemodOptions);
35
+
36
+ const options = {
37
+ __styles__: 'styles',
38
+ componentStructure: codemodOptions.componentStructure,
39
+ project,
40
+ projectRoot: codemodOptions.projectRoot,
41
+ };
42
+
43
+ return options;
44
+ }
@@ -0,0 +1,43 @@
1
+ import { join } from 'node:path';
2
+
3
+ import { importStyles } from './shared/index.js';
4
+
5
+ function getBlueprintFilePaths(options) {
6
+ const { project } = options;
7
+
8
+ if (project.hasTypeScript) {
9
+ return ['ember-cli/component/typescript.ts'];
10
+ }
11
+
12
+ return ['ember-cli/component/javascript.js'];
13
+ }
14
+
15
+ function getFilePath(options) {
16
+ const { componentStructure, project } = options;
17
+
18
+ return function (entityName) {
19
+ let filePath = join('app/components', entityName);
20
+
21
+ if (componentStructure === 'nested') {
22
+ filePath += '/index';
23
+ }
24
+
25
+ if (project.hasTypeScript) {
26
+ filePath += '.ts';
27
+ } else {
28
+ filePath += '.js';
29
+ }
30
+
31
+ return filePath;
32
+ };
33
+ }
34
+
35
+ export function importStylesInComponents(context, options) {
36
+ const customizations = {
37
+ blueprintFilePaths: getBlueprintFilePaths(options),
38
+ entities: context.components,
39
+ getFilePath: getFilePath(options),
40
+ };
41
+
42
+ importStyles(customizations, options);
43
+ }