@teambit/generator 0.0.551 → 0.0.556
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/dist/component-generator.d.ts +3 -0
- package/dist/component-template.d.ts +37 -0
- package/dist/generator.main.runtime.d.ts +29 -0
- package/dist/workspace-generator.d.ts +3 -0
- package/dist/workspace-template.d.ts +45 -0
- package/package.json +26 -20
- package/component-generator.ts +0 -119
- package/component-template.ts +0 -66
- package/create.cmd.ts +0 -44
- package/generator.aspect.ts +0 -5
- package/generator.docs.mdx +0 -8
- package/generator.graphql.ts +0 -66
- package/generator.main.runtime.ts +0 -279
- package/index.ts +0 -4
- package/new.cmd.ts +0 -79
- package/package-tar/teambit-generator-0.0.551.tgz +0 -0
- package/templates/component-generator/files/aspect-file.ts +0 -10
- package/templates/component-generator/files/docs-file.ts +0 -54
- package/templates/component-generator/files/index.ts +0 -10
- package/templates/component-generator/files/main-runtime.ts +0 -125
- package/templates/component-generator/index.ts +0 -32
- package/templates/workspace-generator/files/aspect-file.ts +0 -10
- package/templates/workspace-generator/files/docs-file.ts +0 -37
- package/templates/workspace-generator/files/git-ignore-tpl.ts +0 -113
- package/templates/workspace-generator/files/index-tpl.ts +0 -29
- package/templates/workspace-generator/files/index.ts +0 -10
- package/templates/workspace-generator/files/main-runtime.ts +0 -24
- package/templates/workspace-generator/files/readme-tpl.ts +0 -39
- package/templates/workspace-generator/files/workspace-config-tpl.ts +0 -18
- package/templates/workspace-generator/index.ts +0 -52
- package/templates.cmd.ts +0 -48
- package/tsconfig.json +0 -35
- package/types/asset.d.ts +0 -29
- package/types/style.d.ts +0 -42
- package/types.ts +0 -3
- package/workspace-generator.ts +0 -246
- package/workspace-template.ts +0 -82
|
@@ -19,6 +19,9 @@ export declare class ComponentGenerator {
|
|
|
19
19
|
generate(): Promise<GenerateResult[]>;
|
|
20
20
|
private deleteGeneratedComponents;
|
|
21
21
|
private generateOneComponent;
|
|
22
|
+
/**
|
|
23
|
+
* writes the generated template files to the default directory set in the workspace config
|
|
24
|
+
*/
|
|
22
25
|
private writeComponentFiles;
|
|
23
26
|
private getComponentPath;
|
|
24
27
|
}
|
|
@@ -1,18 +1,55 @@
|
|
|
1
1
|
import { ComponentID } from '@teambit/component-id';
|
|
2
2
|
export interface ComponentFile {
|
|
3
|
+
/**
|
|
4
|
+
* relative path of the file within the component.
|
|
5
|
+
*/
|
|
3
6
|
relativePath: string;
|
|
7
|
+
/**
|
|
8
|
+
* file content
|
|
9
|
+
*/
|
|
4
10
|
content: string;
|
|
11
|
+
/**
|
|
12
|
+
* whether this file will be tracked as the main file
|
|
13
|
+
*/
|
|
5
14
|
isMain?: boolean;
|
|
6
15
|
}
|
|
7
16
|
export interface ComponentContext {
|
|
17
|
+
/**
|
|
18
|
+
* component-name as entered by the user, e.g. `use-date`.
|
|
19
|
+
* without the scope and the namespace.
|
|
20
|
+
*/
|
|
8
21
|
name: string;
|
|
22
|
+
/**
|
|
23
|
+
* component-name as upper camel case, e.g. `use-date` becomes `UseDate`.
|
|
24
|
+
* useful when generating the file content, for example for a class name.
|
|
25
|
+
*/
|
|
9
26
|
namePascalCase: string;
|
|
27
|
+
/**
|
|
28
|
+
* component-name as lower camel case, e.g. `use-date` becomes `useDate`.
|
|
29
|
+
* useful when generating the file content, for example for a function/variable name.
|
|
30
|
+
*/
|
|
10
31
|
nameCamelCase: string;
|
|
32
|
+
/**
|
|
33
|
+
* component id.
|
|
34
|
+
* the name is the name+namespace. the scope is the scope entered by --scope flag or the defaultScope
|
|
35
|
+
*/
|
|
11
36
|
componentId: ComponentID;
|
|
12
37
|
}
|
|
13
38
|
export interface ComponentTemplate {
|
|
39
|
+
/**
|
|
40
|
+
* name of the component template. for example: `hook`, `react-component` or `module`.
|
|
41
|
+
*/
|
|
14
42
|
name: string;
|
|
43
|
+
/**
|
|
44
|
+
* short description of the template. shown in the `bit templates` command.
|
|
45
|
+
*/
|
|
15
46
|
description?: string;
|
|
47
|
+
/**
|
|
48
|
+
* hide this template so that it is not listed with `bit templates`
|
|
49
|
+
*/
|
|
16
50
|
hidden?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* template function for generating the file of a certain component.,
|
|
53
|
+
*/
|
|
17
54
|
generateFiles(context: ComponentContext): ComponentFile[];
|
|
18
55
|
}
|
|
@@ -19,6 +19,9 @@ export declare type TemplateDescriptor = {
|
|
|
19
19
|
hidden?: boolean;
|
|
20
20
|
};
|
|
21
21
|
export declare type GeneratorConfig = {
|
|
22
|
+
/**
|
|
23
|
+
* array of aspects to include in the list of templates.
|
|
24
|
+
*/
|
|
22
25
|
aspects: string[];
|
|
23
26
|
};
|
|
24
27
|
export declare class GeneratorMain {
|
|
@@ -30,15 +33,41 @@ export declare class GeneratorMain {
|
|
|
30
33
|
private aspectLoader;
|
|
31
34
|
private aspectLoaded;
|
|
32
35
|
constructor(componentTemplateSlot: ComponentTemplateSlot, workspaceTemplateSlot: WorkspaceTemplateSlot, config: GeneratorConfig, workspace: Workspace, envs: EnvsMain, aspectLoader: AspectLoaderMain);
|
|
36
|
+
/**
|
|
37
|
+
* register a new component template.
|
|
38
|
+
*/
|
|
33
39
|
registerComponentTemplate(templates: ComponentTemplate[]): this;
|
|
40
|
+
/**
|
|
41
|
+
* register a new component template.
|
|
42
|
+
*/
|
|
34
43
|
registerWorkspaceTemplate(templates: WorkspaceTemplate[]): this;
|
|
44
|
+
/**
|
|
45
|
+
* list all component templates registered in the workspace or workspace templates in case the
|
|
46
|
+
* workspace is not available
|
|
47
|
+
*/
|
|
35
48
|
listTemplates(): Promise<TemplateDescriptor[]>;
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated use this.listTemplates()
|
|
51
|
+
*/
|
|
36
52
|
listComponentTemplates(): Promise<TemplateDescriptor[]>;
|
|
37
53
|
isRunningInsideWorkspace(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* get all component templates registered by a specific aspect ID.
|
|
56
|
+
*/
|
|
38
57
|
getComponentTemplateByAspect(aspectId: string): ComponentTemplate[];
|
|
58
|
+
/**
|
|
59
|
+
* returns a specific component template.
|
|
60
|
+
*/
|
|
39
61
|
getComponentTemplate(name: string, aspectId?: string): ComponentTemplate | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* in the case the aspect-id is given and this aspect doesn't exist locally, import it to the
|
|
64
|
+
* global scope and load it from the capsule
|
|
65
|
+
*/
|
|
40
66
|
findTemplateInGlobalScope(aspectId: string, name?: string): Promise<WorkspaceTemplate | undefined>;
|
|
41
67
|
findTemplateInOtherWorkspace(workspacePath: string, name: string, aspectId?: string): Promise<WorkspaceTemplate | undefined>;
|
|
68
|
+
/**
|
|
69
|
+
* returns a specific workspace template.
|
|
70
|
+
*/
|
|
42
71
|
getWorkspaceTemplate(name: string, aspectId?: string): Promise<{
|
|
43
72
|
workspaceTemplate: WorkspaceTemplate;
|
|
44
73
|
aspect?: Component;
|
|
@@ -21,6 +21,9 @@ export declare class WorkspaceGenerator {
|
|
|
21
21
|
generate(): Promise<string>;
|
|
22
22
|
private initGit;
|
|
23
23
|
private buildUI;
|
|
24
|
+
/**
|
|
25
|
+
* writes the generated template files to the default directory set in the workspace config
|
|
26
|
+
*/
|
|
24
27
|
private writeWorkspaceFiles;
|
|
25
28
|
private reloadBitInWorkspaceDir;
|
|
26
29
|
private addComponentsFromRemote;
|
|
@@ -1,23 +1,68 @@
|
|
|
1
1
|
import type { Component } from '@teambit/component';
|
|
2
2
|
export interface WorkspaceFile {
|
|
3
|
+
/**
|
|
4
|
+
* relative path of the file within the workspace.
|
|
5
|
+
*/
|
|
3
6
|
relativePath: string;
|
|
7
|
+
/**
|
|
8
|
+
* file content
|
|
9
|
+
*/
|
|
4
10
|
content: string;
|
|
5
11
|
}
|
|
6
12
|
export interface WorkspaceContext {
|
|
13
|
+
/**
|
|
14
|
+
* workspace-name as entered by the user, e.g. `react-app`.
|
|
15
|
+
* it is used as the directory name for the workspace.
|
|
16
|
+
*/
|
|
7
17
|
name: string;
|
|
18
|
+
/**
|
|
19
|
+
* default scope as entered by the user.
|
|
20
|
+
* it will be set in the workspace.jsonc and be used for components
|
|
21
|
+
*/
|
|
8
22
|
defaultScope?: string;
|
|
23
|
+
/**
|
|
24
|
+
* whether user entered `--empty` flag in `bit new` to avoid creating components.
|
|
25
|
+
*/
|
|
9
26
|
empty?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* in case the "--aspect" flag used to import a remote aspect, this is populated with that aspect.
|
|
29
|
+
* useful to get the aspect-id and other info.
|
|
30
|
+
*/
|
|
10
31
|
aspectComponent?: Component;
|
|
11
32
|
}
|
|
12
33
|
export interface ComponentToImport {
|
|
34
|
+
/**
|
|
35
|
+
* full component id
|
|
36
|
+
*/
|
|
13
37
|
id: string;
|
|
38
|
+
/**
|
|
39
|
+
* path where to write the component
|
|
40
|
+
*/
|
|
14
41
|
path: string;
|
|
42
|
+
/**
|
|
43
|
+
* a new component name. if not specified, use the original id (without the scope)
|
|
44
|
+
*/
|
|
15
45
|
targetName?: string;
|
|
16
46
|
}
|
|
17
47
|
export interface WorkspaceTemplate {
|
|
48
|
+
/**
|
|
49
|
+
* name of the workspace template. for example: `react-workspace`.
|
|
50
|
+
*/
|
|
18
51
|
name: string;
|
|
52
|
+
/**
|
|
53
|
+
* short description of the template. shown in the `bit templates` command when outside of bit-workspace.
|
|
54
|
+
*/
|
|
19
55
|
description?: string;
|
|
56
|
+
/**
|
|
57
|
+
* hide this template so that it is not listed with `bit templates`
|
|
58
|
+
*/
|
|
20
59
|
hidden?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* template function for generating the template files,
|
|
62
|
+
*/
|
|
21
63
|
generateFiles(context: WorkspaceContext): Promise<WorkspaceFile[]>;
|
|
64
|
+
/**
|
|
65
|
+
* populate existing components into the new workspace and add them as new components
|
|
66
|
+
*/
|
|
22
67
|
importComponents?: () => ComponentToImport[];
|
|
23
68
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/generator",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.556",
|
|
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.556"
|
|
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.373",
|
|
25
|
+
"@teambit/component-id": "0.0.377",
|
|
26
|
+
"@teambit/envs": "0.0.556",
|
|
27
|
+
"@teambit/workspace": "0.0.556",
|
|
28
|
+
"@teambit/cli": "0.0.387",
|
|
29
|
+
"@teambit/graphql": "0.0.556",
|
|
30
|
+
"@teambit/aspect-loader": "0.0.556",
|
|
31
|
+
"@teambit/bit": "0.0.558",
|
|
32
|
+
"@teambit/component": "0.0.556",
|
|
33
|
+
"@teambit/legacy-bit-id": "0.0.376",
|
|
34
|
+
"@teambit/compiler": "0.0.556",
|
|
35
|
+
"@teambit/dependency-resolver": "0.0.556",
|
|
36
|
+
"@teambit/logger": "0.0.472",
|
|
37
|
+
"@teambit/pkg": "0.0.556",
|
|
38
|
+
"@teambit/ui": "0.0.556"
|
|
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.109"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@teambit/legacy": "1.0.
|
|
52
|
+
"@teambit/legacy": "1.0.173",
|
|
53
53
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
54
54
|
"react": "^16.8.0 || ^17.0.0"
|
|
55
55
|
},
|
|
@@ -77,12 +77,18 @@
|
|
|
77
77
|
"react": "-"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
|
-
"@teambit/legacy": "1.0.
|
|
80
|
+
"@teambit/legacy": "1.0.173",
|
|
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
|
+
"README.md",
|
|
90
|
+
"README.mdx"
|
|
91
|
+
],
|
|
86
92
|
"private": false,
|
|
87
93
|
"engines": {
|
|
88
94
|
"node": ">=12.22.0"
|
package/component-generator.ts
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import Vinyl from 'vinyl';
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import pMapSeries from 'p-map-series';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import { Workspace } from '@teambit/workspace';
|
|
6
|
-
import { EnvsMain } from '@teambit/envs';
|
|
7
|
-
import camelcase from 'camelcase';
|
|
8
|
-
import { BitError } from '@teambit/bit-error';
|
|
9
|
-
import { PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';
|
|
10
|
-
import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
|
|
11
|
-
import DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';
|
|
12
|
-
import { composeComponentPath } from '@teambit/legacy/dist/utils/bit/compose-component-path';
|
|
13
|
-
import { ComponentID } from '@teambit/component-id';
|
|
14
|
-
import { ComponentTemplate, ComponentFile } from './component-template';
|
|
15
|
-
import { CreateOptions } from './create.cmd';
|
|
16
|
-
|
|
17
|
-
export type GenerateResult = { id: ComponentID; dir: string; files: string[]; envId: string };
|
|
18
|
-
|
|
19
|
-
export class ComponentGenerator {
|
|
20
|
-
constructor(
|
|
21
|
-
private workspace: Workspace,
|
|
22
|
-
private componentIds: ComponentID[],
|
|
23
|
-
private options: CreateOptions,
|
|
24
|
-
private template: ComponentTemplate,
|
|
25
|
-
private envs: EnvsMain
|
|
26
|
-
) {}
|
|
27
|
-
|
|
28
|
-
async generate(): Promise<GenerateResult[]> {
|
|
29
|
-
const dirsToDeleteIfFailed: string[] = [];
|
|
30
|
-
const generateResults = await pMapSeries(this.componentIds, async (componentId) => {
|
|
31
|
-
try {
|
|
32
|
-
const componentPath = this.getComponentPath(componentId);
|
|
33
|
-
if (fs.existsSync(path.join(this.workspace.path, componentPath))) {
|
|
34
|
-
throw new BitError(`unable to create a component at "${componentPath}", this path already exist`);
|
|
35
|
-
}
|
|
36
|
-
if (await this.workspace.hasName(componentId.fullName)) {
|
|
37
|
-
throw new BitError(
|
|
38
|
-
`unable to create a component "${componentId.fullName}", a component with the same name already exist`
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
dirsToDeleteIfFailed.push(componentPath);
|
|
42
|
-
return await this.generateOneComponent(componentId, componentPath);
|
|
43
|
-
} catch (err: any) {
|
|
44
|
-
await this.deleteGeneratedComponents(dirsToDeleteIfFailed);
|
|
45
|
-
throw err;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
await this.workspace.writeBitMap();
|
|
50
|
-
|
|
51
|
-
return generateResults;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
private async deleteGeneratedComponents(dirs: string[]) {
|
|
55
|
-
await Promise.all(
|
|
56
|
-
dirs.map(async (dir) => {
|
|
57
|
-
const absoluteDir = path.join(this.workspace.path, dir);
|
|
58
|
-
try {
|
|
59
|
-
await fs.remove(absoluteDir);
|
|
60
|
-
} catch (err: any) {
|
|
61
|
-
if (err.code !== 'ENOENT') {
|
|
62
|
-
// if not exist, it's fine
|
|
63
|
-
throw err;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
private async generateOneComponent(componentId: ComponentID, componentPath: string): Promise<GenerateResult> {
|
|
71
|
-
const name = componentId.name;
|
|
72
|
-
const namePascalCase = camelcase(name, { pascalCase: true });
|
|
73
|
-
const nameCamelCase = camelcase(name);
|
|
74
|
-
const files = this.template.generateFiles({ name, namePascalCase, nameCamelCase, componentId });
|
|
75
|
-
const mainFile = files.find((file) => file.isMain);
|
|
76
|
-
await this.writeComponentFiles(componentPath, files);
|
|
77
|
-
const addResults = await this.workspace.track({
|
|
78
|
-
rootDir: componentPath,
|
|
79
|
-
mainFile: mainFile?.relativePath,
|
|
80
|
-
componentName: componentId.fullName,
|
|
81
|
-
});
|
|
82
|
-
const component = await this.workspace.get(componentId);
|
|
83
|
-
const env = this.envs.getEnv(component);
|
|
84
|
-
return {
|
|
85
|
-
id: componentId,
|
|
86
|
-
dir: componentPath,
|
|
87
|
-
files: addResults.files,
|
|
88
|
-
envId: env.id,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* writes the generated template files to the default directory set in the workspace config
|
|
94
|
-
*/
|
|
95
|
-
private async writeComponentFiles(
|
|
96
|
-
componentPath: string,
|
|
97
|
-
templateFiles: ComponentFile[]
|
|
98
|
-
): Promise<PathOsBasedRelative[]> {
|
|
99
|
-
const dataToPersist = new DataToPersist();
|
|
100
|
-
const vinylFiles = templateFiles.map((templateFile) => {
|
|
101
|
-
const templateFileVinyl = new Vinyl({
|
|
102
|
-
base: componentPath,
|
|
103
|
-
path: path.join(componentPath, templateFile.relativePath),
|
|
104
|
-
contents: Buffer.from(templateFile.content),
|
|
105
|
-
});
|
|
106
|
-
return AbstractVinyl.fromVinyl(templateFileVinyl);
|
|
107
|
-
});
|
|
108
|
-
const results = vinylFiles.map((v) => v.path);
|
|
109
|
-
dataToPersist.addManyFiles(vinylFiles);
|
|
110
|
-
dataToPersist.addBasePath(this.workspace.path);
|
|
111
|
-
await dataToPersist.persistAllToFS();
|
|
112
|
-
return results;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
private getComponentPath(componentId: ComponentID) {
|
|
116
|
-
if (this.options.path) return this.options.path;
|
|
117
|
-
return composeComponentPath(componentId._legacy.changeScope(componentId.scope), this.workspace.defaultDirectory);
|
|
118
|
-
}
|
|
119
|
-
}
|
package/component-template.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { ComponentID } from '@teambit/component-id';
|
|
2
|
-
|
|
3
|
-
export interface ComponentFile {
|
|
4
|
-
/**
|
|
5
|
-
* relative path of the file within the component.
|
|
6
|
-
*/
|
|
7
|
-
relativePath: string;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* file content
|
|
11
|
-
*/
|
|
12
|
-
content: string;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* whether this file will be tracked as the main file
|
|
16
|
-
*/
|
|
17
|
-
isMain?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface ComponentContext {
|
|
21
|
-
/**
|
|
22
|
-
* component-name as entered by the user, e.g. `use-date`.
|
|
23
|
-
* without the scope and the namespace.
|
|
24
|
-
*/
|
|
25
|
-
name: string;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* component-name as upper camel case, e.g. `use-date` becomes `UseDate`.
|
|
29
|
-
* useful when generating the file content, for example for a class name.
|
|
30
|
-
*/
|
|
31
|
-
namePascalCase: string;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* component-name as lower camel case, e.g. `use-date` becomes `useDate`.
|
|
35
|
-
* useful when generating the file content, for example for a function/variable name.
|
|
36
|
-
*/
|
|
37
|
-
nameCamelCase: string;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* component id.
|
|
41
|
-
* the name is the name+namespace. the scope is the scope entered by --scope flag or the defaultScope
|
|
42
|
-
*/
|
|
43
|
-
componentId: ComponentID;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface ComponentTemplate {
|
|
47
|
-
/**
|
|
48
|
-
* name of the component template. for example: `hook`, `react-component` or `module`.
|
|
49
|
-
*/
|
|
50
|
-
name: string;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* short description of the template. shown in the `bit templates` command.
|
|
54
|
-
*/
|
|
55
|
-
description?: string;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* hide this template so that it is not listed with `bit templates`
|
|
59
|
-
*/
|
|
60
|
-
hidden?: boolean;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* template function for generating the file of a certain component.,
|
|
64
|
-
*/
|
|
65
|
-
generateFiles(context: ComponentContext): ComponentFile[];
|
|
66
|
-
}
|
package/create.cmd.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Command, CommandOptions } from '@teambit/cli';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { GeneratorMain } from './generator.main.runtime';
|
|
4
|
-
|
|
5
|
-
export type CreateOptions = {
|
|
6
|
-
namespace?: string;
|
|
7
|
-
aspect?: string;
|
|
8
|
-
scope?: string;
|
|
9
|
-
path?: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export class CreateCmd implements Command {
|
|
13
|
-
name = 'create <templateName> <componentNames...>';
|
|
14
|
-
description = 'create a new component from a template';
|
|
15
|
-
shortDescription = '';
|
|
16
|
-
alias = '';
|
|
17
|
-
loader = true;
|
|
18
|
-
group = 'development';
|
|
19
|
-
options = [
|
|
20
|
-
['n', 'namespace <string>', `sets the component's namespace and nested dirs inside the scope`],
|
|
21
|
-
['s', 'scope <string>', `sets the component's scope-name. if not entered, the default-scope will be used`],
|
|
22
|
-
['a', 'aspect <string>', 'aspect-id of the template. helpful when multiple aspects use the same template name'],
|
|
23
|
-
['p', 'path <string>', 'relative path in the workspace. by default the path is `<scope>/<namespace>/<name>`'],
|
|
24
|
-
] as CommandOptions;
|
|
25
|
-
|
|
26
|
-
constructor(private generator: GeneratorMain) {}
|
|
27
|
-
|
|
28
|
-
async report([templateName, componentNames]: [string, string[]], options: CreateOptions) {
|
|
29
|
-
const results = await this.generator.generateComponentTemplate(componentNames, templateName, options);
|
|
30
|
-
const title = `${results.length} component(s) were created`;
|
|
31
|
-
|
|
32
|
-
const componentsData = results
|
|
33
|
-
.map((result) => {
|
|
34
|
-
return `${chalk.bold(result.id.toString())}
|
|
35
|
-
location: ${result.dir}
|
|
36
|
-
env: ${result.envId}
|
|
37
|
-
`;
|
|
38
|
-
})
|
|
39
|
-
.join('\n');
|
|
40
|
-
const footer = `env configuration is according to workspace variants. learn more at https://harmony-docs.bit.dev/building-with-bit/environments/#configure-environment-for-components`;
|
|
41
|
-
|
|
42
|
-
return `${chalk.green(title)}\n\n${componentsData}\n\n${footer}`;
|
|
43
|
-
}
|
|
44
|
-
}
|
package/generator.aspect.ts
DELETED
package/generator.docs.mdx
DELETED
package/generator.graphql.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { Schema } from '@teambit/graphql';
|
|
2
|
-
import gql from 'graphql-tag';
|
|
3
|
-
import { GeneratorMain } from './generator.main.runtime';
|
|
4
|
-
|
|
5
|
-
export function generatorSchema(generator: GeneratorMain): Schema {
|
|
6
|
-
return {
|
|
7
|
-
typeDefs: gql`
|
|
8
|
-
type GenerateResult {
|
|
9
|
-
id: String
|
|
10
|
-
dir: String
|
|
11
|
-
files: [String]
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type Mutation {
|
|
15
|
-
# create Component by template
|
|
16
|
-
createComponent(
|
|
17
|
-
name: String!
|
|
18
|
-
templateName: String!
|
|
19
|
-
scope: String
|
|
20
|
-
namespace: String
|
|
21
|
-
aspect: String
|
|
22
|
-
): [GenerateResult]
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
type TemplateDescriptor {
|
|
26
|
-
aspectId: String!
|
|
27
|
-
name: String!
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
type Generator {
|
|
31
|
-
templates: [TemplateDescriptor]
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
type Query {
|
|
35
|
-
generator: Generator
|
|
36
|
-
}
|
|
37
|
-
`,
|
|
38
|
-
resolvers: {
|
|
39
|
-
Mutation: {
|
|
40
|
-
createComponent: async (
|
|
41
|
-
req: any,
|
|
42
|
-
{
|
|
43
|
-
name,
|
|
44
|
-
templateName,
|
|
45
|
-
...options
|
|
46
|
-
}: { name: string; templateName: string; scope?: string; namespace?: string; aspect?: string }
|
|
47
|
-
) => {
|
|
48
|
-
const res = await generator.generateComponentTemplate([name], templateName, options);
|
|
49
|
-
return res.map((component) => ({
|
|
50
|
-
id: component.id.toString(),
|
|
51
|
-
dir: component.dir,
|
|
52
|
-
files: component.files,
|
|
53
|
-
}));
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
Generator: {
|
|
57
|
-
templates: async () => {
|
|
58
|
-
return generator.listTemplates();
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
Query: {
|
|
62
|
-
generator: () => generator,
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
}
|