@storybook/codemod 6.5.9 → 7.0.0-alpha.10
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/lib/utils.js +5 -0
- package/dist/cjs/transforms/csf-2-to-3.js +5 -1
- package/dist/esm/lib/utils.js +5 -0
- package/dist/esm/transforms/csf-2-to-3.js +5 -1
- package/dist/{ts3.9 → types}/lib/utils.d.ts +0 -0
- package/dist/{ts3.9 → types}/transforms/csf-2-to-3.d.ts +0 -0
- package/package.json +5 -7
- package/dist/modern/index.js +0 -99
- package/dist/modern/lib/utils.js +0 -25
- package/dist/modern/transforms/add-component-parameters.js +0 -57
- package/dist/modern/transforms/csf-2-to-3.js +0 -159
- package/dist/modern/transforms/csf-hoist-story-annotations.js +0 -86
- package/dist/modern/transforms/csf-to-mdx.js +0 -188
- package/dist/modern/transforms/mdx-to-csf.js +0 -139
- package/dist/modern/transforms/move-builtin-addons.js +0 -50
- package/dist/modern/transforms/storiesof-to-csf.js +0 -287
- package/dist/modern/transforms/update-addon-info.js +0 -94
- package/dist/modern/transforms/update-organisation-name.js +0 -74
- package/dist/modern/transforms/upgrade-hierarchy-separators.js +0 -35
- package/dist/ts3.4/lib/utils.d.ts +0 -2
- package/dist/ts3.4/transforms/csf-2-to-3.d.ts +0 -6
@@ -1,94 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Takes the deprecated addon-info API, addWithInfo, and
|
3
|
-
* converts to the new withInfo API.
|
4
|
-
*
|
5
|
-
* Example of deprecated addWithInfo API:
|
6
|
-
*
|
7
|
-
* storiesOf('Button')
|
8
|
-
* .addWithInfo(
|
9
|
-
* 'story name',
|
10
|
-
* 'Story description.',
|
11
|
-
* () => (
|
12
|
-
* <Button label="The Button" />
|
13
|
-
* )
|
14
|
-
* )
|
15
|
-
*
|
16
|
-
* Converts to the new withInfo API:
|
17
|
-
*
|
18
|
-
* storiesOf('Button')
|
19
|
-
* .add('story name', withInfo(
|
20
|
-
* 'Story description.'
|
21
|
-
* )(() => (
|
22
|
-
* <Button label="The Button" />
|
23
|
-
* )))
|
24
|
-
*/
|
25
|
-
export default function transformer(file, api) {
|
26
|
-
var j = api.jscodeshift;
|
27
|
-
var root = j(file.source);
|
28
|
-
/**
|
29
|
-
* Returns a list of parameters for the withInfo function. The contents
|
30
|
-
* of this list is either the second argument from the original
|
31
|
-
* addWithInfo function, if no additional options were used, or a
|
32
|
-
* combined object of all the options from the original function.
|
33
|
-
* @param {list} args - original addWithInfo function parameters
|
34
|
-
* @return {list} the modified list of parameters for the new function
|
35
|
-
*/
|
36
|
-
|
37
|
-
var getOptions = function (args) {
|
38
|
-
if (args[3] === undefined) {
|
39
|
-
if (args[2] === undefined) {
|
40
|
-
// when the optional description string is not supplied for addWithInfo, use story name
|
41
|
-
return [args[0]];
|
42
|
-
}
|
43
|
-
|
44
|
-
return [args[1]];
|
45
|
-
}
|
46
|
-
|
47
|
-
return [j.objectExpression([j.property('init', j.identifier('text'), args[1]), ...args[3].properties])];
|
48
|
-
};
|
49
|
-
/**
|
50
|
-
* Constructs the new withInfo function from the parameters of the
|
51
|
-
* original addWithInfo function.
|
52
|
-
* @param {CallExpression} addWithInfoExpression - original function
|
53
|
-
* @returns {CallExpression} the new withInfo function
|
54
|
-
*/
|
55
|
-
|
56
|
-
|
57
|
-
var withInfo = function (addWithInfoExpression) {
|
58
|
-
var node = addWithInfoExpression.node;
|
59
|
-
var args = node.arguments; // if optional description string is not supplied, the story component becomes second arg
|
60
|
-
|
61
|
-
var storyComponent = args[2] ? args[2] : args[1];
|
62
|
-
node.callee.property.name = 'add';
|
63
|
-
node.arguments = [args[0], j.callExpression(j.callExpression(j.identifier('withInfo'), getOptions(args)), [storyComponent])];
|
64
|
-
return node;
|
65
|
-
};
|
66
|
-
/**
|
67
|
-
* Checks for - import { withInfo } from "@storybook/addon-info";
|
68
|
-
* Adds the import if necessary.
|
69
|
-
*/
|
70
|
-
|
71
|
-
|
72
|
-
var checkWithInfoImport = function () {
|
73
|
-
var importExists = root.find(j.ImportDeclaration).filter(function (imp) {
|
74
|
-
return imp.node.source.value === '@storybook/addon-info';
|
75
|
-
}).size();
|
76
|
-
if (importExists) return;
|
77
|
-
root.find(j.ImportDeclaration).at(-1).insertAfter(j.importDeclaration([j.importSpecifier(j.identifier('withInfo'))], j.literal('@storybook/addon-info')));
|
78
|
-
};
|
79
|
-
|
80
|
-
var addWithInfoExpressions = root.find(j.CallExpression, {
|
81
|
-
callee: {
|
82
|
-
property: {
|
83
|
-
name: 'addWithInfo'
|
84
|
-
}
|
85
|
-
}
|
86
|
-
});
|
87
|
-
|
88
|
-
if (addWithInfoExpressions.size()) {
|
89
|
-
checkWithInfoImport();
|
90
|
-
addWithInfoExpressions.replaceWith(withInfo);
|
91
|
-
}
|
92
|
-
|
93
|
-
return root.toSource();
|
94
|
-
}
|
@@ -1,74 +0,0 @@
|
|
1
|
-
export var packageNames = {
|
2
|
-
'@kadira/react-storybook-decorator-centered': '@storybook/addon-centered',
|
3
|
-
'@kadira/storybook-addons': '@storybook/addons',
|
4
|
-
'@kadira/storybook-addon-actions': '@storybook/addon-actions',
|
5
|
-
'@kadira/storybook-addon-comments': '@storybook/addon-comments',
|
6
|
-
'@kadira/storybook-addon-graphql': '@storybook/addon-graphql',
|
7
|
-
'@kadira/storybook-addon-info': '@storybook/addon-info',
|
8
|
-
'@kadira/storybook-addon-knobs': '@storybook/addon-knobs',
|
9
|
-
'@kadira/storybook-addon-links': '@storybook/addon-links',
|
10
|
-
'@kadira/storybook-addon-notes': '@storybook/addon-notes',
|
11
|
-
'@kadira/storybook-addon-options': '@storybook/addon-options',
|
12
|
-
'@kadira/storybook-channels': '@storybook/channels',
|
13
|
-
'@kadira/storybook-channel-postmsg': '@storybook/channel-postmessage',
|
14
|
-
'@kadira/storybook-channel-websocket': '@storybook/channel-websocket',
|
15
|
-
'@kadira/storybook-ui': '@storybook/ui',
|
16
|
-
'@kadira/react-native-storybook': '@storybook/react-native',
|
17
|
-
'@kadira/react-storybook': '@storybook/react',
|
18
|
-
'@kadira/getstorybook': '@storybook/cli',
|
19
|
-
'@kadira/storybook': '@storybook/react',
|
20
|
-
storyshots: '@storybook/addon-storyshots',
|
21
|
-
getstorybook: '@storybook/cli'
|
22
|
-
};
|
23
|
-
export default function transformer(file, api) {
|
24
|
-
var j = api.jscodeshift;
|
25
|
-
var packageNamesKeys = Object.keys(packageNames);
|
26
|
-
/**
|
27
|
-
* Checks whether the node value matches a Storybook package
|
28
|
-
* @param {string} the import declaration node
|
29
|
-
* @returns {string} whether the node value matches a Storybook package
|
30
|
-
*/
|
31
|
-
|
32
|
-
var getMatch = function (oldpart) {
|
33
|
-
return packageNamesKeys.find(function (newpart) {
|
34
|
-
return oldpart.match(newpart);
|
35
|
-
});
|
36
|
-
};
|
37
|
-
/**
|
38
|
-
* Returns the name of the Storybook packages with the organisation name,
|
39
|
-
* replacing the old `@kadira/` prefix.
|
40
|
-
* @param {string} oldPackageName the name of the old package
|
41
|
-
* @return {string} the new package name
|
42
|
-
* @example
|
43
|
-
* // returns '@storybook/storybook'
|
44
|
-
* getNewPackageName('@kadira/storybook')
|
45
|
-
*/
|
46
|
-
|
47
|
-
|
48
|
-
var getNewPackageName = function (oldPackageName) {
|
49
|
-
var match = getMatch(oldPackageName);
|
50
|
-
|
51
|
-
if (match) {
|
52
|
-
var replacement = packageNames[match];
|
53
|
-
return oldPackageName.replace(match, replacement);
|
54
|
-
}
|
55
|
-
|
56
|
-
return oldPackageName;
|
57
|
-
};
|
58
|
-
/**
|
59
|
-
* updatePackageName - updates the source name of the Storybook packages
|
60
|
-
* @param {ImportDeclaration} declaration the import declaration
|
61
|
-
* @returns {ImportDeclaration.Node} the import declaration node
|
62
|
-
*/
|
63
|
-
|
64
|
-
|
65
|
-
var updatePackageName = function (declaration) {
|
66
|
-
// eslint-disable-next-line no-param-reassign
|
67
|
-
declaration.node.source.value = getNewPackageName(declaration.node.source.value);
|
68
|
-
return declaration.node;
|
69
|
-
};
|
70
|
-
|
71
|
-
return j(file.source).find(j.ImportDeclaration).replaceWith(updatePackageName).toSource({
|
72
|
-
quote: 'single'
|
73
|
-
});
|
74
|
-
}
|
@@ -1,35 +0,0 @@
|
|
1
|
-
function upgradeSeparator(path) {
|
2
|
-
return path.replace(/[|.]/g, '/');
|
3
|
-
}
|
4
|
-
|
5
|
-
export default function transformer(file, api, options) {
|
6
|
-
var j = api.jscodeshift;
|
7
|
-
var root = j(file.source); // storiesOf(...)
|
8
|
-
|
9
|
-
root.find(j.CallExpression).filter(function (call) {
|
10
|
-
return call.node.callee.name === 'storiesOf';
|
11
|
-
}).filter(function (call) {
|
12
|
-
return call.node.arguments.length > 0 && ['Literal', 'StringLiteral'].includes(call.node.arguments[0].type);
|
13
|
-
}).forEach(function (call) {
|
14
|
-
var arg0 = call.node.arguments[0];
|
15
|
-
arg0.value = upgradeSeparator(arg0.value);
|
16
|
-
}); // export default { title: ... }
|
17
|
-
|
18
|
-
root.find(j.ExportDefaultDeclaration).filter(function (def) {
|
19
|
-
return def.node.declaration.properties.map(function (p) {
|
20
|
-
return p.key.name;
|
21
|
-
}).includes('title');
|
22
|
-
}).forEach(function (def) {
|
23
|
-
if (def.node.declaration && def.node.declaration.properties) {
|
24
|
-
def.node.declaration.properties.forEach(function (p) {
|
25
|
-
if (p.key.name === 'title') {
|
26
|
-
// eslint-disable-next-line no-param-reassign
|
27
|
-
p.value.value = upgradeSeparator(p.value.value);
|
28
|
-
}
|
29
|
-
});
|
30
|
-
}
|
31
|
-
});
|
32
|
-
return root.toSource({
|
33
|
-
quote: 'single'
|
34
|
-
});
|
35
|
-
}
|