@atlaskit/forge-react-types 0.14.0 → 0.14.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/CHANGELOG.md +94 -83
- package/LICENSE.md +6 -8
- package/dist/cjs/components/__generated__/BoxProps.codegen.js +2 -2
- package/dist/es2019/components/__generated__/BoxProps.codegen.js +2 -2
- package/dist/esm/components/__generated__/BoxProps.codegen.js +2 -2
- package/dist/types/components/__generated__/BoxProps.codegen.d.ts +2 -2
- package/dist/types/components/__generated__/ButtonProps.codegen.d.ts +1 -1
- package/dist/types/components/__generated__/CheckboxGroupProps.codegen.d.ts +2 -2
- package/dist/types/components/__generated__/DatePickerProps.codegen.d.ts +1 -1
- package/dist/types/components/__generated__/FormProps.codegen.d.ts +2 -2
- package/dist/types/components/__generated__/IconProps.codegen.d.ts +2 -2
- package/dist/types/components/__generated__/ListItemProps.codegen.d.ts +2 -2
- package/dist/types/components/__generated__/ListProps.codegen.d.ts +2 -2
- package/dist/types/components/__generated__/types.codegen.d.ts +2 -2
- package/dist/types-ts4.5/components/__generated__/BoxProps.codegen.d.ts +2 -2
- package/dist/types-ts4.5/components/__generated__/ButtonProps.codegen.d.ts +1 -1
- package/dist/types-ts4.5/components/__generated__/CheckboxGroupProps.codegen.d.ts +2 -2
- package/dist/types-ts4.5/components/__generated__/DatePickerProps.codegen.d.ts +1 -1
- package/dist/types-ts4.5/components/__generated__/FormProps.codegen.d.ts +2 -2
- package/dist/types-ts4.5/components/__generated__/IconProps.codegen.d.ts +2 -2
- package/dist/types-ts4.5/components/__generated__/ListItemProps.codegen.d.ts +2 -2
- package/dist/types-ts4.5/components/__generated__/ListProps.codegen.d.ts +2 -2
- package/dist/types-ts4.5/components/__generated__/types.codegen.d.ts +2 -2
- package/package.json +71 -73
- package/scripts/codegen/codeGenerator.ts +306 -347
- package/scripts/codegen/componentPropTypes.ts +167 -212
- package/scripts/codegen-runner.ts +4 -4
- package/src/components/__generated__/BoxProps.codegen.tsx +2 -2
- package/src/components/__generated__/ButtonProps.codegen.tsx +358 -358
- package/src/components/__generated__/CheckboxGroupProps.codegen.tsx +8 -8
- package/src/components/__generated__/DatePickerProps.codegen.tsx +12 -12
- package/src/components/__generated__/FormProps.codegen.tsx +4 -4
- package/src/components/__generated__/IconProps.codegen.tsx +364 -364
- package/src/components/__generated__/ListItemProps.codegen.tsx +3 -3
- package/src/components/__generated__/ListProps.codegen.tsx +4 -4
- package/src/components/__generated__/types.codegen.ts +20 -20
- package/src/index.ts +58 -58
|
@@ -8,12 +8,11 @@ import fs from 'fs';
|
|
|
8
8
|
import { generateComponentPropTypeSourceCode } from './codeGenerator';
|
|
9
9
|
|
|
10
10
|
const forgeUIProject = new Project({
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
tsConfigFilePath: require.resolve('@atlassian/forge-ui/tsconfig.json'),
|
|
12
|
+
skipAddingFilesFromTsConfig: true,
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
const isExportSpecifier = (node: Node): node is ExportSpecifier =>
|
|
16
|
-
'getExportDeclaration' in node;
|
|
15
|
+
const isExportSpecifier = (node: Node): node is ExportSpecifier => 'getExportDeclaration' in node;
|
|
17
16
|
|
|
18
17
|
const isSourceFile = (node: Node): node is SourceFile => 'getFilePath' in node;
|
|
19
18
|
|
|
@@ -24,176 +23,146 @@ const isSourceFile = (node: Node): node is SourceFile => 'getFilePath' in node;
|
|
|
24
23
|
* in the index file will resolve to:
|
|
25
24
|
* platform/packages/forge/forge-ui/src/components/UIKit2-codegen/badge/__generated__/index.partial.tsx
|
|
26
25
|
*/
|
|
27
|
-
const loadComponentSourceFile = (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
} finally {
|
|
58
|
-
if (nestedSourceFile) {
|
|
59
|
-
// unload the parent source file if nested source file is found
|
|
60
|
-
project.removeSourceFile(sourceFile);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
26
|
+
const loadComponentSourceFile = (componentSymbol: Symbol, project: Project): SourceFile | null => {
|
|
27
|
+
const declaration = componentSymbol.getDeclarations()[0];
|
|
28
|
+
if (!declaration || !isExportSpecifier(declaration)) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const importSrcDeclaration = declaration
|
|
32
|
+
.getExportDeclaration()
|
|
33
|
+
.getModuleSpecifier()
|
|
34
|
+
?.getSymbol()
|
|
35
|
+
?.getValueDeclaration();
|
|
36
|
+
if (!importSrcDeclaration || !isSourceFile(importSrcDeclaration)) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const importSrc = importSrcDeclaration.getFilePath();
|
|
40
|
+
const sourceFile = project.addSourceFileAtPath(importSrc);
|
|
41
|
+
const baseComponentSymbol = findBaseSymbolFromSourceFile(sourceFile, componentSymbol);
|
|
42
|
+
if (!baseComponentSymbol) {
|
|
43
|
+
return sourceFile;
|
|
44
|
+
}
|
|
45
|
+
// recursively resolve the source file of the base component symbol, it is
|
|
46
|
+
// needed for TagProps
|
|
47
|
+
let nestedSourceFile = loadComponentSourceFile(baseComponentSymbol!, project);
|
|
48
|
+
try {
|
|
49
|
+
return nestedSourceFile ?? sourceFile;
|
|
50
|
+
} finally {
|
|
51
|
+
if (nestedSourceFile) {
|
|
52
|
+
// unload the parent source file if nested source file is found
|
|
53
|
+
project.removeSourceFile(sourceFile);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
63
56
|
};
|
|
64
57
|
|
|
65
|
-
const findBaseSymbolFromSourceFile = (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
exportSymbol.getName() === symbol.getAliasedSymbol()!.getName()
|
|
73
|
-
);
|
|
74
|
-
});
|
|
58
|
+
const findBaseSymbolFromSourceFile = (sourceFile: SourceFile, symbol: Symbol) => {
|
|
59
|
+
return sourceFile.getExportSymbols().find((exportSymbol) => {
|
|
60
|
+
return (
|
|
61
|
+
exportSymbol.getName() === symbol.getName() ||
|
|
62
|
+
exportSymbol.getName() === symbol.getAliasedSymbol()!.getName()
|
|
63
|
+
);
|
|
64
|
+
});
|
|
75
65
|
};
|
|
76
66
|
|
|
77
67
|
const makeComponentPropTypeSourceCode = (
|
|
78
|
-
|
|
79
|
-
|
|
68
|
+
componentSymbol: Symbol,
|
|
69
|
+
componentSourceFile: SourceFile,
|
|
80
70
|
) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return generateComponentPropTypeSourceCode(
|
|
93
|
-
componentSymbol,
|
|
94
|
-
componentSourceFile,
|
|
95
|
-
);
|
|
71
|
+
const baseComponentSymbol = findBaseSymbolFromSourceFile(componentSourceFile, componentSymbol);
|
|
72
|
+
if (!baseComponentSymbol) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
'Could not find base component symbol for component: ' + componentSymbol.getName(),
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return generateComponentPropTypeSourceCode(componentSymbol, componentSourceFile);
|
|
96
79
|
};
|
|
97
80
|
|
|
98
81
|
const generateComponentPropTypeSourceFiles = (
|
|
99
|
-
|
|
100
|
-
|
|
82
|
+
componentOutputDir: string,
|
|
83
|
+
componentPropTypeSymbols: Symbol[],
|
|
101
84
|
) => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
} finally {
|
|
138
|
-
forgeUIProject.removeSourceFile(componentSourceFile);
|
|
139
|
-
}
|
|
140
|
-
} else {
|
|
141
|
-
// eslint-disable-next-line no-console
|
|
142
|
-
console.error(
|
|
143
|
-
`Could not find source file for component: ${componentSymbol.getName()}`,
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
85
|
+
// eslint-disable-next-line no-console
|
|
86
|
+
console.log('Generating component prop type source files');
|
|
87
|
+
|
|
88
|
+
// iterate component prop declarations in the index file
|
|
89
|
+
componentPropTypeSymbols.forEach((componentSymbol) => {
|
|
90
|
+
const componentSourceFile = loadComponentSourceFile(componentSymbol, forgeUIProject);
|
|
91
|
+
if (componentSourceFile) {
|
|
92
|
+
try {
|
|
93
|
+
const sourceCode = makeComponentPropTypeSourceCode(componentSymbol, componentSourceFile);
|
|
94
|
+
const sourceFilePath = resolve(
|
|
95
|
+
componentOutputDir,
|
|
96
|
+
`${componentSymbol.getName()}.codegen.tsx`,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const signedSourceCode = createSignedArtifact(
|
|
100
|
+
sourceCode,
|
|
101
|
+
'yarn workspace @atlaskit/forge-react-types codegen',
|
|
102
|
+
{
|
|
103
|
+
description: `Extract component prop types from UIKit 2 components - ${componentSymbol.getName()}`,
|
|
104
|
+
dependencies: [componentSourceFile.getFilePath()],
|
|
105
|
+
outputFolder: componentOutputDir,
|
|
106
|
+
},
|
|
107
|
+
);
|
|
108
|
+
fs.writeFileSync(sourceFilePath, signedSourceCode);
|
|
109
|
+
|
|
110
|
+
// eslint-disable-next-line no-console
|
|
111
|
+
console.log(`Generated component prop type file: ${componentSymbol.getName()}`);
|
|
112
|
+
} finally {
|
|
113
|
+
forgeUIProject.removeSourceFile(componentSourceFile);
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
// eslint-disable-next-line no-console
|
|
117
|
+
console.error(`Could not find source file for component: ${componentSymbol.getName()}`);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
147
120
|
};
|
|
148
121
|
|
|
149
|
-
const updatePackageJsonWithADSComponentDependencies = (
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}, {});
|
|
194
|
-
|
|
195
|
-
packageJson.dependencies = updatedDependencies;
|
|
196
|
-
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
122
|
+
const updatePackageJsonWithADSComponentDependencies = (componentOutputDir: string) => {
|
|
123
|
+
// collect all @atlaskit dependencies from the generated code in the component output dir
|
|
124
|
+
const componentOutputProject = new Project({
|
|
125
|
+
tsConfigFilePath: require.resolve('../../tsconfig.json'),
|
|
126
|
+
});
|
|
127
|
+
const utilizedPackages = componentOutputProject
|
|
128
|
+
.getSourceFiles(`${componentOutputDir}/*.tsx`)
|
|
129
|
+
.reduce((packages, source) => {
|
|
130
|
+
source.getImportDeclarations().forEach((importDeclaration) => {
|
|
131
|
+
const importPath = importDeclaration.getModuleSpecifierValue();
|
|
132
|
+
// clean up import path so it contains only @atlaskit/package-name (without @atlaskit/package-name/further)
|
|
133
|
+
const packageMatch = importPath.match(/(@atlaskit\/[^/]+)/);
|
|
134
|
+
if (packageMatch) {
|
|
135
|
+
packages.add(packageMatch[1]);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
return packages;
|
|
139
|
+
}, new Set<string>());
|
|
140
|
+
|
|
141
|
+
// eslint-disable-next-line no-console
|
|
142
|
+
console.log('Updating package.json with ADS component dependencies');
|
|
143
|
+
|
|
144
|
+
const forgeUIPackageJson = JSON.parse(
|
|
145
|
+
fs.readFileSync(require.resolve('@atlassian/forge-ui/package.json')).toString(),
|
|
146
|
+
);
|
|
147
|
+
const packageJsonPath = resolve(__dirname, '..', '..', 'package.json');
|
|
148
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
149
|
+
|
|
150
|
+
// remove all existing @atlaskit dependencies from packageJson
|
|
151
|
+
const updatedDependencies = Object.entries<string>(packageJson.dependencies)
|
|
152
|
+
.filter(([key]) => !key.startsWith('@atlaskit/'))
|
|
153
|
+
.concat(
|
|
154
|
+
Object.entries<string>(forgeUIPackageJson.dependencies).filter(([key]) =>
|
|
155
|
+
utilizedPackages.has(key),
|
|
156
|
+
),
|
|
157
|
+
)
|
|
158
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
159
|
+
.reduce<Record<string, string>>((acc, [key, value]) => {
|
|
160
|
+
acc[key] = value;
|
|
161
|
+
return acc;
|
|
162
|
+
}, {});
|
|
163
|
+
|
|
164
|
+
packageJson.dependencies = updatedDependencies;
|
|
165
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
197
166
|
};
|
|
198
167
|
|
|
199
168
|
/**
|
|
@@ -201,59 +170,45 @@ const updatePackageJsonWithADSComponentDependencies = (
|
|
|
201
170
|
* to __generated__ folder.
|
|
202
171
|
*/
|
|
203
172
|
const generateSharedTypesFile = (componentOutputDir: string) => {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const typesFilePath = resolve(componentOutputDir, 'types.codegen.ts');
|
|
222
|
-
fs.writeFileSync(typesFilePath, signedSourceCode);
|
|
173
|
+
// eslint-disable-next-line no-console
|
|
174
|
+
console.log('Generating shared types file');
|
|
175
|
+
|
|
176
|
+
const uiKit2TypesFile = require.resolve('@atlassian/forge-ui/UIKit2-codegen/types');
|
|
177
|
+
|
|
178
|
+
const signedSourceCode = createSignedArtifact(
|
|
179
|
+
fs.readFileSync(uiKit2TypesFile, 'utf8'),
|
|
180
|
+
'yarn workspace @atlaskit/forge-react-types codegen',
|
|
181
|
+
{
|
|
182
|
+
description: 'Shared types file from UIKit 2',
|
|
183
|
+
dependencies: [uiKit2TypesFile],
|
|
184
|
+
outputFolder: componentOutputDir,
|
|
185
|
+
},
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
const typesFilePath = resolve(componentOutputDir, 'types.codegen.ts');
|
|
189
|
+
fs.writeFileSync(typesFilePath, signedSourceCode);
|
|
223
190
|
};
|
|
224
191
|
|
|
225
192
|
const generateComponentPropTypes = (componentPropTypeFilter?: string) => {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
// generate share types file first
|
|
246
|
-
generateSharedTypesFile(componentOutputDir);
|
|
247
|
-
|
|
248
|
-
generateComponentPropTypeSourceFiles(
|
|
249
|
-
componentOutputDir,
|
|
250
|
-
componentPropTypeSymbols,
|
|
251
|
-
);
|
|
252
|
-
|
|
253
|
-
updatePackageJsonWithADSComponentDependencies(componentOutputDir);
|
|
254
|
-
} finally {
|
|
255
|
-
forgeUIProject.removeSourceFile(componentIndexSourceFile);
|
|
256
|
-
}
|
|
193
|
+
const componentOutputDir = resolve(__dirname, '..', '..', 'src', 'components', '__generated__');
|
|
194
|
+
const componentIndexSourceFile = forgeUIProject.addSourceFileAtPath(
|
|
195
|
+
require.resolve('@atlassian/forge-ui/UIKit2-codegen'),
|
|
196
|
+
);
|
|
197
|
+
try {
|
|
198
|
+
const componentPropTypeSymbols = componentIndexSourceFile
|
|
199
|
+
.getExportSymbols()
|
|
200
|
+
.filter((symbol) => symbol.getName().endsWith(componentPropTypeFilter ?? 'Props'))
|
|
201
|
+
.sort((a, b) => a.getName().localeCompare(b.getName()));
|
|
202
|
+
|
|
203
|
+
// generate share types file first
|
|
204
|
+
generateSharedTypesFile(componentOutputDir);
|
|
205
|
+
|
|
206
|
+
generateComponentPropTypeSourceFiles(componentOutputDir, componentPropTypeSymbols);
|
|
207
|
+
|
|
208
|
+
updatePackageJsonWithADSComponentDependencies(componentOutputDir);
|
|
209
|
+
} finally {
|
|
210
|
+
forgeUIProject.removeSourceFile(componentIndexSourceFile);
|
|
211
|
+
}
|
|
257
212
|
};
|
|
258
213
|
|
|
259
214
|
export { generateComponentPropTypes };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { generateComponentPropTypes } from './codegen';
|
|
2
2
|
|
|
3
3
|
if (process.argv.length < 3) {
|
|
4
|
-
|
|
4
|
+
generateComponentPropTypes();
|
|
5
5
|
} else {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
// e.g yarn workspace @atlaskit/forge-react-types codegen ButtonProp
|
|
7
|
+
const componentPropTypeFilter = process.argv[2];
|
|
8
|
+
generateComponentPropTypes(componentPropTypeFilter);
|
|
9
9
|
}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Extract component prop types from UIKit 2 components - BoxProps
|
|
5
5
|
*
|
|
6
|
-
* @codegen <<SignedSource::
|
|
6
|
+
* @codegen <<SignedSource::ff889836988991365ebf829e9793e10d>>
|
|
7
7
|
* @codegenCommand yarn workspace @atlaskit/forge-react-types codegen
|
|
8
|
-
* @codegenDependency ../../../../forge-ui/src/components/UIKit2-codegen/box/__generated__/index.partial.tsx <<SignedSource::
|
|
8
|
+
* @codegenDependency ../../../../forge-ui/src/components/UIKit2-codegen/box/__generated__/index.partial.tsx <<SignedSource::c2e0a3f5394718d7a9864acb3ffccd00>>
|
|
9
9
|
*/
|
|
10
10
|
/* eslint-disable @atlaskit/design-system/ensure-design-token-usage/preview */
|
|
11
11
|
|