ember-codemod-remove-ember-css-modules 0.1.5 → 0.2.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/README.md +6 -1
- package/{bin → dist/bin}/ember-codemod-remove-ember-css-modules.js +9 -17
- package/{src → dist/src}/index.js +1 -2
- package/dist/src/migration/ember-app/index.js +21 -0
- package/dist/src/migration/ember-app/steps/analyze-app.js +98 -0
- package/dist/src/migration/ember-app/steps/create-options.js +24 -0
- package/dist/src/migration/ember-app/steps/import-styles-in-components.js +35 -0
- package/dist/src/migration/ember-app/steps/import-styles-in-routes.js +32 -0
- package/dist/src/migration/ember-app/steps/move-stylesheets.js +35 -0
- package/dist/src/migration/ember-app/steps/shared/import-styles.js +136 -0
- package/dist/src/migration/ember-app/steps/shared/update-templates.js +354 -0
- package/dist/src/migration/ember-app/steps/update-app-app-js.js +46 -0
- package/dist/src/migration/ember-app/steps/update-component-templates.js +22 -0
- package/dist/src/migration/ember-app/steps/update-package-json.js +38 -0
- package/dist/src/migration/ember-app/steps/update-route-templates.js +18 -0
- package/dist/src/types/index.js +1 -0
- package/dist/src/utils/blueprints/blueprints-root.js +4 -0
- package/dist/src/utils/blueprints/get-version.js +13 -0
- package/dist/src/utils/string/ember-cli-string-utils/camelize.js +11 -0
- package/dist/src/utils/string/ember-cli-string-utils/classify.js +10 -0
- package/{src → dist/src}/utils/string/entity-name/classify.js +1 -2
- package/{src → dist/src}/utils/string/entity-name/double-colonize.js +3 -6
- package/dist/src/utils/string/entity-name/parse.js +15 -0
- package/package.json +20 -14
- package/src/migration/ember-app/index.js +0 -37
- package/src/migration/ember-app/steps/analyze-app.js +0 -155
- package/src/migration/ember-app/steps/create-options.js +0 -30
- package/src/migration/ember-app/steps/import-styles-in-components.js +0 -43
- package/src/migration/ember-app/steps/import-styles-in-routes.js +0 -39
- package/src/migration/ember-app/steps/move-stylesheets.js +0 -51
- package/src/migration/ember-app/steps/shared/import-styles.js +0 -210
- package/src/migration/ember-app/steps/shared/index.js +0 -2
- package/src/migration/ember-app/steps/shared/update-templates.js +0 -445
- package/src/migration/ember-app/steps/update-app-app-js.js +0 -64
- package/src/migration/ember-app/steps/update-component-templates.js +0 -28
- package/src/migration/ember-app/steps/update-package-json.js +0 -61
- package/src/migration/ember-app/steps/update-route-templates.js +0 -22
- package/src/utils/blueprints/blueprints-root.js +0 -8
- package/src/utils/blueprints/get-version.js +0 -16
- package/src/utils/string/ember-cli-string-utils/camelize.js +0 -12
- package/src/utils/string/ember-cli-string-utils/classify.js +0 -14
- package/src/utils/string/entity-name/parse.js +0 -19
- /package/{src/blueprints → blueprints}/ember-cli/component/javascript.js +0 -0
- /package/{src/blueprints → blueprints}/ember-cli/component/typescript.ts +0 -0
- /package/{src/blueprints → blueprints}/ember-cli/controller/javascript.js +0 -0
- /package/{src/blueprints → blueprints}/ember-cli/controller/typescript.ts +0 -0
- /package/{src → dist/src}/migration/ember-app/steps/index.js +0 -0
- /package/{src → dist/src}/migration/index.js +0 -0
- /package/{src → dist/src}/utils/blueprints.js +0 -0
- /package/{src → dist/src}/utils/string.js +0 -0
|
@@ -1,445 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
import { ASTHandlebars as AST } from '@codemod-utils/ast';
|
|
5
|
-
import { createFiles } from '@codemod-utils/files';
|
|
6
|
-
|
|
7
|
-
function sanitizeClassAndLocalClassAttributes(file) {
|
|
8
|
-
function removeAttributeWithoutValue(attributeName, attributes) {
|
|
9
|
-
const attributeIndex = attributes.findIndex(
|
|
10
|
-
(attribute) => attribute.name === attributeName,
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
if (attributeIndex === -1) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const attribute = attributes[attributeIndex];
|
|
18
|
-
|
|
19
|
-
if (attribute.isValueless) {
|
|
20
|
-
attributes.splice(attributeIndex, 1);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (attribute.value.type !== 'TextNode') {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const attributeValue = attribute.value.chars.trim();
|
|
29
|
-
|
|
30
|
-
if (attributeValue === '') {
|
|
31
|
-
attributes.splice(attributeIndex, 1);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const traverse = AST.traverse();
|
|
37
|
-
|
|
38
|
-
const ast = traverse(file, {
|
|
39
|
-
ElementNode(node) {
|
|
40
|
-
const { attributes } = node;
|
|
41
|
-
|
|
42
|
-
removeAttributeWithoutValue('class', attributes);
|
|
43
|
-
removeAttributeWithoutValue('local-class', attributes);
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
return AST.print(ast);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function mergeClassAndLocalClassAttributes(file, data) {
|
|
51
|
-
const traverse = AST.traverse();
|
|
52
|
-
|
|
53
|
-
const ast = traverse(file, {
|
|
54
|
-
ElementNode(node) {
|
|
55
|
-
// Check that both class and local-class attributes exist
|
|
56
|
-
const { attributes } = node;
|
|
57
|
-
|
|
58
|
-
const localClassAttributeIndex = attributes.findIndex(
|
|
59
|
-
(attribute) => attribute.name === 'local-class',
|
|
60
|
-
);
|
|
61
|
-
const classAttributeIndex = attributes.findIndex(
|
|
62
|
-
(attribute) => attribute.name === 'class',
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
if (localClassAttributeIndex === -1 || classAttributeIndex === -1) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Merge attributes only when both have TextNode values
|
|
70
|
-
const localClassAttribute = attributes[localClassAttributeIndex];
|
|
71
|
-
const classAttribute = attributes[classAttributeIndex];
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
localClassAttribute.value.type !== 'TextNode' ||
|
|
75
|
-
classAttribute.value.type !== 'TextNode'
|
|
76
|
-
) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const localClassAttributeValue = localClassAttribute.value.chars.trim();
|
|
81
|
-
const classAttributeValue = classAttribute.value.chars.trim();
|
|
82
|
-
|
|
83
|
-
// Update the class attribute
|
|
84
|
-
const localClassNames = localClassAttributeValue.split(/\s+/);
|
|
85
|
-
let params;
|
|
86
|
-
|
|
87
|
-
if (localClassNames.length === 1) {
|
|
88
|
-
params = [
|
|
89
|
-
AST.builders.path(`this.${data.__styles__}.${localClassNames[0]}`),
|
|
90
|
-
AST.builders.string(` ${classAttributeValue}`),
|
|
91
|
-
];
|
|
92
|
-
} else {
|
|
93
|
-
params = [
|
|
94
|
-
AST.builders.sexpr('local-class', [
|
|
95
|
-
AST.builders.path(`this.${data.__styles__}`),
|
|
96
|
-
...localClassNames.map(AST.builders.string),
|
|
97
|
-
]),
|
|
98
|
-
AST.builders.string(` ${classAttributeValue}`),
|
|
99
|
-
];
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
attributes[classAttributeIndex].value = AST.builders.mustache(
|
|
103
|
-
AST.builders.path('concat'),
|
|
104
|
-
params,
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
// Remove the local-class attribute
|
|
108
|
-
attributes.splice(localClassAttributeIndex, 1);
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
return AST.print(ast);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function removeLocalClassHelpers(file, data) {
|
|
116
|
-
/*
|
|
117
|
-
The {{local-class}} helper from ember-css-modules allows
|
|
118
|
-
1 positional argument. The argument's value is presumed
|
|
119
|
-
to be a concatenated string or `undefined`.
|
|
120
|
-
*/
|
|
121
|
-
function canRemoveLocalClassHelper(path) {
|
|
122
|
-
const hasFromArgument = path.hash.pairs.some((pair) => pair.key === 'from');
|
|
123
|
-
|
|
124
|
-
if (hasFromArgument) {
|
|
125
|
-
throw new RangeError(
|
|
126
|
-
`Unable to handle the {{local-class}} helper's \`from\` key. See lines ${path.loc.start.line}-${path.loc.end.line}.`,
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const param = path.params[0];
|
|
131
|
-
|
|
132
|
-
if (param === undefined) {
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (param.type !== 'StringLiteral') {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const value = param.value.trim();
|
|
141
|
-
|
|
142
|
-
return value === '';
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const traverse = AST.traverse();
|
|
146
|
-
|
|
147
|
-
const ast = traverse(file, {
|
|
148
|
-
AttrNode(node) {
|
|
149
|
-
if (node.name !== 'class') {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const hasLocalClassHelper =
|
|
154
|
-
node.value.type === 'MustacheStatement' &&
|
|
155
|
-
node.value.path.original === 'local-class';
|
|
156
|
-
|
|
157
|
-
if (!hasLocalClassHelper) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (canRemoveLocalClassHelper(node.value)) {
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const param = node.value.params[0];
|
|
166
|
-
|
|
167
|
-
if (param.type !== 'StringLiteral') {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const localClassNames = param.value.trim().split(/\s+/);
|
|
172
|
-
|
|
173
|
-
if (localClassNames.length === 1) {
|
|
174
|
-
node.value = AST.builders.mustache(
|
|
175
|
-
AST.builders.path(`this.${data.__styles__}.${localClassNames[0]}`),
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
node.value = AST.builders.mustache(AST.builders.path('local-class'), [
|
|
182
|
-
AST.builders.path(`this.${data.__styles__}`),
|
|
183
|
-
...localClassNames.map(AST.builders.string),
|
|
184
|
-
]);
|
|
185
|
-
},
|
|
186
|
-
|
|
187
|
-
SubExpression(node) {
|
|
188
|
-
const hasLocalClassHelper = node.path.original === 'local-class';
|
|
189
|
-
|
|
190
|
-
if (!hasLocalClassHelper) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (canRemoveLocalClassHelper(node)) {
|
|
195
|
-
return AST.builders.string('');
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const param = node.params[0];
|
|
199
|
-
|
|
200
|
-
if (param.type !== 'StringLiteral') {
|
|
201
|
-
return node;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const localClassNames = param.value.trim().split(/\s+/);
|
|
205
|
-
|
|
206
|
-
if (localClassNames.length === 1) {
|
|
207
|
-
return AST.builders.path(
|
|
208
|
-
`this.${data.__styles__}.${localClassNames[0]}`,
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return AST.builders.sexpr(AST.builders.path('local-class'), [
|
|
213
|
-
AST.builders.path(`this.${data.__styles__}`),
|
|
214
|
-
...localClassNames.map(AST.builders.string),
|
|
215
|
-
]);
|
|
216
|
-
},
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
return AST.print(ast);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function removeLocalClassAttributes(file, data) {
|
|
223
|
-
function transformParam(param) {
|
|
224
|
-
switch (param.type) {
|
|
225
|
-
case 'StringLiteral': {
|
|
226
|
-
const localClassNames = param.value.trim().split(/\s+/);
|
|
227
|
-
|
|
228
|
-
if (localClassNames.length === 1) {
|
|
229
|
-
param.value = localClassNames[0];
|
|
230
|
-
} else {
|
|
231
|
-
param = AST.builders.sexpr(
|
|
232
|
-
'array',
|
|
233
|
-
localClassNames.map(AST.builders.string),
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
break;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
case 'SubExpression': {
|
|
241
|
-
switch (param.path.original) {
|
|
242
|
-
case 'if':
|
|
243
|
-
case 'unless': {
|
|
244
|
-
const subparams = param.params.map(transformParam);
|
|
245
|
-
|
|
246
|
-
param = AST.builders.sexpr(param.path.original, subparams);
|
|
247
|
-
|
|
248
|
-
break;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
break;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
return param;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
function transformPart(part) {
|
|
260
|
-
switch (part.type) {
|
|
261
|
-
case 'MustacheStatement': {
|
|
262
|
-
switch (part.path.original) {
|
|
263
|
-
case 'concat': {
|
|
264
|
-
// eslint-disable-next-line no-inner-declarations
|
|
265
|
-
function hasPathExpression(params) {
|
|
266
|
-
return params.some((param) => param.type === 'PathExpression');
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
if (hasPathExpression(part.params)) {
|
|
270
|
-
return AST.builders.mustache(AST.builders.path('get'), [
|
|
271
|
-
AST.builders.path(`this.${data.__styles__}`),
|
|
272
|
-
AST.builders.sexpr(part.path.original, part.params),
|
|
273
|
-
]);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
const params = part.params.map(transformParam);
|
|
277
|
-
|
|
278
|
-
return AST.builders.mustache('local-class', [
|
|
279
|
-
AST.builders.path(`this.${data.__styles__}`),
|
|
280
|
-
...params,
|
|
281
|
-
]);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
case 'if':
|
|
285
|
-
case 'unless': {
|
|
286
|
-
const params = part.params.map(transformParam);
|
|
287
|
-
|
|
288
|
-
return AST.builders.mustache('local-class', [
|
|
289
|
-
AST.builders.path(`this.${data.__styles__}`),
|
|
290
|
-
AST.builders.sexpr(part.path.original, params),
|
|
291
|
-
]);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
default: {
|
|
295
|
-
return AST.builders.mustache(AST.builders.path('get'), [
|
|
296
|
-
AST.builders.path(`this.${data.__styles__}`),
|
|
297
|
-
part.path,
|
|
298
|
-
]);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
case 'TextNode': {
|
|
304
|
-
const value = part.chars.trim();
|
|
305
|
-
|
|
306
|
-
if (value === '') {
|
|
307
|
-
return part;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
const localClassNames = value.split(/\s+/);
|
|
311
|
-
|
|
312
|
-
if (localClassNames.length === 1) {
|
|
313
|
-
return AST.builders.mustache(
|
|
314
|
-
AST.builders.path(`this.${data.__styles__}.${localClassNames[0]}`),
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
return AST.builders.mustache(AST.builders.path('local-class'), [
|
|
319
|
-
AST.builders.path(`this.${data.__styles__}`),
|
|
320
|
-
...localClassNames.map(AST.builders.string),
|
|
321
|
-
]);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
function transformParts(parts) {
|
|
327
|
-
const numParts = parts.length;
|
|
328
|
-
|
|
329
|
-
return parts.reduce((accumulator, part, index) => {
|
|
330
|
-
accumulator.push(transformPart(part));
|
|
331
|
-
|
|
332
|
-
if (index < numParts - 1) {
|
|
333
|
-
accumulator.push(AST.builders.text(' '));
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
return accumulator;
|
|
337
|
-
}, []);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
const traverse = AST.traverse();
|
|
341
|
-
|
|
342
|
-
const ast = traverse(file, {
|
|
343
|
-
ElementNode(node) {
|
|
344
|
-
// Check if the local-class attribute (still) exists
|
|
345
|
-
const { attributes } = node;
|
|
346
|
-
|
|
347
|
-
const localClassAttributeIndex = attributes.findIndex(
|
|
348
|
-
(attribute) => attribute.name === 'local-class',
|
|
349
|
-
);
|
|
350
|
-
|
|
351
|
-
if (localClassAttributeIndex === -1) {
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
// Change the local-class attribute to class
|
|
356
|
-
const localClassAttribute = attributes[localClassAttributeIndex];
|
|
357
|
-
|
|
358
|
-
switch (localClassAttribute.value.type) {
|
|
359
|
-
case 'ConcatStatement': {
|
|
360
|
-
localClassAttribute.name = 'class';
|
|
361
|
-
localClassAttribute.value.parts = transformParts(
|
|
362
|
-
localClassAttribute.value.parts,
|
|
363
|
-
);
|
|
364
|
-
|
|
365
|
-
break;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
case 'MustacheStatement': {
|
|
369
|
-
localClassAttribute.name = 'class';
|
|
370
|
-
localClassAttribute.value = transformPart(localClassAttribute.value);
|
|
371
|
-
|
|
372
|
-
break;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
case 'TextNode': {
|
|
376
|
-
localClassAttribute.name = 'class';
|
|
377
|
-
localClassAttribute.value = transformPart(localClassAttribute.value);
|
|
378
|
-
|
|
379
|
-
break;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
},
|
|
383
|
-
|
|
384
|
-
HashPair(node) {
|
|
385
|
-
if (node.key !== 'local-class') {
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
node.key = 'class';
|
|
390
|
-
node.value = AST.builders.sexpr('local-class', [
|
|
391
|
-
AST.builders.path(`this.${data.__styles__}`),
|
|
392
|
-
transformParam(node.value),
|
|
393
|
-
]);
|
|
394
|
-
},
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
return AST.print(ast);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
function updateTemplate(customizations, options) {
|
|
401
|
-
const { filePath } = customizations;
|
|
402
|
-
const { __styles__, projectRoot } = options;
|
|
403
|
-
|
|
404
|
-
let file = readFileSync(join(projectRoot, filePath), 'utf8');
|
|
405
|
-
|
|
406
|
-
try {
|
|
407
|
-
file = sanitizeClassAndLocalClassAttributes(file);
|
|
408
|
-
|
|
409
|
-
file = mergeClassAndLocalClassAttributes(file, {
|
|
410
|
-
__styles__,
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
file = removeLocalClassHelpers(file, {
|
|
414
|
-
__styles__,
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
file = removeLocalClassAttributes(file, {
|
|
418
|
-
__styles__,
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
const fileMapping = new Map([[filePath, file]]);
|
|
422
|
-
|
|
423
|
-
createFiles(fileMapping, options);
|
|
424
|
-
} catch (e) {
|
|
425
|
-
console.warn(
|
|
426
|
-
`WARNING: updateTemplate could not update \`${filePath}\`. Please update the file manually. (${e.message})\n`,
|
|
427
|
-
);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
export function updateTemplates(customizations, options) {
|
|
432
|
-
const { entities, getFilePath } = customizations;
|
|
433
|
-
|
|
434
|
-
for (const [entityName, extensions] of entities) {
|
|
435
|
-
const hasTemplate = extensions.has('.hbs');
|
|
436
|
-
|
|
437
|
-
if (!hasTemplate) {
|
|
438
|
-
continue;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
const filePath = getFilePath(entityName);
|
|
442
|
-
|
|
443
|
-
updateTemplate({ filePath }, options);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { extname, join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
import { ASTJavaScript as AST } from '@codemod-utils/ast';
|
|
5
|
-
import { createFiles, findFiles } from '@codemod-utils/files';
|
|
6
|
-
|
|
7
|
-
function addCssEntryPoint(file, data) {
|
|
8
|
-
const traverse = AST.traverse(data.isTypeScript);
|
|
9
|
-
|
|
10
|
-
const ast = traverse(file, {
|
|
11
|
-
visitProgram(path) {
|
|
12
|
-
const nodesToAdd = [
|
|
13
|
-
AST.builders.importDeclaration(
|
|
14
|
-
[],
|
|
15
|
-
AST.builders.literal('./assets/app.css'),
|
|
16
|
-
),
|
|
17
|
-
AST.builders.noop(),
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
path.value.body.unshift(...nodesToAdd);
|
|
21
|
-
|
|
22
|
-
return false;
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
return AST.print(ast);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function updateAppAppJs(options) {
|
|
30
|
-
const { projectRoot } = options;
|
|
31
|
-
|
|
32
|
-
const filePaths = findFiles('app/app.{js,ts}', {
|
|
33
|
-
projectRoot,
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
if (filePaths.length !== 1) {
|
|
37
|
-
console.warn(
|
|
38
|
-
'WARNING: updateAppAppJs could not find app.{js,ts} in the app folder. Will skip this step.\n',
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const filePath = filePaths[0];
|
|
45
|
-
|
|
46
|
-
const fileExtension = extname(filePath);
|
|
47
|
-
const isTypeScript = fileExtension === '.ts';
|
|
48
|
-
|
|
49
|
-
let file = readFileSync(join(projectRoot, filePath), 'utf8');
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
file = addCssEntryPoint(file, {
|
|
53
|
-
isTypeScript,
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
const fileMapping = new Map([[filePath, file]]);
|
|
57
|
-
|
|
58
|
-
createFiles(fileMapping, options);
|
|
59
|
-
} catch (e) {
|
|
60
|
-
console.warn(
|
|
61
|
-
`WARNING: updateAppAppJs could not update \`${filePath}\`. Please update the file manually. (${e.message})\n`,
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
2
|
-
|
|
3
|
-
import { updateTemplates } from './shared/index.js';
|
|
4
|
-
|
|
5
|
-
function getFilePath(options) {
|
|
6
|
-
const { componentStructure } = options;
|
|
7
|
-
|
|
8
|
-
return function (entityName) {
|
|
9
|
-
let filePath = join('app/components', entityName);
|
|
10
|
-
|
|
11
|
-
if (componentStructure === 'nested') {
|
|
12
|
-
filePath += '/index';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
filePath += '.hbs';
|
|
16
|
-
|
|
17
|
-
return filePath;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function updateComponentTemplates(context, options) {
|
|
22
|
-
const customizations = {
|
|
23
|
-
entities: context.components,
|
|
24
|
-
getFilePath: getFilePath(options),
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
updateTemplates(customizations, options);
|
|
28
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { writeFileSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
convertToMap,
|
|
6
|
-
convertToObject,
|
|
7
|
-
readPackageJson,
|
|
8
|
-
} from '@codemod-utils/json';
|
|
9
|
-
|
|
10
|
-
import { getVersion } from '../../../utils/blueprints.js';
|
|
11
|
-
|
|
12
|
-
function updateDevDependencies(packageJson, options) {
|
|
13
|
-
const { project } = options;
|
|
14
|
-
|
|
15
|
-
const devDependencies = convertToMap(packageJson['devDependencies']);
|
|
16
|
-
|
|
17
|
-
const packagesToDelete = ['ember-css-modules'];
|
|
18
|
-
|
|
19
|
-
packagesToDelete.forEach((packageName) => {
|
|
20
|
-
devDependencies.delete(packageName);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const packagesToInstall = new Set(['embroider-css-modules']);
|
|
24
|
-
|
|
25
|
-
if (project.hasTypeScript) {
|
|
26
|
-
packagesToInstall.add('type-css-modules');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
[...packagesToInstall].sort().forEach((packageName) => {
|
|
30
|
-
const version = getVersion(packageName, options);
|
|
31
|
-
|
|
32
|
-
devDependencies.set(packageName, version);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
packageJson['devDependencies'] = convertToObject(devDependencies);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function updateScripts(packageJson, options) {
|
|
39
|
-
const { project } = options;
|
|
40
|
-
|
|
41
|
-
const scripts = convertToMap(packageJson.scripts);
|
|
42
|
-
|
|
43
|
-
if (project.hasTypeScript) {
|
|
44
|
-
scripts.set('prelint:types', 'type-css-modules --src app');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
packageJson['scripts'] = convertToObject(scripts);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function updatePackageJson(options) {
|
|
51
|
-
const { projectRoot } = options;
|
|
52
|
-
|
|
53
|
-
const packageJson = readPackageJson(options);
|
|
54
|
-
updateDevDependencies(packageJson, options);
|
|
55
|
-
updateScripts(packageJson, options);
|
|
56
|
-
|
|
57
|
-
const destination = join(projectRoot, 'package.json');
|
|
58
|
-
const file = JSON.stringify(packageJson, null, 2) + '\n';
|
|
59
|
-
|
|
60
|
-
writeFileSync(destination, file, 'utf8');
|
|
61
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
2
|
-
|
|
3
|
-
import { updateTemplates } from './shared/index.js';
|
|
4
|
-
|
|
5
|
-
function getFilePath() {
|
|
6
|
-
return function (entityName) {
|
|
7
|
-
let filePath = join('app/templates', entityName);
|
|
8
|
-
|
|
9
|
-
filePath += '.hbs';
|
|
10
|
-
|
|
11
|
-
return filePath;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function updateRouteTemplates(context, options) {
|
|
16
|
-
const customizations = {
|
|
17
|
-
entities: context.routes,
|
|
18
|
-
getFilePath: getFilePath(),
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
updateTemplates(customizations, options);
|
|
22
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { decideVersion } from '@codemod-utils/blueprints';
|
|
2
|
-
|
|
3
|
-
const latestVersions = new Map([
|
|
4
|
-
['embroider-css-modules', '0.1.6'],
|
|
5
|
-
['type-css-modules', '0.1.4'],
|
|
6
|
-
['webpack', '5.86.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
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/* https://github.com/ember-cli/ember-cli-string-utils/blob/v1.1.0/index.js */
|
|
2
|
-
const STRING_CAMELIZE_REGEXP = /(-|_|\.|\s)+(.)?/g;
|
|
3
|
-
|
|
4
|
-
export function camelize(string) {
|
|
5
|
-
return string
|
|
6
|
-
.replace(STRING_CAMELIZE_REGEXP, function (_match, _separator, character) {
|
|
7
|
-
return character ? character.toUpperCase() : '';
|
|
8
|
-
})
|
|
9
|
-
.replace(/^([A-Z])/, function (match) {
|
|
10
|
-
return match.toLowerCase();
|
|
11
|
-
});
|
|
12
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/* https://github.com/ember-cli/ember-cli-string-utils/blob/v1.1.0/index.js */
|
|
2
|
-
import { camelize } from './camelize.js';
|
|
3
|
-
|
|
4
|
-
export function classify(string) {
|
|
5
|
-
const tokens = string.split('.');
|
|
6
|
-
|
|
7
|
-
const tokensTransformed = tokens.map((token) => {
|
|
8
|
-
const camelized = camelize(token);
|
|
9
|
-
|
|
10
|
-
return camelized.charAt(0).toUpperCase() + camelized.substring(1);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
return tokensTransformed.join('.');
|
|
14
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { parse } from 'node:path';
|
|
2
|
-
|
|
3
|
-
import { classifyEntityName } from './classify.js';
|
|
4
|
-
import { doubleColonizeEntityName } from './double-colonize.js';
|
|
5
|
-
|
|
6
|
-
export function parseEntityName(entityName) {
|
|
7
|
-
const classifiedName = classifyEntityName(entityName);
|
|
8
|
-
const doubleColonizedName = doubleColonizeEntityName(entityName);
|
|
9
|
-
const { name: fileName } = parse(entityName);
|
|
10
|
-
|
|
11
|
-
const entity = {
|
|
12
|
-
classifiedName,
|
|
13
|
-
doubleColonizedName,
|
|
14
|
-
fileName,
|
|
15
|
-
name: entityName,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
return entity;
|
|
19
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|