ember-codemod-remove-ember-css-modules 0.1.0 → 0.1.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 +6 -1
- package/package.json +10 -9
- package/src/migration/ember-app/steps/analyze-app.js +8 -8
- package/src/migration/ember-app/steps/create-options.js +2 -2
- package/src/migration/ember-app/steps/move-stylesheets.js +1 -1
- package/src/migration/ember-app/steps/shared/import-styles.js +17 -18
- package/src/migration/ember-app/steps/shared/update-templates.js +14 -13
- package/src/migration/ember-app/steps/update-app-app-js.js +5 -4
- package/src/migration/ember-app/steps/update-package-json.js +4 -3
- package/src/utils/abstract-syntax-tree/javascript.js +10 -16
- package/src/utils/blueprints/blueprints-root.js +8 -0
- package/src/utils/blueprints/get-version.js +16 -0
- package/src/utils/blueprints.js +2 -3
- package/src/utils/blueprints/blueprint-root.js +0 -13
- package/src/utils/blueprints/decide-version.js +0 -25
- package/src/utils/blueprints/process-template.js +0 -12
- package/src/utils/files/copy-files.js +0 -19
- package/src/utils/files/create-files.js +0 -17
- package/src/utils/files/find-files.js +0 -28
- package/src/utils/files/map-file-paths.js +0 -25
- package/src/utils/files/move-files.js +0 -22
- package/src/utils/files/remove-directory-if-empty.js +0 -19
- package/src/utils/files/remove-files.js +0 -15
- package/src/utils/files.js +0 -7
- package/src/utils/json/convert-to-map.js +0 -3
- package/src/utils/json/convert-to-object.js +0 -5
- package/src/utils/json.js +0 -2
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ Step 3. Celebrate.
|
|
|
41
41
|
<details>
|
|
42
42
|
<summary>Optional: Specify the component structure</summary>
|
|
43
43
|
|
|
44
|
-
By default, an Octane
|
|
44
|
+
By default, an Octane project has the flat component structure. Pass `--component-structure` to indicate otherwise.
|
|
45
45
|
|
|
46
46
|
```sh
|
|
47
47
|
npx ember-codemod-remove-ember-css-modules --component-structure="nested"
|
|
@@ -217,6 +217,11 @@ The codemod is not responsible for fixing complex expressions. Refactor template
|
|
|
217
217
|
* Node.js v16 or above
|
|
218
218
|
|
|
219
219
|
|
|
220
|
+
## Contributing
|
|
221
|
+
|
|
222
|
+
See the [Contributing](../../CONTRIBUTING.md) guide for details.
|
|
223
|
+
|
|
224
|
+
|
|
220
225
|
## License
|
|
221
226
|
|
|
222
227
|
This project is licensed under the [MIT License](LICENSE.md).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-codemod-remove-ember-css-modules",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Codemod to replace ember-css-modules with embroider-css-modules",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codemod",
|
|
@@ -27,25 +27,26 @@
|
|
|
27
27
|
"test": "tests"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@babel/parser": "^7.21.
|
|
30
|
+
"@babel/parser": "^7.21.5",
|
|
31
|
+
"@codemod-utils/blueprints": "^0.1.1",
|
|
32
|
+
"@codemod-utils/files": "^0.1.0",
|
|
33
|
+
"@codemod-utils/json": "^0.1.1",
|
|
31
34
|
"ember-template-recast": "^6.1.4",
|
|
32
|
-
"glob": "^10.0.0",
|
|
33
|
-
"lodash.template": "^4.5.0",
|
|
34
35
|
"recast": "^0.23.1",
|
|
35
|
-
"yargs": "^17.7.
|
|
36
|
+
"yargs": "^17.7.2"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@babel/core": "^7.21.
|
|
39
|
+
"@babel/core": "^7.21.5",
|
|
39
40
|
"@babel/eslint-parser": "^7.21.3",
|
|
41
|
+
"@codemod-utils/tests": "^0.1.0",
|
|
40
42
|
"@sondr3/minitest": "^0.1.1",
|
|
41
|
-
"eslint": "^8.
|
|
43
|
+
"eslint": "^8.39.0",
|
|
42
44
|
"eslint-config-prettier": "^8.8.0",
|
|
43
45
|
"eslint-plugin-import": "^2.27.5",
|
|
44
46
|
"eslint-plugin-n": "^15.7.0",
|
|
45
47
|
"eslint-plugin-prettier": "^4.2.1",
|
|
46
48
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
47
|
-
"
|
|
48
|
-
"prettier": "^2.8.7"
|
|
49
|
+
"prettier": "^2.8.8"
|
|
49
50
|
},
|
|
50
51
|
"engines": {
|
|
51
52
|
"node": "16.* || >= 18"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join, parse } from 'node:path';
|
|
2
2
|
|
|
3
|
-
import { findFiles, renameDirectory } from '
|
|
3
|
+
import { findFiles, renameDirectory } from '@codemod-utils/files';
|
|
4
4
|
|
|
5
5
|
function findAndRenameFiles(findOptions, replaceOptions) {
|
|
6
6
|
const { globPattern, ignoreList, projectRoot } = findOptions;
|
|
@@ -57,7 +57,7 @@ function analyzeComponents(options) {
|
|
|
57
57
|
{
|
|
58
58
|
from: 'app/components',
|
|
59
59
|
to: '',
|
|
60
|
-
}
|
|
60
|
+
},
|
|
61
61
|
);
|
|
62
62
|
|
|
63
63
|
const stylesheetFilePaths = findAndRenameFiles(
|
|
@@ -68,7 +68,7 @@ function analyzeComponents(options) {
|
|
|
68
68
|
{
|
|
69
69
|
from: 'app/components',
|
|
70
70
|
to: '',
|
|
71
|
-
}
|
|
71
|
+
},
|
|
72
72
|
);
|
|
73
73
|
|
|
74
74
|
const templateFilePaths = findAndRenameFiles(
|
|
@@ -79,7 +79,7 @@ function analyzeComponents(options) {
|
|
|
79
79
|
{
|
|
80
80
|
from: 'app/components',
|
|
81
81
|
to: '',
|
|
82
|
-
}
|
|
82
|
+
},
|
|
83
83
|
);
|
|
84
84
|
|
|
85
85
|
const entities = analyzeEntities({
|
|
@@ -94,7 +94,7 @@ function analyzeComponents(options) {
|
|
|
94
94
|
const newEntityName = entityName.replace(/\/index$/, '');
|
|
95
95
|
|
|
96
96
|
return [newEntityName, extensions];
|
|
97
|
-
})
|
|
97
|
+
}),
|
|
98
98
|
);
|
|
99
99
|
}
|
|
100
100
|
|
|
@@ -113,7 +113,7 @@ function analyzeRoutes(options) {
|
|
|
113
113
|
{
|
|
114
114
|
from: 'app/controllers',
|
|
115
115
|
to: '',
|
|
116
|
-
}
|
|
116
|
+
},
|
|
117
117
|
);
|
|
118
118
|
|
|
119
119
|
const stylesheetFilePaths = findAndRenameFiles(
|
|
@@ -125,7 +125,7 @@ function analyzeRoutes(options) {
|
|
|
125
125
|
{
|
|
126
126
|
from: 'app/styles',
|
|
127
127
|
to: '',
|
|
128
|
-
}
|
|
128
|
+
},
|
|
129
129
|
);
|
|
130
130
|
|
|
131
131
|
const templateFilePaths = findAndRenameFiles(
|
|
@@ -137,7 +137,7 @@ function analyzeRoutes(options) {
|
|
|
137
137
|
{
|
|
138
138
|
from: 'app/templates',
|
|
139
139
|
to: '',
|
|
140
|
-
}
|
|
140
|
+
},
|
|
141
141
|
);
|
|
142
142
|
|
|
143
143
|
return analyzeEntities({
|
|
@@ -7,7 +7,7 @@ function analyzePackageJson(codemodOptions) {
|
|
|
7
7
|
try {
|
|
8
8
|
const packageJsonFile = readFileSync(
|
|
9
9
|
join(projectRoot, 'package.json'),
|
|
10
|
-
'utf8'
|
|
10
|
+
'utf8',
|
|
11
11
|
);
|
|
12
12
|
|
|
13
13
|
const { dependencies, devDependencies } = JSON.parse(packageJsonFile);
|
|
@@ -25,7 +25,7 @@ function analyzePackageJson(codemodOptions) {
|
|
|
25
25
|
};
|
|
26
26
|
} catch (e) {
|
|
27
27
|
throw new SyntaxError(
|
|
28
|
-
`ERROR: package.json is missing or is not valid. (${e.message})\n
|
|
28
|
+
`ERROR: package.json is missing or is not valid. (${e.message})\n`,
|
|
29
29
|
);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { join, parse } from 'node:path';
|
|
3
3
|
|
|
4
|
+
import { processTemplate } from '@codemod-utils/blueprints';
|
|
5
|
+
import { createFiles } from '@codemod-utils/files';
|
|
6
|
+
|
|
4
7
|
import { ASTJavaScript as AST } from '../../../../utils/abstract-syntax-tree.js';
|
|
5
|
-
import {
|
|
6
|
-
blueprintRoot,
|
|
7
|
-
processTemplate,
|
|
8
|
-
} from '../../../../utils/blueprints.js';
|
|
9
|
-
import { createFiles } from '../../../../utils/files.js';
|
|
8
|
+
import { blueprintsRoot } from '../../../../utils/blueprints.js';
|
|
10
9
|
import { parseEntityName } from '../../../../utils/string.js';
|
|
11
10
|
|
|
12
11
|
function removeTemplateOnlyComponentMethod(file, data) {
|
|
@@ -29,10 +28,10 @@ function removeTemplateOnlyComponentMethod(file, data) {
|
|
|
29
28
|
AST.builders.classBody([
|
|
30
29
|
AST.builders.classProperty(
|
|
31
30
|
AST.builders.identifier(data.__styles__),
|
|
32
|
-
AST.builders.identifier(data.__styles__)
|
|
31
|
+
AST.builders.identifier(data.__styles__),
|
|
33
32
|
),
|
|
34
33
|
]),
|
|
35
|
-
superClass
|
|
34
|
+
superClass,
|
|
36
35
|
);
|
|
37
36
|
},
|
|
38
37
|
|
|
@@ -42,7 +41,7 @@ function removeTemplateOnlyComponentMethod(file, data) {
|
|
|
42
41
|
}
|
|
43
42
|
|
|
44
43
|
const defaultImport = path.value.specifiers.find(
|
|
45
|
-
(specifier) => specifier.type === 'ImportDefaultSpecifier'
|
|
44
|
+
(specifier) => specifier.type === 'ImportDefaultSpecifier',
|
|
46
45
|
);
|
|
47
46
|
|
|
48
47
|
if (defaultImport?.local?.name !== 'templateOnlyComponent') {
|
|
@@ -52,10 +51,10 @@ function removeTemplateOnlyComponentMethod(file, data) {
|
|
|
52
51
|
return AST.builders.importDeclaration(
|
|
53
52
|
[
|
|
54
53
|
AST.builders.importDefaultSpecifier(
|
|
55
|
-
AST.builders.identifier('Component')
|
|
54
|
+
AST.builders.identifier('Component'),
|
|
56
55
|
),
|
|
57
56
|
],
|
|
58
|
-
AST.builders.literal('@glimmer/component')
|
|
57
|
+
AST.builders.literal('@glimmer/component'),
|
|
59
58
|
);
|
|
60
59
|
},
|
|
61
60
|
});
|
|
@@ -91,11 +90,11 @@ function importStylesInClass(file, data) {
|
|
|
91
90
|
AST.builders.importDeclaration(
|
|
92
91
|
[
|
|
93
92
|
AST.builders.importDefaultSpecifier(
|
|
94
|
-
AST.builders.identifier(data.__styles__)
|
|
93
|
+
AST.builders.identifier(data.__styles__),
|
|
95
94
|
),
|
|
96
95
|
],
|
|
97
|
-
AST.builders.literal(`./${data.fileName}.css`)
|
|
98
|
-
)
|
|
96
|
+
AST.builders.literal(`./${data.fileName}.css`),
|
|
97
|
+
),
|
|
99
98
|
);
|
|
100
99
|
|
|
101
100
|
return AST.print(ast);
|
|
@@ -111,7 +110,7 @@ function addStylesAsClassProperty(file, data) {
|
|
|
111
110
|
const nodesToAdd = [
|
|
112
111
|
AST.builders.classProperty(
|
|
113
112
|
AST.builders.identifier(data.__styles__),
|
|
114
|
-
AST.builders.identifier(data.__styles__)
|
|
113
|
+
AST.builders.identifier(data.__styles__),
|
|
115
114
|
),
|
|
116
115
|
];
|
|
117
116
|
|
|
@@ -134,8 +133,8 @@ function createClass(customizations, options) {
|
|
|
134
133
|
const fileMapping = new Map(
|
|
135
134
|
blueprintFilePaths.map((blueprintFilePath) => {
|
|
136
135
|
const blueprintFile = readFileSync(
|
|
137
|
-
join(
|
|
138
|
-
'utf8'
|
|
136
|
+
join(blueprintsRoot, blueprintFilePath),
|
|
137
|
+
'utf8',
|
|
139
138
|
);
|
|
140
139
|
|
|
141
140
|
const file = processTemplate(blueprintFile, {
|
|
@@ -144,7 +143,7 @@ function createClass(customizations, options) {
|
|
|
144
143
|
});
|
|
145
144
|
|
|
146
145
|
return [filePath, file];
|
|
147
|
-
})
|
|
146
|
+
}),
|
|
148
147
|
);
|
|
149
148
|
|
|
150
149
|
createFiles(fileMapping, options);
|
|
@@ -181,7 +180,7 @@ function updateClass(customizations, options) {
|
|
|
181
180
|
createFiles(fileMapping, options);
|
|
182
181
|
} catch (e) {
|
|
183
182
|
console.warn(
|
|
184
|
-
`WARNING: updateClass could not update \`${filePath}\`. Please update the file manually. (${e.message})\n
|
|
183
|
+
`WARNING: updateClass could not update \`${filePath}\`. Please update the file manually. (${e.message})\n`,
|
|
185
184
|
);
|
|
186
185
|
}
|
|
187
186
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
|
|
4
|
+
import { createFiles } from '@codemod-utils/files';
|
|
5
|
+
|
|
4
6
|
import { ASTHandlebars as AST } from '../../../../utils/abstract-syntax-tree.js';
|
|
5
|
-
import { createFiles } from '../../../../utils/files.js';
|
|
6
7
|
|
|
7
8
|
function sanitizeClassAndLocalClassAttributes(file) {
|
|
8
9
|
function removeAttributeWithoutValue(attributeName, attributes) {
|
|
9
10
|
const attributeIndex = attributes.findIndex(
|
|
10
|
-
(attribute) => attribute.name === attributeName
|
|
11
|
+
(attribute) => attribute.name === attributeName,
|
|
11
12
|
);
|
|
12
13
|
|
|
13
14
|
if (attributeIndex === -1) {
|
|
@@ -52,10 +53,10 @@ function mergeClassAndLocalClassAttributes(file, data) {
|
|
|
52
53
|
const { attributes } = node;
|
|
53
54
|
|
|
54
55
|
const localClassAttributeIndex = attributes.findIndex(
|
|
55
|
-
(attribute) => attribute.name === 'local-class'
|
|
56
|
+
(attribute) => attribute.name === 'local-class',
|
|
56
57
|
);
|
|
57
58
|
const classAttributeIndex = attributes.findIndex(
|
|
58
|
-
(attribute) => attribute.name === 'class'
|
|
59
|
+
(attribute) => attribute.name === 'class',
|
|
59
60
|
);
|
|
60
61
|
|
|
61
62
|
if (localClassAttributeIndex === -1 || classAttributeIndex === -1) {
|
|
@@ -97,7 +98,7 @@ function mergeClassAndLocalClassAttributes(file, data) {
|
|
|
97
98
|
|
|
98
99
|
attributes[classAttributeIndex].value = AST.builders.mustache(
|
|
99
100
|
AST.builders.path('concat'),
|
|
100
|
-
params
|
|
101
|
+
params,
|
|
101
102
|
);
|
|
102
103
|
|
|
103
104
|
// Remove the local-class attribute
|
|
@@ -119,7 +120,7 @@ function removeLocalClassHelpers(file, data) {
|
|
|
119
120
|
|
|
120
121
|
if (hasFromArgument) {
|
|
121
122
|
throw new RangeError(
|
|
122
|
-
`Unable to handle the {{local-class}} helper's \`from\` key. See lines ${path.loc.start.line}-${path.loc.end.line}
|
|
123
|
+
`Unable to handle the {{local-class}} helper's \`from\` key. See lines ${path.loc.start.line}-${path.loc.end.line}.`,
|
|
123
124
|
);
|
|
124
125
|
}
|
|
125
126
|
|
|
@@ -166,7 +167,7 @@ function removeLocalClassHelpers(file, data) {
|
|
|
166
167
|
|
|
167
168
|
if (localClassNames.length === 1) {
|
|
168
169
|
node.value = AST.builders.mustache(
|
|
169
|
-
AST.builders.path(`this.${data.__styles__}.${localClassNames[0]}`)
|
|
170
|
+
AST.builders.path(`this.${data.__styles__}.${localClassNames[0]}`),
|
|
170
171
|
);
|
|
171
172
|
|
|
172
173
|
return;
|
|
@@ -199,7 +200,7 @@ function removeLocalClassHelpers(file, data) {
|
|
|
199
200
|
|
|
200
201
|
if (localClassNames.length === 1) {
|
|
201
202
|
return AST.builders.path(
|
|
202
|
-
`this.${data.__styles__}.${localClassNames[0]}
|
|
203
|
+
`this.${data.__styles__}.${localClassNames[0]}`,
|
|
203
204
|
);
|
|
204
205
|
}
|
|
205
206
|
|
|
@@ -224,7 +225,7 @@ function removeLocalClassAttributes(file, data) {
|
|
|
224
225
|
} else {
|
|
225
226
|
param = AST.builders.sexpr(
|
|
226
227
|
'array',
|
|
227
|
-
localClassNames.map(AST.builders.string)
|
|
228
|
+
localClassNames.map(AST.builders.string),
|
|
228
229
|
);
|
|
229
230
|
}
|
|
230
231
|
|
|
@@ -305,7 +306,7 @@ function removeLocalClassAttributes(file, data) {
|
|
|
305
306
|
|
|
306
307
|
if (localClassNames.length === 1) {
|
|
307
308
|
return AST.builders.mustache(
|
|
308
|
-
AST.builders.path(`this.${data.__styles__}.${localClassNames[0]}`)
|
|
309
|
+
AST.builders.path(`this.${data.__styles__}.${localClassNames[0]}`),
|
|
309
310
|
);
|
|
310
311
|
}
|
|
311
312
|
|
|
@@ -337,7 +338,7 @@ function removeLocalClassAttributes(file, data) {
|
|
|
337
338
|
const { attributes } = node;
|
|
338
339
|
|
|
339
340
|
const localClassAttributeIndex = attributes.findIndex(
|
|
340
|
-
(attribute) => attribute.name === 'local-class'
|
|
341
|
+
(attribute) => attribute.name === 'local-class',
|
|
341
342
|
);
|
|
342
343
|
|
|
343
344
|
if (localClassAttributeIndex === -1) {
|
|
@@ -351,7 +352,7 @@ function removeLocalClassAttributes(file, data) {
|
|
|
351
352
|
case 'ConcatStatement': {
|
|
352
353
|
localClassAttribute.name = 'class';
|
|
353
354
|
localClassAttribute.value.parts = transformParts(
|
|
354
|
-
localClassAttribute.value.parts
|
|
355
|
+
localClassAttribute.value.parts,
|
|
355
356
|
);
|
|
356
357
|
|
|
357
358
|
break;
|
|
@@ -415,7 +416,7 @@ function updateTemplate(customizations, options) {
|
|
|
415
416
|
createFiles(fileMapping, options);
|
|
416
417
|
} catch (e) {
|
|
417
418
|
console.warn(
|
|
418
|
-
`WARNING: updateTemplate could not update \`${filePath}\`. Please update the file manually. (${e.message})\n
|
|
419
|
+
`WARNING: updateTemplate could not update \`${filePath}\`. Please update the file manually. (${e.message})\n`,
|
|
419
420
|
);
|
|
420
421
|
}
|
|
421
422
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { extname, join } from 'node:path';
|
|
3
3
|
|
|
4
|
+
import { createFiles, findFiles } from '@codemod-utils/files';
|
|
5
|
+
|
|
4
6
|
import { ASTJavaScript as AST } from '../../../utils/abstract-syntax-tree.js';
|
|
5
|
-
import { createFiles, findFiles } from '../../../utils/files.js';
|
|
6
7
|
|
|
7
8
|
function addCssEntryPoint(file, data) {
|
|
8
9
|
const traverse = AST.traverse(data.hasTypeScript);
|
|
@@ -12,7 +13,7 @@ function addCssEntryPoint(file, data) {
|
|
|
12
13
|
const nodesToAdd = [
|
|
13
14
|
AST.builders.importDeclaration(
|
|
14
15
|
[],
|
|
15
|
-
AST.builders.literal('./assets/app.css')
|
|
16
|
+
AST.builders.literal('./assets/app.css'),
|
|
16
17
|
),
|
|
17
18
|
AST.builders.noop(),
|
|
18
19
|
];
|
|
@@ -35,7 +36,7 @@ export function updateAppAppJs(options) {
|
|
|
35
36
|
|
|
36
37
|
if (filePaths.length !== 1) {
|
|
37
38
|
console.warn(
|
|
38
|
-
'WARNING: updateAppAppJs could not find app.{js,ts} in the app folder. Will skip this step.\n'
|
|
39
|
+
'WARNING: updateAppAppJs could not find app.{js,ts} in the app folder. Will skip this step.\n',
|
|
39
40
|
);
|
|
40
41
|
|
|
41
42
|
return;
|
|
@@ -58,7 +59,7 @@ export function updateAppAppJs(options) {
|
|
|
58
59
|
createFiles(fileMapping, options);
|
|
59
60
|
} catch (e) {
|
|
60
61
|
console.warn(
|
|
61
|
-
`WARNING: updateAppAppJs could not update \`${filePath}\`. Please update the file manually. (${e.message})\n
|
|
62
|
+
`WARNING: updateAppAppJs could not update \`${filePath}\`. Please update the file manually. (${e.message})\n`,
|
|
62
63
|
);
|
|
63
64
|
}
|
|
64
65
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import { convertToMap, convertToObject } from '@codemod-utils/json';
|
|
5
|
+
|
|
6
|
+
import { getVersion } from '../../../utils/blueprints.js';
|
|
6
7
|
|
|
7
8
|
function updateDevDependencies(packageJson, options) {
|
|
8
9
|
const { project } = options;
|
|
@@ -22,7 +23,7 @@ function updateDevDependencies(packageJson, options) {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
[...packagesToInstall].sort().forEach((packageName) => {
|
|
25
|
-
const version =
|
|
26
|
+
const version = getVersion(packageName, options);
|
|
26
27
|
|
|
27
28
|
devDependencies.set(packageName, version);
|
|
28
29
|
});
|
|
@@ -71,29 +71,25 @@ const tsOptions = {
|
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
function getParseOptions(hasTypeScript) {
|
|
74
|
+
const options = hasTypeScript ? tsOptions : jsOptions;
|
|
75
|
+
|
|
74
76
|
return {
|
|
75
77
|
parser: {
|
|
76
78
|
parse(file) {
|
|
77
|
-
return babelParser(file,
|
|
79
|
+
return babelParser(file, options);
|
|
78
80
|
},
|
|
79
81
|
},
|
|
80
82
|
};
|
|
81
83
|
}
|
|
82
84
|
|
|
83
|
-
function
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
visit(ast, visitMethods);
|
|
87
|
-
|
|
88
|
-
return ast;
|
|
89
|
-
}
|
|
85
|
+
function traverse(hasTypeScript) {
|
|
86
|
+
return function (file, visitMethods) {
|
|
87
|
+
const ast = parse(file, getParseOptions(hasTypeScript));
|
|
90
88
|
|
|
91
|
-
|
|
92
|
-
const ast = parse(file, getParseOptions(true));
|
|
89
|
+
visit(ast, visitMethods);
|
|
93
90
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return ast;
|
|
91
|
+
return ast;
|
|
92
|
+
};
|
|
97
93
|
}
|
|
98
94
|
|
|
99
95
|
const tools = {
|
|
@@ -101,9 +97,7 @@ const tools = {
|
|
|
101
97
|
print(ast) {
|
|
102
98
|
return print(ast, formattingOptions).code;
|
|
103
99
|
},
|
|
104
|
-
traverse
|
|
105
|
-
return hasTypeScript ? traverseTypeScript : traverseJavaScript;
|
|
106
|
-
},
|
|
100
|
+
traverse,
|
|
107
101
|
};
|
|
108
102
|
|
|
109
103
|
export default tools;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { decideVersion } from '@codemod-utils/blueprints';
|
|
2
|
+
|
|
3
|
+
const latestVersions = new Map([
|
|
4
|
+
['embroider-css-modules', '0.1.1'],
|
|
5
|
+
['type-css-modules', '0.1.1'],
|
|
6
|
+
['webpack', '5.81.0'],
|
|
7
|
+
]);
|
|
8
|
+
|
|
9
|
+
export function getVersion(packageName, options) {
|
|
10
|
+
const { project } = options;
|
|
11
|
+
|
|
12
|
+
return decideVersion(packageName, {
|
|
13
|
+
dependencies: project.dependencies,
|
|
14
|
+
latestVersions,
|
|
15
|
+
});
|
|
16
|
+
}
|
package/src/utils/blueprints.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export * from './blueprints/
|
|
2
|
-
export * from './blueprints/
|
|
3
|
-
export * from './blueprints/process-template.js';
|
|
1
|
+
export * from './blueprints/blueprints-root.js';
|
|
2
|
+
export * from './blueprints/get-version.js';
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { dirname, join } from 'node:path';
|
|
2
|
-
import { fileURLToPath } from 'node:url';
|
|
3
|
-
|
|
4
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
-
const __dirname = dirname(__filename);
|
|
6
|
-
|
|
7
|
-
function getBlueprintRoot() {
|
|
8
|
-
const srcDirectory = join(__dirname, '../..');
|
|
9
|
-
|
|
10
|
-
return join(srcDirectory, 'blueprints');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const blueprintRoot = getBlueprintRoot();
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const latestVersions = new Map([
|
|
2
|
-
['embroider-css-modules', '0.1.0'],
|
|
3
|
-
['type-css-modules', '0.1.0'],
|
|
4
|
-
['webpack', '5.78.0'],
|
|
5
|
-
]);
|
|
6
|
-
|
|
7
|
-
export function decideVersion(packageName, options) {
|
|
8
|
-
const { project } = options;
|
|
9
|
-
|
|
10
|
-
const installedVersion = project.dependencies.get(packageName);
|
|
11
|
-
|
|
12
|
-
if (installedVersion) {
|
|
13
|
-
return installedVersion;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const latestVersion = latestVersions.get(packageName);
|
|
17
|
-
|
|
18
|
-
if (!latestVersion) {
|
|
19
|
-
throw new RangeError(
|
|
20
|
-
`ERROR: The latest version of \`${packageName}\` is unknown.\n`
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return `^${latestVersion}`;
|
|
25
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/* https://github.com/ember-cli/ember-cli/blob/v4.11.0/lib/utilities/process-template.js */
|
|
2
|
-
import template from 'lodash.template';
|
|
3
|
-
|
|
4
|
-
export function processTemplate(file, data) {
|
|
5
|
-
const settings = {
|
|
6
|
-
escape: /<%-([\s\S]+?)%>/g,
|
|
7
|
-
evaluate: /<%([\s\S]+?)%>/g,
|
|
8
|
-
interpolate: /<%=([\s\S]+?)%>/g,
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
return template(file, settings)(data);
|
|
12
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { copyFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
2
|
-
import { dirname, join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
export function copyFiles(pathMapping, options) {
|
|
5
|
-
const { projectRoot } = options;
|
|
6
|
-
|
|
7
|
-
pathMapping.forEach((newPath, oldPath) => {
|
|
8
|
-
const oldAbsolutePath = join(projectRoot, oldPath);
|
|
9
|
-
|
|
10
|
-
const newAbsolutePath = join(projectRoot, newPath);
|
|
11
|
-
const newDirectory = dirname(newAbsolutePath);
|
|
12
|
-
|
|
13
|
-
if (!existsSync(newDirectory)) {
|
|
14
|
-
mkdirSync(newDirectory, { recursive: true });
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
copyFileSync(oldAbsolutePath, newAbsolutePath);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { dirname, join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
export function createFiles(fileMapping, options) {
|
|
5
|
-
const { projectRoot } = options;
|
|
6
|
-
|
|
7
|
-
fileMapping.forEach((file, newPath) => {
|
|
8
|
-
const newAbsolutePath = join(projectRoot, newPath);
|
|
9
|
-
const newDirectory = dirname(newAbsolutePath);
|
|
10
|
-
|
|
11
|
-
if (!existsSync(newDirectory)) {
|
|
12
|
-
mkdirSync(newDirectory, { recursive: true });
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
writeFileSync(newAbsolutePath, file, 'utf8');
|
|
16
|
-
});
|
|
17
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { globSync } from 'glob';
|
|
2
|
-
|
|
3
|
-
export function findFiles(pattern, { cwd, ignoreList = [] }) {
|
|
4
|
-
if (!pattern) {
|
|
5
|
-
throw new RangeError('ERROR: The glob pattern is unknown.\n');
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (!cwd) {
|
|
9
|
-
throw new RangeError('ERROR: The current working directory is unknown.\n');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const filePaths = globSync(pattern, {
|
|
13
|
-
cwd,
|
|
14
|
-
dot: true,
|
|
15
|
-
ignore: ignoreList,
|
|
16
|
-
nodir: true,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
return filePaths;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function unionize(files) {
|
|
23
|
-
if (files.length <= 1) {
|
|
24
|
-
return files.join(',');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return `{${files.join(',')}}`;
|
|
28
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
2
|
-
|
|
3
|
-
export function renameDirectory(oldPath, { from, to }) {
|
|
4
|
-
if (from === '') {
|
|
5
|
-
return join(to, oldPath);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (!oldPath.startsWith(`${from}/`)) {
|
|
9
|
-
return oldPath;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return join(to, oldPath.replace(`${from}/`, ''));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function mapFilePaths(filePaths, directory) {
|
|
16
|
-
const { from, to } = directory;
|
|
17
|
-
|
|
18
|
-
return new Map(
|
|
19
|
-
filePaths.map((filePath) => {
|
|
20
|
-
const newPath = renameDirectory(filePath, { from, to });
|
|
21
|
-
|
|
22
|
-
return [filePath, newPath];
|
|
23
|
-
})
|
|
24
|
-
);
|
|
25
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, renameSync } from 'node:fs';
|
|
2
|
-
import { dirname, join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
import { removeDirectoryIfEmpty } from './remove-directory-if-empty.js';
|
|
5
|
-
|
|
6
|
-
export function moveFiles(pathMapping, options) {
|
|
7
|
-
const { projectRoot } = options;
|
|
8
|
-
|
|
9
|
-
pathMapping.forEach((newPath, oldPath) => {
|
|
10
|
-
const oldAbsolutePath = join(projectRoot, oldPath);
|
|
11
|
-
|
|
12
|
-
const newAbsolutePath = join(projectRoot, newPath);
|
|
13
|
-
const newDirectory = dirname(newAbsolutePath);
|
|
14
|
-
|
|
15
|
-
if (!existsSync(newDirectory)) {
|
|
16
|
-
mkdirSync(newDirectory, { recursive: true });
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
renameSync(oldAbsolutePath, newAbsolutePath);
|
|
20
|
-
removeDirectoryIfEmpty({ oldPath, projectRoot });
|
|
21
|
-
});
|
|
22
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { readdirSync, rmSync } from 'node:fs';
|
|
2
|
-
import { dirname, join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
export function removeDirectoryIfEmpty({ oldPath, projectRoot }) {
|
|
5
|
-
const directories = dirname(oldPath).split('/');
|
|
6
|
-
const depth = directories.length;
|
|
7
|
-
|
|
8
|
-
for (let i = 0; i < depth; i++) {
|
|
9
|
-
const directory = join(projectRoot, ...directories);
|
|
10
|
-
const numFilesLeft = readdirSync(directory).length;
|
|
11
|
-
|
|
12
|
-
if (numFilesLeft > 0) {
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
rmSync(directory, { recursive: true });
|
|
17
|
-
directories.pop();
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { rmSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
import { removeDirectoryIfEmpty } from './remove-directory-if-empty.js';
|
|
5
|
-
|
|
6
|
-
export function removeFiles(oldPaths, options) {
|
|
7
|
-
const { projectRoot } = options;
|
|
8
|
-
|
|
9
|
-
oldPaths.forEach((oldPath) => {
|
|
10
|
-
const oldAbsolutePath = join(projectRoot, oldPath);
|
|
11
|
-
|
|
12
|
-
rmSync(oldAbsolutePath);
|
|
13
|
-
removeDirectoryIfEmpty({ oldPath, projectRoot });
|
|
14
|
-
});
|
|
15
|
-
}
|
package/src/utils/files.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export * from './files/copy-files.js';
|
|
2
|
-
export * from './files/create-files.js';
|
|
3
|
-
export * from './files/find-files.js';
|
|
4
|
-
export * from './files/map-file-paths.js';
|
|
5
|
-
export * from './files/move-files.js';
|
|
6
|
-
export * from './files/remove-directory-if-empty.js';
|
|
7
|
-
export * from './files/remove-files.js';
|
package/src/utils/json.js
DELETED