@next/codemod 13.5.7-canary.27 → 13.5.7-canary.28
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/package.json
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function transformer(file, api) {
|
|
4
|
+
const j = api.jscodeshift;
|
|
5
|
+
const root = j(file.source);
|
|
6
|
+
// Find the metadata export
|
|
7
|
+
const metadataExport = root.find(j.ExportNamedDeclaration, {
|
|
8
|
+
declaration: {
|
|
9
|
+
type: 'VariableDeclaration',
|
|
10
|
+
declarations: [
|
|
11
|
+
{
|
|
12
|
+
id: { name: 'metadata' },
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
if (metadataExport.size() !== 1) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const metadataObject = metadataExport.find(j.ObjectExpression).get(0).node;
|
|
21
|
+
if (!metadataObject) {
|
|
22
|
+
console.error('Could not find metadata object');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
let metadataProperties = metadataObject.properties;
|
|
26
|
+
let viewportProperties;
|
|
27
|
+
const viewport = metadataProperties.find((prop) => prop.key.name === 'viewport');
|
|
28
|
+
if (viewport) {
|
|
29
|
+
viewportProperties = viewport.value.properties;
|
|
30
|
+
metadataProperties = metadataProperties.filter((prop) => prop.key.name !== 'viewport');
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
viewportProperties = [];
|
|
34
|
+
}
|
|
35
|
+
const colorScheme = metadataProperties.find((prop) => prop.key.name === 'colorScheme');
|
|
36
|
+
if (colorScheme) {
|
|
37
|
+
viewportProperties.push(colorScheme);
|
|
38
|
+
metadataProperties = metadataProperties.filter((prop) => prop.key.name !== 'colorScheme');
|
|
39
|
+
}
|
|
40
|
+
const themeColor = metadataProperties.find((prop) => prop.key.name === 'themeColor');
|
|
41
|
+
if (themeColor) {
|
|
42
|
+
viewportProperties.push(themeColor);
|
|
43
|
+
metadataProperties = metadataProperties.filter((prop) => prop.key.name !== 'themeColor');
|
|
44
|
+
}
|
|
45
|
+
// Update the metadata export
|
|
46
|
+
metadataExport
|
|
47
|
+
.find(j.ObjectExpression)
|
|
48
|
+
.replaceWith(j.objectExpression(metadataProperties));
|
|
49
|
+
// Create the new viewport object
|
|
50
|
+
const viewportExport = j.exportNamedDeclaration(j.variableDeclaration('const', [
|
|
51
|
+
j.variableDeclarator(j.identifier('viewport'), j.objectExpression(viewportProperties)),
|
|
52
|
+
]));
|
|
53
|
+
// Append the viewport export to the body of the program
|
|
54
|
+
if (viewportProperties.length) {
|
|
55
|
+
root.get().node.program.body.push(viewportExport);
|
|
56
|
+
}
|
|
57
|
+
return root.toSource();
|
|
58
|
+
}
|
|
59
|
+
exports.default = transformer;
|
|
60
|
+
//# sourceMappingURL=metadata-to-viewport-export.js.map
|