@teambit/generator 0.0.567 → 0.0.571
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-tar/teambit-generator-0.0.571.tgz +0 -0
- package/package.json +20 -35
- package/templates/component-generator/files/aspect-file.ts +10 -0
- package/templates/component-generator/files/docs-file.ts +54 -0
- package/templates/component-generator/files/index.ts +10 -0
- package/templates/component-generator/files/main-runtime.ts +125 -0
- package/templates/component-generator/index.ts +32 -0
- package/templates/workspace-generator/files/aspect-file.ts +10 -0
- package/templates/workspace-generator/files/docs-file.ts +37 -0
- package/templates/workspace-generator/files/git-ignore-tpl.ts +113 -0
- package/templates/workspace-generator/files/index-tpl.ts +29 -0
- package/templates/workspace-generator/files/index.ts +10 -0
- package/templates/workspace-generator/files/main-runtime.ts +24 -0
- package/templates/workspace-generator/files/readme-tpl.ts +39 -0
- package/templates/workspace-generator/files/workspace-config-tpl.ts +18 -0
- package/templates/workspace-generator/index.ts +52 -0
- package/types/asset.d.ts +29 -0
- package/types/style.d.ts +42 -0
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/generator",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.571",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/generator/generator",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.generator",
|
|
8
8
|
"name": "generator",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.571"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"camelcase": "6.2.0",
|
|
@@ -21,21 +21,21 @@
|
|
|
21
21
|
"isbinaryfile": "4.0.6",
|
|
22
22
|
"@babel/runtime": "7.12.18",
|
|
23
23
|
"core-js": "^3.0.0",
|
|
24
|
-
"@teambit/bit-error": "0.0.
|
|
25
|
-
"@teambit/component-id": "0.0.
|
|
26
|
-
"@teambit/envs": "0.0.
|
|
27
|
-
"@teambit/workspace": "0.0.
|
|
28
|
-
"@teambit/cli": "0.0.
|
|
29
|
-
"@teambit/graphql": "0.0.
|
|
30
|
-
"@teambit/aspect-loader": "0.0.
|
|
31
|
-
"@teambit/bit": "0.0.
|
|
32
|
-
"@teambit/component": "0.0.
|
|
33
|
-
"@teambit/legacy-bit-id": "0.0.
|
|
34
|
-
"@teambit/compiler": "0.0.
|
|
35
|
-
"@teambit/dependency-resolver": "0.0.
|
|
36
|
-
"@teambit/logger": "0.0.
|
|
37
|
-
"@teambit/pkg": "0.0.
|
|
38
|
-
"@teambit/ui": "0.0.
|
|
24
|
+
"@teambit/bit-error": "0.0.381",
|
|
25
|
+
"@teambit/component-id": "0.0.385",
|
|
26
|
+
"@teambit/envs": "0.0.571",
|
|
27
|
+
"@teambit/workspace": "0.0.571",
|
|
28
|
+
"@teambit/cli": "0.0.395",
|
|
29
|
+
"@teambit/graphql": "0.0.571",
|
|
30
|
+
"@teambit/aspect-loader": "0.0.571",
|
|
31
|
+
"@teambit/bit": "0.0.573",
|
|
32
|
+
"@teambit/component": "0.0.571",
|
|
33
|
+
"@teambit/legacy-bit-id": "0.0.384",
|
|
34
|
+
"@teambit/compiler": "0.0.571",
|
|
35
|
+
"@teambit/dependency-resolver": "0.0.571",
|
|
36
|
+
"@teambit/logger": "0.0.483",
|
|
37
|
+
"@teambit/pkg": "0.0.571",
|
|
38
|
+
"@teambit/ui": "0.0.571"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/fs-extra": "9.0.7",
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"@types/react-dom": "^17.0.5",
|
|
47
47
|
"@types/react": "^17.0.8",
|
|
48
48
|
"@types/node": "12.20.4",
|
|
49
|
-
"@teambit/generator.aspect-docs.generator": "0.0.
|
|
49
|
+
"@teambit/generator.aspect-docs.generator": "0.0.121"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@teambit/legacy": "1.0.
|
|
52
|
+
"@teambit/legacy": "1.0.181",
|
|
53
53
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
54
54
|
"react": "^16.8.0 || ^17.0.0"
|
|
55
55
|
},
|
|
@@ -77,27 +77,12 @@
|
|
|
77
77
|
"react": "-"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
|
-
"@teambit/legacy": "1.0.
|
|
80
|
+
"@teambit/legacy": "1.0.181",
|
|
81
81
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
82
82
|
"react": "^16.8.0 || ^17.0.0"
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
|
-
"files": [
|
|
87
|
-
"dist",
|
|
88
|
-
"!dist/tsconfig.tsbuildinfo",
|
|
89
|
-
"**/*.md",
|
|
90
|
-
"**/*.mdx",
|
|
91
|
-
"**/*.js",
|
|
92
|
-
"**/*.json",
|
|
93
|
-
"**/*.sass",
|
|
94
|
-
"**/*.scss",
|
|
95
|
-
"**/*.less",
|
|
96
|
-
"**/*.css",
|
|
97
|
-
"**/*.css",
|
|
98
|
-
"**/*.jpeg",
|
|
99
|
-
"**/*.gif"
|
|
100
|
-
],
|
|
101
86
|
"private": false,
|
|
102
87
|
"engines": {
|
|
103
88
|
"node": ">=12.22.0"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ComponentContext } from '@teambit/generator';
|
|
2
|
+
|
|
3
|
+
export function aspectFile({ namePascalCase, componentId }: ComponentContext) {
|
|
4
|
+
return `import { Aspect } from '@teambit/harmony';
|
|
5
|
+
|
|
6
|
+
export const ${namePascalCase}Aspect = Aspect.create({
|
|
7
|
+
id: '${componentId}',
|
|
8
|
+
});
|
|
9
|
+
`;
|
|
10
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export function docsFile() {
|
|
2
|
+
return `### Configuring your Generator
|
|
3
|
+
|
|
4
|
+
Edit your \`workspace.jsonc\` file and set this component to use the \`teambit.harmony/aspect\` env under the variants object.
|
|
5
|
+
|
|
6
|
+
\`\`\`json
|
|
7
|
+
"teambit.workspace/variants": {
|
|
8
|
+
"{my-components}": {
|
|
9
|
+
"teambit.harmony/aspect": {}
|
|
10
|
+
},
|
|
11
|
+
}
|
|
12
|
+
\`\`\`
|
|
13
|
+
|
|
14
|
+
To check if your component is using the correct env you can run \`bit envs\` or \`bit show my-components\`
|
|
15
|
+
|
|
16
|
+
Edit your \`workspace.jsonc\` file and add the component id, (scope name / component name) to teambit generator. This should go at root level. The component id can be found in the \`aspect.ts\` file:
|
|
17
|
+
|
|
18
|
+
\`\`\`json
|
|
19
|
+
{
|
|
20
|
+
"teambit.generator/generator": {
|
|
21
|
+
"aspects": ["my-scope-name/my-components"]
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
\`\`\`
|
|
25
|
+
|
|
26
|
+
This registers the component aspect so that your templates will appear in the CLI when you run \`bit templates\`.
|
|
27
|
+
|
|
28
|
+
### Modifying your Generator
|
|
29
|
+
|
|
30
|
+
The \`my-components.main.runtime.ts\` file contains an array of templates that you can modify and add to to create different templates and numerous files to be generated.
|
|
31
|
+
|
|
32
|
+
### Using your Generator
|
|
33
|
+
|
|
34
|
+
Use your generator to create the component files
|
|
35
|
+
|
|
36
|
+
\`\`\`bash
|
|
37
|
+
bit create my-components component1
|
|
38
|
+
\`\`\`
|
|
39
|
+
|
|
40
|
+
### Exporting your Generator
|
|
41
|
+
|
|
42
|
+
Tag and export your generator component so you can use it in any other workspace. Make sure the scope name is set correctly in the \`aspect.ts\` file before tagging and exporting. Once you have tagged and exported the component you can add it to the \`workspace.jsonc\` file in the workspace where you want to use this generator.
|
|
43
|
+
|
|
44
|
+
\`\`\`json
|
|
45
|
+
{
|
|
46
|
+
"teambit.generator/generator": {
|
|
47
|
+
"aspects": ["my-scope-name/my-components"]
|
|
48
|
+
},
|
|
49
|
+
}
|
|
50
|
+
\`\`\`
|
|
51
|
+
|
|
52
|
+
Run \`bit templates\` to see your generator and then use it to generate you components.
|
|
53
|
+
`;
|
|
54
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ComponentContext } from '@teambit/generator';
|
|
2
|
+
|
|
3
|
+
export function indexFile({ namePascalCase, name }: ComponentContext) {
|
|
4
|
+
return `import { ${namePascalCase}Aspect } from './${name}.aspect';
|
|
5
|
+
|
|
6
|
+
export type { ${namePascalCase}Main } from './${name}.main.runtime';
|
|
7
|
+
export default ${namePascalCase}Aspect;
|
|
8
|
+
export { ${namePascalCase}Aspect };
|
|
9
|
+
`;
|
|
10
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { ComponentContext } from '@teambit/generator';
|
|
2
|
+
|
|
3
|
+
export function mainRuntime({ name, namePascalCase }: ComponentContext) {
|
|
4
|
+
return `import { MainRuntime } from '@teambit/cli';
|
|
5
|
+
import { GeneratorMain, GeneratorAspect, ComponentContext } from '@teambit/generator';
|
|
6
|
+
import { ${namePascalCase}Aspect } from './${name}.aspect';
|
|
7
|
+
|
|
8
|
+
export class ${namePascalCase}Main {
|
|
9
|
+
static slots = [];
|
|
10
|
+
static dependencies = [GeneratorAspect];
|
|
11
|
+
static runtime = MainRuntime;
|
|
12
|
+
static async provider([generator]: [GeneratorMain]) {
|
|
13
|
+
/**
|
|
14
|
+
* Array of templates. Add as many templates as you want
|
|
15
|
+
* Separate the templates to multiple files if you prefer
|
|
16
|
+
* Modify, add or remove files as needed
|
|
17
|
+
* See the docs file of this component for more info
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
generator.registerComponentTemplate([
|
|
21
|
+
{
|
|
22
|
+
name: 'component1',
|
|
23
|
+
description: 'description for component1',
|
|
24
|
+
generateFiles: (context: ComponentContext) => {
|
|
25
|
+
return [
|
|
26
|
+
|
|
27
|
+
// index file
|
|
28
|
+
{
|
|
29
|
+
relativePath: 'index.ts',
|
|
30
|
+
isMain: true,
|
|
31
|
+
content: \`export { \${context.namePascalCase} } from './\${context.name}';
|
|
32
|
+
export type { \${context.namePascalCase}Props } from './\${context.name}';
|
|
33
|
+
\`,
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
// component file
|
|
37
|
+
{
|
|
38
|
+
relativePath: \`\${context.name}.tsx\`,
|
|
39
|
+
content: \`import React from 'react';
|
|
40
|
+
|
|
41
|
+
export type \${context.namePascalCase}Props = {
|
|
42
|
+
/**
|
|
43
|
+
* a text to be rendered in the component.
|
|
44
|
+
*/
|
|
45
|
+
text: string
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export function \${context.namePascalCase}({ text }: \${context.namePascalCase}Props) {
|
|
49
|
+
return (
|
|
50
|
+
<div>
|
|
51
|
+
{text}
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
}\`,
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
// docs file
|
|
58
|
+
{
|
|
59
|
+
relativePath: \`\${context.name}.docs.mdx\`,
|
|
60
|
+
content: \`---
|
|
61
|
+
description: 'A React Component for rendering text.'
|
|
62
|
+
labels: ['text', 'ui']
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
import { \${context.namePascalCase} } from './\${context.name}';
|
|
66
|
+
\`
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
// composition file
|
|
70
|
+
{
|
|
71
|
+
relativePath: \`\${context.name}.composition.tsx\`,
|
|
72
|
+
content: \`import React from 'react';
|
|
73
|
+
import { \${context.namePascalCase} } from './\${context.name}';
|
|
74
|
+
|
|
75
|
+
export const Basic\${context.namePascalCase} = () => (
|
|
76
|
+
<\${context.namePascalCase} text="hello from \${context.namePascalCase} " />
|
|
77
|
+
);
|
|
78
|
+
\`
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
// test file
|
|
82
|
+
{
|
|
83
|
+
relativePath: \`\${context.name}.spec.tsx\`,
|
|
84
|
+
content: \`import React from 'react';
|
|
85
|
+
import { render } from '@testing-library/react';
|
|
86
|
+
import { Basic\${context.namePascalCase} } from './\${context.name}.composition';
|
|
87
|
+
|
|
88
|
+
it('should render with the correct text', () => {
|
|
89
|
+
const { getByText } = render(<Basic\${context.namePascalCase} />);
|
|
90
|
+
const rendered = getByText('hello from \${context.namePascalCase}');
|
|
91
|
+
expect(rendered).toBeTruthy();
|
|
92
|
+
});
|
|
93
|
+
\`
|
|
94
|
+
},
|
|
95
|
+
// add more files here such as css/sass
|
|
96
|
+
];
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
// component 2
|
|
101
|
+
{
|
|
102
|
+
name: 'component2',
|
|
103
|
+
description: 'description for component2',
|
|
104
|
+
generateFiles: (context: ComponentContext) => {
|
|
105
|
+
return [
|
|
106
|
+
|
|
107
|
+
// index file
|
|
108
|
+
{
|
|
109
|
+
relativePath: 'index.ts',
|
|
110
|
+
isMain: true,
|
|
111
|
+
content: \`export {} from '';
|
|
112
|
+
\`,
|
|
113
|
+
},
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
]);
|
|
118
|
+
|
|
119
|
+
return new ${namePascalCase}Main();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
${namePascalCase}Aspect.addRuntime(${namePascalCase}Main);
|
|
124
|
+
`;
|
|
125
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ComponentContext, ComponentTemplate } from '@teambit/generator';
|
|
2
|
+
import { indexFile } from './files/index';
|
|
3
|
+
import { aspectFile } from './files/aspect-file';
|
|
4
|
+
import { docsFile } from './files/docs-file';
|
|
5
|
+
import { mainRuntime } from './files/main-runtime';
|
|
6
|
+
|
|
7
|
+
export const componentGeneratorTemplate: ComponentTemplate = {
|
|
8
|
+
name: 'component-generator',
|
|
9
|
+
description:
|
|
10
|
+
'create your own component generator \nDocs: https://harmony-docs.bit.dev/extending-bit/creating-a-custom-generator',
|
|
11
|
+
generateFiles: (context: ComponentContext) => {
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
relativePath: 'index.ts',
|
|
15
|
+
content: indexFile(context),
|
|
16
|
+
isMain: true,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
relativePath: `${context.name}.aspect.ts`,
|
|
20
|
+
content: aspectFile(context),
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
relativePath: `${context.name}.docs.mdx`,
|
|
24
|
+
content: docsFile(),
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
relativePath: `${context.name}.main.runtime.ts`,
|
|
28
|
+
content: mainRuntime(context),
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
},
|
|
32
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ComponentContext } from '@teambit/generator';
|
|
2
|
+
|
|
3
|
+
export function aspectFile({ namePascalCase, componentId }: ComponentContext) {
|
|
4
|
+
return `import { Aspect } from '@teambit/harmony';
|
|
5
|
+
|
|
6
|
+
export const ${namePascalCase}Aspect = Aspect.create({
|
|
7
|
+
id: '${componentId}',
|
|
8
|
+
});
|
|
9
|
+
`;
|
|
10
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export function docsFile() {
|
|
2
|
+
return `---
|
|
3
|
+
description: Generator for generating a workspace
|
|
4
|
+
labels: ['generator', 'templates', 'workspace']
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Registering your Workspace
|
|
8
|
+
|
|
9
|
+
Register your workspace template under the aspect environment in the variants section of the workspace.jsonc file.
|
|
10
|
+
|
|
11
|
+
\`\`\`json
|
|
12
|
+
"teambit.workspace/variants": {
|
|
13
|
+
"{workspace-name}": {
|
|
14
|
+
"teambit.harmony/aspect": {}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
\`\`\`
|
|
18
|
+
|
|
19
|
+
## Customizing your Workspace
|
|
20
|
+
|
|
21
|
+
See the docs for more info on [Customizing your Generator](https://harmony-docs.bit.dev/extending-bit/creating-a-custom-workspace-generator)
|
|
22
|
+
|
|
23
|
+
## Using the Workspace Generator
|
|
24
|
+
|
|
25
|
+
How to use this generator locally, essentially for development purposes:
|
|
26
|
+
|
|
27
|
+
\`\`\`js
|
|
28
|
+
bit new <template-name> <workspace-name> --load-from /Users/me/path/to/this/dir --aspect <workspace-template-id>
|
|
29
|
+
\`\`\`
|
|
30
|
+
|
|
31
|
+
How to use this generator after exporting to a remote scope:
|
|
32
|
+
|
|
33
|
+
\`\`\`js
|
|
34
|
+
bit new <template-name> <workspace-name> --aspect <workspace-template-id>
|
|
35
|
+
\`\`\`
|
|
36
|
+
`;
|
|
37
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export function gitIgnoreTemplate() {
|
|
2
|
+
return `export function gitIgnore() {
|
|
3
|
+
return \`# Bit
|
|
4
|
+
.bit
|
|
5
|
+
public
|
|
6
|
+
|
|
7
|
+
# Logs
|
|
8
|
+
logs
|
|
9
|
+
*.log
|
|
10
|
+
npm-debug.log*
|
|
11
|
+
yarn-debug.log*
|
|
12
|
+
yarn-error.log*
|
|
13
|
+
lerna-debug.log*
|
|
14
|
+
|
|
15
|
+
# Diagnostic reports (https://nodejs.org/api/report.html)
|
|
16
|
+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
17
|
+
|
|
18
|
+
# Runtime data
|
|
19
|
+
pids
|
|
20
|
+
*.pid
|
|
21
|
+
*.seed
|
|
22
|
+
*.pid.lock
|
|
23
|
+
|
|
24
|
+
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
25
|
+
lib-cov
|
|
26
|
+
|
|
27
|
+
# Coverage directory used by tools like istanbul
|
|
28
|
+
coverage
|
|
29
|
+
*.lcov
|
|
30
|
+
|
|
31
|
+
# nyc test coverage
|
|
32
|
+
.nyc_output
|
|
33
|
+
|
|
34
|
+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
|
35
|
+
.grunt
|
|
36
|
+
|
|
37
|
+
# Bower dependency directory (https://bower.io/)
|
|
38
|
+
bower_components
|
|
39
|
+
|
|
40
|
+
# node-waf configuration
|
|
41
|
+
.lock-wscript
|
|
42
|
+
|
|
43
|
+
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
|
44
|
+
build/Release
|
|
45
|
+
|
|
46
|
+
# Dependency directories
|
|
47
|
+
node_modules/
|
|
48
|
+
jspm_packages/
|
|
49
|
+
|
|
50
|
+
# TypeScript v1 declaration files
|
|
51
|
+
typings/
|
|
52
|
+
|
|
53
|
+
# TypeScript cache
|
|
54
|
+
*.tsbuildinfo
|
|
55
|
+
|
|
56
|
+
# Optional npm cache directory
|
|
57
|
+
.npm
|
|
58
|
+
|
|
59
|
+
# Optional eslint cache
|
|
60
|
+
.eslintcache
|
|
61
|
+
|
|
62
|
+
# Microbundle cache
|
|
63
|
+
.rpt2_cache/
|
|
64
|
+
.rts2_cache_cjs/
|
|
65
|
+
.rts2_cache_es/
|
|
66
|
+
.rts2_cache_umd/
|
|
67
|
+
|
|
68
|
+
# Optional REPL history
|
|
69
|
+
.node_repl_history
|
|
70
|
+
|
|
71
|
+
# Output of 'npm pack'
|
|
72
|
+
*.tgz
|
|
73
|
+
|
|
74
|
+
# Yarn Integrity file
|
|
75
|
+
.yarn-integrity
|
|
76
|
+
|
|
77
|
+
# dotenv environment variables file
|
|
78
|
+
.env
|
|
79
|
+
.env.test
|
|
80
|
+
|
|
81
|
+
# parcel-bundler cache (https://parceljs.org/)
|
|
82
|
+
.cache
|
|
83
|
+
|
|
84
|
+
# Next.js build output
|
|
85
|
+
.next
|
|
86
|
+
|
|
87
|
+
# Nuxt.js build / generate output
|
|
88
|
+
.nuxt
|
|
89
|
+
dist
|
|
90
|
+
|
|
91
|
+
# Gatsby files
|
|
92
|
+
.cache/
|
|
93
|
+
|
|
94
|
+
# vuepress build output
|
|
95
|
+
.vuepress/dist
|
|
96
|
+
|
|
97
|
+
# Serverless directories
|
|
98
|
+
.serverless/
|
|
99
|
+
|
|
100
|
+
# FuseBox cache
|
|
101
|
+
.fusebox/
|
|
102
|
+
|
|
103
|
+
# DynamoDB Local files
|
|
104
|
+
.dynamodb/
|
|
105
|
+
|
|
106
|
+
# TernJS port file
|
|
107
|
+
.tern-port
|
|
108
|
+
|
|
109
|
+
.history
|
|
110
|
+
\`;
|
|
111
|
+
}
|
|
112
|
+
`;
|
|
113
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function indexTemplate() {
|
|
2
|
+
return `import { WorkspaceContext, WorkspaceTemplate } from '@teambit/generator';
|
|
3
|
+
import { workspaceConfig } from './files/workspace-config';
|
|
4
|
+
import { readme } from './files/readme-file';
|
|
5
|
+
import { gitIgnore } from './files/git-ignore';
|
|
6
|
+
|
|
7
|
+
export const workspaceTemplate: WorkspaceTemplate = {
|
|
8
|
+
name: 'template-example',
|
|
9
|
+
description: 'demonstration of a workspace template',
|
|
10
|
+
generateFiles: async (context: WorkspaceContext) => [
|
|
11
|
+
{
|
|
12
|
+
relativePath: 'workspace.jsonc',
|
|
13
|
+
content: await workspaceConfig(context),
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
relativePath: '.gitignore',
|
|
17
|
+
content: gitIgnore(),
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
relativePath: 'README.md',
|
|
21
|
+
content: readme(),
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
importComponents: () => [
|
|
25
|
+
{ id: 'teambit.react/templates/ui/text', path: 'ui/text' },
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
`;
|
|
29
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ComponentContext } from '@teambit/generator';
|
|
2
|
+
|
|
3
|
+
export function indexFile({ namePascalCase, name }: ComponentContext) {
|
|
4
|
+
return `import { ${namePascalCase}Aspect } from './${name}.aspect';
|
|
5
|
+
|
|
6
|
+
export type { ${namePascalCase}Main } from './${name}.main.runtime';
|
|
7
|
+
export default ${namePascalCase}Aspect;
|
|
8
|
+
export { ${namePascalCase}Aspect };
|
|
9
|
+
`;
|
|
10
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ComponentContext } from '@teambit/generator';
|
|
2
|
+
|
|
3
|
+
export function mainRuntime({ name, namePascalCase }: ComponentContext) {
|
|
4
|
+
return `import { MainRuntime } from '@teambit/cli';
|
|
5
|
+
import { GeneratorMain, GeneratorAspect } from '@teambit/generator';
|
|
6
|
+
import { ${namePascalCase}Aspect } from './${name}.aspect';
|
|
7
|
+
import { workspaceTemplate } from './template';
|
|
8
|
+
|
|
9
|
+
export class ${namePascalCase}Main {
|
|
10
|
+
static slots = [];
|
|
11
|
+
|
|
12
|
+
static dependencies = [GeneratorAspect];
|
|
13
|
+
|
|
14
|
+
static runtime = MainRuntime;
|
|
15
|
+
|
|
16
|
+
static async provider([generator]: [GeneratorMain]) {
|
|
17
|
+
generator.registerWorkspaceTemplate([workspaceTemplate]);
|
|
18
|
+
return new ${namePascalCase}Main();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
${namePascalCase}Aspect.addRuntime(${namePascalCase}Main);
|
|
23
|
+
`;
|
|
24
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function readmeTemplate() {
|
|
2
|
+
return `export function readme() {
|
|
3
|
+
return \`## Workspace Generator
|
|
4
|
+
|
|
5
|
+
Easily generate a new workspace with a single command.
|
|
6
|
+
|
|
7
|
+
## Registering your Workspace
|
|
8
|
+
|
|
9
|
+
Register your workspace template under the aspect environment in the variants section of the workspace.jsonc file.
|
|
10
|
+
|
|
11
|
+
\\\`\\\`\\\`json
|
|
12
|
+
"teambit.workspace/variants": {
|
|
13
|
+
"{workspace-name}": {
|
|
14
|
+
"teambit.harmony/aspect": {}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
\\\`\\\`\\\`
|
|
18
|
+
|
|
19
|
+
## Customizing your Workspace
|
|
20
|
+
|
|
21
|
+
See the docs for more info on [Customizing your Generator](https://harmony-docs.bit.dev/extending-bit/creating-a-custom-workspace-generator)
|
|
22
|
+
|
|
23
|
+
## Using the Workspace Generator
|
|
24
|
+
|
|
25
|
+
How to use this generator locally, essentially for development purposes:
|
|
26
|
+
|
|
27
|
+
\\\`\\\`\\\`js
|
|
28
|
+
bit new <template-name> <workspace-name> --load-from /Users/me/path/to/this/dir --aspect <workspace-template-id>
|
|
29
|
+
\\\`\\\`\\\`
|
|
30
|
+
|
|
31
|
+
How to use this generator after exporting to a remote scope:
|
|
32
|
+
|
|
33
|
+
\\\`\\\`\\\`js
|
|
34
|
+
bit new <template-name> <workspace-name> --aspect <workspace-template-id>
|
|
35
|
+
\\\`\\\`\\\`
|
|
36
|
+
\`;
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function workspaceConfigTemplate() {
|
|
2
|
+
return `import { WorkspaceContext } from '@teambit/generator';
|
|
3
|
+
import { getWorkspaceConfigTemplateParsed, stringifyWorkspaceConfig } from '@teambit/config';
|
|
4
|
+
|
|
5
|
+
export async function workspaceConfig({ name, defaultScope }: WorkspaceContext) {
|
|
6
|
+
const configParsed = await getWorkspaceConfigTemplateParsed();
|
|
7
|
+
configParsed['teambit.workspace/workspace'].name = name;
|
|
8
|
+
configParsed['teambit.workspace/workspace'].defaultScope = defaultScope || 'company.scope';
|
|
9
|
+
configParsed['teambit.workspace/variants'] = {
|
|
10
|
+
'*': {
|
|
11
|
+
'teambit.react/react': {},
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return stringifyWorkspaceConfig(configParsed);
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ComponentContext, ComponentTemplate } from '@teambit/generator';
|
|
2
|
+
import { indexFile } from './files/index';
|
|
3
|
+
import { aspectFile } from './files/aspect-file';
|
|
4
|
+
import { docsFile } from './files/docs-file';
|
|
5
|
+
import { mainRuntime } from './files/main-runtime';
|
|
6
|
+
import { gitIgnoreTemplate } from './files/git-ignore-tpl';
|
|
7
|
+
import { readmeTemplate } from './files/readme-tpl';
|
|
8
|
+
import { indexTemplate } from './files/index-tpl';
|
|
9
|
+
import { workspaceConfigTemplate } from './files/workspace-config-tpl';
|
|
10
|
+
|
|
11
|
+
export const workspaceGeneratorTemplate: ComponentTemplate = {
|
|
12
|
+
name: 'workspace-generator',
|
|
13
|
+
description:
|
|
14
|
+
'create your own workspace generator - \nDocs: https://harmony-docs.bit.dev/extending-bit/creating-a-custom-workspace-generator',
|
|
15
|
+
generateFiles: (context: ComponentContext) => {
|
|
16
|
+
return [
|
|
17
|
+
{
|
|
18
|
+
relativePath: 'index.ts',
|
|
19
|
+
content: indexFile(context),
|
|
20
|
+
isMain: true,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
relativePath: `${context.name}.aspect.ts`,
|
|
24
|
+
content: aspectFile(context),
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
relativePath: `${context.name}.main.runtime.ts`,
|
|
28
|
+
content: mainRuntime(context),
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
relativePath: `${context.name}.docs.mdx`,
|
|
32
|
+
content: docsFile(),
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
relativePath: 'template/files/git-ignore.ts',
|
|
36
|
+
content: gitIgnoreTemplate(),
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
relativePath: 'template/files/readme-file.ts',
|
|
40
|
+
content: readmeTemplate(),
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
relativePath: 'template/files/workspace-config.ts',
|
|
44
|
+
content: workspaceConfigTemplate(),
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
relativePath: 'template/index.ts',
|
|
48
|
+
content: indexTemplate(),
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
},
|
|
52
|
+
};
|
package/types/asset.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare module '*.png' {
|
|
2
|
+
const value: any;
|
|
3
|
+
export = value;
|
|
4
|
+
}
|
|
5
|
+
declare module '*.svg' {
|
|
6
|
+
import type { FunctionComponent, SVGProps } from 'react';
|
|
7
|
+
|
|
8
|
+
export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
|
|
9
|
+
const src: string;
|
|
10
|
+
export default src;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// @TODO Gilad
|
|
14
|
+
declare module '*.jpg' {
|
|
15
|
+
const value: any;
|
|
16
|
+
export = value;
|
|
17
|
+
}
|
|
18
|
+
declare module '*.jpeg' {
|
|
19
|
+
const value: any;
|
|
20
|
+
export = value;
|
|
21
|
+
}
|
|
22
|
+
declare module '*.gif' {
|
|
23
|
+
const value: any;
|
|
24
|
+
export = value;
|
|
25
|
+
}
|
|
26
|
+
declare module '*.bmp' {
|
|
27
|
+
const value: any;
|
|
28
|
+
export = value;
|
|
29
|
+
}
|
package/types/style.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
declare module '*.module.css' {
|
|
2
|
+
const classes: { readonly [key: string]: string };
|
|
3
|
+
export default classes;
|
|
4
|
+
}
|
|
5
|
+
declare module '*.module.scss' {
|
|
6
|
+
const classes: { readonly [key: string]: string };
|
|
7
|
+
export default classes;
|
|
8
|
+
}
|
|
9
|
+
declare module '*.module.sass' {
|
|
10
|
+
const classes: { readonly [key: string]: string };
|
|
11
|
+
export default classes;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '*.module.less' {
|
|
15
|
+
const classes: { readonly [key: string]: string };
|
|
16
|
+
export default classes;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare module '*.less' {
|
|
20
|
+
const classes: { readonly [key: string]: string };
|
|
21
|
+
export default classes;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare module '*.css' {
|
|
25
|
+
const classes: { readonly [key: string]: string };
|
|
26
|
+
export default classes;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare module '*.sass' {
|
|
30
|
+
const classes: { readonly [key: string]: string };
|
|
31
|
+
export default classes;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare module '*.scss' {
|
|
35
|
+
const classes: { readonly [key: string]: string };
|
|
36
|
+
export default classes;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module '*.mdx' {
|
|
40
|
+
const component: any;
|
|
41
|
+
export default component;
|
|
42
|
+
}
|