ember-codemod-remove-global-styles 0.6.0 → 0.6.2
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/README.md +3 -3
- package/dist/src/steps/update-project/update-classes.js +10 -4
- package/dist/src/steps/update-project/update-templates.js +10 -4
- package/dist/src/utils/css/get-class-to-styles.js +2 -1
- package/dist/src/utils/update-project/update-class.js +29 -13
- package/dist/src/utils/update-project/update-template.js +28 -6
- package/package.json +10 -13
package/README.md
CHANGED
|
@@ -68,13 +68,13 @@ pnpx ember-codemod-remove-global-styles --convert routes
|
|
|
68
68
|
By default, the codemod considers all files and folders for components and routes. Pass `--folder` to limit the search to 1 folder. (You may use glob patterns to specify multiple folders.)
|
|
69
69
|
|
|
70
70
|
```sh
|
|
71
|
-
# `ui` folder only
|
|
71
|
+
# `ui` folder only (search `app/{components,templates}/ui`)
|
|
72
72
|
pnpx ember-codemod-remove-global-styles --folder ui
|
|
73
73
|
|
|
74
|
-
# `ui/form` folder only
|
|
74
|
+
# `ui/form` folder only (search `app/{components,templates}/ui/form`)
|
|
75
75
|
pnpx ember-codemod-remove-global-styles --folder ui/form
|
|
76
76
|
|
|
77
|
-
# `route1` and `route2` folders only
|
|
77
|
+
# `route1` and `route2` folders only (search `app/templates/{route1,route2}`)
|
|
78
78
|
pnpx ember-codemod-remove-global-styles --convert routes --folder "{route1,route2}"
|
|
79
79
|
```
|
|
80
80
|
|
|
@@ -3,12 +3,18 @@ import { updateClass } from '../../utils/update-project/index.js';
|
|
|
3
3
|
export function updateClasses(project, options) {
|
|
4
4
|
const fileMap = new Map();
|
|
5
5
|
project.components.forEach((_data, templateFilePath) => {
|
|
6
|
-
const {
|
|
7
|
-
|
|
6
|
+
const { output, status } = updateClass(templateFilePath, options);
|
|
7
|
+
if (status === 'error') {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
fileMap.set(output.classFilePath, output.classFile);
|
|
8
11
|
});
|
|
9
12
|
project.routes.forEach((_data, templateFilePath) => {
|
|
10
|
-
const {
|
|
11
|
-
|
|
13
|
+
const { output, status } = updateClass(templateFilePath, options);
|
|
14
|
+
if (status === 'error') {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
fileMap.set(output.classFilePath, output.classFile);
|
|
12
18
|
});
|
|
13
19
|
createFiles(fileMap, options);
|
|
14
20
|
}
|
|
@@ -3,12 +3,18 @@ import { updateTemplate } from '../../utils/update-project/index.js';
|
|
|
3
3
|
export function updateTemplates(project, options) {
|
|
4
4
|
const fileMap = new Map();
|
|
5
5
|
project.components.forEach((_data, templateFilePath) => {
|
|
6
|
-
const
|
|
7
|
-
|
|
6
|
+
const { output, status } = updateTemplate(templateFilePath, options);
|
|
7
|
+
if (status === 'error') {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
fileMap.set(templateFilePath, output.templateFile);
|
|
8
11
|
});
|
|
9
12
|
project.routes.forEach((_data, templateFilePath) => {
|
|
10
|
-
const
|
|
11
|
-
|
|
13
|
+
const { output, status } = updateTemplate(templateFilePath, options);
|
|
14
|
+
if (status === 'error') {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
fileMap.set(templateFilePath, output.templateFile);
|
|
12
18
|
});
|
|
13
19
|
createFiles(fileMap, options);
|
|
14
20
|
}
|
|
@@ -31,6 +31,8 @@ export function getClassToStyles(file) {
|
|
|
31
31
|
const plugins = [
|
|
32
32
|
{
|
|
33
33
|
postcssPlugin: 'postcss-get-class-to-styles',
|
|
34
|
+
// @ts-expect-error: Incorrect type
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
34
36
|
prepare() {
|
|
35
37
|
return {
|
|
36
38
|
Rule: processRule,
|
|
@@ -38,7 +40,6 @@ export function getClassToStyles(file) {
|
|
|
38
40
|
},
|
|
39
41
|
},
|
|
40
42
|
];
|
|
41
|
-
// @ts-expect-error: Incorrect type
|
|
42
43
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
43
44
|
postcss(plugins).process(file).css;
|
|
44
45
|
return classToStyles;
|
|
@@ -10,20 +10,36 @@ export function updateClass(templateFilePath, options) {
|
|
|
10
10
|
isTemplateTag: ext === '.gjs' || ext === '.gts',
|
|
11
11
|
isTypeScript: ext === '.gts' || ext === '.ts',
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
try {
|
|
14
|
+
if (data.isTemplateTag) {
|
|
15
|
+
classFile = updateJavaScript(classFile, (code) => {
|
|
16
|
+
return importStylesheet(code, data);
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
output: {
|
|
20
|
+
classFile,
|
|
21
|
+
classFilePath,
|
|
22
|
+
},
|
|
23
|
+
status: 'success',
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
classFile = replaceTemplateOnlyComponent(classFile, data);
|
|
27
|
+
classFile = importStylesheet(classFile, data);
|
|
28
|
+
classFile = addStylesToClass(classFile, data);
|
|
17
29
|
return {
|
|
18
|
-
|
|
19
|
-
|
|
30
|
+
output: {
|
|
31
|
+
classFile,
|
|
32
|
+
classFilePath,
|
|
33
|
+
},
|
|
34
|
+
status: 'success',
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.log(`WARNING: ${classFilePath} could not be updated.`);
|
|
39
|
+
console.log(error.message);
|
|
40
|
+
return {
|
|
41
|
+
output: undefined,
|
|
42
|
+
status: 'error',
|
|
20
43
|
};
|
|
21
44
|
}
|
|
22
|
-
classFile = replaceTemplateOnlyComponent(classFile, data);
|
|
23
|
-
classFile = importStylesheet(classFile, data);
|
|
24
|
-
classFile = addStylesToClass(classFile, data);
|
|
25
|
-
return {
|
|
26
|
-
classFile,
|
|
27
|
-
classFilePath,
|
|
28
|
-
};
|
|
29
45
|
}
|
|
@@ -4,16 +4,38 @@ import { updateTemplates } from '@codemod-utils/ast-template-tag';
|
|
|
4
4
|
import { addLocalClasses, getClassToStyles, getModuleFilePath, } from '../css/index.js';
|
|
5
5
|
export function updateTemplate(templateFilePath, options) {
|
|
6
6
|
const { projectRoot } = options;
|
|
7
|
+
let templateFile = readFileSync(join(projectRoot, templateFilePath), 'utf8');
|
|
7
8
|
const cssModuleFile = readFileSync(join(projectRoot, getModuleFilePath(templateFilePath)), 'utf8');
|
|
8
|
-
const templateFile = readFileSync(join(projectRoot, templateFilePath), 'utf8');
|
|
9
9
|
const data = {
|
|
10
10
|
classToStyles: getClassToStyles(cssModuleFile),
|
|
11
11
|
isHbs: templateFilePath.endsWith('.hbs'),
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
try {
|
|
14
|
+
if (data.isHbs) {
|
|
15
|
+
templateFile = addLocalClasses(templateFile, data);
|
|
16
|
+
return {
|
|
17
|
+
output: {
|
|
18
|
+
templateFile,
|
|
19
|
+
},
|
|
20
|
+
status: 'success',
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
templateFile = updateTemplates(templateFile, (code) => {
|
|
24
|
+
return addLocalClasses(code, data);
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
output: {
|
|
28
|
+
templateFile,
|
|
29
|
+
},
|
|
30
|
+
status: 'success',
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.log(`WARNING: ${templateFilePath} could not be updated.`);
|
|
35
|
+
console.log(error.message);
|
|
36
|
+
return {
|
|
37
|
+
output: undefined,
|
|
38
|
+
status: 'error',
|
|
39
|
+
};
|
|
15
40
|
}
|
|
16
|
-
return updateTemplates(templateFile, (code) => {
|
|
17
|
-
return addLocalClasses(code, data);
|
|
18
|
-
});
|
|
19
41
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-codemod-remove-global-styles",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Codemod to localize global styles",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codemod",
|
|
@@ -20,32 +20,29 @@
|
|
|
20
20
|
"type": "module",
|
|
21
21
|
"main": "dist/src/index.js",
|
|
22
22
|
"bin": "dist/bin/ember-codemod-remove-global-styles.js",
|
|
23
|
-
"directories": {
|
|
24
|
-
"test": "tests"
|
|
25
|
-
},
|
|
26
23
|
"files": [
|
|
27
24
|
"dist"
|
|
28
25
|
],
|
|
29
26
|
"dependencies": {
|
|
30
|
-
"@codemod-utils/ast-javascript": "^2.1.
|
|
31
|
-
"@codemod-utils/ast-template": "^2.1.
|
|
32
|
-
"@codemod-utils/ast-template-tag": "^1.2.
|
|
33
|
-
"@codemod-utils/files": "^3.2.
|
|
27
|
+
"@codemod-utils/ast-javascript": "^2.1.3",
|
|
28
|
+
"@codemod-utils/ast-template": "^2.1.3",
|
|
29
|
+
"@codemod-utils/ast-template-tag": "^1.2.1",
|
|
30
|
+
"@codemod-utils/files": "^3.2.4",
|
|
34
31
|
"postcss": "^8.5.6",
|
|
35
32
|
"yargs": "^18.0.0"
|
|
36
33
|
},
|
|
37
34
|
"devDependencies": {
|
|
38
|
-
"@codemod-utils/tests": "^2.2.
|
|
35
|
+
"@codemod-utils/tests": "^2.2.3",
|
|
39
36
|
"@sondr3/minitest": "^0.1.2",
|
|
40
|
-
"@types/node": "^20.19.
|
|
37
|
+
"@types/node": "^20.19.30",
|
|
41
38
|
"@types/yargs": "^17.0.35",
|
|
42
39
|
"concurrently": "^9.2.1",
|
|
43
40
|
"eslint": "^9.39.2",
|
|
44
|
-
"prettier": "^3.
|
|
41
|
+
"prettier": "^3.8.1",
|
|
45
42
|
"typescript": "^5.9.3",
|
|
46
43
|
"@shared-configs/eslint-config-node": "0.0.0",
|
|
47
|
-
"@shared-configs/
|
|
48
|
-
"@shared-configs/
|
|
44
|
+
"@shared-configs/typescript": "0.0.0",
|
|
45
|
+
"@shared-configs/prettier": "0.0.0"
|
|
49
46
|
},
|
|
50
47
|
"engines": {
|
|
51
48
|
"node": "20.* || >= 22"
|