@teambit/react 0.0.565 → 0.0.569
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/compositions-app.tsx +31 -0
- package/dist/react.env.d.ts +0 -2
- package/dist/react.env.js +1 -38
- package/dist/react.env.js.map +1 -1
- package/dist/webpack/webpack.config.component.dev.d.ts +1 -1
- package/dist/webpack/webpack.config.component.dev.js +9 -13
- package/dist/webpack/webpack.config.component.dev.js.map +1 -1
- package/highlighter-widget.tsx +19 -0
- package/mount.tsx +17 -0
- package/package-tar/teambit-react-0.0.569.tgz +0 -0
- package/package.json +46 -61
- package/react.composition.tsx +7 -0
- package/react.ui.runtime.tsx +35 -0
- package/templates/react-app/files/app-root.ts +10 -0
- package/templates/react-app/files/app.ts +30 -0
- package/templates/react-app/files/aspect.ts +10 -0
- package/templates/react-app/files/compositions.ts +11 -0
- package/templates/react-app/files/doc.ts +29 -0
- package/templates/react-app/files/index.ts +10 -0
- package/templates/react-app/files/main.runtime.ts +22 -0
- package/templates/react-app/index.ts +47 -0
- package/templates/react-component/files/component.ts +25 -0
- package/templates/react-component/files/composition.ts +16 -0
- package/templates/react-component/files/docs.ts +32 -0
- package/templates/react-component/files/test.ts +19 -0
- package/templates/react-component/index.ts +40 -0
- package/templates/react-component-js/files/component.ts +18 -0
- package/templates/react-component-js/files/composition.ts +16 -0
- package/templates/react-component-js/files/docs.ts +32 -0
- package/templates/react-component-js/files/test.ts +21 -0
- package/templates/react-component-js/index.ts +38 -0
- package/templates/react-context/files/composition.ts +27 -0
- package/templates/react-context/files/context-provider.ts +27 -0
- package/templates/react-context/files/context.ts +21 -0
- package/templates/react-context/files/docs.ts +51 -0
- package/templates/react-context/files/test.ts +18 -0
- package/templates/react-context/index.ts +32 -0
- package/templates/react-env/files/aspect.ts +10 -0
- package/templates/react-env/files/doc.ts +163 -0
- package/templates/react-env/files/index.ts +10 -0
- package/templates/react-env/files/jest.config.ts +21 -0
- package/templates/react-env/files/main.runtime.ts +84 -0
- package/templates/react-env/files/preview.runtime.ts +27 -0
- package/templates/react-env/files/typescript.config.ts +21 -0
- package/templates/react-env/files/webpack.config.ts +48 -0
- package/templates/react-env/index.ts +51 -0
- package/templates/react-hook/files/component.ts +16 -0
- package/templates/react-hook/files/composition.ts +23 -0
- package/templates/react-hook/files/docs.ts +33 -0
- package/templates/react-hook/files/test.ts +20 -0
- package/templates/react-hook/index.ts +21 -0
- package/templates/react-workspace/index.ts +27 -0
- package/templates/react-workspace-app/index.ts +20 -0
- package/templates/react-workspace-deprecated/index.ts +28 -0
- package/templates/react-workspace-lib/index.ts +21 -0
- package/templates/workspace-common/files/eslint-config.ts +6 -0
- package/templates/workspace-common/files/git-ignore.ts +113 -0
- package/templates/workspace-common/files/prettier-config.ts +5 -0
- package/templates/workspace-common/files/readme-file.ts +36 -0
- package/templates/workspace-common/files/ts-config.ts +7 -0
- package/templates/workspace-common/files/types/asset.ts +28 -0
- package/templates/workspace-common/files/types/style.ts +43 -0
- package/templates/workspace-common/files/workspace-config.ts +58 -0
- package/templates/workspace-common/generate-files.ts +51 -0
- package/templates/workspace-common/index.ts +1 -0
- package/types/asset.d.ts +29 -0
- package/types/style.d.ts +42 -0
- package/typescript/asset.d.ts +29 -0
- package/typescript/style.d.ts +42 -0
- package/webpack/postcss.config.ts +21 -0
- package/webpack/webpack.config.base.prod.ts +123 -0
- package/webpack/webpack.config.base.ts +365 -0
- package/webpack/webpack.config.component.dev.ts +99 -0
- package/webpack/webpack.config.component.prod.ts +39 -0
- package/webpack/webpack.config.env.dev.ts +21 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { ComponentContext } from '@teambit/generator';
|
|
2
|
+
|
|
3
|
+
export function docFile({ name, componentId }: ComponentContext) {
|
|
4
|
+
return `---
|
|
5
|
+
description: 'A standard React component development environment'
|
|
6
|
+
labels: ['react', 'typescript', 'env', 'extension']
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
A customized version which extends the default React component development environment created by teambit. This environment can be applied to all your components or a set of components under the variants of your \`workspace.json\` file. That means they will use your custom environment instead of the default environment. Environment components are just like any other Bit components in that they can be exported and then shared and used in various projects which makes it easier to create standards when working with many teams.
|
|
12
|
+
|
|
13
|
+
### Usage instructions
|
|
14
|
+
|
|
15
|
+
Under the **variant** section of your \`workspace.json\` file choose which components you want to have the custom environment set. You can find the id of the extension in the \`${name}.aspect.ts\` file.
|
|
16
|
+
|
|
17
|
+
\`\`\`json
|
|
18
|
+
{
|
|
19
|
+
"teambit.workspace/variants": {
|
|
20
|
+
"{ui/**}, {pages/**}": {
|
|
21
|
+
"${componentId}": {}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
\`\`\`
|
|
26
|
+
|
|
27
|
+
## Runtime Configurations
|
|
28
|
+
|
|
29
|
+
Extend the \`main.runtime\` file when you want to add custom configurations at runtime.
|
|
30
|
+
|
|
31
|
+
### Compilation
|
|
32
|
+
|
|
33
|
+
By default, Component compilation is done with the TypeScript compiler. Target format is \`ES2015\` which
|
|
34
|
+
supports execution from both NodeJS and browser runtimes for server-side rendering. You can modify the \`tsconfig.json\` file to add your own compiler options which will then be merged with the default configs set by teambit.
|
|
35
|
+
|
|
36
|
+
Example:
|
|
37
|
+
|
|
38
|
+
\`\`\`json
|
|
39
|
+
{
|
|
40
|
+
"compilerOptions": {
|
|
41
|
+
"target": "es2017",
|
|
42
|
+
"module": "es2015",
|
|
43
|
+
"moduleResolution": "node",
|
|
44
|
+
"lib": ["es2017", "dom"],
|
|
45
|
+
"experimentalDecorators": true,
|
|
46
|
+
"esModuleInterop": true,
|
|
47
|
+
"outDir": "dist",
|
|
48
|
+
"sourceMap": true,
|
|
49
|
+
"emitDecoratorMetadata": true,
|
|
50
|
+
"allowJs": true,
|
|
51
|
+
"baseUrl": ".",
|
|
52
|
+
"jsx": "react"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
\`\`\`
|
|
56
|
+
|
|
57
|
+
### Testing
|
|
58
|
+
|
|
59
|
+
Component testing is done through [Jest](https://jestjs.io/) with the default \`teambit.react/react\` environment. You can modify the \`jestconfig.js\` file to add your own configurations which will then be merged with the default configs set by teambit.
|
|
60
|
+
|
|
61
|
+
Example:
|
|
62
|
+
|
|
63
|
+
To Override the Jest config to ignore transpiling from specific folders add this to the \`jestconfig.js\` file:
|
|
64
|
+
|
|
65
|
+
\`\`\`js
|
|
66
|
+
const reactJestConfig = require('@teambit/react/jest/jest.config');
|
|
67
|
+
module.exports = {
|
|
68
|
+
...reactJestConfig,
|
|
69
|
+
transformIgnorePatterns: ['/node_modules/(?!(prop-types|@teambit))']
|
|
70
|
+
};
|
|
71
|
+
\`\`\`
|
|
72
|
+
|
|
73
|
+
### Webpack
|
|
74
|
+
|
|
75
|
+
Bit uses webpack 5 to bundle components. You can modify the \`webpack.config.js\` file to add your own configurations which will then be merged with the default configs set by teambit.
|
|
76
|
+
|
|
77
|
+
Example:
|
|
78
|
+
|
|
79
|
+
\`\`\`ts
|
|
80
|
+
module.exports = {
|
|
81
|
+
module: {
|
|
82
|
+
// add your custom rules here
|
|
83
|
+
rules: []
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
\`\`\`
|
|
87
|
+
|
|
88
|
+
### ESLint
|
|
89
|
+
|
|
90
|
+
Bit uses ESLint to lint your components. You can add your own rules in the \`${name}.main.runtime\` file.
|
|
91
|
+
|
|
92
|
+
Example:
|
|
93
|
+
|
|
94
|
+
\`\`\`ts
|
|
95
|
+
react.useEslint({
|
|
96
|
+
transformers: [
|
|
97
|
+
(config) => {
|
|
98
|
+
config.setRule('no-console', ['error']);
|
|
99
|
+
// add more rules here
|
|
100
|
+
return config;
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
}),
|
|
104
|
+
\`\`\`
|
|
105
|
+
|
|
106
|
+
To use ESLint:
|
|
107
|
+
|
|
108
|
+
\`\`\`bash
|
|
109
|
+
bit lint
|
|
110
|
+
bit lint --fix
|
|
111
|
+
\`\`\`
|
|
112
|
+
|
|
113
|
+
### Formatting
|
|
114
|
+
|
|
115
|
+
Bit uses Prettier to format your components. You can add your own rules in the \`${name}.main.runtime\` file.
|
|
116
|
+
|
|
117
|
+
Example:
|
|
118
|
+
|
|
119
|
+
\`\`\`ts
|
|
120
|
+
react.usePrettier({
|
|
121
|
+
transformers: [
|
|
122
|
+
(config) => {
|
|
123
|
+
config.setKey('tabWidth', 2);
|
|
124
|
+
// add more rules here
|
|
125
|
+
return config;
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
}),
|
|
129
|
+
\`\`\`
|
|
130
|
+
|
|
131
|
+
To use Prettier:
|
|
132
|
+
|
|
133
|
+
\`\`\`bash
|
|
134
|
+
bit format --check
|
|
135
|
+
bit format
|
|
136
|
+
\`\`\`
|
|
137
|
+
|
|
138
|
+
### Dependencies
|
|
139
|
+
|
|
140
|
+
Override the default dependencies in the \`${name}.main.runtime\` file to include react types of a different version for example.
|
|
141
|
+
|
|
142
|
+
\`\`\`ts
|
|
143
|
+
react.overrideDependencies({
|
|
144
|
+
devDependencies: {
|
|
145
|
+
'@types/react': '17.0.3'
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
\`\`\`
|
|
149
|
+
|
|
150
|
+
## Preview Configurations
|
|
151
|
+
|
|
152
|
+
Extend the \`${name}.preview.runtime\` file when you want to add your own customizations only for previewing in the Bit UI.
|
|
153
|
+
|
|
154
|
+
### Adding a Theme
|
|
155
|
+
|
|
156
|
+
A custom theme has been added to the env which wraps all the composition files with the required theme so they can be developed with the correct themeing rather than the browsers default. This is added only in the preview runtime and not in the main runtime meaning it is only applied to compositions and not when consuming components. Adding a theme when consuming should be done at App level as you component may be consumed in various apps and have different themes applied depending on where it is consumed.
|
|
157
|
+
|
|
158
|
+
Example:
|
|
159
|
+
|
|
160
|
+
\`\`\`ts
|
|
161
|
+
react.registerProvider([ThemeCompositions]);
|
|
162
|
+
`;
|
|
163
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ComponentContext } from '@teambit/generator';
|
|
2
|
+
|
|
3
|
+
export function indexFile({ namePascalCase: Name, name }: ComponentContext) {
|
|
4
|
+
return `import { ${Name}Aspect } from './${name}.aspect';
|
|
5
|
+
|
|
6
|
+
export type { ${Name}Main } from './${name}.main.runtime';
|
|
7
|
+
export default ${Name}Aspect;
|
|
8
|
+
export { ${Name}Aspect };
|
|
9
|
+
`;
|
|
10
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function jestConfigFile() {
|
|
2
|
+
return `
|
|
3
|
+
// Override the Jest config to ignore transpiling from specific folders
|
|
4
|
+
// See the base Jest config: https://bit.dev/teambit/react/react/~code/jest/jest.config.js
|
|
5
|
+
|
|
6
|
+
// const reactJestConfig = require('@teambit/react/jest/jest.config');
|
|
7
|
+
// uncomment the line below and install the package if you want to use this function
|
|
8
|
+
// const {
|
|
9
|
+
// generateNodeModulesPattern,
|
|
10
|
+
// } = require('@teambit/dependencies.modules.packages-excluder');
|
|
11
|
+
// const packagesToExclude = ['prop-types', '@teambit'];
|
|
12
|
+
|
|
13
|
+
// module.exports = {
|
|
14
|
+
// ...reactJestConfig,
|
|
15
|
+
// transformIgnorePatterns: [
|
|
16
|
+
// ...reactJestConfig.transformIgnorePatterns,
|
|
17
|
+
// '/' + generateNodeModulesPattern({ packages: packagesToExclude }),
|
|
18
|
+
// ],
|
|
19
|
+
// };
|
|
20
|
+
`;
|
|
21
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ComponentContext } from '@teambit/generator';
|
|
2
|
+
|
|
3
|
+
export function mainRuntimeFile({ namePascalCase: Name, name }: ComponentContext) {
|
|
4
|
+
return `import { MainRuntime } from '@teambit/cli';
|
|
5
|
+
import { ReactAspect, ReactMain } from '@teambit/react';
|
|
6
|
+
import { EnvsAspect, EnvsMain } from '@teambit/envs';
|
|
7
|
+
import { ${Name}Aspect } from './${name}.aspect';
|
|
8
|
+
// import { previewConfigTransformer, devServerConfigTransformer } from './webpack/webpack-transformers';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Uncomment to include config files for overrides of Typescript or Webpack
|
|
12
|
+
*/
|
|
13
|
+
// const tsconfig = require('./typescript/tsconfig');
|
|
14
|
+
|
|
15
|
+
export class ${Name}Main {
|
|
16
|
+
static slots = [];
|
|
17
|
+
|
|
18
|
+
static dependencies = [ReactAspect, EnvsAspect];
|
|
19
|
+
|
|
20
|
+
static runtime = MainRuntime;
|
|
21
|
+
|
|
22
|
+
static async provider([react, envs]: [ReactMain, EnvsMain]) {
|
|
23
|
+
const templatesReactEnv = envs.compose(react.reactEnv, [
|
|
24
|
+
/**
|
|
25
|
+
* Uncomment to override the config files for TypeScript, Webpack or Jest
|
|
26
|
+
* Your config gets merged with the defaults
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
// react.overrideTsConfig(tsconfig),
|
|
30
|
+
// react.useWebpack({
|
|
31
|
+
// previewConfig: [previewConfigTransformer],
|
|
32
|
+
// devServerConfig: [devServerConfigTransformer],
|
|
33
|
+
// }),
|
|
34
|
+
// react.overrideJestConfig(require.resolve('./jest/jest.config')),
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* override the ESLint default config here then check your files for lint errors
|
|
38
|
+
* @example
|
|
39
|
+
* bit lint
|
|
40
|
+
* bit lint --fix
|
|
41
|
+
*/
|
|
42
|
+
react.useEslint({
|
|
43
|
+
transformers: [
|
|
44
|
+
(config) => {
|
|
45
|
+
config.setRule('no-console', ['error']);
|
|
46
|
+
return config;
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
}),
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* override the Prettier default config here the check your formatting
|
|
53
|
+
* @example
|
|
54
|
+
* bit format --check
|
|
55
|
+
* bit format
|
|
56
|
+
*/
|
|
57
|
+
react.usePrettier({
|
|
58
|
+
transformers: [
|
|
59
|
+
(config) => {
|
|
60
|
+
config.setKey('tabWidth', 2);
|
|
61
|
+
return config;
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
}),
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* override dependencies here
|
|
68
|
+
* @example
|
|
69
|
+
* Uncomment types to include version 17.0.3 of the types package
|
|
70
|
+
*/
|
|
71
|
+
react.overrideDependencies({
|
|
72
|
+
devDependencies: {
|
|
73
|
+
// '@types/react': '17.0.3'
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
]);
|
|
77
|
+
envs.registerEnv(templatesReactEnv);
|
|
78
|
+
return new ${Name}Main();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
${Name}Aspect.addRuntime(${Name}Main);
|
|
83
|
+
`;
|
|
84
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ComponentContext } from '@teambit/generator';
|
|
2
|
+
|
|
3
|
+
export function previewRuntimeFile({ namePascalCase: Name, nameCamelCase: nameCamel, name }: ComponentContext) {
|
|
4
|
+
return `import { PreviewRuntime } from '@teambit/preview';
|
|
5
|
+
import { ReactAspect, ReactPreview } from '@teambit/react';
|
|
6
|
+
// uncomment the line below and install the theme if you want to use our theme or create your own and import it here
|
|
7
|
+
// import { ThemeCompositions } from '@teambit/documenter.theme.theme-compositions';
|
|
8
|
+
|
|
9
|
+
import { ${Name}Aspect } from './${name}.aspect';
|
|
10
|
+
|
|
11
|
+
export class ${Name}PreviewMain {
|
|
12
|
+
static runtime = PreviewRuntime;
|
|
13
|
+
|
|
14
|
+
static dependencies = [ReactAspect];
|
|
15
|
+
|
|
16
|
+
static async provider([react]: [ReactPreview]) {
|
|
17
|
+
const ${nameCamel}PreviewMain = new ${Name}PreviewMain();
|
|
18
|
+
// uncomment the line below to register a new provider to wrap all compositions using this environment with a custom theme.
|
|
19
|
+
// react.registerProvider([ThemeCompositions]);
|
|
20
|
+
|
|
21
|
+
return ${nameCamel}PreviewMain;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
${Name}Aspect.addRuntime(${Name}PreviewMain);
|
|
26
|
+
`;
|
|
27
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function typescriptConfigFile() {
|
|
2
|
+
return `{
|
|
3
|
+
// add your compiler options here
|
|
4
|
+
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
// "target": "es2017",
|
|
7
|
+
// "module": "es2015",
|
|
8
|
+
// "moduleResolution": "node",
|
|
9
|
+
// "lib": ["es2017", "dom"],
|
|
10
|
+
// "experimentalDecorators": true,
|
|
11
|
+
// "esModuleInterop": true,
|
|
12
|
+
// "outDir": "dist",
|
|
13
|
+
// "sourceMap": true,
|
|
14
|
+
// "emitDecoratorMetadata": true,
|
|
15
|
+
// "allowJs": true,
|
|
16
|
+
// "baseUrl": ".",
|
|
17
|
+
// "jsx": "react"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export function webpackConfigFile() {
|
|
2
|
+
return `
|
|
3
|
+
import { WebpackConfigTransformer, WebpackConfigMutator, WebpackConfigTransformContext } from '@teambit/webpack';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Transformation to apply for both preview and dev server
|
|
7
|
+
* @param config
|
|
8
|
+
* @param _context
|
|
9
|
+
*/
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
11
|
+
function commonTransformation(config: WebpackConfigMutator, _context: WebpackConfigTransformContext) {
|
|
12
|
+
// Merge config with the webpack.config.js file if you choose to import a module export format config.
|
|
13
|
+
// config.merge([webpackConfig]);
|
|
14
|
+
// config.addAliases({});
|
|
15
|
+
// config.addModuleRule(youRuleHere);
|
|
16
|
+
return config;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Transformation for the preview only
|
|
21
|
+
* @param config
|
|
22
|
+
* @param context
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export const previewConfigTransformer: WebpackConfigTransformer = (
|
|
26
|
+
config: WebpackConfigMutator,
|
|
27
|
+
context: WebpackConfigTransformContext
|
|
28
|
+
) => {
|
|
29
|
+
const newConfig = commonTransformation(config, context);
|
|
30
|
+
return newConfig;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Transformation for the dev server only
|
|
35
|
+
* @param config
|
|
36
|
+
* @param context
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
export const devServerConfigTransformer: WebpackConfigTransformer = (
|
|
40
|
+
config: WebpackConfigMutator,
|
|
41
|
+
context: WebpackConfigTransformContext
|
|
42
|
+
) => {
|
|
43
|
+
const newConfig = commonTransformation(config, context);
|
|
44
|
+
return newConfig;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
`;
|
|
48
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ComponentContext, ComponentTemplate } from '@teambit/generator';
|
|
2
|
+
import { indexFile } from './files/index';
|
|
3
|
+
import { docFile } from './files/doc';
|
|
4
|
+
import { mainRuntimeFile } from './files/main.runtime';
|
|
5
|
+
import { previewRuntimeFile } from './files/preview.runtime';
|
|
6
|
+
import { aspectFile } from './files/aspect';
|
|
7
|
+
import { webpackConfigFile } from './files/webpack.config';
|
|
8
|
+
import { typescriptConfigFile } from './files/typescript.config';
|
|
9
|
+
import { jestConfigFile } from './files/jest.config';
|
|
10
|
+
|
|
11
|
+
export const reactEnvTemplate: ComponentTemplate = {
|
|
12
|
+
name: 'react-env',
|
|
13
|
+
description: 'customize the base React env with your configs and tools',
|
|
14
|
+
generateFiles: (context: ComponentContext) => {
|
|
15
|
+
return [
|
|
16
|
+
{
|
|
17
|
+
relativePath: 'index.ts',
|
|
18
|
+
content: indexFile(context),
|
|
19
|
+
isMain: true,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
relativePath: `${context.name}.docs.mdx`,
|
|
23
|
+
content: docFile(context),
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
relativePath: `${context.name}.main.runtime.ts`,
|
|
27
|
+
content: mainRuntimeFile(context),
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
relativePath: `${context.name}.preview.runtime.ts`,
|
|
31
|
+
content: previewRuntimeFile(context),
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
relativePath: `${context.name}.aspect.ts`,
|
|
35
|
+
content: aspectFile(context),
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
relativePath: `webpack/webpack-transformers.ts`,
|
|
39
|
+
content: webpackConfigFile(),
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
relativePath: `typescript/tsconfig.json`,
|
|
43
|
+
content: typescriptConfigFile(),
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
relativePath: `jest/jest.config.js`,
|
|
47
|
+
content: jestConfigFile(),
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
},
|
|
51
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ComponentContext } from '@teambit/generator';
|
|
2
|
+
|
|
3
|
+
export const componentFile = (context: ComponentContext) => {
|
|
4
|
+
const { name, nameCamelCase: Name } = context;
|
|
5
|
+
return {
|
|
6
|
+
relativePath: `${name}.tsx`,
|
|
7
|
+
content: `import { useState } from 'react';
|
|
8
|
+
|
|
9
|
+
export function ${Name}() {
|
|
10
|
+
const [count, setCount] = useState(0)
|
|
11
|
+
const increment = () => setCount((c) => c + 1)
|
|
12
|
+
return { count, increment }
|
|
13
|
+
}
|
|
14
|
+
`,
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ComponentContext } from '@teambit/generator';
|
|
2
|
+
|
|
3
|
+
export const compositionFile = (context: ComponentContext) => {
|
|
4
|
+
const { name, nameCamelCase: Name } = context;
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
relativePath: `${name}.composition.tsx`,
|
|
8
|
+
content: `import React from 'react';
|
|
9
|
+
import { ${Name} } from './${name}';
|
|
10
|
+
|
|
11
|
+
export const Basic${Name} = () => {
|
|
12
|
+
const { count, increment } = ${Name}();
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<>
|
|
16
|
+
<h1>The count is {count}</h1>
|
|
17
|
+
<button onClick={increment}>increment</button>
|
|
18
|
+
</>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
`,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ComponentContext } from '@teambit/generator';
|
|
2
|
+
|
|
3
|
+
export const docsFile = (context: ComponentContext) => {
|
|
4
|
+
const { name, nameCamelCase: Name } = context;
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
relativePath: `${name}.docs.mdx`,
|
|
8
|
+
content: `---
|
|
9
|
+
description: 'A React Hook that increments a count by 1 each time it is called.'
|
|
10
|
+
labels: ['hook', 'counter']
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
import { ${Name} } from './${name}';
|
|
14
|
+
|
|
15
|
+
## A React Hook to increment a count
|
|
16
|
+
|
|
17
|
+
Increments the state of \`count\` by 1 each time \`increment\` is called
|
|
18
|
+
|
|
19
|
+
### Component usage
|
|
20
|
+
|
|
21
|
+
In this example clicking the button calls \`increment\` which increments the \`count\` by 1
|
|
22
|
+
|
|
23
|
+
\`\`\`js
|
|
24
|
+
import { ${Name} } from './${name}';
|
|
25
|
+
|
|
26
|
+
const { count, increment } = ${Name}();
|
|
27
|
+
|
|
28
|
+
<h1>The count is {count}</h1>
|
|
29
|
+
<button onClick={increment}>increment</button>
|
|
30
|
+
\`\`\`
|
|
31
|
+
`,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ComponentContext } from '@teambit/generator';
|
|
2
|
+
|
|
3
|
+
export const testFile = (context: ComponentContext) => {
|
|
4
|
+
const { name, nameCamelCase: Name } = context;
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
relativePath: `${name}.spec.tsx`,
|
|
8
|
+
content: `import { renderHook, act } from '@testing-library/react-hooks';
|
|
9
|
+
import { ${Name} } from './${name}';
|
|
10
|
+
|
|
11
|
+
it('should increment counter', () => {
|
|
12
|
+
const { result } = renderHook(() => ${Name}())
|
|
13
|
+
act(() => {
|
|
14
|
+
result.current.increment()
|
|
15
|
+
})
|
|
16
|
+
expect(result.current.count).toBe(1)
|
|
17
|
+
})
|
|
18
|
+
`,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentTemplate, ComponentContext } from '@teambit/generator';
|
|
2
|
+
import { componentFile } from './files/component';
|
|
3
|
+
import { compositionFile } from './files/composition';
|
|
4
|
+
import { docsFile } from './files/docs';
|
|
5
|
+
import { testFile } from './files/test';
|
|
6
|
+
|
|
7
|
+
export const reactHook: ComponentTemplate = {
|
|
8
|
+
name: 'react-hook',
|
|
9
|
+
description: 'a react hook component',
|
|
10
|
+
|
|
11
|
+
generateFiles: (context: ComponentContext) => {
|
|
12
|
+
const { name, nameCamelCase: Name } = context;
|
|
13
|
+
const indexFile = {
|
|
14
|
+
relativePath: 'index.ts',
|
|
15
|
+
content: `export { ${Name} } from './${name}';
|
|
16
|
+
`,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
return [indexFile, componentFile(context), compositionFile(context), docsFile(context), testFile(context)];
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { WorkspaceContext, WorkspaceTemplate } from '@teambit/generator';
|
|
2
|
+
import { generateFiles as generateCommonFiles } from '../workspace-common';
|
|
3
|
+
|
|
4
|
+
export const reactWorkspaceTemplate: WorkspaceTemplate = {
|
|
5
|
+
name: 'react',
|
|
6
|
+
description: 'React workspace with demo components',
|
|
7
|
+
generateFiles: async (context: WorkspaceContext) => {
|
|
8
|
+
return generateCommonFiles(context);
|
|
9
|
+
},
|
|
10
|
+
importComponents: () => {
|
|
11
|
+
return [
|
|
12
|
+
{
|
|
13
|
+
id: 'teambit.react/templates/envs/my-react',
|
|
14
|
+
targetName: 'envs/my-react',
|
|
15
|
+
path: 'demo/envs/my-react',
|
|
16
|
+
},
|
|
17
|
+
{ id: 'teambit.react/templates/ui/text', targetName: 'ui/text', path: 'demo/ui/text' },
|
|
18
|
+
{ id: 'teambit.react/templates/ui/heading', targetName: 'ui/heading', path: 'demo/ui/heading' },
|
|
19
|
+
{ id: 'teambit.react/templates/ui/card', targetName: 'ui/card', path: 'demo/ui/card' },
|
|
20
|
+
{
|
|
21
|
+
id: 'teambit.react/templates/pages/welcome',
|
|
22
|
+
targetName: 'pages/welcome',
|
|
23
|
+
path: 'demo/pages/welcome',
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
},
|
|
27
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { WorkspaceContext, WorkspaceTemplate } from '@teambit/generator';
|
|
2
|
+
import { generateFiles as generateCommonFiles } from '../workspace-common';
|
|
3
|
+
|
|
4
|
+
export const reactWorkspaceAppTemplate: WorkspaceTemplate = {
|
|
5
|
+
name: 'react-app',
|
|
6
|
+
description: 'EXPERIMENTAL. react workspace for an app',
|
|
7
|
+
hidden: true,
|
|
8
|
+
generateFiles: async (context: WorkspaceContext) => {
|
|
9
|
+
return generateCommonFiles(context);
|
|
10
|
+
},
|
|
11
|
+
importComponents: () => {
|
|
12
|
+
return [
|
|
13
|
+
{ id: 'teambit.react/templates/apps/my-app', path: 'apps/my-app' },
|
|
14
|
+
{ id: 'teambit.react/templates/envs/my-react', path: 'envs/my-react' },
|
|
15
|
+
{ id: 'teambit.react/templates/themes/theme', path: 'themes/theme' },
|
|
16
|
+
{ id: 'teambit.react/templates/styles/colors', path: 'styles/colors' },
|
|
17
|
+
{ id: 'teambit.react/templates/ui/heading', path: 'ui/heading' },
|
|
18
|
+
];
|
|
19
|
+
},
|
|
20
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { WorkspaceContext, WorkspaceTemplate } from '@teambit/generator';
|
|
2
|
+
import { generateFiles as generateCommonFiles } from '../workspace-common';
|
|
3
|
+
|
|
4
|
+
export const deprecatedReactWorkspaceTemplate: WorkspaceTemplate = {
|
|
5
|
+
name: 'react-workspace',
|
|
6
|
+
description: 'React workspace with demo components',
|
|
7
|
+
hidden: true,
|
|
8
|
+
generateFiles: async (context: WorkspaceContext) => {
|
|
9
|
+
return generateCommonFiles(context);
|
|
10
|
+
},
|
|
11
|
+
importComponents: () => {
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
id: 'teambit.react/templates/envs/my-react',
|
|
15
|
+
targetName: 'envs/my-react',
|
|
16
|
+
path: 'demo/envs/my-react',
|
|
17
|
+
},
|
|
18
|
+
{ id: 'teambit.react/templates/ui/text', targetName: 'ui/text', path: 'demo/ui/text' },
|
|
19
|
+
{ id: 'teambit.react/templates/ui/heading', targetName: 'ui/heading', path: 'demo/ui/heading' },
|
|
20
|
+
{ id: 'teambit.react/templates/ui/card', targetName: 'ui/card', path: 'demo/ui/card' },
|
|
21
|
+
{
|
|
22
|
+
id: 'teambit.react/templates/pages/welcome',
|
|
23
|
+
targetName: 'pages/welcome',
|
|
24
|
+
path: 'demo/pages/welcome',
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
},
|
|
28
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { WorkspaceContext, WorkspaceTemplate } from '@teambit/generator';
|
|
2
|
+
import { generateFiles as generateCommonFiles } from '../workspace-common';
|
|
3
|
+
|
|
4
|
+
export const reactWorkspaceLibTemplate: WorkspaceTemplate = {
|
|
5
|
+
name: 'react-lib',
|
|
6
|
+
description: 'EXPERIMENTAL. react workspace for a component library',
|
|
7
|
+
hidden: true,
|
|
8
|
+
generateFiles: async (context: WorkspaceContext) => {
|
|
9
|
+
return generateCommonFiles(context);
|
|
10
|
+
},
|
|
11
|
+
importComponents: () => {
|
|
12
|
+
return [
|
|
13
|
+
{ id: 'teambit.react/templates/envs/my-react', targetName: 'envs/my-react', path: 'demo/envs/my-react' },
|
|
14
|
+
{ id: 'teambit.react/templates/ui/text', targetName: 'ui/text', path: 'demo/ui/text' },
|
|
15
|
+
{ id: 'teambit.react/templates/ui/heading', targetName: 'ui/heading', path: 'demo/ui/heading' },
|
|
16
|
+
{ id: 'teambit.react/templates/ui/card', targetName: 'ui/card', path: 'demo/ui/card' },
|
|
17
|
+
{ id: 'teambit.react/templates/styles/colors', targetName: 'styles/colors', path: 'demo/styles/colors' },
|
|
18
|
+
{ id: 'teambit.react/templates/themes/theme', targetName: 'themes/theme', path: 'demo/themes/theme' },
|
|
19
|
+
];
|
|
20
|
+
},
|
|
21
|
+
};
|